-
Notifications
You must be signed in to change notification settings - Fork 3k
Add cpp API for CMSIS OS 2 EventFlags #4517
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
Conversation
@YarivCol Thanks for the PR. Also, we recommend our contributors follow Chris Beam’s seven rules of great commit messages to keep the commit history clear. To match this format, please change the subject line of your PR to the imperative mood. For example, you could change it to "Add cpp API for CMSIS OS 2 EventFlags". Thanks for your contribution. |
This PR is not done still need to fix compile errors and test it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the addition. Please make sure to add tests https://github.com/ARMmbed/mbed-os/tree/master/TESTS/mbedmicro-rtos-mbed and to update the code style to follow https://docs.mbed.com/docs/mbed-os-handbook/en/latest/cont/code_style/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks great 👍
I think it mostly just needs a few style changes.
rtos/EventFlags.cpp
Outdated
{ | ||
memset(&_obj_mem, 0, sizeof(_obj_mem)); | ||
memset(&_attr, 0, sizeof(_attr)); | ||
_attr.name = name ? name : "aplication_unnamed_eventflags"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the name just be NULL by default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I followed Mutex class implementation, when the user does not give name the Mutex is called aplication_unnamed_mutex
rtos/EventFlags.cpp
Outdated
MBED_ASSERT(_id); | ||
} | ||
|
||
uint32_t EventFlags::Set (uint32_t flags) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be lowercase snake_case EventFlags::set
rtos/EventFlags.cpp
Outdated
return osEventFlagsSet(_id, flags); | ||
} | ||
|
||
uint32_t EventFlags::Clear (uint32_t flags) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be lowercase snake_case EventFlags::clear
, the other functions should be lowercase snake_case as well.
rtos/EventFlags.h
Outdated
/** Get the current Event Flags. | ||
@return current event flags. | ||
*/ | ||
uint32_t Get ()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra paren?
rtos/EventFlags.h
Outdated
@param flags specifies the flags that shall be set. | ||
@return event flags after setting or error code if highest bit set. | ||
*/ | ||
uint32_t Set (uint32_t flags); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: We could provide a default to set and clear to set and clear all flags
uint32_t set(uint32_t flags=0xffffffff);
...
eventflags.set(); // sets all flags
rtos/EventFlags.h
Outdated
@param timeout timeout value or 0 in case of no time-out. (default: osWaitForever) | ||
@return event flags before clearing or error code if highest bit set. | ||
*/ | ||
uint32_t Wait (uint32_t flags, uint32_t options, uint32_t timeout); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: The cmsis-rtos documentation had some defaults we could use here
uint32_t wait(uint32_t flags=0xffffffff, uint32_t options=osFlagsWaitAny , uint32_t timeout=osWaitForever);
...
eventflags.wait(); // waits for any flags to get set
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you declare the constructor and copy assignment operator as private. That will disable those two operations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you write tests please? And share results (to be run at least on one platform), we will trigger then CI tests to confirm and run on multiple devices.
rtos/EventFlags.cpp
Outdated
|
||
namespace rtos { | ||
|
||
EventFlags::EventFlags() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`{`` on the new line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@0xc0170 I added test for event flags.
I did not fully understand your comment about the styling of the code, could you provide an example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
void function()
{
//body here
}
One more , who's omriarad ? Can they sign https://developer.mbed.org/contributor_agreement/ ? |
My computer was used by this user in the past, i forgot to change the user in git to mine. |
You should be able to rebase and change the user . That would be good, to avoid any confusion |
@@ -0,0 +1,50 @@ | |||
#include "mbed.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests should contain also license header, please add it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add the license header to this file please?
printf("Handling %d events...\r\n", EVENT_TO_EMIT); | ||
|
||
while (true) { | ||
Thread::wait(2 * EVENT_HANDLE_DELEY); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DELEY - DELAY typo
rtos/EventFlags.cpp
Outdated
return osEventFlagsClear(_id, flags); | ||
} | ||
|
||
uint32_t EventFlags::get () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
()
should be next to the function/method name. In this case ::get()
rtos/EventFlags.cpp
Outdated
void EventFlags::constructor(const char *name) { | ||
memset(&_obj_mem, 0, sizeof(_obj_mem)); | ||
memset(&_attr, 0, sizeof(_attr)); | ||
_attr.name = name ? name : "aplication_unnamed_eventflags"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aplication - application typo
@YarivCol I left few minor changes requested. If you can rebase, change the owner, would be appreciated. Thanks for adding the simple test. This will need to be extended to test also clear, wait methods, destructor. Can you do that? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @YarivCol thanks for submitting that! I wasn't aware it's a separate pull request I put some comments here #4580 (comment) and here #4580 (comment) can you please treat them as made against this PR.
Also we are trying to move towards more unit testing approach, please see this PR as a example #4620
Last changes 18 days ago, my comment is from 10 days ago. |
@bulislaw a rebase will not change the date in github. If the changes are newer than your comment, they will appear below your comment on github. |
Ok. I've checked the code and my comments are not addressed. |
Jenkins CI failed to compile main.cpp file : |
@YarivCol Would you like help? We would like to get this PR in. |
Yes it will be helpful, unfortunately i dont have free time to finish this PR in the near future :(. |
@YarivCol thanks for contributing that code. I'll try to finish it up in coming days. |
/morph test |
rtos/EventFlags.h
Outdated
@return event flags before clearing or error code if highest bit set (@a osFlagsError). | ||
@note flags that are specified to wait for will be automatically cleared. | ||
*/ | ||
uint32_t wait_all(uint32_t flags = 0, uint32_t timeout = osWaitForever); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uhm, how do I pass in osFlagsNoClear
now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't. I was thinking that we had issues with the RTOS APIs changing and exposing 95% of functionality in abstracted out, simpler and more intuitive way is better than having C++ shim on rtx object. Do we have a use case that osFlagsNoClear
is needed and can't be achieved another way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're already using osFlagsNoClear
in the C layer:
https://github.com/ARMmbed/mbed-os/blob/master/features/FEATURE_LWIP/lwip-interface/lwip-sys/arch/lwip_sys_arch.c#L167-L168
osFlagsNoClear
is useful when you want to flag conditions that are not immediately invalidated by the consumer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, how about I'll add a parameter to wait bool clear = true
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That works.
Why not just have the origin wait function along with wait_any and wait_all? The cmsis-rtos APIs have already gone through these iterations. I wouldn't call a standard set of API flags internal details.
Result: FAILUREYour command has finished executing! Here's what you wrote!
|
/morph test |
Result: SUCCESSYour command has finished executing! Here's what you wrote!
OutputAll builds and test passed! |
That is my fix on top of the original work, someone else needs to review it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 small things
👍 for taking over this PR @bulislaw
rtos/EventFlags.h
Outdated
/** Get the currently set Event Flags. | ||
@return set event flags. | ||
*/ | ||
uint32_t get(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could be uint32_t get() const
@@ -0,0 +1,50 @@ | |||
#include "mbed.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add the license header to this file please?
You are now contributing
EventFlags class is a wrapper for Event Flag functionality introduced in RTOS2/RTX5.
/morph test |
Result: SUCCESSYour command has finished executing! Here's what you wrote!
OutputAll builds and test passed! |
This is now ready to be integrated, please send your comments if there are still things to be addressed here. |
Can we get a todo for API docs on this? |
@sg- I can make a JIRA ticket and add them to my list of docs. Do they need to go into 5.6? |
yes! |
Description
Added the ability to set, clear or wait for event flag, it will be useful for building drivers with block like api.
for example building block device that preforms async operations on top of the spi driver to allow the system to do other tasks, in that case event flag will be waited in program, erase, etc... and the event flag will be set in the callback of async operation.