ulp_riscv.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. /**
  20. * @brief ULP riscv init parameters
  21. *
  22. */
  23. typedef struct {
  24. ulp_riscv_wakeup_source_t wakeup_source; /*!< ULP wakeup source */
  25. } ulp_riscv_cfg_t;
  26. #define ULP_RISCV_DEFAULT_CONFIG() \
  27. { \
  28. .wakeup_source = ULP_RISCV_WAKEUP_SOURCE_TIMER, \
  29. }
  30. /**
  31. * @brief Configure the ULP and run the program loaded into RTC memory
  32. *
  33. * @param cfg pointer to the config struct
  34. * @return ESP_OK on success
  35. */
  36. esp_err_t ulp_riscv_config_and_run(ulp_riscv_cfg_t* cfg);
  37. /**
  38. * @brief Configure the ULP with default settings
  39. * and run the program loaded into RTC memory
  40. *
  41. * @return ESP_OK on success
  42. */
  43. esp_err_t ulp_riscv_run(void);
  44. /**
  45. * @brief Load ULP-RISC-V program binary into RTC memory
  46. *
  47. * Different than ULP FSM, the binary program has no special format, it is the ELF
  48. * file generated by RISC-V toolchain converted to binary format using objcopy.
  49. *
  50. * Linker script in components/ulp/ld/ulp_riscv.ld produces ELF files which
  51. * correspond to this format. This linker script produces binaries with load_addr == 0.
  52. *
  53. * @param program_binary pointer to program binary
  54. * @param program_size_bytes size of the program binary
  55. * @return
  56. * - ESP_OK on success
  57. * - ESP_ERR_INVALID_SIZE if program_size_bytes is more than 8KiB
  58. */
  59. esp_err_t ulp_riscv_load_binary(const uint8_t* program_binary, size_t program_size_bytes);
  60. /**
  61. * @brief Stop the ULP timer
  62. *
  63. * @note This will stop the ULP from waking up if halted, but will not abort any program
  64. * currently executing on the ULP.
  65. */
  66. void ulp_riscv_timer_stop(void);
  67. /**
  68. * @brief Resumes the ULP timer
  69. *
  70. * @note This will resume an already configured timer, but does no other configuration
  71. *
  72. */
  73. void ulp_riscv_timer_resume(void);
  74. /**
  75. * @brief Halts the program currently running on the ULP-RISC-V
  76. *
  77. * @note Program will restart at the next ULP timer trigger if timer is still running.
  78. * If you want to stop the ULP from waking up then call ulp_riscv_timer_stop() first.
  79. */
  80. void ulp_riscv_halt(void);
  81. #ifdef __cplusplus
  82. }
  83. #endif