EmbeddedRelated.com
Forums

Acess ARM9 hardware timers ( C and Linux )

Started by JimNorton April 10, 2009
Hello everybody,

I'm new to embedded linux development. I want to write some routines that
need 1uS timer resolution. I understand that the ARM9 processors have 16
bit hardware timers.

How do one use these timers in linux from 'C'. Anybody have any example
code?

If I was writing is Assembly, as I do with PICS, it would probably be
easy.. but this is the first time working with ARM9 and Linux....

Any help or pointers are greatly appreciated...

-Jim


On Fri, 10 Apr 2009 16:12:29 -0500, "JimNorton"
<jimnorton@jimnorton.org> wrote in comp.arch.embedded:

> Hello everybody, > > I'm new to embedded linux development. I want to write some routines that > need 1uS timer resolution. I understand that the ARM9 processors have 16 > bit hardware timers.
You have a misunderstanding. There are no 16-bit hardware timers in the ARM9 core. If you are buying an off-the-shelf chip built on an ARM9 core, from Atmel, or Texas Instruments, or Freescale, or one of many, many others, then it has whatever peripherals the chip maker decided to put on the chip with the core. I suspect that most off-the-shelf ARM9 microcontrollers would have one or more hardware timers, at least 16 bits and perhaps more likely 32 bits.
> How do one use these timers in linux from 'C'. Anybody have any example > code?
You haven't said exactly what you want to use the timers for. Many ARM9 micros have on-chip peripherals to generate PWM waveforms, generate interrupts, and probably do quite a few other things with their on-chip timers.
> If I was writing is Assembly, as I do with PICS, it would probably be > easy.. but this is the first time working with ARM9 and Linux.... > > Any help or pointers are greatly appreciated...
The first thing you need to do is mention the specific ARM9 based micro you are using. And it would be a good idea to mention exactly what you want to use the timers for. -- Jack Klein Home: http://JK-Technology.Com FAQs for comp.lang.c http://c-faq.com/ comp.lang.c++ http://www.parashift.com/c++-faq-lite/ alt.comp.lang.learn.c-c++ http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Hi Jack,

My processor is a Samsung S3C2410A. Datasheet is here: 
http://www.datasheetcatalog.org/datasheet2/e/0lrp9fdj0zyd6e2k2e8ej8lkzupy.pdf

I just want to use a timer to time the reading and writing of some GPIO
pins to access some hardware that require uS timing...

I know there is the nanosleep() function in Linux, but I'm not sure how
accurate it is compared to accessing a timer by loading it with a value and
letting it under or overflow...

I am new to this embedded linux stuff... my experience is with accessing
the hardware directly in Assembly without the OS layer...

Any help would be appreciated...


>On Fri, 10 Apr 2009 16:12:29 -0500, "JimNorton" ><jimnorton@jimnorton.org> wrote in comp.arch.embedded: > >> Hello everybody, >> >> I'm new to embedded linux development. I want to write some routines
that
>> need 1uS timer resolution. I understand that the ARM9 processors have
16
>> bit hardware timers. > >You have a misunderstanding. There are no 16-bit hardware timers in >the ARM9 core. > >If you are buying an off-the-shelf chip built on an ARM9 core, from >Atmel, or Texas Instruments, or Freescale, or one of many, many >others, then it has whatever peripherals the chip maker decided to put >on the chip with the core. > >I suspect that most off-the-shelf ARM9 microcontrollers would have one >or more hardware timers, at least 16 bits and perhaps more likely 32 >bits. > >> How do one use these timers in linux from 'C'. Anybody have any
example
>> code? > >You haven't said exactly what you want to use the timers for. Many >ARM9 micros have on-chip peripherals to generate PWM waveforms, >generate interrupts, and probably do quite a few other things with >their on-chip timers. > >> If I was writing is Assembly, as I do with PICS, it would probably be >> easy.. but this is the first time working with ARM9 and Linux.... >> >> Any help or pointers are greatly appreciated... > >The first thing you need to do is mention the specific ARM9 based >micro you are using. And it would be a good idea to mention exactly >what you want to use the timers for. > >-- >Jack Klein >Home: http://JK-Technology.Com >FAQs for >comp.lang.c http://c-faq.com/ >comp.lang.c++ http://www.parashift.com/c++-faq-lite/ >alt.comp.lang.learn.c-c++ >http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html >
On Fri, 10 Apr 2009 22:00:21 -0500, JimNorton wrote:

> My processor is a Samsung S3C2410A. Datasheet is here: > http://www.datasheetcatalog.org/datasheet2/e/0lrp9fdj0zyd6e2k2e8ej8lkzupy.pdf
The kernel includes a clock framework: http://www.kernel.org/doc/htmldocs/kernel-api/ch17.html include/linux/clk.h The s3c24xx timers are accessible via this framework: arch/arm/plat-s3c24xx/pwm.c arch/arm/plat-s3c24xx/pwm-clock.c Much of the relevant code has Simtec's name on it: http://armlinux.simtec.co.uk/
> I just want to use a timer to time the reading and writing of some GPIO > pins to access some hardware that require uS timing... > > I know there is the nanosleep() function in Linux, but I'm not sure how > accurate it is compared to accessing a timer by loading it with a value and > letting it under or overflow...
nanosleep() is for use by applications. If you're accessing hardware, you probably want to write a device driver.
> I am new to this embedded linux stuff... my experience is with accessing > the hardware directly in Assembly without the OS layer...
You may have a fairly steep learning curve ahead. Programming ARM-Linux is likely to be 99% Linux, 1% ARM.
On 11 Apr, 05:00, "JimNorton" <jimnor...@jimnorton.org> wrote:
> Hi Jack, > > My processor is a Samsung S3C2410A. Datasheet is here:http://www.datasheetcatalog.org/datasheet2/e/0lrp9fdj0zyd6e2k2e8ej8lk... > > I just want to use a timer to time the reading and writing of some GPIO > pins to access some hardware that require uS timing... >
Getting uS timing for a Linux application on ARM9 will be tricky. Linux is not a real-time OS, so it will be difficult for you to ensure that your I/O-pin-manipulating process is scheduled during the correct uS. What if an interrupt handler takes over the CPU just when you wish to toggle the I/O line? Even ignoring Linux, the CPU can give you a few surprises - a cache miss at the wrong moment might be enough to mess your timing up. Since you know PICs and assembly programming, the easiest solution might be to add a little 8-bitter that handles the timing-critical I/ O, connected to the ARM9 via a serial link (uart, I2C, SPI). Or can the ARM9's timers be used to generate the desired waveform, without SW intervention?
Thank you for the great answers here....


>On Fri, 10 Apr 2009 22:00:21 -0500, JimNorton wrote: > >> My processor is a Samsung S3C2410A. Datasheet is here: >>
http://www.datasheetcatalog.org/datasheet2/e/0lrp9fdj0zyd6e2k2e8ej8lkzupy.pdf
> >The kernel includes a clock framework: > > http://www.kernel.org/doc/htmldocs/kernel-api/ch17.html > include/linux/clk.h > >The s3c24xx timers are accessible via this framework: > > arch/arm/plat-s3c24xx/pwm.c > arch/arm/plat-s3c24xx/pwm-clock.c > >Much of the relevant code has Simtec's name on it: > > http://armlinux.simtec.co.uk/ > >> I just want to use a timer to time the reading and writing of some
GPIO
>> pins to access some hardware that require uS timing... >> >> I know there is the nanosleep() function in Linux, but I'm not sure
how
>> accurate it is compared to accessing a timer by loading it with a value
and
>> letting it under or overflow... > >nanosleep() is for use by applications. If you're accessing hardware,
you
>probably want to write a device driver. > >> I am new to this embedded linux stuff... my experience is with
accessing
>> the hardware directly in Assembly without the OS layer... > >You may have a fairly steep learning curve ahead. Programming ARM-Linux
is
>likely to be 99% Linux, 1% ARM. > >
Hey that isn't a bad idea... Add a small PIC to do the fast bit banging
that is required.. controlled by the ARM via a serial port...

I'll have to think on that one... :-)


>On 11 Apr, 05:00, "JimNorton" <jimnor...@jimnorton.org> wrote: >> Hi Jack, >> >> My processor is a Samsung S3C2410A. Datasheet is
here:http://www.datasheetcatalog.org/datasheet2/e/0lrp9fdj0zyd6e2k2e8ej8lk...
>> >> I just want to use a timer to time the reading and writing of some
GPIO
>> pins to access some hardware that require uS timing... >> > >Getting uS timing for a Linux application on ARM9 will be tricky. >Linux is not a real-time OS, so it will be difficult for you to ensure >that your I/O-pin-manipulating process is scheduled during the correct >uS. What if an interrupt handler takes over the CPU just when you wish >to toggle the I/O line? Even ignoring Linux, the CPU can give you a >few surprises - a cache miss at the wrong moment might be enough to >mess your timing up. > >Since you know PICs and assembly programming, the easiest solution >might be to add a little 8-bitter that handles the timing-critical I/ >O, connected to the ARM9 via a serial link (uart, I2C, SPI). Or can >the ARM9's timers be used to generate the desired waveform, without SW >intervention? >