update credits
[librepilot.git] / flight / pios / stm32f4xx / pios_bkp.c
blob8b9357c5f6d87c13efeb5c400c48d9349263ae85
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 <stm32f4xx_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,
63 RTC_BKP_DR16,
64 RTC_BKP_DR17,
65 RTC_BKP_DR18,
66 RTC_BKP_DR19
68 #define PIOS_BKP_REGISTERS_COUNT NELEMENTS(pios_bkp_registers_map)
70 void PIOS_BKP_Init(void)
72 /* Enable CRC clock */
73 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_CRC | RCC_AHB1Periph_BKPSRAM, ENABLE);
75 /* Enable PWR and BKP clock */
76 RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
78 /* Clear Tamper pin Event(TE) pending flag */
79 RTC_ClearFlag(RTC_FLAG_TAMP1F);
82 uint16_t PIOS_BKP_ReadRegister(uint32_t regnumber)
84 if (PIOS_BKP_REGISTERS_COUNT < regnumber) {
85 PIOS_Assert(0);
86 } else {
87 return (uint16_t)RTC_ReadBackupRegister(pios_bkp_registers_map[regnumber]);
91 void PIOS_BKP_WriteRegister(uint32_t regnumber, uint16_t data)
93 if (PIOS_BKP_REGISTERS_COUNT < regnumber) {
94 PIOS_Assert(0);
95 } else {
96 RTC_WriteBackupRegister(pios_bkp_registers_map[regnumber], (uint32_t)data);
100 void PIOS_BKP_EnableWrite(void)
102 /* Enable write access to Backup domain */
103 PWR_BackupAccessCmd(ENABLE);
106 void PIOS_BKP_DisableWrite(void)
108 /* Enable write access to Backup domain */
109 PWR_BackupAccessCmd(DISABLE);
113 /****************************************************************************************
114 * Public Data
115 ****************************************************************************************/