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

The XL2515 over SPI (Serial Peripheral Interface): the part of the CAN (Controller Area Network) driver that touches hardware. More...

#include <stdbool.h>
#include <stdint.h>
#include "link_can.h"

Go to the source code of this file.

Functions

bool xl2515_init (uint32_t bitrate)
 Reset, set the bit timing for bitrate, and enter normal mode.
bool xl2515_send (const link_can_frame_t *f)
 Queue one frame in TXB0 and request transmission.
bool xl2515_recv (link_can_frame_t *f, uint32_t *refused)
 Take one frame from whichever receive buffer has one.
void xl2515_errors (uint8_t *tx_errors, uint8_t *rx_errors, uint8_t *flags)
 The controller's own error counters, for the bring-up report.
bool xl2515_take_overflow (void)
 True if a frame arrived with both receive buffers full since the last call.

Detailed Description

The XL2515 over SPI (Serial Peripheral Interface): the part of the CAN (Controller Area Network) driver that touches hardware.

Everything that can be computed rather than poked (the bit timing, the identifier's layout across four registers, the register map) lives in shared/can with tests. This file holds chip-select edges and the register writes in the order the datasheet gives them.

SPDX-License-Identifier: MIT

Function Documentation

◆ xl2515_errors()

void xl2515_errors ( uint8_t * tx_errors,
uint8_t * rx_errors,
uint8_t * flags )

The controller's own error counters, for the bring-up report.

Either pointer may be NULL.

Parameters
tx_errorsReceives the transmit error counter (TEC). May be NULL.
rx_errorsReceives the receive error counter (REC). May be NULL.
flagsReceives the error flags register (EFLG). May be NULL.

◆ xl2515_init()

bool xl2515_init ( uint32_t bitrate)

Reset, set the bit timing for bitrate, and enter normal mode.

False if the part does not answer. The datasheet guarantees configuration mode after a reset, so a CANSTAT that says otherwise means nothing is listening on the SPI bus: an SPI wiring fault, not a CAN wiring fault.

Parameters
bitrateCAN bit rate in bit/s.
Returns
True when the controller is in normal mode. False when the part does not answer, or the crystal cannot make bitrate.

◆ xl2515_recv()

bool xl2515_recv ( link_can_frame_t * f,
uint32_t * refused )

Take one frame from whichever receive buffer has one.

A buffer holding a frame this link does not carry is consumed, adds 1 to refused (modulo 2^32, NULL counts nothing) and the other buffer is tried. False if none holds a valid frame.

Parameters
fReceives the frame.
refusedCounts the frames this link does not carry. NULL counts nothing.
Returns
True when a valid frame was taken. False when no buffer holds one.

◆ xl2515_send()

bool xl2515_send ( const link_can_frame_t * f)

Queue one frame in TXB0 and request transmission.

False if the buffer is still busy with the previous one.

Parameters
fThe frame to send. NULL is refused, and so is a DLC above 8.
Returns
True when the frame is queued. False when the buffer is still busy with the previous frame, or the identifier cannot be packed.

◆ xl2515_take_overflow()

bool xl2515_take_overflow ( void )

True if a frame arrived with both receive buffers full since the last call.

The flags are sticky and the MCU (microcontroller unit) clears them, which makes this the one record of a frame lost with nothing wrong on the wire: it arrived, it was correct, and there was nowhere to put it. Reading clears them, so the answer covers the time since the last call.

Returns
True when an overflow was seen since the last call.