we have now several HAL drivers which access GPIO pins (for now in ARM builds, 
but I am sure the problem is more general)

due to the way hardware resources are accessed in RT threads, one cannot rely 
on kernel coordination between different HAL drivers accessing pins; in fact 
drivers might have to be disabled, or at least ignored, and so cannot assumed 
to provide access coordination in all cases

this leaves the question how different HAL drivers access GPIO pins such they 
dont trample on each others assumptions (that would be true for other resources 
as well, like PWM's, ADC's, SPI channels etc, but I start with GPIO for now)

a current case is Ian's hal_bb_gpio.c driver and Charles PRU stepgen - both 
wiggle GPIO pins but are currently ships in the night: uncoordinated pin 
access, and it's just a matter of time until the support problems will surface

--

here is a starting point to address the issue:

The idea is to have an allocator module (gpiomap) which does the following:
- view pins as an array of 0..some maximum (the latter defined by platform)
- pre-reserve the pins which are unavailable for HAL drivers (eg because they 
might serve some other vital function, like HDMI or mmc access)
- export RT methods to test, reserve and free pins at runtime - this would be 
used in rtapi_app_main/rtapi_app_exit of these drivers.

The usage scenario looks like so:

 halcmd loadrt gpiomap platform=<platform> [reserve=<list of extra reserved 
pins beyond platform reserved pins>]
 # example: reserve all GPIO pins unavailable in the BeagleBone Black; ontop of 
those,
 # block pins 42 and 45 from use by other HAL drivers:

 halcmd loadrt gpiomap platform=bbb reserve=42,45

This gpiomap module has no RT functionality proper, it just exports some 
methods for use by other components:

Using code (HAL drivers using GPIO pins) shall do this:
- a using module should include "gpiomap.h"
- the RT methods are:
retrieve number of pins described for the current platform: 
      int gpio_npins(void);

test pin availability (to test & allocate, pass reserve=1):
      int gpio_test_pin(int pinno, int reserve);
         this returns 0 on success and < 0 if the pin already was allocated

free a pin (usage example: rtapi_app_exit() of a HAL driver):
      int gpio_free_pin(int pinno);
         this returns 0 on success and < 0 if the pin was unallocated

An initial implementation of gpiomap, and an example using driver (gpiouse) is 
here:
   
http://git.mah.priv.at/gitweb?p=emc2-dev.git;a=shortlog;h=refs/heads/arm335x-hal-pru-module

----> what needs to be done by driver writers (Ian and Charles, plus the folks 
working on RPI's for a start):
    to agree on a numbering convention, and macros, to uniquely map a certain 
platform pin onto an integer 0..maxpins
    this should go into header file(s)

I'm happy to integrate but happily pass the buck on working out the convention

--

the code is here: 
http://git.mah.priv.at/gitweb?p=emc2-dev.git;a=shortlog;h=refs/heads/arm335x-hal-pru-module

(I have merged Ian's bb-hal-gpio branch into arm335x-hal-pru-module and added 
the gpiomap work there).

please integrate, and let me know what's missing/needs work

while I dont think a full replica of kernel resource management is desirable or 
warranted - I think the scope is 'goof detection' here - some other resource 
classes might be subsumed here too (eg PWM, ADC, SPI etc); extending this 
scheme to multiple categories beyond GPIO shouldnt be hard. However, describing 
cross-dependencies between categories (eg. using PWM X disables GPIO use of pin 
Y) might be hard, and out of scope.

- Michael




------------------------------------------------------------------------------
AlienVault Unified Security Management (USM) platform delivers complete
security visibility with the essential security capabilities. Easily and
efficiently configure, manage, and operate all of your security controls
from a single console and one unified framework. Download a free trial.
http://p.sf.net/sfu/alienvault_d2d
_______________________________________________
Emc-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/emc-developers

Reply via email to