📄 can_accfilt_lpc2xxx.c
字号:
if ((entry.channel_no == new_entry.channel_no)
&& (entry.id > new_entry.id))
{
break;
}
} // for (i = 0; i < entries; ++i)
lpc2xxx_can_accfilt_ram_insert_entry(table, i);
lpc2xxx_can_accfilt_set_entry(table, i, &new_entry);
//
// finally restore the prvious state of the acceptance filter
//
HAL_WRITE_UINT32(CAN_ACCFILT_AFMR, accfilt_bck);
return true;
}
//===========================================================================
// Remove all entries from a certain controller
//===========================================================================
void lpc2xxx_can_accfilt_remove_all_ctrl_entries(lpc2xxx_can_info_t *info)
{
cyg_uint32 accfilt_bck; // acceptance filter backup
cyg_uint16 i;
cyg_uint16 entries;
cyg_uint32 TableStartAddress = CAN_ACCFILT_SFF_SA;
lpc2xxx_accfilt_entry_t Entry;
cyg_uint8 channel_no = (CAN_ISRVEC(info) - CYGNUM_HAL_INTERRUPT_CAN1_TX) + 1;
cyg_uint16 entry_idx;
//
// first step: disable acceptance filter and prepare it for modification
//
HAL_READ_UINT32(CAN_ACCFILT_AFMR, accfilt_bck);
HAL_WRITE_UINT32(CAN_ACCFILT_AFMR, AFMR_OFF | AFMR_BYPASS);
//
// now remove all entries for a certain controller
//
for (TableStartAddress = CAN_ACCFILT_SFF_SA; TableStartAddress < CAN_ACCFILT_ENDOFTABLE; TableStartAddress += 4)
{
entries = lpc2xxx_can_accfilt_get_table_entries(TableStartAddress);
entry_idx = 0;
for (i = 0; i < entries; ++i)
{
lpc2xxx_can_accfilt_get_entry(TableStartAddress, entry_idx, &Entry);
if (Entry.channel_no == channel_no)
{
lpc2xxx_can_accfilt_ram_remove_entry(TableStartAddress, entry_idx);
}
else
{
entry_idx++;
}
} // for (i = 0; i < entries; ++i)
} // for (TableStartAddress = CAN_ACCFILT_SFF_SA ...
//
// finally restore the prvious state of the acceptance filter
//
HAL_WRITE_UINT32(CAN_ACCFILT_AFMR, accfilt_bck);
}
#endif // CYGOPT_IO_CAN_RUNTIME_MBOX_CFG
#ifndef CYGOPT_IO_CAN_RUNTIME_MBOX_CFG
//===========================================================================
// Setup reception of all CAN identifiers
// If runtime acceptance filter configuration is not required then we simply
// setup the acceptance filter here to receive all CAN identifiers
//===========================================================================
static void lpc2xxx_can_accfilt_simple_rx_all(void)
{
cyg_uint32 regval;
//
// First check if it is really necessary to setup filters. If end of table is
// != 0 then the acceptance filter is already setup properly
//
HAL_READ_UINT32(CAN_ACCFILT_ENDOFTABLE, regval);
if (regval)
{
return;
}
cyg_uint32 accfilt_bck; // acceptance filter backup
cyg_uint8 i = 0; // loop counter
lsc_buf_t accfilt_entry; // std group entry
#ifdef CYGOPT_IO_CAN_STD_CAN_ID
cyg_uint8 std_address = 0; // std group entry address
#ifdef CYGOPT_IO_CAN_EXT_CAN_ID
cyg_uint8 ext_address = lpc2xxx_global_can_info.init_cnt << 2;
#endif
#else
cyg_uint8 ext_address = 0;
#endif
//
// first step: disable acceptance filter and prepare it for modification
//
HAL_READ_UINT32(CAN_ACCFILT_AFMR, accfilt_bck);
HAL_WRITE_UINT32(CAN_ACCFILT_AFMR, AFMR_OFF | AFMR_BYPASS);
//
// Write table start adresses - we use only standard group and extended filter
// group
//
HAL_WRITE_UINT32(CAN_ACCFILT_SFF_SA, 0);
HAL_WRITE_UINT32(CAN_ACCFILT_SFF_GRP_SA, 0);
HAL_WRITE_UINT32(CAN_ACCFILT_EFF_SA, ext_address);
HAL_WRITE_UINT32(CAN_ACCFILT_EFF_GRP_SA, ext_address);
//
// Now loop through all active CAN channels and setup the acceptance filter for
// each channel to receive all standard and extended CAN identifiers
//
while (lpc2xxx_global_can_info.active_channels[i])
{
lpc2xxx_can_info_t *info = (lpc2xxx_can_info_t *)lpc2xxx_global_can_info.active_channels[i++]->dev_priv;
cyg_uint8 channel_no = (CAN_ISRVEC(info) - CYGNUM_HAL_INTERRUPT_CAN1_TX) + 1;
#ifdef CYGOPT_IO_CAN_STD_CAN_ID
accfilt_entry.column.lower = (channel_no << 13) | (0x000 & ACCFILT_STD_ID_MASK);
accfilt_entry.column.upper = (channel_no << 13) | (0x7FF & ACCFILT_STD_ID_MASK);
HAL_WRITE_UINT32(CAN_ACCFILT_RAM_BASE + std_address, accfilt_entry.dword);
std_address += sizeof(cyg_uint32);
#endif // CYGOPT_IO_CAN_STD_CAN_ID
#ifdef CYGOPT_IO_CAN_EXT_CAN_ID
accfilt_entry.dword = (channel_no << 29) | (0x00000000 & ACCFILT_EXT_ID_MASK);
HAL_WRITE_UINT32(CAN_ACCFILT_RAM_BASE + ext_address, accfilt_entry.dword);
ext_address += sizeof(cyg_uint32);
accfilt_entry.dword = (channel_no << 29) | (0x1FFFFFFF & ACCFILT_EXT_ID_MASK);
HAL_WRITE_UINT32(CAN_ACCFILT_RAM_BASE + ext_address, accfilt_entry.dword);
ext_address += sizeof(cyg_uint32);
#endif // CYGOPT_IO_CAN_EXT_CAN_ID
} // while (lpc2xxx_global_can_info.active_channels[i])
//
// finally store end of table value and restore the previous state of the
// acceptance filter
//
HAL_WRITE_UINT32(CAN_ACCFILT_ENDOFTABLE, ext_address);
HAL_WRITE_UINT32(CAN_ACCFILT_AFMR, accfilt_bck);
}
#endif // CYGOPT_IO_CAN_RUNTIME_MBOX_CFG
//===========================================================================
// Reset acceptance filter to poweron defaults
//===========================================================================
void lpc2xxx_can_accfilt_reset(void)
{
cyg_uint32 accfilt_bck; // acceptance filter backup
//
// first step: disable acceptance filter and prepare it for modification
//
HAL_READ_UINT32(CAN_ACCFILT_AFMR, accfilt_bck);
HAL_WRITE_UINT32(CAN_ACCFILT_AFMR, AFMR_OFF | AFMR_BYPASS);
//
// Now write zero to all addresses of acceptance filter table
//
HAL_WRITE_UINT32(CAN_ACCFILT_SFF_SA, 0);
HAL_WRITE_UINT32(CAN_ACCFILT_SFF_GRP_SA, 0);
HAL_WRITE_UINT32(CAN_ACCFILT_EFF_SA, 0);
HAL_WRITE_UINT32(CAN_ACCFILT_EFF_GRP_SA, 0);
HAL_WRITE_UINT32(CAN_ACCFILT_ENDOFTABLE, 0);
//
// finally restore the prvious state of the acceptance filter
//
HAL_WRITE_UINT32(CAN_ACCFILT_AFMR, accfilt_bck);
}
//===========================================================================
// Dump content of acceptance filter lookup table
//===========================================================================
#ifdef CYGDBG_DEVS_CAN_LPC2XXX_DEBUG
void lpc2xxx_can_accfilt_dbg_dump(void)
{
cyg_uint32 sff_sa;
cyg_uint32 sff_grp_sa;
cyg_uint32 eff_sa;
cyg_uint32 eff_grp_sa;
cyg_uint32 end_of_table;
cyg_uint32 entry_address;
lsc_buf_t data;
HAL_READ_UINT32(CAN_ACCFILT_SFF_SA, sff_sa);
HAL_READ_UINT32(CAN_ACCFILT_SFF_GRP_SA, sff_grp_sa);
HAL_READ_UINT32(CAN_ACCFILT_EFF_SA, eff_sa);
HAL_READ_UINT32(CAN_ACCFILT_EFF_GRP_SA, eff_grp_sa);
HAL_READ_UINT32(CAN_ACCFILT_ENDOFTABLE, end_of_table);
entry_address = sff_sa;
//
// Print lookup table registers
//
diag_printf("\n\nDUMP CAN ACCEPTANCE FILTER REGISTERS\n");
diag_printf("----------------------------------------\n");
diag_printf("SFF_sa:\t\t0x%08x\n", sff_sa);
diag_printf("SFF_GRP_sa:\t0x%08x\n", sff_grp_sa);
diag_printf("EFF_sa:\t\t0x%08x\n", eff_sa);
diag_printf("EFF_GRP_sa:\t0x%08x\n", eff_grp_sa);
diag_printf("EOT:\t\t0x%08x\n", end_of_table);
//
// Print table of standard identifiers
//
diag_printf("\n\nDUMP CAN LOOKUP TABLE RAM");
diag_printf("\nSFF_sa\t\tcolumn_lower\tcolumn_upper\traw_data\n");
diag_printf("----------------------------------------------------------\n");
while (entry_address < sff_grp_sa)
{
HAL_READ_UINT32(CAN_ACCFILT_RAM_BASE + entry_address, data.dword);
diag_printf("0x%04x:\t\t0x%x\t\t0x%x\t\t0x%x\n", entry_address, data.column.lower, data.column.upper, data.dword);
entry_address += sizeof(cyg_uint32);
}
//
// Print table of standard identifier groups
//
diag_printf("\nSFF_GRP_sa\tcolumn_lower\tcolumn_upper\traw_data\n");
diag_printf("----------------------------------------------------------\n");
while (entry_address < eff_sa)
{
HAL_READ_UINT32(CAN_ACCFILT_RAM_BASE + entry_address, data.dword);
diag_printf("0x%04x:\t\t0x%x\t\t0x%x\t\t0x%x\n", entry_address, data.column.lower, data.column.upper, data.dword);
entry_address += sizeof(cyg_uint32);
}
//
// Print table of extended identifiers
//
diag_printf("\nEFF_sa\t\t-\t\t-\t\traw_data\n");
diag_printf("----------------------------------------------------------\n");
while (entry_address < eff_grp_sa)
{
HAL_READ_UINT32(CAN_ACCFILT_RAM_BASE + entry_address, data.dword);
diag_printf("0x%04x:\t\t\t\t\t\t0x%x\n", entry_address, data.dword);
entry_address += sizeof(cyg_uint32);
}
//
// Print table of extended identifier groups
//
diag_printf("\nEFF_GRP_sa\t-\t\t-\t\traw_data\n");
diag_printf("----------------------------------------------------------\n");
while (entry_address < end_of_table)
{
HAL_READ_UINT32(CAN_ACCFILT_RAM_BASE + entry_address, data.dword);
diag_printf("0x%04x:\t\t\t\t\t\t0x%x\n", entry_address, data.dword);
entry_address += sizeof(cyg_uint32);
}
}
#endif // CYGDBG_DEVS_CAN_LPC2XXX_DEBUG
//===========================================================================
// Dump content of acceptance filter lookup table
//===========================================================================
#ifdef CYGDBG_DEVS_CAN_LPC2XXX_DEBUG
void lpc2xxx_can_reg_dump(struct cyg_devtab_entry* devtab_entry)
{
can_channel *chan = (can_channel*)devtab_entry->priv;
cyg_uint32 reg_val;
CAN_DECLARE_INFO(chan);
chan = chan; // avoid compiler warnings for unused variables
//
// Print table of extended identifier groups
//
diag_printf("\n\nCAN REGISTER DUMP\n");
diag_printf("\nRegister\tValue\n");
diag_printf("----------------------------------------------------------\n");
HAL_READ_UINT32(CAN_CTRL_MOD(info), reg_val);
diag_printf("CANMOD\t\t0x%08x\n", reg_val);
HAL_READ_UINT32(CAN_CTRL_CMR(info), reg_val);
diag_printf("CANCMR\t\t0x%08x\n", reg_val);
HAL_READ_UINT32(CAN_CTRL_GSR(info), reg_val);
diag_printf("CANGSR\t\t0x%08x\n", reg_val);
HAL_READ_UINT32(CAN_CTRL_ICR(info), reg_val);
diag_printf("CANICR\t\t0x%08x\n", reg_val);
HAL_READ_UINT32(CAN_CTRL_IER(info), reg_val);
diag_printf("CANIER\t\t0x%08x\n", reg_val);
HAL_READ_UINT32(CAN_CTRL_BTR(info), reg_val);
diag_printf("CANBTR\t\t0x%08x\n", reg_val);
HAL_READ_UINT32(CAN_CTRL_EWL(info), reg_val);
diag_printf("CANEWL\t\t0x%08x\n", reg_val);
HAL_READ_UINT32(CAN_CTRL_SR(info), reg_val);
diag_printf("CANSR\t\t0x%08x\n", reg_val);
HAL_READ_UINT32(CAN_CTRL_RFS(info), reg_val);
diag_printf("CANRFS\t\t0x%08x\n", reg_val);
HAL_READ_UINT32(CAN_CTRL_RID(info), reg_val);
diag_printf("CANRID\t\t0x%08x\n", reg_val);
HAL_READ_UINT32(CAN_CTRL_RDA(info), reg_val);
diag_printf("CANRDA\t\t0x%08x\n", reg_val);
HAL_READ_UINT32(CAN_CTRL_RDB(info), reg_val);
diag_printf("CANRDB\t\t0x%08x\n", reg_val);
diag_printf("\n\nCAN CENTRAL REGISTER DUMP\n");
diag_printf("\nRegister\tValue\n");
diag_printf("----------------------------------------------------------\n");
HAL_READ_UINT32(CAN_CENTRAL_TXSR, reg_val);
diag_printf("CANTxSR\t\t0x%08x\n", reg_val);
HAL_READ_UINT32(CAN_CENTRAL_RXSR, reg_val);
diag_printf("CANRxSR\t\t0x%08x\n", reg_val);
HAL_READ_UINT32(CAN_CENTRAL_MSR, reg_val);
diag_printf("CANMSR\t\t0x%08x\n", reg_val);
diag_printf("\n\nCAN ACCEPTANCE FILTER REGISTER DUMP\n");
diag_printf("\nRegister\tValue\n");
diag_printf("----------------------------------------------------------\n");
HAL_READ_UINT32(CAN_ACCFILT_AFMR, reg_val);
diag_printf("AFMR\t\t0x%08x\n", reg_val);
HAL_READ_UINT32(CAN_ACCFILT_LUT_ERR, reg_val);
diag_printf("LUTERR\t\t0x%08x\n", reg_val);
HAL_READ_UINT32(CAN_ACCFILT_LUT_ERR_ADDR, reg_val);
diag_printf("LUTERRADDR\t0x%08x\n", reg_val);
}
#endif // #ifdef CYGDBG_DEVS_CAN_LPC2XXX_DEBUG
//---------------------------------------------------------------------------
// EOF can_accfilt_lpc2xxx.c
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -