| BlueNRG-1 Peripherals drivers APIs

- Main Page
- Modules
- Classes
- Files

- File List
- File Members

BlueNRG1_sysCtrl.c
Go to the documentation of this file.
1
22 /* Includes ------------------------------------------------------------------*/
23 #include "BlueNRG1_sysCtrl.h"
24
46 #define SOC_REASON_SYSREQ (0x00000002)
47 #define SOC_REASON_WDG (0x00000004)
48 #define SOC_REASON_LOCKUP (0x00000008)
49
50 #define BLE_REASON_WAKEUP_RST (0x00000001)
51 #define BLE_REASON_BOR_RST (0x00000002 | BLE_REASON_WAKEUP_RST)
52 #define BLE_REASON_POR_RST (0x00000004 | BLE_REASON_WAKEUP_RST)
53 #define BLE_REASON_FROM_IO9 (0x00000008 | BLE_REASON_WAKEUP_RST)
54 #define BLE_REASON_FROM_IO10 (0x00000010 | BLE_REASON_WAKEUP_RST)
55 #define BLE_REASON_FROM_IO11 (0x00000020 | BLE_REASON_WAKEUP_RST)
56 #define BLE_REASON_FROM_IO12 (0x00000040 | BLE_REASON_WAKEUP_RST)
57 #define BLE_REASON_FROM_IO13 (0x00000080 | BLE_REASON_WAKEUP_RST)
58 #define BLE_REASON_FROM_TIMER1 (0x00000100 | BLE_REASON_WAKEUP_RST)
59 #define BLE_REASON_FROM_TIMER2 (0x00000400 | BLE_REASON_WAKEUP_RST)
60
61
100 void SysCtrl_DeInit(void)
101 {
102 SYSTEM_CTRL->WKP_IO_IS = 0x00;
103 SYSTEM_CTRL->WKP_IO_IE = 0x03;
104 CKGEN_SOC->CONTROL = 0x01FA03F0;
105 CKGEN_SOC->CLOCK_EN = 0x0003FFFF;
106 CKGEN_BLE->CLK32K_COUNT = 0x0000000F;
107 CKGEN_BLE->CLK32K_IT = 0x00000000;
108 }
109
110
132 void SysCtrl_PeripheralClockCmd(uint32_t PeriphClock, FunctionalState NewState)
133 {
134 /* Check the parameters */
135 assert_param(IS_CLOCK_PERIPH(PeriphClock));
136 assert_param(IS_FUNCTIONAL_STATE(NewState));
137
138 if (NewState == ENABLE) {
139 SET_BIT(CKGEN_SOC->CLOCK_EN, PeriphClock);
140 }
141 else {
142 CLEAR_BIT(CKGEN_SOC->CLOCK_EN, PeriphClock);
143 }
144 }
145
151 RESET_REASON_Type SysCtrl_GetWakeupResetReason(void)
152 {
153 uint32_t tmpSoc, tmpBle;
154
155 tmpSoc = CKGEN_SOC->REASON_RST;
156 tmpBle = CKGEN_BLE->REASON_RST;
157
158 if ((tmpSoc == 0) &&
159 (tmpBle >= BLE_REASON_FROM_IO9) &&
160 (tmpBle <= BLE_REASON_FROM_IO13)) {
161 if ((tmpBle & BLE_REASON_FROM_IO9) == BLE_REASON_FROM_IO9) {
162 return RESET_BLE_WAKEUP_FROM_IO9;
163 }
164 if ((tmpBle & BLE_REASON_FROM_IO10) == BLE_REASON_FROM_IO10) {
165 return RESET_BLE_WAKEUP_FROM_IO10;
166 }
167 if ((tmpBle & BLE_REASON_FROM_IO11) == BLE_REASON_FROM_IO11) {
168 return RESET_BLE_WAKEUP_FROM_IO11;
169 }
170 if ((tmpBle & BLE_REASON_FROM_IO12) == BLE_REASON_FROM_IO12) {
171 return RESET_BLE_WAKEUP_FROM_IO12;
172 }
173 if ((tmpBle & BLE_REASON_FROM_IO13) == BLE_REASON_FROM_IO13) {
174 return RESET_BLE_WAKEUP_FROM_IO13;
175 }
176 }
177
178 if ((tmpSoc == 0) &&
179 ((tmpBle & BLE_REASON_FROM_TIMER1) == BLE_REASON_FROM_TIMER1)) {
180 return RESET_BLE_WAKEUP_FROM_TIMER1;
181 }
182 if ((tmpSoc == 0) &&
183 ((tmpBle & BLE_REASON_FROM_TIMER2) == BLE_REASON_FROM_TIMER2)) {
184 return RESET_BLE_WAKEUP_FROM_TIMER2;
185 }
186 if ((tmpSoc == 0) &&
187 ((tmpBle & BLE_REASON_POR_RST) == BLE_REASON_POR_RST)) {
188 return RESET_BLE_POR;
189 }
190 if ((tmpSoc == 0) &&
191 ((tmpBle & BLE_REASON_BOR_RST) == BLE_REASON_BOR_RST)) {
192 return RESET_BLE_BOR;
193 }
194 if (tmpSoc == SOC_REASON_SYSREQ) {
195 return RESET_SYSREQ;
196 }
197 if (tmpSoc == SOC_REASON_WDG) {
198 return RESET_WDG;
199 }
200 if((tmpSoc == SOC_REASON_LOCKUP)) {
201 return RESET_LOCKUP;
202 }
203
204 return RESET_NONE;
205 }
206
207
223 void SysCtrl_WakeupFromIo(uint8_t IO, uint8_t LevelState, FunctionalState NewState)
224 {
225 /* Check the parameters */
226 assert_param(IS_WAKEUP_ON_IO(IO));
227 assert_param(IS_WAKEUP_ON_STATE(LevelState));
228 assert_param(IS_FUNCTIONAL_STATE(NewState));
229
230 if(LevelState == WAKEUP_ON_HIGH_STATE) {
231 SET_BIT(SYSTEM_CTRL->WKP_IO_IS, IO);
232 }
233 else {
234 CLEAR_BIT(SYSTEM_CTRL->WKP_IO_IS, IO);
235 }
236
237 if(NewState == ENABLE) {
238 SET_BIT(SYSTEM_CTRL->WKP_IO_IE, IO);
239 }
240 else {
241 CLEAR_BIT(SYSTEM_CTRL->WKP_IO_IE, IO);
242 }
243
244 }
245
253 void SysCtrl_SelectXO(uint8_t XOFreq)
254 {
255 /* Check the parameters */
256 assert_param(IS_XO_FREQ(XOFreq));
257
258 if(XOFreq == XO_32MHZ) {
259 SYSTEM_CTRL->CTRL_b.MHZ32_SEL = SET;
260 }
261 else if(XOFreq == XO_16MHZ) {
262 SYSTEM_CTRL->CTRL_b.MHZ32_SEL = RESET;
263 }
264 }
265
266
267
280 /******************* (C) COPYRIGHT 2016 STMicroelectronics *****END OF FILE****/
BLE_REASON_FROM_IO12
#define BLE_REASON_FROM_IO12
Definition: BlueNRG1_sysCtrl.c:56
RESET_BLE_WAKEUP_FROM_IO10
Definition: BlueNRG1_sysCtrl.h:59
BlueNRG1_sysCtrl.h
This file contains all the functions prototypes for the System Controller firmware library...
RESET_REASON_Type
RESET_REASON_Type
System Reset and Wakeup Sources.
Definition: BlueNRG1_sysCtrl.h:50
RESET_BLE_WAKEUP_FROM_IO11
Definition: BlueNRG1_sysCtrl.h:60
IS_WAKEUP_ON_STATE
#define IS_WAKEUP_ON_STATE(STATE)
Definition: BlueNRG1_sysCtrl.h:116
RESET_BLE_WAKEUP_FROM_IO12
Definition: BlueNRG1_sysCtrl.h:61
BLE_REASON_FROM_TIMER1
#define BLE_REASON_FROM_TIMER1
Definition: BlueNRG1_sysCtrl.c:58
IS_XO_FREQ
#define IS_XO_FREQ(XO)
Definition: BlueNRG1_sysCtrl.h:130
BLE_REASON_FROM_IO9
#define BLE_REASON_FROM_IO9
Definition: BlueNRG1_sysCtrl.c:53
XO_32MHZ
#define XO_32MHZ
Definition: BlueNRG1_sysCtrl.h:127
BLE_REASON_BOR_RST
#define BLE_REASON_BOR_RST
Definition: BlueNRG1_sysCtrl.c:51
RESET_LOCKUP
Definition: BlueNRG1_sysCtrl.h:55
RESET_NONE
Definition: BlueNRG1_sysCtrl.h:52
RESET_WDG
Definition: BlueNRG1_sysCtrl.h:54
BLE_REASON_FROM_IO13
#define BLE_REASON_FROM_IO13
Definition: BlueNRG1_sysCtrl.c:57
RESET_BLE_WAKEUP_FROM_TIMER2
Definition: BlueNRG1_sysCtrl.h:64
RESET_BLE_WAKEUP_FROM_TIMER1
Definition: BlueNRG1_sysCtrl.h:63
SysCtrl_WakeupFromIo
void SysCtrl_WakeupFromIo(uint8_t IO, uint8_t LevelState, FunctionalState NewState)
Configure the wakeup source from IO.
Definition: BlueNRG1_sysCtrl.c:223
IS_WAKEUP_ON_IO
#define IS_WAKEUP_ON_IO(IOS)
Definition: BlueNRG1_sysCtrl.h:114
SysCtrl_GetWakeupResetReason
RESET_REASON_Type SysCtrl_GetWakeupResetReason(void)
Get the wakeup reason.
Definition: BlueNRG1_sysCtrl.c:151
SysCtrl_DeInit
void SysCtrl_DeInit(void)
De init function.
Definition: BlueNRG1_sysCtrl.c:100
WAKEUP_ON_HIGH_STATE
#define WAKEUP_ON_HIGH_STATE
Definition: BlueNRG1_sysCtrl.h:111
SysCtrl_SelectXO
void SysCtrl_SelectXO(uint8_t XOFreq)
Enable disable the XO clock divider for the system control.
Definition: BlueNRG1_sysCtrl.c:253
RESET_BLE_WAKEUP_FROM_IO13
Definition: BlueNRG1_sysCtrl.h:62
RESET_BLE_POR
Definition: BlueNRG1_sysCtrl.h:57
SysCtrl_PeripheralClockCmd
void SysCtrl_PeripheralClockCmd(uint32_t PeriphClock, FunctionalState NewState)
Enables the clock for the specified peripheral.
Definition: BlueNRG1_sysCtrl.c:132
RESET_SYSREQ
Definition: BlueNRG1_sysCtrl.h:53
SOC_REASON_WDG
#define SOC_REASON_WDG
Definition: BlueNRG1_sysCtrl.c:47
XO_16MHZ
#define XO_16MHZ
Definition: BlueNRG1_sysCtrl.h:128
RESET_BLE_BOR
Definition: BlueNRG1_sysCtrl.h:56
SOC_REASON_SYSREQ
#define SOC_REASON_SYSREQ
Definition: BlueNRG1_sysCtrl.c:46
BLE_REASON_POR_RST
#define BLE_REASON_POR_RST
Definition: BlueNRG1_sysCtrl.c:52
IS_CLOCK_PERIPH
#define IS_CLOCK_PERIPH(PERIPH)
Definition: BlueNRG1_sysCtrl.h:94
BLE_REASON_FROM_IO10
#define BLE_REASON_FROM_IO10
Definition: BlueNRG1_sysCtrl.c:54
SOC_REASON_LOCKUP
#define SOC_REASON_LOCKUP
Definition: BlueNRG1_sysCtrl.c:48
RESET_BLE_WAKEUP_FROM_IO9
Definition: BlueNRG1_sysCtrl.h:58
BLE_REASON_FROM_IO11
#define BLE_REASON_FROM_IO11
Definition: BlueNRG1_sysCtrl.c:55
BLE_REASON_FROM_TIMER2
#define BLE_REASON_FROM_TIMER2
Definition: BlueNRG1_sysCtrl.c:59