]>
Commit | Line | Data |
---|---|---|
ec1bef8e | 1 | /* vim:ts=4 sts=4 et tw=80 |
2 | * | |
3 | * fnordlicht firmware | |
4 | * | |
5 | * for additional information please | |
6 | * see http://lochraster.org/fnordlichtmini | |
7 | * | |
8 | * (c) by Alexander Neumann <alexander@bumpern.de> | |
9 | * Lars Noschinski <lars@public.noschinski.de> | |
10 | * | |
11 | * This program is free software: you can redistribute it and/or modify it | |
12 | * under the terms of the GNU General Public License version 3 as published by | |
13 | * the Free Software Foundation. | |
14 | * | |
15 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
16 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
17 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
18 | * more details. | |
19 | * | |
20 | * You should have received a copy of the GNU General Public License along with | |
21 | * this program. If not, see <http://www.gnu.org/licenses/>. | |
22 | */ | |
23 | ||
24 | /* includes */ | |
25 | #include "globals.h" | |
26 | #include "../common/io.h" | |
27 | ||
28 | #include <stdint.h> | |
29 | #include <avr/interrupt.h> | |
30 | #include <avr/pgmspace.h> | |
31 | #include <avr/wdt.h> | |
32 | ||
33 | #include "../common/common.h" | |
34 | #include "pwm.h" | |
35 | #include "uart.h" | |
36 | #include "remote.h" | |
37 | #include "timer.h" | |
38 | #include "script.h" | |
39 | #include "storage.h" | |
40 | ||
41 | static void startup(void) | |
42 | { | |
43 | /* if configuration is valid */ | |
44 | if (storage_valid_config()) { | |
937531b6 | 45 | /* set global address to stored value */ |
46 | global_remote.address = startup_config.startup_addr; | |
0c9ba54a | 47 | } |
ec1bef8e | 48 | |
0c9ba54a | 49 | #if CONFIG_SCRIPT |
50 | /* start default program: showcfg FIXME cleanup magic values */ | |
b1fe38e5 | 51 | script_start(0u, 3u, (union program_params_t *)startup_config.params.program_parameters); |
0c9ba54a | 52 | #else |
53 | /* or set some default color */ | |
54 | global_pwm.target.red = 50u; | |
ec1bef8e | 55 | #endif |
ec1bef8e | 56 | } |
57 | ||
58 | /* NEVER CALL DIRECTLY! */ | |
59 | void disable_watchdog(void) \ | |
60 | __attribute__((naked)) \ | |
61 | __attribute__((section(".init3"))); | |
62 | void disable_watchdog(void) | |
63 | { | |
64 | MCUSR = 0; | |
65 | wdt_disable(); | |
66 | } | |
67 | ||
68 | /** main function | |
69 | */ | |
70 | int main(void) | |
71 | { | |
72 | pwm_init(); | |
73 | timer_init(); | |
74 | uart_init(); | |
75 | storage_init(); | |
76 | remote_init(); | |
77 | script_init(); | |
78 | ||
79 | /* do high-level startup configuration */ | |
80 | startup(); | |
81 | ||
82 | /* enable interrupts globally */ | |
83 | sei(); | |
84 | ||
85 | while (1) | |
86 | { | |
87 | /* update pwm */ | |
88 | pwm_poll(); | |
89 | ||
90 | /* check for remote commands */ | |
91 | remote_poll(); | |
92 | ||
93 | /* update pwm */ | |
94 | pwm_poll(); | |
95 | ||
96 | /* call scripting */ | |
97 | script_poll(); | |
98 | ||
99 | /* update pwm */ | |
100 | pwm_poll(); | |
101 | ||
102 | /* update fading */ | |
103 | pwm_poll_fading(); | |
104 | ||
105 | /* update pwm */ | |
106 | pwm_poll(); | |
107 | ||
108 | /* process storage requests */ | |
109 | storage_poll(); | |
110 | } | |
111 | } |