Keil Logo

C166: IDENTIFY INSTRUCTION CAUSING CLASS B HARDWARE TRAP


Information in this article applies to:

  • C166 Version 4.20 or higher

QUESTION

My program generates a Class B Hardware Trap which indicates execution of:

  • Undefined Opcode
  • Protected Instruction Fault
  • Illegal Word Operand Access
  • Illegal Instruction Access
  • Illegal External Bus Access

How can I determine the reason of the Class B Hardware Trap and the CPU instruction that causes this problem?

ANSWER

You can add the TRAPS.C file to your application. This file contains a TRAP Handler for 166/167/XC16x hardware traps. The current version of this file contains a PRINT_TRAP define that you can enable.

This adds the following code to your program:

#include <intrins.h>
.
.
.
#pragma NOFRAME               // do not save registers for following interrupt

void Class_B_trap (void) interrupt 0x0A  {
  unsigned int ip, csp;

  ip  = _pop_ ();
  csp = _pop_ ();
  printf ("\nClass B Trap at PC=0x%02X%04X TFR=0x%04X\n", csp, ip, TFR);
  /* add your code here */
  while (1);                 /* end-less loop */
}

The printf statement outputs (via the serial interface) the PC address and the Trap Flag Register (TFR) value. You can load your application into the µVision Debugger and enter the Unassemble command in the Debugger Command Window. This typically displays the instruction (or the instruction after the instruction) that caused the Class B trap. The TFR value indicates the Class B Trap reason.

For C16x/ST10 based devices the following TFR values are defined:

  • TFR.0 = Illegal External Bus Access (no external BUS defined for address)
  • TFR.1 = Illegal Instruction Access (branch to odd address)
  • TFR.2 = Illegal Word Operand Access (word read/write on odd address)
  • TFR.3 = Protection Fault (protected instruction with illegal format)
  • TFR.7 = Undefined Opcode (invalid 166/167 op-code)
  • TFR.13 = Stack Underflow
  • TFR.14 = Stack Overflow
  • TFR.15 = Non Maskable Interrupt

For XC16x/Super10 based devices the following TFR values are defined:

  • TFR.2 = Illegal Word Operand Access (word read/write on odd address)
  • TFR.3 = Protection Fault (protected instruction with illegal format)
  • TFR.4 = Illegal or erroneous access to program memory interface
  • TFR.7 = Undefined Opcode (invalid 166/167 op-code)
  • TFR.12 = Software break event
  • TFR.13 = Stack Underflow
  • TFR.14 = Stack Overflow
  • TFR.15 = Non Maskable Interrupt

MORE INFORMATION

SEE ALSO

FORUM THREADS

The following Discussion Forum threads may provide information related to this topic.

Last Reviewed: Friday, July 22, 2005


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.