Zephyr API Documentation 4.0.0-rc2
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
can_sja1000.h File Reference

API for NXP SJA1000 (and compatible) CAN controller frontend drivers. More...

Go to the source code of this file.

Data Structures

struct  can_sja1000_config
 SJA1000 driver internal configuration structure. More...
 
struct  can_sja1000_rx_filter
 SJA1000 driver internal RX filter structure. More...
 
struct  can_sja1000_data
 SJA1000 driver internal data structure. More...
 

Macros

#define CAN_SJA1000_TIMING_MIN_INITIALIZER
 SJA1000 specific static initializer for a minimum can_timing struct.
 
#define CAN_SJA1000_TIMING_MAX_INITIALIZER
 SJA1000 specific static initializer for a maximum can_timing struct.
 
#define CAN_SJA1000_DT_CONFIG_GET(node_id, _custom, _read_reg, _write_reg, _ocr, _cdr, _min_bitrate)
 Static initializer for can_sja1000_config struct.
 
#define CAN_SJA1000_DT_CONFIG_INST_GET(inst, _custom, _read_reg, _write_reg, _ocr, _cdr, _min_bitrate)
 Static initializer for can_sja1000_config struct from a DT_DRV_COMPAT instance.
 
#define CAN_SJA1000_DATA_INITIALIZER(_custom)
 Initializer for a can_sja1000_data struct.
 
SJA1000 Output Control Register (OCR) bits
#define CAN_SJA1000_OCR_OCMODE_MASK   GENMASK(1, 0)
 
#define CAN_SJA1000_OCR_OCPOL0   BIT(2)
 
#define CAN_SJA1000_OCR_OCTN0   BIT(3)
 
#define CAN_SJA1000_OCR_OCTP0   BIT(4)
 
#define CAN_SJA1000_OCR_OCPOL1   BIT(5)
 
#define CAN_SJA1000_OCR_OCTN1   BIT(6)
 
#define CAN_SJA1000_OCR_OCTP1   BIT(7)
 
#define CAN_SJA1000_OCR_OCMODE_BIPHASE   FIELD_PREP(CAN_SJA1000_OCR_OCMODE_MASK, 0U)
 
#define CAN_SJA1000_OCR_OCMODE_TEST   FIELD_PREP(CAN_SJA1000_OCR_OCMODE_MASK, 1U)
 
#define CAN_SJA1000_OCR_OCMODE_NORMAL   FIELD_PREP(CAN_SJA1000_OCR_OCMODE_MASK, 2U)
 
#define CAN_SJA1000_OCR_OCMODE_CLOCK   FIELD_PREP(CAN_SJA1000_OCR_OCMODE_MASK, 3U)
 
SJA1000 Clock Divider Register (CDR) bits
#define CAN_SJA1000_CDR_CD_MASK   GENMASK(2, 0)
 
#define CAN_SJA1000_CDR_CLOCK_OFF   BIT(3)
 
#define CAN_SJA1000_CDR_RXINTEN   BIT(5)
 
#define CAN_SJA1000_CDR_CBP   BIT(6)
 
#define CAN_SJA1000_CDR_CAN_MODE   BIT(7)
 
#define CAN_SJA1000_CDR_CD_DIV1   FIELD_PREP(CAN_SJA1000_CDR_CD_MASK, 7U)
 
#define CAN_SJA1000_CDR_CD_DIV2   FIELD_PREP(CAN_SJA1000_CDR_CD_MASK, 0U)
 
#define CAN_SJA1000_CDR_CD_DIV4   FIELD_PREP(CAN_SJA1000_CDR_CD_MASK, 1U)
 
#define CAN_SJA1000_CDR_CD_DIV6   FIELD_PREP(CAN_SJA1000_CDR_CD_MASK, 2U)
 
#define CAN_SJA1000_CDR_CD_DIV8   FIELD_PREP(CAN_SJA1000_CDR_CD_MASK, 3U)
 
#define CAN_SJA1000_CDR_CD_DIV10   FIELD_PREP(CAN_SJA1000_CDR_CD_MASK, 4U)
 
#define CAN_SJA1000_CDR_CD_DIV12   FIELD_PREP(CAN_SJA1000_CDR_CD_MASK, 5U)
 
#define CAN_SJA1000_CDR_CD_DIV14   FIELD_PREP(CAN_SJA1000_CDR_CD_MASK, 6U)
 

Typedefs

typedef void(* can_sja1000_write_reg_t) (const struct device *dev, uint8_t reg, uint8_t val)
 SJA1000 driver front-end callback for writing a register value.
 
typedef uint8_t(* can_sja1000_read_reg_t) (const struct device *dev, uint8_t reg)
 SJA1000 driver front-end callback for reading a register value.
 

Functions

int can_sja1000_set_timing (const struct device *dev, const struct can_timing *timing)
 SJA1000 callback API upon setting CAN bus timing See can_set_timing() for argument description.
 
int can_sja1000_get_capabilities (const struct device *dev, can_mode_t *cap)
 SJA1000 callback API upon getting CAN controller capabilities See can_get_capabilities() for argument description.
 
int can_sja1000_start (const struct device *dev)
 SJA1000 callback API upon starting CAN controller See can_start() for argument description.
 
int can_sja1000_stop (const struct device *dev)
 SJA1000 callback API upon stopping CAN controller See can_stop() for argument description.
 
int can_sja1000_set_mode (const struct device *dev, can_mode_t mode)
 SJA1000 callback API upon setting CAN controller mode See can_set_mode() for argument description.
 
int can_sja1000_send (const struct device *dev, const struct can_frame *frame, k_timeout_t timeout, can_tx_callback_t callback, void *user_data)
 SJA1000 callback API upon sending a CAN frame See can_send() for argument description.
 
int can_sja1000_add_rx_filter (const struct device *dev, can_rx_callback_t callback, void *user_data, const struct can_filter *filter)
 SJA1000 callback API upon adding an RX filter See can_add_rx_callback() for argument description.
 
void can_sja1000_remove_rx_filter (const struct device *dev, int filter_id)
 SJA1000 callback API upon removing an RX filter See can_remove_rx_filter() for argument description.
 
int can_sja1000_get_state (const struct device *dev, enum can_state *state, struct can_bus_err_cnt *err_cnt)
 SJA1000 callback API upon getting the CAN controller state See can_get_state() for argument description.
 
void can_sja1000_set_state_change_callback (const struct device *dev, can_state_change_callback_t callback, void *user_data)
 SJA1000 callback API upon setting a state change callback See can_set_state_change_callback() for argument description.
 
int can_sja1000_get_max_filters (const struct device *dev, bool ide)
 SJA1000 callback API upon getting the maximum number of concurrent CAN RX filters See can_get_max_filters() for argument description.
 
void can_sja1000_isr (const struct device *dev)
 SJA1000 IRQ handler callback.
 
int can_sja1000_init (const struct device *dev)
 SJA1000 driver initialization callback.
 

Detailed Description

API for NXP SJA1000 (and compatible) CAN controller frontend drivers.

Macro Definition Documentation

◆ CAN_SJA1000_CDR_CAN_MODE

#define CAN_SJA1000_CDR_CAN_MODE   BIT(7)

◆ CAN_SJA1000_CDR_CBP

#define CAN_SJA1000_CDR_CBP   BIT(6)

◆ CAN_SJA1000_CDR_CD_DIV1

#define CAN_SJA1000_CDR_CD_DIV1   FIELD_PREP(CAN_SJA1000_CDR_CD_MASK, 7U)

◆ CAN_SJA1000_CDR_CD_DIV10

#define CAN_SJA1000_CDR_CD_DIV10   FIELD_PREP(CAN_SJA1000_CDR_CD_MASK, 4U)

◆ CAN_SJA1000_CDR_CD_DIV12

#define CAN_SJA1000_CDR_CD_DIV12   FIELD_PREP(CAN_SJA1000_CDR_CD_MASK, 5U)

◆ CAN_SJA1000_CDR_CD_DIV14

#define CAN_SJA1000_CDR_CD_DIV14   FIELD_PREP(CAN_SJA1000_CDR_CD_MASK, 6U)

◆ CAN_SJA1000_CDR_CD_DIV2

#define CAN_SJA1000_CDR_CD_DIV2   FIELD_PREP(CAN_SJA1000_CDR_CD_MASK, 0U)

◆ CAN_SJA1000_CDR_CD_DIV4

#define CAN_SJA1000_CDR_CD_DIV4   FIELD_PREP(CAN_SJA1000_CDR_CD_MASK, 1U)

◆ CAN_SJA1000_CDR_CD_DIV6

#define CAN_SJA1000_CDR_CD_DIV6   FIELD_PREP(CAN_SJA1000_CDR_CD_MASK, 2U)

◆ CAN_SJA1000_CDR_CD_DIV8

#define CAN_SJA1000_CDR_CD_DIV8   FIELD_PREP(CAN_SJA1000_CDR_CD_MASK, 3U)

◆ CAN_SJA1000_CDR_CD_MASK

#define CAN_SJA1000_CDR_CD_MASK   GENMASK(2, 0)

◆ CAN_SJA1000_CDR_CLOCK_OFF

#define CAN_SJA1000_CDR_CLOCK_OFF   BIT(3)

◆ CAN_SJA1000_CDR_RXINTEN

#define CAN_SJA1000_CDR_RXINTEN   BIT(5)

◆ CAN_SJA1000_DATA_INITIALIZER

#define CAN_SJA1000_DATA_INITIALIZER ( _custom)
Value:
{ \
.custom = _custom, \
}

Initializer for a can_sja1000_data struct.

Parameters
_customPointer to custom driver frontend data structure

◆ CAN_SJA1000_DT_CONFIG_GET

#define CAN_SJA1000_DT_CONFIG_GET ( node_id,
_custom,
_read_reg,
_write_reg,
_ocr,
_cdr,
_min_bitrate )
Value:
{ \
.common = CAN_DT_DRIVER_CONFIG_GET(node_id, _min_bitrate, 1000000), \
.read_reg = _read_reg, \
.write_reg = _write_reg, \
.ocr = _ocr, \
.cdr = _cdr, \
.custom = _custom, \
}

Static initializer for can_sja1000_config struct.

Parameters
node_idDevicetree node identifier
_customPointer to custom driver frontend configuration structure
_read_regDriver frontend SJA100 register read function
_write_regDriver frontend SJA100 register write function
_ocrInitial SJA1000 Output Control Register (OCR) value
_cdrInitial SJA1000 Clock Divider Register (CDR) value
_min_bitrateminimum bitrate supported by the CAN controller

◆ CAN_SJA1000_DT_CONFIG_INST_GET

#define CAN_SJA1000_DT_CONFIG_INST_GET ( inst,
_custom,
_read_reg,
_write_reg,
_ocr,
_cdr,
_min_bitrate )
Value:
CAN_SJA1000_DT_CONFIG_GET(DT_DRV_INST(inst), _custom, _read_reg, _write_reg, _ocr, _cdr, \
_min_bitrate)
#define CAN_SJA1000_DT_CONFIG_GET(node_id, _custom, _read_reg, _write_reg, _ocr, _cdr, _min_bitrate)
Static initializer for can_sja1000_config struct.
Definition can_sja1000.h:124
#define DT_DRV_INST(inst)
Node identifier for an instance of a DT_DRV_COMPAT compatible.
Definition devicetree.h:3802

Static initializer for can_sja1000_config struct from a DT_DRV_COMPAT instance.

Parameters
instDT_DRV_COMPAT instance number
_customPointer to custom driver frontend configuration structure
_read_regDriver frontend SJA100 register read function
_write_regDriver frontend SJA100 register write function
_ocrInitial SJA1000 Output Control Register (OCR) value
_cdrInitial SJA1000 Clock Divider Register (CDR) value
_min_bitrateminimum bitrate supported by the CAN controller
See also
CAN_SJA1000_DT_CONFIG_GET()

◆ CAN_SJA1000_OCR_OCMODE_BIPHASE

#define CAN_SJA1000_OCR_OCMODE_BIPHASE   FIELD_PREP(CAN_SJA1000_OCR_OCMODE_MASK, 0U)

◆ CAN_SJA1000_OCR_OCMODE_CLOCK

#define CAN_SJA1000_OCR_OCMODE_CLOCK   FIELD_PREP(CAN_SJA1000_OCR_OCMODE_MASK, 3U)

◆ CAN_SJA1000_OCR_OCMODE_MASK

#define CAN_SJA1000_OCR_OCMODE_MASK   GENMASK(1, 0)

◆ CAN_SJA1000_OCR_OCMODE_NORMAL

#define CAN_SJA1000_OCR_OCMODE_NORMAL   FIELD_PREP(CAN_SJA1000_OCR_OCMODE_MASK, 2U)

◆ CAN_SJA1000_OCR_OCMODE_TEST

#define CAN_SJA1000_OCR_OCMODE_TEST   FIELD_PREP(CAN_SJA1000_OCR_OCMODE_MASK, 1U)

◆ CAN_SJA1000_OCR_OCPOL0

#define CAN_SJA1000_OCR_OCPOL0   BIT(2)

◆ CAN_SJA1000_OCR_OCPOL1

#define CAN_SJA1000_OCR_OCPOL1   BIT(5)

◆ CAN_SJA1000_OCR_OCTN0

#define CAN_SJA1000_OCR_OCTN0   BIT(3)

◆ CAN_SJA1000_OCR_OCTN1

#define CAN_SJA1000_OCR_OCTN1   BIT(6)

◆ CAN_SJA1000_OCR_OCTP0

#define CAN_SJA1000_OCR_OCTP0   BIT(4)

◆ CAN_SJA1000_OCR_OCTP1

#define CAN_SJA1000_OCR_OCTP1   BIT(7)

◆ CAN_SJA1000_TIMING_MAX_INITIALIZER

#define CAN_SJA1000_TIMING_MAX_INITIALIZER
Value:
{ \
.sjw = 4, \
.prop_seg = 0, \
.phase_seg1 = 16, \
.phase_seg2 = 8, \
.prescaler = 64 \
}

SJA1000 specific static initializer for a maximum can_timing struct.

◆ CAN_SJA1000_TIMING_MIN_INITIALIZER

#define CAN_SJA1000_TIMING_MIN_INITIALIZER
Value:
{ \
.sjw = 1, \
.prop_seg = 0, \
.phase_seg1 = 1, \
.phase_seg2 = 1, \
.prescaler = 1 \
}

SJA1000 specific static initializer for a minimum can_timing struct.

Typedef Documentation

◆ can_sja1000_read_reg_t

typedef uint8_t(* can_sja1000_read_reg_t) (const struct device *dev, uint8_t reg)

SJA1000 driver front-end callback for reading a register value.

Parameters
devPointer to the device structure for the driver instance.
regRegister offset
Return values
Registervalue

◆ can_sja1000_write_reg_t

typedef void(* can_sja1000_write_reg_t) (const struct device *dev, uint8_t reg, uint8_t val)

SJA1000 driver front-end callback for writing a register value.

Parameters
devPointer to the device structure for the driver instance.
regRegister offset
valRegister value

Function Documentation

◆ can_sja1000_add_rx_filter()

int can_sja1000_add_rx_filter ( const struct device * dev,
can_rx_callback_t callback,
void * user_data,
const struct can_filter * filter )

SJA1000 callback API upon adding an RX filter See can_add_rx_callback() for argument description.

◆ can_sja1000_get_capabilities()

int can_sja1000_get_capabilities ( const struct device * dev,
can_mode_t * cap )

SJA1000 callback API upon getting CAN controller capabilities See can_get_capabilities() for argument description.

◆ can_sja1000_get_max_filters()

int can_sja1000_get_max_filters ( const struct device * dev,
bool ide )

SJA1000 callback API upon getting the maximum number of concurrent CAN RX filters See can_get_max_filters() for argument description.

◆ can_sja1000_get_state()

int can_sja1000_get_state ( const struct device * dev,
enum can_state * state,
struct can_bus_err_cnt * err_cnt )

SJA1000 callback API upon getting the CAN controller state See can_get_state() for argument description.

◆ can_sja1000_init()

int can_sja1000_init ( const struct device * dev)

SJA1000 driver initialization callback.

Parameters
devPointer to the device structure for the driver instance.

◆ can_sja1000_isr()

void can_sja1000_isr ( const struct device * dev)

SJA1000 IRQ handler callback.

Parameters
devPointer to the device structure for the driver instance.

◆ can_sja1000_remove_rx_filter()

void can_sja1000_remove_rx_filter ( const struct device * dev,
int filter_id )

SJA1000 callback API upon removing an RX filter See can_remove_rx_filter() for argument description.

◆ can_sja1000_send()

int can_sja1000_send ( const struct device * dev,
const struct can_frame * frame,
k_timeout_t timeout,
can_tx_callback_t callback,
void * user_data )

SJA1000 callback API upon sending a CAN frame See can_send() for argument description.

◆ can_sja1000_set_mode()

int can_sja1000_set_mode ( const struct device * dev,
can_mode_t mode )

SJA1000 callback API upon setting CAN controller mode See can_set_mode() for argument description.

◆ can_sja1000_set_state_change_callback()

void can_sja1000_set_state_change_callback ( const struct device * dev,
can_state_change_callback_t callback,
void * user_data )

SJA1000 callback API upon setting a state change callback See can_set_state_change_callback() for argument description.

◆ can_sja1000_set_timing()

int can_sja1000_set_timing ( const struct device * dev,
const struct can_timing * timing )

SJA1000 callback API upon setting CAN bus timing See can_set_timing() for argument description.

◆ can_sja1000_start()

int can_sja1000_start ( const struct device * dev)

SJA1000 callback API upon starting CAN controller See can_start() for argument description.

◆ can_sja1000_stop()

int can_sja1000_stop ( const struct device * dev)

SJA1000 callback API upon stopping CAN controller See can_stop() for argument description.