blob: 124dead1c0201565298b191392c342da15470114 (
plain)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
/*
* Funcgen firmware
* Utility functions
*
* Copyright (C) 2007 Michael Buesch <m@bues.ch>
*
* 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.
*/
#include "util.h"
#include "calibration.h"
#include "main.h"
#include "lcd.h"
#include <avr/io.h>
void mdelay(uint16_t msecs)
{
uint8_t timer, i;
TCCR0 = DELAY_1MS_TIMERFREQ;
do {
/* Delay one millisecond */
for (i = DELAY_1MS_LOOP_TIMES; i; i--) {
TCNT0 = 0;
do {
timer = TCNT0;
} while (timer < DELAY_1MS_LOOP);
}
} while (--msecs);
TCCR0 = 0;
}
void udelay(uint16_t usecs)
{
uint8_t tmp;
__asm__ __volatile__(
"1: \n"
" ldi %1, %2 \n"
"2: \n"
" dec %1 \n"
" brne 2b \n"
" dec %A3 \n"
" brne 1b \n"
" cp %B3, __zero_reg__ \n"
" breq 3f \n"
" dec %B3 \n"
" ldi %A3, 0xFF \n"
" rjmp 1b \n"
"3: \n"
: "=d" (usecs),
"=d" (tmp)
: "M" (DELAY_1US_LOOP),
"0" (usecs)
);
}
void panic(const char PROGPTR *msg)
{
emergency_shutdown();
lcd_clear_buffer();
lcd_put_str("Whee! PANIC :(");
lcd_cursor(1, 0);
lcd_put_pstr(msg);
lcd_commit();
while (1)
__asm__ __volatile__("sleep" : : );
}
|