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
|
ASCII Serial Com Register Pointers. More...
#include "ascii_serial_com.h"
Go to the source code of this file.
Classes | |
struct | ascii_serial_com_register_pointers_struct |
ASCII Serial Com Register Pointers State struct. More... | |
Macros | |
#define | REGWIDTHBITS 8 |
#define | REGWIDTHBYTES 1 |
#define | REGTYPE uint8_t |
#define | REGPRINTTYPEINT PRIu8 |
#define | REGPRINTTYPEHEX PRIX8 |
Typedefs | |
typedef struct ascii_serial_com_register_pointers_struct | ascii_serial_com_register_pointers |
ASCII Serial Com Register Pointers State struct. | |
Functions | |
void | ascii_serial_com_register_pointers_init (ascii_serial_com_register_pointers *register_pointers_state, volatile REGTYPE **pointers, REGTYPE *write_masks, uint16_t n_regs) |
ASCII Serial Com Register Pointers init. | |
void | ascii_serial_com_register_pointers_handle_message (ascii_serial_com *asc, char ascVersion, char appVersion, char command, char *data, size_t dataLen, void *register_pointers_state) |
ASCII Serial Com Register Pointers handle message. | |
ASCII Serial Com Register Pointers.
Register interface for devices.
This interface contains an array of pointers, so that each message address points to an arbitrary address. Additionally, a write mask controls which bits of the pointed to words are writable.
You probably want to create the array of pointers like:
#define NREGS 6 REGTYPE * reg_pointers[NREGS] = { &x, &y, &z, NULL, NULL, NULL }; REGTYPE reg_write_masks[NREGS] = { 0, 0x3, 0xFF, 0, 0, 0 } ascii_serial_com_register_pointers_init(&rps,reg_pointers,reg_write_masks,NREGS);
A set of convenience macros are provided to ease the common use of ascii_serial_com_register_pointers with ascii_serial_com_device.
To use the macros:
DECLARE_ASC_DEVICE_W_REGISTER_POINTERS()
on a line with no semicolonSETUP_ASC_DEVICE_W_REGISTER_POINTERS(reg_map,reg_write_masks, NREGS);
, where the variables are declared as in the previous section.HANDLE_ASC_COMM_IN_POLLING_LOOP(USART1);
, replacing USART1 with the appropriate USART.Number 4 assumes something is putting received bytes into a circular_buffer_uint8 called extraInputBuffer
(declared and setup by the macros). This can be accomplished using, for STM32, def_usart_isr_push_rx_to_circ_buf(<usart_isr>,<usart>,&extraInputBuffer)
(no semicolon)
The boolean valued macro READY_TO_STREAM_ASC_DEVICE_W_REGISTER_POINTERS
should be checked before actually streaming a message. and STREAM_TO_HOST_ASC_DEVICE_W_REGISTER_POINTERS(data,data_len);
should be run to send the message.
The macros define a bool streaming_is_on
that is initialized to false, set to true when a "n" message is received, and set to false when a "f" message is received. It should be used to decide when to start auxiliary routines that prepare to stream messages.
Definition in file ascii_serial_com_register_pointers.h.
#define REGPRINTTYPEHEX PRIX8 |
Definition at line 84 of file ascii_serial_com_register_pointers.h.
#define REGPRINTTYPEINT PRIu8 |
Definition at line 83 of file ascii_serial_com_register_pointers.h.
#define REGTYPE uint8_t |
Definition at line 82 of file ascii_serial_com_register_pointers.h.
#define REGWIDTHBITS 8 |
Definition at line 80 of file ascii_serial_com_register_pointers.h.
#define REGWIDTHBYTES 1 |
Definition at line 81 of file ascii_serial_com_register_pointers.h.
ASCII Serial Com Register Pointers State struct.
Keeps track of the state of the ASCII Serial Com Register Pointers
void ascii_serial_com_register_pointers_handle_message | ( | ascii_serial_com * | asc, |
char | ascVersion, | ||
char | appVersion, | ||
char | command, | ||
char * | data, | ||
size_t | dataLen, | ||
void * | register_pointers_state ) |
ASCII Serial Com Register Pointers handle message.
This is the function passed to ascii_serial_com_device as frw
The parameters are the same as in that function (and ascii_serial_com_get_message_from_input_buffer + register_pointers_state).
WILL CLOBBER data
register_pointers_state | should be a pointer to an initialized ascii_serial_com_register_pointers |
Definition at line 26 of file ascii_serial_com_register_pointers.c.
References ascii_serial_com_put_error_in_output_buffer(), ascii_serial_com_put_message_in_output_buffer(), convert_hex_to_uint16(), ascii_serial_com_register_pointers_struct::n_regs, ascii_serial_com_register_pointers_struct::pointers, and ascii_serial_com_register_pointers_struct::write_masks.
void ascii_serial_com_register_pointers_init | ( | ascii_serial_com_register_pointers * | register_pointers_state, |
volatile REGTYPE ** | pointers, | ||
REGTYPE * | write_masks, | ||
uint16_t | n_regs ) |
ASCII Serial Com Register Pointers init.
Initialize ASCII Serial Com register_pointers
register_pointers_state | should be an uninitialized ascii_serial_com_register_pointers object |
pointers | points to an array of pointers to registers (entries may be NULL). It's volatile so that it can point to device registers without reads/writes to them being optimized out. |
an | array of write masks. Every one bit in these masks is a bit that may be written to the registers. |
n_regs | is the number of registers in the pointers (not necessarily the number of bytes) |
Definition at line 18 of file ascii_serial_com_register_pointers.c.
References ascii_serial_com_register_pointers_struct::n_regs, ascii_serial_com_register_pointers_struct::pointers, and ascii_serial_com_register_pointers_struct::write_masks.