解决过日无法休眠问题,适用于7-8号车

This commit is contained in:
2025-08-05 07:05:51 +08:00
parent 517a5f9ebb
commit 93baee9527
18 changed files with 2178 additions and 1697 deletions

312
CAN.C
View File

@@ -12,7 +12,7 @@
// @Description: This file contains functions that use the CAN module.
//
//----------------------------------------------------------------------------
// @Date 2024/8/22 08:23:16
// @Date 2025/1/18 20:45:35
//
//****************************************************************************
@@ -113,7 +113,7 @@
// @Parameters None
//
//----------------------------------------------------------------------------
// @Date 2024/8/22
// @Date 2025/1/18
//
//****************************************************************************
@@ -150,11 +150,14 @@ void CAN_vInit(void)
/// General Configuration of the Node 0:
/// - set INIT and CCE
/// - enable interrupt generation upon a change of BOFF or EWARN or upon a
/// set of LLE, LOE or INIT
/// - alert interrupt node pointer: MultiCAN SRN 0
//-----------CAN_NCR0 = 0x00000041-------------------------------------
//-----------CAN_NCR0 = 0x00000049-------------------------------------
CAN_vWriteCANAddress(CAN_NCR0); // Addressing CAN_NCR0
CAN_DATA0 = 0x41; // load NODE 0 control register[7-0]
CAN_DATA0 = 0x49; // load NODE 0 control register[7-0]
CAN_vWriteEN(D0_VALID+ADR_INC); // Data0 is Valid for transmission and
// Write is EnabledCAN Address pointing
// to the CAN_NSR0.
@@ -195,14 +198,14 @@ void CAN_vInit(void)
/// - required baud rate = 250.000 kbaud
/// - real baud rate = 250.000 kbaud
/// - sample point = 75.00 %
/// - there are 5 time quanta before sample point
/// - there are 2 time quanta after sample point
/// - there are 11 time quanta before sample point
/// - there are 4 time quanta after sample point
/// - the (re)synchronization jump width is 2 time quanta
//-----------CAN_NBTR0 = 0x00001457-------------------------------------
//-----------CAN_NBTR0 = 0x00003A4B-------------------------------------
CAN_DATA0 = 0x57; // load NBTR0_SJW, BRP
CAN_DATA1 = 0x14; // load NBTR0_DIV8, TSEG2, TSEG1
CAN_DATA0 = 0x4B; // load NBTR0_SJW, BRP
CAN_DATA1 = 0x3A; // load NBTR0_DIV8, TSEG2, TSEG1
CAN_vWriteEN(D0_VALID+D1_VALID+ADR_INC); // Data0, 1 are valid for
// transmission and Write is
// Enabled with Auto
@@ -277,7 +280,10 @@ void CAN_vInit(void)
CAN_vSetListCommand(0x01070002); // MO7 for list 1
CAN_vSetListCommand(0x01090002); // MO9 for list 1
CAN_vSetListCommand(0x010A0002); // MO10 for list 1
CAN_vSetListCommand(0x010B0002); // MO11 for list 1
CAN_vSetListCommand(0x010C0002); // MO12 for list 1
CAN_vSetListCommand(0x010D0002); // MO13 for list 1
/// -----------------------------------------------------------------------
/// Configuration of the CAN Message Objects 0 - 31:
/// -----------------------------------------------------------------------
@@ -396,12 +402,12 @@ void CAN_vInit(void)
/// - priority class 3; transmit acceptance filtering is based on the list
/// order (like class 1)
/// - standard 11-bit identifier
/// - identifier 11-bit: 0x711
/// - extended 29-bit identifier
/// - identifier 29-bit: 0x15000001
//--------------MOAR6 = 0xDC440000---------------------------------------
//--------------MOAR6 = 0xF5000001---------------------------------------
CAN_vWriteAMData(0xDC440000); // load MO6 arbitration register
CAN_vWriteAMData(0xF5000001); // load MO6 arbitration register
// CAN Address pointing to the CAN_MODATAH6
CAN_ADCON = ADR_DEC; // Auto Decrement the current address(-1)
@@ -422,7 +428,7 @@ void CAN_vInit(void)
CAN_ADCON = ADR_DEC; // Auto Decrement the current address(-1)
/// - only accept receive frames with matching IDE bit
/// - acceptance mask 11-bit: 0x7FF
/// - acceptance mask 29-bit: 0x1FFFFFFF
//--------------CAN_MOAMR6 = 0x3FFFFFFF------------------------------------
@@ -473,12 +479,12 @@ void CAN_vInit(void)
/// - priority class 3; transmit acceptance filtering is based on the list
/// order (like class 1)
/// - standard 11-bit identifier
/// - identifier 11-bit: 0x712
/// - extended 29-bit identifier
/// - identifier 29-bit: 0x15000002
//--------------MOAR7 = 0xDC480000---------------------------------------
//--------------MOAR7 = 0xF5000002---------------------------------------
CAN_vWriteAMData(0xDC480000); // load MO7 arbitration register
CAN_vWriteAMData(0xF5000002); // load MO7 arbitration register
// CAN Address pointing to the CAN_MODATAH7
CAN_ADCON = ADR_DEC; // Auto Decrement the current address(-1)
@@ -499,7 +505,7 @@ void CAN_vInit(void)
CAN_ADCON = ADR_DEC; // Auto Decrement the current address(-1)
/// - only accept receive frames with matching IDE bit
/// - acceptance mask 11-bit: 0x7FF
/// - acceptance mask 29-bit: 0x1FFFFFFF
//--------------CAN_MOAMR7 = 0x3FFFFFFF------------------------------------
@@ -536,26 +542,26 @@ void CAN_vInit(void)
/// Configuration of Message Object 8:
/// -----------------------------------------------------------------------
/// - message object 8 is valid
/// - message object is used as receive object
/// - message object is used as transmit object
/// - this message object is assigned to list 1 (node 0)
//--------------MOCTR8 = 0x00A00000---------------------------------------
//--------------MOCTR8 = 0x0EA80000---------------------------------------
CAN_vWriteCANAddress(CAN_MOCTR8); // Addressing MO8 control register
CAN_vWriteAMData(0x00A00000); // load MO8 control register
CAN_vWriteAMData(0x0EA80000); // load MO8 control register
// CAN Address pointing to the CAN_MOAR8
CAN_ADCON = ADR_DEC; // Auto Decrement the current address(-1)
/// - priority class 3; transmit acceptance filtering is based on the list
/// order (like class 1)
/// - standard 11-bit identifier
/// - identifier 11-bit: 0x713
/// - extended 29-bit identifier
/// - identifier 29-bit: 0x11000002
//--------------MOAR8 = 0xDC4C0000---------------------------------------
//--------------MOAR8 = 0xF1000002---------------------------------------
CAN_vWriteAMData(0xDC4C0000); // load MO8 arbitration register
CAN_vWriteAMData(0xF1000002); // load MO8 arbitration register
// CAN Address pointing to the CAN_MODATAH8
CAN_ADCON = ADR_DEC; // Auto Decrement the current address(-1)
@@ -576,7 +582,7 @@ void CAN_vInit(void)
CAN_ADCON = ADR_DEC; // Auto Decrement the current address(-1)
/// - only accept receive frames with matching IDE bit
/// - acceptance mask 11-bit: 0x7FF
/// - acceptance mask 29-bit: 0x1FFFFFFF
//--------------CAN_MOAMR8 = 0x3FFFFFFF------------------------------------
@@ -705,11 +711,11 @@ void CAN_vInit(void)
/// - priority class 3; transmit acceptance filtering is based on the list
/// order (like class 1)
/// - extended 29-bit identifier
/// - identifier 29-bit: 0x11000000
/// - identifier 29-bit: 0x14000002
//--------------MOAR10 = 0xF1000000---------------------------------------
//--------------MOAR10 = 0xF4000002---------------------------------------
CAN_vWriteAMData(0xF1000000); // load MO10 arbitration register
CAN_vWriteAMData(0xF4000002); // load MO10 arbitration register
// CAN Address pointing to the CAN_MODATAH10
CAN_ADCON = ADR_DEC; // Auto Decrement the current address(-1)
@@ -763,18 +769,238 @@ void CAN_vInit(void)
CAN_vWriteAMData(0x08000000); // load MO10 function control register
/// -----------------------------------------------------------------------
/// -----------------------------------------------------------------------
/// Configuration of Message Object 11:
/// -----------------------------------------------------------------------
/// - message object 11 is not valid
/// - message object 11 is valid
/// - message object is used as receive object
/// - this message object is assigned to list 1 (node 0)
//--------------MOCTR11 = 0x00A00000---------------------------------------
CAN_vWriteCANAddress(CAN_MOCTR11); // Addressing MO11 control register
CAN_vWriteAMData(0x00A00000); // load MO11 control register
// CAN Address pointing to the CAN_MOAR11
CAN_ADCON = ADR_DEC; // Auto Decrement the current address(-1)
/// - priority class 3; transmit acceptance filtering is based on the list
/// order (like class 1)
/// - extended 29-bit identifier
/// - identifier 29-bit: 0x15000004
//--------------MOAR11 = 0xF5000004---------------------------------------
CAN_vWriteAMData(0xF5000004); // load MO11 arbitration register
// CAN Address pointing to the CAN_MODATAH11
CAN_ADCON = ADR_DEC; // Auto Decrement the current address(-1)
//--------------MODATAH11 = 0x00000000---------------------------------------
CAN_vWriteAMData(0x00000000); // load MO11 data register high
// CAN Address pointing to the CAN_MODATAL11
CAN_ADCON = ADR_DEC; // Auto Decrement the current address(-1)
//--------------MODATAL11 = 0x00000000---------------------------------------
CAN_vWriteAMData(0x00000000); // load MO11 data register low
// CAN Address pointing to the CAN_MOAMR11
CAN_ADCON = ADR_DEC; // Auto Decrement the current address(-1)
/// - only accept receive frames with matching IDE bit
/// - acceptance mask 29-bit: 0x1FFFFFFF
//--------------CAN_MOAMR11 = 0x3FFFFFFF------------------------------------
CAN_vWriteAMData(0x3FFFFFFF); // load MO11 acceptance mask register
// CAN Address pointing to the CAN_MOIPR11
CAN_ADCON = ADR_DEC; // Auto Decrement the current address(-1)
/// - use message pending register 0 bit position 11
//--------------MOIPR11 = 0x00000B00---------------------------------------
CAN_vWriteAMData(0x00000B00); // load MO11 interrupt pointer register
// CAN Address pointing to the CAN_MOFGPR11
CAN_ADCON = ADR_DEC; // Auto Decrement the current address(-1)
//--------------MOFGPR11 = 0x00000000---------------------------------------
CAN_vWriteAMData(0x00000000); // load MO11 FIFO/gateway pointer register
// CAN Address pointing to the CAN_MOFCR11
CAN_ADCON = ADR_DEC; // Auto Decrement the current address(-1)
/// - this object is a STANDARD MESSAGE OBJECT
/// - 8 valid data bytes
//--------------MOFCR11 = 0x08000000---------------------------------------
CAN_vWriteAMData(0x08000000); // load MO11 function control register
/// -----------------------------------------------------------------------
/// Configuration of Message Object 12:
/// -----------------------------------------------------------------------
/// - message object 12 is not valid
/// - message object 12 is valid
/// - message object is used as transmit object
/// - this message object is assigned to list 1 (node 0)
//--------------MOCTR12 = 0x0EA80000---------------------------------------
CAN_vWriteCANAddress(CAN_MOCTR12); // Addressing MO12 control register
CAN_vWriteAMData(0x0EA80000); // load MO12 control register
// CAN Address pointing to the CAN_MOAR12
CAN_ADCON = ADR_DEC; // Auto Decrement the current address(-1)
/// - priority class 3; transmit acceptance filtering is based on the list
/// order (like class 1)
/// - extended 29-bit identifier
/// - identifier 29-bit: 0x15000003
//--------------MOAR12 = 0xF5000003---------------------------------------
CAN_vWriteAMData(0xF5000003); // load MO12 arbitration register
// CAN Address pointing to the CAN_MODATAH12
CAN_ADCON = ADR_DEC; // Auto Decrement the current address(-1)
//--------------MODATAH12 = 0x00000000---------------------------------------
CAN_vWriteAMData(0x00000000); // load MO12 data register high
// CAN Address pointing to the CAN_MODATAL12
CAN_ADCON = ADR_DEC; // Auto Decrement the current address(-1)
//--------------MODATAL12 = 0x00000000---------------------------------------
CAN_vWriteAMData(0x00000000); // load MO12 data register low
// CAN Address pointing to the CAN_MOAMR12
CAN_ADCON = ADR_DEC; // Auto Decrement the current address(-1)
/// - only accept receive frames with matching IDE bit
/// - acceptance mask 29-bit: 0x1FFFFFFF
//--------------CAN_MOAMR12 = 0x3FFFFFFF------------------------------------
CAN_vWriteAMData(0x3FFFFFFF); // load MO12 acceptance mask register
// CAN Address pointing to the CAN_MOIPR12
CAN_ADCON = ADR_DEC; // Auto Decrement the current address(-1)
/// - use message pending register 0 bit position 12
//--------------MOIPR12 = 0x00000C00---------------------------------------
CAN_vWriteAMData(0x00000C00); // load MO12 interrupt pointer register
// CAN Address pointing to the CAN_MOFGPR12
CAN_ADCON = ADR_DEC; // Auto Decrement the current address(-1)
//--------------MOFGPR12 = 0x00000000---------------------------------------
CAN_vWriteAMData(0x00000000); // load MO12 FIFO/gateway pointer register
// CAN Address pointing to the CAN_MOFCR12
CAN_ADCON = ADR_DEC; // Auto Decrement the current address(-1)
/// - this object is a STANDARD MESSAGE OBJECT
/// - 8 valid data bytes
//--------------MOFCR12 = 0x08000000---------------------------------------
CAN_vWriteAMData(0x08000000); // load MO12 function control register
/// -----------------------------------------------------------------------
/// Configuration of Message Object 13:
/// -----------------------------------------------------------------------
/// - message object 13 is not valid
/// - message object 13 is valid
/// - message object is used as receive object
/// - this message object is assigned to list 1 (node 0)
//--------------MOCTR13 = 0x00A00000---------------------------------------
CAN_vWriteCANAddress(CAN_MOCTR13); // Addressing MO13 control register
CAN_vWriteAMData(0x00A00000); // load MO13 control register
// CAN Address pointing to the CAN_MOAR13
CAN_ADCON = ADR_DEC; // Auto Decrement the current address(-1)
/// - priority class 3; transmit acceptance filtering is based on the list
/// order (like class 1)
/// - extended 29-bit identifier
/// - identifier 29-bit: 0x14000001
//--------------MOAR13 = 0xF4000001---------------------------------------
CAN_vWriteAMData(0xF4000001); // load MO13 arbitration register
// CAN Address pointing to the CAN_MODATAH13
CAN_ADCON = ADR_DEC; // Auto Decrement the current address(-1)
//--------------MODATAH13 = 0x00000000---------------------------------------
CAN_vWriteAMData(0x00000000); // load MO13 data register high
// CAN Address pointing to the CAN_MODATAL13
CAN_ADCON = ADR_DEC; // Auto Decrement the current address(-1)
//--------------MODATAL13 = 0x00000000---------------------------------------
CAN_vWriteAMData(0x00000000); // load MO13 data register low
// CAN Address pointing to the CAN_MOAMR13
CAN_ADCON = ADR_DEC; // Auto Decrement the current address(-1)
/// - accept reception of standard and extended frames
/// - acceptance mask 29-bit: 0x1FFFFFFF
/// - acceptance mask 11-bit: 0x7FF
//--------------CAN_MOAMR13 = 0x1FFFFFFF------------------------------------
CAN_vWriteAMData(0x1FFFFFFF); // load MO13 acceptance mask register
// CAN Address pointing to the CAN_MOIPR13
CAN_ADCON = ADR_DEC; // Auto Decrement the current address(-1)
/// - use message pending register 0 bit position 13
//--------------MOIPR13 = 0x00000D00---------------------------------------
CAN_vWriteAMData(0x00000D00); // load MO13 interrupt pointer register
// CAN Address pointing to the CAN_MOFGPR13
CAN_ADCON = ADR_DEC; // Auto Decrement the current address(-1)
//--------------MOFGPR13 = 0x00000000---------------------------------------
CAN_vWriteAMData(0x00000000); // load MO13 FIFO/gateway pointer register
// CAN Address pointing to the CAN_MOFCR13
CAN_ADCON = ADR_DEC; // Auto Decrement the current address(-1)
/// - this object is a STANDARD MESSAGE OBJECT
/// - 8 valid data bytes
//--------------MOFCR13 = 0x08000000---------------------------------------
CAN_vWriteAMData(0x08000000); // load MO13 function control register
/// -----------------------------------------------------------------------
/// Configuration of Message Object 14:
/// -----------------------------------------------------------------------
@@ -910,7 +1136,7 @@ void CAN_vInit(void)
// 32-bit Data
//
//----------------------------------------------------------------------------
// @Date 2024/8/22
// @Date 2025/1/18
//
//****************************************************************************
@@ -945,7 +1171,7 @@ void CAN_vWriteAMData(ulong ulValue)
// 32-bit Data
//
//----------------------------------------------------------------------------
// @Date 2024/8/22
// @Date 2025/1/18
//
//****************************************************************************
@@ -983,7 +1209,7 @@ void CAN_vSetListCommand(ulong ulVal)
// Pointer on a message object to be filled by this function
//
//----------------------------------------------------------------------------
// @Date 2024/8/22
// @Date 2025/1/18
//
//****************************************************************************
@@ -1140,7 +1366,7 @@ ubyte ubTemp;
// Number of the message object (0-31)
//
//----------------------------------------------------------------------------
// @Date 2024/8/22
// @Date 2025/1/18
//
//****************************************************************************
@@ -1183,7 +1409,7 @@ return(ubReturn);
// Number of the message object (0-31)
//
//----------------------------------------------------------------------------
// @Date 2024/8/22
// @Date 2025/1/18
//
//****************************************************************************
@@ -1227,7 +1453,7 @@ return(ubReturn);
// Number of the message object (0-31)
//
//----------------------------------------------------------------------------
// @Date 2024/8/22
// @Date 2025/1/18
//
//****************************************************************************
@@ -1267,7 +1493,7 @@ void CAN_vTransmit(ubyte ubObjNr)
// Pointer on a data buffer
//
//----------------------------------------------------------------------------
// @Date 2024/8/22
// @Date 2025/1/18
//
//****************************************************************************
@@ -1331,7 +1557,7 @@ void CAN_vLoadData(ubyte ubObjNr, ulong *ulpubData)
// Number of the message object (0-31)
//
//----------------------------------------------------------------------------
// @Date 2024/8/22
// @Date 2025/1/18
//
//****************************************************************************