AFBR-S50 API Reference Manual v1.5.6
AFBR-S50 Time-of-Flight Sensor SDK for Embedded Software
Loading...
Searching...
No Matches
sci_datalink.c File Reference
#include "sci_cmd.h"
#include "sci_datalink.h"
#include "sci_byte_stuffing.h"
#include "sci_crc8.h"
#include "sci_handshaking.h"
#include "driver/irq.h"
#include "debug.h"
#include "driver/uart.h"
#include <stddef.h>
#include <assert.h>
#include "utility/time.h"
Include dependency graph for sci_datalink.c:

Macros

#define AFBR_SCI_USB   0
 SCI Layer 2: Data Link and Data Frame Module.
 

Functions

static void RaiseError (status_t error)
 
static void RxCallback (uint8_t const *data, uint32_t size)
 
static void TxCallback (status_t status, sci_frame_t *frame)
 
static sci_frame_tSCI_DataLink_RequestFrame (sci_frame_queue_t *queue)
 
static status_t SCI_DataLink_SendFrame (sci_frame_t *frame)
 
static void SCI_DataLink_ReleaseFrame (sci_frame_t *frame)
 
static uint8_t SCI_DataLink_GetCRC (sci_frame_t const *frame)
 
static uint8_t SCI_DataLink_CalcCRC (sci_frame_t const *frame)
 
static void SCI_Frame_QueueCRC (sci_frame_t *frame)
 Inserts a checksum into the Tx frame;.
 
status_t SCI_DataLink_Init (void)
 Initialize the data link module.
 
status_t SCI_DataLink_CheckRxFrame (sci_frame_t *frame)
 Checks the CRC checksum for a RX frame.
 
void SCI_DataLink_ReleaseFrames (sci_frame_t *frame)
 Releases the frame queue.
 
void SCI_DataLink_ResetRxFrames (sci_frame_t *frame)
 Resets the frame read pointer to the very first byte (= command byte).
 
sci_frame_tSCI_DataLink_RequestTxFrame (bool queueStartByte)
 Find an unused TX buffer from the queue and prepare it with a start byte.
 
bool SCI_DataLink_IsTxBusy (void)
 Returns whether the TX line is currently busy and data is being sent.
 
status_t SCI_DataLink_SendTxFrame (sci_frame_t *frame, bool high_priority)
 Trigger the data transfer and releases the TX buffers.
 

Variables

static uint8_t SCI_DataBuffer [SCI_FRAME_SIZE *SCI_FRAME_BUF_CT] = { 0 }
 
static sci_frame_t SCI_FrameBuffer [SCI_FRAME_BUF_CT]
 
static sci_frame_queue_t SCI_RxFrameQueue
 
static sci_frame_queue_t SCI_TxFrameQueue
 
sci_rx_cmd_cb_t SCI_RxCallback = 0
 
sci_error_cb_t SCI_ErrorCallback = 0
 
static volatile sci_frame_tSCI_CurrentTxFrame = 0
 

Macro Definition Documentation

◆ AFBR_SCI_USB

#define AFBR_SCI_USB   0

SCI Layer 2: Data Link and Data Frame Module.

This file provides a data link layer for the systems communication interface. It also contains the implementation of the data frame interface.

Copyright (c) 2023, Broadcom Inc. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Preprocessor flag to choose between USB and non-USB (UART) connection.

Function Documentation

◆ RaiseError()

static void RaiseError ( status_t  error)
inlinestatic

◆ RxCallback()

static void RxCallback ( uint8_t const *  data,
uint32_t  size 
)
static

< Flag for byte stuffing

< the current buffer in the queue.

< the first buffer in the queue.

◆ SCI_DataLink_CalcCRC()

static uint8_t SCI_DataLink_CalcCRC ( sci_frame_t const *  frame)
static

◆ SCI_DataLink_GetCRC()

static uint8_t SCI_DataLink_GetCRC ( sci_frame_t const *  frame)
static

◆ SCI_DataLink_ReleaseFrame()

static void SCI_DataLink_ReleaseFrame ( sci_frame_t frame)
inlinestatic

◆ SCI_DataLink_RequestFrame()

static sci_frame_t * SCI_DataLink_RequestFrame ( sci_frame_queue_t queue)
static

◆ SCI_DataLink_SendFrame()

static status_t SCI_DataLink_SendFrame ( sci_frame_t frame)
inlinestatic

◆ SCI_Frame_QueueCRC()

static void SCI_Frame_QueueCRC ( sci_frame_t frame)
static

Inserts a checksum into the Tx frame;.


Given a Tx frame with data filled, this function calculates and appends the CRC to the frame buffer. It assumes that the first byte in the TX buffer is start byte which is usually ensured by the SCI_DataLink_RequestTxFrame function.

Parameters
frameThe frame for which a checksum is calculated.

◆ TxCallback()

static void TxCallback ( status_t  status,
sci_frame_t frame 
)
static

Variable Documentation

◆ SCI_CurrentTxFrame

volatile sci_frame_t* SCI_CurrentTxFrame = 0
static

A pointer to the frame that is currently sent. It is used to enqueue more frames if the UART is busy.

◆ SCI_DataBuffer

uint8_t SCI_DataBuffer[SCI_FRAME_SIZE *SCI_FRAME_BUF_CT] = { 0 }
static

The data buffer for rx and tx frames.

◆ SCI_ErrorCallback

sci_error_cb_t SCI_ErrorCallback = 0

Callback function pointer for error event.

◆ SCI_FrameBuffer

sci_frame_t SCI_FrameBuffer[SCI_FRAME_BUF_CT]
static

The frame buffer for rx and tx frames.

◆ SCI_RxCallback

sci_rx_cmd_cb_t SCI_RxCallback = 0

Callback function pointer for received frame event.

◆ SCI_RxFrameQueue

sci_frame_queue_t SCI_RxFrameQueue
static

The data frame queue for rx frames.

◆ SCI_TxFrameQueue

sci_frame_queue_t SCI_TxFrameQueue
static

The data frame queue for tx frames.