dharanivel
Posts: 33
Joined: Sun Dec 16, 2018 4:36 am

how to use system timer in arm-asm

Tue Dec 25, 2018 6:08 am

how to use system timer in arm-asm in rpi zero. can anyone help me to know about this.

wh7qq
Posts: 1346
Joined: Thu Oct 09, 2014 2:50 am

Re: how to use system timer in arm-asm

Wed Dec 26, 2018 3:30 am

You might find "cron" to be easier/better supported.

dharanivel
Posts: 33
Joined: Sun Dec 16, 2018 4:36 am

Re: how to use system timer in arm-asm

Wed Dec 26, 2018 7:31 am

what is cron

wh7qq
Posts: 1346
Joined: Thu Oct 09, 2014 2:50 am

Re: how to use system timer in arm-asm

Wed Dec 26, 2018 4:41 pm

Really?
dharanivel wrote:what is cron
Really?

Code: Select all

man cron
Explains it much better than I can. Still, I did not notice the forum you posted in...perhaps your needs are more extreme,

LdB
Posts: 1317
Joined: Wed Dec 07, 2016 2:29 pm

Re: how to use system timer in arm-asm

Fri Dec 28, 2018 7:36 am

Assumes you are using linux :-)

In baremetal ignore that as there is no such thing as cron you have to pick setup the timer for irq or fiq vector.

boochow
Posts: 9
Joined: Thu Feb 08, 2018 2:42 pm
Contact: Website Twitter

Re: how to use system timer in arm-asm

Fri Dec 28, 2018 9:58 am

In the BCM2835 peripheral manual page 113, nothing is described concerning IRQ number for the system timer. According to the linux kernel code ( https://github.com/raspberrypi/linux/bl ... platform.h ), they are IRQ #0, #1, #2, and #3.

The code below works on RPi Zero and is written in C but probably you can easily translate it to ASM.

https://github.com/boochow/bare_matal_r ... timer-irq2

emilpopa
Posts: 2
Joined: Sat Jan 19, 2019 6:29 pm

Re: how to use system timer in arm-asm

Sat Jan 19, 2019 8:49 pm

The response in depending on your context.
There are 4 sys timers defined. For each of them you have the registers : CS, CLO, CHI, and c0--c3 attached to system timer 0-3.
Each timer is connected to an interrupt, for PI 2 interrupt 0-3.
You have to follow this steps :
- select a timer (ex T1)
- enable the selected timer in the CS register (01 correspond to timer 1)
-
- set the free run counter (CLO, CHI) 64 bit Low, High.(depends on your application)
- reset timer match (write 01 in the CS register)
-
- clear the pending interrupt (IRQ pending 1, bit 1)
- enable the interrupt 1 corresponding to SYS_TIMER_1

You are now ready to receive the interrupts :

- in the IRQ routine :
- check the interrupt pending bit for t1 (interrupt controller)
- if it is set :
- check register CS bit 1 for t1 interrupt
- if is set :
- do your action (so fast you can do, because the interrupts are disabled)
- set again the CLO, CHI counter
- clear pending interrupt for t1 (c1)
- clear the pending interrupt 1 (interrupt controller)
- restore saved registers
- exit IRQ mode and restore the original core mode.

If you need the more information or code example, let me know !

Emil

Return to “Bare metal, Assembly language”