Skip to content

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

Merged
merged 3 commits into from
Aug 21, 2017
Merged

Add cpp API for CMSIS OS 2 EventFlags #4517

merged 3 commits into from
Aug 21, 2017

Conversation

YarivCol
Copy link
Contributor

@YarivCol YarivCol commented Jun 9, 2017

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.

@AnotherButler
Copy link
Contributor

@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.

@YarivCol YarivCol changed the title Cpp api for cmsis os 2 EventFlags Add cpp API for CMSIS OS 2 EventFlags Jun 9, 2017
@YarivCol
Copy link
Contributor Author

This PR is not done still need to fix compile errors and test it

sg-
sg- previously requested changes Jun 15, 2017
Copy link
Contributor

@sg- sg- left a 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/

Copy link
Contributor

@geky geky left a 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.

{
memset(&_obj_mem, 0, sizeof(_obj_mem));
memset(&_attr, 0, sizeof(_attr));
_attr.name = name ? name : "aplication_unnamed_eventflags";
Copy link
Contributor

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?

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 followed Mutex class implementation, when the user does not give name the Mutex is called aplication_unnamed_mutex

MBED_ASSERT(_id);
}

uint32_t EventFlags::Set (uint32_t flags)
Copy link
Contributor

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

return osEventFlagsSet(_id, flags);
}

uint32_t EventFlags::Clear (uint32_t flags)
Copy link
Contributor

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.

/** Get the current Event Flags.
@return current event flags.
*/
uint32_t Get ());
Copy link
Contributor

Choose a reason for hiding this comment

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

extra paren?

@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);
Copy link
Contributor

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

@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);
Copy link
Contributor

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

Copy link
Member

@pan- pan- left a 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.

Copy link
Contributor

@0xc0170 0xc0170 left a 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.


namespace rtos {

EventFlags::EventFlags() {
Copy link
Contributor

Choose a reason for hiding this comment

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

`{`` on the new line

Copy link
Contributor Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

void function()
{
    //body here
}

@0xc0170
Copy link
Contributor

0xc0170 commented Jun 22, 2017

One more , who's omriarad ? Can they sign https://developer.mbed.org/contributor_agreement/ ?

@YarivCol
Copy link
Contributor Author

My computer was used by this user in the past, i forgot to change the user in git to mine.
All the changes in this PR were made by me (YarivCol).

@0xc0170
Copy link
Contributor

0xc0170 commented Jun 22, 2017

My computer was used by this user in the past, i forgot to change the user in git to mine.
All the changes in this PR were made by me (YarivCol).

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"
Copy link
Contributor

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

Copy link
Contributor

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);
Copy link
Contributor

Choose a reason for hiding this comment

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

DELEY - DELAY typo

return osEventFlagsClear(_id, flags);
}

uint32_t EventFlags::get () {
Copy link
Contributor

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()

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";
Copy link
Contributor

Choose a reason for hiding this comment

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

aplication - application typo

@0xc0170
Copy link
Contributor

0xc0170 commented Jun 26, 2017

@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?

Copy link
Member

@bulislaw bulislaw left a 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

@theotherjimmy
Copy link
Contributor

@sg- @0xc0170 @bulislaw It looks like some changes have happened on this PR since you last reviewed. Could you take a look?

@bulislaw
Copy link
Member

Last changes 18 days ago, my comment is from 10 days ago.

@theotherjimmy
Copy link
Contributor

@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.

@bulislaw
Copy link
Member

Ok. I've checked the code and my comments are not addressed.

@theotherjimmy
Copy link
Contributor

theotherjimmy commented Jul 10, 2017

Thanks! @YarivCol Could please you address the comments made by @0xc0170 and @bulislaw?

@0xc0170
Copy link
Contributor

0xc0170 commented Jul 11, 2017

Jenkins CI failed to compile main.cpp file : Error: main.cpp@23,21: request for member ‘wait’ in ‘event_flags’, which is of non-class type ‘rtos::EventFlags()’

@theotherjimmy
Copy link
Contributor

@YarivCol Would you like help? We would like to get this PR in.

@YarivCol
Copy link
Contributor Author

Yes it will be helpful, unfortunately i dont have free time to finish this PR in the near future :(.

@bulislaw
Copy link
Member

bulislaw commented Jul 31, 2017

@YarivCol thanks for contributing that code. I'll try to finish it up in coming days.

@bulislaw
Copy link
Member

bulislaw commented Aug 3, 2017

/morph test

@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);
Copy link
Contributor

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?

Copy link
Member

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?

Copy link
Contributor

@geky geky Aug 3, 2017

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.

Copy link
Member

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?

Copy link
Contributor

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.

@mbed-bot
Copy link

mbed-bot commented Aug 3, 2017

Result: FAILURE

Your command has finished executing! Here's what you wrote!

/morph test

@bulislaw
Copy link
Member

bulislaw commented Aug 4, 2017

/morph test

@mbed-bot
Copy link

mbed-bot commented Aug 4, 2017

Result: SUCCESS

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 936

All builds and test passed!

@0xc0170
Copy link
Contributor

0xc0170 commented Aug 4, 2017

The last round of the review? @sg- and @bulislaw please review again

@bulislaw
Copy link
Member

bulislaw commented Aug 4, 2017

That is my fix on top of the original work, someone else needs to review it.

Copy link
Contributor

@0xc0170 0xc0170 left a 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

/** Get the currently set Event Flags.
@return set event flags.
*/
uint32_t get();
Copy link
Contributor

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"
Copy link
Contributor

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?

@theotherjimmy theotherjimmy dismissed stale reviews from bulislaw and sg- August 7, 2017 15:08

You are now contributing

@theotherjimmy
Copy link
Contributor

@bulislaw Could you address @0xc0170's comments?

YarivCol and others added 3 commits August 15, 2017 13:27
@bulislaw
Copy link
Member

/morph test

@mbed-bot
Copy link

Result: SUCCESS

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 1045

All builds and test passed!

@0xc0170
Copy link
Contributor

0xc0170 commented Aug 16, 2017

This is now ready to be integrated, please send your comments if there are still things to be addressed here.

@sg-
Copy link
Contributor

sg- commented Aug 21, 2017

Can we get a todo for API docs on this?

@AnotherButler
Copy link
Contributor

@sg- I can make a JIRA ticket and add them to my list of docs. Do they need to go into 5.6?

@sg-
Copy link
Contributor

sg- commented Aug 22, 2017

yes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants