rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
can_timing.c File Reference

CAN (Controller Area Network) bit timing: the segment counts for a bit rate, and the limits of each controller. See can_timing.h. More...

#include "can_timing.h"
#include <string.h>

Functions

void can_timing_limits_mcp2515 (can_timing_limits_t *out, uint32_t crystal_hz)
void can_timing_limits_twai (can_timing_limits_t *out)
 The panel's TWAI on the ESP32-P4, off the 40MHz crystal: even prescalers from 2 to 32768.
static uint32_t sp_error (uint8_t tseg1, uint8_t tq, uint16_t target)
bool can_timing_solve (const can_timing_limits_t *lim, uint32_t bitrate, uint16_t target_permille, can_timing_t *out)
uint32_t can_timing_max_bitrate (const can_timing_limits_t *lim)
bool mcp2515_encode_timing (const can_timing_t *t, uint8_t cnf[3])

Detailed Description

CAN (Controller Area Network) bit timing: the segment counts for a bit rate, and the limits of each controller. See can_timing.h.

SPDX-License-Identifier: MIT

Function Documentation

◆ can_timing_limits_mcp2515()

void can_timing_limits_mcp2515 ( can_timing_limits_t * out,
uint32_t crystal_hz )

The IOmcu's XL2515 (MCP2515-compatible), given its crystal.

◆ can_timing_limits_twai()

void can_timing_limits_twai ( can_timing_limits_t * out)

The panel's TWAI on the ESP32-P4, off the 40MHz crystal: even prescalers from 2 to 32768.

Parameters
outFilled with the limits; NULL is ignored.

◆ can_timing_max_bitrate()

uint32_t can_timing_max_bitrate ( const can_timing_limits_t * lim)

The highest rate this controller can reach exactly, or 0 if none.

◆ can_timing_solve()

bool can_timing_solve ( const can_timing_limits_t * lim,
uint32_t bitrate,
uint16_t target_permille,
can_timing_t * out )

Solve for the segmentation closest to target_permille that hits bitrate exactly.

False when no combination does, which means the source clock cannot make the rate.

◆ mcp2515_encode_timing()

bool mcp2515_encode_timing ( const can_timing_t * t,
uint8_t cnf[3] )

Encode a solution into CNF1..CNF3.

cnf receives three bytes in register order CNF1, CNF2, CNF3.

tseg1 is split into propagation and phase-1 segments here, because that split is the MCP2515's business: both are 1..8 quanta, and the bus does not care where the boundary falls. Returns false if the solution cannot be expressed; a tseg1 of 17 or more has no legal split.