Peripheral Simulation
For NXP (founded by Philips) LPC2292 — CAN
Simulation support for this peripheral or feature is comprised of:
- Dialog boxes which display and allow you to change peripheral configuration.
- VTREGs (Virtual Target Registers) which support I/O with the peripheral.
These simulation capabilities are described below.
CAN Acceptance Filter Dialog
The Controller Area Network (CAN) Acceptance Filter dialog
displays the identifier lookup tables for CAN messages received by
all of the CAN controllers supported by this device.
Acceptance Filter Group
-
AFMR (Acceptance Filter Mode Register) contains the
following control bits:
-
AccOff is set to disable the Acceptance Filter
operation. It requires that AccBP is reset.
-
AccBP is set to accept all messages on enabled CAN
controllers. This bit must be set before modifying the Look Up
Tables (LUT).
-
eFCAN (Enable Full CAN) is set to allow the Acceptance
Filter to take care of receiving and storing messages for selected
IDs on selected buses. If reset, the software must read all
messages for all IDs and buses.
LUT Error Group
-
LUTerrAd (LUT Error Address Register) when LUTerr is
set, contains the address in AF Lookup Table RAM where the
Acceptance Filter found an error.
-
LUTerr (LUT Error) is set when the Acceptance Filter
finds an error in the content of the AF Lookup Table.
Table Addresses Group
-
SFF_sa (Standard Frame Start Address Register) contains
the address of the start of the individual Standard IDs in the AF
Lookup Table memory. If Full CAN mode is enabled (eFCAN is set),
this contains the size of the Standard ID table to search.
-
SFF_GRP_sa (Standard Frame Group Start Address Register)
contains the address of the start of the grouped Standard IDs in
the AF Lookup Table memory.
-
EFF_sa (Extended Frame Start Address Register) contains
the address of the start of the individual Extended IDs in the AF
Lookup Table memory.
-
EFF_GRP_sa (Extended Frame Group Start Addr Register)
contains the address of the start of the grouped Extended IDs in
the AF Lookup Table memory.
-
ENDofTable (End of AF Tables Register) contains the
address above the last active address in the last active AF table.
If Full CAN mode is enabled (eFCAN is set), this value marks the
start of the area of Acceptance Filter RAM, where the Acceptance
Filter will automatically receive messages for selected IDs on
selected CAN buses.
Acceptance Filter Tables Group
- Idx is the Look Up Table Index.
- Table is the Look Up Table.
- Adr is the address of the Look Up Table
-
# is the controller number. Entries which are not in
ascending order are marked in red.
-
Dis is set if this filter is disabled. When there is a
mismatch in the lower/upper group ID pair, the entry is marked in
red.
-
ID is the Identifier. Entries which are not in ascending
order or where the upper ID is lower than the lower ID in group IDs
are marked in red.
Automatically Stored Rx Messages in Full CAN Group
- Idx is the Look Up Table Index.
-
SEM (Semaphore) is set to 1 as a message is being
updated, and 3 when compete. Software must reset this to 0 after
reading the message.
- DLC (Data Length Code)
- see DLC above.
- RTR (Remote Transmit Request) see RTR above.
- ID is the Identifier.
-
Rx Data (Hex) is the received data in hexadecimal
format.
CAN Central Registers Dialog
The Controller Area Network (CAN) Central Registers dialog
displays the status registers for all of the CAN controllers
supported by this device.
TxStatus Group
-
CANTxSR (Central Transmit Status Register) contains the
transmit status for the each CAN controller:
-
TSn (Transmit Status n) is set while the specified CAN
controller is sending a message.
-
TBSn (Transmit Buffer Status n) is set when all 3
transmit buffers are available to the CPU.
-
TCSn (Transmit Complete Status n) is set when all
requested transmissions successfully complete.
RxStatus Group
-
CANRxSR (Central Receive Status Register) contains the
receive status for the each CAN controller:
-
RSn (Receive Status n) is set while the specified CAN
controller is receiving a message.
-
RBSn (Receive Buffer Status n) is set when a received
message is available to the CAN controller.
-
DOSn (Data Overrun Status n) is set when a message is
lost because the previous message was not read from the receive
buffer in time.
Miscellaneous Status Group
-
CANMSR (Miscellaneous Status Register) contains the
following status bits for each CAN controller:
-
ESn (Error Status n) is set when either of the Transmit
Error (TXERR) or Receive Error (TXERR) status counters has reached
the Error Warning Limit (CANEWL) register limit.
-
BSn (Bus Status n) is set when there is activity on the
bus for this CAN controller.
CAN Communication Dialog
The Controller Area Network (CAN) Communication Dialog displays
the CAN communication activity on the CAN bus. The message Number,
States, Channel #, Message Identifiers, Message Direction, Data
Length and Data content are displayed for each message. To clear the
message display, double-click anywhere in the message display
area.
CAN Controller n Dialog
The Controller Area Network (CAN) Controller n dialog
configures on-chip CAN Controller n. Each CAN controller
provides storage for up to 15 message objects which can be a maximum
of 8 bytes long.
Mode Group
-
CnMOD (Mode Register) controls the basic
operating mode of the CAN controller and contains the following
control bits:
-
RM (Reset Mode) is set to disable CAN operation and
allows register modification. If reset, this bit enables the CAN
controller and prevents modification of some registers.
-
TPM (Transmit Priority Mode) is set to transmit the 3
transmit buffers based on their Transmit Priority field definition.
If reset, it bases transmit priority on the CAN ID.
-
STM (Self Test Mode) is set to not require an
acknowledgment of a transmitted message. If set, each transmitted
message requires an acknowledgment.
-
LOM (Listen Only Mode) is set to suppress the
acknowledgment after CAN message reception. CAN message
transmission is suppressed also.
-
RPM (Reverse Polarity Mode) is set make the Rx pin
active high. Normally, Rx and Tx are active low.
-
TM (Test Mode) is set to clock the signal on the RX pin
to the Tx pin.
-
SM (Sleep Mode) is set to enter sleep mode when there
are no pending CAN interrupts and no activity on the CAN bus.
Command Group
-
CnCMR (Command Register) is a write-only register
than contains the following control bits:
-
TR (Transmission Request) is set to queue the current
message for transmission.
-
AT (Abort Transmission) is set to cancel a pending
transmission. If set with the TR bit, the transmission is attempted
only once.
-
RB8 (Release Receive Buffer) is set to release the
current frame status (CANRFS) and ID (CANRID) information and allow
new receive data to occupy the receive buffer.
-
CD0 (Clear Data Overrun) resets the Data Overrun status
(DOS) in the CAN status register (CANSR).
-
SRR (Self Reception Request) is set to queue the current
message for transmission, but does not disable the receiver. It
will receive the message if the Acceptance Filter recognizes the
message ID.
-
STBn (Select Transmit Buffer 1-3) selects buffer 1, 2 or
3 for transmission.
Interrupt Enable Group
-
CnIER (Interrupt Enable Register) controls which
CAN controller events result in an interrupt. CANIER contains the
following control bits:
-
RIE (Receiver Interrupt Enable) is set to trigger an
interrupt when a CAN message data is received..
-
DOIE (Data Overrun Interrupt Enable) is set to trigger
an interrupt when Data Overrun errors occur.
-
IDIE (ID Ready Interrupt Enable) is set to trigger an
interrupt when a CAN identifier is received.
-
TIEn (Transmit Interrupt Enable 1 - 3) is set to trigger
an interrupt when the TBSn in CANSR goes from 0 to 1, indicating
that Transmit buffer n is available.
-
EIE (Error Warning Interrupt Enable) is set to trigger
an interrupt when Error Status (ES) or Bus Status (BS) in the
Status register (CANSR) changes.
-
EPIE (Error Passive Interrupt Enable) is set to trigger
an interrupt when the CAN controller switches between Error Passive
(LOM enabled) and Error Active mode (LOM disabled).
-
ALIE (Arbitration Lost Interrupt Enable) is set to
trigger an interrupt when the CAN controller loses arbitration
while attempting to transmit.
-
BEIE (Bus Error Interrupt Enable) is set to trigger an
interrupt when the CAN controller detects an error on the CAN
bus.
-
WUIE (Wake-Up Interrupt Enable) is set to trigger an
interrupt when the CAN bus activity is detected while the CAN
controller is in Sleep mode.
Interrupt & Capture Status Group
-
CnICR (Interrupt and Capture Register) contains
the status of the following interrupt events:
-
RI (Receive Interrupt) is set when a received message is
available.
-
DOI (Data Overrun Interrupt) is set when a message is
lost because the preceding message wasn't read from the receive
buffer in time.
-
IDI (ID Ready Interrupt) is set when a CAN identifier is
received.
-
TIn (Transmit Interrupt 1 - 3) is set when Transmit
buffer n is available.
-
EI (Error Warning Interrupt) is set when Error Status
(ES) or Bus Status (BS) in the Status register (CANSR)
changes.
-
EPI (Error Passive Interrupt) is set when the CAN
controller switches between Error Passive (LOM enabled) and Error
Active mode (LOM disabled).
-
ALI (Arbitration Lost Interrupt) is set when arbitration
is lost during a transmit.
-
BEI (Bus Error Interrupt) is set when the CAN controller
detects an error on the CAN bus.
-
WUI (Wake-Up Interrupt) is set when there is CAN bus
activity while the controller is in Sleep mode.
-
ERRDIR (Error Direction) is set when the CAN controller
detects a bus error while receiving. It is reset if the bus error
happens while transmitting.
-
ERRBIT (Error Code Capture) contains the location of the
error with the frame after a bus error.
-
ERRC (Error Type) contains the type of bus error
detected (Bit error, Form error, Stuff error or Other error).
-
ALCBIT (Arbitration Lost Bit) contains the bit number
within the frame when arbitration was lost when trying to send a
message.
Global Status Group
-
CnGSR (Global Status Register) contains the
following CAN controller status bits:
-
RXERR (Rx Error Counter) contains the number of messages
received in error. Setting the RM bit in the Mode register (CANMOD)
allows clearing of this counter.
-
TXERR (Tx Error Counter) contains the number of messages
transmitted in error. Setting the RM bit in the Mode register
(CANMOD) allows clearing of this counter.
-
BS (Bus Status) is set when the Transmit Error Counter
(TXERR) reaches 255. Bus activity is not allowed when this bit is
set.
-
ES (Error Status) is set when the one or both of the
Receive or Transmit Error Counter (RXERR or TXERR) reaches the
Error Warning Limit. Bus activity is not allowed when this bit is
set.
-
RBS (Receive Buffer Status) is set when a received
message is available.
-
TBS (Transmit Buffer Status) is set when no transmit
message is pending in any of the 3 buffers.
-
DOS (Data Overrun Status) is set when a message is lost
because the preceding message wasn't read from the receive buffer
in time.
-
TCS (Transmit Complete Status) is set when there are no
requested transmissions pending.
-
RS (Receive Status) is set while a CAN controller is
receiving a message.
-
TS (Transmit Status) is set while a CAN controller is
sending a message.
Status Group
-
CnSR (Status Register) contains the following CAN
controller status bits:
- BS (Bus Status) See BS in the Global Status group.
-
ES (Error Status) See ES in the Global Status
group.
-
RBS (Receive Buffer Status) See RBS in the Global Status
group.
-
DOS (Data Overrun Status) See DOS in the Global Status
group.
-
RS (Receive Status) See RS in the Global Status
group.
-
TBSn (Transmit Buffer Status) is set when a new message
may be written to transmit buffer n.
-
TCSn (Transmit Complete Status) is set when transmission
of the previous message for buffer n completes.
-
TSn (Transmit Status) is set while the transmission is
active for buffer n.
Bus Timing Group
-
CnBTR (Bus Timing Register) controls timing on
the CAN bus based on the VLSI Peripheral Bus (VPB) clock. It
contains the following controls:
-
BRP (Baud Rate Prescaler) is the value (plus 1) divided
into the VPB clock to produce the CAN clock.
-
SAM (Sample Rate) is set to sample the bus 3 times. If
reset, the bus is sampled only once.
-
SJW (Synchronization Jump Width) is this number of CAN
clocks (1 - 4).
-
TSEG1 (Sync to Sample Delay) is the number of CAN clocks
(minus 1) delay from the nominal sync point to the sample
point.
-
TSEG2 (Sample to Sync Delay) is the number of CAN clocks
(minus 1) delay from the sample point to the next nominal sync
point.
Rx Frame Status Group
- CnRFS (Rx Frame Status Register)
-
ID Index contains the number of the Lookup Table entry
which matched the received message identifier.
-
DLC (Data Length Code) contains the length (DLC) field
of the current received message.
-
BP (Bypass) is set when the current message is received
in AF Bypass mode. If set, the ID Index field has no meaning.
-
FF (Frame Format) is set when the received message has a
29-bit ID. If reset, this message has an 11-bit ID.
-
RTR (Remote Transmission Request) from the received
message. If set, it indicates the number of data bytes to be sent
back to the sender using the same ID.
Rx ID & Data Group
-
CnRID (Rx Identifier Register) contains the
Identifier field of the current received message. This is either an
11-bit or 29-bit field depending on the state of the Frame Format
(FF) bit.
-
CANRDA (Rx Data Register A) contains bytes 1 - 4 of the
current received message.
-
CANRDB (Rx Data Register B) contains bytes 5 - 8 of the
current received message.
Txn Frame Information Group
-
CnTFI1 - CnTFI3 (Tx Frame Information
Registers) contain the following frame definition information for
the message to be transmitted:
-
PRIO (Priority) contains the priority value used for
message arbitration when the Transmit Priority Mode (TPM) bit is
set in CANMOD. Lower values have higher priority.
-
DLC (Data Length Code) contains the length (DLC) field
of the next message to transmit when RTR is reset. If RTR is set,
this is a request for a number of bytes to be returned.
-
FF (Frame Format) is set to transmit the next message
with a 29-bit ID. If reset, transmit this message with an 11-bit
ID.
-
RTR (Remote Transmission Request) is set to request a
number of data bytes be sent back to this ID.
Txn ID & Data Group
-
CnTID1 - CnTID3 (Tx Identifier Register 1
- 3) contains the Identifier field of the next message to transmit
for buffer n. This is either an 11-bit or 29-bit field depending on
the state of the Frame Format (FF) bit.
-
CANTDAn (Tx Data Register A 1 - 3) contains bytes 1 - 4
of the next message to transmit for buffer n.
-
CANTDBn (Tx Data Register B 1 - 3) contains bytes 5 - 8
of the next message to transmit for buffer n.
CANnBx VTREG
Data Type: unsigned char
The CANnBx VTREGs contains the eight bytes of the CAN message for
CAN controller n. CANnB0 is the first byte, CAN1B1 is the
second byte, and so on.
-
When the simulated MCU transmits a CAN message, these VTREGs
contain the message data bytes.
-
To simulate a received CAN message, these VTREGs must be
initialized with the message data bytes.
CANnID VTREG
Data Type: unsigned long
The CANnID VTREG specifies the ID of the CAN message for CAN
controller n. For example, CAN1ID is the ID of the CAN message
for CAN controller 1.
-
When the simulated MCU transmits a CAN message, this VTREG
contains the message ID.
-
To simulate a received CAN message, this VTREG must be
initialized with the message ID.
CANnIN VTREG
Data Type: unsigned int
The CANnIN VTREG specifies the type of CAN message that CAN
controller n will receive. The values 1-5 may be assigned to
this VTREG:
- 1: Message with 11-bit ID.
- 2: Message with 29-bit ID.
- 3: Message Request with 11-bit ID.
- 4: Message Request with 29-bit ID.
- 5: Bus Activity Start
For example:
CAN1IN=2; // Input a 29-bit ID message
The following debugger function shows how you can receive CAN
messages into your application.
func void CAN1_Send (unsigned char msgno) {
switch (msgno)
{
case 0:
CAN1B0=' '; CAN1B1=' '; CAN1B2='K'; CAN1B3='E';
CAN1B4='I'; CAN1B5='L'; CAN1B6=' '; CAN1B7=' ';
CAN1L=8;
break;
case 1:
CAN1B0='S'; CAN1B1='o'; CAN1B2='f'; CAN1B3='t';
CAN1B4='w'; CAN1B5='a'; CAN1B6='r'; CAN1B7='e';
CAN1L=8;
break;
default:
CAN1B0='H'; CAN1B1='e'; CAN1B2='l'; CAN1B3='l';
CAN1B4='o'; CAN1B5='!'; CAN1B6=' '; CAN1B7=' ';
CAN1L=6;
break;
}
CAN1ID = 456;
CAN1IN = 1;
}
CANnL VTREG
Data Type: unsigned char
The CANnL VTREG specifies the length of the CAN message in bytes
for CAN controller n.
-
When the simulated MCU transmits a CAN message, this VTREG
contains the number of bytes in the message.
-
To simulate a received CAN message, this VTREG must be
initialized with the number of bytes in the message.
CANnOUT VTREG
Data Type: unsigned int
The CANnOUT VTREG specifies the type of CAN message that was
transmitted by CAN controller n. This VTREG may have the
values 1-5:
- 1: Message with 11-bit ID was sent.
- 2: Message with 29-bit ID was sent.
- 3: Message Request with 11-bit ID was sent.
- 4: Message Request with 29-bit ID was sent.
- 5: Bus Activity Start.
The following debugger signal function shows how you can monitor
and report on CAN messages transmitted by your application.
signal void CAN1_Recv (void) {
while (1)
{
wwatch(CANOUT);
printf ("Received CAN Message\n");
printf ("CAN ID %4.4lX (%u): ", CAN1ID, (unsigned) CAN1L);
printf ("%2.2X %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X ",
(int)CAN1B0, (int)CAN1B1, (int)CAN1B2, (int)CAN1B3,
(int)CAN1B4, (int)CAN1B5, (int)CAN1B6, (int)CAN1B7);
printf ("\n");
}
}