9、can总线相关内容
can总线是一种串行通讯总线。具有多主控制的特点,及在总线空闲时,所有单元都可以开始发送消息,最先访问总线的单元可以获得发送权。多个单元同时访问总线时,发送高优先级id消息的单元可以优先访问。
can总线中利用id标识各个节点。在节点发送数据时,发送的报文帧中也应含有节点的id信息。
// can总线相关抽象结构体定义
typedef struct { __IO uint32_t TIR; /*!< CAN TX mailbox identifier register */ __IO uint32_t TDTR; /*!< CAN mailbox data length control and time stamp register */ __IO uint32_t TDLR; /*!< CAN mailbox data low register */ __IO uint32_t TDHR; /*!< CAN mailbox data high register */ } CAN_TxMailBox_TypeDef; /** * @brief Controller Area Network FIFOMailBox */ typedef struct { __IO uint32_t RIR; /*!< CAN receive FIFO mailbox identifier register */ __IO uint32_t RDTR; /*!< CAN receive FIFO mailbox data length control and time stamp register */ __IO uint32_t RDLR; /*!< CAN receive FIFO mailbox data low register */ __IO uint32_t RDHR; /*!< CAN receive FIFO mailbox data high register */ } CAN_FIFOMailBox_TypeDef; /** * @brief Controller Area Network FilterRegister */ typedef struct { __IO uint32_t FR1; /*!< CAN Filter bank register 1 */ __IO uint32_t FR2; /*!< CAN Filter bank register 1 */ } CAN_FilterRegister_TypeDef; /** * @brief Controller Area Network */ typedef struct { __IO uint32_t MCR; /*!< CAN master control register, Address offset: 0x00 */ __IO uint32_t MSR; /*!< CAN master status register, Address offset: 0x04 */ __IO uint32_t TSR; /*!< CAN transmit status register, Address offset: 0x08 */ __IO uint32_t RF0R; /*!< CAN receive FIFO 0 register, Address offset: 0x0C */ __IO uint32_t RF1R; /*!< CAN receive FIFO 1 register, Address offset: 0x10 */ __IO uint32_t IER; /*!< CAN interrupt enable register, Address offset: 0x14 */ __IO uint32_t ESR; /*!< CAN error status register, Address offset: 0x18 */ __IO uint32_t BTR; /*!< CAN bit timing register, Address offset: 0x1C */ uint32_t RESERVED0[88]; /*!< Reserved, 0x020 - 0x17F */ CAN_TxMailBox_TypeDef sTxMailBox[3]; /*!< CAN Tx MailBox, Address offset: 0x180 - 0x1AC */ CAN_FIFOMailBox_TypeDef sFIFOMailBox[2]; /*!< CAN FIFO MailBox, Address offset: 0x1B0 - 0x1CC */ uint32_t RESERVED1[12]; /*!< Reserved, 0x1D0 - 0x1FF */ __IO uint32_t FMR; /*!< CAN filter master register, Address offset: 0x200 */ __IO uint32_t FM1R; /*!< CAN filter mode register, Address offset: 0x204 */ uint32_t RESERVED2; /*!< Reserved, 0x208 */ __IO uint32_t FS1R; /*!< CAN filter scale register, Address offset: 0x20C */ uint32_t RESERVED3; /*!< Reserved, 0x210 */ __IO uint32_t FFA1R; /*!< CAN filter FIFO assignment register, Address offset: 0x214 */ uint32_t RESERVED4; /*!< Reserved, 0x218 */ __IO uint32_t FA1R; /*!< CAN filter activation register, Address offset: 0x21C */ uint32_t RESERVED5[8]; /*!< Reserved, 0x220-0x23F */ CAN_FilterRegister_TypeDef sFilterRegister[28]; /*!< CAN Filter Register, Address offset: 0x240-0x31C */ } CAN_TypeDef;
// 这是要用到的一些宏定义
#define SET_BIT(REG, BIT) ((REG) |= (BIT)) #define CLEAR_BIT(REG, BIT) ((REG) &= ~(BIT)) #define READ_BIT(REG, BIT) ((REG) & (BIT)) #define CLEAR_REG(REG) ((REG) = (0x0)) #define WRITE_REG(REG, VAL) ((REG) = (VAL)) #define READ_REG(REG) ((REG)) #define MODIFY_REG(REG, CLEARMASK, SETMASK) WRITE_REG((REG), (((READ_REG(REG)) & (~(CLEARMASK))) | (SETMASK))) #define POSITION_VAL(VAL) (__CLZ(__RBIT(VAL)))
//====================================================================== //文件名称:can.c //功能概要:uart底层驱动构件源文件 //版权所有:苏州大学嵌入式系统与物联网研究所(sumcu.suda.edu.cn) //更新记录:2021-02-03 V1.0 JJL //====================================================================== #include "can.h" CAN_TypeDef *CAN_ARR[] = {(CAN_TypeDef*)CAN1_BASE}; IRQn_Type table_irq_can[2] = {CAN1_RX0_IRQn, CAN1_RX1_IRQn}; uint8_t can_send_once(uint8_t canNo, uint32_t DestID, uint16_t len ,uint8_t* buff); uint8_t CAN_HWInit(uint8_t CANChannel); uint8_t CAN_SWInit_Entry(uint8_t canNo); void CAN_SWInit_CTLMode(uint8_t canNo); void CAN_SWInit_BT(uint8_t canNo, uint32_t CANMode, uint32_t Prescaler); uint8_t CAN_SWInit_Quit(uint8_t canNo); uint8_t CANFilterConfig(uint8_t canNo, uint32_t canID, uint32_t FilterBank, uint32_t Can_Rx_FifoNo, uint8_t IsActivate, uint32_t FilterMode, uint32_t FilterScale); //===================================================================== //函数名称:can_init //函数返回:无 //参数说明:canNo:模块号,本芯片只有CAN_1 // canID:自身CAN节点的唯一标识,例如按照CANopen协议给出 // BitRate:位速率 //功能概要:初始化CAN模块 //===================================================================== void can_init(uint8_t canNo, uint32_t canID, uint32_t BitRate) { //声明Init函数使用的局部变量 uint32_t CANMode; uint32_t CANFilterBank; uint32_t CANFiltermode; uint32_t CAN_Filterscale; //给Init函数使用的局部变量赋初值 CANMode = CAN_MODE_NORMAL; CANFilterBank = CANFilterBank0; CANFiltermode = CAN_FILTERMODE_IDMASK; CAN_Filterscale = CAN_FILTERSCALE_32BIT; //(1)CAN总线硬件初始化 CAN_HWInit(CAN_CHANNEL); //(2)CAN总线进入软件初始化模式 CAN_SWInit_Entry(canNo); //(3)CAN总线模式设置 CAN_SWInit_CTLMode(canNo); //(4)CAN总线位时序配置 CAN_SWInit_BT(canNo,CANMode,BitRate); //(5)CAN总线过滤器初始化 CANFilterConfig(canNo, canID, CANFilterBank, CAN_RX_FIFO0, 1, CANFiltermode, CAN_Filterscale); //(6)CAN总线退出软件初始化模式,进入正常模式 CAN_SWInit_Quit(canNo); }
//=====================================================================
//函数名称:can_send_once
//函数返回:0=正常,1=错误
//参数说明:canNo:模块号,本芯片只有CAN_1
// DestID:目标CAN节点的唯一标识,例如按照CANopen协议给出
// len:待发送数据的字节数
// buff:待发送数据发送缓冲区首地址
//功能概要:CAN模块发送一次数据
//=====================================================================
uint8_t can_send_once(uint8_t canNo, uint32_t DestID, uint16_t len ,uint8_t* buff)
{
//(1)定义Can发送函数所需要用到的变量
uint32_t transmit_mailbox;
uint32_t register_tsr;
uint32_t rtr;
rtr = CAN_RTR_DATA;
register_tsr = READ_REG(CAN_ARR[canNo-1]->TSR);
//(2)判断3个邮箱中是否有空闲邮箱,若有,选取其中一个进行发送,选取顺序为1,2,3
if (((register_tsr & CAN_TSR_TME0) != 0U) ||
((register_tsr & CAN_TSR_TME1) != 0U) ||
((register_tsr & CAN_TSR_TME2) != 0U))
{
transmit_mailbox = (register_tsr & CAN_TSR_CODE) >> CAN_TSR_CODE_Pos;
if(transmit_mailbox > 2U)
{
return 1;
}
//(2.1)判断并设置发送帧为标准帧还是扩展帧
if(DestID <= 0x7FFU)
{
CAN_ARR[canNo-1]->sTxMailBox[transmit_mailbox].TIR = ((DestID << CAN_TI0R_STID_Pos)|CAN_ID_STD|rtr);
}
else
{
CAN_ARR[canNo-1]->sTxMailBox[transmit_mailbox].TIR = ((DestID << CAN_TI0R_EXID_Pos)|CAN_ID_EXT|rtr);
}
//(2.2)设置发送帧的数据长度
CAN_ARR[canNo-1]->sTxMailBox[transmit_mailbox].TDTR = len;
//SET_BIT(CAN_ARR[canNo-1]->sTxMailBox[transmit_mailbox].TDTR, CAN_TDT0R_TGT);
//(2.3)设置发送帧的数据
WRITE_REG(CAN_ARR[canNo-1]->sTxMailBox[transmit_mailbox].TDHR,
((uint32_t)buff[7] << CAN_TDH0R_DATA7_Pos) |
((uint32_t)buff[6] << CAN_TDH0R_DATA6_Pos) |
((uint32_t)buff[5] << CAN_TDH0R_DATA5_Pos) |
((uint32_t)buff[4] << CAN_TDH0R_DATA4_Pos));
WRITE_REG(CAN_ARR[canNo-1]->sTxMailBox[transmit_mailbox].TDLR,
((uint32_t)buff[3] << CAN_TDL0R_DATA3_Pos) |
((uint32_t)buff[2] << CAN_TDL0R_DATA2_Pos) |
((uint32_t)buff[1] << CAN_TDL0R_DATA1_Pos) |
((uint32_t)buff[0] << CAN_TDL0R_DATA0_Pos));
//(2.4)发送Can数据报
SET_BIT(CAN_ARR[canNo-1]->sTxMailBox[transmit_mailbox].TIR, CAN_TI0R_TXRQ);
return 0;
}
else
{
return 1;
}
}
//===================================================================== //函数名称:can_send //函数返回:0=正常,1=错误 //参数说明:canNo:模块号,本芯片只有CAN_1 // DestID:目标CAN节点的唯一标识,例如按照CANopen协议给出 // len:待发送数据的字节数 // buff:待发送数据发送缓冲区首地址 //功能概要:CAN模块发送数据 //===================================================================== uint8_t can_send(uint8_t canNo, uint32_t DestID, uint16_t len ,uint8_t* buff) { if(DestID > 0x1FFFFFFFU) return 1; uint8_t send_length; for(int i = len; i > 0; i = i-8) { send_length = (i>8)?8:i; if(can_send_once(canNo,DestID,send_length,buff+len-i) == 1) { return 1; } } return 0; } //===================================================================== //函数名称:can_recv //函数返回:接收到的字节数 //参数说明:canNo:模块号,本芯片只有CAN_1 // buff:接收到的数据存放的内存区首地址 //功能概要:在CAN模块接收中断中调用本函数接收已经到达的数据 //===================================================================== uint8_t can_recv(uint8_t canNo, uint8_t *buff) { uint8_t len; uint32_t RxFifo = CAN_RX_FIFO0; //(1)判断哪个邮箱收到了报文信息 if(RxFifo == CAN_RX_FIFO0) { if ((CAN_ARR[canNo-1]->RF0R & CAN_RF0R_FMP0) == 0U) { return 1; } } else { if ((CAN_ARR[canNo-1]->RF1R & CAN_RF1R_FMP1) == 0U) { return 1; } } //(2)获取数据长度 len = (CAN_RDT0R_DLC & CAN_ARR[canNo-1]->sFIFOMailBox[RxFifo].RDTR) >> CAN_RDT0R_DLC_Pos; //(3)获取数据帧中的数据 buff[0] = (uint8_t)((CAN_RDL0R_DATA0 & CAN_ARR[canNo-1]->sFIFOMailBox[RxFifo].RDLR) >> CAN_RDL0R_DATA0_Pos); buff[1] = (uint8_t)((CAN_RDL0R_DATA1 & CAN_ARR[canNo-1]->sFIFOMailBox[RxFifo].RDLR) >> CAN_RDL0R_DATA1_Pos); buff[2] = (uint8_t)((CAN_RDL0R_DATA2 & CAN_ARR[canNo-1]->sFIFOMailBox[RxFifo].RDLR) >> CAN_RDL0R_DATA2_Pos); buff[3] = (uint8_t)((CAN_RDL0R_DATA3 & CAN_ARR[canNo-1]->sFIFOMailBox[RxFifo].RDLR) >> CAN_RDL0R_DATA3_Pos); buff[4] = (uint8_t)((CAN_RDH0R_DATA4 & CAN_ARR[canNo-1]->sFIFOMailBox[RxFifo].RDHR) >> CAN_RDH0R_DATA4_Pos); buff[5] = (uint8_t)((CAN_RDH0R_DATA5 & CAN_ARR[canNo-1]->sFIFOMailBox[RxFifo].RDHR) >> CAN_RDH0R_DATA5_Pos); buff[6] = (uint8_t)((CAN_RDH0R_DATA6 & CAN_ARR[canNo-1]->sFIFOMailBox[RxFifo].RDHR) >> CAN_RDH0R_DATA6_Pos); buff[7] = (uint8_t)((CAN_RDH0R_DATA7 & CAN_ARR[canNo-1]->sFIFOMailBox[RxFifo].RDHR) >> CAN_RDH0R_DATA7_Pos); //(4)清除标志位,等待接收下一帧数据 if (RxFifo == CAN_RX_FIFO0) { SET_BIT(CAN_ARR[canNo-1]->RF0R, CAN_RF0R_RFOM0); } else { SET_BIT(CAN_ARR[canNo-1]->RF1R, CAN_RF1R_RFOM1); } return len; } //===================================================================== //函数名称:CAN_enable_re_int //函数返回:无 //参数说明:canNo:模块基地址号,Can_Rx_FifoNo:中断使用的邮箱号 //功能概要:CAN接收中断开启 //===================================================================== void can_enable_recv_int(uint8_t canNo) { uint8_t Can_Rx_FifoNo; Can_Rx_FifoNo = CAN_RX_FIFO0; if(Can_Rx_FifoNo == CAN_RX_FIFO0) SET_BIT(CAN_ARR[canNo-1]->IER, CAN_IER_FMPIE0); else SET_BIT(CAN_ARR[canNo-1]->IER,CAN_IER_FMPIE1); NVIC_EnableIRQ(table_irq_can[Can_Rx_FifoNo]); } //===================================================================== //函数名称:can_disable_recv_int //函数返回:无 //参数说明:canNo:模块号,本芯片只有CAN_1 //功能概要:关闭CAN接收中断 //===================================================================== void can_disable_recv_int (uint8_t canNo) { uint8_t Can_Rx_FifoNo; Can_Rx_FifoNo = CAN_RX_FIFO0; if(Can_Rx_FifoNo == CAN_RX_FIFO0) CLEAR_BIT(CAN_ARR[canNo-1]->IER, CAN_IER_FMPIE0); else CLEAR_BIT(CAN_ARR[canNo-1]->IER,CAN_IER_FMPIE1); NVIC_DisableIRQ(table_irq_can[Can_Rx_FifoNo]); } //===================================================================== //函数名称:CAN_HWInit //函数返回:0=正常,1=错误 //参数说明:CANChannel:硬件引脚组号,共有3组,分别为PTA11&PTA12(CAN_CHANNEL0),PTB8&PTB9(CAN_CHANNEL1),PTD0&PTD1(2) //功能概要:CAN模块引脚初始化 //===================================================================== uint8_t CAN_HWInit(uint8_t CANChannel) { if(CANChannel < 0 || CANChannel > 2) { return 1; } if(CANChannel == 0) { RCC->APB1ENR1 |= RCC_APB1ENR1_CAN1EN; RCC->AHB2ENR |= RCC_AHB2ENR_GPIOAEN; GPIOA->MODER &= ~(GPIO_MODER_MODE11|GPIO_MODER_MODE12); GPIOA->MODER |= (GPIO_MODER_MODE11_1|GPIO_MODER_MODE12_1); GPIOA->AFR[1] &= ~(GPIO_AFRH_AFSEL11|GPIO_AFRH_AFSEL12); GPIOA->AFR[1] |= (GPIO_AFRH_AFSEL11_0|GPIO_AFRH_AFSEL11_3)|(GPIO_AFRH_AFSEL12_0|GPIO_AFRH_AFSEL12_3); } else if(CANChannel == 1) { RCC->APB1ENR1 |= RCC_APB1ENR1_CAN1EN; RCC->AHB2ENR |= RCC_AHB2ENR_GPIOBEN; GPIOB->MODER &= ~(GPIO_MODER_MODE8|GPIO_MODER_MODE9); GPIOB->MODER |= (GPIO_MODER_MODE8_1|GPIO_MODER_MODE9_1); GPIOB->AFR[1] &= ~(GPIO_AFRH_AFSEL8|GPIO_AFRH_AFSEL9); GPIOB->AFR[1] |= ((GPIO_AFRH_AFSEL8_0|GPIO_AFRH_AFSEL8_3)| (GPIO_AFRH_AFSEL9_0|GPIO_AFRH_AFSEL9_3)); } else { RCC->APB1ENR1 |= RCC_APB1ENR1_CAN1EN; RCC->AHB2ENR |= RCC_AHB2ENR_GPIODEN; GPIOD->MODER &= ~(GPIO_MODER_MODE0|GPIO_MODER_MODE1); GPIOD->MODER |= (GPIO_MODER_MODE0_1|GPIO_MODER_MODE1_1); GPIOD->AFR[0] &= ~(GPIO_AFRL_AFSEL0|GPIO_AFRL_AFSEL1); GPIOD->AFR[0] |= ((GPIO_AFRL_AFSEL0_0 | GPIO_AFRL_AFSEL0_3)| (GPIO_AFRL_AFSEL1_0 | GPIO_AFRL_AFSEL1_3)); } return 0; } //===================================================================== //函数名称:CAN_SWInit_Entry //函数返回:0=正常,1=错误 //参数说明:canNo:模块基地址号,本芯片只有CAN_1, //功能概要:进入初始化模式 //===================================================================== uint8_t CAN_SWInit_Entry(uint8_t canNo) { int i; CLEAR_BIT(CAN_ARR[canNo-1]->MCR, CAN_MCR_SLEEP); i = 0; while ((CAN_ARR[canNo-1]->MSR & CAN_MSR_SLAK) != 0U) { if(i++ > 0x30000) { return 1; } } SET_BIT(CAN_ARR[canNo-1]->MCR, CAN_MCR_INRQ); i = 0; while ((CAN_ARR[canNo-1]->MSR & CAN_MSR_INAK) == 0U) { if(i++ > 0x30000) { return 1; } } return 0; } //===================================================================== //函数名称:CAN_SWInit_CTLMode //函数返回:无 //参数说明:canNo:模块基地址号,本芯片只有CAN_1, //功能概要:CAN总线模式设置 //===================================================================== void CAN_SWInit_CTLMode(uint8_t canNo) { CLEAR_BIT(CAN_ARR[canNo-1]->MCR, CAN_MCR_TTCM); CLEAR_BIT(CAN_ARR[canNo-1]->MCR, CAN_MCR_ABOM); CLEAR_BIT(CAN_ARR[canNo-1]->MCR, CAN_MCR_AWUM); SET_BIT(CAN_ARR[canNo-1]->MCR, CAN_MCR_NART); CLEAR_BIT(CAN_ARR[canNo-1]->MCR, CAN_MCR_RFLM); CLEAR_BIT(CAN_ARR[canNo-1]->MCR, CAN_MCR_TXFP); } //函数名称:CAN_SWInit_CTLMode //函数返回:无 //参数说明:canNo:模块基地址号,本芯片只有CAN_1, // CANMode:CAN总线工作模式,分别为正常模式(CAN_MODE_NORMAL)、回环模式(CAN_MODE_LOOPBACK)、 // 静默模式(CAN_MODE_SILENT)以及回环与静默组合模式(CAN_MODE_SILENT_LOOPBACK) //功能概要:CAN总线位时序配置 void CAN_SWInit_BT(uint8_t canNo, uint32_t CANMode, uint32_t Prescaler) { CAN_ARR[canNo-1]->BTR |= ((uint32_t)(Prescaler-1)|CAN_SJW_1TQ|CAN_BTR_TS1_1|CAN_BTR_TS1_0|CAN_BTR_TS2_2|CANMode); } //===================================================================== //函数名称:CAN_SWInit_Quit //函数返回:0=正常,1=错误 //参数说明:canNo:模块基地址号 //功能概要:退出初始化模式,进入正常模式 //===================================================================== uint8_t CAN_SWInit_Quit(uint8_t canNo) { int i; CLEAR_BIT(CAN_ARR[canNo-1]->MCR, CAN_MCR_INRQ); i = 0; while ((CAN_ARR[canNo-1]->MSR & CAN_MSR_INAK) != 0U) { if (i++ > 0x30000) { return 1; } } return 0; } //===================================================================== //函数名称: CANFilterConfig //函数返回:0=正常,1=错误 //参数说明: canNo:模块基地址号, // canID:自身CAN节点的唯一标识,例如按照CANopen协议给出 // Can_Rx_FifoNo:中断使用的邮箱号, // IsActivate:是否激活过滤器 // CANFilterBank:CAN总线过滤器组选择,共有28个,(CANFilterBank0~CANFilterBank27) // CANFiltermode:CAN总线过滤器模式,分别为掩码模式(CAN_FILTERMODE_IDMASK)和列表模式(CAN_FILTERMODE_IDLIST) // CAN_Filterscale:CAN总线过滤器位数,分别为32位(CAN_FILTERSCALE_32BIT)和16位(CAN_FILTERSCALE_16BIT) //功能概要:CAN接收中断开启 //===================================================================== uint8_t CANFilterConfig(uint8_t canNo, uint32_t CanID, uint32_t FilterBank, uint32_t Can_Rx_FifoNo, uint8_t IsActivate, uint32_t FilterMode, uint32_t FilterScale) { uint32_t FilterIdHigh, FilterIdLow, FilterMaskIdHigh, FilterMaskIdLow, filternbrbitpos; if(CanID <= 0x7FFU) CanID = CanID << CAN_TI0R_STID_Pos; FilterIdHigh = (CanID >> 16) & 0xFFFF; FilterIdLow = (CanID & 0xFFFF); FilterMaskIdHigh = 0xFFE0; FilterMaskIdLow = 0x0000; filternbrbitpos = (uint32_t)1 << (FilterBank & 0x1FU); //设置过滤器初始化模式 (FINIT=1),在此模式下可以进行过滤器初始化 SET_BIT(CAN_ARR[canNo-1]->FMR, CAN_FMR_FINIT); CLEAR_BIT(CAN_ARR[canNo-1]->FA1R, filternbrbitpos); if (FilterScale == CAN_FILTERSCALE_16BIT) { CLEAR_BIT(CAN_ARR[canNo-1]->FS1R, filternbrbitpos); CAN_ARR[canNo-1]->sFilterRegister[FilterBank].FR1 = ((0x0000FFFFU & (uint32_t)FilterMaskIdLow) << 16U) | (0x0000FFFFU & (uint32_t)FilterIdLow); CAN_ARR[canNo-1]->sFilterRegister[FilterBank].FR2 = ((0x0000FFFFU & (uint32_t)FilterMaskIdHigh) << 16U) | (0x0000FFFFU & (uint32_t)FilterIdHigh); } if (FilterScale == CAN_FILTERSCALE_32BIT) { SET_BIT(CAN_ARR[canNo-1]->FS1R, filternbrbitpos); CAN_ARR[canNo-1]->sFilterRegister[FilterBank].FR1 = ((0x0000FFFFU & (uint32_t)FilterIdHigh) << 16U) | (0x0000FFFFU & (uint32_t)FilterIdLow); CAN_ARR[canNo-1]->sFilterRegister[FilterBank].FR2 = ((0x0000FFFFU & (uint32_t)FilterMaskIdHigh) << 16U) | (0x0000FFFFU & (uint32_t)FilterMaskIdLow); } if (FilterMode == CAN_FILTERMODE_IDMASK) { CLEAR_BIT(CAN_ARR[canNo-1]->FM1R, filternbrbitpos); } else { SET_BIT(CAN_ARR[canNo-1]->FM1R, filternbrbitpos); } if (Can_Rx_FifoNo == CAN_FILTER_FIFO0) { CLEAR_BIT(CAN_ARR[canNo-1]->FFA1R, filternbrbitpos); } else { SET_BIT(CAN_ARR[canNo-1]->FFA1R, filternbrbitpos); } if (IsActivate == 1) { SET_BIT(CAN_ARR[canNo-1]->FA1R, filternbrbitpos); } //退出过滤器初始化模式 (FINIT=0) CLEAR_BIT(CAN_ARR[canNo-1]->FMR, CAN_FMR_FINIT); return 0; }