|
PebbleOS v4.47.0-1075-g013613c8a
|
#include <stdbool.h>#include <stdint.h>#include <pbl/device.h>#include <pbl/kernel/mutex.h>#include <pbl/kernel/sem.h>#include <pbl/kernel/types.h>#include <pbl/util/bits.h>Data Structures | |
| struct | pbl_can_frame |
| A CAN or CAN FD frame. More... | |
| struct | pbl_can_config |
| Bus configuration. More... | |
| struct | pbl_can_filter |
Acceptance filter: frames whose identifier matches id in the bits of mask. More... | |
| struct | pbl_can_timing |
| Bit timing of one phase, in time quanta. More... | |
| struct | pbl_can_timing_limits |
| Bit timing limits of one phase. More... | |
| struct | pbl_can_err_cnt |
| Error counters. More... | |
| struct | pbl_can_stats |
| Counts of errors and bus off events, since the controller was initialized. More... | |
| struct | pbl_can_ops |
| Controller driver operations. More... | |
| struct | pbl_can |
| A CAN controller. More... | |
| union | pbl_can_frame.__unnamed6__ |
| Data. More... | |
Macros | |
| #define | PBL_CAN_STD_ID_MASK 0x7ffU |
| Largest standard (11-bit) identifier. | |
| #define | PBL_CAN_EXT_ID_MASK 0x1fffffffU |
| Largest extended (29-bit) identifier. | |
| #define | PBL_CAN_MAX_LEN 8U |
| Most data bytes of a CAN frame. | |
| #define | PBL_CAN_FD_MAX_LEN 64U |
| Most data bytes of a CAN FD frame. | |
| #define | PBL_CAN_STATE_DEFINE(sym, _tx_slots) |
Define the class state of controller sym, for the PBL_CAN_*_DEFINE() macro of a driver. | |
| #define | PBL_CAN_INIT(sym, _name, _parent, _ops, _limits, _data_limits, _modes, _num_filters) |
Initializer for the struct pbl_can of controller sym. | |
Frame flags | |
| #define | PBL_CAN_FRAME_IDE PBL_BIT(0) |
| Extended (29-bit) identifier. | |
| #define | PBL_CAN_FRAME_RTR PBL_BIT(1) |
| Remote frame, CAN only. | |
| #define | PBL_CAN_FRAME_FDF PBL_BIT(2) |
| CAN FD frame. | |
| #define | PBL_CAN_FRAME_BRS PBL_BIT(3) |
| CAN FD frame whose data phase goes at the data bit rate. | |
| #define | PBL_CAN_FRAME_ESI PBL_BIT(4) |
| CAN FD frame from an error passive node, on reception. | |
Modes | |
| #define | PBL_CAN_MODE_LOOPBACK PBL_BIT(0) |
| Receive the frames sent, without driving the bus. | |
| #define | PBL_CAN_MODE_LISTEN_ONLY PBL_BIT(1) |
| Receive only, without acknowledging frames or signalling errors; sending is refused. | |
| #define | PBL_CAN_MODE_FD PBL_BIT(2) |
| Send and receive CAN FD frames, as ISO 11898-1:2015 specifies them. | |
| #define | PBL_CAN_MODE_FD_NON_ISO PBL_BIT(3) |
| With PBL_CAN_MODE_FD, CAN FD frames as first specified, without the stuff count. | |
| #define | PBL_CAN_MODE_ONE_SHOT PBL_BIT(4) |
| Send each frame once, without retransmitting it after an error or a lost arbitration. | |
| #define | PBL_CAN_MODE_MANUAL_RECOVERY PBL_BIT(5) |
| Stay bus off until pbl_can_recover(), instead of recovering on its own. | |
Typedefs | |
| typedef void(* | pbl_can_rx_callback_t) (const struct pbl_can *can, const struct pbl_can_frame *frame, void *arg) |
| Receive callback, called from the controller's interrupt for each frame accepted. | |
| typedef void(* | pbl_can_tx_callback_t) (const struct pbl_can *can, int status, void *arg) |
| Transmit callback, called from the controller's interrupt once a frame is done. | |
| typedef void(* | pbl_can_state_callback_t) (const struct pbl_can *can, enum pbl_can_bus_state state, struct pbl_can_err_cnt cnt, void *arg) |
| State callback, called from the controller's interrupt when its state changes. | |
Enumerations | |
| enum | pbl_can_bus_state { PBL_CAN_STATE_STOPPED , PBL_CAN_STATE_ERROR_ACTIVE , PBL_CAN_STATE_ERROR_WARNING , PBL_CAN_STATE_ERROR_PASSIVE , PBL_CAN_STATE_BUS_OFF } |
| Fault confinement state. More... | |
| enum | pbl_can_error { PBL_CAN_ERROR_BIT , PBL_CAN_ERROR_STUFF , PBL_CAN_ERROR_FORM , PBL_CAN_ERROR_ACK , PBL_CAN_ERROR_CRC , PBL_CAN_ERROR_ARBITRATION_LOST , PBL_CAN_ERROR_RX_OVERRUN , PBL_CAN_ERROR_COUNT } |
| Kinds of errors the controller counts. More... | |
Functions | |
| int | pbl_can_dev_init (const struct pbl_device *dev) |
| Device init of every controller: calls the driver's init. | |
| void | pbl_can_receive (const struct pbl_can *can, const struct pbl_can_frame *frame) |
| Hand a received frame to the receive callback. | |
| void | pbl_can_tx_done (const struct pbl_can *can, pbl_can_tx_callback_t cb, void *arg, int status) |
| Complete a frame given to the driver's send(). | |
| void | pbl_can_report_state (const struct pbl_can *can, enum pbl_can_bus_state state, struct pbl_can_err_cnt cnt) |
| Report a state change. | |
| void | pbl_can_report_error (const struct pbl_can *can, enum pbl_can_error error) |
| Count an error. | |
| int | pbl_can_calc_timing (const struct pbl_can_timing_limits *limits, uint32_t clock, uint32_t bitrate, uint16_t sample_point, struct pbl_can_timing *timing) |
| Compute the bit timing of one phase. | |
| uint8_t | pbl_can_dlc_to_len (uint8_t dlc) |
| Get the bytes of a frame of a data length code. | |
| uint8_t | pbl_can_len_to_dlc (uint8_t len) |
Get the data length code of a frame of len bytes. | |
| int | pbl_can_configure (const struct pbl_can *can, const struct pbl_can_config *cfg) |
| Set the bit rates and mode, while stopped. | |
| int | pbl_can_config_get (const struct pbl_can *can, struct pbl_can_config *cfg) |
| Get the configuration. | |
| int | pbl_can_add_filter (const struct pbl_can *can, const struct pbl_can_filter *filter) |
| Add an acceptance filter, while stopped. | |
| int | pbl_can_remove_filter (const struct pbl_can *can, int idx) |
| Remove an acceptance filter, while stopped. | |
| void | pbl_can_set_rx_callback (const struct pbl_can *can, pbl_can_rx_callback_t cb, void *arg) |
| Set the receive callback. | |
| void | pbl_can_set_state_callback (const struct pbl_can *can, pbl_can_state_callback_t cb, void *arg) |
| Set the state callback. | |
| int | pbl_can_start (const struct pbl_can *can) |
| Join the bus, with the configuration and filters given while stopped. | |
| int | pbl_can_stop (const struct pbl_can *can) |
| Leave the bus. | |
| int | pbl_can_send (const struct pbl_can *can, const struct pbl_can_frame *frame, pbl_timeout_t timeout, pbl_can_tx_callback_t cb, void *arg) |
| Send a frame. | |
| int | pbl_can_get_state (const struct pbl_can *can, enum pbl_can_bus_state *state, struct pbl_can_err_cnt *cnt) |
| Get the state and error counters. | |
| int | pbl_can_recover (const struct pbl_can *can) |
| Start the recovery from bus off, with PBL_CAN_MODE_MANUAL_RECOVERY. | |
| int | pbl_can_get_stats (const struct pbl_can *can, struct pbl_can_stats *stats) |
| Get the error counts. | |
Variables | |
| const struct pbl_device_class | pbl_can_class |
| Class of the CAN controllers. | |
| const struct pbl_can *const | CAN_BUS |
| The controller of the board's CAN bus connector. | |