Skip to content

Commit

Permalink
Added event_wait_ex, which takes callback to event enabling function …
Browse files Browse the repository at this point in the history
…as parameter.
  • Loading branch information
ptrxt committed Apr 17, 2019
1 parent c659b15 commit f58f1d7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
6 changes: 4 additions & 2 deletions inc/os_applAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ static void myTask(void) {
}
@endcode
*******************************************************************************/
#define event_wait(event) OS_WAIT_SINGLE_EVENT(event,0)
#define event_wait(event) OS_WAIT_SINGLE_EVENT(event,0,0)
#define event_wait_ex(event, cb) OS_WAIT_SINGLE_EVENT(event,0,cb)


/*********************************************************************************/
Expand Down Expand Up @@ -290,7 +291,8 @@ static void myTask(void) {
}
@endcode
*******************************************************************************/
#define event_wait_timeout(event,timeout) OS_WAIT_SINGLE_EVENT(event,timeout)
#define event_wait_timeout(event,timeout) OS_WAIT_SINGLE_EVENT(event,timeout,0)
#define event_wait_timeout_ex(event,timeout,cb) OS_WAIT_SINGLE_EVENT(event,timeout,cb)

/*********************************************************************************/
/* event_get_timeout() *//**
Expand Down
6 changes: 3 additions & 3 deletions inc/os_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ extern "C" {
#define EVENT_OFS2 11000
#define EVENT_OFS3 12000

#define OS_WAIT_SINGLE_EVENT(x,timeout) do {\
os_wait_event(running_tid,x,1,timeout);\
#define OS_WAIT_SINGLE_EVENT(x,timeout, cb) do {\
os_wait_event(running_tid,x,1,timeout, cb);\
OS_SCHEDULE(EVENT_OFS1);\
} while (0)

Expand Down Expand Up @@ -101,7 +101,7 @@ typedef struct {


void os_event_init( void );
void os_wait_event( uint8_t tid, Evt_t ev, uint8_t waitSingleEvent, uint32_t timeout );
void os_wait_event( uint8_t tid, Evt_t ev, uint8_t waitSingleEvent, uint32_t timeout, void (*cb)(void) );
void os_wait_multiple( uint8_t waitAll, ...);
void os_signal_event( Evt_t ev );
void os_event_set_signaling_tid( Evt_t ev, uint8_t tid );
Expand Down
5 changes: 4 additions & 1 deletion src/os_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,14 @@ Evt_t event_last_signaled_get(void) {
}


void os_wait_event(uint8_t tid, Evt_t ev, uint8_t waitSingleEvent, uint32_t timeout) {
void os_wait_event(uint8_t tid, Evt_t ev, uint8_t waitSingleEvent, uint32_t timeout, void (*cb)(void)) {
#if( N_TOTAL_EVENTS > 0 )
if ( ev < nEvents ) {
eventList[ ev ].signaledByTid = NO_TID;
os_task_wait_event( tid, ev, waitSingleEvent, timeout );
if (cb) {
cb();
}
}
#endif
}
Expand Down

5 comments on commit f58f1d7

@matteofranceschini
Copy link
Contributor

Choose a reason for hiding this comment

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

hi @ptrxt , would you mind making a little update to the documentation to explain with an example what a use case of the callback could be? :) I'm missing the logic behind this, but it's probably due to an incomplete knowledge about it!

@ptrxt
Copy link
Contributor Author

@ptrxt ptrxt commented on f58f1d7 Mar 9, 2020

Choose a reason for hiding this comment

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

Hi @matteofranceschini , I understand the confusion ! I will update the readme

@matteofranceschini
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you very much! I'm looking forward to it :)

@cocoOS
Copy link
Owner

@cocoOS cocoOS commented on f58f1d7 Mar 11, 2020

Choose a reason for hiding this comment

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

Please have a look, it is at the bottom.

@matteofranceschini
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, cool feature. I've had this issue a couple of times!
Thank you for the explanation!

Please sign in to comment.