[En-Nut-Discussion] RFA_2: Nut/OS GPIO API

Uwe Bonnes bon at elektron.ikp.physik.tu-darmstadt.de
Tue Oct 16 22:54:26 CEST 2012


For the reader's ease: I mark all line from the original test to be removed
with '---' and my own replacement with '+++' 

The following rules apply to the Gpio API.
1 The main purpose of the Gpio API is to offer a common interface for
target-independent bit-banged drivers, typically located in nut/dev.
+++ Implementation can be as functions or macros

2 The Gpio API may be used by portable application samples, typically
located in nut/app.

3 The Gpio API may be used by target-specific drivers, typically located
--- in nut/app.
+++ in nut/arch
3.1 If the driver requires special function, which are not available in
the Gpio API, then this has to be implemented somewhere else. It is not
--- acceptable to extend the Gpio API in a target-specific way
+++ acceptable to extend the Gpio API in a target-specific way beside using more
+++ flags in the function to set up the pin/port.

4 The parameter bank specifies the GPIO group of bits (aka. port) and
must be specified by index of type int. This fixed type allows callers
to handle them in a common way during runtime.
4.1 The bank index base is target dependent.
4.2 Bank indexes may not be consecutively numbered.
4.3 If the implementation requires a different type, this may be done by
typecasting the integer index type.

5 The parameter bit specifies the bit within a bank and must be
specified by an index of type int.
5.1 The bit index base is 0.
5.2 Bit indexes are consecutively numbered.

+++ 6 For port-wide operations, the parameter mask specifies the sum
+++  of the bitvalues (_BV()) from the bit indexes involved.

7 Functions, which set GPIO output values, are of type void.
7.1 The only way to determine the validity of a bank or related bit is
by configuring it.

--- 6 Functions, which query pin input values, must return a value of type
----int.
+++ 6 The functionallity to query a pin or port is often implemented as macros
+++ and returns a value of the same type as a port register access. If
+++ implemented as function it must return a value of type int
 
8.1 A value of 0 is returned, if the pin state is low. Any other value
indicates a high state.
8.1 If the requested bank or bit is not available on the target, the
function result is undefined.
+++ 8.2. With NUTDEBUG defined, is is usefull if a possible much slower
+++ codepath is taken that checks for parameter validity.

--- 7 Functions, which query pin group (aka port) values, must return a
--- value of type unsigned int.
--- 7.1 This is bad for 8-bitters, but done to preserve compatibility with
--- the existing API.

9 The Gpio API will guarantee the following pin configuration
capabilities for all supported targets:
9.1 GPIO_CFG_INPUT to switch the pin to input mode
9.2 GPIO_CFG_OUTPUT to switch the pin to output mode
+++ 9.3 GPIO_CFG_INIT_HIGH|LOW to switch on the pin in the requested state
+++ when configured as output
--- 8.3 If the requested capability is not available for the specified
--- pin/port, the API function must return -1 to indicate an error.
--- Otherwise 0 is returned.

10 The Gpio API may provide the following pin configuration capabilities:
10.1 GPIO_CFG_PULLUP to enable the internal pull-up
10.2 GPIO_CFG_MULTIDRIVE to enable open drain mode of an output,
otherwise push-pull is assumed
--- 9.3 If the requested capability is not available for the specified
--- pin/port, the API function must return -1 to indicate an error.
--- Otherwise 0 is returned.
+++ 10.3. The return values is the flags of the requested capabilities with the not
+++   implemented capabilities masked to 0

11 The Gpio API may offer to register an interrupt handler for a
specific bit and to enable and disable this interrupt.
11.1 After registration, interrupts are disabled.
11.2 It is expected, that interrupts are triggered on any pin change.
Level triggering or triggering on specific edges is not supported.
11.3 If the requested interrupt is not available on that target or for
the specified pin/port, the API functions must return -1 to indicate an
error. Otherwise 0 is returned.

13 In order to use this API, dev/gpio.h needs be included only.
Depending on the target, this header may include others.
13.1 The prototypes of all public API functions are:

 extern uint32_t GpioPinConfigGet(int bank, int bit);
 extern int GpioPinConfigSet(int bank, int bit, uint32_t flags);
 extern int GpioPortConfigSet(int bank, unsigned int mask, uint32_t flags);

 extern int GpioPinGet(int bank, int bit);
 extern void GpioPinSet(int bank, int bit, int value);
 extern void GpioPinSetLow(int bank, int bit);
 extern void GpioPinSetHigh(int bank, int bit);
+++ extern void GpioPinDrive(int bank, int bit);
+++ extern void GpioPinRelease(int bank, int bit);
+++ void GpioPinToggle(int bank, int bit);

 extern unsigned int GpioPortGet(int bank);
--- extern void GpioPortSet(int bank, unsigned int value);
+++ extern void GpioPortSet(int bank, unsigned int mask, unsigned int value);
 extern void GpioPortSetLow(int bank, unsigned int mask);
 extern void GpioPortSetHigh(int bank, unsigned int mask);
+++  extern void GpioPortDrive(int bank, unsigned int mask);
+++  extern void GpioPortRelease(int bank, unsigned int mask);

 extern int GpioRegisterIrqHandler(GPIO_SIGNAL * sig, int bit, void
(*handler) (void *), void *arg);
 extern int GpioIrqEnable(GPIO_SIGNAL * sig, int bit);
 extern int GpioIrqDisable(GPIO_SIGNAL * sig, int bit);

+++ 13.2. If not provided in the platform code, dev/gpio.h provides
+++   GpioPinDrive(), GpioPinRelease(), GpioPortDrive() and Gpio PortRelease()
+++   as empty macros. Platform code can have its own implementation to
+++   allow fast switching between push/pull and tristate without
+++   calling Gpio{Pin|Port}ConfigSet() 

+++ 13.2. If not provided in the platform code, dev/gpio.h provides
+++  void GpioPinToggle(int bank, int bit);
+++  as a inlined combination of GpioPinGet() and GpioPinSet().

14 Currently there are several features, mainly pin configurations, used
by code in the trunk, which is temporarily accepted.
14.1 These additional feature can be removed from the API only, if the
same patch (revision) includes alternatives for those parts using these
features. In no way it is acceptable to break any existing code in the
trunk, just to please this RFA.


Thanks,

--- Harald
+++ Uwe
_______________________________________________
http://lists.egnite.de/mailman/listinfo/en-nut-discussion

-- 
Uwe Bonnes                bon at elektron.ikp.physik.tu-darmstadt.de

Institut fuer Kernphysik  Schlossgartenstrasse 9  64289 Darmstadt
--------- Tel. 06151 162516 -------- Fax. 06151 164321 ----------



More information about the En-Nut-Discussion mailing list