Next dojo in starting jaguar development. I tried to figure out how to use a jerry timer. The exercise was to write a subroutine, getting a timer divider, a cancellation token, and an updateable counter. So it can be called from C:
typedef void(*TimerHandler)(uint32_t time, uint32_t *cancellationToken, volatile uint32_t *count);
Jerry should update the counter per interrupt until the host writes a value !=0 to the cancellationToken than Jerry has to stop.
The ISR (Timer0 [interrupt 2] - remember to start ISR at D_RAM + 32) should look like (compare v8.pdf)
dsp_int:
load (r28),r29 ;get dsp flags
bclr #3,r29 ;interrupt serviced
load (r31),r30 ;get return from stack
bset #11,r29 ;clear int source flag
addq #4,r31 ;update stack
addq #2,r30 ;update return address
; custom Code start
load (r27),r26
addq #1,r26
store r26,(r27)
; custom Code end
jump (r30) ;return from int
store r29,(r28) ;set dsp flags
The main loop in Jerry is very strait forward:
jwaitloop:
load (r9),r25
cmpq #0,r25 ; Test cancellation Token
jr eq,jwaitloop
nop
First of all I find out my ISR never was executed, because I am writing the JPIT1 divider from a running Jerry. This didn't work. Set JPIT1 before starting Jerry!
The second error was a little bit harder to detect. The program is running, but after a few seconds Jerry terminates himself by aborting the jwaitloop, but r25 was zero!
This error can only happens if the interrupts occurs between the cmpq and the jr in the mainloop and the ISR isn't restoring the flags correctly.
So I exchanged the last two line of the ISR and place a nop after the jump:
store r29,(r28) ;set dsp flags
jump (r30) ;return from int
nop
So my conclusion is. There is an error in the v8.pdf or the DSP. Under some circumstances the pipelined instruction after the jump isn't executed correctly, so the FLAGS restored wrong.
Attached is my Visual Studio 2013 solution (it can build by commandline, too), so you can test by yourself
- toarnold
JerryTimer.zip