Skip to content

[RTOS] Added idle hook API #1463

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

Closed
wants to merge 2 commits into from
Closed

[RTOS] Added idle hook API #1463

wants to merge 2 commits into from

Conversation

neilt6
Copy link
Contributor

@neilt6 neilt6 commented Dec 1, 2015

Added a new API for attaching an idle hook to be executed by the idle task. This will allow developers to add custom logic to the idle task (e.g. to call sleep()) without modifying the library code.

Added a new API for attaching an idle hook to be executed by the idle
task.
Moved rtos_idle.h to the various TARGET_ folders.
@neilt6
Copy link
Contributor Author

neilt6 commented Dec 1, 2015

Here's an example program demonstrating the new API:

#include "mbed.h"
#include "rtos.h"

DigitalOut led1(LED1);

void idleHook()
{
    sleep();
}

int main()
{
    Thread::attach_idle_hook(idleHook);

    while(1) {
        led1 = 1;
        Thread::wait(500);
        led1 = 0;
        Thread::wait(500);
    }
}

@sg-
Copy link
Contributor

sg- commented Dec 1, 2015

Did you consider using the FunctionPointer class for handling the user handler?

@neilt6
Copy link
Contributor Author

neilt6 commented Dec 2, 2015

I wasn't sure I could access a C++ class instance from os_idle_demon(), and it made sense to keep the RTX layer pure C.

@neilt6
Copy link
Contributor Author

neilt6 commented Feb 24, 2016

Is this pull request still being considered, or should I withdraw it?

@0xc0170
Copy link
Contributor

0xc0170 commented Feb 28, 2016

@neilt6 We will have a second look at this, will let you know the upcoming week.

cc @sg-

@adamgreen
Copy link
Contributor

This functionality looks like a good addition. I do have a few comments/questions:

  • There are some files you touched where you used tabs for indentation when the original code used spaces. It would be good to keep things consistent and use spaces.
  • Why did you place rtos_idle_hook_fptr in the global namespace and not just have a C function that application code could call to attach/detach to a module scoped function pointer (ie. static)? The NULL pointer check you currently have in the C++ attach/detach method could then be pushed down into that C function.

@neilt6
Copy link
Contributor Author

neilt6 commented Feb 29, 2016

Thanks for the feedback @sg- and @adamgreen. I'm going to withdraw this for now, and see if there's a better way to implement this functionality.

@neilt6 neilt6 closed this Feb 29, 2016
@neilt6 neilt6 deleted the rtos-idle-patch branch March 8, 2016 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants