14#ifndef ZEPHYR_INCLUDE_ZEPHYR_DRIVERS_LIN_H
15#define ZEPHYR_INCLUDE_ZEPHYR_DRIVERS_LIN_H
51#define LIN_ID_MASK 0x3FU
58#define LIN_MAX_DLEN 8U
70#define LIN_BUS_CONFLICT_DETECTION BIT(0)
71#define LIN_BUS_AUTO_SYNC BIT(1)
107#define LIN_ERR_BUS_COLLISION BIT(0)
108#define LIN_ERR_INVALID_CHECKSUM BIT(1)
109#define LIN_ERR_COUNTER_OVERFLOW BIT(2)
110#define LIN_ERR_OVERRUN BIT(3)
111#define LIN_ERR_PARITY BIT(4)
112#define LIN_ERR_FRAMING BIT(5)
321#define LIN_DT_DRIVER_CONFIG_GET(node_id, _min_bitrate, _max_bitrate) \
323 .phy = DEVICE_DT_GET_OR_NULL(DT_PHANDLE(node_id, phys)), \
324 .min_bitrate = DT_PROP_OR(node_id, min_bitrate, _min_bitrate), \
325 .max_bitrate = DT_PROP_OR(node_id, max_bitrate, _max_bitrate), \
326 .bitrate = DT_PROP_OR(node_id, bitrate, 0), \
337#define LIN_DT_DRIVER_CONFIG_INST_GET(inst, _min_bitrate, _max_bitrate) \
338 LIN_DT_DRIVER_CONFIG_GET(DT_DRV_INST(inst), _min_bitrate, _max_bitrate)
459static const struct device *z_impl_lin_get_transceiver(
const struct device *dev)
479static inline int z_impl_lin_start(
const struct device *dev)
497static inline int z_impl_lin_stop(
const struct device *dev)
513static inline int z_impl_lin_configure(
const struct device *dev,
const struct lin_config *config)
529static inline int z_impl_lin_get_config(
const struct device *dev,
struct lin_config *config)
552static inline int z_impl_lin_send(
const struct device *dev,
const struct lin_msg *msg,
575static inline int z_impl_lin_receive(
const struct device *dev,
struct lin_msg *msg,
601static inline int z_impl_lin_response(
const struct device *dev,
const struct lin_msg *msg,
610 return api->
response(dev, msg, timeout);
632static inline int z_impl_lin_read(
const struct device *dev,
struct lin_msg *msg,
641 return api->
read(dev, msg, timeout);
655static inline int z_impl_lin_wakeup_send(
const struct device *dev)
679 return DEVICE_API_GET(lin, dev)->set_event_callback(dev, callback, user_data);
698static inline int z_impl_lin_set_rx_filter(
const struct device *dev,
718#include <zephyr/syscalls/lin.h>
APIs and macros for the Zephyr device model.
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1486
static int lin_set_event_callback(const struct device *dev, lin_event_callback_t callback, void *user_data)
Set LIN event callback.
Definition lin.h:676
int lin_wakeup_send(const struct device *dev)
Send LIN wakeup signal.
static uint8_t lin_compute_pid(uint8_t id)
Helper function to compute LIN protected identifier (PID) from frame identifier.
Definition lin.h:424
int lin_receive(const struct device *dev, struct lin_msg *msg, k_timeout_t timeout)
Receive LIN message (commander mode only).
int(* lin_start_t)(const struct device *dev)
Callback API for starting LIN controller.
Definition lin.h:233
int(* lin_wakeup_send_t)(const struct device *dev)
Callback API for sending a LIN wakeup signal.
Definition lin.h:282
int lin_send(const struct device *dev, const struct lin_msg *msg, k_timeout_t timeout)
Send LIN message (commander mode only).
int(* lin_get_config_t)(const struct device *dev, struct lin_config *config)
Callback API for getting LIN configuration.
Definition lin.h:251
uint32_t lin_error_flags_t
Provide a type to hold LIN error flags.
Definition lin.h:119
int(* lin_configure_t)(const struct device *dev, const struct lin_config *config)
Callback API for configuring LIN controller.
Definition lin.h:245
int(* lin_response_t)(const struct device *dev, const struct lin_msg *msg, k_timeout_t timeout)
Callback API for processing LIN response messages.
Definition lin.h:269
lin_mode
LIN operation mode.
Definition lin.h:124
uint32_t lin_config_flags_t
Provide a type to hold LIN controller configuration flags.
Definition lin.h:80
int lin_read(const struct device *dev, struct lin_msg *msg, k_timeout_t timeout)
Start data reception (responder mode only).
int(* lin_set_rx_filter_t)(const struct device *dev, const struct lin_filter *filter)
Callback API for setting a LIN RX filter.
Definition lin.h:295
int lin_start(const struct device *dev)
Start LIN controller.
int lin_set_rx_filter(const struct device *dev, const struct lin_filter *filter)
Set a LIN RX filter (responder mode only).
int(* lin_send_t)(const struct device *dev, const struct lin_msg *msg, k_timeout_t timeout)
Callback API for sending LIN message.
Definition lin.h:257
const struct device * lin_get_transceiver(const struct device *dev)
Get the LIN transceiver device associated with the LIN controller.
int lin_get_config(const struct device *dev, struct lin_config *config)
Get current LIN configuration.
int lin_configure(const struct device *dev, const struct lin_config *config)
Configure LIN controller.
int(* lin_stop_t)(const struct device *dev)
Callback API for stopping LIN controller.
Definition lin.h:239
lin_event_type
LIN event types.
Definition lin.h:93
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.
Definition lin.h:276
static uint8_t lin_get_frame_id(uint8_t pid)
Helper function to extract LIN frame identifier from protected identifier (PID).
Definition lin.h:413
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.
Definition lin.h:288
#define LIN_ID_MASK
LIN frame definitions.
Definition lin.h:51
int(* lin_receive_t)(const struct device *dev, struct lin_msg *msg, k_timeout_t timeout)
Callback API for receiving LIN message.
Definition lin.h:263
void(* lin_event_callback_t)(const struct device *dev, const struct lin_event *event, void *user_data)
LIN event callback function type.
Definition lin.h:212
int lin_stop(const struct device *dev)
Stop LIN controller.
static bool lin_verify_pid(uint8_t pid)
Helper function to verify LIN protected identifier (PID).
Definition lin.h:442
lin_checksum_type
LIN checksum type.
Definition lin.h:85
int lin_response(const struct device *dev, const struct lin_msg *msg, k_timeout_t timeout)
Respond to a received header (responder mode only).
@ LIN_MODE_RESPONDER
LIN responder node.
Definition lin.h:128
@ LIN_MODE_COMMANDER
LIN commander node.
Definition lin.h:126
@ LIN_EVT_RX_WAKEUP
Receive wake up complete event.
Definition lin.h:99
@ LIN_EVT_RX_DATA
Data received event.
Definition lin.h:96
@ LIN_EVT_RX_HEADER
Header received event (responder mode only).
Definition lin.h:94
@ LIN_EVT_TX_DATA
Data transmission complete event.
Definition lin.h:97
@ LIN_EVT_ERR
Error event.
Definition lin.h:100
@ LIN_EVT_TX_HEADER
Header transmission complete event (commander mode only).
Definition lin.h:95
@ LIN_EVT_TX_WAKEUP
Transmit wake up complete event.
Definition lin.h:98
@ LIN_CHECKSUM_CLASSIC
Classic checksum.
Definition lin.h:86
@ LIN_CHECKSUM_ENHANCED
Enhanced checksum.
Definition lin.h:87
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition util_macro.h:44
#define DIV_ROUND_UP(n, d)
Divide and round up.
Definition util.h:348
#define ENOSYS
Function not implemented.
Definition errno.h:83
#define NULL
Definition iar_missing_defs.h:20
#define FIELD_GET(mask, value)
Definition silabs-pinctrl-siwx91x.h:14
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
Runtime device structure (in ROM) per driver instance.
Definition device.h:543
const void * config
Address of device instance config information.
Definition device.h:547
Kernel timeout type.
Definition clock.h:65
LIN configuration structure.
Definition lin.h:134
size_t break_len
LIN break field bit length.
Definition lin.h:140
lin_config_flags_t flags
LIN flags.
Definition lin.h:144
size_t break_delimiter_len
LIN break delimiter bit length.
Definition lin.h:142
uint32_t baudrate
LIN baud rate.
Definition lin.h:138
enum lin_mode mode
LIN operation mode.
Definition lin.h:136
@driver_ops{LIN Controller}
Definition lin.h:360
lin_set_rx_filter_t set_rx_filter
@driver_ops_optional Set a LIN RX filter (responder mode only).
Definition lin.h:380
lin_receive_t receive
@driver_ops_mandatory Receive LIN message (commander mode only).
Definition lin.h:388
lin_wakeup_send_t wakeup_send
@driver_ops_optional Send LIN wakeup signal.
Definition lin.h:400
lin_start_t start
@driver_ops_mandatory Start LIN controller.
Definition lin.h:364
lin_response_t response
@driver_ops_optional Respond to a received header (responder mode only).
Definition lin.h:392
lin_stop_t stop
@driver_ops_mandatory Stop LIN controller.
Definition lin.h:368
lin_set_event_callback_t set_event_callback
@driver_ops_mandatory Set LIN event callback.
Definition lin.h:404
lin_configure_t configure
@driver_ops_mandatory Configure LIN controller.
Definition lin.h:372
lin_get_config_t get_config
@driver_ops_mandatory Get current LIN configuration.
Definition lin.h:376
lin_read_t read
@driver_ops_optional Start data reception (responder mode only).
Definition lin.h:396
lin_send_t send
@driver_ops_mandatory Send LIN message (commander mode only).
Definition lin.h:384
Common LIN driver configuration structure.
Definition lin.h:303
uint32_t min_bitrate
Minimum supported bitrate by the LIN controller/transceiver combination.
Definition lin.h:307
uint32_t bitrate
Initial LIN bitrate.
Definition lin.h:311
uint32_t max_bitrate
Maximum supported bitrate by the LIN controller/transceiver combination.
Definition lin.h:309
const struct device * phy
Pointer to the device structure for the associated LIN transceiver device or NULL.
Definition lin.h:305
Common LIN driver data structure.
Definition lin.h:346
void * callback_data
User data pointer passed to the callback function.
Definition lin.h:354
lin_event_callback_t callback
LIN event callback function pointer or NULL.
Definition lin.h:352
struct lin_config config
Current LIN controller configuration.
Definition lin.h:348
bool started
True if LIN controller is started, false otherwise.
Definition lin.h:350
LIN event structure.
Definition lin.h:177
struct lin_event::@203144216051364135023232003005047351231046251210::@264115246004362217116127123064113351331230354056 data
LIN data event context, if any.
struct lin_event::@203144216051364135023232003005047351231046251210::@377355224204001377217007137166025210227101324354 header
LIN header event context, if any.
lin_error_flags_t error_flags
LIN error event flags, if any.
Definition lin.h:199
uint8_t pid
LIN Protected ID.
Definition lin.h:187
uint8_t bytes_received
Number of data bytes received.
Definition lin.h:194
enum lin_event_type type
LIN event type.
Definition lin.h:179
int status
LIN status code, if any.
Definition lin.h:181
uint8_t checksum
Received checksum.
Definition lin.h:196
LIN frame filter configuration (responder mode only).
Definition lin.h:220
uint8_t primary_pid
LIN PID to match.
Definition lin.h:222
uint8_t secondary_pid
Secondary PID, if any.
Definition lin.h:224
uint8_t mask
LIN mask for ID matching.
Definition lin.h:226
LIN message structure.
Definition lin.h:150
uint8_t id
LIN message ID.
Definition lin.h:152
enum lin_checksum_type checksum_type
Checksum type for the message.
Definition lin.h:169
uint8_t flags
Flags for the message.
Definition lin.h:154
uint8_t data_len
Data length for the message.
Definition lin.h:156
uint8_t data[LIN_MAX_DLEN]
Payload data accessed by bytes.
Definition lin.h:164
uint32_t data_32[DIV_ROUND_UP(LIN_MAX_DLEN, sizeof(uint32_t))]
Payload data accessed by 32-bit words.
Definition lin.h:166