1 /* 2 * Copyright (c) 2021 HPMicro 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 */ 7 8 #ifndef HPM_BPOR_DRV_H 9 #define HPM_BPOR_DRV_H 10 11 #include "hpm_common.h" 12 #include "hpm_bpor_regs.h" 13 14 /** 15 * 16 * @brief BPOR driver APIs 17 * @defgroup bpor_interface BPOR driver APIs 18 * @ingroup io_interfaces 19 * @{ 20 * 21 */ 22 23 /** @brief Define BPOR power on cause */ 24 typedef enum { 25 bpor_power_on_cause_wbutn = 0, 26 bpor_power_on_cause_safety_violation = 1, 27 bpor_power_on_cause_rtc_0 = 2, 28 bpor_power_on_cause_rtc_1 = 3, 29 bpor_power_on_cause_gpio = 4 30 } bpor_power_on_cause_t; 31 32 33 #ifdef __cplusplus 34 extern "C" { 35 #endif 36 37 /** 38 * @brief Get power on cause 39 * 40 * @param[in] ptr BPOR base address 41 * @retval POR_CAUSE register value 42 */ bpor_get_power_on_cause(BPOR_Type * ptr)43static inline uint32_t bpor_get_power_on_cause(BPOR_Type *ptr) 44 { 45 return ptr->POR_CAUSE; 46 } 47 48 /** 49 * @brief Select power on cause 50 * 51 * @param[in] ptr BPOR base address 52 * @param[in] cause bpor_power_on_cause_t 53 */ bpor_select_power_on_cause(BPOR_Type * ptr,bpor_power_on_cause_t cause)54static inline void bpor_select_power_on_cause(BPOR_Type *ptr, bpor_power_on_cause_t cause) 55 { 56 ptr->POR_SELECT |= 1 << cause; 57 } 58 59 /** 60 * @brief Enable register value retention when power down occurs 61 * 62 * @param[in] ptr BPOR base address 63 */ bpor_enable_reg_value_retention(BPOR_Type * ptr)64static inline void bpor_enable_reg_value_retention(BPOR_Type *ptr) 65 { 66 ptr->POR_CONFIG |= BPOR_POR_CONFIG_RETENTION_MASK; 67 } 68 69 /** 70 * @brief Disable register value retention when power down occurs 71 * 72 * @param[in] ptr BPOR base address 73 */ bpor_disable_reg_value_retention(BPOR_Type * ptr)74static inline void bpor_disable_reg_value_retention(BPOR_Type *ptr) 75 { 76 ptr->POR_CONFIG &= ~BPOR_POR_CONFIG_RETENTION_MASK; 77 } 78 79 /** 80 * @brief Set power down counter 81 * 82 * @param[in] ptr BPOR base address 83 * @param[in] counter counter value 84 */ bpor_set_power_down_counter(BPOR_Type * ptr,uint16_t counter)85static inline void bpor_set_power_down_counter(BPOR_Type *ptr, uint16_t counter) 86 { 87 ptr->POR_CONTROL = BPOR_POR_CONTROL_COUNTER_SET(counter); 88 } 89 90 #ifdef __cplusplus 91 } 92 #endif 93 /** 94 * @} 95 */ 96 #endif /* HPM_BPOR_DRV_H */ 97