Use bool consistently now that we're on C23

This commit is contained in:
Allen Hill
2026-05-16 01:26:43 +00:00
parent 9fbaa7a55f
commit c0bb9c4018
5 changed files with 45 additions and 46 deletions
+13 -14
View File
@@ -210,12 +210,12 @@ static inline void AVCLAN_setBusDriven() {
// clang-format on // clang-format on
// Returns true if device TX is muted on AVCLAN bus // Returns true if device TX is muted on AVCLAN bus
static inline uint8_t AVCLAN_ismuted() { static inline bool AVCLAN_ismuted() {
return (((VPORTA_DIR & PIN4_bm) | (VPORTA_DIR & PIN0_bm)) == 0); return (((VPORTA_DIR & PIN4_bm) | (VPORTA_DIR & PIN0_bm)) == 0);
} }
// Mute device TX on AVCLAN bus // Mute device TX on AVCLAN bus
void AVCLAN_muteDevice(uint8_t mute) { void AVCLAN_muteDevice(bool mute) {
if (mute) { if (mute) {
// clang-format off // clang-format off
__asm__ __volatile__("cbi %[vporta_dir], 4; \n\t" // set as INPUT (output values ignored) __asm__ __volatile__("cbi %[vporta_dir], 4; \n\t" // set as INPUT (output values ignored)
@@ -291,7 +291,7 @@ void AVCLAN_init() {
AVCLAN_setBusIdle(); AVCLAN_setBusIdle();
AVCLAN_muteDevice(0); // unmute AVCLAN bus TX AVCLAN_muteDevice(false); // unmute AVCLAN bus TX
cd_status.cds = cd_CD1; cd_status.cds = cd_CD1;
cd_status.disc = 1; cd_status.disc = 1;
@@ -328,7 +328,7 @@ static void serializeCDStatus(uint8_t *dst) {
dst[5] = toBCD(cd_status.secs); dst[5] = toBCD(cd_status.secs);
} }
uint8_t AVCLAN_isPlaying() { return (CD_Mode == stPlay); } bool AVCLAN_isPlaying() { return (CD_Mode == stPlay); }
void AVCLAN_incrementTime() { void AVCLAN_incrementTime() {
// Sentinel values (>99) mean "no time"; leave them alone until setTime() // Sentinel values (>99) mean "no time"; leave them alone until setTime()
@@ -414,7 +414,7 @@ uint8_t AVCLAN_readbit_ACK() {
set_AVC_logic_for(0, AVCLAN_BIT1_LOGIC_0); set_AVC_logic_for(0, AVCLAN_BIT1_LOGIC_0);
AVCLAN_setBusIdle(); // Stop driving bus AVCLAN_setBusIdle(); // Stop driving bus
while (1) { while (true) {
if (!BUS_IS_IDLE && (TCB1.CNT > AVCLAN_READBIT_THRESHOLD)) if (!BUS_IS_IDLE && (TCB1.CNT > AVCLAN_READBIT_THRESHOLD))
break; // ACK break; // ACK
if (TCB1.CNT > AVCLAN_BIT_LENGTH_MAX) if (TCB1.CNT > AVCLAN_BIT_LENGTH_MAX)
@@ -512,7 +512,7 @@ uint8_t AVCLAN_readbitsi(uint8_t *bits, uint8_t len) {
sei(); sei();
TCB1.CNT = 0; TCB1.CNT = 0;
while (READING_NBITS != 0) { while (READING_NBITS) {
// 200% the duration of `len` bits // 200% the duration of `len` bits
if (TCB1.CNT > ((uint16_t)AVCLAN_BIT_LENGTH_MAX * 2 * len)) { if (TCB1.CNT > ((uint16_t)AVCLAN_BIT_LENGTH_MAX * 2 * len)) {
READING_BYTE = 0; READING_BYTE = 0;
@@ -551,7 +551,7 @@ uint8_t AVCLAN_readbyte(uint8_t *byte) {
sei(); sei();
TCB1.CNT = 0; TCB1.CNT = 0;
while (READING_NBITS != 0) { while (READING_NBITS) {
// 200% the length of a byte // 200% the length of a byte
if (TCB1.CNT > ((uint16_t)AVCLAN_BIT_LENGTH_MAX * 2 * 8)) { if (TCB1.CNT > ((uint16_t)AVCLAN_BIT_LENGTH_MAX * 2 * 8)) {
READING_BYTE = 0; READING_BYTE = 0;
@@ -644,8 +644,7 @@ uint8_t AVCLAN_readframe(AVCLAN_frame_t *frame, log_t print) {
goto handle_err; goto handle_err;
} }
uint8_t shouldACK = bool shouldACK = !AVCLAN_ismuted() && (frame->peripheral_addr == DEVICE_ADDR);
!AVCLAN_ismuted() && (frame->peripheral_addr == DEVICE_ADDR);
if (shouldACK) if (shouldACK)
AVCLAN_sendbit_ACK(); AVCLAN_sendbit_ACK();
@@ -705,7 +704,7 @@ uint8_t AVCLAN_readframe(AVCLAN_frame_t *frame, log_t print) {
} }
} }
if (0) { if (false) {
handle_err:; handle_err:;
startEvent(); startEvent();
RS232_Print("ERR(read): "); RS232_Print("ERR(read): ");
@@ -740,7 +739,7 @@ uint8_t AVCLAN_readframe(AVCLAN_frame_t *frame, log_t print) {
startEvent(); startEvent();
} }
// Only print if some data has been correctly recieved // Only print if some data has been correctly received
if (print.print && (err.errno < STARTBIT_TOO_SHORT)) { if (print.print && (err.errno < STARTBIT_TOO_SHORT)) {
if (err.errno > BAD_DATA_PARITY) if (err.errno > BAD_DATA_PARITY)
frame->length = 0; frame->length = 0;
@@ -848,7 +847,7 @@ uint8_t AVCLAN_sendframe(const AVCLAN_frame_t *frame, log_t print) {
} }
// back to read mode // back to read mode
if (0) { if (false) {
handle_err:; handle_err:;
startEvent(); startEvent();
RS232_Print("Error"); RS232_Print("Error");
@@ -1057,7 +1056,7 @@ uint8_t AVCLAN_tryrespond(const AVCLAN_frame_t *resp) {
return r; return r;
} }
void AVCLAN_printframe(const AVCLAN_frame_t *frame, uint8_t binary) { void AVCLAN_printframe(const AVCLAN_frame_t *frame, bool binary) {
if (binary) { if (binary) {
uint8_t buffer[8]; uint8_t buffer[8];
buffer[0] = 0x10; // Data Link Escape, signaling binary data forthcoming buffer[0] = 0x10; // Data Link Escape, signaling binary data forthcoming
@@ -1138,7 +1137,7 @@ uint8_t AVCLAN_parseframe(const uint8_t *bytes, uint8_t len,
goto handle_err; goto handle_err;
} }
if (0) { if (false) {
handle_err:; handle_err:;
RS232_Print("ERR(parse): "); RS232_Print("ERR(parse): ");
switch (err.errno) { switch (err.errno) {
+2 -2
View File
@@ -195,7 +195,7 @@ typedef struct RFrame_struct {
} RFrame_t; } RFrame_t;
void AVCLAN_init(); void AVCLAN_init();
void AVCLAN_muteDevice(uint8_t mute); void AVCLAN_muteDevice(bool mute);
uint8_t AVCLAN_readframe(AVCLAN_frame_t *frame, log_t print); uint8_t AVCLAN_readframe(AVCLAN_frame_t *frame, log_t print);
response_t AVCLAN_handleframe(const AVCLAN_frame_t *in, AVCLAN_frame_t *out); response_t AVCLAN_handleframe(const AVCLAN_frame_t *in, AVCLAN_frame_t *out);
@@ -207,7 +207,7 @@ uint8_t AVCLAN_parseframe(const uint8_t *bytes, uint8_t len,
AVCLAN_frame_t *AVCLAN_getStatusFrame(); AVCLAN_frame_t *AVCLAN_getStatusFrame();
void AVCLAN_generateStatus(AVCLAN_frame_t *status); void AVCLAN_generateStatus(AVCLAN_frame_t *status);
uint8_t AVCLAN_isPlaying(); bool AVCLAN_isPlaying();
void AVCLAN_incrementTime(); void AVCLAN_incrementTime();
void AVCLAN_setTime(uint8_t mins, uint8_t secs); void AVCLAN_setTime(uint8_t mins, uint8_t secs);
void AVCLAN_normalizeState(); void AVCLAN_normalizeState();
+5 -5
View File
@@ -4,11 +4,11 @@
#include "queue.h" #include "queue.h"
void constructQueue(Queue_t *q, void **slots, void *items, uint8_t itemSize, void constructQueue(Queue_t *q, void **slots, void *items, uint8_t itemSize,
uint8_t len, uint8_t constructFull) { uint8_t len, bool constructFull) {
q->read = 0; q->read = 0;
q->size = len; q->size = len;
q->buf = slots; q->buf = slots;
if (!!constructFull) { if (constructFull) {
q->write = len; q->write = len;
for (uint8_t i = 0; i < len; ++i) { for (uint8_t i = 0; i < len; ++i) {
@@ -21,12 +21,12 @@ void constructQueue(Queue_t *q, void **slots, void *items, uint8_t itemSize,
} }
void constructEmptyQueue(Queue_t *q, void **slots, uint8_t len) { void constructEmptyQueue(Queue_t *q, void **slots, uint8_t len) {
constructQueue(q, slots, nullptr, 0, len, 0); constructQueue(q, slots, nullptr, 0, len, false);
} }
uint8_t isEmpty(const Queue_t *q) { return (q->write == q->read); } bool isEmpty(const Queue_t *q) { return (q->write == q->read); }
static inline uint8_t isFull(const Queue_t *q) { static inline bool isFull(const Queue_t *q) {
return ((q->write - q->read) == q->size); return ((q->write - q->read) == q->size);
} }
+2 -2
View File
@@ -10,9 +10,9 @@ typedef struct Queue_struct {
} Queue_t; } Queue_t;
void constructQueue(Queue_t *q, void **slots, void *items, uint8_t itemSize, void constructQueue(Queue_t *q, void **slots, void *items, uint8_t itemSize,
uint8_t len, uint8_t constructFull); uint8_t len, bool constructFull);
void constructEmptyQueue(Queue_t *q, void **slots, uint8_t len); void constructEmptyQueue(Queue_t *q, void **slots, uint8_t len);
uint8_t isEmpty(const Queue_t *q); bool isEmpty(const Queue_t *q);
static inline void incrementRead(Queue_t *q) { q->read++; } static inline void incrementRead(Queue_t *q) { q->read++; }
uint8_t pushQueue(Queue_t *q, void *x); uint8_t pushQueue(Queue_t *q, void *x);
void *peekQueue(const Queue_t *q); void *peekQueue(const Queue_t *q);
+22 -22
View File
@@ -37,19 +37,19 @@
const char *const offon[] = {"OFF", "ON"}; const char *const offon[] = {"OFF", "ON"};
#define CACHE_SIZE 16 #define CACHE_SIZE 16
_Static_assert((CACHE_SIZE & (CACHE_SIZE - 1)) == 0, static_assert((CACHE_SIZE & (CACHE_SIZE - 1)) == 0,
"CACHE_SIZE must be a power of two (qMask depends on it)"); "CACHE_SIZE must be a power of two (qMask depends on it)");
AVCLAN_frame_t frames[CACHE_SIZE]; static AVCLAN_frame_t frames[CACHE_SIZE];
RFrame_t responses[CACHE_SIZE]; static RFrame_t responses[CACHE_SIZE];
uint8_t framesdata[CACHE_SIZE][MAXMSGLEN]; static uint8_t framesdata[CACHE_SIZE][MAXMSGLEN];
void *cacheSlots[CACHE_SIZE]; static void *cacheSlots[CACHE_SIZE];
void *rcacheSlots[CACHE_SIZE]; static void *rcacheSlots[CACHE_SIZE];
void *incomingSlots[CACHE_SIZE]; static void *incomingSlots[CACHE_SIZE];
void *outgoingSlots[CACHE_SIZE]; static void *outgoingSlots[CACHE_SIZE];
Queue_t cache, rcache, incoming, outgoing; static Queue_t cache, rcache, incoming, outgoing;
volatile uint8_t enqueueStatus = 0; volatile uint8_t enqueueStatus = 0;
@@ -75,14 +75,14 @@ static uint8_t push_or_return_resp(RFrame_t *resp) {
return err; return err;
} }
static void toggle_flag(uint8_t *flag, const char *msg) { static void toggle_flag(bool *flag, const char *msg) {
*flag ^= 1; *flag = !*flag;
RS232_Print(msg); RS232_Print(msg);
RS232_Print(offon[*flag]); RS232_Print(offon[*flag]);
RS232_Print("\n"); RS232_Print("\n");
} }
static void set_flag(uint8_t *flag, uint8_t val, const char *msg) { static void set_flag(bool *flag, bool val, const char *msg) {
*flag = val; *flag = val;
RS232_Print(msg); RS232_Print(msg);
RS232_Print(offon[val]); RS232_Print(offon[val]);
@@ -95,14 +95,14 @@ int main() {
uint8_t hexDigit = 0; // current digit being written to hexChars uint8_t hexDigit = 0; // current digit being written to hexChars
bool seqIsUnicast = false; bool seqIsUnicast = false;
uint8_t lastPrintAllFrames = 1; bool lastPrintAllFrames = 1;
uint8_t verbose = 1; bool verbose = 1;
uint8_t printAllFrames = 1; bool printAllFrames = 1;
uint8_t printBinary = 0; bool printBinary = 0;
uint8_t echoCharacters = 1; bool echoCharacters = 1;
uint8_t readBinary = 0; bool readBinary = 0;
uint8_t muteBus = 0; bool muteBus = 0;
// Binary-mode REPL includes the full wire preamble (broadcast + 2*addr + // Binary-mode REPL includes the full wire preamble (broadcast + 2*addr +
// control + length), so size for the worst case. // control + length), so size for the worst case.
@@ -117,17 +117,17 @@ int main() {
} }
constructQueue(&cache, cacheSlots, frames, sizeof(AVCLAN_frame_t), CACHE_SIZE, constructQueue(&cache, cacheSlots, frames, sizeof(AVCLAN_frame_t), CACHE_SIZE,
1); true);
constructEmptyQueue(&incoming, incomingSlots, CACHE_SIZE); constructEmptyQueue(&incoming, incomingSlots, CACHE_SIZE);
constructQueue(&rcache, rcacheSlots, responses, sizeof(RFrame_t), CACHE_SIZE, constructQueue(&rcache, rcacheSlots, responses, sizeof(RFrame_t), CACHE_SIZE,
1); true);
constructEmptyQueue(&outgoing, outgoingSlots, CACHE_SIZE); constructEmptyQueue(&outgoing, outgoingSlots, CACHE_SIZE);
Setup(); Setup();
print_help(); print_help();
while (1) { while (true) {
if (!BUS_IS_IDLE) { if (!BUS_IS_IDLE) {
if (AVCLAN_frame_t *msg = popQueue(&cache)) { if (AVCLAN_frame_t *msg = popQueue(&cache)) {