📄 jbuffer.h
字号:
/*--------------------------------------------------------------------
JBUFFER.H
--------------------------------------------------------------------
Copyright (C) 2004 Vector Informatik GmbH, Stuttgart
Function: Header for basic routines to filter and store CAN
messages
* Comments:
*
*
* Version Date Author Comments
* ------- ---------- -------------- ------------------------------
* 1.0 15.05.2001 Ma Create
* 1.1 23.01.2002 Ma changed Buffer configurations and made
* adaption to BIG_ENDIAN capability
* 1.2 31.01.2002 Ma chenged GetId -> SetId macro
* 2.0 24.06.2004 Ma removed TX allocation handling and adaption to new
* demo application
* 2.1 28.06.2004 Ma changed comments & hash table configuration
--------------------------------------------------------------------*/
#ifndef _BUFFER_H_
#define _BUFFER_H_
#include "Types.h"
#include "J1939PGN.h"
/* some forward declarations for callback function into the driver */
BYTE gCB_PreCheckXtdId(DWORD wId);
BYTE gCB_PreCheckStdId(WORD wId);
BYTE gCB_CanBufferMsg(const CAN_MSG MEM_AREA *);
BYTE gCB_CheckSysPGSend(void);
void gCB_ClearIdFilter(BYTE bManager);
void gCB_SignalTx(void);
/*--------------------------------------------------------------------*/
/* global defines */
/*--------------------------------------------------------------------*/
/*! Switch to select the lookup data structure */
#define USE_HASHTABLE 0 /*!< 1 - a hash table is used to look up for PGN in ISR */
/*!< 0 - a linear search routine will look up for PGN's in ISR*/
#define BENCHMARK 0 /*!< 1 - some benchmark functions will be activated and GPT4 will
be activated. A debugger is neccessary to check the timer */
/*!< 0 - no benchmark timers can be activated */
/*--------------------------------------------------------------------*/
/* macros */
/*--------------------------------------------------------------------*/
/*! \brief diverse macros */
/*!< returns 1 if a pg is a system PG */
#define IsSysPG(pg) (((pg->mPDUF != 0xEC) && \
(pg->mPDUF != 0xEE) && \
(pg->mPDUF != 0xEA) && \
(pg->mPDUF != 0xE8) && \
(pg->mPDUF != 0xEB))?0:1)
/*!< return a can ID from a PG */
#define SetId(pg) ((((DWORD)pg->mPriority)<<26) | \
(((DWORD)pg->mPDUF)<<16) | \
(((DWORD)pg->mPDUS)<<8) | \
((DWORD)pg->mSource))
#define GetPDUF(msg) ((msg->qbId.dw&0x00FF0000)>>16) /*!< return the PDUF from a can msg */
#define GetPDUS(msg) ((msg->qbId.dw&0x0000FF00)>>8) /*!< return the PDUS from a can msg */
#define GetSource(msg) (msg->qbId.dw&0x000000FF) /*!< return the source field from a can msg */
#define GetPrio(msg) ((msg->qbId.dw&0xFC000000)>>26) /*!< return the priority from a can msg */
/*!
\brief Selection flag of the PG buffer
This define describes which Buffer shall be selected
*/
#define RX_BUFF 0
/*!
\brief Selection flag of the PG buffer
This define describes which Buffer shall be selected
*/
#define TX_BUFF 1
/*!
\brief Selection flag of the System PG buffer
This define describes which Buffer shall be selected
*/
#define TX_SYS_BUFF 2
/*!
\brief Selection flag of a RX PG buffer
This define describes which Buffer shall be selected
*/
#define RX_SYS_BUFF 3
/*!
\brief Value signs an incorrect selected buffer
This define describes an invalid Buffer (init value)
*/
#define INVAL_BUFFER 0xFF
/*!
If we don't find an Entry in the table we will return a defined value
This define describes the value of an invalid index
*/
#define INVAL_INDEX 0xFFFF
/*!
The following defines describe the table sizes of the buffer
*/
/*! [USER_MODIFIED] */
#define MAX_RX_ELMS 12 /*!< buffer size of the RX table; in hash mode
RX modulator shall be adjusted */
/*!< NOTE: MAX_RX_ELMS shall be > 1 !!! */
/*! [USER_MODIFIED] */
#define MAX_RX_QUEUESIZE 5 /*!< queue size of the system PG queue */
/*!< NOTE: Queuesize shall be > 1 !!! */
#define CAN_DATASIZE 8 /*!< max data size of a can message */
#define INVAL_RX_INX MAX_RX_ELMS /*!< invalid index of the RX table */
/*!
System PG queue element description
*/
typedef struct _VJ19QueueElm {
BYTE Used; /*!< free flag; 0 - buffer is free 1 buffer is used */
BYTE Overrun; /*!< overrun flag for time delay */
VJ1939PGN mPGN; /*!< buffered Rx/Tx PGN */
BYTE mPGNData[CAN_DATASIZE]; /*!< pgn Data */
}VJ19QueueElm;
/* ########################### begin HASH STRUCTURE ############################# */
# if (USE_HASHTABLE == 1)
/*!
\brief This define is neccessary for define a modulator for the hash function
NOTE: The best results of the hashing methode can be reached if the modulator
was a prime number near the highest index of the table. If the lookup
times of the hash table are not satisfactory, the modulator of the
table shall be changed to an other value.
*/
/*!
[USER_MODIFIED]
*/
#define RX_MODULATOR 7 /*!< modulator of the RX table It should be a prime
number nearest the maxime of the RX table */
/*!
Structure for parameter group element within the hash table
*/
typedef struct _VJ1939PGNElm {
BYTE Used; /*!< free flag; 0 - buffer is free 1 buffer is used */
BYTE Overrun; /*!< overrun flag for time delay */
BYTE Requested; /*!< flag to sign a sent PG 1-sent 0-not sent */
VJ1939PGN* ptPGN; /*!< buffered Rx/Tx PGN */
}VJ1939PGNElm;
/*!
Structure for hash table elements
*/
typedef struct _VTableElm {
unsigned short mElement; /*!< data of Table */
unsigned short mNext; /*!< pointer to next */
void* mIndex; /*!< pointer to next table index */
}VTableElm;
/*!
Hashtable and buffer structure for user PGs.
*/
typedef struct _VJ1939PGNBuffer {
/* RX Hash Table */
VTableElm mPDURxTable[MAX_RX_ELMS]; /*!< RX PG Hash Table */
unsigned short PDURxIndex[MAX_RX_ELMS]; /*!< RX Entrance index List to enter the hash table */
BYTE RxElms; /*!< element counter of Rx elements */
unsigned short mPDURxFree; /*!< free pointer to the next free table element */
unsigned short mCurrRxPG; /*!< holds the index of the last received Rx PG */
unsigned short mPDUTxFree; /*!< free pointer to the next free table element */
BYTE PGType; /*!< PG type flag to signal a system or user PG */
/* TX System PGN */
VJ1939PGNElm TxPGN; /*!< Tx buffer */
/* RX Sys PGN Queue */
unsigned short mRxQueueWritePtr; /*!< queue write pointer */
unsigned short mRxQueueReadPtr; /*!< queue read pointer */
VJ19QueueElm RxSysPGNQueue[MAX_RX_QUEUESIZE]; /*!< list of queue elements */
}VJ1939PGNBuffer;
/* ########################### end HASH STRUCTURE ############################# */
# else
/*!
Parameter group element of the linear list structure
*/
typedef struct _VJ1939PGNElm {
BYTE Used; /*!< free flag; 0 - buffer is free 1 buffer is used */
BYTE Overrun; /*!< overrun flag for time delay */
BYTE Requested; /*!< flag to sign a sent PG 1-sent 0-not sent */
VJ1939PGN* ptPGN; /*!< buffered Rx/Tx PGN */
}VJ1939PGNElm;
/*!
Linear list and buffer structure for user PGs.
*/
typedef struct _VJ1939PGNBuffer {
BYTE RxElms; /*!< element counter of Rx elements */
BYTE PGType; /*!< kind of PG in transmit mode */
unsigned long reqPGN; /*!< buffer index for holding the current sent PG */
VJ1939PGNElm TxPGNBuff; /*!< TX buffer for all TX PGs (sys/user) */
VJ1939PGNElm RxPGN[MAX_RX_ELMS]; /*!< List of Rx PGN's */
unsigned short mCurrRxPG; /*!< holds the index of the last received Rx PG */
/* RX Sys PGN Queue */
unsigned short mRxQueueWritePtr; /*!< queue write pointer */
unsigned short mRxQueueReadPtr; /*!< queue read pointer */
VJ19QueueElm RxSysPGNQueue[MAX_RX_QUEUESIZE]; /*!< list of queue elements */
} VJ1939PGNBuffer;
# endif /* USE_HASHTABLE */
#endif /* _BUFFER_H_ */
/*--------------------------------------------------------------------*/
/* documentation */
/*--------------------------------------------------------------------*/
/*!
\file
\brief Header for basic routines to filter and store CAN messages and transform them to J1939 PGNs.
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -