WE310F5  39.00.000
m2mb_spi_master.h
Go to the documentation of this file.
1 /*===============================================================================================*/
2 /* >>> Copyright (C) Telit Communications S.p.A. Italy All Rights Reserved. <<< */
28 #ifndef M2M_M2MB_SPI_API_H
29 #define M2M_M2MB_SPI_API_H
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
44 /*-----------------------------------------------------------------------------------------------*/
45 
50 /*-----------------------------------------------------------------------------------------------*/
51 /* Global declarations ==========================================================================*/
52 #define M2MB_SPI_CLKPOL_IDLE_LOW 0
53 #define M2MB_SPI_CLKPOL_IDLE_HIGH 1
55 #define M2MB_SPI_CLKPHASE_RISING_EDGE 0
56 #define M2MB_SPI_CLKPHASE_FALLING_EDGE 1
58 #define M2MB_SPI_BITS_PER_WORD_8 8
60 #define M2MB_SPI_BAUD_RATE_10MHZ 10000000
63 /* Global enums ==============================================================================*/
64 
66 {
93 
94 /* Global typedefs ==============================================================================*/
95 
96 /* SPI phase type.
97  * This type defines the clock phase that the client can set in the
98  * SPI configuration.
99  */
100 typedef enum
101 {
108 
109 /* SPI chip select polarity type.
110  */
111 typedef enum
112 {
117 
118 /* SPI clock mode
119  */
120 typedef enum
121 {
124  M2MB_SPI_CLK_INVALID = 0x7FFFFFFF
126 
127 /* SPI chip select assertion type.
128  * This type defines how the chip select line is configured between N word cycles.
129  */
130 typedef enum
131 {
136 
137 /* Order in which bytes from Tx/Rx buffer words are put on the bus.
138  */
139 typedef enum
140 {
146 
147 /* SPI callback function type.
148  * This type is used by the client to register its callback notification function. The
149  * callback_ctxt is the context object that will be passed untouched by the SPI Master
150  * driver to help the client identify which transfer completion instance is being signaled.
151  */
152 typedef void (*M2MB_SPI_CALLBACK_FN_T) (UINT32 status, void *callback_ctxt);
153 
154 /* SPI access ID*/
155 typedef void* M2MB_SPI_ID_t;
156 
157 /* SPI configuration.
158  * The SPI configuration is the collection of settings specified for each SPI
159  * transfer call to select the various possible SPI transfer parameters.
160  */
161 typedef struct
162 {
164  M2MB_SPI_SHIFT_MODE_T spi_mode;
165  M2MB_SPI_CS_POLARITY_T cs_polarity;
166  M2MB_SPI_CS_MODE_T cs_mode;
168  M2MB_SPI_BYTE_ORDER_T endianness;
170  HANDLE callback_ctxt;
171  UINT32 clk_freq_Hz;
177 
178 /* Global functions =============================================================================*/
179 
180 /*-----------------------------------------------------------------------------------------------*/
210 INT32 m2mb_spi_open( const CHAR *path, INT32 flags, ... );
211 /*-----------------------------------------------------------------------------------------------*/
235 /*-----------------------------------------------------------------------------------------------*/
262 
263 /*-----------------------------------------------------------------------------------------------*/
288 #ifdef WE310_BUILD_GCC
289 SSIZE_T m2mb_spi_read( INT32 fd, void *buf, INT32 nbyte );
290 #else
291 SSIZE_T m2mb_spi_read( INT32 fd, void *buf, SIZE_T nbyte );
292 #endif
293 /*-----------------------------------------------------------------------------------------------*/
318 #ifdef WE310_BUILD_GCC
319 SSIZE_T m2mb_spi_write( INT32 fd, const void *buf, INT32 nbyte );
320 #else
321 SSIZE_T m2mb_spi_write( INT32 fd, const void *buf, SIZE_T nbyte );
322 #endif
323 /*-----------------------------------------------------------------------------------------------*/
352 #ifdef WE310_BUILD_GCC
353 SSIZE_T m2mb_spi_write_read( INT32 fd, const void *bufwr, void *bufWr, INT32 nbyte );
354 #else
355 SSIZE_T m2mb_spi_write_read( INT32 fd, const void *bufwr, void *bufWr, SIZE_T nbyte );
356 #endif
357 
360 /*-----------------m2mb_spi_write_read------------------------------------------------------------------------------*/
361 
362 
363 #ifdef __cplusplus
364 }
365 #endif
366 
367 #endif /* M2M_M2MB_SPI_API_H */
368 
369 
INT32 SSIZE_T
Definition: m2mb_types.h:107
INT32 m2mb_spi_close(INT32 fd)
close a SPI device
M2MB_SPI_CS_POLARITY_T
M2MB_SPI_IOCTL_REQUEST
Definition: m2mb_spi.h:48
SSIZE_T m2mb_spi_write_read(INT32 fd, const void *bufwr, void *bufWr, SIZE_T nbyte)
perform a bi-directional (full duplex) transfer.
UINT32 inter_word_delay_cycles
void(* M2MB_SPI_CALLBACK_FN_T)(UINT32 status, void *callback_ctxt)
INT32 m2mb_spi_open(const CHAR *path, INT32 flags,...)
open a SPI device
M2MB_SPI_CLK_MODE_T
char CHAR
Definition: m2mb_types.h:76
M2MB_SPI_BYTE_ORDER_T
Definition: m2mb_spi.h:114
INT32 m2mb_spi_ioctl(INT32 fd, M2MB_SPI_IOCTL_REQUEST_T request,...)
configure a SPI device
SSIZE_T m2mb_spi_read(INT32 fd, void *buf, SIZE_T nbyte)
read nbyte Bytes from a SPI device into the array pointed by buf
SSIZE_T m2mb_spi_write(INT32 fd, const void *buf, SIZE_T nbyte)
write nbyte Bytes from the array pointed by buf to a SPI device
UINT32 SIZE_T
Definition: m2mb_types.h:105
M2MB_SPI_SHIFT_MODE_T
Definition: m2mb_spi.h:84
enum M2MB_SPI_IOCTL_REQUEST M2MB_SPI_IOCTL_REQUEST_T
UINT32 cs_clk_delay_cycles
M2MB_SPI_BYTE_ORDER_T
M2MB_SPI_SHIFT_MODE_T
unsigned long int UINT32
Definition: m2mb_types.h:88
M2MB_SPI_CALLBACK_FN_T callback_fn
signed int INT32
Definition: m2mb_types.h:82
M2MB_SPI_CS_MODE_T
Definition: m2mb_spi.h:105
void * HANDLE
Definition: m2mb_types.h:98
M2MB_SPI_CS_MODE_T
M2MB_SPI_CLK_MODE_T clk_mode
void * M2MB_SPI_ID_t
M2MB_SPI_CS_POLARITY_T
Definition: m2mb_spi.h:95
M2MB_SPI_ID_t accessId