Setting Filters in CAN without init for CAN
Posted: Mon Mar 26, 2012 10:03 am
I need a macro to setup the filter configuration for the CAN
module other than the init provided by FLOWCODE
(the filter IDs must be provided by other electronic module or DIP configuration)
I know similar is the set up for the TX_ID is the code below,the wich is redundant with the INIT setting, but I am getting
confused converting this code to Filter, since I am not "C" programmer,
can someone help me?
//this is the definition for setting the TX ID variable
static void FCD_CAN0_SetTxID(char buffer, char hi, char lo);
//-------------------------------------------------------------------------------------------
// this is the definition of the component macro FCD_CAN0_SetTxID
static void FCD_CAN0_SetTxID(char buffer, char hi, char lo)
{
// Code_SetTxID
if (buffer > CAN_MAX_TX_BUF)
{
return;
}
#ifdef USE_INT_CAN
switch(buffer)
{
case 0:
C1TX0SID = ((hi << 5) | (lo >> 3)) & 0x00FF; //Transmit Buffer 0 S-ID
C1TX0SID = C1TX0SID | ((hi << 8) & 0xFF00);
break;
case 1:
C1TX1SID = ((hi << 5) | (lo >> 3)) & 0x00FF; //Transmit Buffer 1 S-ID
C1TX1SID = C1TX1SID | ((hi << 8) & 0xFF00);
break;
case 2:
C1TX2SID = ((hi << 5) | (lo >> 3)) & 0x00FF; //Transmit Buffer 2 S-ID
C1TX2SID = C1TX2SID | ((hi << 8) & 0xFF00);
break;
}
#else
char i;
char id_addr = TXBxSIDH(buffer);
//enable SPI
clear_bit(MX_CAN_CS_PORT, CAN_CHIPSEL);
FCD_CAN0_SPI_SendByte(CAN_WRITE); //CAN write mode
FCD_CAN0_SPI_SendByte(id_addr); //start writting at hi id address
FCD_CAN0_SPI_SendByte(hi); //send the Hi ID value
FCD_CAN0_SPI_SendByte(lo); //send the Lo ID value
//disable SPI
set_bit(MX_CAN_CS_PORT, CAN_CHIPSEL);
#endif
}
//-------------------------------------------------------------------------------------------
// then we call the component macro after in MAIN
FCD_CAN0_SetTxID(0, 86, 64);
module other than the init provided by FLOWCODE
(the filter IDs must be provided by other electronic module or DIP configuration)
I know similar is the set up for the TX_ID is the code below,the wich is redundant with the INIT setting, but I am getting
confused converting this code to Filter, since I am not "C" programmer,
can someone help me?
//this is the definition for setting the TX ID variable
static void FCD_CAN0_SetTxID(char buffer, char hi, char lo);
//-------------------------------------------------------------------------------------------
// this is the definition of the component macro FCD_CAN0_SetTxID
static void FCD_CAN0_SetTxID(char buffer, char hi, char lo)
{
// Code_SetTxID
if (buffer > CAN_MAX_TX_BUF)
{
return;
}
#ifdef USE_INT_CAN
switch(buffer)
{
case 0:
C1TX0SID = ((hi << 5) | (lo >> 3)) & 0x00FF; //Transmit Buffer 0 S-ID
C1TX0SID = C1TX0SID | ((hi << 8) & 0xFF00);
break;
case 1:
C1TX1SID = ((hi << 5) | (lo >> 3)) & 0x00FF; //Transmit Buffer 1 S-ID
C1TX1SID = C1TX1SID | ((hi << 8) & 0xFF00);
break;
case 2:
C1TX2SID = ((hi << 5) | (lo >> 3)) & 0x00FF; //Transmit Buffer 2 S-ID
C1TX2SID = C1TX2SID | ((hi << 8) & 0xFF00);
break;
}
#else
char i;
char id_addr = TXBxSIDH(buffer);
//enable SPI
clear_bit(MX_CAN_CS_PORT, CAN_CHIPSEL);
FCD_CAN0_SPI_SendByte(CAN_WRITE); //CAN write mode
FCD_CAN0_SPI_SendByte(id_addr); //start writting at hi id address
FCD_CAN0_SPI_SendByte(hi); //send the Hi ID value
FCD_CAN0_SPI_SendByte(lo); //send the Lo ID value
//disable SPI
set_bit(MX_CAN_CS_PORT, CAN_CHIPSEL);
#endif
}
//-------------------------------------------------------------------------------------------
// then we call the component macro after in MAIN
FCD_CAN0_SetTxID(0, 86, 64);