]>
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()) { | |
d134ebec | 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 */ | |
51 | script_start(0u, 4u, (union program_params_t *)startup_config.params.program_parameters); | |
52 | #else | |
53 | /* or set some default color */ | |
54 | global_pwm.target.red = 50u; | |
ec1bef8e | 55 | #endif |
56 | } | |
57 | } | |
58 | ||
59 | /* NEVER CALL DIRECTLY! */ | |
60 | void disable_watchdog(void) \ | |
61 | __attribute__((naked)) \ | |
62 | __attribute__((section(".init3"))); | |
63 | void disable_watchdog(void) | |
64 | { | |
65 | MCUSR = 0; | |
66 | wdt_disable(); | |
67 | } | |
68 | ||
69 | /** main function | |
70 | */ | |
71 | int main(void) | |
72 | { | |
73 | pwm_init(); | |
74 | timer_init(); | |
75 | uart_init(); | |
76 | storage_init(); | |
77 | remote_init(); | |
78 | script_init(); | |
79 | ||
80 | /* do high-level startup configuration */ | |
81 | startup(); | |
82 | ||
83 | /* enable interrupts globally */ | |
84 | sei(); | |
85 | ||
86 | while (1) | |
87 | { | |
88 | /* update pwm */ | |
89 | pwm_poll(); | |
90 | ||
91 | /* check for remote commands */ | |
92 | remote_poll(); | |
93 | ||
94 | /* update pwm */ | |
95 | pwm_poll(); | |
96 | ||
97 | /* call scripting */ | |
98 | script_poll(); | |
99 | ||
100 | /* update pwm */ | |
101 | pwm_poll(); | |
102 | ||
103 | /* update fading */ | |
104 | pwm_poll_fading(); | |
105 | ||
106 | /* update pwm */ | |
107 | pwm_poll(); | |
108 | ||
109 | /* process storage requests */ | |
110 | storage_poll(); | |
111 | } | |
112 | } |