dRonin  adbada4
dRonin firmware
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pios_iap.c
Go to the documentation of this file.
1 
16 /*
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation; either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful, but
23  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25  * for more details.
26  *
27  * You should have received a copy of the GNU General Public License along
28  * with this program; if not, see <http://www.gnu.org/licenses/>
29  */
30 
31 /****************************************************************************************
32  * Header files
33  ****************************************************************************************/
34 #include <pios.h>
35 
36 /****************************************************************************************
37  * Private Definitions/Macros
38  ****************************************************************************************/
39 
40 /* these definitions reside here for protection and privacy. */
41 #define IAP_MAGIC_WORD_1 0x1122
42 #define IAP_MAGIC_WORD_2 0xAA55
43 #define IAP_MAGIC_WORD_3 0xBB11
44 
45 #define UPPERWORD16(lw) (uint16_t)((uint32_t)(lw)>>16)
46 #define LOWERWORD16(lw) (uint16_t)((uint32_t)(lw)&0x0000ffff)
47 #define UPPERBYTE(w) (uint8_t)((w)>>8)
48 #define LOWERBYTE(w) (uint8_t)((w)&0x00ff)
49 
50 /****************************************************************************************
51  * Private Functions
52  ****************************************************************************************/
53 
54 /****************************************************************************************
55  * Private (static) Data
56  ****************************************************************************************/
57 
58 /****************************************************************************************
59  * Public/Global Data
60  ****************************************************************************************/
61 
69 void PIOS_IAP_Init( void )
70 {
71  /* Enable CRC clock */
72  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC, ENABLE);
73 
74  /* Enable PWR and BKP clock */
75  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
76 
77  /* Enable write access to Backup domain */
78  PWR_BackupAccessCmd(ENABLE);
79 
80  /* Clear Tamper pin Event(TE) pending flag */
81  BKP_ClearFlag();
82 
83 }
84 
89 uint32_t PIOS_IAP_CheckRequest( void )
90 {
91  uint32_t retval = false;
92  uint16_t reg1;
93  uint16_t reg2;
94 
95  reg1 = BKP_ReadBackupRegister( MAGIC_REG_1 );
96  reg2 = BKP_ReadBackupRegister( MAGIC_REG_2 );
97 
98  if( reg1 == IAP_MAGIC_WORD_1 && reg2 == IAP_MAGIC_WORD_2 ) {
99  // We have a match.
100  retval = true;
101  } else {
102  retval = false;
103  }
104  return retval;
105 }
106 
111 uint32_t PIOS_Boot_CheckRequest( void )
112 {
113  uint32_t retval = false;
114  uint16_t reg1;
115  uint16_t reg2;
116 
117  reg1 = BKP_ReadBackupRegister( MAGIC_REG_1 );
118  reg2 = BKP_ReadBackupRegister( MAGIC_REG_2 );
119 
120  if( reg1 == IAP_MAGIC_WORD_1 && reg2 == IAP_MAGIC_WORD_3 ) {
121  // We have a match.
122  retval = true;
123  } else {
124  retval = false;
125  }
126  return retval;
127 }
128 
135 void PIOS_IAP_SetRequest1(void)
136 {
137  BKP_WriteBackupRegister( MAGIC_REG_1, IAP_MAGIC_WORD_1);
138 }
139 
140 void PIOS_IAP_SetRequest2(void)
141 {
142  BKP_WriteBackupRegister( MAGIC_REG_2, IAP_MAGIC_WORD_2);
143 }
144 
145 void PIOS_IAP_SetRequest3(void)
146 {
147  BKP_WriteBackupRegister( MAGIC_REG_2, IAP_MAGIC_WORD_3);
148 }
149 
150 void PIOS_IAP_ClearRequest(void)
151 {
152  BKP_WriteBackupRegister( MAGIC_REG_1, 0);
153  BKP_WriteBackupRegister( MAGIC_REG_2, 0);
154 }
155 
156 uint16_t PIOS_IAP_ReadBootCount(void)
157 {
158  return BKP_ReadBackupRegister ( IAP_BOOTCOUNT );
159 }
160 
161 void PIOS_IAP_WriteBootCount (uint16_t boot_count)
162 {
163  BKP_WriteBackupRegister ( IAP_BOOTCOUNT, boot_count );
164 }
uint32_t PIOS_IAP_CheckRequest(void)
Determines if an In-Application-Programming request has been made.
Definition: pios_iap.c:57
#define MAGIC_REG_1
Definition: pios_iap.h:47
#define IAP_MAGIC_WORD_1
Definition: pios_iap.c:41
Main PiOS header to include all the compiled in PiOS options.
#define IAP_BOOTCOUNT
Definition: pios_iap.h:49
uint16_t PIOS_IAP_ReadBootCount(void)
Definition: pios_iap.c:93
void PIOS_IAP_Init(void)
PIOS_IAP_Init - performs required initializations for iap module.
Definition: pios_iap.c:44
#define MAGIC_REG_2
Definition: pios_iap.h:48
void PIOS_IAP_SetRequest3(void)
Definition: pios_iap.c:84
#define IAP_MAGIC_WORD_3
Definition: pios_iap.c:43
void PIOS_IAP_ClearRequest(void)
Definition: pios_iap.c:89
uint32_t PIOS_Boot_CheckRequest(void)
Determines if a boot request has been made.
Definition: pios_iap.c:63
void PIOS_IAP_WriteBootCount(uint16_t)
Definition: pios_iap.c:98
void PIOS_IAP_SetRequest2(void)
Definition: pios_iap.c:79
void PIOS_IAP_SetRequest1(void)
Sets the 1st word of the request sequence.
Definition: pios_iap.c:74
#define IAP_MAGIC_WORD_2
Definition: pios_iap.c:42