I am trying to understand how 28377 CAN API works and I am getting confused. Here is a piece of the comment of CANIntStatus() function from can.c:
//! \b CAN_INT_STS_CAUSE returns the value of the controller interrupt register
//! and indicates the cause of the interrupt. It will be a value of
//! \b CAN_INT_INT0ID_STATUS if the cause is a status interrupt. In this case,
//! the status register should be read with the CANStatusGet() function.
//! Calling this function to read the status will also clear the status
//! interrupt. If the value of the interrupt register is in the range 1-32,
//! then this indicates the number of the highest priority message object that
//! has an interrupt pending. The message object interrupt can be cleared by
//! using the CANIntClear() function, or by reading the message using
//! CANMessageGet() in the case of a received message.
I looked inside the source code and try to correlate this explanation to the register definition
if(status = CANIntStatus(CANB_BASE, CAN_INT_STS_CAUSE)) {....}
When I looked in the source code I found this:
case CAN_INT_STS_CAUSE:
{
ui32Status = HWREG(ui32Base + CAN_O_INT); // CAN_O_INT = 0x10
break;
}
The function returns 32 bit value of CAN_INT registers at offset 0x10. Here is the explanation from register description
(21.16.2.5 CAN_INT Register (offset = 10h) [reset = 0h]):
|
Bit |
Description |
|
31-24 |
Reserved |
|
23-16 |
Interrupt Identifier 1: The number here indicates the source of theinterrupt. 0x00 No interrupt is pending. 0x01-0x20 Number of mailbox (mailbox) which caused the interrupt. 0x21-0xFF Unused. If several interrupts are pending, the CAN Interrupt Register will point to the pending interrupt with the highest priority. The CANn_INT1 interrupt line remains active until INT0ID reaches value 0 (the cause of the interrupt is reset) or until IE0 is cleared. A message interrupt is cleared by clearing the mailbox's IntPnd bit. Among the message interrupts, the mailbox's interrupt priority decreases with increasing message number. |
|
15-0 |
Interrupt Identifier (the number here indicates the source of the interrupt) 0x0000 No interrupt is pending 0x0001- Number of message object which caused the interrupt. 0x0080 0x0081- Unused 0x7FFF 0x8000 Error and Status Register value is not 0x07. 0x8001- Unused If several interrupts are pending, the CAN Interrupt Register will point to the pending 0xFFFF interrupt with the highest priority. The CAN0INT interrupt line remains active until Int0ID reaches value 0 (the cause of the interrupt is reset) or until IE0 is cleared. The Status Interrupt has the highest priority. Among the message interrupts, the message object's interrupt priority decreases with increasing message number. |
Q1: What is the meaning of value 0x0001 in bits 15-0? Does this supposed to be range of 0x0001 to 0x0020 ? If the answer is yes, how is it different than bits 23-16?
Q2: If the LEC field of CAN_ES is not 0x7, does it return 0x8000 or 0x7fff? Can not be both! The example code seems to suggest that if 0x8000 is returned there is an error. Is this true? Under what condition will 0x7FFF be returned?
Q3: Can I use bits 23-16 to get the number of message box that has new message (highlighted in green)?
Q4: What is significance of value 0x8001? What does it mean “Unused if several interrupts are pending”? Unused ??? Why it has to be mentioned in the description if it is unused?
Q4: What is “pending 0xFFFF interrupt”? Is “0xFFFF” a name of interrupt? It is very strange name.
This one is the worst explanation I ever seen in any register description of any manual I ever read in last 25 years ( I said it and I feel better now)! Could you answer each question from above please?
Slobodan Gataric