GigaDevice
/
GD32_example_blinky
This a fork of https://developer.mbed.org/teams/mbed-os-examples/code/mbed-os-example-blinky/
main.cpp@0:8b84a0b4f817, 2019-02-18 (annotated)
- Committer:
- c_jin
- Date:
- Mon Feb 18 05:30:47 2019 +0000
- Revision:
- 0:8b84a0b4f817
Fork of https://developer.mbed.org/teams/mbed-os-examples/code/mbed-os-example-blinky/
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
c_jin | 0:8b84a0b4f817 | 1 | /* mbed Microcontroller Library |
c_jin | 0:8b84a0b4f817 | 2 | * Copyright (c) 2018 ARM Limited |
c_jin | 0:8b84a0b4f817 | 3 | * SPDX-License-Identifier: Apache-2.0 |
c_jin | 0:8b84a0b4f817 | 4 | */ |
c_jin | 0:8b84a0b4f817 | 5 | |
c_jin | 0:8b84a0b4f817 | 6 | #include "mbed.h" |
c_jin | 0:8b84a0b4f817 | 7 | #include "stats_report.h" |
c_jin | 0:8b84a0b4f817 | 8 | |
c_jin | 0:8b84a0b4f817 | 9 | DigitalOut led1(LED1); |
c_jin | 0:8b84a0b4f817 | 10 | |
c_jin | 0:8b84a0b4f817 | 11 | #define SLEEP_TIME 500 // (msec) |
c_jin | 0:8b84a0b4f817 | 12 | #define PRINT_AFTER_N_LOOPS 20 |
c_jin | 0:8b84a0b4f817 | 13 | |
c_jin | 0:8b84a0b4f817 | 14 | // main() runs in its own thread in the OS |
c_jin | 0:8b84a0b4f817 | 15 | int main() |
c_jin | 0:8b84a0b4f817 | 16 | { |
c_jin | 0:8b84a0b4f817 | 17 | SystemReport sys_state( SLEEP_TIME * PRINT_AFTER_N_LOOPS /* Loop delay time in ms */); |
c_jin | 0:8b84a0b4f817 | 18 | |
c_jin | 0:8b84a0b4f817 | 19 | int count = 0; |
c_jin | 0:8b84a0b4f817 | 20 | while (true) { |
c_jin | 0:8b84a0b4f817 | 21 | // Blink LED and wait 0.5 seconds |
c_jin | 0:8b84a0b4f817 | 22 | led1 = !led1; |
c_jin | 0:8b84a0b4f817 | 23 | wait_ms(SLEEP_TIME); |
c_jin | 0:8b84a0b4f817 | 24 | |
c_jin | 0:8b84a0b4f817 | 25 | if ((0 == count) || (PRINT_AFTER_N_LOOPS == count)) { |
c_jin | 0:8b84a0b4f817 | 26 | // Following the main thread wait, report on the current system status |
c_jin | 0:8b84a0b4f817 | 27 | sys_state.report_state(); |
c_jin | 0:8b84a0b4f817 | 28 | count = 0; |
c_jin | 0:8b84a0b4f817 | 29 | } |
c_jin | 0:8b84a0b4f817 | 30 | ++count; |
c_jin | 0:8b84a0b4f817 | 31 | } |
c_jin | 0:8b84a0b4f817 | 32 | } |