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
- Committer:
- mbed_official
- Date:
- 2018-06-19
- Revision:
- 2:a343e54632c0
- Parent:
- 0:3114f82feb68
- Child:
- 15:86c93f5d67c4
File content as of revision 2:a343e54632c0:
#include "mbed.h"
#if !defined(MBED_CPU_STATS_ENABLED) || !defined(DEVICE_LPTICKER) || !defined(DEVICE_SLEEP)
#error [NOT_SUPPORTED] test not supported
#endif
DigitalOut led1(LED1);
#define MAX_THREAD_STACK 384
#define SAMPLE_TIME 1000
#define LOOP_TIME 3000
uint64_t prev_idle_time = 0;
int32_t wait_time = 5000;
void busy_thread()
{
volatile uint64_t i = ~0;
while(i--) {
led1 = !led1;
wait_us(wait_time);
}
}
void print_stats()
{
mbed_stats_cpu_t stats;
mbed_stats_cpu_get(&stats);
printf("%-20lld", stats.uptime);
printf("%-20lld", stats.idle_time);
printf("%-20lld", stats.sleep_time);
printf("%-20lld\n", stats.deep_sleep_time);
}
int main()
{
// Request the shared queue
EventQueue *stats_queue = mbed_event_queue();
Thread *thread;
int id;
id = stats_queue->call_every(SAMPLE_TIME, print_stats);
printf("%-20s%-20s%-20s%-20s\n", "Uptime", "Idle Time", "Sleep time", "DeepSleep time");
thread = new Thread(osPriorityNormal, MAX_THREAD_STACK);
thread->start(busy_thread);
// Steadily increase the system load
for (int count = 1; ; count++) {
Thread::wait(LOOP_TIME);
if (wait_time <= 0) {
break;
}
wait_time -= 1000;
}
thread->terminate();
stats_queue->cancel(id);
return 0;
}