Example #1
0
PUBLIC void
ixOsalTicksToTimeval (UINT32 ticks, IxOsalTimeval * pTv)
{
    UINT32 tickPerSecs = 0;
    UINT32 nanoSecsPerTick = 0;
    /*
     * Reset the time value 
     */
    pTv->secs = 0;
    pTv->nsecs = 0;

    tickPerSecs = ixOsalSysClockRateGet ();
    nanoSecsPerTick = IX_OSAL_BILLION / tickPerSecs;

    /*
     * value less than 1 sec 
     */
    if (tickPerSecs > ticks)    /* value less then 1 sec */
    {
        pTv->nsecs = ticks * nanoSecsPerTick;
    }
    else
    {
        pTv->secs = ticks / tickPerSecs;
        pTv->nsecs = (ticks % tickPerSecs) * nanoSecsPerTick;
    }
}
Example #2
0
IX_STATUS
ixOsalSemaphoreWait (IxOsalSemaphore * sid, INT32 timeout)
{

    int retVal;
	UINT32 ticks;

	if ( (timeout == IX_OSAL_WAIT_FOREVER) 
	   || (timeout == IX_OSAL_WAIT_NONE))
	{
        retVal = semTake (*(SEM_ID *) sid, timeout);
	}
	else if (timeout > 0)
	{
        ticks = (ixOsalSysClockRateGet () * timeout) / 1000;
        retVal = semTake (*(SEM_ID *) sid, ticks);
	}
	else
	{
        ixOsalLog (IX_OSAL_LOG_LVL_ERROR,
            IX_OSAL_LOG_DEV_STDOUT,
            "ixOsalSemaphoreWait(): Illegal timeout value. \n", 0, 0, 0, 0, 0, 0);
        return IX_FAIL;
	}

    if (retVal != OK)
    {
        return IX_FAIL;
    }
    return IX_SUCCESS;
}
Example #3
0
PUBLIC IX_STATUS
ixOsalMutexLock (IxOsalMutex * mutex, INT32 timeout)
{
    UINT32 ticks;

    if (timeout > 0)
    {
        ticks = (ixOsalSysClockRateGet () * timeout) / 1000;
        return IX_OSAL_MAP_VX_RETCODE (semTake ((*mutex), (INT32) ticks));
    }
    else if (timeout == IX_OSAL_WAIT_FOREVER)
    {
        return IX_OSAL_MAP_VX_RETCODE (semTake ((*mutex), WAIT_FOREVER));
    }
    else if (timeout == IX_OSAL_WAIT_NONE)
    {
        return IX_OSAL_MAP_VX_RETCODE (semTake ((*mutex), NO_WAIT));
    }
    else
    {
        ixOsalLog (IX_OSAL_LOG_LVL_ERROR,
            IX_OSAL_LOG_DEV_STDOUT,
            "ixOsalMutexLock(): ERROR - wrong timeout value =  %d \n",
            timeout, 0, 0, 0, 0, 0);

        return IX_FAIL;
    }
}
Example #4
0
PUBLIC UINT32
ixOsalTimevalToTicks (IxOsalTimeval tv)
{
    UINT32 tickPerSecs = 0;
    UINT32 nanoSecsPerTick = 0;

    tickPerSecs = ixOsalSysClockRateGet ();
    nanoSecsPerTick = IX_OSAL_BILLION / tickPerSecs;
    return ((tv.secs * tickPerSecs) + (tv.nsecs / nanoSecsPerTick));
}
Example #5
0
PUBLIC void
ixOsalSleep (UINT32 milliseconds)
{
    UINT32 delay = (ixOsalSysClockRateGet () * milliseconds) / 1000;

    /*
     * Cover a rounding down to zero 
     */
    if (delay == 0 && milliseconds != 0)
        ++delay;

    taskDelay (delay);
}
Example #6
0
PRIVATE IX_STATUS
createNewTimer (IxOsalVoidFnVoidPtr func, void *param, UINT32 priority,
    UINT32 interval, BOOL isRepeating, UINT32 * timerId)
{
    UINT32 i;
    IX_STATUS status = IX_SUCCESS;
    int osTicks;
    IxOsalTimeval timeVal;

    /*
     * Check if callback is NULL 
     */
    if (func == NULL)
    {
        ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT,
            "client registered a NULL callback function\n", 0, 0, 0, 0, 0, 0);
        return IX_FAIL;
    }

    osTicks = ixOsalSysClockRateGet ();
    /*
     * Figure out how many milisecond per tick and compare against interval 
     */
    if (interval < (UINT32) (1000 / osTicks))
    {
        ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT,
            "client requested time interval (%d) finer than clock ticks\n",
            interval, 0, 0, 0, 0, 0);
        return IX_FAIL;
    }

    /*
     * Increment timerId 
     */
    *timerId = ++lastTimerId;

    status =
        ixOsalSemaphoreWait (&ixOsalCriticalSectSem, IX_OSAL_WAIT_FOREVER);
    if (status != IX_SUCCESS)
    {
        ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT,
            "createNewTimer  fail to get semaphore \n", 0, 0, 0, 0, 0, 0);
        return IX_FAIL;
    }

    for (i = 0; i < IX_OSAL_MAX_TIMERS; i++)
    {
        if (!ixOsalTimers[i].inUse)
        {
            break;
        }
    }

    if ((i >= IX_OSAL_TIMER_WARNING_THRESHOLD)
        && (ixOsalThresholdErr == FALSE))
    {
        /*
         * This error serves as an early indication that the number of
         * available timer slots will need to be increased. This is done
         * by increasing IX_OSAL_MAX_TIMERS
         */
        ixOsalLog (IX_OSAL_LOG_LVL_WARNING, IX_OSAL_LOG_DEV_STDOUT,
            "Timer threshold reached. Only %d timer slots now available\n",
            IX_OSAL_MAX_TIMERS - i, 0, 0, 0, 0, 0);
        ixOsalThresholdErr = TRUE;
    }

    if (i == IX_OSAL_MAX_TIMERS)
    {
        /*
         *  If you get this error, increase MAX_TIMERS above 
         */
        ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT,
            "Out of timer slots %d used - request ignored\n",
            i, 0, 0, 0, 0, 0);
        status = IX_FAIL;
    }
    else
    {
        ixOsalTimers[i].inUse = TRUE;

        IX_OSAL_MS_TO_TIMEVAL (interval, &timeVal);

        ixOsalTimers[i].period = timeVal;
        ixOsalTimers[i].isRepeating = isRepeating;
        ixOsalTimeGet (&(ixOsalTimers[i].expires));
        IX_OSAL_TIME_ADD ((ixOsalTimers[i].expires), (ixOsalTimers[i].period))
            ixOsalTimers[i].priority = priority;
        ixOsalTimers[i].callback = func;
        ixOsalTimers[i].callbackParam = param;
        ixOsalTimers[i].id = *timerId;

        if ((i) >= ixOsalHigestTimeSlotUsed)
        {
            ixOsalHigestTimeSlotUsed = i + 1;
        }

        status = ixOsalSemaphorePost (&ixOsalTimerRecalcSem);
        if (status != IX_SUCCESS)
        {
            ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT,
                "createNewTimer:  fail to release semaphore \n",
                0, 0, 0, 0, 0, 0);
            return IX_FAIL;
        }

    }

    status = ixOsalSemaphorePost (&ixOsalCriticalSectSem);
    if (status != IX_SUCCESS)
    {
        ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT,
            "createNewTimer:  fail to release semaphore: ixOsalCriticalSectSem \n",
            0, 0, 0, 0, 0, 0);
        return IX_FAIL;
    }

    return status;
}