]> git.zerfleddert.de Git - fnordlicht-mini/blob - firmware/fnordlicht-firmware/fnordlicht.c
f0b011b3f6fe8b4ff30013c66ab8494870a99634
[fnordlicht-mini] / firmware / fnordlicht-firmware / fnordlicht.c
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()) {
45 /* set global address to stored value */
46 global_remote.address = startup_config.startup_addr;
47
48 /* read default mode from storage (do nothing if mode is invalid) */
49 if (startup_config.params.mode == STARTUP_PROGRAM) {
50 /* start program */
51 script_start(0, startup_config.params.program, (union program_params_t *)startup_config.params.program_parameters);
52 }
53 } else {
54 /* start default program */
55 script_start_default();
56
57 #if !CONFIG_SCRIPT
58 /* or set some default color */
59 global_pwm.target.red = 50;
60 #endif
61 }
62 }
63
64 /* NEVER CALL DIRECTLY! */
65 void disable_watchdog(void) \
66 __attribute__((naked)) \
67 __attribute__((section(".init3")));
68 void disable_watchdog(void)
69 {
70 MCUSR = 0;
71 wdt_disable();
72 }
73
74 /** main function
75 */
76 int main(void)
77 {
78 pwm_init();
79 timer_init();
80 uart_init();
81 storage_init();
82 remote_init();
83 script_init();
84
85 /* do high-level startup configuration */
86 startup();
87
88 /* enable interrupts globally */
89 sei();
90
91 while (1)
92 {
93 /* update pwm */
94 pwm_poll();
95
96 /* check for remote commands */
97 remote_poll();
98
99 /* update pwm */
100 pwm_poll();
101
102 /* call scripting */
103 script_poll();
104
105 /* update pwm */
106 pwm_poll();
107
108 /* update fading */
109 pwm_poll_fading();
110
111 /* update pwm */
112 pwm_poll();
113
114 /* process storage requests */
115 storage_poll();
116 }
117 }
Impressum, Datenschutz