Skip to content
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

Added User Functions #240

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

mdiepart
Copy link
Contributor

This PR contains one commit that implements a user functions thread.

This thread handles a set of functions added by the user.
Those functions can be either periodic (with a frequency of 1Hz, 10Hz, 20Hz, 50Hz, 100Hz or 1kHhz) or aperiodic (asynchronous).
Periodic functions will be called periodically depending on their scheduling. Async functions need to be triggered using user_functions_trigger(id).

The maximum amount of user functions that can be handled have to be defined in hwconfig.h using the macro CONFIG_USER_FUNCTIONS. If this macro is not defined, the user functions thread will not be created.

For now, it is implemented by checking for async functions to call every 5ms. This is because the version of miosix used does not support pthread_cond_timedwait().

Some code (untested, commented-out) have been voluntarily left in the user_functions.c waiting for the miosix kernel to be updated.

#include <stddef.h>
#include <errno.h>

#if defined(CONFIG_USER_FUNCTIONS) && (CONFIG_USER_FUNCTIONS > 0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this guard is not needed, because:

  • target-specific code using the user function system, will for sure need to define the CONFIG_USER_FUNCTIONS
  • all the function calls in the common code have to be guarded with #ifdef to avoid linker errors in case the target does not support the user functions (see threads.c)
  • functions not called anywhere and unused variables are garbage-collected at link time

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 can remove the guard if needed. But if user functions are expected to be used in common code then it is not really user functions anymore and we should also modify slightly the mechanism to account for functions added from common code.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I called them "user functions" following the terminology used in the code I used at work, but a more correct term should be "tasklet" or something like that. About adding periodic functions from common code, I see that the current gps_task is a good candidate for this mechanism: if there is the GPS hardware, or if the GPS is enabled, add a periodic function which retrieves and parses the NMEA sentences.

@mdiepart mdiepart force-pushed the user_functions branch 3 times, most recently from 98e83dd to 05e8f35 Compare February 18, 2024 16:47
This thread handles a set of user functions. 
Those user functions can be either periodic (with a frequency of 1Hz, 10Hz, 20Hz, 50Hz or 100Hz) or aperiodic (asynchronous). 
Periodic functions will be called periodically depending on their scheduling. Async functions need to be triggered usign user_functions_trigger(id).

The maximum amount of user functions that can be handled have to be defined in hwconfig.h using the macro CONFIG_USER_FUNCTIONS. If this macro is not defined, the user functions thread will not be created.
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.

None yet

2 participants