Skip to content
/ hwa Public

Header-only library for bare metal hardware programming in C with a pleasant generic style.

License

Notifications You must be signed in to change notification settings

duparq/hwa

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HWA: HardWare Advanced

HWA is essentially a set of C definitions designed for bare metal programming of hardware with a generic, pleasant style.

To give you an idea, the following code blinks a LED connected to an STM32F103RBT6 using Systick interrupts and sleeping mode:

#include <hwa/stm32f103rbt6.h>

#define AHBHZ   HW_DEVICE_HSIHZ         // The HSI frequency (8 MHz)
#define LED     (porta,2)               // PA2
#define PERIOD  0.5                     // Blinking period in seconds

HW_ISR(systick) {}                      // The IRQ is used only to wake the core up.

int main ( )
{
  hwa( begin, reset );                  // Record the configuration in a context

  hwa( power, (LED,port), on );         // Power the LED port
  hwa( commit );                        // Write the context in the hardware

  hwa( configure, LED,                  // Configure the LED pin
       function,  gpio,                 //   Optional argument
       mode,      digital_output,       //   Mandatory argument
       frequency, lowest );             //   Optional argument

  hwa( configure, systick,              // Configure the system tick timer
       clock,     ahb/8,                //   Clock it at 1/8th the AHB frequency
       reload,    PERIOD/2*AHBHZ/8-1,
       run,       yes );

  hwa( enable, (systick,irq) );         // Enable Systick IRQs (to wake the core up)

  hwa( commit );                        // Write all that into the hardware

  for(;;) {
    hw( wait, irq );                    // wait event is OK too.
    hw( toggle, LED );                  // Toggle the LED at wake-up
  }
}

This compiles to 94 bytes of application code.

Briefly, HWA provides:

  • a set of objects that represent the hardware,
  • a generic instruction, hw(...), that acts on these objects using various types and numbers of mandatory and optionnal symbolic arguments,
  • a generic instruction, hwa(...), that provides a transactional processing mechanism that allows further optimization of the binary code produced,
  • an error-checking mechanism that produces meaningful messages to help the developer quickly find a solution.

Performances and compatibility

Any C compiler compatible with the C11 standard should be able to compile HWA code.

Being a header-only library, HWA helps the compiler to produce the most efficient machine code, as if the developer had himself written smart accesses to hardware registers.

HWA relies heavily on macro definitions to implement object-oriented generic instructions. As the C preprocessor can be used to parse assembly language code, a few features of HWA can be used for assembly programming. The implementation of a software UART for Atmel AVR microcontrollers and the Diabolo bootloader are examples of such a usage.

Examples

A set of commented examples is provided. Example projects are store in vendor/architecture/examples/ directories (e.g. atmel/avr/examples/). The documentation explains how to compile the examples.

Documentation

A ready-made documentation is available here. You can start with the Using HWA page or browse the examples.

Building your own copy of the documentation from the sources requires Doxygen and Gnu Make. Run make doc in the HWA directory, then open the doxygen/html/index.html page.

Supported hardware

Status

WARNING! The development of HWA is very chaotic and this project is subject to heavy changes of the code base.

Hosting, feedback

HWA is hosted on Github.

Feedbacks will be greatly appreciated. For any bug report, question or suggestion, please open a new issue on Github, or use my gmail address (duparq) and put HWA in the object.

License

HWA is free software. See the license page for license information.