max80.ino 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. // Configure USB power control
  25. pinMode(7, OUTPUT); // USB_PWR_EN
  26. digitalWrite(7, 1); // Disable power sourcing
  27. pinMode(8, OUTPUT); // USB_PWR_SINK
  28. digitalWrite(8, 0); // This is a power sink
  29. // Configure LEDs
  30. led_init();
  31. led_set(LED_BLUE, LED_FLASH); // ESP32 software initializing
  32. // Enable external PSRAM for heap
  33. heap_caps_malloc_extmem_enable(2048); // >= 2K allocations in PSRAM
  34. }
  35. void setup() {
  36. printf("[START] MAX80 firmware compiled on " __DATE__ " " __TIME__ "\n");
  37. init_hw();
  38. init_config();
  39. SetupWiFi();
  40. //fpga_services_start();
  41. printf("[RDY]\n");
  42. dump_config();
  43. led_set(LED_BLUE, LED_ON); // Software ready
  44. printf("Total heap: %d\n"
  45. "Free heap: %d\n"
  46. "Total PSRAM: %d\n"
  47. "Free PSRAM: %d\n",
  48. ESP.getHeapSize(), ESP.getFreeHeap(),
  49. ESP.getPsramSize(), ESP.getFreePsram());
  50. }
  51. static inline char task_state(eTaskState state)
  52. {
  53. switch (state) {
  54. case eInvalid:
  55. return 'X';
  56. case eReady:
  57. case eRunning:
  58. return 'R';
  59. case eBlocked:
  60. return 'D';
  61. case eSuspended:
  62. return 'S';
  63. case eDeleted:
  64. return 'Z';
  65. default:
  66. return '?';
  67. }
  68. }
  69. static void dump_tasks(void)
  70. {
  71. TaskHandle_t task = NULL;
  72. while (1) {
  73. task = pxTaskGetNext(task);
  74. if (!task)
  75. break;
  76. printf("%-16s %c %2u\n",
  77. pcTaskGetName(task),
  78. task_state(eTaskGetState(task)),
  79. uxTaskPriorityGet(task));
  80. }
  81. }
  82. void loop() {
  83. printf("loop task: %s\n", pcTaskGetName(xTaskGetCurrentTaskHandle()));
  84. printf("idle task: %s\n", pcTaskGetName(xTaskGetIdleTaskHandle()));
  85. dump_tasks();
  86. putchar('\n');
  87. vTaskDelay(120 * configTICK_RATE_HZ);
  88. }