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.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. serialInit(0, BAUD(38400, F_CPU));
  68. #endif
  69. #ifdef __AVR__
  70. sei(); // Enable interrupts (required for timer)
  71. #ifdef ENABLE_WATCHDOG
  72. //wdt_enable(WDTO_250MS); // Trigger Watchdog after 250ms
  73. wdt_enable(WDTO_2S); // Trigger Watchdog after 2s
  74. #endif
  75. #endif
  76. //debugWrite("RX reset.\n");
  77. spiInit();
  78. rxInit();
  79. //debugWrite("RX ready!\n");
  80. for(;;) {
  81. #ifdef __AVR__
  82. wdt_reset();
  83. #endif
  84. rxReceivePacket();
  85. #ifdef DEBUG_UART_MENU
  86. uartMenu();
  87. #endif
  88. }
  89. }