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
ascii_serial_com_register_pointers.h
Go to the documentation of this file.
1#ifndef ASCII_SERIAL_COM_REGISTER_POINTERS_H
2#define ASCII_SERIAL_COM_REGISTER_POINTERS_H
3
4/** \file ascii_serial_com_register_pointers.h
5 *
6 * \brief ASCII Serial Com Register Pointers
7 *
8 * Register interface for devices.
9 *
10 * This interface contains an array of pointers, so that each message address
11 * points to an arbitrary address. Additionally, a write mask controls which
12 * bits of the pointed to words are writable.
13 *
14 * You probably want to create the array of pointers like:
15 *
16 * #define NREGS 6
17 * REGTYPE * reg_pointers[NREGS] = {
18 * &x,
19 * &y,
20 * &z,
21 * NULL,
22 * NULL,
23 * NULL
24 * };
25 *
26 * REGTYPE reg_write_masks[NREGS] = {
27 * 0,
28 * 0x3,
29 * 0xFF,
30 * 0,
31 * 0,
32 * 0
33 * }
34 *
35 * ascii_serial_com_register_pointers_init(&rps,reg_pointers,reg_write_masks,NREGS);
36 *
37 * ## Convenience Macros
38 *
39 * A set of convenience macros are provided to ease the common use of
40 * ascii_serial_com_register_pointers with ascii_serial_com_device.
41 *
42 * ### Required Macros
43 *
44 * To use the macros:
45 *
46 * 1. Declare the register pointer and register write mask array as above
47 * 2. Before the main() function, put `DECLARE_ASC_DEVICE_W_REGISTER_POINTERS()`
48 * on a line **with no semicolon**
49 * 3. In the setup portion of main(), before the polling loop, inside a
50 * Try/Catch block, put:
51 * `SETUP_ASC_DEVICE_W_REGISTER_POINTERS(reg_map,reg_write_masks, NREGS);`,
52 * where the variables are declared as in the previous section.
53 * 4. Inside the polling loop and a Try/Catch block, put:
54 * `HANDLE_ASC_COMM_IN_POLLING_LOOP(USART1);`, replacing USART1 with the
55 * appropriate USART.
56 *
57 * Number 4 assumes something is putting received bytes into a
58 * circular_buffer_uint8 called `extraInputBuffer` (declared and setup by the
59 * macros). This can be accomplished using, for STM32,
60 * `def_usart_isr_push_rx_to_circ_buf(<usart_isr>,<usart>,&extraInputBuffer)`
61 * (no semicolon)
62 *
63 * ## Streaming
64 *
65 * The boolean valued macro `READY_TO_STREAM_ASC_DEVICE_W_REGISTER_POINTERS`
66 * should be checked before actually streaming a message. and
67 * `STREAM_TO_HOST_ASC_DEVICE_W_REGISTER_POINTERS(data,data_len);` should be
68 * run to send the message.
69 *
70 * The macros define a `bool streaming_is_on` that is initialized to false, set
71 * to true when a "n" message is received, and set to false when a "f" message
72 * is received. It should be used to decide when to start auxiliary routines
73 * that prepare to stream messages.
74 *
75 */
76
77#include "ascii_serial_com.h"
78
79#ifdef __AVR
80#define REGWIDTHBITS 8
81#define REGWIDTHBYTES 1
82#define REGTYPE uint8_t
83#define REGPRINTTYPEINT PRIu8
84#define REGPRINTTYPEHEX PRIX8
85#else
86#define REGWIDTHBITS 32
87#define REGWIDTHBYTES 4
88#define REGTYPE uint32_t
89#define REGPRINTTYPEINT PRIu32
90#define REGPRINTTYPEHEX PRIX32
91#endif
92
93/** \brief ASCII Serial Com Register Pointers State struct
94 *
95 * Keeps track of the state of the ASCII Serial Com Register Pointers
96 *
97 */
99 volatile REGTYPE *
100 *pointers; /**< points to start of block of register pointers of memory */
101 REGTYPE *write_masks; /**< points to start of block write masks */
102 uint16_t n_regs; /**< number of registers (number of registers not necessarily
103 number of bytes) */
105
106/** \brief ASCII Serial Com Register Pointers init
107 *
108 * Initialize ASCII Serial Com register_pointers
109 *
110 * \param register_pointers_state should be an uninitialized
111 * ascii_serial_com_register_pointers object
112 *
113 * \param pointers points to an array of pointers to registers (entries may be
114 * NULL). It's volatile so that it can point to device registers without
115 * reads/writes to them being optimized out.
116 *
117 * \param an array of write masks. Every one bit in these masks is a bit that
118 * may be written to the registers.
119 *
120 * \param n_regs is the number of registers in the pointers (not necessarily the
121 * number of bytes)
122 *
123 */
125 ascii_serial_com_register_pointers *register_pointers_state,
126 volatile REGTYPE **pointers, REGTYPE *write_masks, uint16_t n_regs);
127
128/** \brief ASCII Serial Com Register Pointers handle message
129 *
130 * This is the function passed to ascii_serial_com_device as frw
131 *
132 * The parameters are the same as in that function (and
133 * ascii_serial_com_get_message_from_input_buffer + register_pointers_state).
134 *
135 * WILL CLOBBER data
136 *
137 * \param register_pointers_state should be a pointer to an initialized
138 * ascii_serial_com_register_pointers
139 *
140 */
142 ascii_serial_com *asc, char ascVersion, char appVersion, char command,
143 char *data, size_t dataLen, void *register_pointers_state);
144
145#endif
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.
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.
struct ascii_serial_com_register_pointers_struct ascii_serial_com_register_pointers
ASCII Serial Com Register Pointers State struct.
ASCII Serial Com Interface State struct.
ASCII Serial Com Register Pointers State struct.