ISSDK  1.8
IoT Sensing Software Development Kit
host_io_uart.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, Freescale Semiconductor, Inc.
3  * Copyright 2016-2017 NXP
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 /**
10  * @file host_io_uart.h
11  * @brief The host_io_uart.h file contains the Host Protocol interface definitions and configuration.
12  */
13 
14 #ifndef HOST_IO_UART_H_
15 #define HOST_IO_UART_H_
16 
17 /*******************************************************************************
18  * CMSIS Includes
19  ******************************************************************************/
20 #include "Driver_USART.h"
21 
22 /*******************************************************************************
23  * Types and Definitions
24  ******************************************************************************/
25 #define STREAMING_HEADER_LEN (4) /* ISSDK Host Protocol defined Iso Cmd Header Length + Stream ID. */
26 #define HOST_RX_BUF_LEN (64) /* MAX size of Rx Host CMDs. */
27 #define HOST_RSP_HDR_LEN (4) /* Size of Host response message header. */
28 #define HOST_DEV_RSP_LEN (128) /* MAX size of Host Dev Info Response. */
29 #define HOST_CMD_RSP_LEN (64) /* MAX size of Host Command Response. */
30 #define MAX_HOST_STREAMS (4) /* Max Streams that can be defined by the user Application. */
31 #define HOST_CMD_RESP_ACK (0x80) /* HOST CMD Ack code. */
32 #define HOST_CMD_RESP_NACK (0xC6) /* HOST CMD Nack code. */
33 #define EVENT_STREAM_ID (0xFF) /* Stream ID in ISO Message for posting Events (such as freefall) */
34 
35 /*! @brief This structure holds information regarding the Encoding and RLI interface parameters. */
36 typedef struct
37 {
38  void *deviceInfo;
39  void *pCommDrv;
40  void *pSPIparams;
41  uint16_t slaveAddress;
43 
44 /*! @brief The Host Command Process Function ([IN]Command TAG, [IN]Commad Buffer, [OUT]Response Buffer,
45  * [IN/OUT]MessageSize, [IN]BufferSize) */
46 typedef bool (*host_cmd_proc_fn_t)(uint8_t, uint8_t *, uint8_t *, size_t *, size_t);
47 
48 /*! @brief This structure holds information to receive a packet of data to the host. */
49 typedef struct
50 {
51  uint8_t rxState; /* Internal receive state */
52  uint8_t mIndex; /* Message index */
53  uint8_t *pRxbuf; /* Receive buffer */
55 
56 /*! @brief Bit aligned values for Host Protocol Interface IDs (Bits 5-6). */
57 #define HOST_PRO_INT_CMD_TAG (0x20) /* 1 */
58 #define HOST_PRO_INT_ISO_TAG (0x40) /* 2 */
59 #define HOST_PRO_INT_DEV_TAG (0x60) /* 3 */
60 
61 /*! @brief Bit aligned values for Host Protocol Command Interface Type IDs (Bits 0-4). */
62 #define HOST_PRO_CMD_X_RES_TAG (0x00) /* 0 (Reserved) */
63 #define HOST_PRO_CMD_W_CFG_TAG (0x01) /* 1 */
64 #define HOST_PRO_CMD_R_CFG_TAG (0x02) /* 2 */
65 #define HOST_PRO_CMD_W_REG_TAG (0x03) /* 3 */
66 #define HOST_PRO_CMD_R_REG_TAG (0x04) /* 4 */
67 
68 /*! @brief Bit aligned values for Host Protocol Command Interface Status IDs (Bit 7). */
69 #define HOST_PRO_CMD_WR_NAK_TAG (0x7F) /* 0 */
70 #define HOST_PRO_CMD_WR_ACK_TAG (0x80) /* 1 */
71 
72 enum
73 {
77 };
78 
79 enum
80 {
96 };
97 
98 /*! @brief This enum lists the Configuration Command Operation Codes. */
99 enum
100 {
101  HOST_CMD_NOP = 0, /* 0 (No Operation) */
102  HOST_CMD_START, /* 1 (Start Streaming) */
103  HOST_CMD_STOP, /* 2 (Stop Streaming) */
104  HOST_CMD_FLASH_START, /* 3 (Enter FLASH Mode) */
105  HOST_CMD_FLASH_BYTES, /* 4 (Bytes to FLASH) */
106  HOST_CMD_FLASH_STOP, /* 5 (Exit FLASH Mode) */
107 };
108 
109 /*! @brief Defines the HOST UART signal event handler.
110  * @details The Signal Event Handler function required by host_io_uart.c.
111  * @param[in] event The UART event that occured.
112  * @Constraints None
113  * @Reentrant Yes
114  * @return void
115  */
116 void HOST_SignalEvent_t(uint32_t event);
117 
118 /*******************************************************************************
119  * APIs
120  ******************************************************************************/
121 /* ===================================================================
122  * @brief Function populate Streaming Packet Header.
123  * @details This function sets up streaming related parameters in the ISO Message Header.
124  * @param[in] uint8_t streamID The stream ID this packet corresponds.
125  * @param[in] uint8_t *streamingPacket The handle to the buffer containing the streaming packet.
126  * @param[in] size_t sizePayload The size of the actual payload excluding the Header.
127  * @return None
128  * @constraints This should be the called only after DEBUG Port has been initialized.
129  * @reeentrant No
130  * =================================================================== */
131 void Host_IO_Add_ISO_Header(uint8_t streamID, uint8_t *pStreamingPacket, size_t sizePayload);
132 
133 /* ===================================================================
134  * @brief Function to get Stream ID, set Encoding and configure RLI related parameters.
135  * Stream IDs are allocated incrementally everytime this API is called to for a new Stream.
136  * It also configures UART for receiving RLI messages form Host.
137  * @param[in] ARM_DRIVER_USART *pDrv Pointer to the UART communication bus.
138  * @param[in] void *pBus Pointer to the I2C/SPI communication bus for register read/write support.
139  * @param[in] void *pDevInfo Pointer to the I2C/SPI device info structure.
140  * @param[in] void *spiSlaveParams (Only for SPI) The handle to the structure containing SPI Slave parameters.
141  * @param[in] uint16_t slaveAddress The Sensor's I2C Slave Address to identify the slave (required for both I2C/SPI).
142  * @return uint8_t The unique ID for this stream.
143  * @constraints This should be the called only after DEBUG Port has been initialized.
144  * @reeentrant No
145  * =================================================================== */
146 uint8_t Host_IO_Init(ARM_DRIVER_USART *pDrv, void *pBus, void *pDevInfo, void *spiSlaveParams, uint16_t slaveAddress);
147 
148 /* ===================================================================
149  * @brief Function to send bytes to Host.
150  * @details This function will send a Message to Host over UART.
151  * @param[in] uint8_t *pMsg The handle to the buffer containing the formatted Host message.
152  * @param[in] size_t size The number of bytes to be sent starting form the buffer.
153  * @param[in] uint8_t encoding The encoding format for Host communication (HDLC/JSON etc).
154  * @return None.
155  * @constraints This should be the called only after ::Host_IO_Init() has been called.
156  * @reeentrant No
157  * =================================================================== */
158 void Host_IO_Send(uint8_t *pMsg, size_t size, uint8_t encoding);
159 
160 /* ===================================================================
161  * @brief Function to check Rx and process received bytes and (re)enable UART Rx.
162  * @details This function will check if UART RX is active and if found inactive will enable it.
163  * @param[in] host_cmd_proc_fn_t process_host_command The function to process the user defined payload.
164  * @param[in] uint8_t encoding The encoding format for Host communication (HDLC/JSON etc).
165  * @return void.
166  * @constraints This should be the called only after ::Host_IO_Init() has been called.
167  * @reeentrant No
168  * =================================================================== */
170 
171 #endif // HOST_IO_UART_H_
void Host_IO_Send(uint8_t *pMsg, size_t size, uint8_t encoding)
Definition: host_io_uart.c:136
uint32_t size
void Host_IO_Add_ISO_Header(uint8_t streamID, uint8_t *pStreamingPacket, size_t sizePayload)
Definition: host_io_uart.c:86
This structure holds information to receive a packet of data to the host.
Definition: host_io_uart.h:49
uint8_t * pRxbuf
Definition: host_io_uart.h:53
bool process_host_command(uint8_t tag, uint8_t *hostCommand, uint8_t *hostResponse, size_t *hostMsgSize, size_t respBufferSize)
void Host_IO_Receive(host_cmd_proc_fn_t process_host_command, uint8_t encoding)
Definition: host_io_uart.c:207
This structure holds information regarding the Encoding and RLI interface parameters.
Definition: host_io_uart.h:36
uint8_t Host_IO_Init(ARM_DRIVER_USART *pDrv, void *pBus, void *pDevInfo, void *spiSlaveParams, uint16_t slaveAddress)
Definition: host_io_uart.c:100
void HOST_SignalEvent_t(uint32_t event)
Defines the HOST UART signal event handler.
Definition: host_io_uart.c:47
bool(* host_cmd_proc_fn_t)(uint8_t, uint8_t *, uint8_t *, size_t *, size_t)
The Host Command Process Function ([IN]Command TAG, [IN]Commad Buffer, [OUT]Response Buffer...
Definition: host_io_uart.h:46