Naze32 clone with Frysky receiver
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.c 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * main() method
  3. */
  4. #ifndef DEBUG
  5. // Only use without Arduino Bootloader!
  6. #define ENABLE_WATCHDOG
  7. #endif
  8. #ifdef __AVR__
  9. #include <avr/interrupt.h>
  10. #include <avr/wdt.h>
  11. #endif
  12. #include "spi.h"
  13. #include "timer.h"
  14. #include "cppm.h"
  15. #include "rx.h"
  16. #include "main.h"
  17. #ifdef __AVR__
  18. #ifdef ENABLE_WATCHDOG
  19. void watchdogBoot(void) __attribute__((naked)) __attribute__((section(".init3")));
  20. void watchdogBoot(void) {
  21. MCUSR = 0;
  22. wdt_disable();
  23. }
  24. #endif
  25. #endif
  26. #ifdef DEBUG_UART_MENU
  27. void uartMenu(void) {
  28. if (!serialHasChar(0)) {
  29. return;
  30. }
  31. uint8_t c = serialGet(0);
  32. time_t time = timerGet();
  33. switch (c) {
  34. case 't': case 'T':
  35. debugWrite("Uptime: ");
  36. debugUnsigned64(time);
  37. debugWrite("us / ");
  38. debugUnsigned64(time / 1000000);
  39. debugWrite("s\n");
  40. break;
  41. #ifdef ENABLE_WATCHDOG
  42. case 'q': case 'Q':
  43. debugWrite("Resetting...\n\n");
  44. wdt_enable(WDTO_2S);
  45. for (;;) { }
  46. break;
  47. #endif
  48. default:
  49. debugWrite("Unknown command: '");
  50. debugChar(c);
  51. debugWrite("'\n");
  52. case 'h': case 'H': case '?':
  53. debugWrite("Available commands:\n");
  54. debugWrite(" h - Help\n");
  55. debugWrite(" t - Time\n");
  56. #ifdef ENABLE_WATCHDOG
  57. debugWrite(" q - Reset\n");
  58. #endif
  59. break;
  60. }
  61. }
  62. #endif
  63. void main(void) {
  64. //cppmInit();
  65. timerInit();
  66. #ifdef DEBUG
  67. #if defined(__AVR__)
  68. serialInit(0, BAUD(38400, F_CPU));
  69. #else
  70. serialInit(0, BAUD(230400, F_CPU));
  71. #endif
  72. #endif
  73. #ifdef __AVR__
  74. sei(); // Enable interrupts (required for timer)
  75. #ifdef ENABLE_WATCHDOG
  76. //wdt_enable(WDTO_250MS); // Trigger Watchdog after 250ms
  77. wdt_enable(WDTO_2S); // Trigger Watchdog after 2s
  78. #endif
  79. #endif
  80. //debugWrite("RX reset.\n");
  81. spiInit();
  82. rxInit();
  83. //debugWrite("RX ready!\n");
  84. for(;;) {
  85. #ifdef __AVR__
  86. wdt_reset();
  87. #endif
  88. rxReceivePacket();
  89. #ifdef DEBUG_UART_MENU
  90. uartMenu();
  91. #endif
  92. }
  93. }