Hi everyone,
I'm working on a project on S32DS using the Can_Llce_DS_Can2Can_S32G399A_M7 example, and I've encountered a problem with my CAN message forwarding code. Specifically, I'm only able to forward one message at a time.
Here's what's happening: I'm receiving two CAN messages with IDs 0x01 and 0x02, and my goal is to forward these messages with new IDs 0x51 and 0x52. However, no matter what, the system always forwards only the message with ID 0x51. The two messages arrive almost simultaneously, with 0x02 arriving just a few nanoseconds before 0x01.
I've already tried a few things to resolve this issue:
I've tried setting the receiver to both INTERRUPT and POLLING modes.
I've experimented with using a queue.
I also tried applying a filter to only forward messages with ID 0x02, and it successfully forwards 0x52, so the filter itself isn't the problem.
I'm using a single LLCE line for communication.
Does anyone have any idea what might be causing this behavior or how I can resolve it? Any insights would be greatly appreciated!
Thanks in advance!
I also leave my main.c here and attach the image of my CanController
#include "Can_43_LLCE.h"
#include "Can_43_LLCE_IPW.h"
#include "PlatformInit.h"
#include "Llce_Firmware_Load.h"
#include <stdbool.h>
#include "stubs.h"
/*==================================================================================================
DEFINITIONS AND MACROS
==================================================================================================*/
#define CAN_CONTROLLER_ID (0U)
#define CAN_TRANSMIT_HTH (CanHO_Config0_TX0)
#define CAN_ID_REWRITE_OFFSET (0x50U)
#define MAX_KNOWN_SOURCE_IDS (32U) // Maximum unique IDs that the gateway stores
/* --- Configuration macros --- */
#define MACRO_CONCAT(a,b) a##b
#define CAN_VARIANT(var) MACRO_CONCAT(Can_43_LLCE_Config_, var)
#ifndef CONFIG_VARIANT_USED
#define CAN_LLCE_VARIANT (NULL_PTR)
#else
#define CAN_LLCE_VARIANT (&CAN_VARIANT(CONFIG_VARIANT_USED))
#endif
/**
* @brief Mask to isolate the 29-bit CAN ID from the status flags.
* @details Can_RxId contains flags in the higher bits. This mask clears the flags and keeps only
* the message identifier.
*/
#define CAN_ID_MASK (0x1FFFFFFFUL)
/*==================================================================================================
GLOBAL AND STATIC VARIABLES
==================================================================================================*/
extern volatile uint32 Can_RxIndication;
extern volatile Can_IdType Can_RxId;
extern volatile uint8 Can_RxDlc;
extern volatile uint8 Can_RxData[];
// Array for anti-loop logic: stores the source IDs already processed.
static Can_IdType knownSourceIds[MAX_KNOWN_SOURCE_IDS];
static uint32 knownSourceIdsCount = 0;
#define DEBUG_ID_MSG_RECEIVED (0x7E0U) // Sent when a message is read from the bus
#define DEBUG_ID_MSG_FORWARDED (0x7E1U) // Sent when a message is forwarded
#define DEBUG_ID_MSG_IGNORED (0x7E2U) // Sent when a message is ignored (echo)
static uint8 debugData[8] = {0};
void Send_Debug_Message(Can_IdType debugId, uint8 value)
{
Can_PduType debugPdu;
debugData[0] = value;
debugPdu.id = debugId;
debugPdu.length = 8;
debugPdu.sdu = debugData;
debugPdu.swPduHandle = 0;
(void)Can_43_LLCE_Write(CAN_TRANSMIT_HTH, &debugPdu);
}
/*==================================================================================================
MAIN FUNCTION
==================================================================================================*/
int main(void)
{
Std_ReturnType retval = E_NOT_OK;
Can_PduType txPdu;
uint32 processed_rx_count = 0;
PlatformInit();
Llce_Firmware_Load();
Can_43_LLCE_Init(CAN_LLCE_VARIANT);
Can_CallBackSetUp();
(void)Can_43_LLCE_SetBaudrate(CAN_CONTROLLER_ID, 0);
retval = Can_43_LLCE_SetControllerMode(CAN_CONTROLLER_ID, CAN_CS_STARTED);
if (E_OK != retval) { while(1); }
processed_rx_count = Can_RxIndication;
while (1)
{
Can_43_LLCE_IPW_MainFunctionRead();
while (Can_RxIndication > processed_rx_count)
{
// Process the currently available data in the global variables
Can_IdType cleanId = Can_RxId & CAN_ID_MASK;
if (cleanId < CAN_ID_REWRITE_OFFSET)
{
txPdu.id = (Can_RxId & ~CAN_ID_MASK) | (cleanId + CAN_ID_REWRITE_OFFSET);
txPdu.length = Can_RxDlc;
txPdu.sdu = (uint8*) Can_RxData;
txPdu.swPduHandle = 0;
(void) Can_43_LLCE_Write(CAN_TRANSMIT_HTH, &txPdu);
}
// Incremental acknowledgment: we have processed ONE message.
processed_rx_count++;
// To handle the next message in the backlog, the driver needs
// to reload the data of the next message into the global variables.
// We call the read function again if there are still messages waiting.
if (Can_RxIndication > processed_rx_count)
{
Can_43_LLCE_IPW_MainFunctionRead();
}
}
}
return 0;
}