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