Pawel Poplawski / Mbed OS mbed-os-example-blinky-deep-sleep-test
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2018 ARM Limited
00003  * SPDX-License-Identifier: Apache-2.0
00004  */
00005 
00006 #include "mbed.h"
00007 #include "ThisThread.h"
00008 #include "stats_report.h"
00009 
00010 DigitalOut led1(LED1);
00011 
00012 #define SLEEP_TIME                  500 // (msec)
00013 #define PRINT_AFTER_N_LOOPS         20
00014 
00015 // main() runs in its own thread in the OS
00016 int main()
00017 {
00018     SystemReport sys_state( SLEEP_TIME * PRINT_AFTER_N_LOOPS /* Loop delay time in ms */);
00019 
00020     int count = 0;
00021     while (true) {
00022         // Blink LED and wait 0.5 seconds
00023         led1 = !led1;
00024         ThisThread::sleep_for(SLEEP_TIME);
00025 
00026         if ((0 == count) || (PRINT_AFTER_N_LOOPS == count)) {
00027             // Following the main thread wait, report on the current system status
00028             sys_state.report_state();
00029             count = 0;
00030             
00031             mbed_stats_cpu_t stats;
00032             mbed_stats_cpu_get(&stats);
00033             printf("Uptime: %llu ", stats.uptime / 1000);
00034             printf("Sleep time: %llu ", stats.sleep_time / 1000);
00035             printf("Deep Sleep: %llu\n", stats.deep_sleep_time / 1000);
00036             
00037         wait(1.0);
00038             
00039         }
00040         ++count;
00041     }
00042 }