Acceptance filter
2006-03-14 by David Mercier
Hi,
I have the following code to add extended IDs in the acceptance filter but I
can't get it to work.
May somebody help me to find the problem ?
Or anybody has some code that I could use to get it work ?
Best regards
David Mercier
int16_t canSetFilter (uint16_t canPort, uint32_t canID)
{
uint16_t p, n;
uint32_t buf0, buf1;
uint32_t *pAddr;
AFMR = AF_ACCEPT_ALL; // Allow modif on Acceptance Filter
if (mCANFilter >= MAX_FILTERS)
{
return 0;
}
// Filters must be sorted by interface, then by priority
canID &= 0x1FFFFFFFL; // Mask out 29-bit ID
canID |= (canPort << 29); // Put can_port info in bits 29, 30, 31
// new filter is sorted into array
p = 0;
while (p < mCANFilter) // loop through all existing filters
{
// If ID at position p is bigger than the one we need to insert
if ((mCANFilterList[p].MsgID) > canID)
{
break;
}
p++;
}
// move all remaining entries one row up
for(n = mCANFilter; n > p; n--)
{
mCANFilterList[n].MsgID = mCANFilterList[n-1].MsgID;
}
// insert new filter here
buf0 = mCANFilterList[p].MsgID; // save current entry
mCANFilterList[p].MsgID = canID; // insert the new entry
// move all remaining entries one row up
mCANFilter++;
while (p < mCANFilter)
{
p++;
buf1 = mCANFilterList[p].MsgID;
mCANFilterList[p].MsgID = buf0;
buf0 = buf1;
}
// Now work on Acceptance Filter Configuration
// Set CAN filter for 29-bit extended identifiers
p = 0;
// Set pointer for Standard Frame Individual
// Standard Frame Explicit
SFF_sa = p;
// Set pointer for Standard Frame Groups
// Standard Frame Group Start Address Register
SFF_GRP_sa = p;
// Set pointer for Extended Frame Individual
// Extended Frame Start Address Register
EFF_sa = p;
pAddr = (uint32_t *)&AFRAM;
for (n = 0; n < mCANFilter; n++)
{
*pAddr = mCANFilterList[n].MsgID;
p += 4;
pAddr++;
}
// p is still pointing to end of table;
// last entry must contain unused filters
*pAddr = 0xF7FFF7FF;
p += 4;
// Set pointer for Extended Frame Groups
// Extended Frame Group Start Address Register
EFF_GRP_sa = p;
// Set ENDofTable
// End of AF Tables Register
ENDofTable = p;
// Acceptance Filter Mode Register, start using filter
AFMR = AF_ON;
return 1;
}
[Non-text portions of this message have been removed]