File syn_can.h¶
FileList > drivers > syn_can.h
Go to the source code of this file
CAN bus driver abstraction. More...
#include "../common/syn_defs.h"#include "../port/syn_port_can.h"#include <stdbool.h>#include <stdint.h>
Classes¶
| Type | Name |
|---|---|
| struct | SYN_CAN CAN bus instance — port, bitrate, callbacks, stats. |
| struct | SYN_CAN_Frame CAN bus frame — standard/extended ID, classic CAN or CAN FD. |
Public Types¶
| Type | Name |
|---|---|
| typedef void(* | SYN_CAN_Callback CAN receive callback. |
Public Functions¶
| Type | Name |
|---|---|
| SYN_Status | syn_can_init (SYN_CAN * can, uint8_t port, uint32_t bitrate) Initialize CAN driver. |
| void | syn_can_on_receive (SYN_CAN * can, SYN_CAN_Callback cb, void * ctx) Register receive callback. |
| void | syn_can_poll (SYN_CAN * can) Poll for received frames and dispatch callback. |
| bool | syn_can_send (SYN_CAN * can, const SYN_CAN_Frame * frame) Send a CAN frame. |
| void | syn_can_set_filter (const SYN_CAN * can, uint32_t id, uint32_t mask) Set hardware acceptance filter. |
Macros¶
| Type | Name |
|---|---|
| define | SYN_CAN_MAX_DATA_LEN 8U |
Detailed Description¶
Port-based CAN driver with frame send/receive and callback dispatch.
Usage:
static SYN_CAN can;
syn_can_init(&can, 0, 500000); // CAN0 at 500kbps
syn_can_on_receive(&can, my_rx_handler, NULL);
SYN_CAN_Frame tx = { .id = 0x100, .dlc = 2 };
tx.data[0] = 0x42; tx.data[1] = 0x00;
syn_can_send(&can, &tx);
// In main loop:
syn_can_poll(&can); // dispatches received frames
Public Types Documentation¶
typedef SYN_CAN_Callback¶
CAN receive callback.
Parameters:
frameReceived frame.ctxUser context.
Public Functions Documentation¶
function syn_can_init¶
Initialize CAN driver.
Parameters:
canCAN instance.portCAN peripheral port number.bitrateBitrate in bps (e.g. 500000).
Returns:
SYN_OK on success.
function syn_can_on_receive¶
Register receive callback.
Parameters:
canCAN instance.cbCallback function.ctxUser context.
function syn_can_poll¶
Poll for received frames and dispatch callback.
Call from your main loop.
Parameters:
canCAN instance.
function syn_can_send¶
Send a CAN frame.
Parameters:
canCAN instance.frameFrame to send.
Returns:
true if frame was queued successfully.
function syn_can_set_filter¶
Set hardware acceptance filter.
Parameters:
canCAN instance.idFilter ID.maskFilter mask.
Macro Definition Documentation¶
define SYN_CAN_MAX_DATA_LEN¶
Standard CAN payload size (8 bytes)
The documentation for this class was generated from the following file src/syntropic/drivers/syn_can.h