3#include "externals/unity.h"
15#define regFmtStr "%02zX"
16#elif REGWIDTHBYTES == 2
20#define regFmtStr "%04zX"
21#elif REGWIDTHBYTES == 4
22#define zerohex "00000000"
23#define onehex "00000001"
24#define maxhex "FFFFFFFF"
25#define regFmtStr "%08zX"
29REGTYPE r1, r2, r3, r4, r5;
30volatile REGTYPE *regPtrs[nRegs] = {&r1, &r2, &r3, &r4, &r5};
31REGTYPE masks[nRegs] = {
37 for (
size_t i = 0; i < nRegs; i++) {
47void test_ascii_serial_com_register_pointers_write(
void) {
48 for (
size_t iReg = 0; iReg < nRegs; iReg++) {
59 char ascVersion, appVersion, command, data[MAXDATALEN + 1];
62 char validationStr[MAXMESSAGELEN + 1];
63 for (
size_t iReg = 0; iReg < nRegs; iReg++) {
64 for (
size_t iVal = 0; iVal < 0x100; iVal++) {
69 sprintf(data,
"%04zX," regFmtStr, iReg, iVal);
70 dataLen = 5 + REGWIDTHBYTES * 2;
71 sprintf(validationStr,
">%c%c%c%04zX.", ascVersion, appVersion, command,
74 &asc, ascVersion, appVersion, command, data, dataLen, &ascrb);
75 TEST_ASSERT_EQUAL_size_t(10 + 4,
77 TEST_ASSERT_EQUAL_CHAR_ARRAY(validationStr, out_buf->
buffer, 5 + 4);
80 TEST_ASSERT_EQUAL_MESSAGE(iVal, *regPtrs[iReg],
81 "Register didn't get set to correct value!");
84 sprintf(data,
"%04zX", iReg);
86 sprintf(validationStr,
">%c%c%c%04zX," regFmtStr
".", ascVersion,
87 appVersion, command, iReg, iVal);
89 &asc, ascVersion, appVersion, command, data, dataLen, &ascrb);
90 TEST_ASSERT_EQUAL_size_t(15 + REGWIDTHBYTES * 2,
92 TEST_ASSERT_EQUAL_CHAR_ARRAY(validationStr, out_buf->
buffer,
93 10 + REGWIDTHBYTES * 2);
99 printf(
"Uncaught exception: %u\n", e1);
100 TEST_FAIL_MESSAGE(
"Uncaught exception!");
104void test_ascii_serial_com_register_pointers_write_masked(
void) {
113 char ascVersion, appVersion, command, data[MAXDATALEN + 1];
116 char validationStr[MAXMESSAGELEN + 1];
117 for (
size_t iReg = 0; iReg < nRegs; iReg++) {
120 for (
size_t iReg = 0; iReg < nRegs; iReg++) {
121 for (
size_t iVal = 0; iVal < 0x100; iVal++) {
126 sprintf(data,
"%04zX," regFmtStr, iReg, iVal);
127 dataLen = 5 + REGWIDTHBYTES * 2;
128 sprintf(validationStr,
">%c%c%c%04zX.", ascVersion, appVersion, command,
131 &asc, ascVersion, appVersion, command, data, dataLen, &ascrb);
132 TEST_ASSERT_EQUAL_size_t(10 + 4,
134 TEST_ASSERT_EQUAL_CHAR_ARRAY(validationStr, out_buf->
buffer, 5 + 4);
137 TEST_ASSERT_EQUAL_MESSAGE(iVal & 0x35, *regPtrs[iReg],
138 "Register didn't get set to correct value!");
141 sprintf(data,
"%04zX", iReg);
143 sprintf(validationStr,
">%c%c%c%04zX," regFmtStr
".", ascVersion,
144 appVersion, command, iReg, iVal & 0x35);
146 &asc, ascVersion, appVersion, command, data, dataLen, &ascrb);
147 TEST_ASSERT_EQUAL_size_t(15 + REGWIDTHBYTES * 2,
149 TEST_ASSERT_EQUAL_CHAR_ARRAY(validationStr, out_buf->
buffer,
150 10 + REGWIDTHBYTES * 2);
154 for (
size_t iReg = 0; iReg < nRegs; iReg++) {
155 *regPtrs[iReg] = 0xFF;
157 for (
size_t iReg = 0; iReg < nRegs; iReg++) {
158 for (
size_t iVal = 0; iVal < 0x100; iVal++) {
163 sprintf(data,
"%04zX," regFmtStr, iReg, iVal);
164 dataLen = 5 + REGWIDTHBYTES * 2;
165 sprintf(validationStr,
">%c%c%c%04zX.", ascVersion, appVersion, command,
168 &asc, ascVersion, appVersion, command, data, dataLen, &ascrb);
169 TEST_ASSERT_EQUAL_size_t(10 + 4,
171 TEST_ASSERT_EQUAL_CHAR_ARRAY(validationStr, out_buf->
buffer, 5 + 4);
174 TEST_ASSERT_EQUAL_MESSAGE((iVal & 0x35) | (0xFF & ~0x35),
176 "Register didn't get set to correct value!");
179 sprintf(data,
"%04zX", iReg);
181 sprintf(validationStr,
">%c%c%c%04zX," regFmtStr
".", ascVersion,
182 appVersion, command, iReg, (iVal & 0x35) | (0xFF & ~0x35));
184 &asc, ascVersion, appVersion, command, data, dataLen, &ascrb);
185 TEST_ASSERT_EQUAL_size_t(15 + REGWIDTHBYTES * 2,
187 TEST_ASSERT_EQUAL_CHAR_ARRAY(validationStr, out_buf->
buffer,
188 10 + REGWIDTHBYTES * 2);
194 printf(
"Uncaught exception: %u\n", e1);
195 TEST_FAIL_MESSAGE(
"Uncaught exception!");
201 RUN_TEST(test_ascii_serial_com_register_pointers_write);
202 RUN_TEST(test_ascii_serial_com_register_pointers_write_masked);
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_register_pointers_handle_message(ascii_serial_com *asc, char ascVersion, char appVersion, char command, char *data, size_t dataLen, void *register_pointers_state_vp)
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.
ASCII Serial Com Register Pointers.
size_t circular_buffer_get_size_uint8(const circular_buffer_uint8 *circ_buf)
circular buffer get number of elements
void circular_buffer_clear_uint8(circular_buffer_uint8 *circ_buf)
circular buffer clear
ASCII Serial Com Interface State struct.
ASCII Serial Com Register Pointers State struct.