difference between SWI and TRAP

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

difference between SWI and TRAP

3,180 Views
LBdgWgt
Contributor I
Hello all,

I am working on a project about RTOS on HCS12 uC. I whave a doubt about what is the difference between SWI and TRAP, as far as I read, both are not affected by I bit in CCR, does someone know what is the difference between both (advantage and disadvantage). The RTOS need a simulated interrupt whent performing context switching.

thansk for any help,
Labels (1)
0 Kudos
2 Replies

570 Views
Steve
NXP Employee
NXP Employee
The instructions look similar but are intended for different uses. TRAP is in fact any unimplemented instruction in the S12(X) opcode map. So for S12 it is actually 202 opcodes and for S12XD it is 29 opcodes.
There are two disadvantages to using a TRAP instruction rather than SWI:
1/ The interrupt will be called by any of the unimplemented opcodes so any unintended software execution could cause a call to your RTOS kernel rather than being handled as an error.
2/ The TRAP availability is different on different CPUs (S12 vs S12X V1) and so code compatibility could be an issue for a flexible piece of code like an RTOS.
0 Kudos

570 Views
LBdgWgt
Contributor I
Thanks Steve for the very nice answer. I get it clearly now

regards,
0 Kudos