events: Simplify task_event_recv() API family

Changes the event AIP so that the timeout parameter must be specified
when invoking task_event_recv() thereby making the following APIs obsolete:

	task_event_recv()
	task_event_recv_wait()
	task_event_recv_wait_timeout()
	_task_event_recv()

Change-Id: I165a8efbdedb431fee0c20e9ad1f1942c04124c0
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
This commit is contained in:
Peter Mitsis 2015-12-07 15:36:25 -05:00 committed by Anas Nashif
commit a67b7070b7
9 changed files with 65 additions and 111 deletions

View file

@ -154,7 +154,7 @@ This code processes events of a single type using a task.
while (1) {
/* wait for a key press to be signalled */
task_event_recv(KEYPRESS);
task_event_recv(KEYPRESS, TICKS_NONE);
/* determine what key was pressed */
char c = get_keypress();
@ -198,7 +198,7 @@ so that the receiving task only wakes up when needed.
while (1) {
/* wait for a key press to be signalled */
task_event_recv(KEYPRESS);
task_event_recv(KEYPRESS, TICKS_NONE);
/* process saved key press, which must be a digit */
...
@ -220,13 +220,7 @@ The following Event APIs are provided by :file:`microkernel.h`:
Signal an event from a task.
:c:func:`task_event_recv()`
Tests for an event signal without waiting.
:c:func:`task_event_recv_wait()`
Waits for an event signal.
:c:func:`task_event_recv_wait_timeout()`
Waits for an event signal for a specified time period.
:cpp:func:`task_event_handler_set()`
Registers an event handler function for an event.
Registers an event handler function for an event.

View file

@ -38,25 +38,6 @@ extern "C" {
/* well-known events */
extern const kevent_t TICK_EVENT;
/**
* @cond internal
*/
/**
*
* @brief Test for event request
*
* This routine tests an event to see if it has been signaled.
*
* @param event Event for which to test.
* @param time Maximum number of ticks to wait for event.
*
* @return RC_OK, RC_FAIL, RC_TIME on success, failure, timeout respectively
*/
extern int _task_event_recv(kevent_t event, int32_t time);
/**
* @endcond
*/
/**
*
* @brief Signal an event from an ISR
@ -118,43 +99,23 @@ extern int task_event_send(kevent_t event);
/**
*
* @brief Test for event request
* @brief Test for event request with timeout
*
* This routine tests an event to see if it has been signaled.
*
* @param event Event for which to test.
* @param timeout Affects the action taken should the event not yet be
* signaled. If TICKS_NONE, then return immediately. If TICKS_UNLIMITED, then
* wait as long as necessary. Otherwise wait up to the specified number of
* ticks before timing out.
*
* @return RC_OK, RC_FAIL, RC_TIME on success, failure, timeout respectively
* @retval RC_OK Successfully received signaled event
* @retval RC_TIME Timed out while waiting for signaled event
* @retval RC_FAIL Failed to immediately receive signaled event when
* @a timeout = TICKS_NONE
*/
#define task_event_recv(event) _task_event_recv(event, TICKS_NONE)
extern int task_event_recv(kevent_t event, int32_t timeout);
/**
*
* @brief Test for event request with wait
*
* This routine tests an event to see if it has been signaled.
*
* @param event Event for which to test.
*
* @return RC_OK, RC_FAIL, RC_TIME on success, failure, timeout respectively
*/
#define task_event_recv_wait(event) _task_event_recv(event, TICKS_UNLIMITED)
#ifdef CONFIG_SYS_CLOCK_EXISTS
/**
*
* @brief Test for event request with time out
*
* This routine tests an event to see if it has been signaled.
*
* @param event Event for which to test.
* @param time Maximum number of ticks to wait for event.
*
* @return RC_OK, RC_FAIL, RC_TIME on success, failure, timeout respectively
*/
#define task_event_recv_wait_timeout(event, time) _task_event_recv(event, time)
#endif /* CONFIG_SYS_CLOCK_EXISTS */
/**
* @}
*/

View file

@ -130,7 +130,7 @@ void _k_event_test(struct k_args *A)
}
}
int _task_event_recv(kevent_t event, int32_t time)
int task_event_recv(kevent_t event, int32_t timeout)
{
struct k_args A;
@ -138,7 +138,7 @@ int _task_event_recv(kevent_t event, int32_t time)
A.Comm = _K_SVC_EVENT_TEST;
A.args.e1.event = event;
A.Time.ticks = time;
A.Time.ticks = timeout;
KERNEL_ENTRY(&A);
return A.Time.rcode;
}

View file

@ -123,7 +123,7 @@ void task_irq_free(kirq_t irq_obj)
irq_disable(task_irq_object[irq_obj].irq);
RELEASE_VECTOR(task_irq_object[irq_obj].vector);
(void)task_event_recv(task_irq_object[irq_obj].event);
(void)task_event_recv(task_irq_object[irq_obj].event, TICKS_NONE);
task_irq_object[irq_obj].task_id = INVALID_TASK;
}
@ -151,7 +151,7 @@ int task_irq_wait(kirq_t irq_obj, int32_t timeout)
__ASSERT(task_irq_object[irq_obj].task_id == task_id_get(),
"Incorrect Task ID");
return _task_event_recv(task_irq_object[irq_obj].event, timeout);
return task_event_recv(task_irq_object[irq_obj].event, timeout);
}
/**

View file

@ -78,7 +78,7 @@ void event_test(void)
return; /* error */
}
#endif /* EVENT_CHECK */
nReturn = task_event_recv(TEST_EVENT);
nReturn = task_event_recv(TEST_EVENT, TICKS_NONE);
#ifdef EVENT_CHECK
if (nReturn != RC_OK) {
PRINT_STRING(EventTestErr, output_file);
@ -102,7 +102,7 @@ void event_test(void)
return; /* error */
}
#endif /* EVENT_CHECK */
nReturn = task_event_recv_wait(TEST_EVENT);
nReturn = task_event_recv(TEST_EVENT, TICKS_UNLIMITED);
#ifdef EVENT_CHECK
if (nReturn != RC_OK) {
PRINT_STRING(EventTestErr, output_file);

View file

@ -61,7 +61,7 @@ NANO_CPU_INT_REGISTER(isrDummyIntStub, -1, -1, TEST_SOFT_INT, 0);
static pfunc func_array[] = {
/* event functions */
(pfunc)task_event_send,
(pfunc)_task_event_recv,
(pfunc)task_event_recv,
/* mutex functions */
(pfunc)_task_mutex_lock,
(pfunc)_task_mutex_unlock,

View file

@ -80,7 +80,7 @@ int microIntToTaskEvt(void)
" (rescheduled)");
TICK_SYNCH();
task_sem_give(INTSEMA);
task_event_recv_wait(EVENT0);
task_event_recv(EVENT0, TICKS_UNLIMITED);
timestamp = TIME_STAMP_DELTA_GET(timestamp);
PRINT_FORMAT(" switch time is %lu tcs = %lu nsec",
timestamp, SYS_CLOCK_HW_CYCLES_TO_NS(timestamp));

View file

@ -33,9 +33,9 @@ Sample Output:
tc_start() - Test Microkernel Events
Microkernel objects initialized
Testing task_event_recv() and task_event_send() ...
Testing task_event_recv_wait() and task_event_send() ...
Testing task_event_recv_wait_timeout() and task_event_send() ...
Testing task_event_recv(TICKS_NONE) and task_event_send() ...
Testing task_event_recv(TICKS_UNLIMITED) and task_event_send() ...
Testing task_event_recv(timeout) and task_event_send() ...
Testing isr_event_send() ...
Testing fiber_event_send() ...
Testing task_event_handler_set() ...

View file

@ -23,8 +23,6 @@
* task_event_send()
* isr_event_send()
* task_event_recv()
* task_event_recv_wait()
* task_event_recv_wait_timeout()
*/
#include <tc_util.h>
@ -97,7 +95,7 @@ void microObjectsInit(void)
/**
*
* @brief Test the task_event_recv() API
* @brief Test the task_event_recv(TICKS_NONE) API
*
* There are two cases to be tested here. The first is for testing for an
* event when there is one. The second is for testing for an event when there
@ -118,14 +116,14 @@ int eventNoWaitTest(void)
return TC_FAIL;
}
rv = task_event_recv(EVENT_ID);
rv = task_event_recv(EVENT_ID, TICKS_NONE);
if (rv != RC_OK) {
TC_ERROR("task_event_recv() returned %d, not %d\n", rv, RC_OK);
return TC_FAIL;
}
/* No event has been signalled */
rv = task_event_recv(EVENT_ID);
rv = task_event_recv(EVENT_ID, TICKS_NONE);
if (rv != RC_FAIL) {
TC_ERROR("task_event_recv() returned %d, not %d\n", rv, RC_FAIL);
return TC_FAIL;
@ -136,9 +134,10 @@ int eventNoWaitTest(void)
/**
*
* @brief Test the task_event_recv_wait() API
* @brief Test the task_event_recv(TICKS_UNLIMITED) API
*
* This test checks task_event_recv_wait() against the following cases:
* This test checks task_event_recv(TICKS_UNLIMITED) against the following
* cases:
* 1. There is already an event waiting (signalled from a task and ISR).
* 2. The current task must wait on the event until it is signalled
* from either another task, an ISR or a fiber.
@ -152,53 +151,53 @@ int eventWaitTest(void)
int i; /* loop counter */
/*
* task_event_recv_wait() to return immediately as there will already be
* task_event_recv() to return immediately as there will already be
* an event by a task.
*/
task_event_send(EVENT_ID);
rv = task_event_recv_wait(EVENT_ID);
rv = task_event_recv(EVENT_ID, TICKS_UNLIMITED);
if (rv != RC_OK) {
TC_ERROR("Task: task_event_recv_wait() returned %d, not %d\n", rv, RC_OK);
TC_ERROR("Task: task_event_recv() returned %d, not %d\n", rv, RC_OK);
return TC_FAIL;
}
/*
* task_event_recv_wait() to return immediately as there will already be
* task_event_recv() to return immediately as there will already be
* an event made ready by an ISR.
*/
isrInfo.event = EVENT_ID;
_trigger_isrEventSignal();
rv = task_event_recv_wait(EVENT_ID);
rv = task_event_recv(EVENT_ID, TICKS_UNLIMITED);
if (rv != RC_OK) {
TC_ERROR("ISR: task_event_recv_wait() returned %d, not %d\n", rv, RC_OK);
TC_ERROR("ISR: task_event_recv() returned %d, not %d\n", rv, RC_OK);
return TC_FAIL;
}
/*
* task_event_recv_wait() to return immediately as there will already be
* task_event_recv() to return immediately as there will already be
* an event made ready by a fiber.
*/
releaseTestFiber();
rv = task_event_recv_wait(EVENT_ID);
rv = task_event_recv(EVENT_ID, TICKS_UNLIMITED);
if (rv != RC_OK) {
TC_ERROR("Fiber: task_event_recv_wait() returned %d, not %d\n", rv, RC_OK);
TC_ERROR("Fiber: task_event_recv() returned %d, not %d\n", rv, RC_OK);
return TC_FAIL;
}
task_sem_give(ALTERNATE_SEM); /* Wake the AlternateTask */
/*
* The 1st pass, task_event_recv_wait() will be signalled from a task,
* The 1st pass, task_event_recv() will be signalled from a task,
* from an ISR for the second and from a fiber third.
*/
for (i = 0; i < 3; i++) {
rv = task_event_recv_wait(EVENT_ID);
rv = task_event_recv(EVENT_ID, TICKS_UNLIMITED);
if (rv != RC_OK) {
TC_ERROR("task_event_recv_wait() returned %d, not %d\n", rv, RC_OK);
TC_ERROR("task_event_recv() returned %d, not %d\n", rv, RC_OK);
return TC_FAIL;
}
}
@ -208,9 +207,9 @@ int eventWaitTest(void)
/**
*
* @brief Test the task_event_recv_wait_timeout() API
* @brief Test the task_event_recv(timeout) API
*
* This test checks task_event_recv_wait_timeout() against the following cases:
* This test checks task_event_recv(timeout) against the following cases:
* 1. The current task times out while waiting for the event.
* 2. There is already an event waiting (signalled from a task).
* 3. The current task must wait on the event until it is signalled
@ -225,31 +224,31 @@ int eventTimeoutTest(void)
int i; /* loop counter */
/* Timeout while waiting for the event */
rv = task_event_recv_wait_timeout(EVENT_ID, MSEC(100));
rv = task_event_recv(EVENT_ID, MSEC(100));
if (rv != RC_TIME) {
TC_ERROR("task_event_recv_wait_timeout() returned %d, not %d\n", rv, RC_TIME);
TC_ERROR("task_event_recv() returned %d, not %d\n", rv, RC_TIME);
return TC_FAIL;
}
/* Let there be an event already waiting to be tested */
task_event_send(EVENT_ID);
rv = task_event_recv_wait_timeout(EVENT_ID, MSEC(100));
rv = task_event_recv(EVENT_ID, MSEC(100));
if (rv != RC_OK) {
TC_ERROR("task_event_recv_wait_timeout() returned %d, not %d\n", rv, RC_OK);
TC_ERROR("task_event_recv() returned %d, not %d\n", rv, RC_OK);
return TC_FAIL;
}
task_sem_give(ALTERNATE_SEM); /* Wake AlternateTask() */
/*
* The 1st pass, task_event_recv_wait_timeout() will be signalled from a task,
* The 1st pass, task_event_recv(timeout) will be signalled from a task,
* from an ISR for the second and from a fiber for the third.
*/
for (i = 0; i < 3; i++) {
rv = task_event_recv_wait_timeout(EVENT_ID, MSEC(100));
rv = task_event_recv(EVENT_ID, MSEC(100));
if (rv != RC_OK) {
TC_ERROR("task_event_recv_wait() returned %d, not %d\n", rv, RC_OK);
TC_ERROR("task_event_recv() returned %d, not %d\n", rv, RC_OK);
return TC_FAIL;
}
}
@ -283,14 +282,14 @@ int isrEventSignalTest(void)
_trigger_isrEventSignal();
_trigger_isrEventSignal();
rv = task_event_recv(EVENT_ID);
rv = task_event_recv(EVENT_ID, TICKS_NONE);
if (rv != RC_OK) {
TC_ERROR("task_event_recv() returned %d, not %d\n", rv, RC_OK);
return TC_FAIL;
}
/* The second event signal should be "lost" */
rv = task_event_recv(EVENT_ID);
rv = task_event_recv(EVENT_ID, TICKS_NONE);
if (rv != RC_FAIL) {
TC_ERROR("task_event_recv() returned %d, not %d\n", rv, RC_FAIL);
return TC_FAIL;
@ -312,7 +311,7 @@ int isrEventSignalTest(void)
int fiberEventSignalTest(void)
{
int rv; /* return value from task_event_recv() */
int rv; /* return value from task_event_recv(TICKS_NONE) */
/*
* Trigger two fiber event signals. Only one should be detected.
@ -320,14 +319,14 @@ int fiberEventSignalTest(void)
releaseTestFiber();
rv = task_event_recv(EVENT_ID);
rv = task_event_recv(EVENT_ID, TICKS_NONE);
if (rv != RC_OK) {
TC_ERROR("task_event_recv() returned %d, not %d\n", rv, RC_OK);
return TC_FAIL;
}
/* The second event signal should be "lost" */
rv = task_event_recv(EVENT_ID);
rv = task_event_recv(EVENT_ID, TICKS_NONE);
if (rv != RC_FAIL) {
TC_ERROR("task_event_recv() returned %d, not %d\n", rv, RC_FAIL);
return TC_FAIL;
@ -417,9 +416,9 @@ int eventSignalHandlerTest(void)
*/
task_sem_give(ALTERNATE_SEM); /* Wake alternate task */
rv = task_event_recv_wait_timeout(EVENT_ID, MSEC(100));
rv = task_event_recv(EVENT_ID, MSEC(100));
if (rv != RC_TIME) {
TC_ERROR("task_event_recv_wait_timeout() returned %d not %d\n", rv, RC_TIME);
TC_ERROR("task_event_recv() returned %d not %d\n", rv, RC_TIME);
return TC_FAIL;
}
@ -429,9 +428,9 @@ int eventSignalHandlerTest(void)
*/
task_sem_give(ALTERNATE_SEM); /* Wake alternate task again */
rv = task_event_recv_wait_timeout(EVENT_ID, MSEC(100));
rv = task_event_recv(EVENT_ID, MSEC(100));
if (rv != RC_OK) {
TC_ERROR("task_event_recv_wait_timeout() returned %d not %d\n", rv, RC_OK);
TC_ERROR("task_event_recv() returned %d not %d\n", rv, RC_OK);
return TC_FAIL;
}
@ -478,13 +477,13 @@ int eventSignalHandlerTest(void)
/* Clear out the waiting events */
rv = task_event_recv(EVENT_ID);
rv = task_event_recv(EVENT_ID, TICKS_NONE);
if (rv != RC_OK) {
TC_ERROR("task_event_recv() returned %d not %d\n", rv, RC_OK);
return TC_FAIL;
}
rv = task_event_recv(ALT_EVENT);
rv = task_event_recv(ALT_EVENT, TICKS_NONE);
if (rv != RC_OK) {
TC_ERROR("task_event_recv() returned %d not %d\n", rv, RC_OK);
return TC_FAIL;
@ -546,19 +545,19 @@ void RegressionTask(void)
microObjectsInit();
TC_PRINT("Testing task_event_recv() and task_event_send() ...\n");
TC_PRINT("Testing task_event_recv(TICKS_NONE) and task_event_send() ...\n");
tcRC = eventNoWaitTest();
if (tcRC != TC_PASS) {
goto doneTests;
}
TC_PRINT("Testing task_event_recv_wait() and task_event_send() ...\n");
TC_PRINT("Testing task_event_recv(TICKS_UNLIMITED) and task_event_send() ...\n");
tcRC = eventWaitTest();
if (tcRC != TC_PASS) {
goto doneTests;
}
TC_PRINT("Testing task_event_recv_wait_timeout() and task_event_send() ...\n");
TC_PRINT("Testing task_event_recv(timeout) and task_event_send() ...\n");
tcRC = eventTimeoutTest();
if (tcRC != TC_PASS) {
goto doneTests;