123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- /*
- * main() method
- */
-
- #ifndef DEBUG
- // Only use without Arduino Bootloader!
- #define ENABLE_WATCHDOG
- #endif
-
- #ifdef __AVR__
- #include <avr/interrupt.h>
- #include <avr/wdt.h>
- #endif
-
- #include "spi.h"
- #include "timer.h"
- #include "cppm.h"
- #include "rx.h"
- #include "main.h"
-
- #ifdef __AVR__
- #ifdef ENABLE_WATCHDOG
- void watchdogBoot(void) __attribute__((naked)) __attribute__((section(".init3")));
- void watchdogBoot(void) {
- MCUSR = 0;
- wdt_disable();
- }
- #endif
- #endif
-
- #ifdef DEBUG_UART_MENU
- void uartMenu(void) {
- if (!serialHasChar(0)) {
- return;
- }
-
- uint8_t c = serialGet(0);
- time_t time = timerGet();
- switch (c) {
- case 't': case 'T':
- debugWrite("Uptime: ");
- debugUnsigned64(time);
- debugWrite("us / ");
- debugUnsigned64(time / 1000000);
- debugWrite("s\n");
- break;
-
- #ifdef ENABLE_WATCHDOG
- case 'q': case 'Q':
- debugWrite("Resetting...\n\n");
- wdt_enable(WDTO_2S);
- for (;;) { }
- break;
- #endif
-
- default:
- debugWrite("Unknown command: '");
- debugChar(c);
- debugWrite("'\n");
-
- case 'h': case 'H': case '?':
- debugWrite("Available commands:\n");
- debugWrite(" h - Help\n");
- debugWrite(" t - Time\n");
- #ifdef ENABLE_WATCHDOG
- debugWrite(" q - Reset\n");
- #endif
- break;
- }
- }
- #endif
-
- void main(void) {
- //cppmInit();
- timerInit();
-
- #ifdef DEBUG
- serialInit(0, BAUD(38400, F_CPU));
- #endif
-
- #ifdef __AVR__
- sei(); // Enable interrupts (required for timer)
-
- #ifdef ENABLE_WATCHDOG
- //wdt_enable(WDTO_250MS); // Trigger Watchdog after 250ms
- wdt_enable(WDTO_2S); // Trigger Watchdog after 2s
- #endif
- #endif
-
- //debugWrite("RX reset.\n");
-
- spiInit();
- rxInit();
-
- //debugWrite("RX ready!\n");
-
- for(;;) {
- #ifdef __AVR__
- wdt_reset();
- #endif
-
- rxReceivePacket();
-
- #ifdef DEBUG_UART_MENU
- uartMenu();
- #endif
- }
- }
|