bbdcc1e623
- 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
117 lines
2.7 KiB
C
117 lines
2.7 KiB
C
/*
|
|
* File: defines.h
|
|
* Author: thebears
|
|
*
|
|
* Created on December 18, 2024, 11:41 AM
|
|
*/
|
|
|
|
#ifndef DEFINES_H
|
|
#define DEFINES_H
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#include "stdint.h"
|
|
|
|
#include <stdbool.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
|
|
|
|
// 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];
|
|
|
|
typedef struct {
|
|
uint8_t payload_len;
|
|
char payload[48];
|
|
uint8_t success;
|
|
} ndef_message;
|
|
extern ndef_message NDEF_MSG;
|
|
|
|
typedef struct {
|
|
char str[21]; // Pointer to the modified string
|
|
size_t length; // Length of the modified string
|
|
} trimmed_string_struct;
|
|
extern trimmed_string_struct TRIMMED_STRING;
|
|
|
|
typedef struct {
|
|
uint8_t name_len;
|
|
char name_str[16];
|
|
char diameter_str[16];
|
|
uint8_t diameter_len;
|
|
uint8_t hashed;
|
|
} identifier_results;
|
|
extern identifier_results IDENTIFIER;
|
|
|
|
typedef struct {
|
|
uint8_t len;
|
|
uint8_t to;
|
|
uint8_t from;
|
|
uint8_t dtype;
|
|
uint8_t flags;
|
|
unsigned char msg[60];
|
|
} tx_rx_data_struct;
|
|
extern tx_rx_data_struct TX_DATA;
|
|
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)
|
|
} 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,
|
|
MSG_TYPE_BINARY = 2 } MSG_DATA_TYPE;
|
|
|
|
typedef enum // Goes into flags
|
|
{ MSG_REQ_CTIME = 1,
|
|
MSG_RESP_CTIME = 2,
|
|
MSG_SEND_COUNTS = 31,
|
|
MSG_RECV_COUNTS_SUCCESS = 32,
|
|
MSG_RECV_COUNTS_FAIL = 33,
|
|
MSG_RESENT_COUNTS = 34 } MSG_REQUEST_TYPE_FLAG;
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* DEFINES_H */
|