Refactor firmware for clarity; no functional changes
- main.c: file-header comment describing the hardware and operation, logic split into named phases (sleep_until_interrupt, wake_peripheral_rails, take_counts_snapshot, send_wheel_counts_report, handle_minute_alarm, init_all_hardware); shared state renamed to say what it is and made static. - rfm69.c: reorganized into six labeled sections; cond_1/2/3 and hash scratch globals replaced by a reply_acknowledges() helper with clear locals; packet layout and every init register write documented. - LOG() macro (compiled out when DO_UART is off) replaces the #if DO_UART blocks that obscured the logic. - Drivers: file-header comments; named RTC_REG_*/RTC_ALM_MASK_BIT constants; EEPROM spool scheme documented; ADC_CHANNEL_BANDGAP named; repeated pin if/else helpers collapsed to SET_PIN_TO(). - Removed unused globals/buffers and commented-out code; ran clang-format with the project style. Register writes and radio protocol are byte-identical. Builds clean under -Wall -Wextra on gnu17 and c23; flash 13028 -> 12830 B, static RAM 1038 -> 999 B. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YVJKatfeMJjAmuH9KYiLuv
This commit is contained in:
+27
-24
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* File: defines.h
|
||||
* Author: thebears
|
||||
*
|
||||
@@ -6,33 +6,43 @@
|
||||
*/
|
||||
|
||||
#ifndef DEFINES_H
|
||||
#define DEFINES_H
|
||||
#define DEFINES_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#include "stdint.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#ifndef F_CPU
|
||||
#define F_CPU 8000000UL // 8 MHz clock speed; prefer -DF_CPU=8000000UL in the build flags
|
||||
#endif
|
||||
#define BAUD 38400
|
||||
#define F_SCL 200000UL
|
||||
|
||||
// Build switches: DO_UART compiles in serial logging, ITERATING is a bench
|
||||
// mode that reports every minute instead of every 15.
|
||||
#define DO_UART true
|
||||
#define ITERATING false
|
||||
|
||||
#define MIN(a,b) (((a)<(b))?(a):(b))
|
||||
#define MAX(a,b) (((a)>(b))?(a):(b))
|
||||
// Serial log line, compiled out entirely when DO_UART is off. The caller's
|
||||
// file must include uart.h (directly or via another driver header).
|
||||
#if DO_UART
|
||||
#define LOG(msg) uart_sendString(msg)
|
||||
#else
|
||||
#define LOG(msg) ((void)0)
|
||||
#endif
|
||||
|
||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
|
||||
// Shared scratch buffers (RAM is tight: 2 KB total). DATA_BUFFER_65 holds one
|
||||
// EEPROM page plus a terminator; DATA_BUFFER_7 holds one RTC time readout.
|
||||
extern unsigned char DATA_BUFFER_65[65];
|
||||
extern uint8_t DATA_BUFFER_7[7];
|
||||
//extern uint8_t DATA_BUFFER_254[255];
|
||||
extern unsigned char DATA_BUFFER_20[20];
|
||||
|
||||
typedef struct {
|
||||
uint8_t payload_len;
|
||||
@@ -56,7 +66,6 @@ typedef struct {
|
||||
} identifier_results;
|
||||
extern identifier_results IDENTIFIER;
|
||||
|
||||
|
||||
typedef struct {
|
||||
uint8_t len;
|
||||
uint8_t to;
|
||||
@@ -71,25 +80,22 @@ extern tx_rx_data_struct RX_DATA;
|
||||
typedef struct {
|
||||
uint8_t Second; // 0-59
|
||||
uint8_t Minute; // 0-59
|
||||
uint8_t Hour; // 0-23
|
||||
uint8_t Wday; // Day of week, 1-7 (1 = Sunday)
|
||||
uint8_t Day; // 1-31
|
||||
uint8_t Month; // 1-12
|
||||
uint8_t Year; // Full year (e.g., 2024)
|
||||
uint8_t Hour; // 0-23
|
||||
uint8_t Wday; // Day of week, 1-7 (1 = Sunday)
|
||||
uint8_t Day; // 1-31
|
||||
uint8_t Month; // 1-12
|
||||
uint8_t Year; // Full year (e.g., 2024)
|
||||
} time_struct;
|
||||
extern time_struct TIME;
|
||||
|
||||
|
||||
typedef enum {
|
||||
RTC_RFM69_SET_TIME_SUCCESS = 1,
|
||||
RTC_RFM69_SET_TIME_FAILED = 2,
|
||||
} RTC_RFM69_STATUS;
|
||||
|
||||
|
||||
typedef enum // Goes into ID
|
||||
{ DATA_SEND_SUCCESS = 1,
|
||||
DATA_NOT_SENT = 2 } DATA_SEND_STATUS;
|
||||
|
||||
|
||||
typedef enum // Goes into ID
|
||||
{ MSG_TYPE_STRING = 1,
|
||||
@@ -101,13 +107,10 @@ typedef enum // Goes into flags
|
||||
MSG_SEND_COUNTS = 31,
|
||||
MSG_RECV_COUNTS_SUCCESS = 32,
|
||||
MSG_RECV_COUNTS_FAIL = 33,
|
||||
MSG_RESENT_COUNTS = 34} MSG_REQUEST_TYPE_FLAG;
|
||||
MSG_RESENT_COUNTS = 34 } MSG_REQUEST_TYPE_FLAG;
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* DEFINES_H */
|
||||
|
||||
#endif /* DEFINES_H */
|
||||
|
||||
Reference in New Issue
Block a user