update credits
[librepilot.git] / flight / pios / stm32f30x / pios_bkp.c
blob4475445a2c939aace1adebe5e03f27af49c754cd
1 /**
2 ******************************************************************************
3 * @addtogroup PIOS PIOS Core hardware abstraction layer
4 * @{
5 * @addtogroup PIOS_BKP Backup SRAM functions
6 * @brief Hardware abstraction layer for backup sram
7 * @{
9 * @file pios_bkp.c
10 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2013.
11 * @brief IAP functions
12 * @see The GNU Public License (GPL) Version 3
14 *****************************************************************************/
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 3 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful, but
22 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
23 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 * for more details.
26 * You should have received a copy of the GNU General Public License along
27 * with this program; if not, write to the Free Software Foundation, Inc.,
28 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include <pios.h>
32 #include <pios_bkp.h>
33 #include <stm32f30x_rtc.h>
35 /****************************************************************************************
36 * Header files
37 ****************************************************************************************/
39 /*****************************************************************************************
40 * Public Definitions/Macros
41 ****************************************************************************************/
43 /****************************************************************************************
44 * Public Functions
45 ****************************************************************************************/
46 const uint32_t pios_bkp_registers_map[] = {
47 RTC_BKP_DR0,
48 RTC_BKP_DR1,
49 RTC_BKP_DR2,
50 RTC_BKP_DR3,
51 RTC_BKP_DR4,
52 RTC_BKP_DR5,
53 RTC_BKP_DR6,
54 RTC_BKP_DR7,
55 RTC_BKP_DR8,
56 RTC_BKP_DR9,
57 RTC_BKP_DR10,
58 RTC_BKP_DR11,
59 RTC_BKP_DR12,
60 RTC_BKP_DR13,
61 RTC_BKP_DR14,
62 RTC_BKP_DR15,
64 #define PIOS_BKP_REGISTERS_COUNT NELEMENTS(pios_bkp_registers_map)
66 void PIOS_BKP_Init(void)
68 /* Enable CRC clock */
69 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC, ENABLE);
71 /* Enable PWR and BKP clock */
72 RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
74 /* Clear Tamper pin Event(TE) pending flag */
75 RTC_ClearFlag(RTC_FLAG_TAMP1F);
78 uint16_t PIOS_BKP_ReadRegister(uint32_t regnumber)
80 if (PIOS_BKP_REGISTERS_COUNT < regnumber) {
81 PIOS_Assert(0);
82 } else {
83 return (uint16_t)RTC_ReadBackupRegister(pios_bkp_registers_map[regnumber]);
87 void PIOS_BKP_WriteRegister(uint32_t regnumber, uint16_t data)
89 if (PIOS_BKP_REGISTERS_COUNT < regnumber) {
90 PIOS_Assert(0);
91 } else {
92 RTC_WriteBackupRegister(pios_bkp_registers_map[regnumber], (uint32_t)data);
96 void PIOS_BKP_EnableWrite(void)
98 /* Enable write access to Backup domain */
99 PWR_BackupAccessCmd(ENABLE);
102 void PIOS_BKP_DisableWrite(void)
104 /* Enable write access to Backup domain */
105 PWR_BackupAccessCmd(DISABLE);
109 /****************************************************************************************
110 * Public Data
111 ****************************************************************************************/