RA Flexible Software Package Documentation  Release v5.9.0

 
LIN (r_sci_lin)

Functions

fsp_err_t R_SCI_LIN_Open (lin_ctrl_t *const p_api_ctrl, lin_cfg_t const *const p_cfg)
 
fsp_err_t R_SCI_LIN_StartFrameWrite (lin_ctrl_t *const p_api_ctrl, uint8_t const id)
 
fsp_err_t R_SCI_LIN_InformationFrameWrite (lin_ctrl_t *const p_api_ctrl, const lin_transfer_params_t *const p_transfer_params)
 
fsp_err_t R_SCI_LIN_InformationFrameRead (lin_ctrl_t *const p_api_ctrl, lin_transfer_params_t *const p_transfer_params)
 
fsp_err_t R_SCI_LIN_CommunicationAbort (lin_ctrl_t *const p_api_ctrl)
 
fsp_err_t R_SCI_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_LIN_BaudCalculate (sci_lin_baud_params_t const *const p_baud_params, sci_lin_baud_setting_t *const p_baud_setting)
 
fsp_err_t R_SCI_LIN_IdFilterSet (lin_ctrl_t *const p_api_ctrl, sci_lin_id_filter_setting_t const *const p_config)
 
fsp_err_t R_SCI_LIN_IdFilterGet (lin_ctrl_t *const p_api_ctrl, sci_lin_id_filter_setting_t *const p_config)
 
fsp_err_t R_SCI_LIN_Close (lin_ctrl_t *const p_api_ctrl)
 
fsp_err_t R_SCI_LIN_WakeupSend (lin_ctrl_t *const p_api_ctrl)
 
fsp_err_t R_SCI_LIN_SleepEnter (lin_ctrl_t *const p_api_ctrl)
 
fsp_err_t R_SCI_LIN_SleepExit (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 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.

In this document, the terminology 'Start Frame' refers to the LIN header (Break Field, Sync Field, and Protected Identifier Field), and the terminology 'Information Frame' refers to the LIN Data Field.

Note
Some MCUs call this feature Extended Serial Mode. Extended Serial Mode and Simple Lin are equivalent terms.

Features

Configuration

Build Time Configurations for r_sci_lin

The following build time configurations are defined in fsp_cfg/r_sci_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.
Bus Conflict Detection Support
  • Enabled
  • Disabled
Disabled When set to 'Disabled', code for bus conflict detection is excluded from the build. This setting is applied globally to the project. Enable when at least one LIN instance is using bus conflict detection.

Configurations for Connectivity > LIN (r_sci_lin)

This module can be added to the Stacks tab via New Stack > Connectivity > LIN (r_sci_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.
SCI ChannelMCU Specific OptionsSelect the Serial Communications Interface channel.
Mode
  • Master
  • Slave
Master Select the LIN operating mode (master or slave).
Extra
Digital Filter Clock Select
  • Disabled
  • SCI Base Clock
  • PCLK/8
  • PCLK/16
  • PCLK/32
  • PCLK/64
  • PCLK/128
Disabled Enable the digital filter on RXDXn pin. The digital filter block in SCI consists of three-stage flipflop circuits.
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_lin_extended_cfg_t structure.
Base Clock Cycles Per Bit Period
  • 8
  • 16
16 Select number of SCI base clock cycles per single bit period at the configured baud rate. When 16 base clock cycles is selected, the period of the SCI base clock is 1/16 of a single bit period. When 8 base clock cycles is selected, the period of the SCI base clock is 1/8 of a single bit period.
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.
Break Delimiter BitsValue must be an integer between 1 and 255.1 This configures the period of the break delimiter (in bits).The break delimiter shall be at least one nominal bit time long.
LIN Timer Divider
  • 1
  • 2
  • 4
  • 8
  • 16
  • 32
  • 64
  • 128
1 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.
Interrupts
CallbackName must be a valid C symbolsci_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.
Receive Error Interrupt PriorityMCU Specific OptionsSelect the receive error interrupt priority.
Break Field Low Width Interrupt Priority (SCIX0)MCU Specific OptionsSelect the break field low width interrupt priority.
Control Field 0/1 Match Interrupt Priority (SCIX1)MCU Specific OptionsSelect the Control field 0,1 and Priority bit detection interrupt priority.
Bus Collision Detection Interrupt Priority (SCIX2)MCU Specific OptionsSelect the bus collision detection interrupt priority, or set to 'Disabled' to disable bus collision detection.

Clock Configuration

Peripheral clock for SCI LIN is PCLKA.

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 the Bus Collision Detection Interrupt (SCIX2) 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 SCIX2 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).

A LIN transceiver is required to detect bus collisions. The propagation delay through the transceiver varies depending on individual transceiver design.

When Bus Conflict Detection is enabled, set the Bus Conflict Clock Divider to divide down the clock at least slow enough to avoid false positive collision detections caused by the worst case transceiver propagation delay. The Baud|Base Clock Cycles Per Bit Period setting can be used to adjust the SCI Base Clock frequency if needed.

Example:

The SCI base clock frequency can be calculated by the following formula:

sci_base_clock_frequency = 1 / [ (1/baud_rate)/cycles_per_bit_period ]

The following relationship must be satisfied to avoid false positives:

2 *[ 1e6 / (sci_base_clock_frequency/bus_conflict_clock_divider) ] > max_propagation_delay_us

Suppose:

Then:

Bus Conflict Divider Selection Process:

If no possible divider is found with 16 cycles, Baud|Base Clock Cycles Per Bit Period can be reduced to 8, which will reduce the SCI Base Clock by half compared to 16.

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_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_LIN_IdFilterSet. The current filter settings can be viewed with R_SCI_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_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_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_LIN_InformationFrameRead() before the first information data is received in order to receive the data. The user callback is called when reception is completed. It is permitted to call R_SCI_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_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.

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

The start frame is transmitted by calling R_SCI_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_LIN_InformationFrameRead() after start frame transmission has completed and before the first information frame data is received. It is permitted to call R_SCI_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_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_LIN_InformationFrameRead() is called, but the data is not received in the expected time period. If a timeout occurs, R_SCI_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

Limitations

Examples

Basic LIN Master Read Example

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

void r_sci_lin_basic_master_read_example (void)
{
/* Open the LIN instance with initial configuration. */
fsp_err_t err = R_SCI_LIN_Open(&g_master_ctrl, &g_master_cfg);
assert(FSP_SUCCESS == err);
/* Send the LIN start frame */
err = R_SCI_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_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_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_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_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_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_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_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_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_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;
/* Note: Only in case header frame not followed by information frame
* R_SCI_LIN_CommunicationAbort should be called to ignore the frame. */
err = R_SCI_LIN_CommunicationAbort(&g_slave_ctrl);
assert(FSP_SUCCESS == err);
}
}
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_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_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_lin_basic_id_filtering_example (void)
{
/* Open the LIN instance with initial configuration. */
fsp_err_t err = R_SCI_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,
.primary_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_LIN_PRIORITY_INTERRUPT_BIT_DISABLE,
.compare_data_select = SCI_LIN_COMPARE_DATA_SELECT_PRIORITY,
};
/* Configure the ID filter */
err = R_SCI_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_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_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_lin_advanced_id_filtering_example (void)
{
/* Open the LIN instance with initial configuration. */
fsp_err_t err = R_SCI_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 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,
.primary_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_LIN_PRIORITY_INTERRUPT_BIT_ENABLE,
.compare_data_select = SCI_LIN_COMPARE_DATA_SELECT_BOTH,
};
/* Configure the ID filter */
err = R_SCI_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_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_LIN_Close(&g_slave_ctrl);
assert(FSP_SUCCESS == err);
}

Data Structures

struct  sci_lin_timer_setting_t
 
struct  sci_lin_baud_setting_t
 
struct  sci_lin_id_filter_setting_t
 
struct  sci_lin_baud_params_t
 
struct  sci_lin_extended_cfg_t
 
struct  sci_lin_instance_ctrl_t
 

Enumerations

enum  sci_lin_priority_interrupt_bit_t
 
enum  sci_lin_compare_data_select_t
 
enum  sci_lin_timer_divider_t
 
enum  sci_lin_digital_filter_clock_t
 
enum  sci_lin_bus_conflict_clock_t
 
enum  sci_lin_base_clock_t
 

Data Structure Documentation

◆ sci_lin_timer_setting_t

struct sci_lin_timer_setting_t

Register settings for configuring the LIN timer

Data Fields
uint8_t tcss LIN timer count clock source selection.
uint8_t break_field_tpre Break field prescaler.
uint8_t break_field_tcnt Break field count value.
uint8_t delimiter_tpre Break delimiter prescaler.
uint8_t delimiter_tcnt Break delimiter count value.

◆ sci_lin_baud_setting_t

struct sci_lin_baud_setting_t

Register settings for achieving a desired baud rate.

Data Fields
sci_lin_timer_setting_t timer_setting Break field timer settings associated with this baud rate.
union sci_lin_baud_setting_t __unnamed__
uint8_t brr Bit Rate Register setting.
uint8_t cks: 2 CKS value to get divisor.

◆ sci_lin_id_filter_setting_t

struct sci_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 primary_compare_data

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 Primary comparison data for Control Field 1 (primary_compare_data).

uint8_t compare_data_select: 2

Select the compare data for Control Field 1 (priority, secondary, or both). See sci_lin_compare_data_select_t

uint8_t __pad0__: 2

◆ sci_lin_baud_params_t

struct sci_lin_baud_params_t

Parameters for baud and timer setting calculation

Data Fields
uint32_t baudrate Desired baudrate.
uint16_t break_bits Master mode: Number of break field bits to transmit. Slave mode: Number of break field threshold bits.
uint8_t delimiter_bits Break delimeter length setting (at least 1 nominal bit time long).
sci_lin_base_clock_t base_clock_cycles_per_bit Number of base clock cycles for 1-bit period.

◆ sci_lin_extended_cfg_t

struct sci_lin_extended_cfg_t

SCI LIN extended configuration

Data Fields
sci_lin_digital_filter_clock_t digital_filter_clock Digital filter setting. See sci_lin_digital_filter_clock_t.
sci_lin_bus_conflict_clock_t bus_conflict_clock Bus conflict detection clock setting. See sci_lin_bus_conflict_clock_t.
uint16_t break_bits Master mode: Number of break field bits to transmit. Slave mode: Number of break field threshold bits.
uint8_t delimiter_bits Break delimeter length setting (at least 1 nominal bit time long).
sci_lin_baud_setting_t baud_setting Register settings for a desired baud rate.
sci_lin_id_filter_setting_t filter_setting ID filter setting.
IRQn_Type scix0_irq Break field low width IRQ number.
IRQn_Type scix1_irq Control field 0-1 match / Priority interrupt bit detect IRQ number.
IRQn_Type scix2_irq Bus collision detect IRQ number.
IRQn_Type rxi_irq Receive interrupt IRQ number.
IRQn_Type txi_irq Transmit interrupt IRQ number.
IRQn_Type tei_irq Transmit end interrupt IRQ number.
IRQn_Type eri_irq Error interrupt IRQ number.
uint8_t scix0_ipl Break field low width interrupt priority.
uint8_t scix1_ipl Control field 0-1 match / Priority interrupt bit detect interrupt priority.
uint8_t scix2_ipl Bus collision detect interrupt priority.
uint8_t rxi_ipl Receive interrupt priority.
uint8_t txi_ipl Transmit interrupt priority.
uint8_t tei_ipl Transmit end interrupt priority.
uint8_t eri_ipl Error interrupt priority.

◆ sci_lin_instance_ctrl_t

struct sci_lin_instance_ctrl_t

LIN Instance Control Block. DO NOT INITIALIZE.

Enumeration Type Documentation

◆ sci_lin_priority_interrupt_bit_t

Priority interrupt bit options for ID filtering.

Enumerator
SCI_LIN_PRIORITY_INTERRUPT_BIT_DISABLE 

Disable the priority interrupt bit.

SCI_LIN_PRIORITY_INTERRUPT_BIT_ENABLE 

Enable the priority interrupt bit.

◆ sci_lin_compare_data_select_t

Compare Data Select options for ID filtering.

Enumerator
SCI_LIN_COMPARE_DATA_SELECT_PRIORITY 

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

SCI_LIN_COMPARE_DATA_SELECT_SECONDARY 

Select the secondary compare data filter as the compare data.

SCI_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_lin_timer_divider_t

LIN timer divider selection.

Enumerator
SCI_LIN_TIMER_DIV_1 

LIN timer frequency is PCLK/1.

SCI_LIN_TIMER_DIV_2 

LIN timer frequency is PCLK/2.

SCI_LIN_TIMER_DIV_4 

LIN timer frequency is PCLK/4.

SCI_LIN_TIMER_DIV_8 

LIN timer frequency is PCLK/8.

SCI_LIN_TIMER_DIV_16 

LIN timer frequency is PCLK/16.

SCI_LIN_TIMER_DIV_32 

LIN timer frequency is PCLK/32.

SCI_LIN_TIMER_DIV_64 

LIN timer frequency is PCLK/64.

SCI_LIN_TIMER_DIV_128 

LIN timer frequency is PCLK/128.

◆ sci_lin_digital_filter_clock_t

Digital filter configuration.

Enumerator
SCI_LIN_DIGITAL_FILTER_CLOCK_DISABLED 

Filter is disabled.

SCI_LIN_DIGITAL_FILTER_CLOCK_SCI_BASE_CLK 

Filter clock is SCI base clock.

SCI_LIN_DIGITAL_FILTER_CLOCK_PCLK_DIV_8 

Filter clock is PCLK/8.

SCI_LIN_DIGITAL_FILTER_CLOCK_PCLK_DIV_16 

Filter clock is PCLK/16.

SCI_LIN_DIGITAL_FILTER_CLOCK_PCLK_DIV_32 

Filter clock is PCLK/32.

SCI_LIN_DIGITAL_FILTER_CLOCK_PCLK_DIV_64 

Filter clock is PCLK/64.

SCI_LIN_DIGITAL_FILTER_CLOCK_PCLK_DIV_128 

Filter clock is PCLK/128.

◆ sci_lin_bus_conflict_clock_t

Bus conflict detection clock selection. The period of the SCI base clock is 1/16 of a single bit period when the SCIn.SEMR.ABCS is 0, and 1/8 of a single bit period when the SCIn.SEMR.ABCS is 1.

Enumerator
SCI_LIN_BUS_CONFLICT_CLOCK_DIV_1 

Bus conflict detection clock is base clock.

SCI_LIN_BUS_CONFLICT_CLOCK_DIV_2 

Bus conflict detection clock is base clock/2.

SCI_LIN_BUS_CONFLICT_CLOCK_DIV_4 

Bus conflict detection clock is base clock/4.

◆ sci_lin_base_clock_t

Asynchronous Mode Base Clock Select. The period of the SCI base clock is 1/16 of a single bit period when the SCIn.SEMR.ABCS is 0, and 1/8 of a single bit period when the SCIn.SEMR.ABCS is 1.

Enumerator
SCI_LIN_BASE_CLOCK_16 

Select 16 base clock cycles for 1-bit period.

SCI_LIN_BASE_CLOCK_8 

Select 8 base clock cycles for 1-bit period.

Function Documentation

◆ R_SCI_LIN_Open()

fsp_err_t R_SCI_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_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 LIN mode.
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_LIN_StartFrameWrite()

fsp_err_t R_SCI_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_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_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_LIN_InformationFrameWrite()

fsp_err_t R_SCI_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_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_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_LIN_InformationFrameRead()

fsp_err_t R_SCI_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_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_LIN_CommunicationAbort to cancel it if desired, or wait for the current transfer operation to complete before starting a new one.
FSP_ERR_INVALID_CALLData reception is not possible because a header frame has not been received yet (slave mode only).
Returns
See Common Error Codes or functions called by this function for other possible return codes.

◆ R_SCI_LIN_CommunicationAbort()

fsp_err_t R_SCI_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_LIN_CallbackSet()

fsp_err_t R_SCI_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_LIN_BaudCalculate()

fsp_err_t R_SCI_LIN_BaudCalculate ( sci_lin_baud_params_t const *const  p_baud_params,
sci_lin_baud_setting_t *const  p_baud_setting 
)

Calculates baud rate and LIN timer (TCNT, TPRE 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_LIN_IdFilterSet()

fsp_err_t R_SCI_LIN_IdFilterSet ( lin_ctrl_t *const  p_api_ctrl,
sci_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_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_LIN_IdFilterGet()

fsp_err_t R_SCI_LIN_IdFilterGet ( lin_ctrl_t *const  p_api_ctrl,
sci_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_LIN_Close()

fsp_err_t R_SCI_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_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.

◆ R_SCI_LIN_WakeupSend()

fsp_err_t R_SCI_LIN_WakeupSend ( lin_ctrl_t *const  p_api_ctrl)

Send wakeup is not supported on the SCI LIN driver.

Implements lin_api_t::wakeupSend.

Return values
FSP_ERR_UNSUPPORTEDFunction not supported in this implementation.

◆ R_SCI_LIN_SleepEnter()

fsp_err_t R_SCI_LIN_SleepEnter ( lin_ctrl_t *const  p_api_ctrl)

Sleep is not supported on the SCI LIN driver.

Implements lin_api_t::sleepEnter.

Return values
FSP_ERR_UNSUPPORTEDFunction not supported in this implementation.

◆ R_SCI_LIN_SleepExit()

fsp_err_t R_SCI_LIN_SleepExit ( lin_ctrl_t *const  p_api_ctrl)

Sleep is not supported on the SCI LIN driver.

Implements lin_api_t::sleepExit.

Return values
FSP_ERR_UNSUPPORTEDFunction not supported in this implementation.