Naze32 clone with Frysky receiver
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

main.c 1.8KB

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