EPPL  0.1 alpha
 All Files Typedefs Groups Pages
eppl_config_template.h File Reference

Embedded Port Pins Library - configuration file. More...

Go to the source code of this file.

Macros

#define EPPL_TARGET   avr8
 Target platform. More...
 
#define EPPL_HOTPINS   EPPL_NP
 Hot Pins. More...
 

Detailed Description

Embedded Port Pins Library - configuration file.

):

#define EPPL_HOTPINS \
BUZZER, \
HOUR_D1, \
HOUR_D2, \
HOUR_D4, \
HOUR_D8, \
MIN_D5, \
MIN_D10, \
MIN_D20, \
MIN_D40

If you look at our generated code now, you will see, that the line that maps temperature value to output pins, is protected by calling cli instruction. After operation is finished the interrupt state is set back to the state before instruction execution.

The blocking code is not needed inside the interrupt. You can use instructions with FromISR postfix (eppl_mapOutFromISR) in interrupt to prevent generating the interrupt blocking code. The other option is to set the EPPL_HOTPINS value to EPPL_NP (Not A Pin) before the interrupt runtime. For more details go to Hot Pins concept in multi-threaded applications section.

Optimize interrupts blocking even more by giving more specific information to the library

When you just specify the pins list in EPPL_HOTPINS definition the library will protect any access to any register that belongs to unsafe port. In many programs it is not needed. It is quite common that procedure inside the interrupt modifies just one register and only that register needs to be protected. You can give to the library more information to optimize the code better.

You may do so by using EPPL_SR macro. This macro is normally used for pins reinitialization, inside the eppl_reinit macro. Using it you can specify what kind of pins value changing we can expect.

In our example binary clock, all pins inside interrupt are work in Push-Pull mode and only its state is changed. It means that for the AVR microcontroller only the PORT registers have to be protected. We can modify any DDR register without fear.

For our example you could use more specific Hot Pins definition like below:

#define EPPL_HOTPINS \
EPPL_SR(BUZZER, EPPL_mode_outPP_0, EPPL_mode_outPP_1) \
EPPL_SR(HOUR_D1, EPPL_mode_outPP_0, EPPL_mode_outPP_1) \
EPPL_SR(HOUR_D2, EPPL_mode_outPP_0, EPPL_mode_outPP_1) \
EPPL_SR(HOUR_D4, EPPL_mode_outPP_0, EPPL_mode_outPP_1) \
EPPL_SR(HOUR_D8, EPPL_mode_outPP_0, EPPL_mode_outPP_1) \
EPPL_SR(MIN_D5, EPPL_mode_outPP_0, EPPL_mode_outPP_1) \
EPPL_SR(MIN_D10, EPPL_mode_outPP_0, EPPL_mode_outPP_1) \
EPPL_SR(MIN_D20, EPPL_mode_outPP_0, EPPL_mode_outPP_1) \
EPPL_SR(MIN_D40, EPPL_mode_outPP_0, EPPL_mode_outPP_1)

Notice that in the EPPL_HOTPINS definition when you list possible ways of pins states changes, the direction of the changes is not important, so the code below:

#define EPPL_HOTPINS \
EPPL_SR(BUZZER, EPPL_mode_outPP_0, EPPL_mode_outPP_1)

Is equivalent to the following code:

#define EPPL_HOTPINS \
EPPL_SR(BUZZER, EPPL_mode_outPP_1, EPPL_mode_outPP_0)

You can list one pin more than once in EPPL_HOTPINS definition. It gives you the possibility to inform the library that some pin is for example expected to change state in interrupt but also... for example change the direction:

#define EPPL_HOTPINS \
EPPL_SR(BUZZER, EPPL_mode_outPP_0, EPPL_mode_outPP_1),
EPPL_SR(BUZZER, EPPL_mode_outPP, EPPL_mode_inHz)

Hot Pins concept in multi-threaded applications

It may look as if the presented Hot Pins concept is usable only in systems where we have two threads:

  1. Main loop
  2. Interrupts

And moreover: Interrupts may always break main loop. Main loop may never break interrupts.

But the presented idea is much more flexible. In the example above we have set EPPL_HOTPINS constant in eppl_config.h file. But the EPPL_HOTPINS value is not set globally for the library. The macros are written that way that the value of EPPL_HOTPINS is checked at the point of any macro usage. It means that you can define different values for Hot Pins constant for different files. You can also undefine and then define completely different value at any point of the file.

Look at the example code below:

#define PINS_MODIFIED_IN_THREAD1 \
EPPL_SR(BUZZER, EPPL_mode_outPP_0, EPPL_mode_outPP_1)
#define PINS_MODIFIED_IN_THREAD2 \
EPPL_SR(HOUR_D1, EPPL_mode_outPP_0, EPPL_mode_outPP_1), \
EPPL_SR(HOUR_D2, EPPL_mode_outPP_0, EPPL_mode_outPP_1), \
EPPL_SR(HOUR_D4, EPPL_mode_outPP_0, EPPL_mode_outPP_1), \
EPPL_SR(HOUR_D8, EPPL_mode_outPP_0, EPPL_mode_outPP_1)
#define PINS_MODIFIED_IN_THREAD3 \
EPPL_SR(TEMP_DS, EPPL_mode_outPP_0, EPPL_mode_outPP_1)
#undef EPPL_HOTPINS
#define EPPL_HOTPINS PINS_MODIFIED_IN_THREAD2, PINS_MODIFIED_IN_THREAD3
void thread1(void)
{
...
}
#undef EPPL_HOTPINS
#define EPPL_HOTPINS PINS_MODIFIED_IN_THREAD1, PINS_MODIFIED_IN_THREAD3
void thread2(void)
{
...
}
#undef EPPL_HOTPINS
#define EPPL_HOTPINS PINS_MODIFIED_IN_THREAD1, PINS_MODIFIED_IN_THREAD2
void thread3(void)
{
...
}
#undef EPPL_HOTPINS
#define EPPL_HOTPINS EPPL_NP
int main(void)
{
...
}
Author
Radoslaw Koppel <r.koppel@k-el.com>
Date
2013 Use these file as settings template or use it directly.
See Also
<eppl_config> Configuration settings
Attention
Put settings in eppl_config.h file. Some settings changes how macros are defined, so it has to be included inside, at the very beginning of the EPPL macro files.