/********************************************************************* * @fn Util_stopClock * * @brief Stop a clock. * * @param pClock - pointer to clock struct * * @return none */ void Util_stopClock(Clock_Struct *pClock) { Clock_Handle handle = Clock_handle(pClock); // Stop clock instance Clock_stop(handle); }
/********************************************************************* * @fn Util_rescheduleClock * * @brief Reschedule a clock by changing the timeout and period values. * * @param pClock - pointer to clock struct * @param clockPeriod - longevity of clock timer in milliseconds * @return none */ void Util_rescheduleClock(Clock_Struct *pClock, uint32_t clockPeriod) { bool running; uint32_t clockTicks; Clock_Handle handle; handle = Clock_handle(pClock); running = Clock_isActive(handle); if (running) { Clock_stop(handle); } // Convert period in milliseconds to ticks. clockTicks = clockPeriod * (1000 / Clock_tickPeriod); Clock_setTimeout(handle, clockTicks); Clock_setPeriod(handle, clockTicks); if (running) { Clock_start(handle); } }
static Int32 IpcFramesInLink_deletePrdObj(IpcFramesInLink_Obj * pObj) { /* Stop the clock */ Clock_stop(pObj->prd.clkHandle); Clock_destruct(&(pObj->prd.clkStruct)); pObj->prd.clkHandle = NULL; pObj->prd.clkStarted = FALSE; return IPC_FRAMES_IN_LINK_S_SUCCESS; }
Int32 NullSrcLink_drvStop(NullSrcLink_Obj * pObj) { Clock_stop(pObj->timer); #ifdef SYSTEM_DEBUG_NULL Vps_printf(" %d: NULL_SRC: Stop Done !!!\n", Utils_getCurTimeInMsec()); #endif return FVID2_SOK; }
/* * ======== Event_post ======== */ Void Event_post(Event_Object *event, UInt eventId) { UInt tskKey, hwiKey; Event_PendElem *elem; Queue_Handle pendQ; Assert_isTrue((eventId != 0), Event_A_nullEventId); Log_write3(Event_LM_post, (UArg)event, (UArg)event->postedEvents, (UArg)eventId); pendQ = Event_Instance_State_pendQ(event); /* atomically post this event */ hwiKey = Hwi_disable(); /* or in this eventId */ event->postedEvents |= eventId; /* confirm that ANY tasks are pending on this event */ if (Queue_empty(pendQ)) { Hwi_restore(hwiKey); return; } tskKey = Task_disable(); /* examine pendElem on pendQ */ elem = (Event_PendElem *)Queue_head(pendQ); /* check for match, consume matching eventIds if so. */ elem->matchingEvents = Event_checkEvents(event, elem->andMask, elem->orMask); if (elem->matchingEvents != 0) { /* remove event elem from elem queue */ Queue_remove((Queue_Elem *)elem); /* mark the Event as having been posted */ elem->pendState = Event_PendState_POSTED; /* disable Clock object */ if (BIOS_clockEnabled && (elem->tpElem.clock != NULL)) { Clock_stop(elem->tpElem.clock); } /* put task back into readyQ */ Task_unblockI(elem->tpElem.task, hwiKey); } Hwi_restore(hwiKey); /* context switch may occur here */ Task_restore(tskKey); }
void LCD_Disable() { Clock_stop(LCD_CLOCK); ScibRegs.SCICTL1.all =0x0000; EALLOW; GpioCtrlRegs.GPAPUD.bit.GPIO14 = 1; GpioCtrlRegs.GPAMUX1.bit.GPIO14 = 0; GpioDataRegs.GPACLEAR.bit.GPIO14 = 1; EDIS; LCD_S.init = 0; }
/********************************************************************* * @fn SensorTagIO_reset * * @brief Reset characteristics * * @param none * * @return none */ void SensorTagIO_reset(void) { ioValue = sensorTestResult(); Io_setParameter( SENSOR_DATA, 1, &ioValue); ioMode = IO_MODE_LOCAL; Io_setParameter( SENSOR_CONF, 1, &ioMode); // Normal mode; make sure LEDs and buzzer are off PIN_setOutputValue(hGpioPin, Board_LED1, Board_LED_OFF); PIN_setOutputValue(hGpioPin, Board_LED2, Board_LED_OFF); Clock_stop(buzzClockHandle); PIN_setOutputValue(hGpioPin, Board_BUZZER, Board_BUZZER_OFF); }
static Int32 IpcFramesInLink_reconfigPrdObj(IpcFramesInLink_Obj * pObj, UInt period) { UTILS_assert(pObj->prd.clkHandle != NULL); if (TRUE == pObj->prd.clkStarted) { Clock_stop(pObj->prd.clkHandle); } Clock_setPeriod(pObj->prd.clkHandle, 0); Clock_setTimeout(pObj->prd.clkHandle, period); Clock_start(pObj->prd.clkHandle); return IPC_FRAMES_IN_LINK_S_SUCCESS; }
/********************************************************************* * @fn Util_restartClock * * @brief Restart a clock by changing the timeout. * * @param pClock - pointer to clock struct * @param clockTimeout - longevity of clock timer in milliseconds * * @return none */ void Util_restartClock(Clock_Struct *pClock, uint32_t clockTimeout) { uint32_t clockTicks; Clock_Handle handle; handle = Clock_handle(pClock); if (Clock_isActive(handle)) { // Stop clock first Clock_stop(handle); } // Convert timeout in milliseconds to ticks. clockTicks = clockTimeout * (1000 / Clock_tickPeriod); // Set the initial timeout Clock_setTimeout(handle, clockTicks); // Start clock instance Clock_start(handle); }
/********************************************************************* * @fn SensorTagIO_processCharChangeEvt * * @brief Process a change in the IO characteristics * * @return none */ void SensorTagIO_processCharChangeEvt(uint8_t paramID) { if( paramID == SENSOR_CONF ) { Io_getParameter(SENSOR_CONF, &ioMode); if (ioMode == IO_MODE_SELFTEST) { ioValue = sensorTestResult(); Io_setParameter(SENSOR_DATA, 1, &ioValue); } else { // Mode change: make sure LEDs and buzzer are off Io_setParameter(SENSOR_DATA, 1, &ioValue); PIN_setOutputValue(hGpioPin, Board_LED1, Board_LED_OFF); PIN_setOutputValue(hGpioPin, Board_LED2, Board_LED_OFF); Clock_stop(buzzClockHandle); PIN_setOutputValue(hGpioPin, Board_BUZZER, Board_BUZZER_OFF); } } else if (paramID == SENSOR_DATA) { Io_getParameter(SENSOR_DATA, &ioValue); } if (ioMode == IO_MODE_REMOTE) { // Control by remote client: // - possible to operate the LEDs and buzzer // - right key functionality overridden (will not terminate connection) if (!!(ioValue & IO_DATA_LED1)) { PIN_setOutputValue(hGpioPin, Board_LED1, Board_LED_ON); } else { PIN_setOutputValue(hGpioPin, Board_LED1, Board_LED_OFF); } if (!!(ioValue & IO_DATA_LED2)) { PIN_setOutputValue(hGpioPin, Board_LED2, Board_LED_ON); } else { PIN_setOutputValue(hGpioPin, Board_LED2, Board_LED_OFF); } if (!!((ioValue & IO_DATA_BUZZER))) { Clock_start(buzzClockHandle); } else { Clock_stop(buzzClockHandle); PIN_setOutputValue(hGpioPin, Board_BUZZER, Board_BUZZER_OFF); } } }
void ReadLightW(Semaphore_Handle Sema, unsigned int *results){ char RMS_str[5]; char RMS_cnt_str[5]; //Set pins as output and set light sensor high. GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_1); GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_1, GPIO_PIN_1); Timer_start(timer1); //Turn on timer1 for 12 microseconds. //Pend on LightSema Semaphore_pend(Sema, BIOS_WAIT_FOREVER); switch (adState) { case 0: // no line dtected if (*results && (black_count >= 20)){ //make sure it is a full line. Clock_start(DataClock); wasWhite = 0; //record state. adState = 1; //next state. } break; case 1: //first rising edge detected //falling edge of first line if (!(*results) && !wasWhite && (black_count >= 20)) { wasWhite = 1; adState = 2; if ((black_count <= 40) && (black_count >= 20)) { //single line detected if (drive_state == FOLLOW1 || prev_follow_state == FOLLOW1){ //First black line found, progress to follow2 // and start acquiring data. drive_state = FOLLOW2; prev_follow_state = FOLLOW2; RMS_cnt = 0; RMS = 0; Clock_start(DataClock); } else if (drive_state == FOLLOW2 || prev_follow_state == FOLLOW2){ //Second black line found, progress to follow3 // and stop acquiring data. prev_follow_state = FOLLOW3; drive_state = FOLLOW3; Clock_stop(DataClock); //RMS /= RMS_cnt; //finalize RMS //RMS = sqrt(RMS); intToStr(RMS_cnt, RMS_cnt_str, 4); strcpy(FullBufferPtr, "\0"); strcpy(FullBufferPtr, "R=\0"); //Clear the fullBuffer. intToStr(RMS, RMS_str, 4); strcat(FullBufferPtr, RMS_str); strcat(FullBufferPtr, "\nC=\0"); strcat(FullBufferPtr, RMS_cnt_str); strcat(FullBufferPtr, "\n\0"); writeFrame("",FullBufferPtr); //Semaphore_post(TxDataSema); //Let writeFrame continue. //Clock_stop(DataClock); } }else if (black_count > 40){ //double line detected StopDrivingFn(); Clock_stop(DataClock); } black_count = 0; } break; case 2: //first falling edge detected if (*results && wasWhite && (black_count >= 20)){ wasWhite = 0; adState = 3; } break; case 3: //second rising edge detected //falling edge of second line if (!(*results) && !wasWhite && (black_count >= 20)) { wasWhite = 1; adState = 4; if ((black_count <= 40) && (black_count >= 20)) { //single line detected if (drive_state == FOLLOW1 || prev_follow_state == FOLLOW1){ //First black line found, progress to follow2 // and start acquiring data. drive_state = FOLLOW2; prev_follow_state = FOLLOW2; RMS_cnt = 0; RMS = 0; Clock_start(DataClock); } else if (drive_state == FOLLOW2 || prev_follow_state == FOLLOW2){ //First black line found, progress to follow3 // and stop acquiring data. prev_follow_state = FOLLOW3; drive_state = FOLLOW3; //Clock_stop(DataClock); Clock_stop(DataClock); //RMS /= RMS_cnt; //finalize RMS //RMS = sqrt(RMS); intToStr(RMS_cnt, RMS_cnt_str, 4); strcpy(FullBufferPtr, "\0"); strcpy(FullBufferPtr, "R=\0"); //Clear the fullBuffer. intToStr(RMS, RMS_str, 4); strcat(FullBufferPtr, RMS_str); strcat(FullBufferPtr, "\nC=\0"); strcat(FullBufferPtr, RMS_cnt_str); strcat(FullBufferPtr, "\n\0"); writeFrame("",FullBufferPtr); //Semaphore_post(TxDataSema); //Let writeFrame continue. } }else if (black_count > 40){//double line detected //StopDrivingFn(); Clock_stop(DataClock); } black_count = 0; } break; case 4: //second falling edge detected. Done collecting data. //Clock_stop(DataClock); //StopAcquireData(); Clock_stop(DataClock); //RMS /= RMS_cnt; //finalize RMS //RMS = sqrt(RMS); intToStr(RMS_cnt, RMS_cnt_str, 4); strcpy(FullBufferPtr, "\0"); strcpy(FullBufferPtr, "R=\0"); //Clear the fullBuffer. intToStr(RMS, RMS_str, 4); strcat(FullBufferPtr, RMS_str); strcat(FullBufferPtr, "\nC=\0"); strcat(FullBufferPtr, RMS_cnt_str); strcat(FullBufferPtr, "\n\0"); writeFrame("",FullBufferPtr); //Semaphore_post(TxDataSema); //Let writeFrame continue. //push whats remaining in the buffer out to transfer it. strcpy(FullBufferPtr, "\0"); strcat(pingptr1, "\n\0"); strcpy(FullBufferPtr, pingptr1); Semaphore_post(TxDataSema); strcpy(pingptr1, "\0"); numChars = 0; wasWhite = 0; adState = 0; break; default: break; } }
void DriveFn (){ static int lightFlag = 0; while(1){ Semaphore_pend(DriveSema, BIOS_WAIT_FOREVER); switch (drive_state) { case START: //enable motors forward. PWMOutputState(PWM0_BASE, MOTOR_LF_EN , true); PWMOutputState(PWM0_BASE, MOTOR_RF_EN , true); //accelerate to speed setSpeed (200, MOTOR_RF_EN); setSpeed (200, MOTOR_LF_EN); drive_state = FOLLOW1; GPIO_write(Board_LED0, Board_LED_ON); break; //Follow1,2 and 3 grouped together since they do the same thing. //They do progress depending on the lines the robot has passed, but that //is handled in another area. case FOLLOW1: case FOLLOW2: case FOLLOW3: prev_follow_state = drive_state; if (lightFlag == 0) //acquire data lightFlag = !lightFlag; if (!wall_det) { drive_state = INTERSECTION; } else if (front_wall_det == 1){ drive_state = UTURN; //stop if front wall detected } //read right wall distance PID_Algorithm(); break; case INTERSECTION: if (Clock_isActive(DataClock) ){ //if collecting data Clock_stop(DataClock); //don't collect data in intersection motor_RightTurn(); Clock_start(DataClock); } else //if not collecting data motor_RightTurn(); //move along break; case UTURN: if (Clock_isActive(DataClock) ){ //if collecting data Clock_stop(DataClock); //don't collect data in uturn motor_Uturn(); Clock_start(DataClock); } else //if not collecting data motor_Uturn(); //move along break; case STOP: //decelerate to a stop setSpeed (0, MOTOR_LF_EN); setSpeed (0, MOTOR_RF_EN); StopDrivingFn(); drive_state = OFF; break; case OFF: //disable motors PWMOutputState(PWM0_BASE, MOTOR_LF_EN , false); PWMOutputState(PWM0_BASE, MOTOR_RF_EN , false); break; } } }
/************************************************************************************************** * @fn macBackoffTimerUpdateWakeup * * @brief Recomputes and provides weakup timing hint to power module. * This function does not read timing variables in a critical * section. The caller must call this function within a critical * section where the timing variable is modified in order * to have more accurate notification. * * @param none * * @return none ************************************************************************************************** */ static void macBackoffTimerUpdateWakeup(void) { int_fast64_t ticks; /* Replicate the timer in order to inform power module to wake up properly * in case the device enters sleep state in the future. */ /* First find out which RAT channel between backoffTimerTrigger and * macBackoffTimerRollover is supposed to expire next. */ ticks = MAC_RADIO_BACKOFF_COUNT(); if (backoffTimerTrigger > ticks && backoffTimerTrigger < macBackoffTimerRollover) { ticks = backoffTimerTrigger - ticks; } else if (macBackoffTimerRollover > ticks) { ticks = macBackoffTimerRollover - ticks; } else { /* Note that current count might have exceeded already set thresholds, * as the code is executed while interrupt is flagged. * In such a case, this function shall be called again anyways and * hence this condition can be ignored. */ return; } /* TODO: For subG, backoff timer unit is not necessarily backoff period * but fixed 320us and hence the following constant * (MAC_SPEC_USECS_PER_BACKOFF) should be replaced with backoff * timer unit period in usecs. */ /* Convert backoff timer unit to RTOS tick unit */ ticks *= MAC_SPEC_USECS_PER_BACKOFF; #ifdef USE_ICALL ticks -= (MAC_BACKOFF_TIMER_ADDITIONAL_WAKEUP_LATENCY + ICall_pwrGetXOSCStartupTime(ticks/1000)); #elif defined OSAL_PORT2TIRTOS ticks -= MAC_BACKOFF_TIMER_ADDITIONAL_WAKEUP_LATENCY + Power_getXoscStartupTime(ticks/1000); #endif /* defined OSAL_PORT2TIRTOS */ if (ticks > 0) { #ifdef USE_ICALL ticks /= osal_tickperiod; #elif defined OSAL_PORT2TIRTOS ticks /= Clock_tickPeriod; #endif /* defined OSAL_PORT2TIRTOS */ } if (ticks > 0) { #ifdef USE_ICALL ICall_setTimer((uint_fast32_t) ticks, macBackoffTimerICallTimerCback, NULL, &macBackoffTimerICallTimerID); #endif /* USE_ICALL */ #ifdef OSAL_PORT2TIRTOS Clock_stop(macBackoffWakeupClock); Clock_setTimeout(macBackoffWakeupClock, (UInt32) ticks); Clock_start(macBackoffWakeupClock); #endif /* OSAL_PORT2TIRTOS */ /* Allow entering sleep state */ macBackoffTimerImpending = FALSE; #ifdef DEBUG_SW_TRACE DBG_PRINTL1(DBGSYS, "BO %u", ticks); #endif /* DEBUG_SW_TRACE */ } else { /* Timing is too close. Suppress sleep. */ macBackoffTimerImpending = TRUE; } macPwrVote(); }
/* * ======== PowerCC3200_sleepPolicy ======== */ void PowerCC3200_sleepPolicy() { bool returnFromSleep = FALSE; uint32_t constraintMask; uint32_t ticks; uint64_t time; uint64_t match; uint64_t curr; uint64_t remain; uint32_t taskKey; uint32_t swiKey; /* disable interrupts */ CPUcpsid(); /* disable Swi and Task scheduling */ swiKey = Swi_disable(); taskKey = Task_disable(); /* query the declared constraints */ constraintMask = Power_getConstraintMask(); /* * Do not go into LPDS if not allowed into DEEPSLEEP. * Check to see if we can go into LPDS (lowest level sleep). * If not allowed, then attempt to go into DEEPSLEEP. * If not allowed in DEEPSLEEP then just SLEEP. */ /* check if we are allowed to go to LPDS */ if ((constraintMask & ((1 << PowerCC3200_DISALLOW_LPDS) | (1 << PowerCC3200_DISALLOW_DEEPSLEEP))) == 0) { /* * Check how many ticks until the next scheduled wakeup. A value of * zero indicates a wakeup will occur as the current Clock tick period * expires; a very large value indicates a very large number of Clock * tick periods will occur before the next scheduled wakeup. */ /* Get the time remaining for the RTC timer to expire */ ticks = Clock_getTicksUntilInterrupt(); /* convert ticks to microseconds */ time = ticks * Clock_tickPeriod; /* check if can go to LPDS */ if (time > Power_getTransitionLatency(PowerCC3200_LPDS, Power_TOTAL)) { /* get the current and match values for RTC */ match = MAP_PRCMSlowClkCtrMatchGet(); curr = MAP_PRCMSlowClkCtrGet(); remain = match - curr - (((uint64_t)PowerCC3200_TOTALTIMELPDS * 32768) / 1000000); /* set the LPDS wakeup time interval */ MAP_PRCMLPDSIntervalSet(remain); /* enable the wake source to be timer */ MAP_PRCMLPDSWakeupSourceEnable(PRCM_LPDS_TIMER); /* go to LPDS mode */ Power_sleep(PowerCC3200_LPDS); /* set 'returnFromSleep' to TRUE*/ returnFromSleep = TRUE; } } /* check if we are allowed to go to DEEPSLEEP */ if ((constraintMask & (1 << PowerCC3200_DISALLOW_DEEPSLEEP) == 0) && (!returnFromSleep)) { /* * Check how many ticks until the next scheduled wakeup. A value of * zero indicates a wakeup will occur as the current Clock tick period * expires; a very large value indicates a very large number of Clock * tick periods will occur before the next scheduled wakeup. */ ticks = Clock_getTicksUntilInterrupt(); /* convert ticks to microseconds */ time = ticks * Clock_tickPeriod; /* check if can go to DEEPSLEEP */ if (time > Power_getTransitionLatency(PowerCC3200_DEEPSLEEP, Power_TOTAL)) { /* schedule the wakeup event */ ticks -= PowerCC3200_RESUMETIMEDEEPSLEEP / Clock_tickPeriod; Clock_setTimeout(Clock_handle(&clockObj), ticks); Clock_start(Clock_handle(&clockObj)); /* go to DEEPSLEEP mode */ Power_sleep(PowerCC3200_DEEPSLEEP); Clock_stop(Clock_handle(&clockObj)); /* set 'returnFromSleep' to TRUE so we don't go to sleep (below) */ returnFromSleep = TRUE; } } /* re-enable interrupts */ CPUcpsie(); /* restore Swi scheduling */ Swi_restore(swiKey); /* restore Task scheduling */ Task_restore(taskKey); /* sleep only if we are not returning from one of the sleep modes above */ if (!(returnFromSleep)) { MAP_PRCMSleepEnter(); } }
void OneMsTaskTimer::stop() { Clock_stop(myClock); }
void Clock::stop() { Clock_stop(ClockHandle); }