RA Flexible Software Package Documentation
Release v5.6.0
|
|
Driver for the SCI peripheral on RA MCUs. This module implements the LIN Interface.
The Simple LIN on SCI_B HAL module supports Local Interface Network (LIN) transactions in master or slave mode. A callback must be provided, and is invoked when a transmission, reception, or other event has completed or occurred. The callback arguments contain information about the transaction status, bytes transferred and a pointer to the user defined context.
Configuration | Options | Default | Description |
---|---|---|---|
Parameter Checking |
| Default (BSP) | If selected code for parameter checking is included in the build. |
Checksum Support |
| Enabled | When set to 'Disabled', code for checksum generation and validation is excluded from the build. This setting is applied globally to the project. Disable only when checksum generation and validation is not required for any LIN instance. |
Auto Synchronization Support |
| Disabled | When set to 'Disabled', code for auto synchronization is excluded from the build. This setting is applied globally to the project. Enable when at least one LIN slave instance is using auto synchronization. |
Configuration | Options | Default | Description |
---|---|---|---|
General | |||
Name | Name must be a valid C symbol | g_lin0 | Module name. |
Channel | MCU Specific Options | Select the LIN channel. | |
Mode |
| Master | Select the LIN operating mode (master or slave). |
Extra | |||
Clock Source | MCU Specific Options | Select whether the peripheral clock (PCLK) or SCICLK/SCISPICLK is used as the baud rate generator. | |
Noise Filter |
| Disable | Enable the digital noise filter on RXDn pin. The digital noise filter block in SCI consists of two-stage flipflop circuits. |
Bus Conflict Detection |
| Disable | Enable the bus conflict detection function. When enabled, the TXDn pin output and the RXDn pin input are sampled by the bus conflict detection clock set by Extra|Bus Conflict Clock Divider. This function only works during transmission. |
Bus Conflict Clock Divider |
| 2 | Select the base clock divider for the sampling clock of the bus conflict detection circuit. |
Baud | |||
Baud Rate | Value must be an integer greater than 0 | 19200 | Enter the desired baud rate. If the requested baud rate cannot be achieved, the settings with the smallest percent error are used. The theoretical calculated baud rate and percent error are printed in a comment in the generated sci_b_lin_extended_cfg_t structure. |
Auto Synchronization |
| Disable | Enable LIN synchronization to the master's clock by measuring the effective edges of the input signal from the RXDn pin during reception of the sync byte. |
Framing | |||
Framing > ID Filter (Slave Mode) | |||
Compare Data Mask | Value must be an integer between 0 and 255. | 0 | Select the bit mask to be applied before comparing the received PID to the selected compare data. This setting specifies which bits of the selected compare data must match. Set to 0 to disable the filter (allow all frame identifiers). |
Priority Compare Data | Value must be an integer between 0 and 255. | 0 | Select the priority compare filter data. |
Secondary Compare Data | Value must be an integer between 0 and 255. | 0 | Select the secondary compare filter data. |
Compare Data Select |
| Priority | Select the compare data to use. If 'both' is selected, the priority compare data is checked before the secondary compare data. |
Priority Interrupt Bit Enable |
| Disabled | Select whether to enable the Priority Interrupt Bit filter. When enabled, regardless of the Filter Data Select setting value, the bit specified by the Priority Interrupt Bit setting is compared with the corresponding bit in the Priority Compare Data Filter and if it matches, the identifier is allowed through the filter. |
Priority Interrupt Bit | Value must be an integer between bit 0 (LSb) and bit 7 (MSb). | 0 | Select the priority interrupt bit (0-7) of the received PID to compare with the corresponding bit in the Priority Compare Data Filter. |
Break Field Bits/Break Detection Threshold (bits) | Value must be an integer. | 13 | For master break field transmission, this configures the dominant period of the break field (in bits). For slave break field reception, this configures the break detection threshold in bits. Must be 13 bits or greater for master mode and 11 bits or greater for slave mode. |
LIN Timer Divider |
| 4 | Set the LIN timer divider. The LIN timer is used for break field transmission and detection. Higher dividers make possible transmission/detection of more break field bits, but are less precise. |
Break Field Delimiter/Stop Bits |
| 1bit | Select the recessive period (in bits) of the break field. This setting also selects the number of stop bits. |
Interrupts | |||
Callback | Name must be a valid C symbol | sci_b_lin0_callback | A user callback function must be provided. It will be called from the interrupt service routine (ISR). |
Receive Interrupt Priority | MCU Specific Options | Select the receive interrupt priority. | |
Transmit Data Empty Interrupt Priority | MCU Specific Options | Select the transmit interrupt priority. | |
Transmit End Interrupt Priority | MCU Specific Options | Select the transmit end interrupt priority. | |
Error Interrupt Priority | MCU Specific Options | Select the error interrupt priority. | |
Break Field Detection Interrupt Priority | MCU Specific Options | Select the break field detection interrupt priority (slave mode only). | |
Active Edge Detection Interrupt Priority | MCU Specific Options | Select the active edge detection interrupt priority. |
The clock for this module is derived from the following peripheral clock for each MCU group:
MCU Group | Peripheral Clock |
---|---|
RA6T2 | SCISPICLK |
RA8D1 | SCICLK |
RA8E1 | SCICLK |
RA8M1 | SCICLK |
RA8T1 | SCICLK |
The clock source for the baud-rate clock generator can be selected from either SCISCPI/SCICLK or the peripheral clock (PCLK).
This module uses TXD and RXD to communicate to external devices. Connect TXD and RXD to an on-board or external LIN transceiver for LIN bus communication.
An external pull up resistor is required on TXD in both master and slave mode.
When Bus Conflict Detection is enabled, the TXDn pin output and the RXDn pin input are sampled by the selected bus conflict detection clock. When a mismatch occurs three times in a row, an SCIn_ERI interrupt is generated and transmission is stopped. This function only works during transmission.
Consideration of the specific application's LIN bus characteristics should be taken into account when enabling this function. If the bus collision sampling clock is too fast, the expected propagation delay through the transceiver may be erroneously detected as a bus collision (false positive). If the bus collision sampling clock is too slow, collisions may be missed (false negative).
When CCR2.ABCS = 1, setting the bus conflict clock divider to 4 is is prohibited by the SCI_B hardware.
A LIN transceiver is required to detect bus collisions.
The SCI performs optional hardware PID filtering in slave mode. When enabled, only start frames with PIDs that pass through the filter are received and passed to the user callback. Other start frames are ignored.
An initial configuration of the filter settings can be applied in the properties view by selecting Framing -> ID Filter and choosing the desired settings. See sci_b_lin_id_filter_setting_t for the available filter settings, as well as the examples in this document. By default, filtering is disabled and all PIDs can be received.
The filter can be updated at runtime by using using R_SCI_B_LIN_IdFilterSet. The current filter settings can be viewed with R_SCI_B_LIN_IdFilterGet.
SCI data reception is disabled until a break field is detected (slave mode) or a call to R_SCI_B_LIN_InformationFrameRead() is made (master and slave mode).
The start frame is detected in slave mode only. Start frame reception is interrupt driven, and is enabled after a successful call to R_SCI_B_LIN_Open() in slave mode.
When the LIN break field is detected by the slave node, start frame reception begins without action from the application. When start frame reception completes, the user callback is called.
If the slave node needs to receive the information frame data, the slave node must call R_SCI_B_LIN_InformationFrameRead() before the first information data is received in order to receive the data. The user callback is called when reception is complete. It is permitted to call R_SCI_B_LIN_InformationFrameRead() from the callback context.
If the slave node needs to publish a response to the start frame, the slave node must call R_SCI_B_LIN_InformationFrameWrite() and provide the response data and the PID of the received header in the lin_transfer_params_t. The user callback is called when transmission is complete.
If the slave node neither needs to receive the information frame data, nor publish a response for a received start frame, no action is required to ignore the frame. Data reception is disabled until a new break field is detected.
The start frame is not detected in master mode. Information frame reception is enabled only after a call to R_SCI_B_LIN_InformationFrameRead().
The start frame is transmitted by calling R_SCI_B_LIN_StartFrameWrite(). The user callback is called when transmission is complete.
If the master node needs to receive the information frame data response, call R_SCI_B_LIN_InformationFrameRead() after start frame transmission has completed and before the first information frame data is received. It is permitted to call R_SCI_B_LIN_InformationFrameRead() from the callback context.
If the master node needs to publish a response to its own start frame, the master node must call R_SCI_B_LIN_InformationFrameWrite() only after start frame transmission has completed, and provide the response data and the PID of the transmitted header in the lin_transfer_params_t. The user callback is called when transmission is complete.
The application is responsible for managing timeouts in case R_SCI_B_LIN_InformationFrameRead() is called, but the data is not received in the expected time period. If a timeout occurs, R_SCI_B_LIN_CommunicationAbort() may be called to cancel a pending read.
When an error occurs, reception is stopped and the user callback is called with the relevant error code.
Auto synchronization is optional. When it is disabled, the baud rate and break field detection threshold set in open are never updated.
This feature works in slave mode only.
The following demonstrates a basic example of frame reception for a LIN master.
The following demonstrates a basic example of frame transmission for a LIN master.
The following demonstrates a basic example of start frame reception and information frame response for a LIN slave.
The following example demonstrates a basic example of frame ID filtering.
The following example demonstrates an advanced example of frame ID filtering.
Data Structures | |
struct | sci_b_lin_timer_setting_t |
struct | sci_b_lin_baud_setting_t |
struct | sci_b_lin_id_filter_setting_t |
struct | sci_b_lin_baud_params_t |
struct | sci_b_lin_extended_cfg_t |
struct sci_b_lin_timer_setting_t |
struct sci_b_lin_baud_setting_t |
Register settings for achieving a desired baud rate.
Data Fields | ||
---|---|---|
union sci_b_lin_baud_setting_t | __unnamed__ | |
sci_b_lin_timer_setting_t | timer_setting | Break field timer settings associated with this baud rate. |
struct sci_b_lin_id_filter_setting_t |
Parameters for configuring the ID filter settings
Data Fields | ||
---|---|---|
uint8_t | compare_data_mask |
Bit mask applied before comparing the received PID to the compare data. Selects which bits of the selected compare data must match. |
uint8_t | priority_compare_data |
Priority/primary compare data |
uint8_t | secondary_compare_data |
Secondary compare data |
uint8_t | priority_interrupt_bit_select: 3 |
Specify ONE of bits 0 to 7 of Control Field 1 as the priority interrupt bit. 0 is bit 0 of the PID, 1 is bit 1 of the PID, and so on. |
uint8_t | priority_interrupt_enable: 1 |
Set to 1 to enable the priority interrupt bit filter specified by priority_interrupt_bit_select, 0 to disable. When this bit is 1, regardless of the compare_data_select setting value, the bit specified by priority_interrupt_bit_select is compared with the priority/primary comparison data for Control Field 1 (priority_compare_data). |
uint8_t | compare_data_select: 2 |
Select the compare data for Control Field 1 (priority, secondary, or both). See sci_b_lin_compare_data_select_t |
uint8_t | __pad0__: 2 |
struct sci_b_lin_baud_params_t |
Parameters for baud and timer setting calculation
Data Fields | ||
---|---|---|
uint32_t | baudrate | Desired baudrate. |
sci_b_lin_clock_source_t | clock_source | Peripheral clock source. |
sci_b_lin_bus_conflict_clock_t | bus_conflict_clock | Bus collision clock divider. |
uint16_t | break_bits | Master mode: Number of break field bits to transmit. Slave mode: Number of break field threshold bits. |
struct sci_b_lin_extended_cfg_t |
SCI B LIN extended configuration
Data Fields | ||
---|---|---|
union sci_b_lin_extended_cfg_t | __unnamed__ | |
sci_b_lin_baud_setting_t | baud_setting | Register settings for a desired baud rate. |
sci_b_lin_id_filter_setting_t | filter_setting | ID filter setting. |
IRQn_Type | bfd_irq | Break field detect IRQ number. |
IRQn_Type | aed_irq | Active edge detect IRQ number. |
uint8_t | bfd_ipl | Break field detect interrupt priority. |
uint8_t | aed_ipl | Active edge detect interrupt priority. |
uint16_t | break_bits | Master mode: Number of break field bits to transmit. Slave mode: Number of break field threshold bits. |
Compare Data Select options for ID filtering.
Bus conflict detection clock selection. Base clock: 1/16 period of 1 bit period when CCR2.ABCS = 0, 1/8 period of 1 bit period when CCR2.ABCS = 1
fsp_err_t R_SCI_B_LIN_Open | ( | lin_ctrl_t *const | p_api_ctrl, |
lin_cfg_t const *const | p_cfg | ||
) |
Configures the LIN driver channel based on the input configuration.
Implements lin_api_t::open.
Example:
FSP_SUCCESS | Channel opened successfully. |
FSP_ERR_ASSERTION | Pointer to LIN control block or configuration structure is NULL. |
FSP_ERR_INVALID_CHANNEL | The requested channel does not exist on this MCU or the channel does not support Simple LIN mode. |
FSP_ERR_INVALID_ARGUMENT | Break field length setting or timer divisor is invalid. |
FSP_ERR_ALREADY_OPEN | Control block has already been opened or channel is being used by another instance. Call close() then open() to reconfigure. |
FSP_ERR_INVALID_MODE | Setting not supported for selected mode |
fsp_err_t R_SCI_B_LIN_StartFrameWrite | ( | lin_ctrl_t *const | p_api_ctrl, |
uint8_t const | id | ||
) |
Begins non-blocking transmission of a LIN start frame (break, sync and protected identifier).
On successful start frame transmission, the callback is called with event lin_event_t::LIN_EVENT_TX_START_FRAME_COMPLETE.
Implements lin_api_t::startFrameWrite.
Example:
FSP_SUCCESS | Start frame transmission started successfully. |
FSP_ERR_ASSERTION | A required pointer is NULL. |
FSP_ERR_NOT_OPEN | The control block has not been opened. |
FSP_ERR_INVALID_ARGUMENT | ID out of range (unprotected ID must be less than 64) |
FSP_ERR_INVALID_MODE | Function called by slave node (not supported for slave nodes) |
FSP_ERR_IN_USE | A transmission or reception is currently in progress. Call R_SCI_B_LIN_CommunicationAbort to cancel it if desired, or wait for the current transfer operation to complete before starting a new one. |
fsp_err_t R_SCI_B_LIN_InformationFrameWrite | ( | lin_ctrl_t *const | p_api_ctrl, |
const lin_transfer_params_t *const | p_transfer_params | ||
) |
Begins non-blocking transmission of a LIN information frame.
On successful information frame transmission, the callback is called with event lin_event_t::LIN_EVENT_TX_INFORMATION_FRAME_COMPLETE.
Implements lin_api_t::informationFrameWrite.
Example:
FSP_SUCCESS | Data transmission started successfully. |
FSP_ERR_NOT_OPEN | The control block has not been opened. |
FSP_ERR_ASSERTION | Pointer to LIN control block, transfer parameters, or tx/rx buffer is NULL, or 0 bytes length provided |
FSP_ERR_IN_USE | A transmission or reception is currently in progress. Call R_SCI_B_LIN_CommunicationAbort to cancel it if desired, or wait for the current transfer operation to complete before starting a new one. |
fsp_err_t R_SCI_B_LIN_InformationFrameRead | ( | lin_ctrl_t *const | p_api_ctrl, |
lin_transfer_params_t *const | p_transfer_params | ||
) |
Begins non-blocking information frame reception to receive user specified number of bytes into destination buffer pointer.
The checksum type specifies the checksum type used for validation. If a non-standard algorithm is used, or the application prefers to validate the checksum outside the driver, or the application prefers to skip checksum validation, specify lin_checksum_type_t::LIN_CHECKSUM_TYPE_NONE. If checksum validation is skipped, the lin_checksum_type_t::LIN_EVENT_ERR_INVALID_CHECKSUM event is not possible. When lin_checksum_type_t::LIN_CHECKSUM_TYPE_NONE is used, the number of bytes specified in the receive buffer length will be received (the driver will not expect to receive an additional 1 checksum byte), so if a non-standard checksum is used, sufficient space must be allocated in the write buffer and accounted for in the provided length.
On successful information frame reception, the callback is called with event lin_event_t::LIN_EVENT_RX_INFORMATION_FRAME_COMPLETE.
Implements lin_api_t::informationFrameRead.
Example:
FSP_SUCCESS | Data reception started successfully. |
FSP_ERR_NOT_OPEN | The control block has not been opened. |
FSP_ERR_ASSERTION | Pointer to LIN control block, transfer parameters, or tx/rx buffer is NULL, or 0 bytes length provided |
FSP_ERR_IN_USE | A transmission or reception is currently in progress. Call R_SCI_B_LIN_CommunicationAbort to cancel it if desired, or wait for the current transfer operation to complete before starting a new one. |
fsp_err_t R_SCI_B_LIN_CommunicationAbort | ( | lin_ctrl_t *const | p_api_ctrl | ) |
Cancels in progress information frame read or write, or start frame read or write. Break field reception cannot be cancelled. For slave nodes, reception of a new start frame reception is still enabled after a call to this function.
Implements lin_api_t::communicationAbort.
FSP_SUCCESS | Data transfer aborted successfully or no transfer was in progress. |
FSP_ERR_NOT_OPEN | The control block has not been opened. |
FSP_ERR_ASSERTION | Pointer to LIN control block is NULL. |
fsp_err_t R_SCI_B_LIN_CallbackSet | ( | lin_ctrl_t *const | p_api_ctrl, |
void(*)(lin_callback_args_t *) | p_callback, | ||
void const *const | p_context, | ||
lin_callback_args_t *const | p_callback_memory | ||
) |
Updates the user callback and has option of providing memory for callback structure.
Implements lin_api_t::callbackSet.
FSP_SUCCESS | Callback updated successfully. |
FSP_ERR_ASSERTION | Pointer to LIN control block or callback is NULL. |
FSP_ERR_NOT_OPEN | The control block has not been opened. |
FSP_ERR_NO_CALLBACK_MEMORY | p_callback is non-secure and p_callback_memory is either secure or NULL. |
fsp_err_t R_SCI_B_LIN_BaudCalculate | ( | sci_b_lin_baud_params_t const *const | p_baud_params, |
sci_b_lin_baud_setting_t *const | p_baud_setting | ||
) |
Calculates baud rate and LIN timer (BFLW and TCSS) register settings. This function evaluates and determines the most accurate settings for the baud rate and timer related registers.
The LIN timer setting is used for break field transmission/detection. Because the timer setting is specified in terms of bits, and the duration of a bit varies depending on baud rate, the baud rate register settings and timer register settings are related. The smallest possible LIN timer divider which can achieve the desired break field bits setting at the configured baud rate is selected to provide the highest measurement accuracy.
The baud rate cannot be updated at runtime with this function. This function is provided to ease configuration of the initial baud settings.
[in] | p_baud_params | Parameters required to calculate the baud rate |
[out] | p_baud_setting | If calculation succeeds, contains computed values to achieve requested baud rate. If calculation fails, the input structure is not modified. |
FSP_SUCCESS | Register settings updated in provided p_baud_setting |
FSP_ERR_ASSERTION | p_baud_setting was NULL |
FSP_ERR_INVALID_ARGUMENT | Cannot achieve combination of break field bits and baudrate with provided settings or p_baud_params->baudrate was 0 or p_baud_params->break_bits was 0 |
fsp_err_t R_SCI_B_LIN_IdFilterSet | ( | lin_ctrl_t *const | p_api_ctrl, |
sci_b_lin_id_filter_setting_t const *const | p_config | ||
) |
Set the the ID filter settings for filtering control field 1 (PID byte).
NOTE: Setting the ID filter will abort any in-progress LIN start frame reception, as the ID filter settings cannot be changed during reception of the start frame. The next start frame will be received with the new settings.
[in] | p_api_ctrl | Pointer to the LIN control block. |
[in] | p_config | The ID filter settings to apply |
FSP_SUCCESS | ID filter updated successfully. |
FSP_ERR_ASSERTION | Pointer to LIN control block or p_config is NULL. |
FSP_ERR_INVALID_MODE | Function called by master node (not supported for master nodes) |
FSP_ERR_NOT_OPEN | The control block has not been opened. |
fsp_err_t R_SCI_B_LIN_IdFilterGet | ( | lin_ctrl_t *const | p_api_ctrl, |
sci_b_lin_id_filter_setting_t *const | p_config | ||
) |
Returns the currently configured ID filter settings.
[in] | p_api_ctrl | Pointer to the LIN control block. |
[out] | p_config | The current ID filter settings |
FSP_SUCCESS | ID filter updated successfully. |
FSP_ERR_ASSERTION | Pointer to LIN control block or p_config is NULL. |
FSP_ERR_INVALID_MODE | Function called by master node (not supported for master nodes) |
FSP_ERR_NOT_OPEN | The control block has not been opened. |
fsp_err_t R_SCI_B_LIN_Close | ( | lin_ctrl_t *const | p_api_ctrl | ) |
Closes the LIN driver.
Implements lin_api_t::close.
Example:
FSP_SUCCESS | Channel successfully closed. |
FSP_ERR_ASSERTION | Pointer to LIN control block is NULL. |
FSP_ERR_NOT_OPEN | The control block has not been opened. |