Skip to content

Idle loop #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 12, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions IdleLoop/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# IdleLoop example #

Idle Loop usage example for mbed OS

This is an example showing the purpose of Idle Loop thread that is scheduled when no other threads are ready to run. In this example, we have a regular thread that is scheduled to run every
5 seconds, and meanwhile, since no other thread is scheduled to run, the idle loop runs and toggles the LED.
31 changes: 31 additions & 0 deletions IdleLoop/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "mbed.h"
#include "rtos_idle.h"

DigitalOut led(LED2);
DigitalOut led1(LED1);
LowPowerTicker watchdogTicker;
Thread watchdogThread;
EventQueue watchdogQueue;


//if we use Serial as a CLI console . The CLI thread allways get the read lock , if another thread want to print something to serial console, it will be blocked by CLI thread .

void watchdogRefreshHandler() {
led = !led;
// target-specific feed function
};

void watchdogRefreshIsr() {
watchdogQueue.call(callback(&watchdogRefreshHandler));
};

void new_idle_loop()
{
led1 = !led1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intendation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think my copy paste to notepadd++ screwed it up. :(

}

int main() {
watchdogThread.start(callback(&watchdogQueue, &EventQueue::dispatch_forever));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intendation

watchdogTicker.attach(callback(&watchdogRefreshIsr), 5);
rtos_attach_idle_hook(&new_idle_loop);
}