How to modify can_pal example to use RX Filter for multiple can Ids?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to modify can_pal example to use RX Filter for multiple can Ids?

465 Views
Sukumar21
Contributor II

I have used can_pal_s32k146 example check communication over CAN interface. now my next step is to use Can driver to receive message from multiple IDs. for example can ID 0x31 and 0x32 and 0x20 and 0x21

my question is how do i modify can_pal_example to fit my requirement? which driver apis to use ?

Labels (1)
Tags (3)
0 Kudos
Reply
3 Replies

438 Views
Senlent
NXP TechSupport
NXP TechSupport
0 Kudos
Reply

388 Views
Sukumar21
Contributor II

Dear @Senlent 

I have made following changes as per the example template, it still doesnt receive messages, i am trying to receive from ID 0x20 & 0x21

// global def
#define MAX_RX_FILTER_ID_COUNT 8
const flexcan_id_table_t RxFIFO_FilterAcceptanceID_Table[MAX_RX_FILTER_ID_COUNT] =
{
		{    /*RxFIFO ID table element 0*/
			.isRemoteFrame = false,
			.isExtendedFrame = false,
			.id = 0x011
		},
		{	 /*RxFIFO ID table element 1*/
			.isRemoteFrame = false,
			.isExtendedFrame = false,
			.id = 0x022
		},
		{    /*RxFIFO ID table element 2*/
			.isRemoteFrame = false,
			.isExtendedFrame = false,
			.id = 0x033
		},
		{	 /*RxFIFO ID table element 3*/
			.isRemoteFrame = false,
			.isExtendedFrame = false,
			.id = 0x044
		},
		{	 /*RxFIFO ID table element 4*/
			.isRemoteFrame = false,
			.isExtendedFrame = false,
			.id = 0x055
		},
		{	 /*RxFIFO ID table element 5*/
			.isRemoteFrame = false,
			.isExtendedFrame = false,
			.id = 0x066
		},
		{	 /*RxFIFO ID table element 6*/
			.isRemoteFrame = false,
			.isExtendedFrame = false,
			.id = 0x077
		},
		{	 /*RxFIFO ID table element 7*/
			.isRemoteFrame = false,
			.isExtendedFrame = false,
			.id = 0x088
		},

};
#define CAN_RX_Buffer_MAX         2   /*define the RX buffer size*/
#define CAN_RxFIFO_RX_Buffer_MAX  2   /*define the RxFIFO RX buffer size*/

can_message_t CAN_RxFIFO_RX_Message_Buffer[CAN_RxFIFO_RX_Buffer_MAX];/*circle buffer for CAN RxFIFO RX*/
can_message_t CAN_RX1_Message_Buffer[CAN_RX_Buffer_MAX];/*circle buffer for CAN RX MB1*/

uint32_t CAN_RxFIFO_RX_BufferIndex = 0;    /*buffer index for CAN RxFIFO RX*/
uint32_t CAN_RX1_BufferIndex = 0;    /*buffer index for CAN RX MB1*/
/* CAN hardware MB(Message Buffer) configuration for RX MB1 */
can_buff_config_t CAN_RX_MB1_Config = {
 .enableFD = false,
 .enableBRS = false,
 .fdPadding = 0x0,
 .idType = CAN_MSG_ID_STD,
 .isRemote = false
};

/*!
  \brief The main function for the project.
  \details The startup initialization sequence is the following:
 * - __start (startup asm routine)
 * - __init_hardware()
 * - main()
 *     - Common_Init()
 *     - Peripherals_Init()
*/
/* define the RxFIFO used standard MB number for RX ID filter configuration */
#define RxFIFO_USED_MB (2 +(can_pal1_rx_fifo_ext0.numIdFilters<<1))
/*
 * define the RxFIFO ID filter table mask, for this demo, configure RxFIFO with Type-B filter:
 *  two 16-bit filer with standard ID
 */
#define RxFIFO_ACK_ID_MASK  0x7FF   /* all ID bits(11 bits for standard message frame) must match with RxFIFO ID table settings  */

/************************************************************************
* configure the following RX_ACK_ID1/2 and RX_ACK_ID1/2_MASK for the RX MB
* ID filter:
* Below default configuration to
*      receive CAN messages with ID = 0x120~0x12F(16 ID in total) with RX MB1
*      receive CAN messages with ID = 0x056,0x156, 0x256 and 0x356(4 ID in total) with RX MB2
*************************************************************************/
#define RX_ACK_ID1          0x21 /*define RX MB1 acceptance message ID*/
/**************************************************************************
 *  define the IDE-bit mask,
 * IDE_MASK_SET: match to receive only standard or extend ID message frames
 * IDE_MASK_CLR: mask and ignore IDE-bit, so both standard and extend ID message
 *               frames will be received
 **************************************************************************/
#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATAB_RTR_SHIFT     (31U)          /*!< FlexCAN RX FIFO ID filter*/
                                                                        /*! format A&B RTR mask.*/
#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATAB_IDE_SHIFT     (30U)          /*!< FlexCAN RX FIFO ID filter*/
                                                                        /*! format A&B IDE mask.*/


#define IDE_MASK_SET  (1<<FLEXCAN_RX_FIFO_ID_FILTER_FORMATAB_IDE_SHIFT)
#define IDE_MASK_CLR  (0<<FLEXCAN_RX_FIFO_ID_FILTER_FORMATAB_IDE_SHIFT)

/**************************************************************************
 *  define the IDE-bit mask,
 * RTR_MASK_SET: match to receive only data or remote message frames
 * RTR_MASK_CLR: mask and ignore RTR-bit, so both data and remote message
 *               frames will be received
 **************************************************************************/
#define RTR_MASK_SET  (1<<FLEXCAN_RX_FIFO_ID_FILTER_FORMATAB_RTR_SHIFT)
#define RTR_MASK_CLR  (0<<FLEXCAN_RX_FIFO_ID_FILTER_FORMATAB_RTR_SHIFT)

#define RX_ACK_ID1_MASK     (0x7FE | IDE_MASK_CLR | RTR_MASK_CLR) /* mask the lower 4LSB ID */
// can isr/callbacks

void can0_rx_complete(uint32_t instance,
                               can_event_t eventType,
                               uint32_t objIdx,
                               void *driverState)

{
	uint16_t lu16rxId = 0;

	if(eventType == CAN_EVENT_RX_COMPLETE)
	{
		/* check whether the RxFIFO is enabled */
		if((0==objIdx)&&(NULL != can_pal1_Config0.extension))
		{
			CAN_RxFIFO_RX_BufferIndex++; /*increase the RxFIFO RX buffer index*/

			/*use next RxFIFO circle buffer for the new CAN message receive*/
			CAN_Receive(&can_pal1_instance,objIdx,&CAN_RxFIFO_RX_Message_Buffer[CAN_RxFIFO_RX_BufferIndex%CAN_RxFIFO_RX_Buffer_MAX]);

//			CAN_RxFIFO_RX_Completed_Flag = true;/*set the RxFIFO RX completed flag*/
		}
		else
		{
			switch (objIdx)
			{
				case RX_MB1:
					{
						CAN_RX1_BufferIndex++; /*increase the RX buffer index*/

						/*use next circle buffer for the new CAN message receive*/
						CAN_Receive(&can_pal1_instance,objIdx,&CAN_RX1_Message_Buffer[CAN_RX1_BufferIndex%CAN_RX_Buffer_MAX]);

//						CAN_RX1_Completed_Flag = true;/*set the RX completed flag*/

						break;
					}
				default: break;
			}

		}
	}

}

// can init
	/* assign the RxFIFIO filter acceptance ID table to rx_fif0 extension of can_pal config structure */
    can_pal1_rx_fifo_ext0.idFilterTable = (flexcan_id_table_t *)RxFIFO_FilterAcceptanceID_Table;

    CAN_Init(&can_pal1_instance, &can_pal1_Config0);

/*configure the RxFIFO ID filter table mask
note: Hangs at i = 0
*/
   /*for(i=0; i < RxFIFO_USED_MB; i++)
   {
	   CAN_SetRxFilter(&can_pal1_instance,CAN_MSG_ID_STD,i,RxFIFO_ACK_ID_MASK);
   }*/
	/*configure the RxFIFO ID filter table mask*/
   CAN_SetRxFilter(&can_pal1_instance,CAN_MSG_ID_STD, 1 ,RxFIFO_ACK_ID_MASK);

   CAN_InstallEventCallback(&can_pal1_instance, can0_rx_complete, NULL);

   FLEXCAN_DRV_InstallErrorCallback(can_pal1_instance.instIdx, CAN_Error_Callback, NULL);
   /* Set information about the data to be sent
    *  - Standard message ID
    *  - Bit rate switch enabled to use a different bitrate for the data segment
    *  - Flexible data rate enabled
    *  - Use zeros for FD padding
    */
	can_buff_config_t buffCfg =  {
	   .enableFD = false,
	   .enableBRS = true,
	   .fdPadding = 0U,
	   .idType = CAN_MSG_ID_STD,
	   .isRemote = false
	};

	/* Configure TX buffer with index TX_MAILBOX*/
	CAN_ConfigTxBuff(&can_pal1_instance, TX_MAILBOX, &buffCfg);


	/* configure the receive MB1 with ACK ID for ID filter */
	CAN_ConfigRxBuff(&can_pal1_instance,RX_MB1, &CAN_RX_MB1_Config, RX_ACK_ID1);
	/* configure the RX MB1 ID filter, use individual with 4 LSB ID masked */
	CAN_SetRxFilter(&can_pal1_instance,CAN_MSG_ID_STD,(RX_MB1+RxFIFO_USED_MB),RX_ACK_ID1_MASK);

 

Tags (1)
0 Kudos
Reply

420 Views
Sukumar21
Contributor II

@Senlent  i tried replicating

S32K144_CAN_PAL_SamplePrj_Basic_TxRx_ID_FiltersConfig_SDKRTM3P0.zip but it fails at

 

 

/*configure the RxFIFO ID filter table mask*/
for(i=0; i<RxFIFO_USED_MB; i++)
{
CAN_SetRxFilter(&can_pal1_instance,CAN_MSG_ID_STD,i ,RxFIFO_ACK_ID_MASK);
}

 

 

 

Currently my version of design studio is 3.4 and RTM 4.0.3 and doesnt accept i = 0

 
 
 
 
 
.
 
 
 
Tags (1)
0 Kudos
Reply