Rx Message Buffering
Rx Message Buffering
I can see that in the PCAN-Router example in one of the forums has a function call to CAN_ReferenceRxQueue. I am new to the Router FD handling, but cannot seem to find anything similar. Is there? Or is there an inherent queue in the call of CAN_Read? If not, is there an example that implements a buffer?
-
- Sales & Support
- Posts: 1083
- Joined: Fri 20. Sep 2019, 13:31
Re: Rx Message Buffering
Hello,
The PCAN-Router examples have Tx and Rx buffer implementations present, that will buffer messages coming in (serving messages from the buffer when CAN_Read() is called) and moving messages to the Tx buffer for transmission using CAN_Write().
In case you dont have the examples at hand, please download the PCAN-Router-package from our website:
https://www.peak-system.com/fileadmin/m ... router.zip
In the folder "Examples" open the very first example called "1_Routing":
in can_user.c you can see that the queues here are defined as arrays upon Initialisation:
In can.h you can find the definitions for CAN_ReferenceTxQueue and CAN_ReferenceRxQueue:
in can_user.h you can see the user defined size of these queues:
The examples given in the PCAN-Router package also show how to utilize these buffer-queues.
Best Regards
Marvin
The PCAN-Router examples have Tx and Rx buffer implementations present, that will buffer messages coming in (serving messages from the buffer when CAN_Read() is called) and moving messages to the Tx buffer for transmission using CAN_Write().
In case you dont have the examples at hand, please download the PCAN-Router-package from our website:
https://www.peak-system.com/fileadmin/m ... router.zip
In the folder "Examples" open the very first example called "1_Routing":
in can_user.c you can see that the queues here are defined as arrays upon Initialisation:
Code: Select all
#include "datatypes.h"
#include "lpc21xx.h"
#include "can.h"
#include "can_user.h"
// Queues for CAN1
CANMsg_t TxQueueCAN1[CAN1_TX_QUEUE_SIZE];
CANMsg_t RxQueueCAN1[CAN1_RX_QUEUE_SIZE];
// Queues for CAN2
CANMsg_t TxQueueCAN2[CAN2_TX_QUEUE_SIZE];
CANMsg_t RxQueueCAN2[CAN2_RX_QUEUE_SIZE];
Code: Select all
void CAN_UserInit ( void)
{
// init CAN1
CAN_ReferenceTxQueue ( CAN_BUS1, &TxQueueCAN1[0], CAN1_TX_QUEUE_SIZE); // Reference above Arrays as Queues
CAN_ReferenceRxQueue ( CAN_BUS1, &RxQueueCAN1[0], CAN1_RX_QUEUE_SIZE);
CAN_SetTimestampHandler ( CAN_BUS1, NULL);
Code: Select all
//! @brief
//! Reference a CANMsg_t array as TxQueue to a CAN bus. The user can vary queue
//! size depending on the application.
//!
//! @param hBus handle for CAN_BUSx
//! @param pQueueStart start of the queue
//! @param QueueSize size of the queue as message count
//!
//! @return CAN_ERR_OK OK, queue is referenced
CANStatus_t CAN_ReferenceTxQueue ( CANHandle_t hBus, CANMsg_t *pQueueStart, u16_t QueueSize);
//! @brief
//! Reference a CANMsg_t array or a CANRxMsg_t array as RxQueue to a CAN bus.
//! The user can vary queue size depending on the application.
//!
//! @param hBus handle for CAN_BUSx
//! @param pQueueStart start of the queue
//! @param QueueSize size of the queue as message count
//!
//! @return CAN_ERR_OK OK, queue is referenced
CANStatus_t CAN_ReferenceRxQueue ( CANHandle_t hBus, void *pQueueStart, u16_t QueueSize);
Code: Select all
// defines
#define CAN1_TX_QUEUE_SIZE 8
#define CAN1_RX_QUEUE_SIZE 16
#define CAN2_TX_QUEUE_SIZE 8
#define CAN2_RX_QUEUE_SIZE 16
Best Regards
Marvin
---
Marvin Heidemann
PEAK-Support Team
Marvin Heidemann
PEAK-Support Team
Re: Rx Message Buffering
Hello, the example you pointed me to is for the PCAN-Router, not the Router FD. Do you have similar functionality in the Router FD?
-
- Sales & Support
- Posts: 1083
- Joined: Fri 20. Sep 2019, 13:31
Re: Rx Message Buffering
Pardon me.
You're right.
The PCAN-Router FD handles it's buffers in a different way.
Using the PCAN-Router the queues where defined in software as arrays whereas the PCAN Router-FD uses hardware buffers.
The difference here is that you cannot change the size of the buffers, which is 4Kilobyte for each direction.
Again, use the example "01_ROUTING" for reference (This time from the PCAN Router FD package)
https://www.peak-system.com/fileadmin/m ... ter_fd.zip
You will find can.h in the "inc" folder, it contains definitons for the buffers:
the file "can_user.c" shows how use the buffers as a parameter to implement the function "CAN_UserRead":
As you can see in main.c a Txbuffer is used.
And a defined Rxbuffer is used to call CAN-UserRead:
You can also take a look at the other examples contained in the PCAN-Router FD package, to see different usecases using those buffers.
Best Regards
Marvin
You're right.
The PCAN-Router FD handles it's buffers in a different way.
Using the PCAN-Router the queues where defined in software as arrays whereas the PCAN Router-FD uses hardware buffers.
The difference here is that you cannot change the size of the buffers, which is 4Kilobyte for each direction.
Again, use the example "01_ROUTING" for reference (This time from the PCAN Router FD package)
https://www.peak-system.com/fileadmin/m ... ter_fd.zip
You will find can.h in the "inc" folder, it contains definitons for the buffers:
Code: Select all
////////////////////////////////////////////////////////////
//! @name buffertypes
//! Types of the different buffers.
//! @{
#define CAN_BUFFER_INVALID 0x0000 //!< invalid BUFFER, do not use
#define CAN_BUFFER_RX_MSG 0x0001 //!< receive message BUFFER
#define CAN_BUFFER_STATUS 0x0003 //!< status notification BUFFER
#define CAN_BUFFER_CRITICAL 0x0102 //!< receive cache level is critical
#define CAN_BUFFER_TX_MSG 0x1000 //!< transmit message BUFFER
/*! @}*/
/////////////////////////////////////////////////////////////
Code: Select all
// CAN_UserRead
// This wrapper is used to pre-process some incoming data.
CANResult_t CAN_UserRead ( CANHandle_t hBus, void *buff)
{
CANResult_t ret;
CANBuffer_t *rx_buff;
ret = CAN_ERR_RX_EMPTY;
rx_buff = buff;
...
Code: Select all
// main_greeting()
// transmit a message at module start
static void main_greeting ( void)
{
CANTxMsg_t Msg;
Msg.bufftype = CAN_BUFFER_TX_MSG;
Msg.dlc = CAN_LEN8_DLC;
Msg.msgtype = CAN_MSGTYPE_STANDARD;
Msg.id = 0x123;
Msg.data32[0] = 0x67452301;
Msg.data32[1] = 0xEFCDAB89;
// Send Msg
CAN_Write ( CAN_BUS1, &Msg);
}
Code: Select all
// main loop
while ( 1)
{
CANRxMsg_t RxMsg;
// process messages from CAN1
if ( CAN_UserRead ( CAN_BUS1, &RxMsg) == CAN_ERR_OK)
{
// message received from CAN1
LED_toggleCAN1 ^= 1;
if ( LED_toggleCAN1)
{
HW_SetLED ( HW_LED_CAN1, HW_LED_ORANGE);
}
else
{
HW_SetLED ( HW_LED_CAN1, HW_LED_GREEN);
}
// forward message to CAN2
CAN_Write ( CAN_BUS2, &RxMsg);
}
You can also take a look at the other examples contained in the PCAN-Router FD package, to see different usecases using those buffers.
Best Regards
Marvin
---
Marvin Heidemann
PEAK-Support Team
Marvin Heidemann
PEAK-Support Team