Zephyr Project API 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
LIN Controller

Interfaces for LIN controllers. More...

Files

file  lin.h
 LIN (Local Interconnect Network) driver API.

Data Structures

struct  lin_config
 LIN configuration structure. More...
struct  lin_msg
 LIN message structure. More...
struct  lin_event
 LIN event structure. More...
struct  lin_filter
 LIN frame filter configuration (responder mode only). More...
struct  lin_driver_config
 Common LIN driver configuration structure. More...
struct  lin_driver_data
 Common LIN driver data structure. More...
struct  lin_driver_api
 @driver_ops{LIN Controller} More...

Macros

#define LIN_ERR_BUS_COLLISION   BIT(0)
 LIN error flags .
#define LIN_ERR_INVALID_CHECKSUM   BIT(1)
 LIN checksum error.
#define LIN_ERR_COUNTER_OVERFLOW   BIT(2)
 LIN counter overflow.
#define LIN_ERR_OVERRUN   BIT(3)
 LIN overrun error.
#define LIN_ERR_PARITY   BIT(4)
 LIN parity error.
#define LIN_ERR_FRAMING   BIT(5)
 LIN framing error.
#define LIN_DT_DRIVER_CONFIG_GET(node_id, _min_bitrate, _max_bitrate)
 Static initializer for lin_driver_config struct.
#define LIN_DT_DRIVER_CONFIG_INST_GET(inst, _min_bitrate, _max_bitrate)
 Static initializer for lin_driver_config struct from DT_DRV_COMPAT instance.

Typedefs

typedef uint32_t lin_config_flags_t
 Provide a type to hold LIN controller configuration flags.
typedef uint32_t lin_error_flags_t
 Provide a type to hold LIN error flags.
typedef void(* lin_event_callback_t) (const struct device *dev, const struct lin_event *event, void *user_data)
 LIN event callback function type.
typedef int(* lin_start_t) (const struct device *dev)
 Callback API for starting LIN controller.
typedef int(* lin_stop_t) (const struct device *dev)
 Callback API for stopping LIN controller.
typedef int(* lin_configure_t) (const struct device *dev, const struct lin_config *config)
 Callback API for configuring LIN controller.
typedef int(* lin_get_config_t) (const struct device *dev, struct lin_config *config)
 Callback API for getting LIN configuration.
typedef int(* lin_send_t) (const struct device *dev, const struct lin_msg *msg, k_timeout_t timeout)
 Callback API for sending LIN message.
typedef int(* lin_receive_t) (const struct device *dev, struct lin_msg *msg, k_timeout_t timeout)
 Callback API for receiving LIN message.
typedef int(* lin_response_t) (const struct device *dev, const struct lin_msg *msg, k_timeout_t timeout)
 Callback API for processing LIN response messages.
typedef int(* lin_read_t) (const struct device *dev, struct lin_msg *msg, k_timeout_t timeout)
 Callback API for reading LIN response message See lin_read() for argument description.
typedef int(* lin_wakeup_send_t) (const struct device *dev)
 Callback API for sending a LIN wakeup signal.
typedef int(* lin_set_event_callback_t) (const struct device *dev, lin_event_callback_t callback, void *user_data)
 Callback API for setting LIN transmit event callback.
typedef int(* lin_set_rx_filter_t) (const struct device *dev, const struct lin_filter *filter)
 Callback API for setting a LIN RX filter.

Enumerations

enum  lin_checksum_type { LIN_CHECKSUM_CLASSIC = 0 , LIN_CHECKSUM_ENHANCED }
 LIN checksum type. More...
enum  lin_event_type {
  LIN_EVT_RX_HEADER = 0 , LIN_EVT_TX_HEADER , LIN_EVT_RX_DATA , LIN_EVT_TX_DATA ,
  LIN_EVT_TX_WAKEUP , LIN_EVT_RX_WAKEUP , LIN_EVT_ERR
}
 LIN event types. More...
enum  lin_mode { LIN_MODE_COMMANDER = 0 , LIN_MODE_RESPONDER }
 LIN operation mode. More...

Functions

static uint8_t lin_get_frame_id (uint8_t pid)
 Helper function to extract LIN frame identifier from protected identifier (PID).
static uint8_t lin_compute_pid (uint8_t id)
 Helper function to compute LIN protected identifier (PID) from frame identifier.
static bool lin_verify_pid (uint8_t pid)
 Helper function to verify LIN protected identifier (PID).
const struct device * lin_get_transceiver (const struct device *dev)
 Get the LIN transceiver device associated with the LIN controller.
int lin_start (const struct device *dev)
 Start LIN controller.
int lin_stop (const struct device *dev)
 Stop LIN controller.
int lin_configure (const struct device *dev, const struct lin_config *config)
 Configure LIN controller.
int lin_get_config (const struct device *dev, struct lin_config *config)
 Get current LIN configuration.
int lin_send (const struct device *dev, const struct lin_msg *msg, k_timeout_t timeout)
 Send LIN message (commander mode only).
int lin_receive (const struct device *dev, struct lin_msg *msg, k_timeout_t timeout)
 Receive LIN message (commander mode only).
int lin_response (const struct device *dev, const struct lin_msg *msg, k_timeout_t timeout)
 Respond to a received header (responder mode only).
int lin_read (const struct device *dev, struct lin_msg *msg, k_timeout_t timeout)
 Start data reception (responder mode only).
int lin_wakeup_send (const struct device *dev)
 Send LIN wakeup signal.
static int lin_set_event_callback (const struct device *dev, lin_event_callback_t callback, void *user_data)
 Set LIN event callback.
int lin_set_rx_filter (const struct device *dev, const struct lin_filter *filter)
 Set a LIN RX filter (responder mode only).
#define LIN_ID_MASK   0x3FU
 LIN frame definitions.
#define LIN_BUS_CONFLICT_DETECTION   BIT(0)
 LIN device configuration flags .
#define LIN_BUS_AUTO_SYNC   BIT(1)
 LIN bus auto synchronization enabled.

Detailed Description

Interfaces for LIN controllers.

Since
4.5
Version
0.1.0

Macro Definition Documentation

◆ LIN_BUS_AUTO_SYNC

#define LIN_BUS_AUTO_SYNC   BIT(1)

#include <lin.h>

LIN bus auto synchronization enabled.

◆ LIN_BUS_CONFLICT_DETECTION

#define LIN_BUS_CONFLICT_DETECTION   BIT(0)

#include <lin.h>

LIN device configuration flags .

LIN bus conflict detection enabled

◆ LIN_DT_DRIVER_CONFIG_GET

#define LIN_DT_DRIVER_CONFIG_GET ( node_id,
_min_bitrate,
_max_bitrate )

#include <lin.h>

Value:
{ \
.phy = DEVICE_DT_GET_OR_NULL(DT_PHANDLE(node_id, phys)), \
.min_bitrate = DT_PROP_OR(node_id, min_bitrate, _min_bitrate), \
.max_bitrate = DT_PROP_OR(node_id, max_bitrate, _max_bitrate), \
.bitrate = DT_PROP_OR(node_id, bitrate, 0), \
}
#define DEVICE_DT_GET_OR_NULL(node_id)
Utility macro to obtain an optional reference to a device.
Definition device.h:412
#define DT_PROP_OR(node_id, prop, default_value)
Like DT_PROP(), but with a fallback to default_value.
Definition devicetree.h:1046
#define DT_PHANDLE(node_id, prop)
Get a node identifier for a phandle property's value.
Definition devicetree.h:1922

Static initializer for lin_driver_config struct.

Parameters
node_idDevicetree node identifier
_min_bitrateminimum bitrate supported by the LIN controller
_max_bitratemaximum bitrate supported by the LIN controller

◆ LIN_DT_DRIVER_CONFIG_INST_GET

#define LIN_DT_DRIVER_CONFIG_INST_GET ( inst,
_min_bitrate,
_max_bitrate )

#include <lin.h>

Value:
LIN_DT_DRIVER_CONFIG_GET(DT_DRV_INST(inst), _min_bitrate, _max_bitrate)
#define DT_DRV_INST(inst)
Node identifier for an instance of a DT_DRV_COMPAT compatible.
Definition devicetree.h:4765
#define LIN_DT_DRIVER_CONFIG_GET(node_id, _min_bitrate, _max_bitrate)
Static initializer for lin_driver_config struct.
Definition lin.h:321

Static initializer for lin_driver_config struct from DT_DRV_COMPAT instance.

Parameters
instDT_DRV_COMPAT instance number
_min_bitrateminimum bitrate supported by the LIN controller
_max_bitratemaximum bitrate supported by the LIN controller
See also
LIN_DT_DRIVER_CONFIG_GET()

◆ LIN_ERR_BUS_COLLISION

#define LIN_ERR_BUS_COLLISION   BIT(0)

#include <lin.h>

LIN error flags .

LIN bus collision detected

◆ LIN_ERR_COUNTER_OVERFLOW

#define LIN_ERR_COUNTER_OVERFLOW   BIT(2)

#include <lin.h>

LIN counter overflow.

◆ LIN_ERR_FRAMING

#define LIN_ERR_FRAMING   BIT(5)

#include <lin.h>

LIN framing error.

◆ LIN_ERR_INVALID_CHECKSUM

#define LIN_ERR_INVALID_CHECKSUM   BIT(1)

#include <lin.h>

LIN checksum error.

◆ LIN_ERR_OVERRUN

#define LIN_ERR_OVERRUN   BIT(3)

#include <lin.h>

LIN overrun error.

◆ LIN_ERR_PARITY

#define LIN_ERR_PARITY   BIT(4)

#include <lin.h>

LIN parity error.

◆ LIN_ID_MASK

#define LIN_ID_MASK   0x3FU

#include <lin.h>

LIN frame definitions.

Bit mask for a LIN identifier.

Typedef Documentation

◆ lin_config_flags_t

#include <lin.h>

Provide a type to hold LIN controller configuration flags.

See also
LIN_CONFIG_FLAGS.

◆ lin_configure_t

typedef int(* lin_configure_t) (const struct device *dev, const struct lin_config *config)

#include <lin.h>

Callback API for configuring LIN controller.

See lin_configure() for argument description.

◆ lin_error_flags_t

#include <lin.h>

Provide a type to hold LIN error flags.

See also
LIN_ERR_FLAGS.

◆ lin_event_callback_t

typedef void(* lin_event_callback_t) (const struct device *dev, const struct lin_event *event, void *user_data)

#include <lin.h>

LIN event callback function type.

This function is called when a LIN event occurs.

Parameters
devPointer to the LIN device structure
eventPointer to the LIN event structure
user_dataPointer to arbitrary user data.

◆ lin_get_config_t

typedef int(* lin_get_config_t) (const struct device *dev, struct lin_config *config)

#include <lin.h>

Callback API for getting LIN configuration.

See lin_get_config() for argument description.

◆ lin_read_t

typedef int(* lin_read_t) (const struct device *dev, struct lin_msg *msg, k_timeout_t timeout)

#include <lin.h>

Callback API for reading LIN response message See lin_read() for argument description.

◆ lin_receive_t

typedef int(* lin_receive_t) (const struct device *dev, struct lin_msg *msg, k_timeout_t timeout)

#include <lin.h>

Callback API for receiving LIN message.

See lin_receive() for argument description.

◆ lin_response_t

typedef int(* lin_response_t) (const struct device *dev, const struct lin_msg *msg, k_timeout_t timeout)

#include <lin.h>

Callback API for processing LIN response messages.

See lin_response() for argument description.

◆ lin_send_t

typedef int(* lin_send_t) (const struct device *dev, const struct lin_msg *msg, k_timeout_t timeout)

#include <lin.h>

Callback API for sending LIN message.

See lin_send() for argument description.

◆ lin_set_event_callback_t

typedef int(* lin_set_event_callback_t) (const struct device *dev, lin_event_callback_t callback, void *user_data)

#include <lin.h>

Callback API for setting LIN transmit event callback.

See lin_set_event_callback() for argument description.

◆ lin_set_rx_filter_t

typedef int(* lin_set_rx_filter_t) (const struct device *dev, const struct lin_filter *filter)

#include <lin.h>

Callback API for setting a LIN RX filter.

See lin_set_rx_filter() for argument description.

◆ lin_start_t

typedef int(* lin_start_t) (const struct device *dev)

#include <lin.h>

Callback API for starting LIN controller.

See lin_start() for argument description.

◆ lin_stop_t

typedef int(* lin_stop_t) (const struct device *dev)

#include <lin.h>

Callback API for stopping LIN controller.

See lin_stop() for argument description.

◆ lin_wakeup_send_t

typedef int(* lin_wakeup_send_t) (const struct device *dev)

#include <lin.h>

Callback API for sending a LIN wakeup signal.

See lin_wakeup_send() for argument description.

Enumeration Type Documentation

◆ lin_checksum_type

#include <lin.h>

LIN checksum type.

Enumerator
LIN_CHECKSUM_CLASSIC 

Classic checksum.

LIN_CHECKSUM_ENHANCED 

Enhanced checksum.

◆ lin_event_type

#include <lin.h>

LIN event types.

Enumerator
LIN_EVT_RX_HEADER 

Header received event (responder mode only).

LIN_EVT_TX_HEADER 

Header transmission complete event (commander mode only).

LIN_EVT_RX_DATA 

Data received event.

LIN_EVT_TX_DATA 

Data transmission complete event.

LIN_EVT_TX_WAKEUP 

Transmit wake up complete event.

LIN_EVT_RX_WAKEUP 

Receive wake up complete event.

LIN_EVT_ERR 

Error event.

◆ lin_mode

enum lin_mode

#include <lin.h>

LIN operation mode.

Enumerator
LIN_MODE_COMMANDER 

LIN commander node.

LIN_MODE_RESPONDER 

LIN responder node.

Function Documentation

◆ lin_compute_pid()

uint8_t lin_compute_pid ( uint8_t id)
inlinestatic

#include <lin.h>

Helper function to compute LIN protected identifier (PID) from frame identifier.

Parameters
idFrame identifier
Returns
uint8_t Protected identifier

◆ lin_configure()

int lin_configure ( const struct device * dev,
const struct lin_config * config )

#include <lin.h>

Configure LIN controller.

This function configures the LIN controller with the given settings.

Parameters
devPointer to the LIN device structure
configPointer to the configuration structure
Returns
0 on success, negative errno code on failure

◆ lin_get_config()

int lin_get_config ( const struct device * dev,
struct lin_config * config )

#include <lin.h>

Get current LIN configuration.

This function retrieves the current configuration of the LIN controller.

Parameters
devPointer to the LIN device structure
configPointer to configuration structure
Returns
0 on success, negative errno code on failure

◆ lin_get_frame_id()

uint8_t lin_get_frame_id ( uint8_t pid)
inlinestatic

#include <lin.h>

Helper function to extract LIN frame identifier from protected identifier (PID).

Parameters
pidProtected identifier
Returns
uint8_t Frame identifier

◆ lin_get_transceiver()

const struct device * lin_get_transceiver ( const struct device * dev)

#include <lin.h>

Get the LIN transceiver device associated with the LIN controller.

This function retrieves the LIN transceiver device associated with the specified LIN controller.

Parameters
devPointer to the LIN device structure
Returns
Pointer to the LIN transceiver device structure, or NULL if not available

◆ lin_read()

int lin_read ( const struct device * dev,
struct lin_msg * msg,
k_timeout_t timeout )

#include <lin.h>

Start data reception (responder mode only).

This is an interrupt-driven API that a responder node uses to initiate a non-blocking reception of a LIN message's data. It should be called when a LIN_EVT_RX_HEADER event occurs to receive the response for the corresponding header.

Only call this API if a header has been received.

Parameters
devPointer to the LIN device structure
msgPointer to the LIN message structure
timeoutTimeout waiting for reception to complete
Return values
0on success
-EPERMif the device is not in responder mode
-EFAULTif there is no header received
negativeerrno code on failure

◆ lin_receive()

int lin_receive ( const struct device * dev,
struct lin_msg * msg,
k_timeout_t timeout )

#include <lin.h>

Receive LIN message (commander mode only).

This function setup an asynchronous LIN read transaction with a specified LIN identifier. When device work in commander mode:

  • Send a header with specified ID for data requesting.
  • Read back data from responder.
Parameters
devPointer to the LIN device structure
msgPointer to the LIN message structure
timeoutTimeout waiting to complete transmission
Return values
0on success
-EPERMif the device is not in commander mode
negativeerrno code on failure

◆ lin_response()

int lin_response ( const struct device * dev,
const struct lin_msg * msg,
k_timeout_t timeout )

#include <lin.h>

Respond to a received header (responder mode only).

This is an interrupt-driven API for a responder node to respond to a LIN header sent by the commander node. For a responder node, it should be called when a LIN_EVT_RX_HEADER event occurs to publish the response for the received header.

Only call this API if a header has been received.

Parameters
devPointer to the LIN device structure
msgPointer to the LIN message structure
timeoutTimeout waiting for the response to complete
Return values
0on success
-EPERMif the device is not in responder mode
-EFAULTif there is no header received
negativeerrno code on failure

◆ lin_send()

int lin_send ( const struct device * dev,
const struct lin_msg * msg,
k_timeout_t timeout )

#include <lin.h>

Send LIN message (commander mode only).

This function setup an asynchronous LIN write transaction with a specified LIN identifier. When device work in commander mode:

  • Send a header with the specified ID.
  • Send the data payload (optional). Leave the msg->data_len as 0 in case response data is not needed.
Parameters
devPointer to LIN device structure
msgPointer to input LIN message structure
timeoutTimeout waiting to complete transmission
Return values
0on success
-EPERMif the device not in commander mode
negativeerrno code on failure

◆ lin_set_event_callback()

int lin_set_event_callback ( const struct device * dev,
lin_event_callback_t callback,
void * user_data )
inlinestatic

#include <lin.h>

Set LIN event callback.

This function sets a callback that will be called on LIN events.

Parameters
devPointer to the LIN device structure.
callbackPointer to the callback function.
user_dataPointer to user data passed to the callback.
Returns
0 on success, negative error code on failure.

◆ lin_set_rx_filter()

int lin_set_rx_filter ( const struct device * dev,
const struct lin_filter * filter )

#include <lin.h>

Set a LIN RX filter (responder mode only).

This function sets a header filter for LIN messages based on ID and mask. In case there is no filter set, all incoming messages are accepted.

When an accepted header is received, a LIN_EVT_RX_HEADER event is generated.

Parameters
devPointer to the LIN device structure.
filterPointer to the LIN filter structure.
Return values
0on success
-EPERMin case device is in commander mode.
negativeerror code on failure.

◆ lin_start()

int lin_start ( const struct device * dev)

#include <lin.h>

Start LIN controller.

This function brings the LIN controller to active state, allowing it to participate in LIN communication. It also enables the LIN transceiver (if supported).

Parameters
devPointer to the LIN device structure
Return values
0if successful.
-EALREADYif the LIN controller is already started.
negativeerrno code on failure.

◆ lin_stop()

int lin_stop ( const struct device * dev)

#include <lin.h>

Stop LIN controller.

This function brings the LIN controller into the deactivated state, preventing it from participating in LIN communication. It also disables the LIN transceiver (if supported).

Parameters
devPointer to the LIN device structure
Return values
0on success
-EALREADYif the LIN controller is already stopped.
negativeerrno code on failure

◆ lin_verify_pid()

bool lin_verify_pid ( uint8_t pid)
inlinestatic

#include <lin.h>

Helper function to verify LIN protected identifier (PID).

Parameters
pidProtected identifier to verify
Returns
true if the PID is valid, false otherwise

◆ lin_wakeup_send()

int lin_wakeup_send ( const struct device * dev)

#include <lin.h>

Send LIN wakeup signal.

Drive the bus dominant for the duration required by the LIN specification so sleeping nodes wake up.

Parameters
devLIN device
Returns
0 on success, negative errno on failure