1 /** 2 ********************************************************************************* 3 * 4 * @file ald_bkpc.h 5 * @brief Header file of BKPC module driver. 6 * 7 * @version V1.0 8 * @date 15 Dec 2017 9 * @author AE Team 10 * @note 11 * 12 * Copyright (C) Shanghai Eastsoft Microelectronics Co. Ltd. All rights reserved. 13 * 14 * SPDX-License-Identifier: Apache-2.0 15 * 16 * Licensed under the Apache License, Version 2.0 (the License); you may 17 * not use this file except in compliance with the License. 18 * You may obtain a copy of the License at 19 * 20 * www.apache.org/licenses/LICENSE-2.0 21 * 22 * Unless required by applicable law or agreed to in writing, software 23 * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 * See the License for the specific language governing permissions and 26 * limitations under the License. 27 * 28 ******************************************************************************** 29 */ 30 31 #ifndef __ALD_BKPC_H__ 32 #define __ALD_BKPC_H__ 33 34 #ifdef __cplusplus 35 extern "C" { 36 #endif 37 38 #include "utils.h" 39 40 41 /** @addtogroup ES32FXXX_ALD 42 * @{ 43 */ 44 45 /** @addtogroup BKPC 46 * @{ 47 */ 48 49 /** @defgroup BKPC_Public_Macros BKPC Public Macros 50 * @{ 51 */ 52 #define BKPC_LOCK() (WRITE_REG(BKPC->PROT, 0U)) 53 #define BKPC_UNLOCK() (WRITE_REG(BKPC->PROT, 0x9669AA55U)) 54 #define BKPC_LRC_ENABLE() \ 55 do { \ 56 BKPC_UNLOCK(); \ 57 SET_BIT(BKPC->CR, BKPC_CR_LRCEN_MSK); \ 58 BKPC_LOCK(); \ 59 } while (0) 60 #define BKPC_LRC_DISABLE() \ 61 do { \ 62 BKPC_UNLOCK(); \ 63 CLEAR_BIT(BKPC->CR, BKPC_CR_LRCEN_MSK); \ 64 BKPC_LOCK(); \ 65 } while (0) 66 #define BKPC_LOSM_ENABLE() \ 67 do { \ 68 BKPC_UNLOCK(); \ 69 SET_BIT(BKPC->CR, BKPC_CR_LOSMEN_MSK); \ 70 BKPC_LOCK(); \ 71 } while (0) 72 #define BKPC_LOSM_DISABLE() \ 73 do { \ 74 BKPC_UNLOCK(); \ 75 CLEAR_BIT(BKPC->CR, BKPC_CR_LOSMEN_MSK);\ 76 BKPC_LOCK(); \ 77 } while (0) 78 #define BKPC_LOSC_ENABLE() \ 79 do { \ 80 BKPC_UNLOCK(); \ 81 SET_BIT(BKPC->CR, BKPC_CR_LOSCEN_MSK); \ 82 BKPC_LOCK(); \ 83 } while (0) 84 #define BKPC_LOSC_DISABLE() \ 85 do { \ 86 BKPC_UNLOCK(); \ 87 CLEAR_BIT(BKPC->CR, BKPC_CR_LOSCEN_MSK);\ 88 BKPC_LOCK(); \ 89 } while (0) 90 /** 91 * @} 92 */ 93 94 /** @defgroup BKPC_Public_Types BKPC Public Types 95 * @{ 96 */ 97 /** 98 * @brief BKPC ldo output select 99 */ 100 typedef enum { 101 BKPC_LDO_OUTPUT_1_6 = 0x0U, /**< 1.6V */ 102 BKPC_LDO_OUTPUT_1_3 = 0x1U, /**< 1.3V */ 103 BKPC_LDO_OUTPUT_1_4 = 0x2U, /**< 1.4V */ 104 BKPC_LDO_OUTPUT_1_5 = 0x4U, /**< 1.5V */ 105 } bkpc_ldo_output_t; 106 107 /** 108 * @brief Standby wakeup port select 109 */ 110 typedef enum { 111 PMU_STANDBY_PORT_SEL_PA0 = 0x0U, /**< Wakeup by PA0 */ 112 PMU_STANDBY_PORT_SEL_PA1 = 0x1U, /**< Wakeup by PA1 */ 113 PMU_STANDBY_PORT_SEL_PA2 = 0x2U, /**< Wakeup by PA2 */ 114 PMU_STANDBY_PORT_SEL_PA3 = 0x3U, /**< Wakeup by PA3 */ 115 PMU_STANDBY_PORT_SEL_NONE = 0xFU, /**< Wakeup by other source */ 116 } bkpc_wakeup_port_t; 117 118 /** 119 * @brief Standby wakeup level 120 */ 121 typedef enum { 122 PMU_STANDBY_LEVEL_HIGH = 0x0U, /**< High level */ 123 PMU_STANDBY_LEVEL_LOW = 0x1U, /**< Low level */ 124 } bkpc_wakeup_level_t; 125 /** 126 * @} 127 */ 128 129 /** 130 * @defgroup BKPC_Private_Macros BKPC Private Macros 131 * @{ 132 */ 133 #define IS_BKPC_LDO_OUTPUT(x) (((x) == BKPC_LDO_OUTPUT_1_6) || \ 134 ((x) == BKPC_LDO_OUTPUT_1_3) || \ 135 ((x) == BKPC_LDO_OUTPUT_1_4) || \ 136 ((x) == BKPC_LDO_OUTPUT_1_5)) 137 #define IS_BKPC_WAKEUP_PORT(x) (((x) == PMU_STANDBY_PORT_SEL_PA0) || \ 138 ((x) == PMU_STANDBY_PORT_SEL_PA1) || \ 139 ((x) == PMU_STANDBY_PORT_SEL_PA2) || \ 140 ((x) == PMU_STANDBY_PORT_SEL_PA3) || \ 141 ((x) == PMU_STANDBY_PORT_SEL_NONE)) 142 #define IS_BKPC_WAKEUP_LEVEL(x) (((x) == PMU_STANDBY_LEVEL_HIGH) || \ 143 ((x) == PMU_STANDBY_LEVEL_LOW)) 144 #define IS_BKPC_RAM_IDX(x) ((x) < 32) 145 /** 146 * @} 147 */ 148 149 /** @addtogroup BKPC_Public_Functions 150 * @{ 151 */ 152 /** @addtogroup BKPC_Public_Functions_Group1 153 * @{ 154 */ 155 /* control functions */ 156 extern void ald_bkpc_standby_wakeup_config(bkpc_wakeup_port_t port, bkpc_wakeup_level_t level); 157 extern void ald_bkpc_ldo_config(bkpc_ldo_output_t output, type_func_t state); 158 /** 159 * @} 160 */ 161 /** @addtogroup BKPC_Public_Functions_Group2 162 * @{ 163 */ 164 /* IO operation functions */ 165 extern void ald_bkpc_write_ram(uint8_t idx, uint32_t value); 166 extern uint32_t ald_bkpc_read_ram(uint8_t idx); 167 /** 168 * @} 169 */ 170 /** 171 * @} 172 */ 173 174 /** 175 * @} 176 */ 177 178 /** 179 * @} 180 */ 181 #ifdef __cplusplus 182 } 183 #endif 184 185 #endif /* __ALD_BKPC_H__ */ 186