ulp_riscv.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include <stdint.h>
  8. #include <stddef.h>
  9. #include <stdlib.h>
  10. #include "esp_err.h"
  11. #include "ulp_common.h"
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. typedef enum {
  16. ULP_RISCV_WAKEUP_SOURCE_TIMER,
  17. ULP_RISCV_WAKEUP_SOURCE_GPIO,
  18. } ulp_riscv_wakeup_source_t;
  19. typedef struct {
  20. ulp_riscv_wakeup_source_t wakeup_source;
  21. } ulp_riscv_cfg_t;
  22. #define ULP_RISCV_DEFAULT_CONFIG() \
  23. { \
  24. .wakeup_source = ULP_RISCV_WAKEUP_SOURCE_TIMER, \
  25. }
  26. /**
  27. * @brief Configure the ULP and run the program loaded into RTC memory
  28. *
  29. * @param cfg pointer to the config struct
  30. * @return ESP_OK on success
  31. */
  32. esp_err_t ulp_riscv_config_and_run(ulp_riscv_cfg_t* cfg);
  33. /**
  34. * @brief Configure the ULP with default settings
  35. * and run the program loaded into RTC memory
  36. *
  37. * @return ESP_OK on success
  38. */
  39. esp_err_t ulp_riscv_run(void);
  40. /**
  41. * @brief Load ULP-RISC-V program binary into RTC memory
  42. *
  43. * Different than ULP FSM, the binary program has no special format, it is the ELF
  44. * file generated by RISC-V toolchain converted to binary format using objcopy.
  45. *
  46. * Linker script in components/ulp/ld/ulp_riscv.ld produces ELF files which
  47. * correspond to this format. This linker script produces binaries with load_addr == 0.
  48. *
  49. * @param program_binary pointer to program binary
  50. * @param program_size_bytes size of the program binary
  51. * @return
  52. * - ESP_OK on success
  53. * - ESP_ERR_INVALID_SIZE if program_size_bytes is more than 8KiB
  54. */
  55. esp_err_t ulp_riscv_load_binary(const uint8_t* program_binary, size_t program_size_bytes);
  56. /**
  57. * @brief Stop the ULP timer
  58. *
  59. * @note This will stop the ULP from waking up if halted, but will not abort any program
  60. * currently executing on the ULP.
  61. */
  62. void ulp_riscv_timer_stop(void);
  63. /**
  64. * @brief Resumes the ULP timer
  65. *
  66. * @note This will resume an already configured timer, but does no other configuration
  67. *
  68. */
  69. void ulp_riscv_timer_resume(void);
  70. /**
  71. * @brief Halts the program currently running on the ULP-RISC-V
  72. *
  73. * @note Program will restart at the next ULP timer trigger if timer is still running.
  74. * If you want to stop the ULP from waking up then call ulp_riscv_timer_stop() first.
  75. */
  76. void ulp_riscv_halt(void);
  77. #ifdef __cplusplus
  78. }
  79. #endif