| BlueNRG-1 Peripherals drivers Examples

- Main Page
- Modules
- Classes
- Files

- File List
- File Members

Micro_Sleep_Test_main.c
Go to the documentation of this file.
1
2 /******************** (C) COPYRIGHT 2016 STMicroelectronics ********************
3 * File Name : Micro_Sleep_Test_main.c
4 * Author : VMA DIVISION
5 * Version : 1.0.0
6 * Date : 2-October-2015
7 * Description : Code demostrating the BlueNRG-1 sleep modes
8 ********************************************************************************
9 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
10 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
11 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
12 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
13 * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
14 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
15 *******************************************************************************/
16
170 /* Includes ------------------------------------------------------------------*/
171 #include <stdio.h>
172 #include <string.h>
173 #include "hw_config.h"
174 #include "BlueNRG1_it.h"
175 #include "BlueNRG1_conf.h"
176 #include "sleep.h"
177 #include "bluenrg1_stack.h"
178 #include "ble_status.h"
179 #include "SDK_EVAL_Led.h"
180 #include "osal.h"
181 #include "Micro_Sleep_Test_config.h"
182
195 /* Private typedef -----------------------------------------------------------*/
196 /* Private define ------------------------------------------------------------*/
197 #define WAKEUP_TIMEOUT 5000 // 5 sec
198
199 /* Private macro -------------------------------------------------------------*/
200 /* Private variables ---------------------------------------------------------*/
201
202
203 void help(void)
204 {
205 printf("\r\n");
206 printf("s: Standby - SLEEPMODE_NOTIMER: wake on uart/button PUSH1\r\n");
207 printf("t: Sleep - SLEEPMODE_WAKETIMER: wake on uart/timeout 5 sec/button PUSH1\r\n");
208 printf("l: Toggle led DL1\r\n");
209 printf("p: Print Hello World message\r\n");
210 printf("r: Reset the BlueNRG-1\r\n");
211 printf("?: Display this help menu\r\n");
212 printf("PUSH1 button: toggle led DL1");
213 printf("\r\n> ");
214 }
215
216 /* Enable the Standby - SLEEPMODE_NOTIMER */
217 void sleep(void)
218 {
219 uint8_t ret, wakeup_source, wakeup_level;
220
221 wakeup_source = WAKEUP_IO13|WAKEUP_IO11;
222 wakeup_level = (WAKEUP_IO_LOW << WAKEUP_IO13) | (WAKEUP_IO_LOW << WAKEUP_IO11);
223
224 printf("\r\nEnter to Standby - SLEEPMODE_NOTIMER\r\n");
225 ret = BlueNRG_Sleep(SLEEPMODE_NOTIMER, wakeup_source, wakeup_level, 0);
226 if (ret != BLE_STATUS_SUCCESS) {
227 printf("BlueNRG_Sleep() error 0x%02x\r\n", ret);
228 while(1);
229 }
230 printf("WAKEUP Reason = ");
231 switch(BlueNRG_WakeupSource()) {
232 case WAKEUP_IO9:
233 printf("IO-9\r\n");
234 break;
235 case WAKEUP_IO10:
236 printf("IO-10\r\n");
237 break;
238 case WAKEUP_IO11:
239 printf("IO-11\r\n");
240 break;
241 case WAKEUP_IO12:
242 printf("IO-12\r\n");
243 break;
244 case WAKEUP_IO13:
245 printf("IO-13\r\n");
246 break;
247 }
248 }
249
250 /* Enable the Sleep - SLEEPMODE_WAKETIMER */
251 void sleep_timer(void)
252 {
253 uint8_t ret, wakeup_source, wakeup_level;
254
255 wakeup_source = WAKEUP_IO13|WAKEUP_IO11;
256 wakeup_level = (WAKEUP_IO_LOW << WAKEUP_IO13) | (WAKEUP_IO_LOW << WAKEUP_IO11);
257
258 printf("\r\nEnter to Sleep - SLEEPMODE_WAKETIMER\r\n");
259 ret = BlueNRG_Sleep(SLEEPMODE_WAKETIMER, wakeup_source, wakeup_level, WAKEUP_TIMEOUT);
260 if (ret != BLE_STATUS_SUCCESS) {
261 printf("BlueNRG_Sleep() error 0x%02x\r\n", ret);
262 while(1);
263 }
264 printf("WAKEUP Reason = ");
265 switch(BlueNRG_WakeupSource()) {
266 case WAKEUP_IO9:
267 printf("IO-9\r\n");
268 break;
269 case WAKEUP_IO10:
270 printf("IO-10\r\n");
271 break;
272 case WAKEUP_IO11:
273 printf("IO-11\r\n");
274 break;
275 case WAKEUP_IO12:
276 printf("IO-12\r\n");
277 break;
278 case WAKEUP_IO13:
279 printf("IO-13\r\n");
280 break;
281 case WAKEUP_SLEEP_TIMER1:
282 case WAKEUP_SLEEP_TIMER2:
283 printf("SLEEP TIMER\r\n");
284 break;
285 default:
286 printf("Unknown source\r\n");
287 break;
288 }
289 }
290
291
292 int main(void)
293 {
294 uint8_t charRead, ret;
295
296 /* System Init */
297 SystemInit();
298
299 /* Identify BlueNRG1 platform */
300 SdkEvalIdentification();
301
302 /* HW configuration */
303 HW_Config();
304
305 /* BlueNRG-1 stack init */
306 ret = BlueNRG_Stack_Initialization(&BlueNRG_Stack_Init_params);
307 if (ret != BLE_STATUS_SUCCESS) {
308 printf("Error during BlueNRG_Stack_Initialization() 0x%02x\r\n", ret);
309 while(1);
310 }
311
312 printf("Sleep Test\r\n");
313 printf("Enter ? for list of commands\r\n");
314
315 while(1) {
316 BTLE_StackTick();
317
318 if (noBlockingRead(&charRead)) {
319 switch (charRead) {
320 case 's':
321 sleep();
322 break;
323 case 't':
324 sleep_timer();
325 break;
326 case 'l':
327 SdkEvalLedToggle(LED1);
328 break;
329 case '?':
330 help();
331 break;
332 case 'p':
333 printf("Hello World Sleep !!!\r\n");
334 break;
335 case 'r':
336 NVIC_SystemReset();
337 break;
338 case '\r':
339 case '\n':
340 // ignored
341 break;
342 default:
343 printf("Unknown Command\r\n");
344 }
345 }
346 }
347 }
348
349 void HAL_VTimerTimeoutCallback(uint8_t timerNum)
350 {
351 /* Add app code to execute @ Sleep timeout */
352 }
353
354 #ifdef USE_FULL_ASSERT
355
362 void assert_failed(uint8_t* file, uint32_t line)
363 {
364 /* User can add his own implementation to report the file name and line number,
365 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
366
367 /* Infinite loop */
368 while (1)
369 {
370 }
371 }
372
373 #endif
374
387 /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/
388
389
HAL_VTimerTimeoutCallback
void HAL_VTimerTimeoutCallback(uint8_t timerNum)
Definition: Micro_Sleep_Test_main.c:349
sleep
void sleep(void)
Definition: Micro_Sleep_Test_main.c:217
sleep_timer
void sleep_timer(void)
Definition: Micro_Sleep_Test_main.c:251
WAKEUP_TIMEOUT
#define WAKEUP_TIMEOUT
Definition: Micro_Sleep_Test_main.c:197
main
int main(void)
Definition: Micro_Sleep_Test_main.c:292
help
void help(void)
Definition: Micro_Sleep_Test_main.c:203