1 /* 2 * Copyright Runtime.io 2018. All rights reserved. 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 /** @file 8 * @brief A driver for sending and receiving mcumgr packets over UART. 9 * 10 * @see include/mgmt/serial.h 11 */ 12 13 #ifndef ZEPHYR_INCLUDE_DRIVERS_CONSOLE_UART_MCUMGR_H_ 14 #define ZEPHYR_INCLUDE_DRIVERS_CONSOLE_UART_MCUMGR_H_ 15 16 #include <stdlib.h> 17 #include <zephyr/types.h> 18 19 #ifdef __cplusplus 20 extern "C" { 21 #endif 22 23 /** 24 * @brief Contains an mcumgr fragment received over UART. 25 */ 26 struct uart_mcumgr_rx_buf { 27 void *fifo_reserved; /* 1st word reserved for use by fifo */ 28 uint8_t data[CONFIG_UART_MCUMGR_RX_BUF_SIZE]; 29 int length; 30 }; 31 32 /** @typedef uart_mcumgr_recv_fn 33 * @brief Function that gets called when an mcumgr packet is received. 34 * 35 * Function that gets called when an mcumgr packet is received. This function 36 * gets called in the interrupt context. Ownership of the specified buffer is 37 * transferred to the callback when this function gets called. 38 * 39 * @param rx_buf A buffer containing the incoming mcumgr packet. 40 */ 41 typedef void uart_mcumgr_recv_fn(struct uart_mcumgr_rx_buf *rx_buf); 42 43 /** 44 * @brief Sends an mcumgr packet over UART. 45 * 46 * @param data Buffer containing the mcumgr packet to send. 47 * @param len The length of the buffer, in bytes. 48 * 49 * @return 0 on success; negative error code on failure. 50 */ 51 int uart_mcumgr_send(const uint8_t *data, int len); 52 53 /** 54 * @brief Frees the supplied receive buffer. 55 * 56 * @param rx_buf The buffer to free. 57 */ 58 void uart_mcumgr_free_rx_buf(struct uart_mcumgr_rx_buf *rx_buf); 59 60 /** 61 * @brief Registers an mcumgr UART receive handler. 62 * 63 * Configures the mcumgr UART driver to call the specified function when an 64 * mcumgr request packet is received. 65 * 66 * @param cb The callback to execute when an mcumgr request 67 * packet is received. 68 */ 69 void uart_mcumgr_register(uart_mcumgr_recv_fn *cb); 70 71 #ifdef __cplusplus 72 } 73 #endif 74 75 #endif 76