RA Flexible Software Package Documentation  Release v5.6.0

 
LIN (r_sci_b_lin)

Functions

fsp_err_t R_SCI_B_LIN_Open (lin_ctrl_t *const p_api_ctrl, lin_cfg_t const *const p_cfg)
 
fsp_err_t R_SCI_B_LIN_StartFrameWrite (lin_ctrl_t *const p_api_ctrl, uint8_t const id)
 
fsp_err_t R_SCI_B_LIN_InformationFrameWrite (lin_ctrl_t *const p_api_ctrl, const lin_transfer_params_t *const p_transfer_params)
 
fsp_err_t R_SCI_B_LIN_InformationFrameRead (lin_ctrl_t *const p_api_ctrl, lin_transfer_params_t *const p_transfer_params)
 
fsp_err_t R_SCI_B_LIN_CommunicationAbort (lin_ctrl_t *const p_api_ctrl)
 
fsp_err_t R_SCI_B_LIN_CallbackSet (lin_ctrl_t *const p_api_ctrl, void(*p_callback)(lin_callback_args_t *), void const *const p_context, lin_callback_args_t *const p_callback_memory)
 
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)
 
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)
 
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)
 
fsp_err_t R_SCI_B_LIN_Close (lin_ctrl_t *const p_api_ctrl)
 

Detailed Description

Driver for the SCI peripheral on RA MCUs. This module implements the LIN Interface.

Overview

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.

Features

Configuration

Build Time Configurations for r_sci_b_lin

The following build time configurations are defined in fsp_cfg/r_sci_b_lin_cfg.h:

ConfigurationOptionsDefaultDescription
Parameter Checking
  • Default (BSP)
  • Enabled
  • Disabled
Default (BSP) If selected code for parameter checking is included in the build.
Checksum Support
  • Enabled
  • Disabled
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
  • Enabled
  • Disabled
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.

Configurations for Connectivity > LIN (r_sci_b_lin)

This module can be added to the Stacks tab via New Stack > Connectivity > LIN (r_sci_b_lin). Non-secure callable guard functions can be generated for this module by right clicking the module in the RA Configuration tool and checking the "Non-secure Callable" box.

ConfigurationOptionsDefaultDescription
General
NameName must be a valid C symbolg_lin0 Module name.
ChannelMCU Specific OptionsSelect the LIN channel.
Mode
  • Master
  • Slave
Master Select the LIN operating mode (master or slave).
Extra
Clock SourceMCU Specific OptionsSelect whether the peripheral clock (PCLK) or SCICLK/SCISPICLK is used as the baud rate generator.
Noise Filter
  • Enable
  • Disable
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
  • Enable
  • Disable
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
  • 1
  • 2
  • 4
2 Select the base clock divider for the sampling clock of the bus conflict detection circuit.
Baud
Baud RateValue must be an integer greater than 019200 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
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 MaskValue 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 DataValue must be an integer between 0 and 255.0 Select the priority compare filter data.
Secondary Compare DataValue must be an integer between 0 and 255.0 Select the secondary compare filter data.
Compare Data Select
  • Priority
  • Secondary
  • Both
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
  • Enabled
  • Disabled
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 BitValue 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
  • 16
  • 64
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
  • 2bits
1bit Select the recessive period (in bits) of the break field. This setting also selects the number of stop bits.
Interrupts
CallbackName must be a valid C symbolsci_b_lin0_callback A user callback function must be provided. It will be called from the interrupt service routine (ISR).
Receive Interrupt PriorityMCU Specific OptionsSelect the receive interrupt priority.
Transmit Data Empty Interrupt PriorityMCU Specific OptionsSelect the transmit interrupt priority.
Transmit End Interrupt PriorityMCU Specific OptionsSelect the transmit end interrupt priority.
Error Interrupt PriorityMCU Specific OptionsSelect the error interrupt priority.
Break Field Detection Interrupt PriorityMCU Specific OptionsSelect the break field detection interrupt priority (slave mode only).
Active Edge Detection Interrupt PriorityMCU Specific OptionsSelect the active edge detection interrupt priority.

Clock Configuration

The clock for this module is derived from the following peripheral clock for each MCU group:

MCU GroupPeripheral Clock
RA6T2SCISPICLK
RA8D1SCICLK
RA8E1SCICLK
RA8M1SCICLK
RA8T1SCICLK

The clock source for the baud-rate clock generator can be selected from either SCISCPI/SCICLK or the peripheral clock (PCLK).

Note
1. See Figure 26.2 "Clock source selector block diagram" in the RA6T2 manual for more information.

Pin Configuration

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.

Interrupt Configuration

Break Field Length/Detection Threshold Configuration

Bus Conflict Detection Configuration

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.

ID Filter Configuration

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.

Usage Notes

LIN Transmission and Reception

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).

Slave Mode Transmission and Reception

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.

Master Mode Transmission and Reception

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.

Timeouts/Errors

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.

Checksum Generation and Validation

Auto Synchronization

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.

Limitations

Examples

Basic LIN Master Read Example

The following demonstrates a basic example of frame reception for a LIN master.

void r_sci_b_lin_basic_master_read_example (void)
{
/* Open the LIN instance with initial configuration. */
fsp_err_t err = R_SCI_B_LIN_Open(&g_master_ctrl, &g_master_cfg);
assert(FSP_SUCCESS == err);
/* Send the LIN start frame */
err = R_SCI_B_LIN_StartFrameWrite(&g_master_ctrl, FRAME_ID);
assert(FSP_SUCCESS == err);
/* Wait for start frame transmission to complete before starting a read of the response */
while (!g_start_frame_tx_complete)
{
}
lin_transfer_params_t read_params =
{
.id = FRAME_ID,
.num_bytes = TRANSFER_LENGTH,
.p_information = g_rx_buf
};
/* Begin reception of the information frame data */
err = R_SCI_B_LIN_InformationFrameRead(&g_master_ctrl, &read_params);
assert(FSP_SUCCESS == err);
/* Wait for information frame reception to complete. The application is responsible for
* timing out if data is not received within the expected time interval*/
while (!g_information_frame_rx_complete)
{
}
/* Close the driver */
err = R_SCI_B_LIN_Close(&g_slave_ctrl);
assert(FSP_SUCCESS == err);
}
void master_callback (lin_callback_args_t * p_args)
{
/* Handle the LIN event */
switch (p_args->event)
{
{
g_information_frame_rx_complete = 1;
break;
}
{
g_start_frame_tx_complete = 1;
break;
}
{
g_information_frame_tx_complete = 1;
break;
}
default:
{
/* Handle error */
}
}
}

Basic LIN Master Write Example

The following demonstrates a basic example of frame transmission for a LIN master.

void r_sci_b_lin_basic_master_write_example (void)
{
/* Initialize transmit buffer to known data. */
for (uint8_t i = 0; i < TRANSFER_LENGTH; i++)
{
g_tx_buf[i] = (uint8_t) ('A' + (i % 26));
}
/* Open the LIN instance with initial configuration. */
fsp_err_t err = R_SCI_B_LIN_Open(&g_master_ctrl, &g_master_cfg);
assert(FSP_SUCCESS == err);
/* Send the LIN start frame: break, sync, and protected identifier */
err = R_SCI_B_LIN_StartFrameWrite(&g_master_ctrl, FRAME_ID);
assert(FSP_SUCCESS == err);
/* Wait for start frame transmission to complete before sending the information frame */
while (!g_start_frame_tx_complete)
{
}
lin_transfer_params_t write_params =
{
.id = FRAME_ID,
.num_bytes = TRANSFER_LENGTH,
.p_information = g_tx_buf
};
/* Send the LIN information frame */
err = R_SCI_B_LIN_InformationFrameWrite(&g_master_ctrl, &write_params);
assert(FSP_SUCCESS == err);
/* Wait for information frame transmission to complete */
while (!g_information_frame_tx_complete)
{
}
/* Close the driver */
err = R_SCI_B_LIN_Close(&g_master_ctrl);
assert(FSP_SUCCESS == err);
}

Basic LIN Slave Example

The following demonstrates a basic example of start frame reception and information frame response for a LIN slave.

void r_sci_b_lin_basic_slave_example (void)
{
/* Initialize transmit buffer to known data */
for (uint32_t i = 0; i < TRANSFER_LENGTH; i++)
{
g_tx_buf[i] = (uint8_t) ('A' + (i % 26));
}
/* Open the LIN instance with initial configuration. */
fsp_err_t err = R_SCI_B_LIN_Open(&g_slave_ctrl, &g_slave_cfg);
assert(FSP_SUCCESS == err);
/* Wait for the header that this slave publishes the response to. */
for ( ; ; )
{
if (g_start_frame_rx_complete)
{
if (g_received_pid == FRAME_ID)
{
/* Frame ID of interest received */
break;
}
/* Ignore this header. No action required by slave. */
g_start_frame_rx_complete = false;
}
}
lin_transfer_params_t write_params =
{
.id = g_received_pid,
.num_bytes = TRANSFER_LENGTH,
.p_information = g_tx_buf
};
/* Send the LIN information frame response */
err = R_SCI_B_LIN_InformationFrameWrite(&g_slave_ctrl, &write_params);
assert(FSP_SUCCESS == err);
/* Wait for the response transmission to complete */
while (!g_information_frame_tx_complete)
{
}
/* Close the driver */
err = R_SCI_B_LIN_Close(&g_slave_ctrl);
assert(FSP_SUCCESS == err);
}
void slave_callback (lin_callback_args_t * p_args)
{
/* Handle the LIN event */
switch (p_args->event)
{
{
g_start_frame_rx_complete = 1;
g_received_pid = p_args->pid;
break;
}
{
g_information_frame_rx_complete = 1;
break;
}
{
g_information_frame_tx_complete = 1;
break;
}
default:
{
/* Handle error */
}
}
}

Basic LIN Slave ID Filtering Example

The following example demonstrates a basic example of frame ID filtering.

#define BASIC_FILTER_MASK (0x30)
#define BASIC_PRIORITY_FILTER_DATA (0x20)
#define BASIC_SECONDARY_FILTER_DATA (0x00) // Don't-care value in this example
#define BASIC_PRIORITY_INTERRUPT_BIT (0) // Don't-care value in this example
void r_sci_b_lin_basic_id_filtering_example (void)
{
/* Open the LIN instance with initial configuration. */
fsp_err_t err = R_SCI_B_LIN_Open(&g_slave_ctrl, &g_slave_cfg);
assert(FSP_SUCCESS == err);
/* If the application is using dynamically assigned identifiers, perform
* any required initial communications to get the identifiers for this slave */
/* Configure filter to accept only frame IDs in the range 0x20-0x2F.
*
* The start frame is received only when the PID bits match the bits
* specified by the filter.
*
* Example: If ID 0x24 is received (PID 0x64), the filter mask (0x30) is applied
* first (0x64 & 0x30 = 0x20) and then the result is compared to the priority
* compare data filter (0x20). Since the result matches the filter, the start
* frame is received and the user callback is called. Otherwise, the SCI awaits
* the next break field, and the callback is not called.
*
* Note: The most significant 2 bits of the PID are the parity bits, and are
* masked off by the filter mask in this example.
*/
{
.compare_data_mask = BASIC_FILTER_MASK,
.priority_compare_data = BASIC_PRIORITY_FILTER_DATA,
.secondary_compare_data = BASIC_SECONDARY_FILTER_DATA,
.priority_interrupt_bit_select = BASIC_PRIORITY_INTERRUPT_BIT,
.priority_interrupt_enable = SCI_B_LIN_PRIORITY_INTERRUPT_BIT_DISABLE,
};
/* Configure the ID filter */
err = R_SCI_B_LIN_IdFilterSet(&g_slave_ctrl, &filter);
assert(FSP_SUCCESS == err);
/* Wait for a header frame which matches the filter */
while (!g_start_frame_rx_complete)
{
}
lin_transfer_params_t write_params =
{
.id = g_received_pid,
.num_bytes = TRANSFER_LENGTH,
.p_information = g_tx_buf
};
/* Send the LIN information frame response */
err = R_SCI_B_LIN_InformationFrameWrite(&g_slave_ctrl, &write_params);
assert(FSP_SUCCESS == err);
/* Wait for the response transmission to complete */
while (!g_information_frame_tx_complete)
{
}
/* Close the driver */
err = R_SCI_B_LIN_Close(&g_slave_ctrl);
assert(FSP_SUCCESS == err);
}

Advanced LIN Slave ID Filtering Example

The following example demonstrates an advanced example of frame ID filtering.

#define ADVANCED_FILTER_MASK (0x3E)
#define ADVANCED_PRIORITY_FILTER_DATA (0x20)
#define ADVANCED_SECONDARY_FILTER_DATA (0x08)
#define ADVANCED_PRIORITY_INTERRUPT_BIT (5)
void r_sci_b_lin_advanced_id_filtering_example (void)
{
/* Open the LIN instance with initial configuration. */
fsp_err_t err = R_SCI_B_LIN_Open(&g_slave_ctrl, &g_slave_cfg);
assert(FSP_SUCCESS == err);
/* If the application is using dynamically assigned identifiers, perform
* any required initial communications to get the identifiers for this slave */
/* Configure filter to accept the following frame IDs:
*
* - Any ID in which bit 5 is set to 1 (0x20-0x3F).
* - IDs 0x08 and 0x09
*
* The priority compare data filter is set to 0x20 (bit 5 set).
* The priority interrupt bit select function is enabled for bit 5.
*
* The secondary compare data filter is be set to 0x08. This will allow
* both 0x08 and 0x09 through the filter, even though bit 5 is not set for
* those values (0x08 & 0x3E = 0x08 and 0x09 & 0x3E = 0x08). All other
* identifiers are filtered out.
*/
{
.compare_data_mask = ADVANCED_FILTER_MASK,
.priority_compare_data = ADVANCED_PRIORITY_FILTER_DATA,
.secondary_compare_data = ADVANCED_SECONDARY_FILTER_DATA,
.priority_interrupt_bit_select = ADVANCED_PRIORITY_INTERRUPT_BIT,
.priority_interrupt_enable = SCI_B_LIN_PRIORITY_INTERRUPT_BIT_ENABLE,
.compare_data_select = SCI_B_LIN_COMPARE_DATA_SELECT_BOTH,
};
/* Configure the ID filter */
err = R_SCI_B_LIN_IdFilterSet(&g_slave_ctrl, &filter);
assert(FSP_SUCCESS == err);
/* Wait for a header frame which matches the filter */
while (!g_start_frame_rx_complete)
{
}
lin_transfer_params_t write_params =
{
.id = g_received_pid,
.num_bytes = TRANSFER_LENGTH,
.p_information = g_tx_buf
};
/* Send the LIN information frame response */
err = R_SCI_B_LIN_InformationFrameWrite(&g_slave_ctrl, &write_params);
assert(FSP_SUCCESS == err);
/* Wait for the response transmission to complete */
while (!g_information_frame_tx_complete)
{
}
/* Close the driver */
err = R_SCI_B_LIN_Close(&g_slave_ctrl);
assert(FSP_SUCCESS == err);
}

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
 

Enumerations

enum  sci_b_lin_priority_interrupt_bit_t
 
enum  sci_b_lin_compare_data_select_t
 
enum  sci_b_lin_clock_source_t
 
enum  sci_b_lin_break_delimiter_bits_t
 
enum  sci_b_lin_timer_divider_t
 
enum  sci_b_lin_synchronization_t
 
enum  sci_b_lin_noise_cancellation_t
 
enum  e_sci_b_lin_bus_conflict_detection_t
 
enum  sci_b_lin_bus_conflict_clock_t
 

Data Structure Documentation

◆ sci_b_lin_timer_setting_t

struct sci_b_lin_timer_setting_t

Register settings for configuring the LIN break field timer

Data Fields
uint8_t __pad0__: 6
uint8_t tcss: 2 LIN timer count clock source selection.
uint16_t bflw Break field length setting (break field length is (bflw + 1) * clock of the timer)

◆ sci_b_lin_baud_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.

◆ sci_b_lin_id_filter_setting_t

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

◆ sci_b_lin_baud_params_t

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.

◆ sci_b_lin_extended_cfg_t

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.

Enumeration Type Documentation

◆ sci_b_lin_priority_interrupt_bit_t

Priority interrupt bit options for ID filtering.

Enumerator
SCI_B_LIN_PRIORITY_INTERRUPT_BIT_DISABLE 

Disable the priority interrupt bit.

SCI_B_LIN_PRIORITY_INTERRUPT_BIT_ENABLE 

Enable the priority interrupt bit.

◆ sci_b_lin_compare_data_select_t

Compare Data Select options for ID filtering.

Enumerator
SCI_B_LIN_COMPARE_DATA_SELECT_PRIORITY 

Select the priority/primary compare data filter as the compare data.

SCI_B_LIN_COMPARE_DATA_SELECT_SECONDARY 

Select the secondary compare data filter as the compare data.

SCI_B_LIN_COMPARE_DATA_SELECT_BOTH 

Select both the priority/primary compare data filter and the secondary compare data filter as the compare data. The priority filter will be checked first.

◆ sci_b_lin_clock_source_t

Source clock selection options for SCI.

Enumerator
SCI_B_LIN_CLOCK_SOURCE_SCISPICLK 

SCISPI clock source.

SCI_B_LIN_CLOCK_SOURCE_SCICLK 

SCI clock source.

SCI_B_LIN_CLOCK_SOURCE_PCLK 

PCLK source.

◆ sci_b_lin_break_delimiter_bits_t

Break field delimiter configuration.

Enumerator
SCI_B_LIN_BREAK_DELIMITER_BITS_1 

1-bit recessive break field delimiter

SCI_B_LIN_BREAK_DELIMITER_BITS_2 

2-bit recessive break field delimiter

◆ sci_b_lin_timer_divider_t

LIN timer configuration, used for break field generation and detection.

Enumerator
SCI_B_LIN_TIMER_DIV_4 

LIN timer frequency is TCLK/4.

SCI_B_LIN_TIMER_DIV_16 

LIN timer frequency is TCLK/16.

SCI_B_LIN_TIMER_DIV_64 

LIN timer frequency is TCLK/64.

◆ sci_b_lin_synchronization_t

Auto synchronization setting.

Enumerator
SCI_B_LIN_AUTO_SYNCHRONIZATION_DISABLE 

Disable auto synchronization during sync byte reception.

SCI_B_LIN_AUTO_SYNCHRONIZATION_ENABLE 

Enable auto synchronization during sync byte reception.

◆ sci_b_lin_noise_cancellation_t

Noise cancellation configuration.

Enumerator
SCI_B_LIN_NOISE_CANCELLATION_DISABLE 

Disable noise cancellation.

SCI_B_LIN_NOISE_CANCELLATION_ENABLE 

Enable noise cancellation.

◆ e_sci_b_lin_bus_conflict_detection_t

Bus conflict detection enable.

Enumerator
SCI_B_LIN_BUS_CONFLICT_DETECTION_DISABLE 

Disable bus conflict detection.

SCI_B_LIN_BUS_CONFLICT_DETECTION_ENABLE 

Enable bus conflict detection.

◆ sci_b_lin_bus_conflict_clock_t

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

Enumerator
SCI_B_LIN_BUS_CONFLICT_DETECTION_BASE_CLOCK_DIV_1 

Bus conflict detection clock is base clock.

SCI_B_LIN_BUS_CONFLICT_DETECTION_BASE_CLOCK_DIV_2 

Bus conflict detection clock is base clock/2.

SCI_B_LIN_BUS_CONFLICT_DETECTION_BASE_CLOCK_DIV_4 

Bus conflict detection clock is base clock/4. Setting prohibited when CCR2.ABCS = 1.

Function Documentation

◆ R_SCI_B_LIN_Open()

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:

/* Open the LIN instance with initial configuration. */
fsp_err_t err = R_SCI_B_LIN_Open(&g_master_ctrl, &g_master_cfg);
Return values
FSP_SUCCESSChannel opened successfully.
FSP_ERR_ASSERTIONPointer to LIN control block or configuration structure is NULL.
FSP_ERR_INVALID_CHANNELThe requested channel does not exist on this MCU or the channel does not support Simple LIN mode.
FSP_ERR_INVALID_ARGUMENTBreak field length setting or timer divisor is invalid.
FSP_ERR_ALREADY_OPENControl block has already been opened or channel is being used by another instance. Call close() then open() to reconfigure.
FSP_ERR_INVALID_MODESetting not supported for selected mode
Returns
See Common Error Codes or functions called by this function for other possible return codes.

◆ R_SCI_B_LIN_StartFrameWrite()

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:

/* Send the LIN start frame: break, sync, and protected identifier */
err = R_SCI_B_LIN_StartFrameWrite(&g_master_ctrl, FRAME_ID);
Return values
FSP_SUCCESSStart frame transmission started successfully.
FSP_ERR_ASSERTIONA required pointer is NULL.
FSP_ERR_NOT_OPENThe control block has not been opened.
FSP_ERR_INVALID_ARGUMENTID out of range (unprotected ID must be less than 64)
FSP_ERR_INVALID_MODEFunction called by slave node (not supported for slave nodes)
FSP_ERR_IN_USEA 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.
Returns
See Common Error Codes or functions called by this function for other possible return codes.

◆ R_SCI_B_LIN_InformationFrameWrite()

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:

/* Send the LIN information frame */
err = R_SCI_B_LIN_InformationFrameWrite(&g_master_ctrl, &write_params);
Return values
FSP_SUCCESSData transmission started successfully.
FSP_ERR_NOT_OPENThe control block has not been opened.
FSP_ERR_ASSERTIONPointer to LIN control block, transfer parameters, or tx/rx buffer is NULL, or 0 bytes length provided
FSP_ERR_IN_USEA 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.
Returns
See Common Error Codes or functions called by this function for other possible return codes.

◆ R_SCI_B_LIN_InformationFrameRead()

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:

/* Begin reception of the information frame data */
err = R_SCI_B_LIN_InformationFrameRead(&g_master_ctrl, &read_params);
Return values
FSP_SUCCESSData reception started successfully.
FSP_ERR_NOT_OPENThe control block has not been opened.
FSP_ERR_ASSERTIONPointer to LIN control block, transfer parameters, or tx/rx buffer is NULL, or 0 bytes length provided
FSP_ERR_IN_USEA 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.
Returns
See Common Error Codes or functions called by this function for other possible return codes.

◆ R_SCI_B_LIN_CommunicationAbort()

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.

Return values
FSP_SUCCESSData transfer aborted successfully or no transfer was in progress.
FSP_ERR_NOT_OPENThe control block has not been opened.
FSP_ERR_ASSERTIONPointer to LIN control block is NULL.
Returns
See Common Error Codes or functions called by this function for other possible return codes.

◆ R_SCI_B_LIN_CallbackSet()

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.

Return values
FSP_SUCCESSCallback updated successfully.
FSP_ERR_ASSERTIONPointer to LIN control block or callback is NULL.
FSP_ERR_NOT_OPENThe control block has not been opened.
FSP_ERR_NO_CALLBACK_MEMORYp_callback is non-secure and p_callback_memory is either secure or NULL.
Returns
See Common Error Codes or functions called by this function for other possible return codes.

◆ R_SCI_B_LIN_BaudCalculate()

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.

Parameters
[in]p_baud_paramsParameters required to calculate the baud rate
[out]p_baud_settingIf calculation succeeds, contains computed values to achieve requested baud rate. If calculation fails, the input structure is not modified.
Return values
FSP_SUCCESSRegister settings updated in provided p_baud_setting
FSP_ERR_ASSERTIONp_baud_setting was NULL
FSP_ERR_INVALID_ARGUMENTCannot 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

◆ R_SCI_B_LIN_IdFilterSet()

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.

/* Configure the ID filter */
err = R_SCI_B_LIN_IdFilterSet(&g_slave_ctrl, &filter);
Parameters
[in]p_api_ctrlPointer to the LIN control block.
[in]p_configThe ID filter settings to apply
Return values
FSP_SUCCESSID filter updated successfully.
FSP_ERR_ASSERTIONPointer to LIN control block or p_config is NULL.
FSP_ERR_INVALID_MODEFunction called by master node (not supported for master nodes)
FSP_ERR_NOT_OPENThe control block has not been opened.
Returns
See Common Error Codes or functions called by this function for other possible return codes.

◆ R_SCI_B_LIN_IdFilterGet()

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.

Parameters
[in]p_api_ctrlPointer to the LIN control block.
[out]p_configThe current ID filter settings
Return values
FSP_SUCCESSID filter updated successfully.
FSP_ERR_ASSERTIONPointer to LIN control block or p_config is NULL.
FSP_ERR_INVALID_MODEFunction called by master node (not supported for master nodes)
FSP_ERR_NOT_OPENThe control block has not been opened.
Returns
See Common Error Codes or functions called by this function for other possible return codes.

◆ R_SCI_B_LIN_Close()

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:

/* Close the driver */
err = R_SCI_B_LIN_Close(&g_master_ctrl);
Return values
FSP_SUCCESSChannel successfully closed.
FSP_ERR_ASSERTIONPointer to LIN control block is NULL.
FSP_ERR_NOT_OPENThe control block has not been opened.
Returns
See Common Error Codes or functions called by this function for other possible return codes.