~toykeeper/flashlight-firmware/fsm

« back to all changes in this revision

Viewing changes to ToyKeeper/spaghetti-monster/fsm-wdt.c

  • Committer: Selene ToyKeeper
  • Date: 2023-11-02 17:05:02 UTC
  • mfrom: (483.12.159 multi-channel)
  • mto: This revision was merged to the branch mainline in revision 491.
  • Revision ID: bzr@toykeeper.net-20231102170502-sinkm18qjxlorsxa
merged multi-channel branch with a major refactor and half a year of updates

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * fsm-wdt.c: WDT (Watch Dog Timer) functions for SpaghettiMonster.
3
 
 *
4
 
 * Copyright (C) 2017 Selene Scriven
5
 
 *
6
 
 * This program is free software: you can redistribute it and/or modify
7
 
 * it under the terms of the GNU General Public License as published by
8
 
 * the Free Software Foundation, either version 3 of the License, or
9
 
 * (at your option) any later version.
10
 
 *
11
 
 * This program is distributed in the hope that it will be useful,
12
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 * GNU General Public License for more details.
15
 
 *
16
 
 * You should have received a copy of the GNU General Public License
17
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 
 */
 
1
// fsm-wdt.c: WDT (Watch Dog Timer) functions for SpaghettiMonster.
 
2
// Copyright (C) 2017-2023 Selene ToyKeeper
 
3
// SPDX-License-Identifier: GPL-3.0-or-later
19
4
 
20
 
#ifndef FSM_WDT_C
21
 
#define FSM_WDT_C
 
5
#pragma once
22
6
 
23
7
#include <avr/interrupt.h>
24
8
#include <avr/wdt.h>
138
122
        #ifndef USE_SLEEP_LVP
139
123
        return;  // no sleep LVP needed if nothing drains power while off
140
124
        #else
141
 
        // stop here, usually...  but proceed often enough for sleep LVP to work
142
 
        if (0 != (ticks_since_last & 0x3f)) return;
 
125
        // stop here, usually...  except during the first few seconds asleep, 
 
126
        // and once in a while afterward for sleep LVP
 
127
        if ((ticks_since_last > (8 * SLEEP_TICKS_PER_SECOND))
 
128
            && (0 != (ticks_since_last & 0x0f))) return;
143
129
 
144
130
        adc_trigger = 0;  // make sure a measurement will happen
 
131
        adc_active_now = 1;  // use ADC noise reduction sleep mode
145
132
        ADC_on();  // enable ADC voltage measurement functions temporarily
146
133
        #endif
147
134
    }
208
195
    #endif
209
196
}
210
197
 
211
 
#endif