HWA
Bare metal programming with style
|
This class implements a software-emulated UART with the following features:
Tested on ATtiny24/44/84 with internal oscillator (rc_8MHz):
swuarta-perfs
defined in hwa/atmel/avr/examples/make/Makefile.cc
displays the number of CPU cycles spent in different sections of the _swuarta
code and in critical sections according to the configuration. These figures determine the performances that can be achieved.If the same pin is used for rxd
and txd
signals, the UART automatically reverts to RX mode after a transmission is completed and transmissions are delayed one a reception is started, i.e. hw(write,UART,data)
blocks until a reception is completed once it has started.
By default, the pin-change controller associated to the RXD pin is used as the interrupt provider for detecting the start bit. This implies that the same pin-change controller should not be used by the application.
The counting unit is configured in up-loop mode, counting from 0 to the maximum it can reach. The user application can use the count value and the overflow interrupt, for example to make a RTC counter.
If defined, autosync
a method to automatically detect the baudrate:
51
: waits for a sequence of 5 low-level bits followed by 1 low-level bit. The ASCII characters 'A' or 'p' will do that.91
: waits for a sequence of 9 low-level bits followed by 1 low-level bit. E.g.: 0x00 / 0xFF bytes.101
: waits for a sequence of 10 low-level bits followed by 1 low-level bit. This can be done by sending a break byte of 10 low-level bits or a '0' byte with even parity, followed by a 0xFF byte.If check_tx
is defined, the status of the bus is compared with the last bit sent before sending a new one. If there is a mismatch (collision), the UART releases the TXD pin and sets the stop
status flag to 0. The UART continues virtually to send until the end of the frame when it sets the txc
bit as usual. That way, the application remains synchronized with the bus and can decide whether to retry the transmission or to listen to what is happening on the bus.
check_tx
can not be set by the constructor.Header file:
HW_SWUARTA(...) declares an object. You must provide:
HW_DECLARE( UART ) declares the functions that implement the device. You can put it in your header files:
Currently, class _swuarta does not support HW_IMPLEMENT(). You must include the assembly file hwa/ext/swuarta.sx
in one of your source files after having defined a UART
symbol, once per object:
Both hw( configure, UART, ... ) and hwa( configure, UART, ... ) configure the object but they differ slightly in what they do:
Optionnal arguments are used for consistency with the class _uarta.
hw( read, UART ) clears the rxc
flag, and returns the last byte received.
hw( write, UART, byte ) places a byte into the shift register, clears the txc
flag and starts the transmission.
This instruction returns before the byte is actually transmitted. You need to check the txc
flag to know when the transmission is complete.
hw( stat, UART ) returns the status with the following flags:
stop
: the state of the last stop bit received, 0 if the byte failed to transmit (collision)rxc
: 1 when a reception is completed (stop bit sampled)txc
: 1 when the transmission is completed (stop bit sent)sync
: 1 when the UART is synchronized
hw( clear, UART ) clears the rxc
and txc
status flags.
hw( reset, UART ) aborts any transmission or reception. If the UART has automatic baudrate detection, the UART will first resynchronize.
hw( wait_idle, UART, n ) wait n idle bits:
dt0
: number of counter clocks between the start condition and the sampling of data bit #0dtn
: number of counter clocks between samplingssr
: status byte Macros | |
#define | HW_SWUARTA(...) |