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
|
#include <inttypes.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "ascii_serial_com.h"
#include "circular_buffer.h"
Go to the source code of this file.
Macros | |
#define | is_uart_rx_data_waiting(uart_no) _is_uart_rx_data_waiting(uart_no) |
#define | _is_uart_rx_data_waiting(uart_no) ((USART_ISR(USART##uart_no) & USART_ISR_RXNE)) |
#define | is_uart_ready_to_tx(uart_no) _is_uart_ready_to_tx(uart_no) |
#define | _is_uart_ready_to_tx(uart_no) ((USART_ISR(USART##uart_no) & USART_ISR_TXE)) |
#define | uart_rx(uart_no, _tmp_byte) _uart_rx(uart_no, _tmp_byte) |
#define | _uart_rx(uart_no, _tmp_byte) |
#define | uart_rx_blocking(uart_no, _tmp_byte) |
#define | uart_tx(uart_no, data) _uart_tx(uart_no, data) |
#define | _uart_tx(uart_no, data) usart_send(USART##uart_no, data) |
#define | uart_tx_blocking(uart_no, _tmp_byte) |
#define | _ATOMIC CM_ATOMIC_BLOCK() |
#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. | |
#define | _extraInputBuffer_size_ 64 |
#define | DECLARE_ASC_DEVICE_W_REGISTER_POINTERS() |
Declarations for ascii_serial_com_device and ascii_serial_com_register_pointers. | |
#define | SETUP_ASC_DEVICE_W_REGISTER_POINTERS(register_map, register_write_masks, nRegs) |
Setup for ascii_serial_com_device and ascii_serial_com_register_pointers. | |
#define | HANDLE_ASC_COMM_IN_POLLING_LOOP(uart_no) |
Polling for ascii_serial_com_device and ascii_serial_com_register_pointers. | |
#define | READY_TO_STREAM_ASC_DEVICE_W_REGISTER_POINTERS |
Check if you should stream a message to the host. | |
#define | STREAM_TO_HOST_ASC_DEVICE_W_REGISTER_POINTERS(data, data_size) |
Stream data to the host. | |
Variables | |
uint8_t | ASC_HELPERS_BYTE |
Helper macros to help with UARTs, etc.
Definition in file asc_helpers.h.
#define _ATOMIC CM_ATOMIC_BLOCK() |
Cross-platform atomic block
Definition at line 164 of file asc_helpers.h.
#define _extraInputBuffer_size_ 64 |
Definition at line 206 of file asc_helpers.h.
#define _is_uart_ready_to_tx | ( | uart_no | ) | ((USART_ISR(USART##uart_no) & USART_ISR_TXE)) |
Second level of macro makes sure parameters are expanded before subbing into string concatenation
Definition at line 60 of file asc_helpers.h.
#define _is_uart_rx_data_waiting | ( | uart_no | ) | ((USART_ISR(USART##uart_no) & USART_ISR_RXNE)) |
Second level of macro makes sure parameters are expanded before subbing into string concatenation
Definition at line 35 of file asc_helpers.h.
#define _uart_rx | ( | uart_no, | |
_tmp_byte ) |
Second level of macro makes sure parameters are expanded before subbing into string concatenation
Definition at line 84 of file asc_helpers.h.
#define _uart_tx | ( | uart_no, | |
data ) usart_send(USART##uart_no, data) |
Second level of macro makes sure parameters are expanded before subbing into string concatenation
Definition at line 130 of file asc_helpers.h.
#define DECLARE_ASC_DEVICE_W_REGISTER_POINTERS | ( | ) |
Declarations for ascii_serial_com_device and ascii_serial_com_register_pointers.
Declarations that should be outside of (and before) main() to ease use of ascii_serial_com_register_pointers with ascii_serial_com_device.
The only "public" variables are:
bool streaming_is_on; circular_buffer_uint8 extraInputBuffer;
Don't follow this with a semicolon
None
Definition at line 228 of file asc_helpers.h.
#define HANDLE_ASC_COMM_IN_POLLING_LOOP | ( | uart_no | ) |
Polling for ascii_serial_com_device and ascii_serial_com_register_pointers.
Within the polling loop, handles transmitting bytes, processing received bytes, and handling received messages. This is part of a group of macros to ease use of ascii_serial_com_register_pointers with ascii_serial_com_device.
Assumes that something else receives bytes and puts them in extraInputBuffer
Make sure this is inside a Try/Catch block
Follow this with a semicolon
uart: the address of the USART used for transmitting bytes. For STM32: USART1, USART2, .... For AVR: UDR0, ....
Definition at line 313 of file asc_helpers.h.
#define is_uart_ready_to_tx | ( | uart_no | ) | _is_uart_ready_to_tx(uart_no) |
Helper to check if UART tx buffer is ready for the user to write to it
Use uart_no as 1,2,3, etc.
Definition at line 53 of file asc_helpers.h.
#define is_uart_rx_data_waiting | ( | uart_no | ) | _is_uart_rx_data_waiting(uart_no) |
Helper to check if UART has a received a byte and is waiting on the user to read it
Use uart_no as 1,2,3, etc.
Definition at line 28 of file asc_helpers.h.
#define READY_TO_STREAM_ASC_DEVICE_W_REGISTER_POINTERS |
Check if you should stream a message to the host.
This is a boolean value macro that checks if streaming is enabled and the transmit buffer is empty. If true, the user may stream a message to the host now with STREAM_TO_HOST_ASC_DEVICE_W_REGISTER_POINTERS
This is part of a group of macros to ease use of ascii_serial_com_register_pointers with ascii_serial_com_device.
Make sure this is inside a Try/Catch block
Definition at line 341 of file asc_helpers.h.
#define SETUP_ASC_DEVICE_W_REGISTER_POINTERS | ( | register_map, | |
register_write_masks, | |||
nRegs ) |
Setup for ascii_serial_com_device and ascii_serial_com_register_pointers.
Setup that should be inside main() before the polling loop. This is part of a group of macros to ease use of ascii_serial_com_register_pointers with ascii_serial_com_device.
Make sure this is inside a Try/Catch block
Follow this with a semicolon
register_map: the register map, type: REGTYPE * array
register_write_masks: the register write masks, type: REGTYPE array
nRegs: the length of the two arrays above
Definition at line 280 of file asc_helpers.h.
#define STREAM_TO_HOST_ASC_DEVICE_W_REGISTER_POINTERS | ( | data, | |
data_size ) |
Stream data to the host.
This macro puts a message in the output buffer
This is part of a group of macros to ease use of ascii_serial_com_register_pointers with ascii_serial_com_device.
Make sure this is inside a Try/Catch block
data: a pointer to data or array of data to be sent
data_size: a uint describing the data size in bytes
Definition at line 364 of file asc_helpers.h.
#define uart_rx | ( | uart_no, | |
_tmp_byte ) _uart_rx(uart_no, _tmp_byte) |
Reads from the UART rx buffer, non-blocking, without checking if data is there
Definition at line 77 of file asc_helpers.h.
#define uart_rx_blocking | ( | uart_no, | |
_tmp_byte ) |
Reads from the UART rx buffer, blocking until data is there
Definition at line 107 of file asc_helpers.h.
#define uart_rx_to_circ_buf | ( | uart_no, | |
circ_buf_ptr ) |
Receive a byte from UART into circular buffer.
Checks if uart has a received byte waiting, and if so, pushes it onto the back of the circular buffer.
Definition at line 179 of file asc_helpers.h.
#define uart_tx | ( | uart_no, | |
data ) _uart_tx(uart_no, data) |
Writes to the UART tx buffer, non-blocking, without checking if it's ready to receive data
Definition at line 123 of file asc_helpers.h.
#define uart_tx_blocking | ( | uart_no, | |
_tmp_byte ) |
Writes to the UART tx buffer, blocking until the buffer is ready for writing
Definition at line 148 of file asc_helpers.h.
#define uart_tx_from_circ_buf | ( | uart_no, | |
circ_buf_ptr ) |
Transmit a byte from the circular buffer.
Checks if uart can accept a byte and the circular buffer isn't empty, and if so, pops a byte off of the circular buffer and transmits it.
Definition at line 194 of file asc_helpers.h.
uint8_t ASC_HELPERS_BYTE |
Definition at line 18 of file asc_helpers.h.