Esempio n. 1
0
// * imu_tim_ISR **************************************************************
// * ISR for soft i2c tim interrupt.                                          *
// *                                                                          *
// * Portions for initialization of softi2c library copied/modified from      *
// * "soft_i2c_atmel.c" example code.                                         *
// ****************************************************************************
void imu_tim_ISR(void)
{
  TimerIntClear(IMU_TIM_BASE, TIMER_TIMA_TIMEOUT);          // clear interrupt
  
  SoftI2CTimerTick(&g_sI2C);                                // perform softi2c tick update
}
Esempio n. 2
0
void vT3InterruptHandler( void )
{
	TimerIntClear( TIMER3_BASE, TIMER_TIMA_TIMEOUT );
	portEND_SWITCHING_ISR( xSecondTimerHandler() );
}
Esempio n. 3
0
uint8 bottomBoardISR() {
	uint32 data, i;
	uint32 timerLoadPeriod;
	uint8 checksum;
	long val;

	TimerIntClear(TIMER1_BASE, TIMER_TIMB_TIMEOUT);

	// Multiplex SPI (bottomboard/radio)
	if (MSPSPIState == MSPSPI_STATE_XMIT_BYTE) {
		radioIntDisable();
		SPISelectDeviceISR(SPI_MSP430);
		timerLoadPeriod = MSP430_SPI_DESELECT_PERIOD;
	} else if (MSPSPIState == MSPSPI_STATE_DESELECT_SPI) {
		SPIDeselectISR();
		radioIntEnable();
		if (bootloaderSet && MSP430MessageIdx == 0) {
			// Deselect but then set the boot-loader to operate.
			msp430BSLInit();
			bootloaderSet = FALSE;
		} else {
			timerLoadPeriod = MSP430_SPI_BYTE_PERIOD;
		}
	}

	// Set delay
	MAP_TimerLoadSet(TIMER1_BASE, TIMER_B, timerLoadPeriod);
	MAP_TimerEnable(TIMER1_BASE, TIMER_B);

	// Transmit message to bottomboard
	if (MSPSPIState == MSPSPI_STATE_XMIT_BYTE) {
		// Pack new message at the beginning of each cycle
		if (MSP430MessageIdx == 0) {
			// Pack code
			for (i = 0; i < MSP430_CODE_LENGTH; i++) {
				MSP430MessageOut[i] = MSP430Code[i];
			}
			// Build and pack payload
			switch (msp430SystemGetCommandMessage()) {
				case MSP430_CMD_COMMAND_NORMAL:
					blinkySystemBuildMessage(&MSP430MessageOut[MSP430_CMD_SYSTEM_LED_IDX]);
					buttonsBuildMessage(&MSP430MessageOut[MSP430_CMD_BUTTONS_IDX]);
					ledsBuildMessage(&MSP430MessageOut[MSP430_CMD_LED_IDX]);
					break;
				case MSP430_CMD_COMMAND_REPROGRAM:
					bootloaderSet = TRUE;
					break;
				default:
					// Do nothing for shutdown or reset
					break;
			}

			msp430SystemCommandBuildMessage(&MSP430MessageOut[MSP430_CMD_COMMAND_IDX]);
			MSP430MessageOut[MSP430_CMD_CHECKSUM_IDX] =  messageChecksum(MSP430MessageOut, MSP430_CODE_LENGTH, MSP430_MSG_LENGTH);
		}

		// Shift receive buffer
		shiftBuffer(MSP430MessageIn, MSP430_MSG_LENGTH);

		// Put data into the transmit buffer
		val = MAP_SSIDataPutNonBlocking(SSI0_BASE, (uint32)MSP430MessageOut[MSP430MessageIdx]);
		if (val == 0) {
			SPIBusError_SSIDataPutNonBlocking = 1;
		}

		// Retrieve the received byte
		MAP_SSIDataGet(SSI0_BASE, &data);

		// Put byte the the end of the receive buffer
		MSP430MessageIn[MSP430_MSG_LENGTH - 1] = data;

		// Check to see if we have a complete message, with correct code and checksum
		if (MSP430MessageIdx == 0) {
			// Checkcode
			for (i = 0; i < MSP430_CODE_LENGTH; i++) {
				if (MSP430MessageIn[i] != MSP430Code[i])
					break;
			}

			if (i == MSP430_CODE_LENGTH) {
				// Checksum
				checksum = messageChecksum(MSP430MessageIn, MSP430_CODE_LENGTH, MSP430_MSG_LENGTH);
				if (checksum == MSP430MessageIn[MSP430_MSG_LENGTH - 1]) {
					// Process incoming message
					bumpSensorsUpdate(MSP430MessageIn[MSP430_MSG_BUMPER_IDX]);
					accelerometerUpdate(&MSP430MessageIn[MSP430_MSG_ACCEL_START_IDX]);
					gyroUpdate(&MSP430MessageIn[MSP430_MSG_GYRO_START_IDX]);
					systemBatteryVoltageUpdate(MSP430MessageIn[MSP430_MSG_VBAT_IDX]);
					systemUSBVoltageUpdate(MSP430MessageIn[MSP430_MSG_VUSB_IDX]);
					systemPowerButtonUpdate(MSP430MessageIn[MSP430_MSG_POWER_BUTTON_IDX]);
					systemMSPVersionUpdate(MSP430MessageIn[MSP430_MSG_VERSION_IDX]);
					reflectiveSensorsUpdate(&MSP430MessageIn[MSP430_MSG_REFLECT_START_IDX]);

					if((MSP430MessageIn[MSP430_MSG_VERSION_IDX] != 0) && (!systemMSP430CommsValid)) {
						systemMSP430CommsValid = TRUE;
					}
				} else {
					checksumFailure++;
					// Fail checksum
					if (showError) {cprintf("Bsum ");}
				}
			} else {
				// Fail checkcode
				if (showError) {cprintf("Bcod ");}
			}
			// Toggle MSP boards, regardless of result
			if (expand0En) {
				MSPSelect = MSP_EXPAND0_BOARD_SEL;
			}
		}

		// Increment index, wrap back to 0 if it exceeds the range
		MSP430MessageIdx++;
		if (MSP430MessageIdx >= MSP430_MSG_LENGTH) {
			MSP430MessageIdx = 0;
		}

		// Toggle states
		MSPSPIState = MSPSPI_STATE_DESELECT_SPI;
	} else if (MSPSPIState == MSPSPI_STATE_DESELECT_SPI) {
		// Toggle states
		MSPSPIState = MSPSPI_STATE_XMIT_BYTE;
	}

	return 0;
}
Esempio n. 4
0
/*
 * @brief Expansion0 MSP430 board ISR
 *
 * @returns void
 */
uint8 expand0BoardISR() {
	uint32 data, i;
	uint32 timerLoadPeriod;
	uint8 checksum;
	long val;
	static uint8 gripperData = 0;

	TimerIntClear(TIMER1_BASE, TIMER_TIMB_TIMEOUT);

	// Multiplex outputs (gripper/radio), set delay
	if (MSPSPIState == MSPSPI_STATE_XMIT_BYTE) {
		radioIntDisable();
		SPISelectDeviceISR(SPI_EXPAND0);
		timerLoadPeriod = MSP430_SPI_DESELECT_PERIOD;
	} else if (MSPSPIState == MSPSPI_STATE_DESELECT_SPI) {
		SPIDeselectISR();
		radioIntEnable();
		timerLoadPeriod = (MSP430_SPI_BYTE_PERIOD);
	}

	MAP_TimerLoadSet(TIMER1_BASE, TIMER_B, timerLoadPeriod);
	MAP_TimerEnable(TIMER1_BASE, TIMER_B);

	// Transmit a byte or just switch state
	if (MSPSPIState == MSPSPI_STATE_XMIT_BYTE) {
		// Pack message
		if (expand0MessageIdx == 0) {
			// Grab next message from buffer
			if (!expand0MessageOutBufLock) {
				memcpy(expand0MessageOut, expand0MessageOutBuf, EXPAND0_MSG_LENGTH);
			}
		}

		// Rotate received buffer
		shiftBuffer(expand0MessageIn, EXPAND0_MSG_LENGTH);

		// Put data into the transmit buffer
		val = MAP_SSIDataPutNonBlocking(SSI0_BASE, (uint32)expand0MessageOut[expand0MessageIdx]);

		// Retrieve the received byte
		MAP_SSIDataGet(SSI0_BASE, &data);

		// Put byte the the end of the received buffer
		expand0MessageIn[EXPAND0_MSG_LENGTH - 1] = data;

		//Integrity checking
		if (expand0MessageIdx == 0) {
			// Checkcode
			for (i = 0; i < EXPAND0_CODE_LENGTH; i++) {
				if (expand0MessageIn[i] != expand0Code[i])
					break;
			}
			if (i == EXPAND0_CODE_LENGTH) {
				// Checksum
				checksum = messageChecksum(expand0MessageIn, EXPAND0_CODE_LENGTH, EXPAND0_MSG_LENGTH);
				if (checksum == expand0MessageIn[EXPAND0_MSG_LENGTH - 1]) {
					// Avoid loading from buffer if the buffer is updating
					if (!expand0MessageInBufLock) {
						memcpy(expand0MessageInBuf, expand0MessageIn, EXPAND0_MSG_LENGTH);
					}
				} else {
					// Fail checksum
					if (showError) {cprintf("Gsum ");}
				}
			} else {
				// Fail checkcode
				if (showError) {cprintf("Gcod ");}
			}
			// Toggle MSP boards, regardless of result
			MSPSelect = MSP_BOTTOM_BOARD_SEL;
		}

		// Increment index, wrap back to 0 if it exceeds the range
		expand0MessageIdx++;
		if (expand0MessageIdx >= EXPAND0_MSG_LENGTH) {
			expand0MessageIdx = 0;
		}

		// Toggle states
		MSPSPIState = MSPSPI_STATE_DESELECT_SPI;
	} else if (MSPSPIState == MSPSPI_STATE_DESELECT_SPI) {
		// Toggle states
		MSPSPIState = MSPSPI_STATE_XMIT_BYTE;
	}

	return 0;
}
Esempio n. 5
0
void Timer1IntHandler( void )
{
    ulHighFrequencyTimerTicks++;
	TimerIntClear( TIMER1_BASE, TIMER_TIMA_TIMEOUT );
}
Esempio n. 6
0
//*****************************************************************************
//
//! Handles the TIMER5A interrupt.
//!
//! This function responds to the TIMER5A interrupt, updating the duty cycle of
//! the output waveform in order to produce sound.  It is the application's
//! responsibility to ensure that this function is called in response to the
//! TIMER5A interrupt, typically by installing it in the vector table as the
//! handler for the TIMER5A interrupt.
//!
//! \return None.
//
//*****************************************************************************
void
SoundIntHandler(void)
{
    int32_t i32DutyCycle;

    //
    // Clear the timer interrupt.
    //
    TimerIntClear(TIMER5_BASE, TIMER_CAPA_EVENT);

    //
    // See if the startup ramp is in progress.
    //
    if(HWREGBITW(&g_sSoundState.ui32Flags, SOUND_FLAG_STARTUP))
    {
        //
        // Increment the ramp count.
        //
        g_sSoundState.i32Step++;

        //
        // Increase the pulse width of the output by one clock.
        //
        TimerMatchSet(TIMER5_BASE, TIMER_A, g_sSoundState.i32Step);

        //
        // See if this was the last step of the ramp.
        //
        if(g_sSoundState.i32Step >= (g_sSoundState.ui32Period / 2))
        {
            //
            // Indicate that the startup ramp has completed.
            //
            HWREGBITW(&g_sSoundState.ui32Flags, SOUND_FLAG_STARTUP) = 0;

            //
            // Set the step back to zero for the start of audio playback.
            //
            g_sSoundState.i32Step = 0;
        }

        //
        // There is nothing further to be done.
        //
        return;
    }

    //
    // See if the shutdown ramp is in progress.
    //
    if(HWREGBITW(&g_sSoundState.ui32Flags, SOUND_FLAG_SHUTDOWN))
    {
        //
        // See if this was the last step of the ramp.
        //
        if(g_sSoundState.i32Step == 1)
        {
            //
            // Disable the output signals.
            //
            TimerMatchSet(TIMER5_BASE, TIMER_A, g_sSoundState.ui32Period);

            //
            // Clear the sound flags.
            //
            g_sSoundState.ui32Flags = 0;

            //
            // Disable the speaker amp.
            //
            GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_4, 0);
        }
        else
        {
            //
            // Decrement the ramp count.
            //
            g_sSoundState.i32Step--;

            //
            // Decrease the pulse width of the output by one clock.
            //
            TimerMatchSet(TIMER5_BASE, TIMER_A, g_sSoundState.i32Step);
        }

        //
        // There is nothing further to be done.
        //
        return;
    }

    //
    // Compute the value of the PCM sample based on the blended average of the
    // previous and current samples.  It should be noted that linear
    // interpolation does not produce the best results with sound (it produces
    // a significant amount of harmonic aliasing) but it is fast.
    //
    i32DutyCycle =
        (((g_sSoundState.pi16Samples[0] * (8 - g_sSoundState.i32Step)) +
          (g_sSoundState.pi16Samples[1] * g_sSoundState.i32Step)) / 8);

    //
    // Adjust the magnitude of the sample based on the current volume.  Since a
    // multiplicative volume control is implemented, the volume value will
    // result in nearly linear volume adjustment if it is squared.
    //
    i32DutyCycle = (((i32DutyCycle * g_sSoundState.i32Volume *
                      g_sSoundState.i32Volume) / 65536) + 32768);

    //
    // Set the PWM duty cycle based on this PCM sample.
    //
    i32DutyCycle = (g_sSoundState.ui32Period * i32DutyCycle) / 65536;
    TimerMatchSet(TIMER5_BASE, TIMER_A, i32DutyCycle);

    //
    // Increment the sound step based on the sample rate.
    //
    if(HWREGBITW(&g_sSoundState.ui32Flags, SOUND_FLAG_8KHZ))
    {
        g_sSoundState.i32Step = (g_sSoundState.i32Step + 1) & 7;
    }
    else if(HWREGBITW(&g_sSoundState.ui32Flags, SOUND_FLAG_16KHZ))
    {
        g_sSoundState.i32Step = (g_sSoundState.i32Step + 2) & 7;
    }
    else if(HWREGBITW(&g_sSoundState.ui32Flags, SOUND_FLAG_32KHZ))
    {
        g_sSoundState.i32Step = (g_sSoundState.i32Step + 4) & 7;
    }

    //
    // See if the next sample has been reached.
    //
    if(g_sSoundState.i32Step == 0)
    {
        //
        // Copy the current sample to the previous sample.
        //
        g_sSoundState.pi16Samples[0] = g_sSoundState.pi16Samples[1];

        //
        // Get the next sample from the buffer.
        //
        g_sSoundState.pi16Samples[1] =
            g_sSoundState.pi16Buffer[g_sSoundState.ui32Offset];

        //
        // Increment the buffer pointer.
        //
        g_sSoundState.ui32Offset++;
        if(g_sSoundState.ui32Offset == g_sSoundState.ui32Length)
        {
            g_sSoundState.ui32Offset = 0;
        }

        //
        // Call the callback function if one of the half-buffers has been
        // consumed.
        //
        if(g_sSoundState.pfnCallback)
        {
            if(g_sSoundState.ui32Offset == 0)
            {
                g_sSoundState.pfnCallback(1);
            }
            else if(g_sSoundState.ui32Offset == (g_sSoundState.ui32Length / 2))
            {
                g_sSoundState.pfnCallback(0);
            }
        }
    }
}
/*
 * Forward declared in startup.c
 */
void timer0_int_handler(void)
{
	TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
	__timer0_ticks++;
}
Esempio n. 8
0
void Timer0IntHandler(void)
{
	//CLEAR INTERRUPT FLAG
	TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
	tempo_passado++;
}
Esempio n. 9
0
File: Base.c Progetto: ilabmp/micro
void Handler2() {
	TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT);

	usnprintf(buffer, BUFFSIZE, "!%d%c%c%d|\n", 44, 'a', 'b', 32);
	UARTPrint((unsigned char *) buffer);
}
void timer0_handler_example(void)
{
	TimerLoadSet(TIMER0_BASE, TIMER_A, 0xf);
	/* Clear the timer interrupt */
	TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
}
Esempio n. 11
0
File: Base.c Progetto: ilabmp/micro
void Handler1() {
	TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);

}
/**
 * Main ISR for the commutation timer
 */
void CommutationControllerClass::ISR()
{
	// Disable ADC interrupt to avoid fuckery, will be reenabled at end
	ADC->disableInterrupt();

	// Clear timer interrupt flag
	TimerIntClear(TIMER_BASE, TIMER_TIMA_TIMEOUT);

	switch (motorParent->getControlState())
	{
	case openloop:
	{
		// Grab the new PWM width
		commutator.setPWMWidth(startup.getPWMWidth());
		targetPWMWidth = startup.getPWMWidth();

		// Force the PWM IIR filter state to the current PWM value so that the soft startup filter starts from the right value
		PWMFilter.reset();
		PWMFilter.iterate(startup.getPWMWidth());

		// Do we need to set the commutator to align or just commutate?
		if (startup.align())
		{
			commutator.align();
		}
		else
		{
			commutator.commutate();
		}

		// Get the new commutation period from the startup sequencer
		this->setTimeoutValue(startup.getCommutationPeriod());

		// If the ZC flag wasn't set on the previous commutation then reset the acquisition counter
		if (ADC->getZCDetectedFlag() == false)
		{
			ADC->clearAcquisitionCounter();
		}

		// Clear the ZC detected flag to evaluate this next commutation cycle afresh
		ADC->clearZCDetectedFlag();

		// Do we need to enable ZC acquisition for this next cycle?
		if (startup.getAcquisitionEnabled())
		{
			ADC->enableAcquisition();
		}
		else
		{
			ADC->disableAcquisition();
		}

		// Increment the startup sequence lookup index
		startup.advance();

		break;
	}

	case closedloop:

		// Advance to the next commutation step and increment the commutation counter
		commutator.commutate(), commutationCounter++;

		// Add the duration of the previous commutation cycle to the cumulative count since the last PWM width update
		timeSinceLastPWMUpdate += this->getTimeoutValue();

		// Are we currently soft-starting?
		if (softStarting)
		{
			commutator.setPWMWidth(PWMFilter.iterate(targetPWMWidth));
			softStartCounter++;

			if (softStartCounter > 50)
			{
				softStarting = false;
			}
		}

		// Is the time since the last PWM width update greater than the timeout value? Aka has the overseer or RPi crashed?
		if (timeSinceLastPWMUpdate > MOTOR_TIMEOUT_VALUE)
		{
			motorParent->stop();
		}
		else
		{
			// Did we have a successful ZC detection last cycle or was this commutation a blind one?
			if (ADC->getZCDetectedFlag())
			{
				missedZCCounter = 0;
				// Clear the ZC detected flag to start the ADC looking for the next ZC
				ADC->clearZCDetectedFlag();
			}
			// Commutation was blind
			else
			{
				missedZCCounter++;
				if (missedZCCounter > MISSED_ZC_LIMIT)
				{
					motorParent->setState(openloop);
					startup.reset();
					ADC->reset();
					this->reset();
					motorParent->start();
				}
			}
		}
		break;
	}

	ADC->enableInterrupt();
}
Esempio n. 13
0
static void joystick_isr(void) {

	TimerIntClear(JOY_TIMER, TIMER_TIMA_TIMEOUT);

	memset(&task_data,0,sizeof(struct task_manual_move_data));


	// Only allow the joystick when AUX1 (Crosshair) is enabled
	if (enabled) {

		unsigned long x = joystick_x[0];
		unsigned long y = joystick_y[0];
		double x_off = 0;
		double y_off = 0;

		if (x > joystick_center[0] + ZERO_THRESHOLD) {
			x_off = (double)(x - joystick_center[0]) / 0x800;
		} else if (x < joystick_center[0] - ZERO_THRESHOLD) {
			x_off = -(double)(joystick_center[0] - x) / 0x800;
		}

		if (y > joystick_center[1] + ZERO_THRESHOLD) {
			y_off = (double)(y - joystick_center[1]) / 0x800;
		} else if (y < joystick_center[1] - ZERO_THRESHOLD) {
			y_off = -(double)(joystick_center[1] - y) / 0x800;
		}

		// Have two speed levels for accuracy and speed when wanted.
		if (fabs(y_off) < 0.5)
			y_off /= 50.0;
		else// if (fabs(y_off) < 1.0)
			y_off /= 10.0;

		if (fabs(x_off) < 0.5)
			x_off /= 50.0;
		else// if (fabs(x_off) < 1.0)
			x_off /= 10.0;

#ifdef JOY_INVERT_Y
		task_data.x_offset = -y_off;
#else
		task_data.x_offset = y_off;
#endif

#ifdef JOY_INVERT_X
		task_data.y_offset = -x_off;
#else
		task_data.y_offset = x_off;
#endif


	}

//	if( current_jog_z ){
//		switch(current_jog_z){
//		case (1<<JOG_Z_UP_BIT):
//				task_data.z_offset =  0.0003; break;
//		case (1<<JOG_Z_DOWN_BIT):
//				task_data.z_offset = -0.0003; break;
//		default:
//			task_data.z_offset = 0;
//		}
//	}
//	if( enabled || current_jog_z ){
//		task_data.rate = 20000;
//		task_enable(TASK_MANUAL_MOVE, &task_data);
//	}
	if( enabled ){
		//
	    // Trigger the next ADC conversion.
	    //
		if (status & STATUS_CH0_IDLE)
			ADCProcessorTrigger(ADC0_BASE, 0);
		if (status & STATUS_CH1_IDLE)
			ADCProcessorTrigger(ADC0_BASE, 1);

	}

}
Esempio n. 14
0
//*****************************************************************************
//
//! \brief xtimer 001 test execute main body.
//!
//! \return None.
//
//*****************************************************************************
static void xTimer001Execute(void)
{
    unsigned long ulTemp;
    unsigned long ulBase;
    int i, j ;
    
    //
    // One shot mode test.
    //
    for(i = 0; i < 4; i++)
    {
        ulBase = ulTimerBase[i];
        
        //
        // Clear the flag first
        //
        TimerIntClear(ulBase, TIMER_INT_MATCH);
        while(TimerIntStatus(ulBase, TIMER_INT_MATCH));  
        
        // 
        // Config as One shot mode
        //        
        TimerInitConfig(ulBase, TIMER_MODE_ONESHOT, 1000);
        
        TimerIntEnable(ulBase, TIMER_INT_MATCH);
        xIntEnable(ulTimerIntID[i]);
        xTimerIntCallbackInit(ulBase, TimerCallbackFunc[i]); 
        TimerStart(ulBase);
        
        //
        // wait until the timer data register reach equel to compare register
        //
        TestAssertQBreak("a","One shot mode Intterrupt test fail", -1);
        xIntDisable(ulTimerIntID[i]);
    }  
    
    //
    // Periodic mode
    //
    for(i = 0; i < 4; i++)
    {
        ulBase = ulTimerBase[i];
        ulTemp = 0;
        
        //
        // Clear the flag first
        //
        TimerIntClear(ulBase, TIMER_INT_MATCH);
        
        //
        // Config as periodic mode
        //
        TimerInitConfig(ulBase, TIMER_MODE_PERIODIC, 1000);    
        TimerIntEnable(ulBase, TIMER_INT_MATCH);
        TimerStart(ulBase);
        
        // 
        // wait the periodic repeat 5 times 
        //
        for (j = 0; j < 5; j++)
        {
            while(!TimerIntStatus(ulBase, TIMER_INT_MATCH));      
            ulTemp++;
            if(ulTemp == 5)
            {
                break;
            }
            TimerIntClear(ulBase, TIMER_INT_MATCH);
        }
        TestAssert(ulTemp == 5,
                   "xtimer mode \" periodic test\" error!");
        TimerStop(ulBase);       
    }
    
    //
    // Toggle mode test
    //
    for(i = 0; i < 4; i++)
    {
        ulBase = ulTimerBase[i];
        ulTemp = 0;
        
        //
        // Clear the Int flag first
        //
        TimerIntClear(ulBase, TIMER_INT_MATCH);
        
        //
        // Config as toggle mode
        //
        TimerInitConfig(ulBase, TIMER_MODE_PERIODIC, 1000);    
        TimerIntEnable(ulBase, TIMER_INT_MATCH);
        TimerStart(ulBase);
        
        // 
        // wait the toggle repeat 5 times 
        //
        for (j = 0; j < 5; j++)
        {
            while(!TimerIntStatus(ulBase, TIMER_INT_MATCH));      
            ulTemp++;
            if(ulTemp == 5)
            {
                break;
            }
            TimerIntClear(ulBase, TIMER_INT_MATCH);
        }
        TestAssert(ulTemp == 5,
                   "xtimer mode \" Toggle mode test\" error!");
        TimerStop(ulBase);       
    }
    
    //
    // Continuous mode test.
    //
    for(i = 0; i < 4; i++)
    {
        ulBase = ulTimerBase[i];
        ulTemp = 0;
        
        //
        // Clear the flag first
        //
        TimerIntClear(ulBase, TIMER_INT_MATCH);
        while(TimerIntStatus(ulBase, TIMER_INT_MATCH));  
        
        // 
        // Config as One shot mode
        //        
        TimerInitConfig(ulBase, TIMER_MODE_CONTINUOUS, 10000);
        TimerMatchSet(ulBase, 10);
        TimerIntEnable(ulBase, TIMER_INT_MATCH);
        TimerStart(ulBase);
        
        //
        // Delay some time to wait the count register reach to 200.
        //
        xSysCtlDelay(100);
        if(TimerIntStatus(ulBase, TIMER_INT_MATCH) == xtrue)
        {
            ulTemp++;
        }
        TimerIntClear(ulBase, TIMER_INT_MATCH);
        TimerMatchSet(ulBase, 2000);
        
        //
        // Wait until reach the 1000
        //
        //while(!TimerIntStatus(ulBase, TIMER_INT_MATCH));       
        xSysCtlDelay(10000);
        if(TimerIntStatus(ulBase, TIMER_INT_MATCH) == xtrue)
        {
            ulTemp++;
        }
        TimerIntClear(ulBase, TIMER_INT_MATCH);
        
        TestAssert(ulTemp == 2,
           "xtimer mode \" Continuous mode test\" error!");
        TimerStop(ulBase);     
        xIntDisable(ulTimerIntID[i]);
   
    }  
    
}
Esempio n. 15
0
File: Timers.c Progetto: yguo89/RTOS
void Timer2A_ISR ( void )
{
    TimerIntClear ( TIMER2_BASE, Timer_IntFlag[Timer2A] );
    Timer_ISR[Timer2A]();

}
Esempio n. 16
0
void Timer0IntHandler(void)
{
	TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
	char sw1val = detectKeyPressSW1();
	char sw2val = detectKeyPressSW2();
	if (sw1val == 1) {
		autoDelay--;
		if(autoDelay<5) autoDelay=5;
		if(manualMode == 1 && !mode)
		{
			ui8Adjust_red-=10;
			if (ui8Adjust_red < 11)
			{
				ui8Adjust_red = 11;
			}
			PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5, ui8Adjust_red * ui32Load / 1000);
		}
		if(manualMode == 2 && !mode)
		{
			ui8Adjust_blue-=10;
			if (ui8Adjust_blue < 11)
			{
				ui8Adjust_blue = 11;
			}
			PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6, ui8Adjust_blue * ui32Load / 1000);
		}
		if(manualMode == 3 && !mode)
		{
			ui8Adjust_green-=10;
			if (ui8Adjust_green < 11)
			{
				ui8Adjust_green = 11;
			}
			PWMPulseWidthSet(PWM1_BASE, PWM_OUT_7, ui8Adjust_green * ui32Load / 1000);
		}
	}

	if (sw2val == 1) {
		autoDelay++;
		if(autoDelay>50) autoDelay=50;
		if(manualMode == 1 && !mode)
		{
			ui8Adjust_red+=10;
			if (ui8Adjust_red > 240)
			{
				ui8Adjust_red = 240;
			}
			PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5, ui8Adjust_red * ui32Load / 1000);
		}
		if(manualMode == 2 && !mode)
		{
			ui8Adjust_blue+=10;
			if (ui8Adjust_blue > 240)
			{
				ui8Adjust_blue = 240;
			}
			PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6, ui8Adjust_blue * ui32Load / 1000);
		}
		if(manualMode == 3 && !mode)
		{
			ui8Adjust_green+=10;
			if (ui8Adjust_green > 240)
			{
				ui8Adjust_green = 240;
			}
			PWMPulseWidthSet(PWM1_BASE, PWM_OUT_7, ui8Adjust_green * ui32Load / 1000);
		}
	}

	if (sw1val == 2 && mode && sw2val==2) {
	manualSetup();
		mode = 0;
		sw1state=0;sw2state=0;
	}
	else if(!mode && sw2val == 2 && sw1val == 2) {manualMode = 3;manualState=0;}
	else if (!mode && sw2val == 2)
	{
		if(sw1val==1)
		{
			manualState++;
			if(manualState == 1) { manualMode = 1;}
			else if(manualState == 2) {manualMode = 2;}
		}
	}
	else if(!mode) manualState=0;
}
Esempio n. 17
0
File: Timers.c Progetto: yguo89/RTOS
void Timer3B_ISR ( void )
{
    TimerIntClear ( TIMER3_BASE, Timer_IntFlag[Timer3B] );
    Timer_ISR[Timer3B]();

}
Esempio n. 18
0
void Timer0IntHandler( void )
{
    timeval++;
	TimerIntClear( TIMER0_BASE, TIMER_TIMA_TIMEOUT );
}
Esempio n. 19
0
void vT2InterruptHandler( void )
{
    TimerIntClear( TIMER2_BASE, TIMER_TIMA_TIMEOUT );	
	portEND_SWITCHING_ISR( xFirstTimerHandler() );
}
Esempio n. 20
0
void dht11count1uS(){
	TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
	count1uS++;
}
Esempio n. 21
0
void timer0_int_handler(void)
{
	TimerIntClear(WTIMER0_BASE, TIMER_TIMB_TIMEOUT);
	ui8PrevCount++;
}
Esempio n. 22
0
//Timer4A interrupt handler
void RF22_Timer4AIntHandler(void)
{
	TimerIntClear(TIMER4_BASE, TIMER_TIMA_TIMEOUT);
	++_time_counter;
}
void Timer0IntHandler(void)
{
	  TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
	  millis++;
}
Esempio n. 24
0
void Timer1BIntHandler(void)
{
    uint32_t intStatus;
    intStatus = TimerIntStatus(TIMER1_BASE, true);
    TimerIntClear(TIMER1_BASE, intStatus);

    //g_ui32Counter++;
    timeCounter++;
    keyStatus = KeyScan();
if(keyStatus == 1)
  {
      iss = 1;
      M1_LED_ON;
      setMotorPowerMax();
      pduty += 50;
  }
else if(keyStatus == 2)
  {
      iss = 2;
      M1_LED_OFF;
      setMotorPowerMin();
  }
#ifdef USE_MCU2
    switch(keyStatus)
    {
    case 0:
      M2_LED1_OFF;
      M2_LED2_OFF;
      break;
    case 1:
      M2_LED1_ON;
      //GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_0, 0x01);
      //GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_1, 0x02);
      break;
    case 2:
      M2_LED2_ON;
      //GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_0, 0x00);
      //GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_1, 0x00);
      M2_LED4_OFF;
      break;
    case 3:
      disVal++;
      if(disVal % 2 == 0)
        {
          M2_LED3_ON;
          M2_LED4_ON;
        }
      else
        {
          M2_LED3_OFF;
          M2_LED4_OFF;
        }
      break;
    }
#endif
    if(timeCounter == NUMBER_OF_INTS)
    {
        //g_ui32Counter = 0;
        timeCounter = 0;
#if 0
        disVal++;
        if(disVal % 2 == 0)
        M1_LED_ON;
        else
        M1_LED_OFF;
#endif
        //OLED_P6x8Num(2,4,disVal++);
        //stop_Timer0B();
    }
}
Esempio n. 25
-1
void Timer0IntHandler(void)
{
	// Clear the timer interrupt
	TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
	if(automaticMode){
		if(GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_4)==0x00 && GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_0)==0x00){
			automaticMode = false;
			m_r = 254;
			m_g = 1;
			m_b = 1;
		}
		if(switch1State == 0){
			if(GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_4)==0x00){
				switch1State = 1;
			}
		}
		else if(switch1State == 1){
			if(GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_4)==0x00){
				switch1State = 2;
				step2-=step3;
			}
			else{
				switch1State = 0;
			}
		}
		else {
			if(GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_4)!=0x00){
				switch1State = 0;
			}
		}
		if(switch2State == 0){
			if(GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_0)==0x00){
				switch2State = 1;
			}
		}
		else if(switch2State == 1){
			if(GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_0)==0x00){
				switch2State = 2;
				step2+=step3;
			}
			else{
				switch2State = 0;
			}
		}
		else {
			if(GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_0)!=0x00){
				switch2State = 0;
			}
		}
	}
	else{
		if (!temporaryState){
			if(GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_4)!=0x00 && GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_0)!=0x00){
				temporaryState = 1;
			}
			else
				return;
		}

		if (state == 10) {
			if (!isLClicked() && !isRClicked())
				state = 0;
			return;
		}

		if (state == 0) {
			if (isLClicked() && !isRClicked()) {
				// Increase colour
				if(colour == 1){
					if(m_r < 254) {
						m_r++;
					}
				}
				else if(colour == 2) {
					if(m_g < 254) {
						m_g++;
					}
				}
				else{
					if(m_b < 254) {
						m_b++;
					}
				}
			}

			else if (isRClicked()) {
				state = 1;
				count = 0;
				if (isLClicked())  {state = 10; colour = 2; m_r = 1; m_g = 254; m_b = 1;};
			}
		} else if (state == 1 || state == 2) {
			if (state == 1 && !isRClicked()) {
				// decrease colour
				if(colour == 1){
					if(m_r > 1) {
						m_r--;
					}
				}
				else if(colour == 2) {
					if(m_g > 1) {
						m_g--;
					}
				}
				else{
					if(m_b > 1) {
						m_b--;
					}
				}
				state = 0;
				return;			}

			if (state == 2 && !isRClicked()) {
				if (cont == 1){
					colour = 1;
					m_r = 254; m_g = 1; m_b = 1;
				
				else{
					colour = 3;
					m_r = 1; m_g = 1; m_b = 254;
				}
				state = 0;
			return;
			}

			if (!lcc && isLClicked()) {
				state = 2;
		count += 1;
	
			lcc = 1;
			} else {
				if (!isLClicked())
					lcc = 0;
			}
		}
	}
Esempio n. 26
-1
/*

* Function Name: Timer0IntHandler()

* Input: none

* Output: none

* Description: Handles the timer intrupt generated

* Example Call: Timer0IntHandler();

*/
void Timer0IntHandler(void) {
	TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);

	// SW1 pressed
	if(!GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_4)) {
		if(sw1State==0) sw1State = 1;
		else if(sw1State==1) {
			sw1State = 2;
			sw1Pressed = 1;

			if(sw2Count>100 && sw1Count<150) ++sw1Count;
			else sw1Count = 0;

			if(mode==0) {
				delay = delay - 1000;
				if (delay<1000) delay = 1000;
			}
		}
		else if(sw1State==2) {
			sw1State = 2;

			if(sw1Pressed<150) ++sw1Pressed;
		}
	}
	else {
		if(sw1State==0) sw1State = 0;
		else if(sw1State==1) sw1State = 0;
		else if(sw1State==2) {
			sw1State = 0;

			if(sw1Pressed>100) sw1Count = 0;
			sw1Pressed = 0;
		}
	}

	// SW2 pressed
	if(!GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_0)) {
		if(sw2State==0) sw2State = 1;
		else if(sw2State==1) {
			sw2State = 2;

			if(mode==0) {
				delay = delay + 1000;
				if(delay>100000) delay = 100000;
			}
		}
		else if(sw2State==2) {
			sw2State = 2;

			if(sw2Count<150) ++sw2Count;
		}
	}
	else {
		if(sw2State==0) sw2State = 0;
		else if(sw2State==1) sw2State = 0;
		else if(sw2State==2) {
			sw2State = 0;
			sw1Count = 0;
			sw2Count = 0;
			sw1Pressed = 0;
		}
	}

	// Check if SW1 and/or SW2 have been long pressed
	if(sw1Pressed>100 && sw2Count>100) mode = 3;
	else if(sw2Count>100) {
		if(sw1Count==1) mode = 1;
		else if(sw1Count==2) mode = 2;
	}
}