lp_core.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include "sdkconfig.h"
  7. #include "esp_log.h"
  8. #include "soc/pmu_reg.h"
  9. #include "soc/lpperi_reg.h"
  10. #include "hal/misc.h"
  11. #include "ulp_common.h"
  12. #include "ulp_lp_core.h"
  13. const static char* TAG = "ulp-lp-core";
  14. esp_err_t ulp_lp_core_run(ulp_lp_core_cfg_t* cfg)
  15. {
  16. REG_SET_FIELD(PMU_LP_CPU_PWR1_REG, PMU_LP_CPU_WAKEUP_EN, 1);
  17. switch(cfg->wakeup_source) {
  18. case ULP_LP_CORE_WAKEUP_SOURCE_HP_CPU:
  19. REG_SET_FIELD(PMU_HP_LP_CPU_COMM_REG, PMU_HP_TRIGGER_LP, 1);
  20. break;
  21. default:
  22. ESP_LOGE(TAG, "No valid wakeup source specified");
  23. break;
  24. }
  25. return ESP_OK;
  26. }
  27. esp_err_t ulp_lp_core_load_binary(const uint8_t* program_binary, size_t program_size_bytes)
  28. {
  29. if (program_binary == NULL) {
  30. return ESP_ERR_INVALID_ARG;
  31. }
  32. if (program_size_bytes > CONFIG_ULP_COPROC_RESERVE_MEM) {
  33. return ESP_ERR_INVALID_SIZE;
  34. }
  35. uint8_t* base = (uint8_t*) RTC_SLOW_MEM;
  36. //Start by clearing memory reserved with zeros, this will also will initialize the bss:
  37. hal_memset(base, 0, CONFIG_ULP_COPROC_RESERVE_MEM);
  38. hal_memcpy(base, program_binary, program_size_bytes);
  39. return ESP_OK;
  40. }