Exemple #1
0
static SYS_TMR_HANDLE _SYS_TMR_ClientCreate ( uint32_t periodMs, uintptr_t context, SYS_TMR_CALLBACK callback, SYS_TMR_FLAGS flags )
{
    SYS_TMR_CLIENT_OBJECT *timerObj;
    SYS_TMR_CLIENT_OBJECT *newObj;
    int index;

    if(!_SYS_TMR_ReadyCheck())
    {
        return SYS_TMR_HANDLE_INVALID;
    }

    // lock user access
    _UserGblLock();

    newObj = (SYS_TMR_CLIENT_OBJECT*)SYS_TMR_HANDLE_INVALID;
    timerObj = sClientObjects + 0;
    for ( index = 0; index < sizeof(sClientObjects)/sizeof(*sClientObjects); index++, timerObj++ )
    {
        if ( timerObj->currState == SYS_TMR_CLIENT_FREE )
        {   // found free object			
            memset(timerObj, 0x0, sizeof(*timerObj));
            if(_SYS_TMR_ClientParamSet(timerObj, periodMs, context, callback))
            {
                if((flags & SYS_TMR_FLAG_PERIODIC) != 0)
                {
                    timerObj->flags.periodic = true;
                }
                else if((flags & SYS_TMR_FLAG_AUTO_DELETE) != 0)
                {
                    timerObj->flags.auto_del = true;
                }

                // enable the object, seen by the ISR thread
                timerObj->currState = SYS_TMR_CLIENT_ACTIVE;
                timerObj->isrState = SYS_TMR_CLIENT_ISR_ACTIVE;
                timerObj->isrEnable = 1;
                newObj = timerObj;
            }
            // else wrong parameters
            break;
        }
    }

    _UserGblUnlock();

    return (SYS_TMR_HANDLE)newObj;
            
} 
Exemple #2
0
bool SYS_TMR_ObjectReload ( SYS_TMR_HANDLE handle, uint32_t periodMs, uintptr_t context, SYS_TMR_CALLBACK callback)
{
    SYS_TMR_CLIENT_OBJECT * timerObj = _SYS_TMR_ClientCheckSrvLock(handle);

    if(timerObj)
    {   
        timerObj->isrEnable = 0;
        bool res = _SYS_TMR_ClientParamSet(timerObj, periodMs, context, callback);

        if(timerObj->isrState == SYS_TMR_CLIENT_ISR_MARK_DEL)
        {   // client is too late
            _SYS_TMR_ClientDelete(timerObj);
            res = false;
        }

        timerObj->isrState = SYS_TMR_CLIENT_ISR_ACTIVE;
        timerObj->isrEnable = 1;
        _SYS_TMR_ClientSrvUnlock();
        return res;
    }

    return false;
}