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

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

#include <stddef.h>
#include <stdint.h>
#include "timestamped_frame.h"
Include dependency graph for spmc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  SPMC_t
 

Functions

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

static constexpr size_t SPMC_CHUNK_NUM_FRAMES = 512
 
static constexpr size_t SPMC_CHUNK_CAPACITY = 12
 
static constexpr size_t SPMC_FRAME_CAPACITY = SPMC_CHUNK_NUM_FRAMES * SPMC_CHUNK_CAPACITY
 
static constexpr size_t SPMC_BYTES_PER_CHUNK = SPMC_CHUNK_NUM_FRAMES * sizeof(timestamped_frame_t)
 
static constexpr size_t SPMC_MINI_NUM_FRAMES = 16
 
SPMC_t g_spmc
 

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

◆ 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

◆ g_spmc

SPMC_t g_spmc
extern

◆ SPMC_BYTES_PER_CHUNK

size_t SPMC_BYTES_PER_CHUNK = SPMC_CHUNK_NUM_FRAMES * sizeof(timestamped_frame_t)
staticconstexpr

◆ SPMC_CHUNK_CAPACITY

size_t SPMC_CHUNK_CAPACITY = 12
staticconstexpr

◆ SPMC_CHUNK_NUM_FRAMES

size_t SPMC_CHUNK_NUM_FRAMES = 512
staticconstexpr

◆ SPMC_FRAME_CAPACITY

size_t SPMC_FRAME_CAPACITY = SPMC_CHUNK_NUM_FRAMES * SPMC_CHUNK_CAPACITY
staticconstexpr

◆ SPMC_MINI_NUM_FRAMES

size_t SPMC_MINI_NUM_FRAMES = 16
staticconstexpr