| 
									
										
										
										
											2021-12-23 11:42:47 +05:30
										 |  |  | /*
 | 
					
						
							|  |  |  |  * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: Apache-2.0 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | #include <stdint.h>
 | 
					
						
							|  |  |  | #include <stddef.h>
 | 
					
						
							|  |  |  | #include <stdlib.h>
 | 
					
						
							|  |  |  | #include "esp_err.h"
 | 
					
						
							|  |  |  | #include "ulp_common.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | extern "C" { | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-28 12:05:48 +08:00
										 |  |  | typedef enum { | 
					
						
							|  |  |  |     ULP_RISCV_WAKEUP_SOURCE_TIMER, | 
					
						
							|  |  |  |     ULP_RISCV_WAKEUP_SOURCE_GPIO, | 
					
						
							|  |  |  | } ulp_riscv_wakeup_source_t; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-11 15:52:09 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * @brief ULP riscv init parameters | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2022-02-28 12:05:48 +08:00
										 |  |  | typedef struct { | 
					
						
							| 
									
										
										
										
											2022-05-11 15:52:09 +08:00
										 |  |  |     ulp_riscv_wakeup_source_t wakeup_source; /*!< ULP wakeup source */ | 
					
						
							| 
									
										
										
										
											2022-02-28 12:05:48 +08:00
										 |  |  | } ulp_riscv_cfg_t; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define ULP_RISCV_DEFAULT_CONFIG()                      \
 | 
					
						
							|  |  |  |     {                                                   \ | 
					
						
							|  |  |  |         .wakeup_source = ULP_RISCV_WAKEUP_SOURCE_TIMER, \ | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-23 11:42:47 +05:30
										 |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2022-02-28 12:05:48 +08:00
										 |  |  |  * @brief Configure the ULP and run the program loaded into RTC memory | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @param cfg pointer to the config struct | 
					
						
							|  |  |  |  * @return  ESP_OK on success | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | esp_err_t ulp_riscv_config_and_run(ulp_riscv_cfg_t* cfg); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * @brief Configure the ULP with default settings | 
					
						
							|  |  |  |  *        and run the program loaded into RTC memory | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-12-23 11:42:47 +05:30
										 |  |  |  * @return  ESP_OK on success | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | esp_err_t ulp_riscv_run(void); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * @brief Load ULP-RISC-V program binary into RTC memory | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Different than ULP FSM, the binary program has no special format, it is the ELF | 
					
						
							|  |  |  |  * file generated by RISC-V toolchain converted to binary format using objcopy. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2022-01-21 14:43:48 +05:30
										 |  |  |  * Linker script in components/ulp/ld/ulp_riscv.ld produces ELF files which | 
					
						
							| 
									
										
										
										
											2021-12-23 11:42:47 +05:30
										 |  |  |  * correspond to this format. This linker script produces binaries with load_addr == 0. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @param program_binary pointer to program binary | 
					
						
							|  |  |  |  * @param program_size_bytes size of the program binary | 
					
						
							|  |  |  |  * @return | 
					
						
							|  |  |  |  *      - ESP_OK on success | 
					
						
							|  |  |  |  *      - ESP_ERR_INVALID_SIZE if program_size_bytes is more than 8KiB | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | esp_err_t ulp_riscv_load_binary(const uint8_t* program_binary, size_t program_size_bytes); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-19 10:57:31 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * @brief Stop the ULP timer | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @note This will stop the ULP from waking up if halted, but will not abort any program | 
					
						
							|  |  |  |  *       currently executing on the ULP. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | void ulp_riscv_timer_stop(void); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * @brief Resumes the ULP timer | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @note This will resume an already configured timer, but does no other configuration | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | void ulp_riscv_timer_resume(void); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * @brief Halts the program currently running on the ULP-RISC-V | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @note  Program will restart at the next ULP timer trigger if timer is still running. | 
					
						
							|  |  |  |  *        If you want to stop the ULP from waking up then call ulp_riscv_timer_stop() first. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | void ulp_riscv_halt(void); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-23 11:42:47 +05:30
										 |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 |