HWA
Bare metal programming with style
hwa/atmel/avr/examples/05-1-swuart-tx/main.c

Send a '.' on TXD every 0.1s. Can use hardware UART as well as software UART.

Test application:

./main.py -b <BAUDRATE>

Note: this can fail if the system frequency is not known precisely enough (if using an internal RC oscillator for example).

config.h
/* This file is part of the HWA project.
* Copyright (c) 2012,2015 Christophe Duparquet.
* All rights reserved. Read LICENSE.TXT for details.
*/
#ifndef CONFIG_H
#define CONFIG_H
#include BOARD_H
#define UART HW_SWUARTA( txd, DIABOLO_PIN_TX, \
counter, counter0, \
compare, compare0, \
clkdiv, 1, \
autosync, 51, \
fastreg, (shared,gpior0) )
HW_DECLARE(UART);
#define BPS 115200
#endif
main.c
/* This file is part of the HWA project.
* Copyright (c) 2012,2015 Christophe Duparquet.
* All rights reserved. Read LICENSE.TXT for details.
*/
#include "config.h"
int
main ( )
{
/* Create a HWA context to collect the hardware configuration
* Preload this context with RESET values
*/
hwa( begin, reset );
/* Configure the UART
*/
hwa( configure, UART,
bps, BPS,
databits, 8,
parity, none,
stopbits, 1 );
/* Write this configuration into the hardware
*/
hwa( commit );
hw( enable, interrupts );
for(;;) {
/* Wait for 0.1s
*/
hw_waste_cycles( 0.1 * HW_SYSHZ );
/* Send a '.'
*/
while ( !hw(stat,UART).txc ) {}
hw( write, UART, '.');
}
}
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
swuarta.h
Software-emulated UART.
hw
#define hw(...)
hw( action, object [,...] ) executes an action immediately on an object.
Definition: hwa_macros.h:523
hw_waste_cycles
#define hw_waste_cycles(n)
Definition: hwa_2.h:98