-
Notifications
You must be signed in to change notification settings - Fork 26
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
Idle loop #2
Changes from 3 commits
89e6c92
7555204
e405605
cc20e62
9840189
39f9f26
597bf34
94063ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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. |
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Intendation There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.