AFBR-S50 API Reference Manual v1.5.6
AFBR-S50 Time-of-Flight Sensor SDK for Embedded Software
Loading...
Searching...
No Matches
sci.h
Go to the documentation of this file.
1/*************************************************************************/
38#ifndef SCI_H
39#define SCI_H
40
41/*!***************************************************************************
42 * @defgroup sci SCI: Systems Communication Interface
43 * @ingroup explorer_app
44 *
45 * @brief Systems Communication Interface
46 *
47 * @details The systems communication interface module provides a high
48 * level protocol for information exchange between several systems.
49 * Basically it is a two point interface containing a single master
50 * and a single slave device.
51 *
52 * The protocol is a frame based hardware interface. Each data
53 * frame consists of a dedicate start and stop byte that determines
54 * the bounds of the frame. After the start byte, the first byte is
55 * considered to be the command identifier that specifies the
56 * following data. After that, an arbitrary number of data bytes
57 * can follow. In order to provide the full range per byte, the
58 * start and stop bytes are escaped and inverted by escape bytes.
59 * Thus the data bytes can have any value. Finally, the frame is
60 * finished with an 8-bit CRC value before the stop byte is send.
61 *
62 * Apart from the CRC value, that assures the correct data integrity,
63 * there are acknowledge messages sent from the device in order
64 * to verify the correct receiving and execution of the commands
65 * within the slave system. I.e. every received command will cause
66 * either an acknowledge or an not-acknowledge with a corresponding
67 * status byte that informs the master about the error cause.
68 * On the other hand, the transmitted messages do not have to be
69 * acknowledged by the master.
70 *
71 * @addtogroup sci
72 * @{
73 *****************************************************************************/
74
75#include "sci_status.h"
76#include "sci_frame.h"
77
78/*!***************************************************************************
79 * The SCI command type identifier byte.
80 *****************************************************************************/
81typedef uint8_t sci_cmd_t;
82
83/*!***************************************************************************
84 * The SCI parameter type. An abstract (integer) parameter to be used in the
85 * function.
86 *****************************************************************************/
87typedef uint32_t sci_param_t;
88
89/*!***************************************************************************
90 * The SCI data pointer type. An abstract void pointer to any data object.
91 *****************************************************************************/
92typedef void const * sci_data_t;
93
94/*!***************************************************************************
95 * The SCI device ID type. A value of DEVICEID_DEFAULT will target the
96 * device assigned as default by the ExplorerApp. Any other value >0 up
97 * to a maximum defined by the ExplorerApp is a valid device.
98 *****************************************************************************/
99typedef uint8_t sci_device_t;
100
101/*!***************************************************************************
102 * The Device ID of the default device (usually the first device).
103 *****************************************************************************/
104#define DEVICEID_DEFAULT 0
105
106/*!***************************************************************************
107 * The specific Device ID of the default device (the first device).
108 *****************************************************************************/
109#define DEVICEID_FIRST_VALID 1
110
111/*!***************************************************************************
112 * @brief Received command invocation function definition.
113 *
114 * @details This function pointer represents a command that is invoked whenever
115 * the corresponding data frame has been received via the SCI module.
116 *
117 * @param deviceID The ID (index) of the SPI device that should process
118 * the received frame.
119 * @param frame Pointer to the received data frame.
120 *
121 * @return Returns the \link #status_t status\endlink (#STATUS_OK on success).
122 *****************************************************************************/
123typedef status_t (*sci_rx_cmd_fct_t)(sci_device_t deviceID, sci_frame_t * frame);
124
125/*!***************************************************************************
126 * @brief Transmitting command function definition.
127 *
128 * @details This function pointer represents a command that is invoked whenever
129 * the corresponding data frame will be sent via the SCI module. It
130 * contains a pointer to the data that must serialized into the data
131 * frame structure.
132 *
133 * @param deviceID The ID (index) of the SPI device that should process
134 * the received frame.
135 * @param frame Pointer to the data frame that will be transmitted.
136 * @param param An optional abstract parameter to be used in the command
137 * function.
138 * @param data An optional abstract pointer to the data to be serialize.
139 * The pointer van be null.
140 *
141 * @return Returns the \link #status_t status\endlink (#STATUS_OK on success).
142 *****************************************************************************/
144 sci_param_t param, sci_data_t data);
145
146/*!***************************************************************************
147 * @brief Callback function type for received SCI data frames.
148 *
149 * @param frame Pointer to the received data frame.
150 *
151 * @return Returns the \link #status_t status\endlink (#STATUS_OK on success).
152 *****************************************************************************/
154
155/*!***************************************************************************
156 * @brief Callback function type for SCI error.
157 *
158 * @param status The corresponding error code.
159 *****************************************************************************/
161
162/*!***************************************************************************
163 * @brief Initialize the SCI module.
164 *
165 * @return Returns the \link #status_t status\endlink (#STATUS_OK on success).
166 *****************************************************************************/
167status_t SCI_Init(void);
168
169/*!***************************************************************************
170 * @brief Installs a callback routine for command received event.
171 *
172 * @details Installs a callback function that will be called after a command
173 * has been received successfully. This call is determined to inform
174 * about an new Rx data frame has been received and the corresponding
175 * command shall be invoked. Thus, after the callback, invoke the
176 * #SCI_InvokeRxCommand() function.
177 *
178 * If no callback is set, the commands are invoked directly from the
179 * interrupt services routine. Therefore, it is highly recommended to
180 * install a callback and invoke the commands from the main thread/task.
181 *
182 * @warning The callback function is called from the interrupt service routine
183 * and should return within an appropriate time!
184 *
185 * @param cb The callback functions to be called
186 *****************************************************************************/
188
189/*!***************************************************************************
190 * @brief Removes the previously installed callback function.
191 *****************************************************************************/
193
194/*!***************************************************************************
195 * @brief Installs a callback routine for the error event.
196 *
197 * @details Installs a callback function that will be called after an error
198 * has occurred.
199 *
200 * @warning The callback function is called from the interrupt service routine
201 * and should return within an appropriate time!
202 *
203 * @param cb The callback functions to be called
204 *****************************************************************************/
206
207/*!***************************************************************************
208 * @brief Removes the previously installed callback function.
209 *****************************************************************************/
210void SCI_RemoveErrorCallback(void);
211
212/*!***************************************************************************
213 * @brief Sends a command via the SCI module.
214 *
215 * @details The corresponding command function will be called in order to
216 * serialize the data from into a data frame. The frame is sent
217 * afterwards.
218 *
219 * @param deviceID deviceID to which this frame belongs to.
220 * @param cmd The command code / keyword.
221 * @param param An optional abstract parameter to be used in the command
222 * function.
223 * @param data An optional abstract pointer to the data to be serialize.
224 * The pointer can be null.
225 *
226 * @return Returns the \link #status_t status\endlink (#STATUS_OK on success).
227 *****************************************************************************/
229
230/*!***************************************************************************
231 * @brief Sets a Rx command function in the list of available commands.
232 *
233 * @details Registers the command code to the SCI module. If already set, the
234 * corresponding Rx function is replaced by the specified one. The Tx
235 * function will not be changed.
236 *
237 * @param cmd The command code / keyword.
238 * @param fct The function to be called when a command is received.
239 *
240 * @return Returns the \link #status_t status\endlink (#STATUS_OK on success).
241 *****************************************************************************/
243
244/*!***************************************************************************
245 * @brief Sets Rx and post Rx command functions in the list of available commands.
246 *
247 * @details Registers the command code to the SCI module. If already set, the
248 * corresponding Rx function is replaced by the specified one. The Tx
249 * function will not be changed.
250 *
251 * An optional post RX function can be passed that will be called
252 * after the RX command has finished. This is after the ACK has been
253 * sent and the TX line has become idle. Note that this might block
254 * the MCU for some time.
255 *
256 * @param cmd The command code / keyword.
257 * @param rxfct The function to be called when a command is received.
258 * @param pfct The function to be called when a command is received but after
259 * the ACK/NAK has been invoked.
260 *
261 * @return Returns the \link #status_t status\endlink (#STATUS_OK on success).
262 *****************************************************************************/
264
265/*!***************************************************************************
266 * @brief Sets a Tx command function in the list of available commands.
267 *
268 * @details Registers the command code to the SCIs module. If already set, the
269 * corresponding Tx function is replaced by the specified one. The Rx
270 * function will not be changed.
271 *
272 * @param cmd The command code / keyword.
273 * @param txfct The function to be called when a command is sent.
274 *
275 * @return Returns the \link #status_t status\endlink (#STATUS_OK on success).
276 *****************************************************************************/
278
279/*!***************************************************************************
280 * @brief Sets the Rx and Tx command functions in the list of available commands.
281 *
282 * @details Registers the command code to the SCI module. If already set, the
283 * corresponding Tx and Rx functions are replaced by the specified ones.
284 *
285 * @param cmd The command code / keyword.
286 * @param rxfct The function to be called when a command is received.
287 * @param txfct The function to be called when a command is sent.
288 *
289 * @return Returns the \link #status_t status\endlink (#STATUS_OK on success).
290 *****************************************************************************/
292
293/*!***************************************************************************
294 * @brief Sets the Rx and Tx command functions in the list of available commands.
295 *
296 * @details Registers the command code to the SCI module. If already set, the
297 * corresponding Tx and Rx functions are replaced by the specified ones.
298 *
299 * An optional post RX function can be passed that will be called
300 * after the RX command has finished. This is after the ACK has been
301 * sent and the TX line has become idle. Note that this might block
302 * the MCU for some time.
303 *
304 * @param cmd The command code / keyword.
305 * @param rxfct The function to be called when a command is received.
306 * @param txfct The function to be called when a command is sent.
307 * @param pfct The function to be called when a command is received but
308 * after the ACK/NAK has been invoked.
309 *
310 * @return Returns the \link #status_t status\endlink (#STATUS_OK on success).
311 *****************************************************************************/
314
315/*!***************************************************************************
316 * @brief Unsets a command from the list of available commands.
317 *
318 * @details Removes the command code from the SCI module, i.e. it deletes the
319 * corresponding Tx and Rx functions. If not set, the function returns
320 * with #ERROR_SCI_UNKNOWN_COMMAND.
321 *
322 * @param cmd The command code / keyword.
323 *
324 * @return Returns the \link #status_t status\endlink (#STATUS_OK on success).
325 *****************************************************************************/
327
328/*!***************************************************************************
329 * @brief Invokes the previously received user command.
330 *
331 * @details Parses and executes the previously received command. To be called
332 * after Command Received Handler has been invoked.
333 *
334 * @param frame The previously received SCI frame (parameter of
335 * "RxFrameCallback") with the command code and parameter
336 * buffer.
337 *
338 * @return Returns the \link #status_t status\endlink (#STATUS_OK on success).
339 *****************************************************************************/
341
343#endif // SCI_H
int32_t status_t
Type used for all status and error return values.
Definition argus_status.h:70
static status_t status
Definition argus_xtalk_cal_cli.c:140
uint8_t sci_device_t
Definition sci.h:99
status_t(* sci_rx_cmd_fct_t)(sci_device_t deviceID, sci_frame_t *frame)
Received command invocation function definition.
Definition sci.h:123
status_t SCI_SetRxTxCommand(sci_cmd_t cmd, sci_rx_cmd_fct_t rxfct, sci_tx_cmd_fct_t txfct)
Sets the Rx and Tx command functions in the list of available commands.
Definition sci.c:157
status_t SCI_UnsetCommand(sci_cmd_t cmd)
Unsets a command from the list of available commands.
Definition sci.c:188
status_t SCI_Init(void)
Initialize the SCI module.
Definition sci.c:108
status_t SCI_SetRxCommand(sci_cmd_t cmd, sci_rx_cmd_fct_t fct)
Sets a Rx command function in the list of available commands.
Definition sci.c:145
uint32_t sci_param_t
Definition sci.h:87
status_t(* sci_rx_cmd_cb_t)(sci_frame_t *frame)
Callback function type for received SCI data frames.
Definition sci.h:153
void(* sci_error_cb_t)(status_t status)
Callback function type for SCI error.
Definition sci.h:160
status_t SCI_SetCommand(sci_cmd_t cmd, sci_rx_cmd_fct_t rxfct, sci_tx_cmd_fct_t txfct, sci_rx_cmd_fct_t pfct)
Sets the Rx and Tx command functions in the list of available commands.
Definition sci.c:163
status_t SCI_SendCommand(sci_device_t deviceID, sci_cmd_t cmd, sci_param_t param, sci_data_t data)
Sends a command via the SCI module.
Definition sci.c:324
status_t SCI_InvokeRxCommand(sci_frame_t *frame)
Invokes the previously received user command.
Definition sci.c:205
status_t SCI_SetTxCommand(sci_cmd_t cmd, sci_tx_cmd_fct_t txfct)
Sets a Tx command function in the list of available commands.
Definition sci.c:153
status_t SCI_SetPostRxCommand(sci_cmd_t cmd, sci_rx_cmd_fct_t rxfct, sci_rx_cmd_fct_t pfct)
Sets Rx and post Rx command functions in the list of available commands.
Definition sci.c:149
void SCI_RemoveRxCommandCallback(void)
Removes the previously installed callback function.
Definition sci.c:132
void SCI_RemoveErrorCallback(void)
Removes the previously installed callback function.
Definition sci.c:140
void SCI_SetRxCommandCallback(sci_rx_cmd_cb_t cb)
Installs a callback routine for command received event.
Definition sci.c:128
status_t(* sci_tx_cmd_fct_t)(sci_device_t deviceID, sci_frame_t *frame, sci_param_t param, sci_data_t data)
Transmitting command function definition.
Definition sci.h:143
uint8_t sci_cmd_t
Definition sci.h:81
void SCI_SetErrorCallback(sci_error_cb_t cb)
Installs a callback routine for the error event.
Definition sci.c:136
void const * sci_data_t
Definition sci.h:92
SCI Data Frame Interface.
This file is part of the AFBR-S50 Explorer Application.
Data buffer for outgoing frames.
Definition sci_internal_types.h:110