CAN programming interface environment
Version 3.10
Loading...
Searching...
No Matches
cp_fifo.h File Reference

Detailed Description

A CAN frame FIFO can be assigned to a message buffer by calling CpCoreFifoConfig(). This file defines the structure of a CAN frame FIFO (CpFifo_s) and inline functions to access the FIFO.

#include "canpie.h"

Data Structures

struct  CpFifo_s
 

Functions

void CpFifoClear (CpFifo_ts *ptsFifoV)
 
bool_t CpFifoCopy (CpFifo_ts *ptsDestFifoV, CpFifo_ts *ptsSrcFifoV)
 
CpCanMsg_tsCpFifoDataInPtr (CpFifo_ts *ptsFifoV)
 
CpCanMsg_tsCpFifoDataOutPtr (CpFifo_ts *ptsFifoV)
 
uint32_t CpFifoFree (CpFifo_ts *ptsFifoV)
 
void CpFifoIncIn (CpFifo_ts *ptsFifoV)
 
void CpFifoIncOut (CpFifo_ts *ptsFifoV)
 
void CpFifoInit (CpFifo_ts *ptsFifoV, CpCanMsg_ts *ptsCanMsgV, uint32_t ulSizeV)
 
bool_t CpFifoIsEmpty (CpFifo_ts *ptsFifoV)
 
bool_t CpFifoIsFull (CpFifo_ts *ptsFifoV)
 
uint32_t CpFifoPending (CpFifo_ts *ptsFifoV)
 

Function Documentation

◆ CpFifoClear()

void CpFifoClear ( CpFifo_ts * ptsFifoV)
Parameters
[in]ptsFifoVPointer to CAN frame FIFO

This function clears all entries inside the FIFO.

◆ CpFifoCopy()

bool_t CpFifoCopy ( CpFifo_ts * ptsDestFifoV,
CpFifo_ts * ptsSrcFifoV )
Parameters
[in]ptsDestFifoVPointer to CAN frame FIFO destination
[in]ptsSrcFifoVPointer to CAN frame FIFO source
Returns
true if the contents have been copied, otherwise false

This function copies the contents from ptsSrcFifoV to ptsDestFifoV. The function checks if the destination FIFO has the same size as the source FIFO. Both FIFOs have to be initialised by CpFifoInit() in advance.

◆ CpFifoDataInPtr()

CpCanMsg_ts * CpFifoDataInPtr ( CpFifo_ts * ptsFifoV)
Parameters
[in]ptsFifoVPointer to CAN frame FIFO
Returns
Pointer to CAN frame entry

This function returns a pointer to the next free CAN frame entry inside the FIFO. Please make sure to call CpFifoIsFull() in advance. After writing to the FIFO, the index has to be adjusted by calling CpFifoIncIn(), as shown in this code example:

static CpFifo_ts tsCanFifoS;
CpCanMsg_ts * ptsCanNewMsgT;
CpCanMsg_ts * ptsCanInEntryT;
if (!(CpFifoIsFull(&tsCanFifoS)))
{
ptsCanInEntryT = CpFifoDataInPtr(&tsCanFifoS);
memcpy(ptsCanInEntryT, ptsCanNewMsgT, sizeof(CpCanMsg_ts));
CpFifoIncIn(&tsCanFifoS);
}
void CpFifoIncIn(CpFifo_ts *ptsFifoV)
CpCanMsg_ts * CpFifoDataInPtr(CpFifo_ts *ptsFifoV)
bool_t CpFifoIsFull(CpFifo_ts *ptsFifoV)
CAN frame structure.
Definition canpie.h:986
Administration variables of a CAN frame FIFO.
Definition cp_fifo.h:79

◆ CpFifoDataOutPtr()

CpCanMsg_ts * CpFifoDataOutPtr ( CpFifo_ts * ptsFifoV)
Parameters
[in]ptsFifoVPointer to CAN frame FIFO
Returns
Pointer to CAN frame entry

This function returns a pointer to the first CAN frame entry inside the FIFO. Please make sure to call CpFifoIsEmpty() in advance. After reading from the FIFO, the index has to be adjusted by calling CpFifoIncOut(), as shown in this code example:

static CpFifo_ts tsCanFifoS;
CpCanMsg_ts * ptsCanNewMsgT;
CpCanMsg_ts * ptsCanOutEntryT;
if (!(CpFifoIsEmpty(&tsCanFifoS)))
{
ptsCanOutEntryT = CpFifoDataOutPtr(&tsCanFifoS);
memcpy(ptsCanNewMsgT, ptsCanOutEntryT, sizeof(CpCanMsg_ts));
CpFifoIncOut(&tsCanFifoS);
}
void CpFifoIncOut(CpFifo_ts *ptsFifoV)
CpCanMsg_ts * CpFifoDataOutPtr(CpFifo_ts *ptsFifoV)
bool_t CpFifoIsEmpty(CpFifo_ts *ptsFifoV)

◆ CpFifoFree()

uint32_t CpFifoFree ( CpFifo_ts * ptsFifoV)
Parameters
[in]ptsFifoVPointer to CAN frame FIFO
Returns
Number of free elements

Returns the number of free elements inside the FIFO given by the pointer ptsFifoV.

◆ CpFifoIncIn()

void CpFifoIncIn ( CpFifo_ts * ptsFifoV)
Parameters
[in]ptsFifoVPointer to CAN frame FIFO

Increments the CpFifo_ts::ulIndexIn element of the CAN frame FIFO.

◆ CpFifoIncOut()

void CpFifoIncOut ( CpFifo_ts * ptsFifoV)
Parameters
[in]ptsFifoVPointer to CAN frame FIFO

Increments the CpFifo_ts::ulIndexOut element of the CAN frame FIFO.

◆ CpFifoInit()

void CpFifoInit ( CpFifo_ts * ptsFifoV,
CpCanMsg_ts * ptsCanMsgV,
uint32_t ulSizeV )
Parameters
[in]ptsFifoVPointer to CAN frame FIFO
[in]ptsCanMsgVPointer to array of CAN frames
[in]ulSizeVSize of CAN frame array

This function initialises a CAN frame FIFO. The parameter ptsCanMsgV points to an array of CpCanMsg_ts elements. The number of CAN frames that can be stored in the array is determined by the parameter ulSizeV.

Example: initialising a CAN frame FIFO

...
#define NUMBER_OF_FIFO_ENTRIES 20
static CpFifo_ts tsCanFifoS;
static CpCanMsg_ts atsCanMsgS[NUMBER_OF_FIFO_ENTRIES];
CpFifoInit(&tsCanFifoS, atsCanMsgS, NUMBER_OF_FIFO_ENTRIES);
void CpFifoInit(CpFifo_ts *ptsFifoV, CpCanMsg_ts *ptsCanMsgV, uint32_t ulSizeV)

◆ CpFifoIsEmpty()

bool_t CpFifoIsEmpty ( CpFifo_ts * ptsFifoV)
Parameters
[in]ptsFifoVPointer to CAN frame FIFO
Returns
true if FIFO is empty, otherwise false
See also
CpFifoIsFull()

Returns true if the FIFO is empty; otherwise returns false.

◆ CpFifoIsFull()

bool_t CpFifoIsFull ( CpFifo_ts * ptsFifoV)
Parameters
[in]ptsFifoVPointer to CAN frame FIFO
Returns
true if FIFO is full, otherwise false
See also
CpFifoIsEmpty()

Returns true if the FIFO is full; otherwise returns false.

◆ CpFifoPending()

uint32_t CpFifoPending ( CpFifo_ts * ptsFifoV)
Parameters
[in]ptsFifoVPointer to CAN frame FIFO
Returns
Number of pending elements

Returns the number of pending elements inside the FIFO given by ptsFifoV.