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:
+14
-7
@@ -1,7 +1,8 @@
|
||||
|
||||
#include "interrupts.h"
|
||||
|
||||
void init_pins(void) {
|
||||
void init_pins(void)
|
||||
{
|
||||
|
||||
// The reed switch (PD3/INT1) switches to ground and the RTC alarm output
|
||||
// (PD2/INT0) is open-drain, so both need the internal pull-up. Leaving them
|
||||
@@ -19,27 +20,32 @@ void init_pins(void) {
|
||||
// asynchronous. Each handler masks its own interrupt while the source is still
|
||||
// asserted, so the low level does not retrigger in a loop.
|
||||
|
||||
void set_up_reed_interrupt(void) {
|
||||
void set_up_reed_interrupt(void)
|
||||
{
|
||||
EICRA &= ~((1 << ISC11) | (1 << ISC10));
|
||||
EIMSK |= (1 << INT1);
|
||||
}
|
||||
|
||||
void set_up_minute_interrupt(void) {
|
||||
void set_up_minute_interrupt(void)
|
||||
{
|
||||
EICRA &= ~((1 << ISC01) | (1 << ISC00));
|
||||
EIMSK |= (1 << INT0);
|
||||
}
|
||||
|
||||
void reed_interrupt_enable(void) {
|
||||
void reed_interrupt_enable(void)
|
||||
{
|
||||
EIFR = (1 << INTF1); // Drop anything latched while we were masked
|
||||
EIMSK |= (1 << INT1);
|
||||
}
|
||||
|
||||
void minute_interrupt_enable(void) {
|
||||
void minute_interrupt_enable(void)
|
||||
{
|
||||
EIFR = (1 << INTF0);
|
||||
EIMSK |= (1 << INT0);
|
||||
}
|
||||
|
||||
void wdt_isr_enable(void) {
|
||||
void wdt_isr_enable(void)
|
||||
{
|
||||
uint8_t sreg = SREG;
|
||||
cli();
|
||||
wdt_reset();
|
||||
@@ -57,7 +63,8 @@ void wdt_isr_enable(void) {
|
||||
SREG = sreg; // Restore, never blanket-sei(): these run inside an ISR
|
||||
}
|
||||
|
||||
void wdt_isr_disable(void) {
|
||||
void wdt_isr_disable(void)
|
||||
{
|
||||
uint8_t sreg = SREG;
|
||||
cli();
|
||||
wdt_reset();
|
||||
|
||||
Reference in New Issue
Block a user