max80.ino 2.2 KB

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