|
| 1 | +/****************************************************************************** |
| 2 | + * The MIT License |
| 3 | + * |
| 4 | + * Copyright (c) 2010 LeafLabs, LLC. |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person |
| 7 | + * obtaining a copy of this software and associated documentation |
| 8 | + * files (the "Software"), to deal in the Software without |
| 9 | + * restriction, including without limitation the rights to use, copy, |
| 10 | + * modify, merge, publish, distribute, sublicense, and/or sell copies |
| 11 | + * of the Software, and to permit persons to whom the Software is |
| 12 | + * furnished to do so, subject to the following conditions: |
| 13 | + * |
| 14 | + * The above copyright notice and this permission notice shall be |
| 15 | + * included in all copies or substantial portions of the Software. |
| 16 | + * |
| 17 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 18 | + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 19 | + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 20 | + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 21 | + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 22 | + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 23 | + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 24 | + * SOFTWARE. |
| 25 | + *****************************************************************************/ |
| 26 | + |
| 27 | +/** |
| 28 | + * @file bkp.h |
| 29 | + * @brief Backup register support. |
| 30 | + */ |
| 31 | + |
| 32 | +#ifndef _BKP_H_ |
| 33 | +#define _BKP_H_ |
| 34 | + |
| 35 | +#include "libmaple.h" |
| 36 | + |
| 37 | +#ifdef __cplusplus |
| 38 | +extern "C" { |
| 39 | +#endif |
| 40 | + |
| 41 | +#if defined(STM32_MEDIUM_DENSITY) |
| 42 | +#define BKP_NR_DATA_REGS 10 |
| 43 | +#elif defined(STM32_HIGH_DENSITY) |
| 44 | +#define BKP_NR_DATA_REGS 42 |
| 45 | +#endif |
| 46 | + |
| 47 | +/** Backup peripheral register map type. */ |
| 48 | +typedef struct bkp_reg_map { |
| 49 | + const uint32 RESERVED1; ///< Reserved |
| 50 | + __io uint32 DR1; ///< Data register 1 |
| 51 | + __io uint32 DR2; ///< Data register 2 |
| 52 | + __io uint32 DR3; ///< Data register 3 |
| 53 | + __io uint32 DR4; ///< Data register 4 |
| 54 | + __io uint32 DR5; ///< Data register 5 |
| 55 | + __io uint32 DR6; ///< Data register 6 |
| 56 | + __io uint32 DR7; ///< Data register 7 |
| 57 | + __io uint32 DR8; ///< Data register 8 |
| 58 | + __io uint32 DR9; ///< Data register 9 |
| 59 | + __io uint32 DR10; ///< Data register 10 |
| 60 | + __io uint32 RTCCR; ///< RTC control register |
| 61 | + __io uint32 CR; ///< Control register |
| 62 | + __io uint32 CSR; ///< Control and status register |
| 63 | +#ifdef STM32_HIGH_DENSITY |
| 64 | + const uint32 RESERVED2; ///< Reserved |
| 65 | + const uint32 RESERVED3; ///< Reserved |
| 66 | + __io uint32 DR11; ///< Data register 11 |
| 67 | + __io uint32 DR12; ///< Data register 12 |
| 68 | + __io uint32 DR13; ///< Data register 13 |
| 69 | + __io uint32 DR14; ///< Data register 14 |
| 70 | + __io uint32 DR15; ///< Data register 15 |
| 71 | + __io uint32 DR16; ///< Data register 16 |
| 72 | + __io uint32 DR17; ///< Data register 17 |
| 73 | + __io uint32 DR18; ///< Data register 18 |
| 74 | + __io uint32 DR19; ///< Data register 19 |
| 75 | + __io uint32 DR20; ///< Data register 20 |
| 76 | + __io uint32 DR21; ///< Data register 21 |
| 77 | + __io uint32 DR22; ///< Data register 22 |
| 78 | + __io uint32 DR23; ///< Data register 23 |
| 79 | + __io uint32 DR24; ///< Data register 24 |
| 80 | + __io uint32 DR25; ///< Data register 25 |
| 81 | + __io uint32 DR26; ///< Data register 26 |
| 82 | + __io uint32 DR27; ///< Data register 27 |
| 83 | + __io uint32 DR28; ///< Data register 28 |
| 84 | + __io uint32 DR29; ///< Data register 29 |
| 85 | + __io uint32 DR30; ///< Data register 30 |
| 86 | + __io uint32 DR31; ///< Data register 31 |
| 87 | + __io uint32 DR32; ///< Data register 32 |
| 88 | + __io uint32 DR33; ///< Data register 33 |
| 89 | + __io uint32 DR34; ///< Data register 34 |
| 90 | + __io uint32 DR35; ///< Data register 35 |
| 91 | + __io uint32 DR36; ///< Data register 36 |
| 92 | + __io uint32 DR37; ///< Data register 37 |
| 93 | + __io uint32 DR38; ///< Data register 38 |
| 94 | + __io uint32 DR39; ///< Data register 39 |
| 95 | + __io uint32 DR40; ///< Data register 40 |
| 96 | + __io uint32 DR41; ///< Data register 41 |
| 97 | + __io uint32 DR42; ///< Data register 42 |
| 98 | +#endif |
| 99 | +} bkp_reg_map; |
| 100 | + |
| 101 | +/** Backup peripheral register map base pointer. */ |
| 102 | +#define BKP_BASE ((struct bkp_reg_map*)0x40006C00) |
| 103 | + |
| 104 | +/** Backup peripheral device type. */ |
| 105 | +typedef struct bkp_dev { |
| 106 | + bkp_reg_map *regs; /**< Register map */ |
| 107 | +} bkp_dev; |
| 108 | + |
| 109 | +extern const bkp_dev *BKP; |
| 110 | + |
| 111 | +/* |
| 112 | + * Register bit definitions |
| 113 | + */ |
| 114 | + |
| 115 | +/* Data Registers */ |
| 116 | + |
| 117 | +#define BKP_DR_D 0xFFFF |
| 118 | + |
| 119 | +/* RTC Clock Calibration Register */ |
| 120 | + |
| 121 | +#define BKP_RTCCR_ASOS_BIT 9 |
| 122 | +#define BKP_RTCCR_ASOE_BIT 8 |
| 123 | +#define BKP_RTCCR_CCO_BIT 7 |
| 124 | + |
| 125 | +#define BKP_RTCCR_ASOS BIT(BKP_RTCCR_ASOS_BIT) |
| 126 | +#define BKP_RTCCR_ASOE BIT(BKP_RTCCR_ASOE_BIT) |
| 127 | +#define BKP_RTCCR_CCO BIT(BKP_RTCCR_CCO_BIT) |
| 128 | +#define BKP_RTCCR_CAL 0x7F |
| 129 | + |
| 130 | +/* Backup control register */ |
| 131 | + |
| 132 | +#define BKP_CR_TPAL_BIT 1 |
| 133 | +#define BKP_CR_TPE_BIT 0 |
| 134 | + |
| 135 | +#define BKP_CR_TPAL BIT(BKP_CR_TPAL_BIT) |
| 136 | +#define BKP_CR_TPE BIT(BKP_CR_TPE_BIT) |
| 137 | + |
| 138 | +/* Backup control/status register */ |
| 139 | + |
| 140 | +#define BKP_CSR_TIF_BIT 9 |
| 141 | +#define BKP_CSR_TEF_BIT 8 |
| 142 | +#define BKP_CSR_TPIE_BIT 2 |
| 143 | +#define BKP_CSR_CTI_BIT 1 |
| 144 | +#define BKP_CSR_CTE_BIT 0 |
| 145 | + |
| 146 | +#define BKP_CSR_TIF BIT(BKP_CSR_TIF_BIT) |
| 147 | +#define BKP_CSR_TEF BIT(BKP_CSR_TEF_BIT) |
| 148 | +#define BKP_CSR_TPIE BIT(BKP_CSR_TPIE_BIT) |
| 149 | +#define BKP_CSR_CTI BIT(BKP_CSR_CTI_BIT) |
| 150 | +#define BKP_CSR_CTE BIT(BKP_CSR_CTE_BIT) |
| 151 | + |
| 152 | +/* |
| 153 | + * Convenience functions |
| 154 | + */ |
| 155 | + |
| 156 | +void bkp_init(void); |
| 157 | +void bkp_enable_writes(void); |
| 158 | +void bkp_disable_writes(void); |
| 159 | +uint16 bkp_read(uint8 reg); |
| 160 | +void bkp_write(uint8 reg, uint16 val); |
| 161 | + |
| 162 | +#ifdef __cplusplus |
| 163 | +} /* extern "C" */ |
| 164 | +#endif |
| 165 | + |
| 166 | +#endif |
0 commit comments