ASCII Serial Com
Serial communication library between computers, microcontrollers, FPGAs, etc. Uses only ASCII. Not the most efficient protocol, but meant to be easy to read
Loading...
Searching...
No Matches
arduino_uno_dummy_register_block.c
1#include "asc_exception.h"
2#include "asc_helpers.h"
3#include "ascii_serial_com.h"
6#include "avr/avr_uart.h"
7#include "circular_buffer.h"
8
9#include <avr/interrupt.h>
10#include <avr/io.h>
11#include <util/atomic.h>
12
13#define F_CPU 16000000L
14#define BAUD 9600
15#define MYUBRR (F_CPU / 16 / BAUD - 1)
16#define UART_NO 0
17
18char dataBuffer[MAXDATALEN];
19#define nRegs 10
20REGTYPE regs[nRegs];
21
26 .state_rw = &reg_block};
27circular_buffer_uint8 *asc_in_buf;
28circular_buffer_uint8 *asc_out_buf;
29
30#define extraInputBuffer_size 64
31uint8_t extraInputBuffer_raw[extraInputBuffer_size];
32circular_buffer_uint8 extraInputBuffer;
33
34CEXCEPTION_T e;
35
36uint16_t nExceptions;
37
38int main(void) {
39
40 nExceptions = 0;
41
42 Try {
43 ascii_serial_com_register_block_init(&reg_block, regs, nRegs);
44 ascii_serial_com_device_init(&ascd, &ascd_config);
47
48 circular_buffer_init_uint8(&extraInputBuffer, extraInputBuffer_size,
49 extraInputBuffer_raw);
50 }
51 Catch(e) { return e; }
52
53 UART_Init(UART_NO, MYUBRR, 1);
54
55 sei();
56
57 while (true) {
58 Try {
59 // if (USART0_can_read_Rx_data) {
60 // circular_buffer_push_back_uint8(asc_in_buf, UDR0);
61 //}
62
63 if (!circular_buffer_is_empty_uint8(&extraInputBuffer)) {
64 uint8_t byte;
65 ATOMIC_BLOCK(ATOMIC_FORCEON) {
66 byte = circular_buffer_pop_front_uint8(&extraInputBuffer);
67 }
68 circular_buffer_push_back_uint8(asc_in_buf, byte);
69 }
70
72
73 uart_tx_from_circ_buf(UART_NO, asc_out_buf);
74 }
75 Catch(e) { nExceptions++; }
76 }
77
78 return 0;
79}
80
81ISR(USART_RX_vect) { uart_rx_to_circ_buf(UART_NO, &extraInputBuffer); }
#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_device_get_output_buffer(ascii_serial_com_device *ascd)
ASCII Serial Com Device get output buffer.
void ascii_serial_com_device_receive(ascii_serial_com_device *ascd)
ASCII Serial Com Device receive messages.
circular_buffer_uint8 * ascii_serial_com_device_get_input_buffer(ascii_serial_com_device *ascd)
ASCII Serial Com Device get input buffer.
void ascii_serial_com_device_init(ascii_serial_com_device *ascd, ascii_serial_com_device_config *config)
ASCII Serial Com Device init.
ASCII Serial Com Device.
void ascii_serial_com_register_block_handle_message(ascii_serial_com *asc, char ascVersion, char appVersion, char command, char *data, size_t dataLen, void *register_block_state_vp)
ASCII Serial Com Register Block handle message.
void ascii_serial_com_register_block_init(ascii_serial_com_register_block *register_block_state, REGTYPE *block, uint16_t n_regs)
ASCII Serial Com Register Block init.
ASCII Serial Com Register Block.
#define UART_Init(uart_no, ubrr, rxIntEnable)
Initialize USART.
Definition avr_uart.h:20
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_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 Device Config Struct.
void(* func_rw)(ascii_serial_com *, char, char, char, char *data, size_t, void *)
ASCII Serial Com Device State struct.
ASCII Serial Com Register Block State struct.
circular buffer struct