Skip to content

Commit

Permalink
Fix #1087, do not register RTOS timer for external sync
Browse files Browse the repository at this point in the history
Skip the registration of a timer in VxWorks when the assigned_signal
is 0 (this indicates an external sync function is used).
  • Loading branch information
jphickey committed Jun 25, 2021
1 parent 64a6b31 commit c8b9301
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 26 deletions.
43 changes: 26 additions & 17 deletions src/os/vxworks/src/os-impl-timebase.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,22 +225,31 @@ void OS_VxWorks_RegisterTimer(osal_id_t obj_id)
{
local = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, token);

memset(&evp, 0, sizeof(evp));
evp.sigev_notify = SIGEV_SIGNAL;
evp.sigev_signo = local->assigned_signal;
if (local->assigned_signal == 0)
{
/* nothing to register in RTOS */
status = 0;
}
else
{
memset(&evp, 0, sizeof(evp));
evp.sigev_notify = SIGEV_SIGNAL;
evp.sigev_signo = local->assigned_signal;

/*
** Create the timer
**
** The result is not returned from this function, because
** this is a different task context from the original creator.
**
** The registration status is returned through the OS_impl_timebase_table entry,
** which is checked by the creator before returning.
**
** If set to ERROR, then this task will be subsequently deleted.
*/
status = timer_create(OS_PREFERRED_CLOCK, &evp, &local->host_timerid);
}

/*
** Create the timer
**
** The result is not returned from this function, because
** this is a different task context from the original creator.
**
** The registration status is returned through the OS_impl_timebase_table entry,
** which is checked by the creator before returning.
**
** If set to ERROR, then this task will be subsequently deleted.
*/
status = timer_create(OS_PREFERRED_CLOCK, &evp, &local->host_timerid);
if (status < 0)
{
OS_DEBUG("timer_create() failed: errno=%d\n", errno);
Expand Down Expand Up @@ -529,8 +538,8 @@ int32 OS_TimeBaseSet_Impl(const OS_object_token_t *token, uint32 start_time, uin
/* There is only something to do here if we are generating a simulated tick */
if (local->assigned_signal <= 0)
{
/* An externally synced timebase does not need to be set */
return_code = OS_ERR_NOT_IMPLEMENTED;
/* An externally synced timebase does not need to be set (noop) */
return_code = OS_SUCCESS;
}
else
{
Expand Down
29 changes: 20 additions & 9 deletions src/unit-test-coverage/vxworks/src/coveragetest-timebase.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,29 @@ void Test_OS_TimeBaseCreate_Impl(void)
/*
* Check outputs of OS_VxWorks_RegisterTimer() function.
*/
UT_TimeBaseTest_ClearTimeBaseRegState(UT_INDEX_1);
UT_TimeBaseTest_CallRegisterTimer(OS_OBJECT_ID_UNDEFINED);
UtAssert_True(UT_TimeBaseTest_CheckTimeBaseRegisteredState(UT_INDEX_0), "timer successfully registered");

UT_TimeBaseTest_ClearTimeBaseRegState(UT_INDEX_1);
UT_TimeBaseTest_Setup(UT_INDEX_0, 10, false);
UT_TimeBaseTest_ClearTimeBaseRegState(UT_INDEX_0);
UT_TimeBaseTest_CallRegisterTimer(token.obj_id);
UtAssert_True(UT_TimeBaseTest_CheckTimeBaseRegisteredState(UT_INDEX_0),
"timer successfully registered, with signal");

UT_TimeBaseTest_Setup(UT_INDEX_0, 10, false);
UT_TimeBaseTest_ClearTimeBaseRegState(UT_INDEX_0);
UT_SetDefaultReturnValue(UT_KEY(OCS_timer_create), -1);
UT_TimeBaseTest_CallRegisterTimer(OS_OBJECT_ID_UNDEFINED);
UT_TimeBaseTest_CallRegisterTimer(token.obj_id);
UtAssert_True(UT_TimeBaseTest_CheckTimeBaseErrorState(UT_INDEX_0), "timer registration failure state");

UT_TimeBaseTest_ClearTimeBaseRegState(UT_INDEX_1);
UT_TimeBaseTest_Setup(UT_INDEX_0, 10, false);
UT_TimeBaseTest_ClearTimeBaseRegState(UT_INDEX_0);
UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERROR);
UT_TimeBaseTest_CallRegisterTimer(OS_OBJECT_ID_UNDEFINED);
UT_TimeBaseTest_CallRegisterTimer(token.obj_id);
UtAssert_True(!UT_TimeBaseTest_CheckTimeBaseRegisteredState(UT_INDEX_0), "timer registration bad ID");
UT_ResetState(UT_KEY(OS_ObjectIdGetById));

UT_TimeBaseTest_Setup(UT_INDEX_0, 0, false);
UT_TimeBaseTest_ClearTimeBaseRegState(UT_INDEX_0);
UT_TimeBaseTest_CallRegisterTimer(token.obj_id);
UtAssert_True(UT_TimeBaseTest_CheckTimeBaseRegisteredState(UT_INDEX_0), "timer successfully registered, no signal");
}

void Test_OS_VxWorks_SigWait(void)
Expand Down Expand Up @@ -217,7 +227,8 @@ void Test_OS_TimeBaseSet_Impl(void)
*/
OS_object_token_t token = UT_TOKEN_0;

OSAPI_TEST_FUNCTION_RC(OS_TimeBaseSet_Impl(&token, 1, 1), OS_ERR_NOT_IMPLEMENTED);
UT_TimeBaseTest_Setup(UT_INDEX_0, 0, false);
OSAPI_TEST_FUNCTION_RC(OS_TimeBaseSet_Impl(&token, 1, 1), OS_SUCCESS);

UT_TimeBaseTest_Setup(UT_INDEX_0, OCS_SIGRTMIN, false);
OSAPI_TEST_FUNCTION_RC(OS_TimeBaseSet_Impl(&token, 1, 1), OS_SUCCESS);
Expand Down

0 comments on commit c8b9301

Please sign in to comment.