Skip to content

[RTOS] Added idle hook API #1597

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 2 commits into from
Mar 15, 2016
Merged

[RTOS] Added idle hook API #1597

merged 2 commits into from
Mar 15, 2016

Conversation

neilt6
Copy link
Contributor

@neilt6 neilt6 commented Mar 8, 2016

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.

Updated version of #1463.

Added a new API for attaching a user-provided function to be executed by
the idle task.
@neilt6
Copy link
Contributor Author

neilt6 commented Mar 8, 2016

@adamgreen, I've created a new pull-request for my RTOS idle hook API, and incorporated your recommendations from #1463.

@@ -204,17 +204,12 @@
/*----------------------------------------------------------------------------
* OS Idle daemon
*---------------------------------------------------------------------------*/
extern void rtos_idle_loop(void);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you not just #include "rtos_idle.h" instead to get the function prototype for rtos_idle_loop() since that header contains the prototype as well? Or maybe consider removing the prototype for rtos_idle_loop() from rtos_idle.h so it isn't exposed from the more public header and then keep these forward declarations in the RTX_Conf* sources.

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 was mirroring the way mbed_die() is forward declared for the error functions, and forgot to remove the unnecessary declaration from rtos_idle.h. Fixed in c52e0dc.

Removed unnecessary loop function prototype.
@adamgreen
Copy link
Contributor

👍

@0xc0170
Copy link
Contributor

0xc0170 commented Mar 9, 2016

Looks good to me.

cc @sg-

@sg-
Copy link
Contributor

sg- commented Mar 15, 2016

👍

As a future improvement it'd be nice to have the same interface that supports https://github.com/mbedmicro/mbed/blob/master/libraries/mbed/api/FunctionPointer.h
so member functions are also compatible.

0xc0170 added a commit that referenced this pull request Mar 15, 2016
@0xc0170 0xc0170 merged commit 1fa489b into ARMmbed:master Mar 15, 2016
@0xc0170
Copy link
Contributor

0xc0170 commented Apr 1, 2016

@neilt6 Referenced PR is having troubles, I'll investigate why CI did not catch this

@neilt6
Copy link
Contributor Author

neilt6 commented Apr 1, 2016

@0xc0170 That's interesting... What if we added a prototype for void rtos_idle_loop(void) to rtos_idle.h, and included that header in RTX_Conf_CM.c instead of using extern void rtos_idle_loop(void)?

Proposed rtos_idle.h:

#ifndef RTOS_IDLE_H
#define RTOS_IDLE_H

#include <stddef.h>

#ifdef __cplusplus
extern "C" {
#endif

void rtos_attach_idle_hook(void (*fptr)(void));

void rtos_idle_loop(void);

#ifdef __cplusplus
}
#endif

#endif

Proposed RTX_Conf_CM.c:

/*----------------------------------------------------------------------------
 *      OS Idle daemon
 *---------------------------------------------------------------------------*/
#include "rtos_idle.h"

void os_idle_demon (void) {
    /* The idle demon is a system thread, running when no other thread is      */
    /* ready to run.                                                           */
    rtos_idle_loop();
}

@adamgreen
Copy link
Contributor

I suspect that this has something to do with a circular dependency. Previously the C++ code in rtos/rtos just depended on the rtos/rtx code but this change introduced a circular dependency where rtos/rtx now depends on rtos/rtos as well. Can the rtos_idle.* files not be placed in the RTX directory with the rest of the C code?

@neilt6
Copy link
Contributor Author

neilt6 commented Apr 2, 2016

Yes, they just need to be duplicated for the three "versions" of RTX.

@neilt6
Copy link
Contributor Author

neilt6 commented Apr 6, 2016

@0xc0170, were you expecting me to submit the patch for #1639? I can write it, but I would be doing so blindly since I'm unable to reproduce the phenomenon on the online compiler...

@0xc0170
Copy link
Contributor

0xc0170 commented Apr 6, 2016

@0xc0170, were you expecting me to submit the patch for #1639? I can write it, but I would be doing so blindly since I'm unable to reproduce the phenomenon on the online compiler...

I haven't got time to reproduce it, I'll have a look and comment to your proposal

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