Linux EPIT timer interrupt handler

Hello,

For a project I’m using the Aplis iMX6Q embedded platform. I have my basic stuff already running like GPIO and SPI. But now I want to add and Timer interrupt.

For this interrupt I’m going to use the EPIT1 timer (according to my research it should be free to use, otherwise EPIT2 would be fine). After a specific time, that I write to the registers, it should generate a interrupt. I have already read into this EPIT timer and I’m sure I can manage to get it working. However the interrupt handler is a problem. I have tried to find an answer but it didn’t suit my expectation.

I’m very familiar with interrupts and handlers, only for a microprocessor. In this case I just enable the bit that causes the interrupt. When the interrupt is fired, it goes directly to an general ISR in which the correct source is allocated or just directly to the correct function. This is actually what I’m looking for to use in the Linux environment.

Can someone help me in the general good direction. An example would be appreciated.

Kind regards,
Remco

Hi

Does this answer help any?
So to setup a SoC subsystem like EPIT you will have to write and instantiate a kernel driver. That driver will then have to also provide the driver specific ISR code which will be called by the kernels generic ISR code.

Maybe, if you are searching for time relating stuff in your user space program the linux operating system already provides an API which does what you need without needing another kernel driver.

The time manpage gives an overview on time related API functionality. E.g. nanosleep allows to make your process wait a while,

Additonally most blocking calls to the kernel have a timeout parameter.

Max

Hi Max,

Thank you for your answer. After reading your post it was confirmed for me that if I want to use the EPIT timer (because of certain advantages of it) I need to write an kernel driver for it. Sounds like a new challenge for me to figure this out when it is allowed :).

The other functions that I read of in the time manpage is not exactly what I wished for. But the following could be a option for some here.

signal(SIGALRM, alarmWakeup);
ualarm(5000, 5000);

Personally it would not be my favorite because I like my interrupts hard ;), like hardware interrupts.But thanks you anyway for you answer, I know where I can go now.

Kind regards,
Remco

If by hard you mean something like hard real-time interrupts you won’t ever be able to achieve this like that as the OS is always in charge of all interrupts and you may incur whatever latency this may cause. This could of course be improved by using the RT patch as e.g. explained here with the latest version thereof being available here. Please note that using a separate timer like the EPIT will really not help you any in achieving any better real-time properties at all.

That is already familiar to me. And I’m not trying to get better real-time properties in the OS. I want to use the EPIT timer because it can generate an interrupt and set a GPIO at a regular interval in free-run-mode without using any cpu usage. This results in a sort three stage rocket for me:

  1. Generate interrupt and set GPIO - is in an instant;
  2. Kernel handle the interrupt at his time, and set a signal - whenever the ISR is called;
  3. Normal routine does what ever it need to do when it is scheduled - whenever the normal task is scheduled.

This results in a regular time update in hardware that is connected to it. The normal routine sets the output when it has the chance. It’s also a great feedback if the timer is too fast because the signal will still be asserted. In that case the EPIT timer needs to work slower.