/* * ======== Timer_reconfig ======== * 1. Init obj using params * 2. Reconfig Hwi * 3. Timer_init() * 4. Timer configuration (wrt emulation, external frequency etc) * 5. Timer_setPeriod() * 6. Timer_start() */ Void Timer_reconfig (Timer_Object *obj, Timer_FuncPtr tickFxn, const Timer_Params *params, Error_Block *eb) { Hwi_Params hwiParams; obj->runMode = params->runMode; obj->startMode = params->startMode; obj->altclk = params->altclk; obj->period = params->period; obj->periodType = params->periodType; obj->prevThreshold = params->prevThreshold; obj->rollovers = 0; obj->savedCurrCount = 0; if (obj->altclk) { /* if using altclk the freq is always 16MHz */ obj->extFreq.lo = 16000000; obj->extFreq.hi = 0; } else { /* else use specified extFreq */ obj->extFreq.lo = params->extFreq.lo; obj->extFreq.hi = params->extFreq.hi; } if (obj->periodType == Timer_PeriodType_MICROSECS) { if (!Timer_setPeriodMicroSecs(obj, obj->period)) { Error_raise(eb, Timer_E_cannotSupport, obj->period, 0); } } obj->arg = params->arg; obj->tickFxn = tickFxn; if (obj->tickFxn) { if (params->hwiParams) { Hwi_Params_copy(&hwiParams, (params->hwiParams)); } else { Hwi_Params_init(&hwiParams); } hwiParams.arg = (UArg)obj; Hwi_reconfig (obj->hwi, Timer_isrStub, &hwiParams); } Timer_postInit(obj, eb); if (obj->startMode == Timer_StartMode_AUTO) { Timer_start(obj); } }
/* * ======== Timer_reconfig ======== * 1. Init obj using params * 2. Reconfig Hwi * 3. Timer_init() * 4. Timer configuration (wrt emulation, external frequency etc) * 5. Timer_setPeriod() * 6. Timer_start() */ Void Timer_reconfig (Timer_Object *obj, Timer_FuncPtr tickFxn, const Timer_Params *params, Error_Block *eb) { Hwi_Params hwiParams; obj->runMode = params->runMode; obj->startMode = params->startMode; obj->period = params->period; obj->periodType = params->periodType; if (obj->periodType == Timer_PeriodType_MICROSECS) { if (!Timer_setPeriodMicroSecs(obj, obj->period)) { Error_raise(eb, Timer_E_cannotSupport, obj->period, 0); } } obj->arg = params->arg; obj->tickFxn = tickFxn; if (obj->tickFxn) { if (params->hwiParams) { Hwi_Params_copy(&hwiParams, (params->hwiParams)); } else { Hwi_Params_init(&hwiParams); } if (obj->id == 0) { hwiParams.arg = (UArg)obj; if (obj->runMode == Timer_RunMode_CONTINUOUS) { Hwi_reconfig (obj->hwi, Timer_periodicStub, &hwiParams); } else { Hwi_reconfig (obj->hwi, Timer_oneShotStub, &hwiParams); } } else { hwiParams.arg = obj->arg; Hwi_reconfig (obj->hwi, obj->tickFxn, &hwiParams); } } postInit(obj, eb); if (obj->startMode == Timer_StartMode_AUTO) { Timer_start(obj); } }
/* * ======== Timer_reconfig ======== * 1. Init obj using params * 2. Reconfig Hwi * 3. Timer_init() * 4. Timer configuration (wrt emulation, external frequency etc) * 5. Timer_setPeriod() * 6. Timer_start() */ Void Timer_reconfig (Timer_Object *obj, Timer_FuncPtr tickFxn, const Timer_Params *params, Error_Block *eb) { Hwi_Params hwiParams; UInt arBit; /* determine controlReg 'ar' value (continuous / oneshot) */ arBit = (params->runMode == Timer_RunMode_CONTINUOUS) ? 1 : 0; obj->controlRegInit = ((arBit << 1) | (params->controlRegInit.ptv << 2) | (params->controlRegInit.ce << 5) | (params->controlRegInit.free << 6)); obj->runMode = params->runMode; obj->startMode = params->startMode; obj->period = params->period; obj->periodType = params->periodType; obj->arg = params->arg; obj->tickFxn = tickFxn; if (params->extFreq.lo) { obj->extFreq.lo = params->extFreq.lo; } if (obj->tickFxn) { if (params->hwiParams) { Hwi_Params_copy(&hwiParams, (params->hwiParams)); } else { Hwi_Params_init(&hwiParams); } hwiParams.arg = obj->arg; Hwi_reconfig (obj->hwi, obj->tickFxn, &hwiParams); } postInit(obj, eb); if (obj->startMode == Timer_StartMode_AUTO) { Timer_start(obj); } }
/* * ======== Timer_Instance_init ======== * 1. Select timer based on id * 2. Mark timer as in use * 3. Save timer handle if necessary (needed by TimestampProvider on 64). * 4. Init obj using params * 5. Create Hwi if tickFxn !=NULL * 6. Timer_init() * 7. Timer configuration (wrt emulation, external frequency etc) * 8. Timer_setPeriod() * 9. Timer_start() */ Int Timer_Instance_init(Timer_Object *obj, Int id, Timer_FuncPtr tickFxn, const Timer_Params *params, Error_Block *eb) { UInt key; Int status; Hwi_Params hwiParams; UInt tempId = 0xffff; if ((id != 0) && (id != Timer_ANY)) { Error_raise(eb, Timer_E_invalidTimer, id, 0); return (1); } key = Hwi_disable(); if (id == Timer_ANY) { if ((Timer_anyMask & 1) && (Timer_module->availMask & 1)) { Timer_module->availMask &= ~(1); tempId = 0; } } else if (Timer_module->availMask & 1) { Timer_module->availMask &= ~(1); tempId = id; } Hwi_restore(key); obj->staticInst = FALSE; if (tempId == 0xffff) { Error_raise(eb, Timer_E_notAvailable, id, 0); return (NO_TIMER_AVAIL); } else { obj->id = tempId; } Timer_module->handle = obj; obj->runMode = params->runMode; obj->startMode = params->startMode; obj->period = params->period; obj->periodType = params->periodType; obj->extFreq.lo = params->extFreq.lo; obj->extFreq.hi = params->extFreq.hi; if (obj->periodType == Timer_PeriodType_MICROSECS) { if (!Timer_setPeriodMicroSecs(obj, obj->period)) { Error_raise(eb, Timer_E_cannotSupport, obj->period, 0); Hwi_restore(key); return (BAD_PERIOD); } } obj->arg = params->arg; obj->intNum = 15; obj->tickFxn = tickFxn; if (obj->tickFxn) { if (params->hwiParams) { Hwi_Params_copy(&hwiParams, (params->hwiParams)); } else { Hwi_Params_init(&hwiParams); } hwiParams.arg = (UArg)obj; if (obj->runMode == Timer_RunMode_CONTINUOUS) { obj->hwi = Hwi_create (obj->intNum, Timer_periodicStub, &hwiParams, eb); } else { obj->hwi = Hwi_create (obj->intNum, Timer_oneShotStub, &hwiParams, eb); } if (obj->hwi == NULL) { return (NO_HWI_OBJ); } } else { obj->hwi = NULL; } status = postInit(obj, eb); if (status) { return (status); } if (obj->startMode == Timer_StartMode_AUTO) { Timer_start(obj); } return (0); }
/* * ======== Timer_Instance_init ======== * 1. Select timer based on id * 2. Mark timer as in use * 3. Save timer handle if necessary (needed by TimestampProvider on 64). * 4. Init obj using params * 5. Create Hwi if tickFxn !=NULL * 6. Timer_init() * 7. Timer configuration (wrt emulation, external frequency etc) * 8. Timer_setPeriod() * 9. Timer_start() */ Int Timer_Instance_init(Timer_Object *obj, Int id, Timer_FuncPtr tickFxn, const Timer_Params *params, Error_Block *eb) { UInt key; Int i, status; Hwi_Params hwiParams; UInt tempId = 0xffff; /* make sure id is not greater than number of 32-bit timer devices */ if (id >= Timer_numTimerDevices ) { if (id != Timer_ANY) { Error_raise(eb, Timer_E_invalidTimer, id, 0); return (1); } } key = Hwi_disable(); if (id == Timer_ANY) { for (i = 0; i < Timer_numTimerDevices; i++) { if ((Timer_anyMask & (1 << i)) && (Timer_module->availMask & (1 << i))) { Timer_module->availMask &= ~(1 << i); tempId = i; break; } } } else if (Timer_module->availMask & (1 << id)) { Timer_module->availMask &= ~(1 << id); tempId = id; } Hwi_restore(key); obj->staticInst = FALSE; if (tempId == 0xffff) { Error_raise(eb, Timer_E_notAvailable, id, 0); return (2); } else { obj->id = tempId; } Timer_module->handles[obj->id] = obj; /* initialize the timer state object */ Timer_initObj(obj, tickFxn, params); /* create the Hwi object if function is specified */ if (obj->tickFxn != NULL) { if (params->hwiParams) { Hwi_Params_copy(&hwiParams, params->hwiParams); } else { Hwi_Params_init(&hwiParams); } hwiParams.eventId = Timer_module->device[obj->id].eventId; hwiParams.arg = (UArg)obj; obj->hwi = Hwi_create(obj->intNum, Timer_stub, &hwiParams, eb); if (obj->hwi == NULL) { return (4); } } else { obj->hwi = NULL; } status = Timer_postInit(obj, eb); if (status) { return (status); } if (obj->startMode == Timer_StartMode_AUTO) { Timer_start(obj); } return (0); }
/* * ======== Timer_Instance_init ======== * 1. Select timer based on id * 2. Mark timer as in use * 3. Save timer handle if necessary (needed by TimestampProvider on 64). * 4. Init obj using params * 5. Create Hwi if tickFxn !=NULL * 6. Timer_init() * 7. Timer configuration (wrt emulation, external frequency etc) * 8. Timer_setPeriod() * 9. Timer_start() */ Int Timer_Instance_init(Timer_Object *obj, Int id, Timer_FuncPtr tickFxn, const Timer_Params *params, Error_Block *eb) { UInt key; Int i, status; Hwi_Params hwiParams; UInt tempId = 0xffff; if (id >= Timer_NUM_TIMER_DEVICES) { if (id != Timer_ANY) { Error_raise(eb, Timer_E_invalidTimer, id, 0); return (1); } } key = Hwi_disable(); if (id == Timer_ANY) { for (i = 0; i < Timer_NUM_TIMER_DEVICES; i++) { if ((Timer_anyMask & (1 << i)) && (Timer_module->availMask & (1 << i))) { Timer_module->availMask &= ~(1 << i); tempId = i; break; } } } else if (Timer_module->availMask & (1 << id)) { Timer_module->availMask &= ~(1 << id); tempId = id; } Hwi_restore(key); obj->staticInst = FALSE; if (tempId == 0xffff) { Error_raise(eb, Timer_E_notAvailable, id, 0); return (2); } else { obj->id = tempId; } /* if timer id == 0 */ if (obj->id == 0) { obj->ctmid = 0; obj->intNum = 17; } else if (obj->id == 1) { obj->ctmid = 1; obj->intNum = 18; } obj->runMode = params->runMode; obj->startMode = params->startMode; obj->period = params->period; obj->periodType = params->periodType; obj->extFreq.lo = params->extFreq.lo; obj->extFreq.hi = params->extFreq.hi; if (obj->periodType == Timer_PeriodType_MICROSECS) { if (!Timer_setPeriodMicroSecs(obj, obj->period)) { Error_raise(eb, Timer_E_cannotSupport, obj->period, 0); Hwi_restore(key); return (4); } } obj->arg = params->arg; obj->tickFxn = tickFxn; if (obj->tickFxn) { if (params->hwiParams) { Hwi_Params_copy(&hwiParams, (params->hwiParams)); } else { Hwi_Params_init(&hwiParams); } /* CTM doesn't need to be acknowledged, no stub required */ hwiParams.arg = obj->arg; obj->hwi = Hwi_create (obj->intNum, obj->tickFxn, &hwiParams, eb); if (obj->hwi == NULL) { return (3); } } else { obj->hwi = NULL; } Timer_module->handles[obj->id] = obj; status = Timer_postInit(obj, eb); if (status) { return (status); } if (obj->startMode == Timer_StartMode_AUTO) { Timer_start(obj); } return (0); }
/* * ======== Timer_Instance_init ======== * 1. Select timer based on id * 2. Mark timer as in use * 3. Save timer handle if necessary (needed by TimestampProvider on 64). * 4. Init obj using params * 5. Create Hwi if tickFxn !=NULL * 6. Timer_init() * 7. Timer configuration (wrt emulation, external frequency etc) * 8. Timer_setPeriod() * 9. Timer_start() */ Int Timer_Instance_init(Timer_Object *obj, Int id, Timer_FuncPtr tickFxn, const Timer_Params *params, Error_Block *eb) { UInt key; Int i, status; Hwi_Params hwiParams; UInt arBit; UInt tempId = 0xffff; if (id >= Timer_NUM_TIMER_DEVICES) { if (id != Timer_ANY) { Error_raise(eb, Timer_E_invalidTimer, id, 0); return (1); } } key = Hwi_disable(); if (id == Timer_ANY) { for (i = 0; i < Timer_NUM_TIMER_DEVICES; i++) { if ((Timer_anyMask & (1 << i)) && (Timer_module->availMask & (1 << i))) { Timer_module->availMask &= ~(1 << i); tempId = i; break; } } } else if (Timer_module->availMask & (1 << id)) { Timer_module->availMask &= ~(1 << id); tempId = id; } Hwi_restore(key); obj->staticInst = FALSE; if (tempId == 0xffff) { Error_raise(eb, Timer_E_notAvailable, id, 0); return (2); } else { obj->id = tempId; } Timer_module->handles[obj->id] = obj; /* determine controlReg 'ar' value (continuous / oneshot) */ arBit = (params->runMode == Timer_RunMode_CONTINUOUS) ? 1 : 0; obj->controlRegInit = ((arBit << 1) | (params->controlRegInit.ptv << 2) | (params->controlRegInit.ce << 5) | (params->controlRegInit.free << 6)); obj->runMode = params->runMode; obj->startMode = params->startMode; obj->period = params->period; obj->periodType = params->periodType; obj->arg = params->arg; obj->intNum = intNumDef[obj->id]; obj->tickFxn = tickFxn; /* extFreq.hi is ignored */ if (params->extFreq.lo) { obj->extFreq.lo = params->extFreq.lo; } if (obj->tickFxn) { if (params->hwiParams) { Hwi_Params_copy(&hwiParams, (params->hwiParams)); } else { Hwi_Params_init(&hwiParams); } hwiParams.arg = obj->arg; obj->hwi = Hwi_create (obj->intNum, obj->tickFxn, &hwiParams, eb); if (obj->hwi == NULL) { return (3); } } else { obj->hwi = NULL; } status = postInit(obj, eb); if (status) { return (status); } if (obj->startMode == Timer_StartMode_AUTO) { Timer_start(obj); } return (0); }
/* * ======== Timer_Instance_init ======== * 1. Select timer based on id * 2. Mark timer as in use * 3. Save timer handle if necessary (needed by TimestampProvider on 64). * 4. Init obj using params * 5. Create Hwi if tickFxn !=NULL * 6. Timer_init() * 7. Timer configuration (wrt emulation, external frequency etc) * 8. Timer_setPeriod() * 9. Timer_start() */ Int Timer_Instance_init(Timer_Object *obj, Int id, Timer_FuncPtr tickFxn, const Timer_Params *params, Error_Block *eb) { UInt key; Int i, status; Hwi_Params hwiParams; UInt tempId = 0xffff; if (id >= Timer_NUM_TIMER_DEVICES) { if (id != Timer_ANY) { Error_raise(eb, Timer_E_invalidTimer, id, 0); return (1); } } key = Hwi_disable(); if (id == Timer_ANY) { for (i = 0; i < Timer_NUM_TIMER_DEVICES; i++) { if ((Timer_anyMask & (1 << i)) && (Timer_module->availMask & (1 << i))) { Timer_module->availMask &= ~(1 << i); tempId = i; break; } } } else if (Timer_module->availMask & (1 << id)) { Timer_module->availMask &= ~(1 << id); tempId = id; } Hwi_restore(key); obj->staticInst = FALSE; if (tempId == 0xffff) { Error_raise(eb, Timer_E_notAvailable, id, 0); return (2); } else { obj->id = tempId; } /* if timer id == 0, use systick */ if (obj->id == 0) { obj->ctmid = 0; obj->intNum = 15; } /* if timer id == 1, must select which CTM timer based on core id */ else { if (Core_getId() == 0) { obj->ctmid = 0; obj->intNum = 18; } else { obj->ctmid = 1; obj->intNum = 22; } } obj->runMode = params->runMode; obj->startMode = params->startMode; obj->period = params->period; obj->periodType = params->periodType; obj->extFreq.lo = params->extFreq.lo; obj->extFreq.hi = params->extFreq.hi; if (obj->periodType == Timer_PeriodType_MICROSECS) { if (!Timer_setPeriodMicroSecs(obj, obj->period)) { Error_raise(eb, Timer_E_cannotSupport, obj->period, 0); Hwi_restore(key); return (4); } } obj->arg = params->arg; obj->tickFxn = tickFxn; if (obj->tickFxn) { if (params->hwiParams) { Hwi_Params_copy(&hwiParams, (params->hwiParams)); } else { Hwi_Params_init(&hwiParams); } /* we'll enable the interrupt when we're ready */ hwiParams.enableInt = FALSE; /* SysTick needs to be acknowledged, use stub functions */ if (obj->id == 0) { hwiParams.arg = (UArg)obj; if (obj->runMode == Timer_RunMode_CONTINUOUS) { obj->hwi = Hwi_create (obj->intNum, Timer_periodicStub, &hwiParams, eb); } else { obj->hwi = Hwi_create (obj->intNum, Timer_oneShotStub, &hwiParams, eb); } } /* CTM doesn't need to be acknowledged, no stub required */ else { hwiParams.arg = obj->arg; obj->hwi = Hwi_create (obj->intNum, obj->tickFxn, &hwiParams, eb); } if (obj->hwi == NULL) { return (3); } } else { obj->hwi = NULL; } Timer_module->handles[obj->id] = obj; status = postInit(obj, eb); if (status) { return (status); } if (obj->startMode == Timer_StartMode_AUTO) { Timer_start(obj); } return (0); }
/* * ======== Timer_Instance_init ======== * 1. Select timer based on id * 2. Mark timer as in use * 3. Save timer handle if necessary * 4. Init obj using params * 5. Create Hwi if tickFxn !=NULL * 6. Timer_init() * 7. Timer configuration (wrt emulation, external frequency etc) * 8. Timer_setPeriod() * 9. Timer_start() */ Int Timer_Instance_init(Timer_Object *obj, Int id, Timer_FuncPtr tickFxn, const Timer_Params *params, Error_Block *eb) { UInt key; Int i, status; Hwi_Params hwiParams; UInt tempId = 0xffff; if (id >= Timer_numTimerDevices) { if (id != Timer_ANY) { Error_raise(eb, Timer_E_invalidTimer, id, 0); return (1); } } key = Hwi_disable(); if (id == Timer_ANY) { for (i = 0; i < Timer_numTimerDevices; i++) { if ((Timer_anyMask & (1 << i)) && (Timer_module->availMask & (1 << i))) { Timer_module->availMask &= ~(1 << i); tempId = i; break; } } } else if (Timer_module->availMask & (1 << id)) { Timer_module->availMask &= ~(1 << id); tempId = id; } Hwi_restore(key); obj->staticInst = FALSE; if (tempId == 0xffff) { Error_raise(eb, Timer_E_notAvailable, id, 0); return (2); } else { obj->id = tempId; } obj->runMode = params->runMode; obj->startMode = params->startMode; if (params->altclk && !Timer_supportsAltclk) { Error_raise(eb, Timer_E_noaltclk, id, 0); return (1); } obj->altclk = params->altclk; obj->period = params->period; obj->periodType = params->periodType; if (obj->altclk) { /* if using altclk the freq is always 16MHz */ obj->extFreq.lo = 16000000; obj->extFreq.hi = 0; } else { /* else use specified extFreq */ obj->extFreq.lo = params->extFreq.lo; obj->extFreq.hi = params->extFreq.hi; } obj->arg = params->arg; obj->intNum = Timer_module->device[obj->id].intNum; obj->tickFxn = tickFxn; obj->prevThreshold = params->prevThreshold; obj->rollovers = 0; obj->savedCurrCount = 0; if (obj->tickFxn) { if (params->hwiParams) { Hwi_Params_copy(&hwiParams, (params->hwiParams)); } else { Hwi_Params_init(&hwiParams); } hwiParams.arg = (UArg)obj; obj->hwi = Hwi_create (obj->intNum, Timer_isrStub, &hwiParams, eb); if (obj->hwi == NULL) { return (3); } } else { obj->hwi = NULL; } Timer_module->handles[obj->id] = obj; /* enable and reset the timer */ Timer_enableFunc(obj->id); Timer_initDevice(obj); if (obj->periodType == Timer_PeriodType_MICROSECS) { if (!Timer_setPeriodMicroSecs(obj, obj->period)) { Error_raise(eb, Timer_E_cannotSupport, obj->period, 0); Hwi_restore(key); return (4); } } status = Timer_postInit(obj, eb); if (status) { return (status); } if (obj->startMode == Timer_StartMode_AUTO) { Timer_start(obj); } return (0); }