Page 1 of 3

Interrupt support on PAL module

Posted: Fri Sep 09, 2011 3:37 pm
by Florian
Hi,

We use ChibiOS/RT (currently V. 1.4.1) for an academic research project. It runs on Atmel SAM7 devices to schedule our software.
Recently we wondered, if there is no interrupt support in the PAL module (neither in version 1.4.1 nor in the current one)?
Since we need interrupts (to trigger events for instance) I would really like to add such functionality to the PAL driver (and at least to the PAL LLD driver for the AT91SAM7X256). Are you interested in getting that code to integrate it in the system?
Are there any issues, I have to peculiarly take care on?
Thanks!

Regards,
Florian

Re: Interrupt support on PAL module

Posted: Fri Sep 09, 2011 5:35 pm
by Giovanni
Hi Florian,

Interrupt support is not in the PAL driver yet because this is a feature not always present and often implemented very differently on the various MCUs.
There are several options:
1) Implement it as a AT91SAM7 specific extension in the low level driver only. The low level driver would export AT91SAM7-specific functions. Probably this is the quickest path even if not particularly elegant.
2) Propose an extension to be implemented in the general PAL driver.
3) Propose a new driver model for external events, separated from the PAL driver. This driver would simply not be implemented on MCUs lacking the feature.
4) Other?

I am interested in hearing suggestions about this topic. Personally I would go for option 3.

About version 1.4.1, it is quite outdated, I recommend switching to the latest stable version.

Giovanni

Re: Interrupt support on PAL module

Posted: Sat Sep 10, 2011 12:47 pm
by Florian
Hi Giovanni,

First thanks for quick responding!
I just started by extending the PAL driver on both levels (high and low) yesterday. As you did for the standard PAL macros, I ask for each low-level macro if it is defined first (using #ifdef).
For a platform that does not provide interrupt functionality in the corresponding LLDs, that macros simply don't exist. So the high-level macros return something like ((void)(parameter), 0) to realize all side-effects in "parameter".

But you're right in the point that this could be confusing for someone not knowing if there are PAL interrupts on a certain platform or not. This way, it would be necessary that one must have a look into the LLD drivers and check if there are macros for IR support any time. I guess that is not such a nice solution so I think about rather realizing your 3rd option (introduce an extra driver PAL_IRQ or so).

Regards,
Florian

Re: Interrupt support on PAL module

Posted: Sat Sep 10, 2011 12:50 pm
by Florian
by the way: We are going to update on the newest version soon but first we have to fix some issues regarding our old customized drivers and integrate them into the OS's drivers properly.

Re: Interrupt support on PAL module

Posted: Sun Sep 11, 2011 12:25 pm
by barthess
STM32 has the EXTI cell for this purpose. It can acts as backend for Florian's hi level interface. I use my own low level EXTI driver in my project and can adopt it if need.

Re: Interrupt support on PAL module

Posted: Mon Sep 12, 2011 7:49 am
by Giovanni
OK then, we can add this in 2.3.x since 2.4.x is nowhere close to release.

I propose to call the driver "EXT" and it would work as follow:

- The PAL driver will be still responsible for the pin setup in "interrupt mode" where this apply (SAM7).
- The EXT driver is responsible for interrupt handling and callback dispatch.

If we are able to make it general enough for AT91, STM32 and LPC1xxx then it will be accepted. I will think to the general driver then barthess can integrate his EXTI implementation and Florian can do the SAM7 work if he wants.

Giovanni

Re: Interrupt support on PAL module

Posted: Mon Sep 12, 2011 8:58 am
by Florian
yes, that sounds good.

I don't know the STM's IRQ model, but for the sam7 I would recommend functions/macros like:
  • enableIrq
  • disableIrq
  • setIrqType [hi, lo, rising edge, falling edge]
  • setIrqPriority [same register as type on the sam7. So you also could combine both in one macro]

The first two should be realized for ports, groups and pads individually.

Important for the SAM7: The enable / disable of certain pads is done in the PIO controller, while the type and priority are set in the AIC (advanced interrupt controller) for a complete port. Hence for setting a pad on en-/disabled we need a pointer to the corresponding PIO base address. But for the priority and type we need the ID of the port instead.

Should we somehow ensure that the PIO functionality is enabled on a pad (and no peripheral) before using it for external interrupts?

Re: Interrupt support on PAL module

Posted: Mon Sep 12, 2011 9:30 am
by Giovanni
The driver would have the usual behavior of all the other drivers, you start() it with a configuration, everything you mentioned would be part of the configuration, AIC priorities would be compile-time configurable parameters like in other drivers. Of course you could have multiple configurations and be able to swap them at run time.

The challenge is not to just write a driver but write a driver that is consistent with the rest of the HAL *and* offer a generic enough interface to the applications.

Giovanni

Re: Interrupt support on PAL module

Posted: Mon Sep 12, 2011 9:53 am
by barthess
May be it will be helpful. In attach Alberto Bianchi driver that I use almost without changes.

Re: Interrupt support on PAL module

Posted: Mon Sep 12, 2011 2:26 pm
by Florian
That sounds good.
The functions I mentioned above were more aligned on the PAL driver than on the others.
I guess, its best if I wait for your ready high-level driver and implement the sam7 low-level driver afterwards.