-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbase.h
40 lines (31 loc) · 1.58 KB
/
base.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
Crazy Clock
Copyright 2014 Nicholas W. Sayer
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
// We're going to set up a timer interrupt for every 100 msec, so what's 1/.1?
// Note that while we're actually doing stuff, we *must* insure that we never
// work through an interrupt. This is because we're not *counting* these
// interrupts, we're just waiting for each one in turn.
#define IRQS_PER_SECOND (10)
// You mark time by calling this method. It puts the CPU to sleep until
// the next timer interrupt. It will also do the funky math to adjust
// the interrupt counter to keep them happening at a nominal 10 Hz rate.
void doSleep();
// This method will tick the clock, and then call doSleep(). So in short,
// for the clock to keep proper time, you must call doSleep() 9 times
// for every call to doTick().
void doTick();
// random(); is too slow for a 32 kHz system clock. This one uses no
// higher math - just bit shifts.
unsigned long q_random();