~toykeeper/flashlight-firmware/fsm

« back to all changes in this revision

Viewing changes to ToyKeeper/spaghetti-monster/fsm-events.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-events.c: Event-handling 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-events.c: Event-handling functions for SpaghettiMonster.
 
2
// Copyright (C) 2017-2023 Selene ToyKeeper
 
3
// SPDX-License-Identifier: GPL-3.0-or-later
19
4
 
20
 
#ifndef FSM_EVENTS_C
21
 
#define FSM_EVENTS_C
 
5
#pragma once
22
6
 
23
7
#include <util/delay_basic.h>
24
8
 
143
127
        uint8_t level = actual_level;  // volatile, avoid repeat access
144
128
        if (level < QUARTERSPEED_LEVEL) {
145
129
            clock_prescale_set(clock_div_4);
146
 
            _delay_loop_2(BOGOMIPS*90/100/4);
 
130
            _delay_loop_2(BOGOMIPS*DELAY_FACTOR/100/4);
147
131
        }
148
132
        //else if (level < HALFSPEED_LEVEL) {
149
133
        //    clock_prescale_set(clock_div_2);
151
135
        //}
152
136
        else {
153
137
            clock_prescale_set(clock_div_1);
154
 
            _delay_loop_2(BOGOMIPS*90/100);
 
138
            _delay_loop_2(BOGOMIPS*DELAY_FACTOR/100);
155
139
        }
156
140
        // restore regular clock speed
157
141
        clock_prescale_set(clock_div_1);
159
143
        // underclock MCU to save power
160
144
        clock_prescale_set(clock_div_4);
161
145
        // wait
162
 
        _delay_loop_2(BOGOMIPS*90/100/4);
 
146
        _delay_loop_2(BOGOMIPS*DELAY_FACTOR/100/4);
163
147
        // restore regular clock speed
164
148
        clock_prescale_set(clock_div_1);
165
149
        #endif  // ifdef USE_RAMPING
166
150
        #else
167
151
        // wait
168
 
        _delay_loop_2(BOGOMIPS*90/100);
 
152
        _delay_loop_2(BOGOMIPS*DELAY_FACTOR/100);
169
153
        #endif  // ifdef USE_DYNAMIC_UNDERCLOCKING
170
154
 
171
155
        // run pending system processes while we wait
212
196
}
213
197
*/
214
198
 
215
 
#endif