HWA
Bare metal programming with style
Definitions for HWA users.

Detailed Description

These definitions can be used in user application code. They may act on various types of arguments. Arguments are checked and explicit error messages are emitted.

Modules

 HWA Classes
 

Macros

#define hw(...)
 
#define HW_ADDRESS(...)
 
#define hw_asm(...)
 
#define HW_BITS(...)
 
#define HW_DECLARE(...)
 
#define HW_IMPLEMENT(...)   HW_F(HW_IMPLEMENT,__VA_ARGS__)
 
#define HW_POSITION(...)
 
#define hw_stat_t(object)
 
#define hw_uint_t(n)
 
#define hwa(...)
 

Macro Definition Documentation

◆ hw

#define hw (   ...)

hw( action, object [,...] ) executes an action immediately on an object.

  • An explicit error message is produced if the object does not exist or if it does not support the action.
  • Additional arguments may follow the name of the object.
hw( configure, (porta,0), direction, output );
hw( write, counter0, 0 );
Examples
hwa/st/stm32/examples/05-2-uart/main.c.

◆ HW_ADDRESS

#define HW_ADDRESS (   ...)

Returns the address of an object or -1 if the object does not exist.

For I/O objects, the address is computed from their definition.

#if HW_ADDRESS(counter0) == -1
# error counter0 does not exist
#endif

◆ hw_asm

#define hw_asm (   ...)

Insert inline assembler code.

hw_asm("reti"); // Insert the RETI instruction
Examples
hwa/atmel/avr/examples/04-1-fade-adc/main.c.

◆ HW_BITS

#define HW_BITS (   ...)

Number of bits of an object, 0 if the object has no bits or does not exist (no error is emitted).

#if HW_BITS(counter0) != 16
# error You must chose a 16-bit counter
#endif
Examples
hwa/atmel/avr/examples/10-1-acmp/main.c.

◆ HW_DECLARE

#define HW_DECLARE (   ...)

Declares the functions that implement an object.

External objects usually rely on functions to implement their HWA actions. These functions are declared by HW_DECLARE() and implemened by HW_IMPLEMENT().

#define PCF HW_PCF8574( interface, twi0, address, 0x27 )

An optionnal parameter 'weak' can be given so that the definitions can be overriden:

HW_DECLARE(PCF,weak);
Examples
hwa/atmel/avr/examples/99-03-HD44780-PCF8574/main.c.

◆ HW_IMPLEMENT

#define HW_IMPLEMENT (   ...)    HW_F(HW_IMPLEMENT,__VA_ARGS__)

Defines the functions that implement an object.

External objects usually rely on functions to implement their HWA actions. These functions are declared by HW_DECLARE() and defined by HW_IMPLEMENT().

#define PCF HW_PCF8574( interface, twi0, address, 0x27 )
Examples
hwa/atmel/avr/examples/99-03-HD44780-PCF8574/main.c.

◆ hw_stat_t

#define hw_stat_t (   object)

Declares the appropriate structure that holds the status of an object.

hw_stat_t(spi0) st = hw(stat,spi0);
if ( st.collision )
++n_collisions;

◆ hw_uint_t

#define hw_uint_t (   n)

Declares an unsigned integer.

This is useful when you need to store a value whose size depends on an object:

hw_uint_t(HW_BITS(counter0)) count = hw( read, counter0 );
Examples
hwa/atmel/avr/examples/03-5-fade-counter-compare-output/main.c.

◆ hwa

#define hwa (   ...)

hwa( action, object [,...] ) stores an action for an object into a HWA context.

  • An explicit error message is produced if the object does not exist or if it does not support the action.
  • Additional arguments may follow the name of the object.
  • The context must have been created, only once in the same translation unit, with hwa(begin) or hwa(begin, reset).
  • hwa(commit) triggers the production of the machine code.
  • hwa(nocommit) does not produce code but is useful to put the context in a known state.
// Configure PA0, PA2, PA4, PA5, PA6, PA7 as outputs
// accessing the DDRA register only once.
//
hwa( begin, reset );
hwa( configure, (porta,0), direction, output );
hwa( configure, ((porta,2)), direction, output ); // Dual parentheses is OK
hwa( configure, (port0,4,4), direction, output );
hwa( commit );
Examples
hwa/st/stm32/examples/05-2-uart/main.c.
HW_BITS
#define HW_BITS(...)
Definition: hwa_1.h:500
hwa
#define hwa(...)
hwa( action, object [,...] ) stores an action for an object into a HWA context.
Definition: hwa_macros.h:552
HW_DECLARE
#define HW_DECLARE(...)
Declares the functions that implement an object.
Definition: hwa_1.h:526
hw
#define hw(...)
hw( action, object [,...] ) executes an action immediately on an object.
Definition: hwa_macros.h:523
hw_asm
#define hw_asm(...)
Insert inline assembler code.
Definition: hwa_2.h:37
hw_uint_t
#define hw_uint_t(n)
Declares an unsigned integer.
Definition: hwa_macros.h:729
hw_stat_t
#define hw_stat_t(object)
Declares the appropriate structure that holds the status of an object.
Definition: hwa_macros.h:711
HW_IMPLEMENT
#define HW_IMPLEMENT(...)
Defines the functions that implement an object.
Definition: hwa_1.h:548