user traps

General discussions about working with the Astrobe IDE and programming ARM Cortex-M3, M4 and M7 microcontrollers.

user traps

Postby steve64 » Thu Sep 13, 2018 9:12 am

It's not clear if it is possible to assign a procedure to a user-defined trap number.
I tried to do something like:

PROCEDURE MyTrapper;
BEGIN
Out.String("MY TRAPPER"); Out.Ln
END MyTrapper;

...
Traps.ShowRegs(FALSE); (* simplified trap log *)
Traps.Assign(100, MyTrapper);
ASSERT(FALSE, 100);
...

but I just get the standard trap error log:

Trap @080045C4H in Test, Line: 218, Code: 100

my procedure seems not invoked at all
steve64
 
Posts: 36
Joined: Mon Jul 09, 2018 8:56 am
Location: Italy

Re: user traps

Postby cfbsoftware » Thu Sep 13, 2018 12:40 pm

ASSERT generates the ARM SVC instruction which is a software interrupt. The interrupt handler that is invoked is the one that is assigned to the address of the SVC interrupt handler (Traps.SVCVector). In a standard Astrobe installation the interrupt handler is the procedure Traps.SVCTrap. The assertion code is just displayed as a number in the error message.

You could use the assertion code to signify that the trap handler should do something different by modifying the source code of Traps.SVCTrap.

For example (* Warning: none of this has been compiled or tested *) in Traps you could declare an array of procedures:

Code: Select all
VAR
   userProcs: ARRAY 155 OF InterruptHandler;

and a procedure

Code: Select all
PROCEDURE AssignSVC*(code: INTEGER; p: InterruptHandler);
BEGIN
  IF code >= 100 THEN userProcs[code - 100] := p END
END AssignSVC;

and modify Traps.SVCTrap to call your function instead of executing the normal trap code:

Code: Select all
PROCEDURE SVCTrap;
 ...
  SYSTEM.GET(trapAddr - 4, instr);
  code := LSR(instr, 16) MOD 100H;
  (* modifications start here: *)
  procNo := code - 100;
  IF (procNo >= 0) & (userProcs[procNo] # NIL) THEN
      userProcs[procNo]
  ELSE ...

Don't forget to initialise the array in Traps.Init:

Code: Select all
 FOR i := 0 TO LEN(userProcs) - 1 DO userProcs[i] := NIL END;

Then in your own code you would write:

Code: Select all
Traps.AssignSVC(100, MyTrapper);

Thank you for prompting this idea. I like it and will consider implementing it in the standard Astrobe distribution ...
cfbsoftware
Site Admin
 
Posts: 355
Joined: Fri Dec 31, 2010 12:30 pm


Return to Astrobe for ARM Cortex-M3, M4 and M7

cron