ISSDK  1.7
IoT Sensing Software Development Kit
host_io_uart.h
Go to the documentation of this file.
1 /*
2  * The Clear BSD License
3  * Copyright (c) 2016, Freescale Semiconductor, Inc.
4  * Copyright 2016-2017 NXP
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without modification,
8  * are permitted (subject to the limitations in the disclaimer below) provided
9  * that the following conditions are met:
10  *
11  * o Redistributions of source code must retain the above copyright notice, this list
12  * of conditions and the following disclaimer.
13  *
14  * o Redistributions in binary form must reproduce the above copyright notice, this
15  * list of conditions and the following disclaimer in the documentation and/or
16  * other materials provided with the distribution.
17  *
18  * o Neither the name of the copyright holder nor the names of its
19  * contributors may be used to endorse or promote products derived from this
20  * software without specific prior written permission.
21  *
22  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
27  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
30  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 /**
36  * @file host_io_uart.h
37  * @brief The host_io_uart.h file contains the Host Protocol interface definitions and configuration.
38  */
39 
40 #ifndef HOST_IO_UART_H_
41 #define HOST_IO_UART_H_
42 
43 /*******************************************************************************
44  * CMSIS Includes
45  ******************************************************************************/
46 #include "Driver_USART.h"
47 
48 /*******************************************************************************
49  * Types and Definitions
50  ******************************************************************************/
51 #define STREAMING_HEADER_LEN (4) /* ISSDK Host Protocol defined Iso Cmd Header Length + Stream ID. */
52 #define HOST_RX_BUF_LEN (64) /* MAX size of Rx Host CMDs. */
53 #define HOST_RSP_HDR_LEN (4) /* Size of Host response message header. */
54 #define HOST_DEV_RSP_LEN (128) /* MAX size of Host Dev Info Response. */
55 #define HOST_CMD_RSP_LEN (64) /* MAX size of Host Command Response. */
56 #define MAX_HOST_STREAMS (4) /* Max Streams that can be defined by the user Application. */
57 #define HOST_CMD_RESP_ACK (0x80) /* HOST CMD Ack code. */
58 #define HOST_CMD_RESP_NACK (0xC6) /* HOST CMD Nack code. */
59 #define EVENT_STREAM_ID (0xFF) /* Stream ID in ISO Message for posting Events (such as freefall) */
60 
61 /*! @brief This structure holds information regarding the Encoding and RLI interface parameters. */
62 typedef struct
63 {
64  void *deviceInfo;
65  void *pCommDrv;
66  void *pSPIparams;
67  uint16_t slaveAddress;
69 
70 /*! @brief The Host Command Process Function ([IN]Command TAG, [IN]Commad Buffer, [OUT]Response Buffer,
71  * [IN/OUT]MessageSize, [IN]BufferSize) */
72 typedef bool (*host_cmd_proc_fn_t)(uint8_t, uint8_t *, uint8_t *, size_t *, size_t);
73 
74 /*! @brief This structure holds information to receive a packet of data to the host. */
75 typedef struct
76 {
77  uint8_t rxState; /* Internal receive state */
78  uint8_t mIndex; /* Message index */
79  uint8_t *pRxbuf; /* Receive buffer */
81 
82 /*! @brief Bit aligned values for Host Protocol Interface IDs (Bits 5-6). */
83 #define HOST_PRO_INT_CMD_TAG (0x20) /* 1 */
84 #define HOST_PRO_INT_ISO_TAG (0x40) /* 2 */
85 #define HOST_PRO_INT_DEV_TAG (0x60) /* 3 */
86 
87 /*! @brief Bit aligned values for Host Protocol Command Interface Type IDs (Bits 0-4). */
88 #define HOST_PRO_CMD_X_RES_TAG (0x00) /* 0 (Reserved) */
89 #define HOST_PRO_CMD_W_CFG_TAG (0x01) /* 1 */
90 #define HOST_PRO_CMD_R_CFG_TAG (0x02) /* 2 */
91 #define HOST_PRO_CMD_W_REG_TAG (0x03) /* 3 */
92 #define HOST_PRO_CMD_R_REG_TAG (0x04) /* 4 */
93 
94 /*! @brief Bit aligned values for Host Protocol Command Interface Status IDs (Bit 7). */
95 #define HOST_PRO_CMD_WR_NAK_TAG (0x7F) /* 0 */
96 #define HOST_PRO_CMD_WR_ACK_TAG (0x80) /* 1 */
97 
98 enum
99 {
103 };
104 
105 enum
106 {
122 };
123 
124 /*! @brief This enum lists the Configuration Command Operation Codes. */
125 enum
126 {
127  HOST_CMD_NOP = 0, /* 0 (No Operation) */
128  HOST_CMD_START, /* 1 (Start Streaming) */
129  HOST_CMD_STOP, /* 2 (Stop Streaming) */
130  HOST_CMD_FLASH_START, /* 3 (Enter FLASH Mode) */
131  HOST_CMD_FLASH_BYTES, /* 4 (Bytes to FLASH) */
132  HOST_CMD_FLASH_STOP, /* 5 (Exit FLASH Mode) */
133 };
134 
135 /*! @brief Defines the HOST UART signal event handler.
136  * @details The Signal Event Handler function required by host_io_uart.c.
137  * @param[in] event The UART event that occured.
138  * @Constraints None
139  * @Reentrant Yes
140  * @return void
141  */
142 void HOST_SignalEvent_t(uint32_t event);
143 
144 /*******************************************************************************
145  * APIs
146  ******************************************************************************/
147 /* ===================================================================
148  * @brief Function populate Streaming Packet Header.
149  * @details This function sets up streaming related parameters in the ISO Message Header.
150  * @param[in] uint8_t streamID The stream ID this packet corresponds.
151  * @param[in] uint8_t *streamingPacket The handle to the buffer containing the streaming packet.
152  * @param[in] size_t sizePayload The size of the actual payload excluding the Header.
153  * @return None
154  * @constraints This should be the called only after DEBUG Port has been initialized.
155  * @reeentrant No
156  * =================================================================== */
157 void Host_IO_Add_ISO_Header(uint8_t streamID, uint8_t *pStreamingPacket, size_t sizePayload);
158 
159 /* ===================================================================
160  * @brief Function to get Stream ID, set Encoding and configure RLI related parameters.
161  * Stream IDs are allocated incrementally everytime this API is called to for a new Stream.
162  * It also configures UART for receiving RLI messages form Host.
163  * @param[in] ARM_DRIVER_USART *pDrv Pointer to the UART communication bus.
164  * @param[in] void *pBus Pointer to the I2C/SPI communication bus for register read/write support.
165  * @param[in] void *pDevInfo Pointer to the I2C/SPI device info structure.
166  * @param[in] void *spiSlaveParams (Only for SPI) The handle to the structure containing SPI Slave parameters.
167  * @param[in] uint16_t slaveAddress The Sensor's I2C Slave Address to identify the slave (required for both I2C/SPI).
168  * @return uint8_t The unique ID for this stream.
169  * @constraints This should be the called only after DEBUG Port has been initialized.
170  * @reeentrant No
171  * =================================================================== */
172 uint8_t Host_IO_Init(ARM_DRIVER_USART *pDrv, void *pBus, void *pDevInfo, void *spiSlaveParams, uint16_t slaveAddress);
173 
174 /* ===================================================================
175  * @brief Function to send bytes to Host.
176  * @details This function will send a Message to Host over UART.
177  * @param[in] uint8_t *pMsg The handle to the buffer containing the formatted Host message.
178  * @param[in] size_t size The number of bytes to be sent starting form the buffer.
179  * @param[in] uint8_t encoding The encoding format for Host communication (HDLC/JSON etc).
180  * @return None.
181  * @constraints This should be the called only after ::Host_IO_Init() has been called.
182  * @reeentrant No
183  * =================================================================== */
184 void Host_IO_Send(uint8_t *pMsg, size_t size, uint8_t encoding);
185 
186 /* ===================================================================
187  * @brief Function to check Rx and process received bytes and (re)enable UART Rx.
188  * @details This function will check if UART RX is active and if found inactive will enable it.
189  * @param[in] host_cmd_proc_fn_t process_host_command The function to process the user defined payload.
190  * @param[in] uint8_t encoding The encoding format for Host communication (HDLC/JSON etc).
191  * @return void.
192  * @constraints This should be the called only after ::Host_IO_Init() has been called.
193  * @reeentrant No
194  * =================================================================== */
196 
197 #endif // HOST_IO_UART_H_
This structure holds information regarding the Encoding and RLI interface parameters.
Definition: host_io_uart.h:62
uint8_t Host_IO_Init(ARM_DRIVER_USART *pDrv, void *pBus, void *pDevInfo, void *spiSlaveParams, uint16_t slaveAddress)
Definition: host_io_uart.c:126
void Host_IO_Send(uint8_t *pMsg, size_t size, uint8_t encoding)
Definition: host_io_uart.c:162
bool process_host_command(uint8_t tag, uint8_t *hostCommand, uint8_t *hostResponse, size_t *hostMsgSize, size_t respBufferSize)
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:72
This structure holds information to receive a packet of data to the host.
Definition: host_io_uart.h:75
uint32_t size
void Host_IO_Add_ISO_Header(uint8_t streamID, uint8_t *pStreamingPacket, size_t sizePayload)
Definition: host_io_uart.c:112
void HOST_SignalEvent_t(uint32_t event)
Defines the HOST UART signal event handler.
Definition: host_io_uart.c:73
uint8_t * pRxbuf
Definition: host_io_uart.h:79
void Host_IO_Receive(host_cmd_proc_fn_t process_host_command, uint8_t encoding)
Definition: host_io_uart.c:233