Reg: Using Timers in IMX

cancel
Showing results for 
Search instead for 
Did you mean: 

Reg: Using Timers in IMX

1,489 Views
vishvapathi
Contributor V

Hi All,

I am new to IMX and Linux. I am interested in using Timers in my program. Kindly share some sample or pointers

Thanks in Advance

Labels (2)
0 Kudos
6 Replies

204 Views
AnsonHuang
NXP Employee
NXP Employee

Hi, Karnan

     You can look into our BSP to gpt timer's use, but first you need to list your requirement, what use case do you want for timer? Basically, there are two modes for our timers, one is reload mode, the other is compare mode:

     1. Reload: setting an counter value, everytime timer count to this value, it will generate an interrupt and auto reload this value and redo the counting;

     2. Compare: timer is running freely and after it goes up/down to the highest/lowest value, it will loop back, eveytime it run to the value match the compare value we set int the register, it will generate an interrupt;

0 Kudos

204 Views
vishvapathi
Contributor V

Hi Huang,

  Thanks for your response. I need to generate interrupts for multiple time durations such as 200ms, 1s, 5s,30s2min etc. Reload mode will suit for my requirement. I have already tried it in SIGALRM method and it works fine for now,

But i want to implement the same in Interrupt method. I doesnt want to load all my events to a single timer.

     I havent worked on interrupts in I.MX+Linux, Kindly give me some pointers.

0 Kudos

204 Views
AnsonHuang
NXP Employee
NXP Employee

I think either reload mode and compare mode are good enough for you. Take GPT for example, looking at the GPT register on i.MX6Q, it has three compare registers(GPT_OCRx), you can set them in what ever you want. For example, when running at compare mode, you need to set GPT in free run mode , see FRR bit in GPT_CR register, it will run from 0x0 to 0xffffffff then roll back to 0x0. And it will generate interrupts each time its counter equal to the compare registers in GPT_OCRx. Then you can re-set the compare value in these three registers to make the interrupt coming at 200mx, 1s, 5s, 30s etc...

We didn't have patch for such function you want, but timer's basic function is simple, you can just read GPT's register description based on what I said upper to make it work.

Thanks!

0 Kudos

204 Views
vishvapathi
Contributor V

Hi Huang,

     Thanks.

     But how do access these registers lik (GPT Interrupt Register (GPT_IR), GPT Status Register (GPT_SR)) etc with Linux as by OS.

     Sorry for the dumb question. I have already worked on controllers only. This is my first time with a Processor with OS.

0 Kudos

204 Views
AnsonHuang
NXP Employee
NXP Employee

I think you can refer to our module's code, and you also need to learn how to request an interrupt handle in linux OS. Please look into sample code first:

arch/arm/plat-mxc/time.c, access registers can use API, __raw_reald() and __raw_writel().

0 Kudos

204 Views
vishvapathi
Contributor V

Hi,

Thanks for your input. I will try to learn. Can you give some pointers abt Serial Interrupt also plz.

0 Kudos