monitor.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. This example code is in the Public Domain (or CC0 licensed, at your option.)
  3. Unless required by applicable law or agreed to in writing, this
  4. software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  5. CONDITIONS OF ANY KIND, either express or implied.
  6. */
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <unistd.h>
  10. #include <string.h>
  11. #include "freertos/FreeRTOS.h"
  12. #include "freertos/timers.h"
  13. #include "esp_system.h"
  14. #include "esp_log.h"
  15. #include "monitor.h"
  16. #define MONITOR_TIMER (10*1000)
  17. static const char TAG[] = "monitor";
  18. static TimerHandle_t monitor_timer;
  19. /****************************************************************************************
  20. *
  21. */
  22. static void monitor_callback(TimerHandle_t xTimer) {
  23. ESP_LOGI(TAG, "Heap internal:%zu (min:%zu) external:%zu (min:%zu)",
  24. heap_caps_get_free_size(MALLOC_CAP_INTERNAL),
  25. heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL),
  26. heap_caps_get_free_size(MALLOC_CAP_SPIRAM),
  27. heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM));
  28. }
  29. /****************************************************************************************
  30. *
  31. */
  32. void monitor_svc_init(void) {
  33. ESP_LOGI(TAG, "Initializing monitoring");
  34. monitor_timer = xTimerCreate("monitor", MONITOR_TIMER / portTICK_RATE_MS, pdTRUE, NULL, monitor_callback);
  35. xTimerStart(monitor_timer, portMAX_DELAY);
  36. }