max80.ino 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // #define DEBUG
  2. #define BAUD_RATE 115200
  3. #include "common.h"
  4. #include <freertos/task_snapshot.h>
  5. #include "fpga.h"
  6. #include "wifi.h"
  7. #include "config.h"
  8. #include "led.h"
  9. // On board v1, IO7 is N/C.
  10. // On board v2, IO7 is USB_PWR_EN and has a 36k pulldown.
  11. static int get_board_version()
  12. {
  13. return 2; // For now
  14. }
  15. static void dump_config()
  16. {
  17. printf("--- Configuration:\n");
  18. write_config(stdout);
  19. printf("--- End configuration\n");
  20. }
  21. static void init_hw()
  22. {
  23. // Configure USB power control
  24. pinMode(7, OUTPUT); // USB_PWR_EN
  25. digitalWrite(7, 1); // Disable power sourcing
  26. pinMode(8, OUTPUT); // USB_PWR_SINK
  27. digitalWrite(8, 0); // This is a power sink
  28. // Configure LEDs
  29. led_init();
  30. led_set(LED_BLUE, LED_FLASH); // ESP32 software initializing
  31. }
  32. void setup() {
  33. printf("[START] MAX80 firmware compiled on " __DATE__ " " __TIME__ "\n");
  34. init_hw();
  35. init_config();
  36. SetupWiFi();
  37. //fpga_services_start();
  38. printf("[RDY]\n");
  39. dump_config();
  40. led_set(LED_BLUE, LED_ON); // Software ready
  41. }
  42. static inline char task_state(eTaskState state)
  43. {
  44. switch (state) {
  45. case eInvalid:
  46. return 'X';
  47. case eReady:
  48. case eRunning:
  49. return 'R';
  50. case eBlocked:
  51. return 'D';
  52. case eSuspended:
  53. return 'S';
  54. case eDeleted:
  55. return 'Z';
  56. default:
  57. return '?';
  58. }
  59. }
  60. static void dump_tasks(void)
  61. {
  62. TaskHandle_t task = NULL;
  63. while (1) {
  64. task = pxTaskGetNext(task);
  65. if (!task)
  66. break;
  67. printf("%-16s %c %2u\n",
  68. pcTaskGetName(task),
  69. task_state(eTaskGetState(task)),
  70. uxTaskPriorityGet(task));
  71. }
  72. }
  73. void loop() {
  74. printf("loop task: %s\n", pcTaskGetName(xTaskGetCurrentTaskHandle()));
  75. printf("idle task: %s\n", pcTaskGetName(xTaskGetIdleTaskHandle()));
  76. dump_tasks();
  77. putchar('\n');
  78. vTaskDelay(120 * configTICK_RATE_HZ);
  79. }