Skip to content

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.

typedef void(* SYN_CAN_Callback) (const SYN_CAN_Frame *frame, void *ctx);

Parameters:

  • frame Received frame.
  • ctx User context.

Public Functions Documentation

function syn_can_init

Initialize CAN driver.

SYN_Status syn_can_init (
    SYN_CAN * can,
    uint8_t port,
    uint32_t bitrate
) 

Parameters:

  • can CAN instance.
  • port CAN peripheral port number.
  • bitrate Bitrate in bps (e.g. 500000).

Returns:

SYN_OK on success.


function syn_can_on_receive

Register receive callback.

void syn_can_on_receive (
    SYN_CAN * can,
    SYN_CAN_Callback cb,
    void * ctx
) 

Parameters:

  • can CAN instance.
  • cb Callback function.
  • ctx User context.

function syn_can_poll

Poll for received frames and dispatch callback.

void syn_can_poll (
    SYN_CAN * can
) 

Call from your main loop.

Parameters:

  • can CAN instance.

function syn_can_send

Send a CAN frame.

bool syn_can_send (
    SYN_CAN * can,
    const SYN_CAN_Frame * frame
) 

Parameters:

  • can CAN instance.
  • frame Frame to send.

Returns:

true if frame was queued successfully.


function syn_can_set_filter

Set hardware acceptance filter.

void syn_can_set_filter (
    const SYN_CAN * can,
    uint32_t id,
    uint32_t mask
) 

Parameters:

  • can CAN instance.
  • id Filter ID.
  • mask Filter mask.

Macro Definition Documentation

define SYN_CAN_MAX_DATA_LEN

#define SYN_CAN_MAX_DATA_LEN `8U`

Standard CAN payload size (8 bytes)



The documentation for this class was generated from the following file src/syntropic/drivers/syn_can.h