can.c
来自「INFINEON公司弹片机XC164源码示例,CAN总线通讯初始化和应用代码示例」· C语言 代码 · 共 1,511 行 · 第 1/5 页
C
1,511 行
CAN_MSGDRL250 = 0x0000; // load data register 0 low
CAN_MSGDRH250 = 0x0000; // load data register 0 high
CAN_MSGDRL254 = 0x0000; // load data register 4 low
CAN_MSGDRH254 = 0x0000; // load data register 4 high
/// - FIFO functionality; this is a FIFO slave object connected to the
/// base object 24
/// - the CANPTR is updated after a correct transmission of a frame (FIFO
/// transmission)
CAN_MSGFGCRL25 = 0x2007; // load FIFO/gateway control register low
CAN_MSGFGCRH25 = 0x0318; // load FIFO/gateway control register high
CAN_MSGCTRH25 = 0x0000; // load message control register high
CAN_MSGCTRL25 = 0x5595; // load message control register low
/// -----------------------------------------------------------------------
/// Configuration of Message Object 26:
/// -----------------------------------------------------------------------
/// - message object 26 is valid
/// - message object is used as transmit object
/// - extended 29-bit identifier
/// - 0 valid data bytes
/// - this message object works with CAN node B
/// - remote monitoring is disabled
CAN_MSGCFGL26 = 0x000E; // load message configuration register low
CAN_MSGCFGH26 = 0x0000; // load message configuration register high
/// - acceptance mask 29-bit: 0xFFFF
/// - identifier 29-bit: 0x0000
CAN_MSGAMRL26 = 0xFFFF; // load acceptance mask register low
CAN_MSGAMRH26 = 0xFFFF; // load acceptance mask register high
CAN_MSGARL26 = 0x0000; // load arbitration register low
CAN_MSGARH26 = 0x0000; // load arbitration register high
CAN_MSGDRL260 = 0x0000; // load data register 0 low
CAN_MSGDRH260 = 0x0000; // load data register 0 high
CAN_MSGDRL264 = 0x0000; // load data register 4 low
CAN_MSGDRH264 = 0x0000; // load data register 4 high
/// - FIFO functionality; this is a FIFO slave object connected to the
/// base object 24
/// - the CANPTR is updated after a correct transmission of a frame (FIFO
/// transmission)
CAN_MSGFGCRL26 = 0x2007; // load FIFO/gateway control register low
CAN_MSGFGCRH26 = 0x0318; // load FIFO/gateway control register high
CAN_MSGCTRH26 = 0x0000; // load message control register high
CAN_MSGCTRL26 = 0x5595; // load message control register low
/// -----------------------------------------------------------------------
/// Configuration of Message Object 27:
/// -----------------------------------------------------------------------
/// - message object 27 is valid
/// - message object is used as transmit object
/// - extended 29-bit identifier
/// - 0 valid data bytes
/// - this message object works with CAN node B
/// - remote monitoring is disabled
CAN_MSGCFGL27 = 0x000E; // load message configuration register low
CAN_MSGCFGH27 = 0x0000; // load message configuration register high
/// - acceptance mask 29-bit: 0xFFFF
/// - identifier 29-bit: 0x0000
CAN_MSGAMRL27 = 0xFFFF; // load acceptance mask register low
CAN_MSGAMRH27 = 0xFFFF; // load acceptance mask register high
CAN_MSGARL27 = 0x0000; // load arbitration register low
CAN_MSGARH27 = 0x0000; // load arbitration register high
CAN_MSGDRL270 = 0x0000; // load data register 0 low
CAN_MSGDRH270 = 0x0000; // load data register 0 high
CAN_MSGDRL274 = 0x0000; // load data register 4 low
CAN_MSGDRH274 = 0x0000; // load data register 4 high
/// - FIFO functionality; this is a FIFO slave object connected to the
/// base object 24
/// - the CANPTR is updated after a correct transmission of a frame (FIFO
/// transmission)
CAN_MSGFGCRL27 = 0x2007; // load FIFO/gateway control register low
CAN_MSGFGCRH27 = 0x0318; // load FIFO/gateway control register high
CAN_MSGCTRH27 = 0x0000; // load message control register high
CAN_MSGCTRL27 = 0x5595; // load message control register low
/// -----------------------------------------------------------------------
/// Configuration of Message Object 28:
/// -----------------------------------------------------------------------
/// - message object 28 is valid
/// - message object is used as transmit object
/// - extended 29-bit identifier
/// - 0 valid data bytes
/// - this message object works with CAN node B
/// - remote monitoring is disabled
CAN_MSGCFGL28 = 0x000E; // load message configuration register low
CAN_MSGCFGH28 = 0x0000; // load message configuration register high
/// - acceptance mask 29-bit: 0xFFFF
/// - identifier 29-bit: 0x0000
CAN_MSGAMRL28 = 0xFFFF; // load acceptance mask register low
CAN_MSGAMRH28 = 0xFFFF; // load acceptance mask register high
CAN_MSGARL28 = 0x0000; // load arbitration register low
CAN_MSGARH28 = 0x0000; // load arbitration register high
CAN_MSGDRL280 = 0x0000; // load data register 0 low
CAN_MSGDRH280 = 0x0000; // load data register 0 high
CAN_MSGDRL284 = 0x0000; // load data register 4 low
CAN_MSGDRH284 = 0x0000; // load data register 4 high
/// - FIFO functionality; this is a FIFO slave object connected to the
/// base object 24
/// - the CANPTR is updated after a correct transmission of a frame (FIFO
/// transmission)
CAN_MSGFGCRL28 = 0x2007; // load FIFO/gateway control register low
CAN_MSGFGCRH28 = 0x0318; // load FIFO/gateway control register high
CAN_MSGCTRH28 = 0x0000; // load message control register high
CAN_MSGCTRL28 = 0x5595; // load message control register low
/// -----------------------------------------------------------------------
/// Configuration of Message Object 29:
/// -----------------------------------------------------------------------
/// - message object 29 is valid
/// - message object is used as transmit object
/// - extended 29-bit identifier
/// - 0 valid data bytes
/// - this message object works with CAN node B
/// - remote monitoring is disabled
CAN_MSGCFGL29 = 0x000E; // load message configuration register low
CAN_MSGCFGH29 = 0x0000; // load message configuration register high
/// - acceptance mask 29-bit: 0xFFFF
/// - identifier 29-bit: 0x0000
CAN_MSGAMRL29 = 0xFFFF; // load acceptance mask register low
CAN_MSGAMRH29 = 0xFFFF; // load acceptance mask register high
CAN_MSGARL29 = 0x0000; // load arbitration register low
CAN_MSGARH29 = 0x0000; // load arbitration register high
CAN_MSGDRL290 = 0x0000; // load data register 0 low
CAN_MSGDRH290 = 0x0000; // load data register 0 high
CAN_MSGDRL294 = 0x0000; // load data register 4 low
CAN_MSGDRH294 = 0x0000; // load data register 4 high
/// - FIFO functionality; this is a FIFO slave object connected to the
/// base object 24
/// - the CANPTR is updated after a correct transmission of a frame (FIFO
/// transmission)
CAN_MSGFGCRL29 = 0x2007; // load FIFO/gateway control register low
CAN_MSGFGCRH29 = 0x0318; // load FIFO/gateway control register high
CAN_MSGCTRH29 = 0x0000; // load message control register high
CAN_MSGCTRL29 = 0x5595; // load message control register low
/// -----------------------------------------------------------------------
/// Configuration of Message Object 30:
/// -----------------------------------------------------------------------
/// - message object 30 is valid
/// - message object is used as transmit object
/// - extended 29-bit identifier
/// - 0 valid data bytes
/// - this message object works with CAN node B
/// - remote monitoring is disabled
CAN_MSGCFGL30 = 0x000E; // load message configuration register low
CAN_MSGCFGH30 = 0x0000; // load message configuration register high
/// - acceptance mask 29-bit: 0xFFFF
/// - identifier 29-bit: 0x0000
CAN_MSGAMRL30 = 0xFFFF; // load acceptance mask register low
CAN_MSGAMRH30 = 0xFFFF; // load acceptance mask register high
CAN_MSGARL30 = 0x0000; // load arbitration register low
CAN_MSGARH30 = 0x0000; // load arbitration register high
CAN_MSGDRL300 = 0x0000; // load data register 0 low
CAN_MSGDRH300 = 0x0000; // load data register 0 high
CAN_MSGDRL304 = 0x0000; // load data register 4 low
CAN_MSGDRH304 = 0x0000; // load data register 4 high
/// - FIFO functionality; this is a FIFO slave object connected to the
/// base object 24
/// - the CANPTR is updated after a correct transmission of a frame (FIFO
/// transmission)
CAN_MSGFGCRL30 = 0x2007; // load FIFO/gateway control register low
CAN_MSGFGCRH30 = 0x0318; // load FIFO/gateway control register high
CAN_MSGCTRH30 = 0x0000; // load message control register high
CAN_MSGCTRL30 = 0x5595; // load message control register low
/// -----------------------------------------------------------------------
/// Configuration of Message Object 31:
/// -----------------------------------------------------------------------
/// - message object 31 is valid
/// - message object is used as transmit object
/// - extended 29-bit identifier
/// - 0 valid data bytes
/// - this message object works with CAN node B
/// - remote monitoring is disabled
CAN_MSGCFGL31 = 0x000E; // load message configuration register low
CAN_MSGCFGH31 = 0x0000; // load message configuration register high
/// - acceptance mask 29-bit: 0xFFFF
/// - identifier 29-bit: 0x0000
CAN_MSGAMRL31 = 0xFFFF; // load acceptance mask register low
CAN_MSGAMRH31 = 0xFFFF; // load acceptance mask register high
CAN_MSGARL31 = 0x0000; // load arbitration register low
CAN_MSGARH31 = 0x0000; // load arbitration register high
CAN_MSGDRL310 = 0x0000; // load data register 0 low
CAN_MSGDRH310 = 0x0000; // load data register 0 high
CAN_MSGDRL314 = 0x0000; // load data register 4 low
CAN_MSGDRH314 = 0x0000; // load data register 4 high
/// - FIFO functionality; this is a FIFO slave object connected to the
/// base object 24
/// - the CANPTR is updated after a correct transmission of a frame (FIFO
/// transmission)
CAN_MSGFGCRL31 = 0x2007; // load FIFO/gateway control register low
CAN_MSGFGCRH31 = 0x0318; // load FIFO/gateway control register high
CAN_MSGCTRH31 = 0x0000; // load message control register high
CAN_MSGCTRL31 = 0x5595; // load message control register low
/// -----------------------------------------------------------------------
/// Configuration of Service Request Nodes 0 - 7:
/// -----------------------------------------------------------------------
/// SRN0 service request node configuration:
/// - SRN0 interrupt priority level (ILVL) = 2
/// - SRN0 interrupt group level (GLVL) = 0
/// - SRN0 group priority extension (GPX) = 0
CAN_0IC = 0x0048;
/// -----------------------------------------------------------------------
/// Initialization of the FIFO Pointer:
/// -----------------------------------------------------------------------
for (i = 0; i < 16; i++)
{
aubFIFOWritePtr[i] = i * 2;
aubFIFOReadPtr[i] = i * 2;
}
// USER CODE BEGIN (Init,3)
// USER CODE END
CAN_PISEL = 0x000B; // load port input select register
// -----------------------------------------------------------------------
// Start the CAN Nodes:
// -----------------------------------------------------------------------
CAN_ACR &= ~(uword)0x0041; // reset INIT and CCE
CAN_BCR &= ~(uword)0x0041; // reset INIT and CCE
// USER CODE BEGIN (Init,4)
// USER CODE END
} // End of function CAN_vInit
//****************************************************************************
// @Function ubyte CAN_ubWriteFIFO(ubyte ubObjNr, TCAN_SWObj *pstObj)
//
//----------------------------------------------------------------------------
// @Description This function sets up the next free TRANSMIT message object
// which is part of a FIFO. This includes the 8 data bytes,
// the identifier (11- or 29-bit) and the data number (0-8
// bytes). The direction bit (DIR), the XTD-bit, the NODE bit
// and the RMM bit can not be changed. The acceptance mask
// register and the Frame C
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?