in FreeRTOS-Plus-POSIX/source/FreeRTOS_POSIX_timer.c [101:149]
int timer_create( clockid_t clockid,
struct sigevent * evp,
timer_t * timerid )
{
int iStatus = 0;
timer_internal_t * pxTimer = NULL;
/* Silence warnings about unused parameters. */
( void ) clockid;
/* POSIX specifies that when evp is NULL, the behavior shall be as is
* sigev_notify is SIGEV_SIGNAL. SIGEV_SIGNAL is currently not supported. */
if( ( evp == NULL ) || ( evp->sigev_notify == SIGEV_SIGNAL ) )
{
errno = ENOTSUP;
iStatus = -1;
}
/* Allocate memory for a new timer object. */
if( iStatus == 0 )
{
pxTimer = pvPortMalloc( sizeof( timer_internal_t ) );
if( pxTimer == NULL )
{
errno = EAGAIN;
iStatus = -1;
}
}
if( iStatus == 0 )
{
/* Copy the event notification structure and set the current timer period. */
pxTimer->xTimerEvent = *evp;
pxTimer->xTimerPeriod = 0;
/* Create a new FreeRTOS timer. This call will not fail because the
* memory for it has already been allocated, so the output parameter is
* also set. */
*timerid = ( timer_t ) xTimerCreateStatic( posixconfigTIMER_NAME, /* Timer name. */
portMAX_DELAY, /* Initial timer period. Timers are created disarmed. */
pdFALSE, /* Don't auto-reload timer. */
( void * ) pxTimer, /* Timer id. */
prvTimerCallback, /* Timer expiration callback. */
&pxTimer->xTimerBuffer ); /* Pre-allocated memory for timer. */
}
return iStatus;
}