1 # APIs for MCU based Host
3 # 1. Serial interface layer
4 This section explains serial interface APIs and data structures provided by MCU based ESP Host software.
8 ### _struct_ `serial_handle_s`
9 This structure holds instance of a virtual serial interface. It contains following fields:
12 - `QueueHandle_t queue`:
13 Buffer queue for storing received data packets
15 ESP Hosted Interface type
17 ESP Hosted Interface number
18 - `struct serial_operations *ops`:
19 Hook functions supported by virtual serial interface
22 - `void (*serial_rx_callback) (void)`:
23 Rx callback registered by upper layer.
27 ### _struct_ `serial_operations`
28 This structure defines hook functions that are defined by virtual serial driver
31 - `int (*open) (serial_handle_t *serial_hdl)`:
32 Prepares and opens specified serial interface for communication.
35 Non null handle for virtual serial interface
40 - `uint8_t *(*read) (const serial_handle_t * serial_hdl, uint16_t * rlen)`:
41 This function performs non blocking read operation over specified serial interface handle.
44 Non null handle for virtual serial interface
46 Output parameter, indicates number of bytes read
48 - On success, pointer to received buffer
49 - On failure [and when no data is available to read], NULL
51 - `int (*write) (const serial_handle_t * serial_hdl, uint8_t * wbuffer, const uint16_t wlen)`:
52 This function performs write operation on specified serial interface handle.
55 Non null handle for virtual serial interface
57 Data buffer to be written over serial interface
59 Length of data to be written in bytes
64 - `int (*close) (serial_handle_t * serial_hdl)`:
65 Closes specified serial interface handle.
68 Non null handle for virtual serial interface
78 ### `serial_handle_t * serial_init(void(*rx_data_ind)(void))`
79 This API can be used by higher layer to setup a serial interface. A serial interface handle is returned in response. This handle can be used to perform further operations on specified serial interface.
82 - `void(*rx_data_ind)(void)`:
83 Call back function in higher layer. This is used to indicate availibility of Rx data to higher layer. Higher layer can perform read operation to get this data.
87 - Non NULL: pointer to a valid serial interface handle
91 # 2. Network interface layer
92 This section explains network interface APIs and data structures provided by ESP Host software.
94 ## 2.1 Data structures
97 - This is a opaque structure which network stack should define.
98 - This denotes instance of a network device in a network stack.
99 - Along with network stack specific data, it should also hold private structure of underlying driver.
104 This is a basic structure that holds a network packet which is being transmitted or received.
107 - `uint8_t *payload`:
108 This points to network payload buffer which is being transmitted or received
110 This represents length of payload field in bytes
114 ### _struct_ `netdev_ops`
115 This structure represents management hooks which are implemented by underlying driver [which is SPI host driver in this case].
118 - `int (* netdev_open) (struct netdev *)`
119 This function prepares underlying driver for data transmission or reception on specified network device instance.
122 Non null network device instance
127 - `int (* netdev_close) (struct netdev *)`
128 Network stack calls this function while closing a network device instance.
131 Non null network device instance
136 - `int (* netdev_xmit) (struct netdev *, struct pbuf *)`
137 Network stack calls this function to transfer a data packet from network stack to underlying SPI host driver.
140 Non null network device instance
142 Non null buffer pointer. This will be freed by SPI host driver.
150 Below are the APIs that are to be implemented by network stack.
152 ### `struct netdev * netdev_alloc(uint32_t sizeof_priv, char *name)`
153 This function allocates and initializes a network device instance for a given network interface name. This function also allocates memory for storing priv instance of SPI host driver.
157 This denotes size [in bytes] of a priv instance of SPI host driver.
159 Name of network interface for which a network device instance to be allocated
163 - Non NULL: Pointer to the struct netdev
167 ### `void netdev_free(struct netdev *ndev)`
168 This function frees network device instance. This also frees memory allocated for storing priv instance of SPI host driver.
172 Non null network device instance to be freed
176 ### `void * netdev_get_priv(struct netdev *ndev)`
177 This function returns pointer to the priv instance of SPI host driver from the specified network device instance
181 Non null network device instance
185 - Non NULL : pointer to the priv instance of SPI host driver
189 ### `int netdev_register(struct netdev *ndev, struct netdev_ops *ops)`
190 This function registers a network device with network stack.
194 Non null network device instance to be registered
196 Management hooks implemented by SPI host driver
204 ### `int netdev_unregister(struct netdev *ndev)`
205 This function unregisters a network device
209 Non null network device instance to be unregistered
218 ### `int netdev_rx(struct netdev *ndev, struct pbuf *net_buf)`
219 SPI host driver calls this function to pass on received network packet to network stack
223 Non null network device instance for which a packet has been received
225 Non null buffer that contains received network packet. The SPI host driver will allocate this buffer. Network stack is supposed to free this buffer.