no-OS
no_os_spi.h
Go to the documentation of this file.
1 /***************************************************************************/
34 #ifndef _NO_OS_SPI_H_
35 #define _NO_OS_SPI_H_
36 
37 /******************************************************************************/
38 /***************************** Include Files **********************************/
39 /******************************************************************************/
40 
41 #include <stdint.h>
42 
43 /******************************************************************************/
44 /********************** Macros and Constants Definitions **********************/
45 /******************************************************************************/
46 
47 #define NO_OS_SPI_CPHA 0x01
48 #define NO_OS_SPI_CPOL 0x02
49 #define SPI_MAX_BUS_NUMBER 8
50 
51 /******************************************************************************/
52 /*************************** Types Declarations *******************************/
53 /******************************************************************************/
54 
61  NO_OS_SPI_MODE_0 = (0 | 0),
68 };
69 
79 };
80 
94 };
95 
102  uint8_t *tx_buff;
104  uint8_t *rx_buff;
106  uint32_t bytes_number;
108  uint8_t cs_change;
113  uint32_t cs_change_delay;
115  uint32_t cs_delay_first;
117  uint32_t cs_delay_last;
118 };
119 
125  uint32_t cs_delay_first;
126  uint32_t cs_delay_last;
127 };
128 
134 struct no_os_spi_platform_ops ;
135 
142  uint32_t device_id;
144  uint32_t max_speed_hz;
146  uint8_t chip_select;
158  void *extra;
161 };
162 
169  void *mutex;
171  uint8_t slave_number;
173  uint32_t device_id;
175  uint32_t max_speed_hz;
185  void *extra;
186 };
187 
196  uint32_t device_id;
198  uint32_t max_speed_hz;
200  uint8_t chip_select;
212  void *extra;
215 };
216 
224  int32_t (*init)(struct no_os_spi_desc **, const struct no_os_spi_init_param *);
226  int32_t (*write_and_read)(struct no_os_spi_desc *, uint8_t *, uint16_t);
228  int32_t (*transfer)(struct no_os_spi_desc *, struct no_os_spi_msg *, uint32_t);
232  int32_t (*dma_transfer_sync)(struct no_os_spi_desc *, struct no_os_spi_msg *,
233  uint32_t);
238  int32_t (*dma_transfer_async)(struct no_os_spi_desc *, struct no_os_spi_msg *,
239  uint32_t, void (*)(void *), void *);
241  int32_t (*remove)(struct no_os_spi_desc *);
242 };
243 
244 /******************************************************************************/
245 /************************ Functions Declarations ******************************/
246 /******************************************************************************/
247 
248 /* Initialize the SPI communication peripheral. */
249 int32_t no_os_spi_init(struct no_os_spi_desc **desc,
250  const struct no_os_spi_init_param *param);
251 
252 /* Free the resources allocated by no_os_spi_init(). */
253 int32_t no_os_spi_remove(struct no_os_spi_desc *desc);
254 
255 /* Write and read data to/from SPI. */
256 int32_t no_os_spi_write_and_read(struct no_os_spi_desc *desc,
257  uint8_t *data,
258  uint16_t bytes_number);
259 
260 /* Iterate over the spi_msg array and send all messages at once */
261 int32_t no_os_spi_transfer(struct no_os_spi_desc *desc,
262  struct no_os_spi_msg *msgs,
263  uint32_t len);
264 
265 /* Transfer a list of messages using DMA. Wait until all transfers are done */
266 int32_t no_os_spi_transfer_dma_sync(struct no_os_spi_desc *desc,
267  struct no_os_spi_msg *msgs,
268  uint32_t len);
269 /*
270  * Transfer a list of messages using DMA. Return once the first one started and
271  * invoke a callback when they are done.
272  */
273 int32_t no_os_spi_transfer_dma_async(struct no_os_spi_desc *desc,
274  struct no_os_spi_msg *msgs,
275  uint32_t len,
276  void (*callback)(void *),
277  void *ctx);
278 
279 /* Initialize SPI bus descriptor*/
280 int32_t no_os_spibus_init(const struct no_os_spi_init_param *param);
281 
282 /* Free the resources allocated for SPI bus desc*/
283 void no_os_spibus_remove(uint32_t bus_number);
284 
285 
286 #endif // _NO_OS_SPI_H_
NO_OS_SPI_MODE_1
@ NO_OS_SPI_MODE_1
Definition: no_os_spi.h:63
NO_OS_SPI_QUAD_LANE
@ NO_OS_SPI_QUAD_LANE
Definition: no_os_spi.h:91
no_os_spibus_desc::mutex
void * mutex
Definition: no_os_spi.h:169
no_os_spi_mode
no_os_spi_mode
SPI configuration for clock phase and polarity.
Definition: no_os_spi.h:59
no_os_spi_desc::device_id
uint32_t device_id
Definition: no_os_spi.h:196
NO_OS_SPI_CPOL
#define NO_OS_SPI_CPOL
Definition: no_os_spi.h:48
no_os_spi_init_param::bit_order
enum no_os_spi_bit_order bit_order
Definition: no_os_spi.h:150
no_os_spi_write_and_read
int32_t no_os_spi_write_and_read(struct no_os_spi_desc *desc, uint8_t *data, uint16_t bytes_number)
Write and read data to/from SPI.
Definition: no_os_spi.c:159
no_os_spibus_desc::mode
enum no_os_spi_mode mode
Definition: no_os_spi.h:177
no_os_spibus_desc::bit_order
enum no_os_spi_bit_order bit_order
Definition: no_os_spi.h:179
no_os_spi_msg
Definition: no_os_spi.h:100
no_os_spi_platform_ops
Structure holding SPI function pointers that point to the platform specific function.
Definition: no_os_spi.h:222
no_os_spi_desc::lanes
enum no_os_spi_lanes lanes
Definition: no_os_spi.h:206
no_os_spi_msg::cs_delay_last
uint32_t cs_delay_last
Definition: no_os_spi.h:117
no_os_spi_init_param::mode
enum no_os_spi_mode mode
Definition: no_os_spi.h:148
no_os_spibus_desc::slave_number
uint8_t slave_number
Definition: no_os_spi.h:171
NO_OS_SPI_MODE_2
@ NO_OS_SPI_MODE_2
Definition: no_os_spi.h:65
no_os_spi_bit_order
no_os_spi_bit_order
SPI configuration for bit order (MSB/LSB).
Definition: no_os_spi.h:74
no_os_spi_transfer_dma_sync
int32_t no_os_spi_transfer_dma_sync(struct no_os_spi_desc *desc, struct no_os_spi_msg *msgs, uint32_t len)
Transfer a list of messages using DMA and busy wait for the completion.
Definition: no_os_spi.c:224
no_os_spibus_desc::device_id
uint32_t device_id
Definition: no_os_spi.h:173
no_os_spibus_desc::platform_ops
const struct no_os_spi_platform_ops * platform_ops
Definition: no_os_spi.h:183
NO_OS_SPI_OCTO_LANE
@ NO_OS_SPI_OCTO_LANE
Definition: no_os_spi.h:93
no_os_spi_init_param::platform_ops
const struct no_os_spi_platform_ops * platform_ops
Definition: no_os_spi.h:154
NO_OS_SPI_MODE_3
@ NO_OS_SPI_MODE_3
Definition: no_os_spi.h:67
no_os_spi_msg::tx_buff
uint8_t * tx_buff
Definition: no_os_spi.h:102
no_os_spi_init_param::device_id
uint32_t device_id
Definition: no_os_spi.h:142
no_os_spi_init_param::chip_select
uint8_t chip_select
Definition: no_os_spi.h:146
no_os_spi_desc::chip_select
uint8_t chip_select
Definition: no_os_spi.h:200
no_os_spi_init_param::platform_delays
struct no_os_platform_spi_delays platform_delays
Definition: no_os_spi.h:156
no_os_spi_desc::parent
struct no_os_spi_desc * parent
Definition: no_os_spi.h:214
no_os_spi_msg::rx_buff
uint8_t * rx_buff
Definition: no_os_spi.h:104
no_os_spi_msg::cs_delay_first
uint32_t cs_delay_first
Definition: no_os_spi.h:115
no_os_spi_init_param::lanes
enum no_os_spi_lanes lanes
Definition: no_os_spi.h:152
no_os_spi_msg::cs_change
uint8_t cs_change
Definition: no_os_spi.h:108
NO_OS_SPI_SINGLE_LANE
@ NO_OS_SPI_SINGLE_LANE
Definition: no_os_spi.h:87
no_os_spibus_desc::lanes
enum no_os_spi_lanes lanes
Definition: no_os_spi.h:181
no_os_spi_init_param::parent
struct no_os_spi_desc * parent
Definition: no_os_spi.h:160
no_os_spi_desc::bit_order
enum no_os_spi_bit_order bit_order
Definition: no_os_spi.h:204
no_os_spi_platform_ops::transfer
int32_t(* transfer)(struct no_os_spi_desc *, struct no_os_spi_msg *, uint32_t)
Definition: no_os_spi.h:228
no_os_spi_desc
Structure holding SPI descriptor.
Definition: no_os_spi.h:192
no_os_spi_platform_ops::dma_transfer_async
int32_t(* dma_transfer_async)(struct no_os_spi_desc *, struct no_os_spi_msg *, uint32_t, void(*)(void *), void *)
Definition: no_os_spi.h:238
no_os_spibus_desc::max_speed_hz
uint32_t max_speed_hz
Definition: no_os_spi.h:175
no_os_spi_transfer
int32_t no_os_spi_transfer(struct no_os_spi_desc *desc, struct no_os_spi_msg *msgs, uint32_t len)
Iterate over head list and send all spi messages.
Definition: no_os_spi.c:185
no_os_spi_msg::bytes_number
uint32_t bytes_number
Definition: no_os_spi.h:106
no_os_spi_desc::extra
void * extra
Definition: no_os_spi.h:212
no_os_spi_msg::cs_change_delay
uint32_t cs_change_delay
Definition: no_os_spi.h:113
no_os_spi_init_param::max_speed_hz
uint32_t max_speed_hz
Definition: no_os_spi.h:144
no_os_platform_spi_delays
Delays resulted from components in the SPI signal path. The values is ns.
Definition: no_os_spi.h:124
no_os_spi_platform_ops::remove
int32_t(* remove)(struct no_os_spi_desc *)
Definition: no_os_spi.h:241
no_os_spi_desc::bus
struct no_os_spibus_desc * bus
Definition: no_os_spi.h:194
no_os_spi_transfer_dma_async
int32_t no_os_spi_transfer_dma_async(struct no_os_spi_desc *desc, struct no_os_spi_msg *msgs, uint32_t len, void(*callback)(void *), void *ctx)
Transfer a list of messages using DMA. The function will return after the first transfer is started....
Definition: no_os_spi.c:248
NO_OS_SPI_BIT_ORDER_LSB_FIRST
@ NO_OS_SPI_BIT_ORDER_LSB_FIRST
Definition: no_os_spi.h:78
NO_OS_SPI_BIT_ORDER_MSB_FIRST
@ NO_OS_SPI_BIT_ORDER_MSB_FIRST
Definition: no_os_spi.h:76
no_os_spibus_desc::extra
void * extra
Definition: no_os_spi.h:185
no_os_platform_spi_delays::cs_delay_first
uint32_t cs_delay_first
Definition: no_os_spi.h:125
no_os_spi_platform_ops::write_and_read
int32_t(* write_and_read)(struct no_os_spi_desc *, uint8_t *, uint16_t)
Definition: no_os_spi.h:226
no_os_spi_remove
int32_t no_os_spi_remove(struct no_os_spi_desc *desc)
Free the resources allocated by no_os_spi_init().
Definition: no_os_spi.c:116
no_os_spi_desc::platform_ops
const struct no_os_spi_platform_ops * platform_ops
Definition: no_os_spi.h:208
no_os_spi_lanes
no_os_spi_lanes
SPI configuration for number of lanes.
Definition: no_os_spi.h:85
no_os_spi_desc::platform_delays
struct no_os_platform_spi_delays platform_delays
Definition: no_os_spi.h:210
no_os_spi_desc::max_speed_hz
uint32_t max_speed_hz
Definition: no_os_spi.h:198
no_os_spi_init
int32_t no_os_spi_init(struct no_os_spi_desc **desc, const struct no_os_spi_init_param *param)
Initialize the SPI communication peripheral.
Definition: no_os_spi.c:52
no_os_spibus_desc
SPI bus descriptor.
Definition: no_os_spi.h:167
no_os_spi_platform_ops::dma_transfer_sync
int32_t(* dma_transfer_sync)(struct no_os_spi_desc *, struct no_os_spi_msg *, uint32_t)
Definition: no_os_spi.h:232
NO_OS_SPI_CPHA
#define NO_OS_SPI_CPHA
Definition: no_os_spi.h:47
no_os_spibus_remove
void no_os_spibus_remove(uint32_t bus_number)
Removes SPI bus instance.
Definition: no_os_spi.c:133
no_os_spi_platform_ops::init
int32_t(* init)(struct no_os_spi_desc **, const struct no_os_spi_init_param *)
Definition: no_os_spi.h:224
no_os_platform_spi_delays::cs_delay_last
uint32_t cs_delay_last
Definition: no_os_spi.h:126
no_os_spi_init_param::extra
void * extra
Definition: no_os_spi.h:158
NO_OS_SPI_MODE_0
@ NO_OS_SPI_MODE_0
Definition: no_os_spi.h:61
no_os_spi_desc::mode
enum no_os_spi_mode mode
Definition: no_os_spi.h:202
NO_OS_SPI_DUAL_LANE
@ NO_OS_SPI_DUAL_LANE
Definition: no_os_spi.h:89
no_os_spi_init_param
Structure holding the parameters for SPI initialization.
Definition: no_os_spi.h:140
no_os_spibus_init
int32_t no_os_spibus_init(const struct no_os_spi_init_param *param)
Initialize the SPI bus communication peripheral.
Definition: no_os_spi.c:88