Barda
Posts: 11
Joined: Mon Dec 15, 2014 12:25 pm

System Timer Interrupts

Mon Dec 15, 2014 12:39 pm

Hi!
I'm trying to program timer interrupts in order to show a message each time an interrupt takes place.
My main problem has to do with OS_Claim. I don't know if my Interrupt Handler will execute rather than the OS one or just after it.
Here's my code, it doesn't show the message, and interrupts are enabled:

.global _start
_start:
@ enable interrrupts
mrs r0, cpsr
bic r0, $0b1000000
msr cspr, r0

@ Enable OS_Claim for Interrupts
mov r0, #0x02
adr r1, handler
mov r2, #0

@ Enable Enable_IRQ_1
mov r1, #1
lsl r1, r1, #1
ldr r2, =0x2000B000
ldr r0, [r2, #0x210]
orr r0, r0, r1
str r0, [r2, #0x210]

@ Load value to Compare Register
ldr r2, =0x20003000
ldrd r0, r1, [r2,#4]
add r0, r0, #0xFF00000
str r0, [r2,#0x10]

@ Infinite Loop to check Timer's Behavior.
loop: b loop

MOV R8, #0
SWI 0x11

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
handler:
stmfd r13!, {r0-r3, r12, lr}

@ disable interrupts
mrs r0, cpsr
orr r0, r0, #80
msr cpsr, r0

adr r0, text
SWI 0x02

text: .asciz "Handler\n"
.align 2

@ Remove interrupt from Status Register
ldr r0, =0x20003000
ldr r1, [r0]
bic r1, r1, #0x2
str r1, [r0]

@ Re-Load Compare Register
ldr r2, =0x20003000
ldrd r0, r1, [r2,#4]
add r0, r0, #0xFF00000
str r0, [r2,#0x10]

@ enable interrupts
mrs r0, cpsr
bic r0, r0, #80
msr cspr, r0

ldmfd r13!, {r0-r3, r12, lr}
subs r15, r14, #4

kayel
Posts: 109
Joined: Sun May 13, 2012 4:45 am
Location: France

Re: System Timer Interrupts

Mon Dec 15, 2014 5:16 pm

Have a look at this.

Code: Select all

ON ERROR REPORT:PRINT " at line ";ERL:END
DIM code% 4096

SYS "OS_Memory",13,&20003000,&100 TO ,,,timer%

FOR pass%=0 TO 2 STEP 2
P%=code%
[OPT pass%

.gettimerreg
SWI "OS_EnterOS"
ldr r2,[r0,r1]
mov r0,r2
SWI "OS_LeaveOS"
mov r15,r14
]
NEXT pass%

c$="0"
PRINT "press 'q' to quit (if you see this, something's wrong)"
WHILE c$<>"q"

  FOR offs%=&0 TO &18 STEP 4
  A%=timer%:B%=offs%
  reg%=USR gettimerreg
  PRINT"Address ",~(timer%+offs%)," contains: ",~reg%
NEXT

  c$=INKEY$ 0
ENDWHILE

PRINT "Finished ok"
END
System Timer Compare 3 is the only one that's not whizzing round like a scalded cat . Try pouring your boiling water on that one.

Barda
Posts: 11
Joined: Mon Dec 15, 2014 12:25 pm

Re: System Timer Interrupts

Mon Dec 15, 2014 5:37 pm

hi kayel!
Thank you very much for your response.
I'll try to do the same with Compare Register 3.
Do you think my handler is correct or CPSR needs a especial treatment?

kayel
Posts: 109
Joined: Sun May 13, 2012 4:45 am
Location: France

Re: System Timer Interrupts

Tue Dec 16, 2014 6:21 pm

Hi Barda,

PRM1-page 66-OS_Claim:

"This call adds the routine whose address is given in R1 to the list of routines claiming the vector. This becomes the first routine to be used when the vector is called."

I think Risc OS does the cpsr stuff for you. (Not sure).

I'll have a go at doing what you're trying to do and post my code if I get lucky.

Bon courage!

kayel
Posts: 109
Joined: Sun May 13, 2012 4:45 am
Location: France

Re: System Timer Interrupts

Wed Dec 17, 2014 7:01 am

Hi again,

I've just noticed you set up the registers for OS_Claim but you don't call OS_Claim.

If you get it to work before I do, let me know.

Barda
Posts: 11
Joined: Mon Dec 15, 2014 12:25 pm

Re: System Timer Interrupts

Wed Dec 17, 2014 6:41 pm

hi kayel!
Thanks for your response.
In my real code in RISC OS I use SWI 0x1F, that was a misprint.
I've tried Compare 3 and I got the same result.
I'm still trying to find a solution, at the moment reading some extra documentation :? :?

Barda
Posts: 11
Joined: Mon Dec 15, 2014 12:25 pm

Re: System Timer Interrupts

Sun Dec 21, 2014 7:26 pm

Hi!
I'm Still working with the timer, but using hal this time.
In this case, the OS locks.

. global _start
_start:

.align 2
counter: .word 0

@ Enable interrupts
SWI 0×13

@ ClaimDeviceVector
mov r0, #5
adr r1, Timer
mov r2, #0
SWI 0×4B

@ IRQEnable
mov r0, #1
mov r8, #0
mov r9, #1
SWI 0×7A

@ TimerSetPeriod
mov r0, #0
mov r1, #0×01000000
mov r8, #0
mov r9, #16
SWI 0×7A

@ Infinite loop
loop:
b loop

mov r8, #0
SWI 0×11

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Timer:

STMFD r13!, {r0-r3, r12, r14}

@ TimerIRQClear
mov r0, #0
mov r8, #0
mov r9, #113
SWI 0×7A

@ IRQClear
mov r0, #1
mov r8, #0
mov r9, #3
SWI 0×7A

@ Counter+1
ldr r0, =counter
ldr r1, [r0]
add r1, r1, #1
str r1, [r0]

out:
LDMFD r13!, {r0-r3,r12,r14}
mov r15, r14

kayel
Posts: 109
Joined: Sun May 13, 2012 4:45 am
Location: France

Re: System Timer Interrupts

Mon Dec 22, 2014 4:58 pm

Back again,

I can't remember where I found this, I know I didn't write it. It says timer n°1 is device n°3. Where did your device n°5 come from?

I'm having the same problem as you (the pi hanging).

Code: Select all


OS_Hardware%=&7A
HAL_Timers%=12
HAL_TimerDevice%=13
HAL_TimerGranularity%=14
HAL_TimerMaxPeriod%=15
HAL_TimerSetPeriod%=16
HAL_TimerPeriod%=17
HAL_TimerReadCountdown%=18
HAL_CounterDelay%=22
SYS OS_Hardware%,,,,,,,,,0,HAL_Timers% TO timers%
PRINT timers%;" timers found"
FOR timer%=0 TO timers%-1
SYS OS_Hardware%,timer%,,,,,,,,0,HAL_TimerDevice% TO device%
SYS OS_Hardware%,timer%,,,,,,,,0,HAL_TimerGranularity% TO gran%
SYS OS_Hardware%,timer%,,,,,,,,0,HAL_TimerMaxPeriod% TO maxperiod%

REM SYS OS_Hardware%,1,100000,,,,,,,0,HAL_TimerSetPeriod%

PRINT "Timer ";timer%;" is device ";device%;" at ";gran%;" ticks/second, maximum period ";maxperiod%
SYS OS_Hardware%,timer%,,,,,,,,0,HAL_TimerPeriod% TO period%
PRINT "Current period is ";period%;" ticks or ";(period%/gran%)*1E6;" microseconds."
PRINT "Time now is:"
PRINT "Timer","TIME/cs"
FOR i%=0 TO 10
SYS OS_Hardware%,timer%,,,,,,,,0,HAL_TimerReadCountdown% TO time%
FOR j%=0 TO 10000:NEXT j%
PRINT time%,TIME
NEXT i%
NEXT timer%
PRINT "Delaying 1s"
t%=TIME
SYS OS_Hardware%,10E5,,,,,,,,0,HAL_CounterDelay%
t2%=TIME
PRINT "Done, took ";(t2%-t%)/100;"s (according to the OS using the same timer!)"
REM SYS OS_Hardware%,1,50,,,,,,,0,HAL_TimerSetPeriod%
SYS OS_Hardware%,,,,,,,,,1,1 TO add%,base%
PRINT ~add%:PRINT ~base%
SYS OS_Hardware%,3,,,,,,,,0,1 TO status%
PRINT status%

END


Barda
Posts: 11
Joined: Mon Dec 15, 2014 12:25 pm

Re: System Timer Interrupts

Mon Dec 22, 2014 8:07 pm

Hi!
Device number 5 is Timer 0, just for the OS_ClaimDeviceVector.
I've read that HAL Timer 0 is just for the OS, only HAL Timer 1 can be used: link
I'm trying HAL Timer 1, there must be a solution for this :x

kayel
Posts: 109
Joined: Sun May 13, 2012 4:45 am
Location: France

Re: System Timer Interrupts

Tue Dec 23, 2014 5:20 am

Hi,

The table you link to is only for pre-HAL machines. You have to use the HAL call to find the device number (Timer 1is device 3). I suppose that's the device number to use with OS_ClaimDeviceVector.

Barda
Posts: 11
Joined: Mon Dec 15, 2014 12:25 pm

Re: System Timer Interrupts

Tue Dec 23, 2014 2:06 pm

I've tried with OS_ClaimDeviceVector 3 and no result for the moment :oops:

Return to “RISCOS”