AFBR-S50 API Reference Manual v1.5.6
AFBR-S50 Time-of-Flight Sensor SDK for Embedded Software
Loading...
Searching...
No Matches
sci_datalink.h
Go to the documentation of this file.
1/*************************************************************************/
38#ifndef SCI_DATALINK_H
39#define SCI_DATALINK_H
40
41/*!***************************************************************************
42 * @defgroup sci_datalink SCI: Data Link Layer
43 * @ingroup sci
44 * @brief SCI Data Link Layer
45 * @details Implements the data link layer protocol for systems communication
46 * interface that connects to an external device. It takes care of
47 * sending and receiving data frames and thus byte stuffing and
48 * CRC check.
49 *
50 * Remarks:
51 * - Transmitting frames:
52 * - Two buffers: one for preparing data, one for sending
53 * at the same time.
54 * - If UART TX Line is still busy when trying to send new
55 * data, the program is delayed until TX is idle.
56 * .
57 * - Receiving frames:
58 * - Special frame buffers collect data from RX (w/o
59 * escape bytes)
60 * - Only data between START and STOP is collected.
61 * - After STOP was received, the FrameReceivedCallback
62 * is invoked.
63 * .
64 *
65 * @addtogroup sci_datalink
66 * @{
67 *****************************************************************************/
68
69#include "sci_status.h"
70#include "sci_internal_types.h"
71
72/*!***************************************************************************
73 * @brief Whether to allow newline (\n) in print / log messages.
74 *****************************************************************************/
75#define SCI_ALLOW_NEWLINE 1
76
77/*!***************************************************************************
78 * @brief Checks whether the command byte is an extended command (= MSB set).
79 *****************************************************************************/
80#define SCI_CMD_IS_EXTENDED_CMD(cmd) ((cmd) & 0x80)
81
82/*!***************************************************************************
83 * @brief Initialize the data link module.
84 * @details Initialization implies the following steps:
85 * - Initialization of the SCI Hardware Layer, i.e. UART/LPSCI.
86 * - Starts to listen to incoming UART data and calls the frame
87 * received callback.
88 * - Initialization of the CRC module.
89 *
90 * @return Returns the \link #status_t status\endlink (#STATUS_OK on success).
91 *****************************************************************************/
93
94/*!***************************************************************************
95 * @brief Checks the CRC checksum for a RX frame.
96 * @param frame The RX frame which requires CRC checking.
97 * @return Returns the \link #status_t status\endlink:
98 * - #STATUS_OK (0) on success.
99 * - #ERROR_SCI_CRC_FAILED if the CRC failed.
100 *****************************************************************************/
102
103/*!***************************************************************************
104 * @brief Releases the frame queue.
105 * @param frame The frame queue to be released.
106 *****************************************************************************/
108
109/*!***************************************************************************
110 * @brief Resets the frame read pointer to the very first byte (= command byte).
111 * @param frame The frame queue to reset.
112 *****************************************************************************/
114
115/*!***************************************************************************
116 * @brief Returns whether the TX line is currently busy and data is being sent.
117 * @return Returns true if the TX line is busy sending data.
118 *****************************************************************************/
119bool SCI_DataLink_IsTxBusy(void);
120
121/*!***************************************************************************
122 * @brief Trigger the data transfer and releases the TX buffers.
123 * @details Before the frame is transferred, a stop byte is added to the end
124 * of the data buffer.
125 * @param frame The frame to be sent.
126 * @param high_priority If set, the frame is queued right after the current
127 * frame. If not set, the frame is queued at the very
128 * end of the frame queue.
129 * @return Returns the \link #status_t status\endlink (#STATUS_OK on success).
130 *****************************************************************************/
131status_t SCI_DataLink_SendTxFrame(sci_frame_t * frame, bool high_priority);
132
133/*!***************************************************************************
134 * @brief Find an unused TX buffer from the queue and prepare it with a start
135 * byte.
136 * @details If sending data over the SCI, an new and empty TX frame needs to be
137 * claimed for usage of the command. This functions finds one and
138 * prepares it with an start byte. A pointer to the frame is returned
139 * if one is found. Otherwise null, so checking for null pointer is
140 * recommended!
141 * @param queueStartByte Whether to queue a start byte into the buffer.
142 * @return Returns a pointer to an free TX frame, zero if no one is currently
143 * available.
144 *****************************************************************************/
145sci_frame_t * SCI_DataLink_RequestTxFrame(bool queueStartByte);
146
148#endif /* SCI_DATALINK_H */
int32_t status_t
Type used for all status and error return values.
Definition argus_status.h:70
SCI: The internal type definitions.
This file is part of the AFBR-S50 Explorer Application.
Data buffer for outgoing frames.
Definition sci_internal_types.h:110