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 <string.h>

Go to the source code of this file.

Classes

struct  timestamped_frame_t
 
struct  SPMC_t
 

Macros

#define SPMC_BUS_ID_Pos   (31U)
 
#define SPMC_IS_EXTID_Pos   (30U)
 

Enumerations

enum  SPMC_status_t : int { SPMC_OK = 0 , SPMC_FULL = -1 , SPMC_EMPTY = -2 }
 

Functions

void SPMC_init (SPMC_t *spmc)
 Initializes the SPMC instance and configures CAN RX interrupts.
 
SPMC_status_t SPMC_enqueue_from_ISR (SPMC_t *spmc, 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 priority to prevent preemption in the middle of a write.
 
size_t SPMC_master_peek_all (SPMC_t *spmc, timestamped_frame_t **first_item, size_t *total_unread)
 Peeks at the next batch of frames available for processing by the master (SD logging) without committing the tail. Intended to be used with a DMA operation.
 
void SPMC_master_commit_tail (SPMC_t *spmc, size_t num_consumed)
 Commits the specified number of consumed frames by advancing the master tail pointer.
 
SPMC_status_t SPMC_follower_pop (SPMC_t *spmc, timestamped_frame_t **out, uint32_t *consecutive_items)
 Pops a single frame for the follower (Ethernet transmission) and advances the follower tail pointer. todo: this function is incomplete todo: optimize for DMA batch transfers, similar to the master's function.
 

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)
Shriya Balu (balu@.nosp@m.purd.nosp@m.ue.ed.nosp@m.u)

Function Documentation

◆ SPMC_enqueue_from_ISR()

SPMC_status_t SPMC_enqueue_from_ISR ( SPMC_t * spmc,
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 priority to prevent preemption 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
SPMC_OK if the frame was enqueued successfully, or SPMC_FULL if the buffer is full and the frame was dropped.

◆ SPMC_follower_pop()

SPMC_status_t SPMC_follower_pop ( SPMC_t * spmc,
timestamped_frame_t ** out,
uint32_t * consecutive_items )

Pops a single frame for the follower (Ethernet transmission) and advances the follower tail pointer. todo: this function is incomplete todo: optimize for DMA batch transfers, similar to the master's function.

Parameters
spmcPointer to the SPMC instance.
outOutput pointer to the popped frame.
consecutive_itemsOutput pointer to the number of consecutive frames available.
Returns
SPMC_OK if a frame was successfully popped, or SPMC_EMPTY if the buffer is empty.

◆ 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.

◆ SPMC_master_commit_tail()

void SPMC_master_commit_tail ( SPMC_t * spmc,
size_t num_consumed )

Commits the specified number of consumed frames by advancing the master tail pointer.

Parameters
spmcPointer to the SPMC instance.
num_consumedThe number of frames to commit.

◆ SPMC_master_peek_all()

size_t SPMC_master_peek_all ( SPMC_t * spmc,
timestamped_frame_t ** first_item,
size_t * total_unread )

Peeks at the next batch of frames available for processing by the master (SD logging) without committing the tail. Intended to be used with a DMA operation.

Parameters
spmcPointer to the SPMC instance.
first_itemOutput pointer that will point to the first item in the batch if available, or NULL if no items are available.
total_unreadOutput pointer that will be set to the total number of unread frames available in the buffer.
Returns
The number of contiguous items available in the batch.