Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@99:688a02d088d4, 2019-09-19 (annotated)
- Committer:
- freelex
- Date:
- Thu Sep 19 09:01:05 2019 +0000
- Revision:
- 99:688a02d088d4
- Parent:
- 98:f2d7e14c84a1
deep_sleep_test
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| mbed_official | 82:abf1b1785bd7 | 1 | /* mbed Microcontroller Library |
| mbed_official | 82:abf1b1785bd7 | 2 | * Copyright (c) 2018 ARM Limited |
| mbed_official | 82:abf1b1785bd7 | 3 | * SPDX-License-Identifier: Apache-2.0 |
| mbed_official | 82:abf1b1785bd7 | 4 | */ |
| mbed_official | 82:abf1b1785bd7 | 5 | |
| Jonathan Austin |
0:2757d7abb7d9 | 6 | #include "mbed.h" |
| mbed_official | 98:f2d7e14c84a1 | 7 | #include "ThisThread.h" |
| mbed_official | 82:abf1b1785bd7 | 8 | #include "stats_report.h" |
| Jonathan Austin |
0:2757d7abb7d9 | 9 | |
| Jonathan Austin |
0:2757d7abb7d9 | 10 | DigitalOut led1(LED1); |
| Jonathan Austin |
0:2757d7abb7d9 | 11 | |
| mbed_official | 88:bea4f2daa48c | 12 | #define SLEEP_TIME 500 // (msec) |
| mbed_official | 88:bea4f2daa48c | 13 | #define PRINT_AFTER_N_LOOPS 20 |
| mbed_official | 88:bea4f2daa48c | 14 | |
| Jonathan Austin |
1:846c97078558 | 15 | // main() runs in its own thread in the OS |
| mbed_official | 82:abf1b1785bd7 | 16 | int main() |
| mbed_official | 82:abf1b1785bd7 | 17 | { |
| mbed_official | 88:bea4f2daa48c | 18 | SystemReport sys_state( SLEEP_TIME * PRINT_AFTER_N_LOOPS /* Loop delay time in ms */); |
| mbed_official | 82:abf1b1785bd7 | 19 | |
| mbed_official | 88:bea4f2daa48c | 20 | int count = 0; |
| Jonathan Austin |
0:2757d7abb7d9 | 21 | while (true) { |
| mbed_official | 82:abf1b1785bd7 | 22 | // Blink LED and wait 0.5 seconds |
| Jonathan Austin |
0:2757d7abb7d9 | 23 | led1 = !led1; |
| mbed_official | 98:f2d7e14c84a1 | 24 | ThisThread::sleep_for(SLEEP_TIME); |
| mbed_official | 82:abf1b1785bd7 | 25 | |
| mbed_official | 88:bea4f2daa48c | 26 | if ((0 == count) || (PRINT_AFTER_N_LOOPS == count)) { |
| mbed_official | 88:bea4f2daa48c | 27 | // Following the main thread wait, report on the current system status |
| mbed_official | 88:bea4f2daa48c | 28 | sys_state.report_state(); |
| mbed_official | 88:bea4f2daa48c | 29 | count = 0; |
| freelex | 99:688a02d088d4 | 30 | |
| freelex | 99:688a02d088d4 | 31 | mbed_stats_cpu_t stats; |
| freelex | 99:688a02d088d4 | 32 | mbed_stats_cpu_get(&stats); |
| freelex | 99:688a02d088d4 | 33 | printf("Uptime: %llu ", stats.uptime / 1000); |
| freelex | 99:688a02d088d4 | 34 | printf("Sleep time: %llu ", stats.sleep_time / 1000); |
| freelex | 99:688a02d088d4 | 35 | printf("Deep Sleep: %llu\n", stats.deep_sleep_time / 1000); |
| freelex | 99:688a02d088d4 | 36 | |
| freelex | 99:688a02d088d4 | 37 | wait(1.0); |
| freelex | 99:688a02d088d4 | 38 | |
| mbed_official | 88:bea4f2daa48c | 39 | } |
| mbed_official | 88:bea4f2daa48c | 40 | ++count; |
| Jonathan Austin |
0:2757d7abb7d9 | 41 | } |
| Jonathan Austin |
0:2757d7abb7d9 | 42 | } |