8#include <avr/interrupt.h>
10#include <util/atomic.h>
12#define F_CPU 16000000L
14#define MYUBRR (F_CPU / 16 / BAUD - 1)
18#define n_overflows F_CPU / 1024 / 256 / 2
22char dataBuffer[MAXDATALEN];
25#define extraInputBuffer_size 64
26uint8_t extraInputBuffer_raw[extraInputBuffer_size];
32char ascVersion, appVersion, command;
37static int uart_putchar(
char c, FILE *stream);
39static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE);
41#pragma GCC diagnostic ignored "-Wunused-variable"
42#pragma GCC diagnostic push
43#pragma GCC diagnostic ignored "-Wunused-parameter"
44#pragma GCC diagnostic push
45static int uart_putchar(
char c, FILE *stream) {
49#pragma GCC diagnostic pop
50#pragma GCC diagnostic pop
54 printf(
"%s\n", title);
56 printf(
" size: %u\n ", sz);
57 for (
size_t i = 0; i < sz; i++) {
66 for (
size_t i = 0; i < cb->
capacity; i++) {
76 for (
size_t i = 0; i < cb->
capacity; i++) {
84 for (
size_t i = 0; i < cb->
capacity; i++) {
87 }
else if (i == cb->
iStop) {
121 ascii_serial_com_set_ignore_CRC_mismatch(&asc);
126 extraInputBuffer_raw);
128 Catch(e) {
return e; }
170 ATOMIC_BLOCK(ATOMIC_FORCEON) {
174 print_buffer(
"in", asc_in_buf);
175 print_buffer(
"out", asc_out_buf);
183 &asc, &ascVersion, &appVersion, &command, dataBuffer, &dataLen);
184 if (command !=
'\0') {
188 &asc, ascVersion, appVersion, command, dataBuffer, dataLen);
195 Catch(e) { nExceptions++; }
203ISR(TIMER0_OVF_vect) {
204 static uint16_t timer_overflow_count;
205 timer_overflow_count += 1;
206 if (timer_overflow_count == n_overflows) {
208 timer_overflow_count = 0;
#define uart_tx(uart_no, data)
#define uart_rx_to_circ_buf(uart_no, circ_buf_ptr)
Receive a byte from UART into circular buffer.
#define uart_tx_from_circ_buf(uart_no, circ_buf_ptr)
Transmit a byte from the circular buffer.
circular_buffer_uint8 * ascii_serial_com_get_output_buffer(ascii_serial_com *asc)
ASCII Serial Com get output buffer.
void ascii_serial_com_init(ascii_serial_com *asc)
ASCII Serial Com Interface init method.
void ascii_serial_com_put_message_in_output_buffer(ascii_serial_com *asc, char ascVersion, char appVersion, char command, const char *data, size_t dataLen)
ASCII Serial Com Pack and put message in output buffer.
void ascii_serial_com_get_message_from_input_buffer(ascii_serial_com *asc, char *ascVersion, char *appVersion, char *command, char *data, size_t *dataLen)
ASCII Serial Com pop message from input buffer and unpack.
circular_buffer_uint8 * ascii_serial_com_get_input_buffer(ascii_serial_com *asc)
ASCII Serial Com get input buffer.
#define TIMER0_Init(cs, ctc, timsk0)
Initialize Timer0.
#define UART_Init(uart_no, ubrr, rxIntEnable)
Initialize USART.
size_t circular_buffer_get_size_uint8(const circular_buffer_uint8 *circ_buf)
circular buffer get number of elements
void circular_buffer_init_uint8(circular_buffer_uint8 *circ_buf, const size_t capacity, uint8_t *buffer)
circular buffer init method
uint8_t circular_buffer_get_element_uint8(const circular_buffer_uint8 *circ_buf, const size_t iElement)
circular buffer get element
uint8_t circular_buffer_pop_front_uint8(circular_buffer_uint8 *circ_buf)
circular buffer pop front
bool circular_buffer_is_empty_uint8(const circular_buffer_uint8 *circ_buf)
circular buffer get if empty
void circular_buffer_push_back_uint8(circular_buffer_uint8 *circ_buf, const uint8_t element)
circular buffer push back
ASCII Serial Com Interface State struct.