PER Firmware
Loading...
Searching...
No Matches
spmc.c File Reference

Custom SPMC designed for high throughput handling of CAN message streams. More...

#include "spmc.h"
#include "common/rtos/rtos.h"
#include "stm32f407xx.h"
Include dependency graph for spmc.c:

Functions

static size_t get_count (size_t head, size_t tail, bool is_full)
 Helper function to compute the number of items in the buffer given head and tail indices, accounting for wraparound.
 
void SPMC_init (SPMC_t *spmc)
 Initializes the SPMC instance and configures CAN RX interrupts.
 
bool SPMC_enqueue_from_ISR (SPMC_t *spmc, const timestamped_frame_t *incoming_frame)
 Enqueues a received CAN message into the SPMC buffer from an ISR context. ! the two producer ISRs must have the same NVIC priority to prevent preemption of each other in the middle of a write.
 
bool SPMC_master_peek_chunk (SPMC_t *spmc, timestamped_frame_t **first_item)
 Peeks at the next chunk for the master (SD logging) without committing the tail.
 
void SPMC_master_advance_tail (SPMC_t *spmc)
 Advances the master tail pointer by one chunk.
 
size_t SPMC_follower_peek_minis (SPMC_t *spmc, timestamped_frame_t **first_item)
 Peeks at the number of contiguous mini chunks available for the follower without lapping the master's tail without committing the tail.
 
void SPMC_follower_advance_tail (SPMC_t *spmc, size_t minis_consumed)
 Advances the follower tail pointer by a given number of mini chunks.
 

Variables

SPMC_t g_spmc
 
static constexpr uint32_t CAN_RX_IRQ_PRIO = 6
 

Detailed Description

Custom SPMC designed for high throughput handling of CAN message streams.

Author
Irving Wang (irvin.nosp@m.gw@p.nosp@m.urdue.nosp@m..edu)

Function Documentation

◆ get_count()

static size_t get_count ( size_t head,
size_t tail,
bool is_full )
inlinestatic

Helper function to compute the number of items in the buffer given head and tail indices, accounting for wraparound.

Here is the caller graph for this function:

◆ SPMC_enqueue_from_ISR()

bool SPMC_enqueue_from_ISR ( SPMC_t * spmc,
const timestamped_frame_t * incoming_frame )

Enqueues a received CAN message into the SPMC buffer from an ISR context. ! the two producer ISRs must have the same NVIC priority to prevent preemption of each other in the middle of a write.

Parameters
spmcPointer to the SPMC instance.
incoming_framePointer to the timestamped_frame_t containing the received CAN message.
Returns
true if the frame was enqueued successfully, or false if the buffer is full and the frame was dropped.
Here is the caller graph for this function:

◆ SPMC_follower_advance_tail()

void SPMC_follower_advance_tail ( SPMC_t * spmc,
size_t minis_consumed )

Advances the follower tail pointer by a given number of mini chunks.

Here is the caller graph for this function:

◆ SPMC_follower_peek_minis()

size_t SPMC_follower_peek_minis ( SPMC_t * spmc,
timestamped_frame_t ** first_item )

Peeks at the number of contiguous mini chunks available for the follower without lapping the master's tail without committing the tail.

Returns
The number of contiguous mini chunks available.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SPMC_init()

void SPMC_init ( SPMC_t * spmc)

Initializes the SPMC instance and configures CAN RX interrupts.

Parameters
spmcPointer to the SPMC instance to initialize.
Here is the caller graph for this function:

◆ SPMC_master_advance_tail()

void SPMC_master_advance_tail ( SPMC_t * spmc)

Advances the master tail pointer by one chunk.

Warning
this function should only be called by the master consumer context
Parameters
spmcPointer to the SPMC instance.
Here is the caller graph for this function:

◆ SPMC_master_peek_chunk()

bool SPMC_master_peek_chunk ( SPMC_t * spmc,
timestamped_frame_t ** first_item )

Peeks at the next chunk for the master (SD logging) without committing the tail.

Parameters
spmcPointer to the SPMC instance.
first_itemOutput pointer that will point to the first item in the chunk if available, or NULL if no items are available.
Returns
true if a chunk is available, false if no items/not enough are available
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ CAN_RX_IRQ_PRIO

uint32_t CAN_RX_IRQ_PRIO = 6
staticconstexpr

◆ g_spmc

SPMC_t g_spmc