EPPL  0.1 alpha
 All Files Typedefs Groups Pages
<eppl> Embedded Port Pins Library main file

Modules

 <eppl_internals> EPPL library internals macros
 
 <eppl_target> Target wrapper
 

Macros

#define EPPL_NP   (-255L)
 Non-Pin value. More...
 
#define EPPL_PINCNT   ( EPPL_port_PORTSIZE * EPPL_port_PORTCNT )
 Maximum number of pins. More...
 
#define EPPL_DEFPP(port, pin)   ( (port)*EPPL_port_PORTSIZE + (pin) )
 Macro for port pin definition. More...
 
#define EPPL_PORTNR(px)   (((px) % EPPL_PINCNT) / EPPL_port_PORTSIZE)
 Get port number from pin identifier. More...
 
#define EPPL_PINNR(px)   ((px)%EPPL_port_PORTSIZE)
 Get pin number from pin identifier. More...
 
#define EPPL_SC(px, conf)   ( ((px) < 0) ? (px) : ( (px) + ( (conf) * EPPL_PINCNT ) ) )
 Set Configuration macro. More...
 
#define EPPL_GC(px)   ( ( (px) / EPPL_PINCNT) % (EPPL_port_CONFSIZE) )
 Get Configuration macro. More...
 
#define EPPL_SR(px, from, to)   ( ((px) < 0) ? (px) : ( ((from) << (EPPL_configBits)) | (to) ) * (EPPL_PINCNT) + (px))
 Set Reinit macro. More...
 
#define EPPL_GRfrom(px)   ( (((px) / EPPL_PINCNT) >> EPPL_configBits) % EPPL_avr8_CONFSIZE )
 Get Reinit from.
 
#define EPPL_GRto(px)   EPPL_GC(px)
 Get Reinit to.
 
#define EPPL_COUNTARGS(args...)   xEPPL_COUNTARGS(args, EPPL_COUNTARGS_RSEQ)
 Macro for counting number of parameters. More...
 
#define EPPL_ActivePinCountInSet(pins...)   EPPL_GETSUBSET(EPPL_checkPinDefined, 0, EPPL_extractOne, +, pins)
 Get active pins count in set given. More...
 
#define EPPL_PinCountInSet(pins...)   EPPL_COUNTARGS(pins)
 Get pins count in set given, including inactive ones. More...
 
#define EPPL_PROCESSEVERYPIN(macro, op, pins...)   EPPL_LC(EPPL_PROCESSEVERYPIN, EPPL_COUNTARGS(pins))(macro, op, pins)
 Macro for processing every single listed pin. More...
 
#define EPPL_PROCESSEVERYARG(macro, op, args...)   EPPL_PROCESSEVERYPIN(macro, op, args)
 Macro for processing every single argument. More...
 
#define EPPL_REPEATONEVERYPIN(macro, pins...)
 Macro for repeating code on listed pins. More...
 
#define EPPL_REPEATONEVERYARG(macro, args...)
 Macro for repeating code on listed arguments. More...
 
#define eppl_init(default, pinconfigs...)
 Macro for port initialization. More...
 
#define eppl_reinitFromISR(pinconfigs...)
 Macro that changes port configuration form interrupt procedure. More...
 
#define eppl_reinit(pinconfigs...)
 Macro that changes port configuration. More...
 
#define eppl_mapIn(pins...)   ( EPPL_REPEAT(EPPL_port_PORTCNT, EPPL_port_generateMapInFromOnePort, pins) (uint8_t)0 )
 Map in function. More...
 
#define eppl_mapOutFromISR(mode, value, pins...)   do{ EPPL_REPEAT(EPPL_port_PORTCNT, EPPL_port_generateMapOutToOnePort, mode, value, pins) }while(0)
 Value output mapping from ISR. More...
 
#define eppl_mapOut(mode, value, pins...)
 Value output mapping. More...
 

Typedefs

typedef signed long eppl_pin_t
 Definition of type that can store pin information. More...
 

Detailed Description

There you can find all functions and constants that should be used in your programs to access processor pins.

Macro Definition Documentation

#define EPPL_ActivePinCountInSet (   pins...)    EPPL_GETSUBSET(EPPL_checkPinDefined, 0, EPPL_extractOne, +, pins)

Get active pins count in set given.

This macro counts all defined pins. Undefined pin is set to EPPL_NP value.

Parameters
pinsPin list to count
Returns
Number of defined pins in given list
#define EPPL_COUNTARGS (   args...)    xEPPL_COUNTARGS(args, EPPL_COUNTARGS_RSEQ)

Macro for counting number of parameters.

Macro returns number of given parameters. Maximum number of processed parameters is 256. The best of all is it returns just one number. It does not return any value that has to be processed (I mean, for e.g. it returns 6 instead of something like: (1+2+3)). It means it could be used directly in macros like EPPL_REPEAT by connecting strings.

Macro is based on the post that could be found there: https://groups.google.com/forum/?fromgroups=#!topic/comp.std.c/d-6Mj5Lko_s

Parameters
[in]argsArguments to be counted, at least 1, at most 256
Returns
Single value that is number of given parameters.
#define EPPL_DEFPP (   port,
  pin 
)    ( (port)*EPPL_port_PORTSIZE + (pin) )

Macro for port pin definition.

Use this macro for for port pin mnemonic definition.

Usage:

#define BTN EPPL_DEFPP(3, 0)

Or use it rather with a target specific definitions from the eppl_internals file.

Parameters
[in]portPort number
[in]pinPin number in port
Returns
Complex pin identifier
#define EPPL_GC (   px)    ( ( (px) / EPPL_PINCNT) % (EPPL_port_CONFSIZE) )

Get Configuration macro.

Macro that extracts configuration information from connected Complex Pin Identifier and configuration.

See Also
EPPL_SC
#define eppl_init (   default,
  pinconfigs... 
)
Value:
do{\
EPPL_REPEAT(EPPL_port_PORTCNT, EPPL_generateInitOnePort, default, pinconfigs) \
}while(0)

Macro for port initialization.

Macro that initializes all pins in microcontroller. Put there all pin states that we require on microcontroller initialization. All pins can be given individually. The macro converts data to single value write to every register that requires initialization.

Parameters
[in]defaultDefault pin configuration. Use values directly (do not use EPPL_SC macro).
[in]pinconfigsPin configurations, separated by coma. Single pin configuration should be created using EPPL_SC macro.
Returns
Macro generates code, that writes values to port registers. Ports are initialized from index 0 to EPPL_port_PORTCNT - 1.

Usage example for AVR8 microcontroller:

#define BTN1 _PB(1)
#define BTN2 _PC(3)
#define LED1 _PA(4)
#define LED2 _PC(4)
int main(void)
{
);
...
}
#define eppl_mapIn (   pins...)    ( EPPL_REPEAT(EPPL_port_PORTCNT, EPPL_port_generateMapInFromOnePort, pins) (uint8_t)0 )

Map in function.

Map in function maps data from processor pins to output value. Pins are mapped from MSB do LSB:

#define BTN0 _PB(0)
#define BTN1 _PB(1)
#define BTN2 _PB(2)
#define BTN3 _PB(3)
#define BTN4 _PB(4)
#define BTN5 _PB(5)
#define BTN6 _PB(6)
#define BTN7 _PB(7)
PORTC = eppl_mapIn(BTN7, BTN6, BTN5, BTN4, BTN3, BTN2, BTN1, BTN0);

The code above would just simply copy data from PORTB to PORTC. An example generated code for the avr8 target:

in r24, 0x16
out 0x15, r24
Parameters
[in]pinsPins list to map in.
Returns
Macro returns mapped value
#define eppl_mapOut (   mode,
  value,
  pins... 
)
Value:
do{ \
eppl_port_LockableBlockBegin(!(EPPL_REPEAT(EPPL_port_PORTCNT, EPPL_generateMapOutSafeCheck, mode, pins) 1)); \
eppl_mapOutFromISR(mode, value, pins); \
eppl_port_LockableBlockEnd(!(EPPL_REPEAT(EPPL_port_PORTCNT, EPPL_generateMapOutSafeCheck, mode, pins) 1)); \
}while(0)

Value output mapping.

Macro that maps value from variable to output pins.

Parameters
modePin output mode. It is target dependent.
valueValue to map out.
pinsList of pins for map to. The LSB of value would be mapped to last listed pin.
Attention
Pins that you are using to map, have to be initialized or reinitialized to functionality, according to mode parameter. In another case, the result of the macro operation could be different than expected.
If you use constant value to map out, try to use eppl_reinit instead. eppl_mapOut is optimized for variables output mapping.
See Also
EPPL_HOTPINS
eppl_mapOutFromISR
eppl_reinit
#define eppl_mapOutFromISR (   mode,
  value,
  pins... 
)    do{ EPPL_REPEAT(EPPL_port_PORTCNT, EPPL_port_generateMapOutToOnePort, mode, value, pins) }while(0)

Value output mapping from ISR.

Macro differs from eppl_mapOut in the way that it does not check if there are going to be any Hot Pins changed. It does not lock interrupts.

See Also
eppl_mapOut
#define EPPL_NP   (-255L)

Non-Pin value.

Value that is used to mark non-pin in a Complex Pin Identifier value. It is used, for example, in EPPL_GETSUBSET where you have to put some value but you do not really want the macro to interpret it.

See Also
EPPL_GETSUBSET
#define EPPL_PINCNT   ( EPPL_port_PORTSIZE * EPPL_port_PORTCNT )

Maximum number of pins.

Maximum number of pins is just maximum number of ports multiplied by number of pins in port. It depends on porting files. It is rather maximum number of pins processed inside porting files than maximum number of real pins inside exact processor.

In correctly designed port files it is equal to maximum number of pins in target processor family.

#define EPPL_PinCountInSet (   pins...)    EPPL_COUNTARGS(pins)

Get pins count in set given, including inactive ones.

Macro counts all pins in given set. Litteraly it equals number of arguments given after replacing in in preprocesor. It means if you write:

#define SOME_PINS Pina, Pinb, Pinc
a = EPPL_PinCountInSet(SOME_PINS);

It would put in variable a value 3 no 1.

Parameters
pinsArgument list to count
Returns
Number of arguments after final unwinding.
#define EPPL_PINNR (   px)    ((px)%EPPL_port_PORTSIZE)

Get pin number from pin identifier.

Macro extracts the pin in port number from the complex pin identifier

Parameters
[in]pxComplex pin identifier
Returns
Pin number inside the port of given pin identifier
#define EPPL_PORTNR (   px)    (((px) % EPPL_PINCNT) / EPPL_port_PORTSIZE)

Get port number from pin identifier.

Macro extracts the port number from the complex pin identifier

Parameters
[in]pxComplex pin identifier
Returns
Port number where given pin belongs
#define EPPL_PROCESSEVERYARG (   macro,
  op,
  args... 
)    EPPL_PROCESSEVERYPIN(macro, op, args)

Macro for processing every single argument.

Functionally it is exacly the same as EPPL_PROCESSEVERYPIN. But it is defined with different name to make code cleaner.

Use this function if you are to process arguments that is not a pin list.

#define EPPL_PROCESSEVERYPIN (   macro,
  op,
  pins... 
)    EPPL_LC(EPPL_PROCESSEVERYPIN, EPPL_COUNTARGS(pins))(macro, op, pins)

Macro for processing every single listed pin.

Macro that processes every listed pin using macro. Processed values are put back to the list, separated by commas.

Example usage:

#define SET_PINS_PROCESSING(n, pin) (EPPL_SC(pin, _cHigh))
#define eppl_setPins(pins...) \
eppl_reinit(EPPL_PROCESSEVERYPIN(SET_PINS_PROCESSING, pins))

Macro differs from EPPL_REPEATONEVERYPIN becouse it puts commas between processed values.

Attention
There have to be at last one pin in the list
To see limitation of maximum number of pins processed, look at EPPL_COUNTARGS macro.
Parameters
macroMacro to be executed on every pin, it have to take 2 arguments: repeat count left and pin to process. Repeats left is pure number, so it can be used for macro names concat (operator ##).
opOperator to be used to connect listed pins. Use one of the fallowing:
  • def(op) - Defines operator given as an argument
  • com - Uses comma operator
  • none - Empty space
pinsPins list to process
Returns
Exacly the same number of pins that is given in parameter, every one processed by given macro separated by comas.
See Also
EPPL_REPEATONEVERYPIN
#define eppl_reinit (   pinconfigs...)
Value:
do{ \
eppl_port_LockableBlockBegin(!(EPPL_REPEAT(EPPL_port_PORTCNT, EPPL_generatePortSafeCheck, pinconfigs) 1)); \
eppl_reinitFromISR(pinconfigs); \
eppl_port_LockableBlockEnd(!(EPPL_REPEAT(EPPL_port_PORTCNT, EPPL_generatePortSafeCheck, pinconfigs) 1)); \
}while(0)

Macro that changes port configuration.

Use this macro for changing port configuration using constant values. By changing port configuration we mean also changing pin state.

These macro works similarly to eppl_init with one difference - there is no default value, because all values that are not listed in pin configuration are left unchanged.

Macro also checks if there is going to be any unsafe port operation. If this is going to be the case, the interrupts would be blocked.

Parameters
[in]pinconfigs
Returns
Macro generates instructions to reinitialize listed pins. Instructions would be optimized to minimize port registers accessing.
See Also
EPPL_HOTPINS
eppl_reinitFromISR
eppl_mapOut
#define eppl_reinitFromISR (   pinconfigs...)
Value:
do{\
EPPL_REPEAT(EPPL_port_PORTCNT, EPPL_generateReinitOnePort, pinconfigs) \
}while(0)

Macro that changes port configuration form interrupt procedure.

Macro differs from eppl_reinit in the way that it does not check it there are going to be any Hot Pins changed. It does not lock interrupts.

Parameters
[in]pinconfigsPin configurations
See Also
eppl_reinit
EPPL_SR
#define EPPL_REPEATONEVERYARG (   macro,
  args... 
)
Value:
do{\
EPPL_PROCESSEVERYARG(macro, none, args) \
}while(0)

Macro for repeating code on listed arguments.

Functionally it is exacly the same as EPPL_REPEATONEVERYPIN. But it is defined with different name to make code cleaner.

Use this function if you are to process arguments that is not a pin list.

#define EPPL_REPEATONEVERYPIN (   macro,
  pins... 
)
Value:
do{\
EPPL_PROCESSEVERYPIN(macro, none, pins) \
}while(0)

Macro for repeating code on listed pins.

Macro that repeats given macro execution on every pin on list. Example usage:

#define PWM_ALL_PINS PWM1, PWM2, PWM3
#define PWM_BELOW_STATE EPPL_mode_outPP_1
#define PWM_ABOVE_STATE EPPL_mode_outPP_0
#define PROCESS_PWMCNT_TO_OUTPUT(n, pin) \
if(pwm[n] > counter) \
EPPL_reinit(EPPL_SR(pin, PWM_BELOW_STATE, PWM_ABOVE_STATE); \
else
EPPL_reinit(EPPL_SR(pin, PWM_ABOVE_STATE, PWM_BELOW_STATE);
...
EPPL_REPEATONEVERYPIN(PROCESS_PWMCNT_TO_OUTPUT, PWM_ALL);
...

Macro differs from EPPL_PROCESSEVERYPIN becouse it does not put commas between processed values. Moreover REPEAT macro is taken inside do {} while(0) loop that makes it looks like one instruction from language tokens point of view. You can safetly use as a conditional or loop instruction.

Parameters
macroMacro to be processed, it have to take 2 arguments: repeat count left and pin to process. Repeats left is pure number, so it can be used for macro names concat (operator ##).
pinsPin list
#define EPPL_SC (   px,
  conf 
)    ( ((px) < 0) ? (px) : ( (px) + ( (conf) * EPPL_PINCNT ) ) )

Set Configuration macro.

Macro that returns a big constant number that keeps information about Complex Pin Identifier and its configuration.

#define EPPL_SR (   px,
  from,
  to 
)    ( ((px) < 0) ? (px) : ( ((from) << (EPPL_configBits)) | (to) ) * (EPPL_PINCNT) + (px))

Set Reinit macro.

Macro to set reinit configuration. Use it to create reinit pins list in the eppl_reinit macro. You can use EPPL_SC as well but then all registers in port need to be reinitialized. If you would give any clue to the macro what mode or state you expected to be before changing, procedure would limit registry access only to the needed ones.

Parameters
pxComplex pin identifier
fromConfiguration that you expect to be there now
toConfiguration that you expect to be after eppl_reinit macro.
Attention
You could use non-complete configuration as the from parameter. E.g. if you know that there is EPPL_mode_outPP mode but you do not know the current output state, you could write: EPPL_SR(LED0, EPPL_mode_outPP, EPPL_mode_outPP | EPPL_outSet_0).
Do not use non-complete configuration as a to parameter, because the run of eppl_reinit would give undefined output.

Typedef Documentation

typedef signed long eppl_pin_t

Definition of type that can store pin information.

This data type is used for functions built into library. t has to be big enough to store all information about pins (port number, pin number, configuration).