コード例 #1
0
ファイル: GTBEA_basic.c プロジェクト: IMEMS/Public
/********
 * Main *
 ********/
int main(void) {

	// Control Parameters
	float amp_set_v = 0.2;
	float pi_k = -1;

	float Q1H_V = -1;
	float Q1L_V = 2;
	float Q2H_V = -3;
	float Q2L_V = 4;
	int32_t P_gain2 = 10; // 2 * ALC Proportional Gain
	int32_t I_gain2 = -62; // 2 * ALC Integral Gain
	//int32_t P_gain2 = 2 * PGA_GAIN_MUTE; // Mute
	//int32_t I_gain2 = 2 * PGA_GAIN_MUTE; // Mute

	/* System initialization */
	uint32_t SysClkFreq;
	#ifdef PART_TM4C123GH6PM
		// Set system clock to 80 MHz (400MHz main PLL (divided by 5 - uses DIV400 bit)  [16MHz external xtal drives PLL]
		SysClkFreq = MAP_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
	#endif
	#ifdef PART_TM4C1294NCPDT
		// Set system clock to 120 MHz
		SysClkFreq = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000);
	#endif

	/* Error LED Initialization */
	GTBEA_initErrLED();

	/* PGA Initialization */
	//pga_init(SysClkFreq, false, true); // unmuted, zero crossing mode enabled

	/* UART Comm. Initialization */
	//twe_initVCOM(SysClkFreq, UART_BAUD);

	/* DAC Initialization */
	DACd_initDAC(DAC_RANGE_PM5V | DAC_RANGE_PM5V_EH, DAC_PWR_PU_AMP_SET | DAC_PWR_PU_PI_K | DAC_PWR_PUALL_EH, SysClkFreq);

	DACd_updateDataVolt(DAC_ADDR_NONE_AD | DAC_ADDR_Q1H, DAC_RANGE_PM5V | DAC_RANGE_PM5V_EH, OFFSET_BINARY, OFFSET_BINARY, 0, Q1H_V);
	MAP_SysCtlDelay(4000);
	DACd_updateDataVolt(DAC_ADDR_NONE_AD | DAC_ADDR_Q1L, DAC_RANGE_PM5V | DAC_RANGE_PM5V_EH, OFFSET_BINARY, OFFSET_BINARY, 0, Q1L_V);
	MAP_SysCtlDelay(4000);
	DACd_updateDataVolt(DAC_ADDR_AMP_SET | DAC_ADDR_Q2H, DAC_RANGE_PM5V | DAC_RANGE_PM5V_EH, OFFSET_BINARY, OFFSET_BINARY, amp_set_v - DAC_AMP_SET_OFFSET, Q2H_V);
	MAP_SysCtlDelay(4000);
	DACd_updateDataVolt(DAC_ADDR_PI_K | DAC_ADDR_Q2L, DAC_RANGE_PM5V | DAC_RANGE_PM5V_EH, OFFSET_BINARY, OFFSET_BINARY, pi_k - DAC_PI_K_OFFSET, Q2L_V);
	MAP_SysCtlDelay(4000);
	DACd_loadDACs_AH();
	//DACd_loadDACsPin_EH();
	//pga_setGainInt(P_gain2, I_gain2);
	//pga_setGainInt(2 * PGA_GAIN_MUTE, 2 * PGA_GAIN_MUTE);  // Mute while testing other circuits...

	while(1) {
		// wait...
	}
}
コード例 #2
0
void ADC0_SampleHandler()
{
	MAP_ADCIntClear(ADC0_BASE, 3);

	MAP_ADCSequenceDataGet(ADC0_BASE, 3, adc_value);

	inputData[inputIndex++] = (float) adc_value[0];

	if (inputIndex > TEST_LENGTH_SAMPLES - 1)
	{
		inputIndex = 0;

		// 'Permanently disable interrupt'
		// We will only run the fft once for now
		MAP_ADCIntDisable(ADC0_BASE, 3);
		MAP_TimerDisable(TIMER1_BASE, TIMER_A);

		runFFT();

		// Delay for 1 second
		MAP_SysCtlDelay(g_ui32SysClock / 3);

		//Re-enable timer and ADC interrupts to run another FFT
		MAP_ADCIntEnable(ADC0_BASE, 3);
		MAP_TimerEnable(TIMER1_BASE, TIMER_A);

	}

}
コード例 #3
0
ファイル: tn_user.c プロジェクト: serikovigor/surd
void hw_delay(unsigned long uS)
{
    TN_INTSAVE_DATA
    tn_disable_interrupt();
    MAP_SysCtlDelay(MAP_SysCtlClockGet() / 1000000 * uS / 3); // The loop takes 3 cycles/loop
    tn_enable_interrupt();
}
コード例 #4
0
ファイル: blink.c プロジェクト: chaitanya4b3/Tiva-Test
int main(){

	// System clock set to run at 50 MHz from PLL with crystal ref.
	// With EK-TM4C123GXL Launchpad, no need to change SYSCTL_XTAL_16MHZ to anything else
	MAP_SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
	MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
	MAP_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, LED_RED|LED_BLUE|LED_GREEN);

	while(1){
		MAP_GPIOPinWrite(GPIO_PORTF_BASE, LED_RED|LED_GREEN|LED_BLUE, LED_GREEN|LED_RED|LED_BLUE);
		// SysCtlDelay and ROM_SysCtlDelay behave differently, see http://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/t/256106.aspx
		MAP_SysCtlDelay(2333333);	// Number of loop iterations to perform @ 3 cycles/loop using ROM. Not Accurate. Input = (DesiredTime*ClockFrequency)/3
		MAP_GPIOPinWrite(GPIO_PORTF_BASE, LED_RED|LED_GREEN|LED_BLUE, 0);
		MAP_SysCtlDelay(16333333);
	}
}
コード例 #5
0
ファイル: delay.c プロジェクト: Veldmonster/contiki-mirror
/* Wait for a specific time in 1 micro second resolution.
 * Max value of t = 85899345 at 50MHz clock which allow
 * (sys_ctl_clock * t) not to exceed 0xFFFFFFFF
 * The overhead of calling this delay is approx. 1us at 50MHz clock */
void delay_us(unsigned long t) {
	if (t > 0) {
		t--; /* Compensate for the overhead of calling this delay */
	}

	unsigned long iterations = ((sys_ctl_clock * t) / 3UL);
	if (iterations == 0) {
		return;
	}

	MAP_SysCtlDelay(iterations);
}
コード例 #6
0
ファイル: enc28j60.c プロジェクト: mota37/Modbus
/**
 * Write value to PHY address.
 * Reading procedure is described in ENC28J60 datasheet
 * section 3.3.
 */
void enc_phy_write(uint8_t addr, uint16_t value) {
	WRITE_REG(ENC_MIREGADR, addr);
	WRITE_REG(ENC_MIWRL, value & 0xFF);
	WRITE_REG(ENC_MIWRH, value >> 8);

	MAP_SysCtlDelay(((MAP_SysCtlClockGet()/3)/1000));

	uint8_t stat;
	do {
		stat = READ_MREG(ENC_MISTAT);
	} while (stat & ENC_MISTAT_BUSY);
}
コード例 #7
0
ファイル: main.c プロジェクト: doragasu/stellaris-fatfs
// Couldn't manage to build UTF version without warnings. Trying
// --fwide-exec-charset=UTF-16 build flag doesn't help.
int main(void)
{
    FATFS fs;
    FIL f;
    FRESULT returned;
    UINT scratch;
    int i;

	/// Set clock to 66,67 MHz (200 MHz / 3)
    MAP_SysCtlClockSet(SYSCTL_SYSDIV_3 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    /// LED initialization
    RgbLedInit();

    /// Initialize UART0 (used for stdout)
    UartInit(0, 115200);
    printf("Test start!\r\n");

    /// Color cycle the LED. Ends with red color.
    for (i = 7; i > 0; i--)
    {
    	MAP_SysCtlDelay(2500000);
    	RgbLedSet(i<<1);
    }

    // TODO: check mount options
    if ((returned = f_mount(&fs, _T("/"), 0)))
    {
        printf("ERROR: couldn't mount volume.\r\n");
        return 1;
    }

    if ((returned = f_open(&f, _T("test.txt"), FA_CREATE_ALWAYS | FA_WRITE)))
    {
        printf("ERROR: couldn't open file.\r\n");
        return 2;
    }

    if ((returned = f_write(&f, HELLO_STR, HELLO_STR_LEN, &scratch)))
    {
        printf("ERROR: couldn't write to file.\r\n");
        return 3;
    }
    printf("%d bytes written.\r\n", scratch);

    // TODO: unmount volume or at least sync filesystem
    f_sync(&f);
   return 0;
}
コード例 #8
0
void runFFT()
{
	int32_t startTime, stopTime, totalTime;
	float32_t maxValue;

	// Setup timer
	// This is just used for timing during test!!
//	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
//	ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
//	ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, g_ui32SysClock); // 1 second

	// Create a RFFT instance
	arm_rfft_fast_instance_f32 fft;
	arm_rfft_fast_init_f32(&fft,fftSize);

	// Run FFT
//	ROM_TimerEnable(TIMER0_BASE, TIMER_A);
//	startTime = TIMER0_TAR_R;

	/* Process the real data through the RFFT module */
	arm_rfft_fast_f32(&fft, inputData, rfftOutput, ifftFlag);

	/* Process the data through the Complex Magnitude Module for
	  calculating the magnitude at each bin */
	arm_cmplx_mag_f32(rfftOutput, testOutput_44khz, fftSize / 2);

	// The 0 index of FFT output is the DC component of
	// the input signal. We don't want to consider this when
	// looking for the peak frequency.
	testOutput_44khz[0] = 0;

	/* Calculates maxValue and returns corresponding BIN value */
	arm_max_f32(testOutput_44khz, TEST_LENGTH_SAMPLES / 2, &maxValue, &testIndex);

//	stopTime = TIMER0_TAR_R;

//	totalTime = startTime - stopTime;

//	int totalTimeUs = totalTime / 120;
	//int peakFrequency = testIndex * 22050 / 128;
	int peakFrequency = testIndex * SAMPLING_RATE / TEST_LENGTH_SAMPLES;

	MAP_SysCtlDelay(1);


}
コード例 #9
0
ファイル: enc28j60.c プロジェクト: mota37/Modbus
/**
 * Read value from PHY address.
 * Reading procedure is described in ENC28J60 datasheet
 * section 3.3.
 */
uint16_t enc_phy_read(uint8_t addr) {
	/*
	 1. Write the address of the PHY register to read
	 from into the MIREGADR register.*/
	WRITE_REG(ENC_MIREGADR, addr);

	/*2. Set the MICMD.MIIRD bit. The read operation
	 begins and the MISTAT.BUSY bit is set.*/
	WRITE_REG(ENC_MICMD, 0x1);

	/*3. Wait 10.24 μs. Poll the MISTAT.BUSY bit to be
	 certain that the operation is complete. While
	 busy, the host controller should not start any
	 MIISCAN operations or write to the MIWRH
	 register.
	 When the MAC has obtained the register
	 contents, the BUSY bit will clear itself.*/

	/* Assuming that we are running at 1MHz, a single cycle is
	 * 1 us */
	MAP_SysCtlDelay(((MAP_SysCtlClockGet()/3)/1000));

	uint8_t stat;
	do {
		stat = READ_MREG(ENC_MISTAT);
	} while (stat & ENC_MISTAT_BUSY);

	/*4. Clear the MICMD.MIIRD bit.*/
	WRITE_REG(ENC_MICMD, 0x00);

	/*5. Read the desired data from the MIRDL and
	 MIRDH registers. The order that these bytes are
	 accessed is unimportant.
	 */
	uint16_t ret;
	ret = READ_MREG(ENC_MIRDL) & 0xFF;
	ret |= READ_MREG(ENC_MIRDH) << 8;

	return ret;
}
コード例 #10
0
ファイル: CAN.cpp プロジェクト: vortex314/projects
//*****************************************************************************
//
// This function provides a 1 second delay using a simple polling method.
//
//*****************************************************************************
void SimpleDelay(void) {
//
// Delay cycles for 1 second
//
	MAP_SysCtlDelay(16000000 / 3);
}
コード例 #11
0
void delayMicroseconds(unsigned long usec){
	MAP_SysCtlDelay((ulClockMS/1000)*usec);
}
コード例 #12
0
ファイル: main.cpp プロジェクト: goncabrita/purpins_firmware
	void delayuSec(unsigned long usec)
	{
		MAP_SysCtlDelay((ulClockMS/1000)*usec);
	}
コード例 #13
0
ファイル: usbstick.c プロジェクト: PhamVanNhi/ECE5770
//*****************************************************************************
//
// This is called by the application main loop to perform regular processing.
// It keeps the USB host stack running and tracks the state of the attached
// device.
//
//*****************************************************************************
void
USBStickRun(void)
{
    //
    // Call the USB stack to keep it running.
    //
    USBHCDMain();

    //
    // Take action based on the application state.
    //
    switch(g_iState)
    {
        //
        // A device has enumerated.
        //
        case eSTATE_DEVICE_ENUM:
        {
            //
            // Check to see if the device is ready.  If not then stay
            // in this state and we will check it again on the next pass.
            //
            if(USBHMSCDriveReady(g_psMSCInstance) != 0)
            {
                //
                // Wait about 500ms before attempting to check if the
                // device is ready again.
                //
                MAP_SysCtlDelay(MAP_SysCtlClockGet()/3);
                break;
            }

            //
            // If there were no errors reported, we are ready for
            // MSC operation.
            //
            g_iState = eSTATE_DEVICE_READY;

            //
            // Set the Device Present flag.
            //
            g_ui32Flags = FLAGS_DEVICE_PRESENT;

            break;
        }

        //
        // If there is no device then just wait for one.
        //
        case eSTATE_NO_DEVICE:
        {
            if(g_ui32Flags == FLAGS_DEVICE_PRESENT)
            {
                //
                // Clear the Device Present flag.
                //
                g_ui32Flags &= ~(FLAGS_DEVICE_PRESENT | FLAGS_FILE_OPENED);
            }
            break;
        }

        //
        // An unknown device was connected.
        //
        case eSTATE_UNKNOWN_DEVICE:
        {
            //
            // If this is a new device then change the status.
            //
            if((g_ui32Flags & FLAGS_DEVICE_PRESENT) == 0)
            {
                //
                // Unknown device is present
                //
            }

            //
            // Set the Device Present flag even though the unknown device
            // is not useful to us.
            //
            g_ui32Flags = FLAGS_DEVICE_PRESENT;
            break;
        }

        //
        // The device is ready and in use.
        //
        case eSTATE_DEVICE_READY:
        {
            break;
        }

        //
        // Something has caused a power fault.
        //
        case eSTATE_POWER_FAULT:
        {
            break;
        }

        //
        // Unexpected USB state.  Set back to default.
        //
        default:
        {
            g_iState = eSTATE_NO_DEVICE;
            g_ui32Flags &= ~(FLAGS_DEVICE_PRESENT | FLAGS_FILE_OPENED);
            break;
        }
    }
}
コード例 #14
0
//*****************************************************************************
//
// Initialization function for the InnoLux display. This turns on the backlight
// after the required 200mS delay.
//
// VLED control - PD6
// LED_EN       - PE5
// LED_PWM      - PR2 or PE4
//
//*****************************************************************************
void
InitInnoLux(uint32_t ui32SysClk)
{
    //
    // Turn on GPIO Ports D, E and R.
    //
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
#ifdef USE_PR2_FOR_PWM
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOR);
#endif

    //
    // Configure PD6 (VLED) as an output.
    //
    HWREG(GPIO_PORTD_BASE + GPIO_O_PCTL) &= 0xF0FFFFFF;
    MAP_GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_6);

    //
    // Configure PE5 and PR2 as outputs.
    //
    HWREG(GPIO_PORTE_BASE + GPIO_O_PCTL) &= 0xFF0FFFFF;
    MAP_GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_5);
#ifdef USE_PR2_FOR_PWM
    HWREG(GPIO_PORTR_BASE + GPIO_O_PCTL) &= 0xFFFFF0FF;
    MAP_GPIOPinTypeGPIOOutput(GPIO_PORTR_BASE, GPIO_PIN_2);
    GPIOPadConfigSet(GPIO_PORTR_BASE, GPIO_PIN_2, GPIO_STRENGTH_12MA, GPIO_PIN_TYPE_STD);
#else
    HWREG(GPIO_PORTE_BASE + GPIO_O_PCTL) &= 0xFFF0FFFF;
    MAP_GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_4);
#endif

    //
    // Drive the enables low for now.
    //
    MAP_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_6, 0);
#ifdef USE_PR2_FOR_PWM
    MAP_GPIOPinWrite(GPIO_PORTR_BASE, GPIO_PIN_2, 0);
    MAP_GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_5, 0);
#else
    MAP_GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_5 | GPIO_PIN_4, 0);
#endif


    //
    // Wait 200mS.  This delay is specified in the display datasheet.
    //
    MAP_SysCtlDelay((ui32SysClk / 5) / 3);

    //
    // Drive PD6 high to enable VLED to the display.
    //
    MAP_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_6, GPIO_PIN_6);

    //
    // Wait another 10mS before we turn on the PWM to set the display
    // backlight brightness.
    //
    MAP_SysCtlDelay((ui32SysClk / 100) / 3);

    //
    // Start the LED backlight signaling by asserting LED-PWM (PR2).
    //
#ifdef USE_PR2_FOR_PWM
    MAP_GPIOPinWrite(GPIO_PORTR_BASE, GPIO_PIN_2, GPIO_PIN_2);
#else
    MAP_GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_4, GPIO_PIN_4);
#endif

    //
    // Wait another 10mS before returning to ensure that the raster is not
    // enabled too soon.
    //
    MAP_SysCtlDelay((ui32SysClk / 100) / 3);

    //
    // Enable the LED backlight by asserting LED-EN (PE5).
    //
    MAP_GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_5, GPIO_PIN_5);
}
コード例 #15
0
ファイル: main.c プロジェクト: Hoxford/tyler-woogduh
//
//a processor loop wait timer.  The number of cycles are calculated from the frequency of the main clock.
//
void wait_time (unsigned int tenths_of_seconds)
{
	MAP_SysCtlDelay(( MAP_SysCtlClockGet() / 30  )*tenths_of_seconds );
}
コード例 #16
0
ファイル: LibSensorTOF.c プロジェクト: Edunj/DriverTiva
//*****************************************************************************
//
//! Prepare a pin for use with a TOF sensor.
//!
//! \param GPIOPin is on the pin for the TOF sensor.
//!
//! This function initializes the GPIO interrupts and peripherals necessary
//! to run the corresponding GPIO port.
//!
//! The \e GPIOPin parameter can take on the following values:
//!
//! - \b PA0 - Pin PA0
//! - \b PA1 - Pin PA1
//! - \b PA2 - Pin PA2
//! - \b PA3 - Pin PA3
//! - \b PA4 - Pin PA4
//! - \b PA5 - Pin PA5
//! - \b PA6 - Pin PA6
//! - \b PA7 - Pin PA7
//! - \b PB0 - Pin PB0
//! - \b PB1 - Pin PB1
//! - \b PB2 - Pin PB2
//! - \b PB3 - Pin PB3
//! - \b PB4 - Pin PB4
//! - \b PB5 - Pin PB5
//! - \b PB6 - Pin PB6
//! - \b PB7 - Pin PB7
//! - \b PC0 - Pin PC0
//! - \b PC1 - Pin PC1
//! - \b PC2 - Pin PC2
//! - \b PC3 - Pin PC3
//! - \b PC4 - Pin PC4
//! - \b PC5 - Pin PC5
//! - \b PC6 - Pin PC6
//! - \b PC7 - Pin PC7
//! - \b PD0 - Pin PD0
//! - \b PD1 - Pin PD1
//! - \b PD2 - Pin PD2
//! - \b PD3 - Pin PD3
//! - \b PD4 - Pin PD4
//! - \b PD5 - Pin PD5
//! - \b PD6 - Pin PD6
//! - \b PD7 - Pin PD7
//! - \b PE0 - Pin PE0
//! - \b PE1 - Pin PE1
//! - \b PE2 - Pin PE2
//! - \b PE3 - Pin PE3
//! - \b PE4 - Pin PE4
//! - \b PE5 - Pin PE5
//! - \b PE6 - Pin PE6
//! - \b PE7 - Pin PE7
//! - \b PF0 - Pin PF0
//! - \b PF1 - Pin PF1
//! - \b PF2 - Pin PF2
//! - \b PF3 - Pin PF3
//! - \b PF4 - Pin PF4
//! - \b PF5 - Pin PF5
//! - \b PF6 - Pin PF6
//! - \b PF7 - Pin PF7
//!
//! \return None.
//!
//*****************************************************************************
void
TOFEchoInit(uint8_t GPIOPin)
{
    //
    // Enable Peripheral Clocks
    //
#ifdef USEPORTA
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    MAP_SysCtlDelay(3);
#endif
#ifdef USEPORTB
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    MAP_SysCtlDelay(3);
#endif
#ifdef USEPORTC
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
    MAP_SysCtlDelay(3);
#endif
#ifdef USEPORTD
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    MAP_SysCtlDelay(3);
#endif
#ifdef USEPORTE
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    MAP_SysCtlDelay(3);
#endif
#ifdef USEPORTF
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    MAP_SysCtlDelay(3);
#endif

    switch(GPIOPin){
#ifdef USEPORTA
	//Puerto A
#ifdef USEPORTAPIN0
    case PA0:{
    	if(!ConfigGPIO.GPIOS.PoA0){
		//
		// Enable pin PA0 for GPIOInput
		//
    	ConfigGPIO.GPIOS.PoA0 = 1;
		MAP_GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_0);
		GPIOIntTypeSet(GPIO_PORTA_BASE,GPIO_PIN_0,GPIO_HIGH_LEVEL);
		Mask[0] += GPIO_INT_PIN_0;
    	}
		break;
    }
#endif
#ifdef USEPORTAPIN1
    case PA1:{
    	if(!ConfigGPIO.GPIOS.PoA1){
		//
		// Enable pin PA1 for GPIOInput
		//
    	ConfigGPIO.GPIOS.PoA1 = 1;
		MAP_GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_1);
		GPIOIntTypeSet(GPIO_PORTA_BASE,GPIO_PIN_1,GPIO_HIGH_LEVEL);
		Mask[0] += GPIO_INT_PIN_1;
    	}
		break;
    }
#endif
#ifdef USEPORTAPIN2
    case PA2:{
    	if(!ConfigGPIO.GPIOS.PoA2){
    	//
		// Enable pin PA2 for GPIOInput
		//
    	ConfigGPIO.GPIOS.PoA2 = 1;
		MAP_GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_2);
		GPIOIntTypeSet(GPIO_PORTA_BASE,GPIO_PIN_2,GPIO_HIGH_LEVEL);
		Mask[0] += GPIO_INT_PIN_2;
    	}
		break;
    }
#endif
#ifdef USEPORTAPIN3
    case PA3:{
    	if(!ConfigGPIO.GPIOS.PoA3){
    	//
		// Enable pin PA3 for GPIOInput
		//
        ConfigGPIO.GPIOS.PoA3 = 1;
		GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_3);
		GPIOIntTypeSet(GPIO_PORTA_BASE,GPIO_PIN_3,GPIO_HIGH_LEVEL);
		Mask[0] += GPIO_INT_PIN_3;
    	}
		break;
	}
#endif
#ifdef USEPORTAPIN4
	case PA4:{
		if(!ConfigGPIO.GPIOS.PoA4){
		//
		// Enable pin PA4 for GPIOInput
		//
	    ConfigGPIO.GPIOS.PoA4 = 1;
		MAP_GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_4);
		GPIOIntTypeSet(GPIO_PORTA_BASE,GPIO_PIN_4,GPIO_HIGH_LEVEL);
		Mask[0] += GPIO_INT_PIN_4;
		}
		break;
	}
#endif
#ifdef USEPORTAPIN5
	case PA5:{
		if(!ConfigGPIO.GPIOS.PoA5){
		//
		// Enable pin PA5 for GPIOInput
		//
	    ConfigGPIO.GPIOS.PoA5 = 1;
		MAP_GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_5);
		GPIOIntTypeSet(GPIO_PORTA_BASE,GPIO_PIN_5,GPIO_HIGH_LEVEL);
		Mask[0] += GPIO_INT_PIN_5;
		}
		break;
	}
#endif
#ifdef USEPORTAPIN6
	case PA6:{
		if(!ConfigGPIO.GPIOS.PoA6){
		//
		// Enable pin PA6 for GPIOInput
		//
	    ConfigGPIO.GPIOS.PoA6 = 1;
		MAP_GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_6);
		GPIOIntTypeSet(GPIO_PORTA_BASE,GPIO_PIN_6,GPIO_HIGH_LEVEL);
		Mask[0] += GPIO_INT_PIN_6;
		}
		break;
	}
#endif
#ifdef USEPORTAPIN7
	case PA7:{
		if(!ConfigGPIO.GPIOS.PoA7){
		//
		// Enable pin PA7 for GPIOInput
		//
		ConfigGPIO.GPIOS.PoA7 = 1;
		MAP_GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_7);
		GPIOIntTypeSet(GPIO_PORTA_BASE,GPIO_PIN_7,GPIO_HIGH_LEVEL);
		Mask[0] += GPIO_INT_PIN_7;
		}
		break;
	}
#endif
#endif
#ifdef USEPORTB
	//Puerto B
#ifdef USEPORTBPIN0
	case PB0:{
		if(!ConfigGPIO.GPIOS.PoB0){
		//
		// Enable pin PB0 for GPIOInput
		//
		ConfigGPIO.GPIOS.PoB0 = 1;
		MAP_GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_0);
		GPIOIntTypeSet(GPIO_PORTB_BASE,GPIO_PIN_0,GPIO_HIGH_LEVEL);
		Mask[1] += GPIO_INT_PIN_0;
		}
		break;
	}
#endif
#ifdef USEPORTBPIN1
	case PB1:{
		if(!ConfigGPIO.GPIOS.PoB1){
		//
		// Enable pin PB1 for GPIOInput
		//
		ConfigGPIO.GPIOS.PoB1 = 1;
		MAP_GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_1);
		GPIOIntTypeSet(GPIO_PORTB_BASE,GPIO_PIN_1,GPIO_HIGH_LEVEL);
		Mask[1] += GPIO_INT_PIN_0;
		}
		break;
	}
#endif
#ifdef USEPORTBPIN2
	case PB2:{
		if(!ConfigGPIO.GPIOS.PoB2){
		//
		// Enable pin PB2 for GPIOInput
		//
		ConfigGPIO.GPIOS.PoB2 = 1;
		MAP_GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_2);
		GPIOIntTypeSet(GPIO_PORTB_BASE,GPIO_PIN_2,GPIO_HIGH_LEVEL);
		Mask[1] += GPIO_INT_PIN_2;
		}
		break;
	}
#endif
#ifdef USEPORTBPIN3
	case PB3:{
		if(!ConfigGPIO.GPIOS.PoB3){
		//
		// Enable pin PB3 for GPIOInput
		//
		ConfigGPIO.GPIOS.PoB3 = 1;
		MAP_GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_3);
		GPIOIntTypeSet(GPIO_PORTB_BASE,GPIO_PIN_3,GPIO_RISING_EDGE  );
		Mask[1] += GPIO_INT_PIN_3;
		}
		break;
	}
#endif
#ifdef USEPORTBPIN4
	case PB4:{
		if(!ConfigGPIO.GPIOS.PoB4){
		//
		// Enable pin PB4 for GPIOInput
		//
			ConfigGPIO.GPIOS.PoB4 = 1;
		MAP_GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_4);
		GPIOIntTypeSet(GPIO_PORTB_BASE,GPIO_PIN_4,GPIO_HIGH_LEVEL);
		Mask[1] += GPIO_INT_PIN_4;
		}
		break;
	}
#endif
#ifdef USEPORTBPIN5
	case PB5:{
		if(!ConfigGPIO.GPIOS.PoB5){
		//
		// Enable pin PB5 for GPIOInput
		//
			ConfigGPIO.GPIOS.PoB5 = 1;
		MAP_GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_5);
		GPIOIntTypeSet(GPIO_PORTB_BASE,GPIO_PIN_5,GPIO_HIGH_LEVEL);
		Mask[1] += GPIO_INT_PIN_5;
		}
		break;
	}
#endif
#ifdef USEPORTBPIN6
	case PB6:{
		if(!ConfigGPIO.GPIOS.PoB6){
		//
		// Enable pin PB6 for GPIOInput
		//
			ConfigGPIO.GPIOS.PoB6 = 1;
		MAP_GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_6);
		GPIOIntTypeSet(GPIO_PORTB_BASE,GPIO_PIN_6,GPIO_HIGH_LEVEL);
		Mask[1] += GPIO_INT_PIN_6;
		}
		break;
	}
#endif
#ifdef USEPORTBPIN7
	case PB7:{
		if(!ConfigGPIO.GPIOS.PoB7){
		//
		// Enable pin PB7 for GPIOInput
		//
			ConfigGPIO.GPIOS.PoB7 = 1;
		MAP_GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_7);
		GPIOIntTypeSet(GPIO_PORTB_BASE,GPIO_PIN_7,GPIO_HIGH_LEVEL);
		Mask[1] += GPIO_INT_PIN_7;
		}
			break;
		}
#endif
#endif
#ifdef USEPORTC
	//Puerto C
#ifdef USEPORTCPIN4
	case PC4:{
		if(!ConfigGPIO.GPIOS.PoC4){
		//
		// Enable pin PC4 for GPIOInput
		//
			ConfigGPIO.GPIOS.PoC4 = 1;
		MAP_GPIOPinTypeGPIOInput(GPIO_PORTC_BASE, GPIO_PIN_4);
		GPIOIntTypeSet(GPIO_PORTC_BASE,GPIO_PIN_4,GPIO_HIGH_LEVEL);
		Mask[2] += GPIO_INT_PIN_4;
		}
		break;
	}
#endif
#ifdef USEPORTCPIN5
	case PC5:{
		if(!ConfigGPIO.GPIOS.PoC5){
		//
		// Enable pin PC5 for GPIOInput
		//
			ConfigGPIO.GPIOS.PoC5 = 1;
		MAP_GPIOPinTypeGPIOInput(GPIO_PORTC_BASE, GPIO_PIN_5);
		GPIOIntTypeSet(GPIO_PORTC_BASE,GPIO_PIN_5,GPIO_HIGH_LEVEL);
		Mask[2] += GPIO_INT_PIN_5;
		}
		break;
	}
#endif
#ifdef USEPORTCPIN6
	case PC6:{
		if(!ConfigGPIO.GPIOS.PoC6){
		//
		// Enable pin PC6 for GPIOInput
		//
			ConfigGPIO.GPIOS.PoC6 = 1;
		MAP_GPIOPinTypeGPIOInput(GPIO_PORTC_BASE, GPIO_PIN_6);
		GPIOIntTypeSet(GPIO_PORTC_BASE,GPIO_PIN_6,GPIO_HIGH_LEVEL);
		Mask[2] += GPIO_INT_PIN_6;
		}
		break;
	}
#endif
#ifdef USEPORTCPIN7
	case PC7:{
		if(!ConfigGPIO.GPIOS.PoC7){
		//
		// Enable pin PC7 for GPIOInput
		//
			ConfigGPIO.GPIOS.PoC7 = 1;
		MAP_GPIOPinTypeGPIOInput(GPIO_PORTC_BASE, GPIO_PIN_7);
		GPIOIntTypeSet(GPIO_PORTC_BASE,GPIO_PIN_7,GPIO_HIGH_LEVEL);
		Mask[2] += GPIO_INT_PIN_7;
		}
		break;
	}
#endif
#endif
#ifdef USEPORTD
	//Puerto D
#ifdef USEPORTDPIN0
	case PD0:{
		if(!ConfigGPIO.GPIOS.PoD0){
		//
		// Enable pin PD0 for GPIOInput
		//
			ConfigGPIO.GPIOS.PoD0 = 1;
		MAP_GPIOPinTypeGPIOInput(GPIO_PORTD_BASE, GPIO_PIN_0);
		GPIOIntTypeSet(GPIO_PORTD_BASE,GPIO_PIN_0,GPIO_HIGH_LEVEL);
		Mask[3] += GPIO_INT_PIN_0;
		}
		break;
	}
#endif
#ifdef USEPORTDPIN1
	case PD1:{
		if(!ConfigGPIO.GPIOS.PoD1){
		//
		// Enable pin PD1 for GPIOInput
		//
			ConfigGPIO.GPIOS.PoD1 = 1;
		MAP_GPIOPinTypeGPIOInput(GPIO_PORTD_BASE, GPIO_PIN_1);
		GPIOIntTypeSet(GPIO_PORTD_BASE,GPIO_PIN_1,GPIO_HIGH_LEVEL);
		Mask[3] += GPIO_INT_PIN_1;
		}
		break;
	}
#endif
#ifdef USEPORTDPIN2
	case PD2:{
		if(!ConfigGPIO.GPIOS.PoD2){
		//
		// Enable pin PD2 for GPIOInput
		//
			ConfigGPIO.GPIOS.PoD2 = 1;
		MAP_GPIOPinTypeGPIOInput(GPIO_PORTD_BASE, GPIO_PIN_2);
		GPIOIntTypeSet(GPIO_PORTD_BASE,GPIO_PIN_2,GPIO_HIGH_LEVEL);
		Mask[3] += GPIO_INT_PIN_2;
		}
		break;
	}
#endif
#ifdef USEPORTDPIN3
	case PD3:{
		if(!ConfigGPIO.GPIOS.PoD3){
		//
		// Enable pin PD3 for GPIOInput
		//
			ConfigGPIO.GPIOS.PoD3 = 1;
		MAP_GPIOPinTypeGPIOInput(GPIO_PORTD_BASE, GPIO_PIN_3);
		GPIOIntTypeSet(GPIO_PORTD_BASE,GPIO_PIN_3,GPIO_HIGH_LEVEL);
		Mask[3] += GPIO_INT_PIN_3;
		}
		break;
	}
#endif
#ifdef USEPORTDPIN4
	case PD4:{
		if(!ConfigGPIO.GPIOS.PoD4){
		//
		// Enable pin PD4 for GPIOInput
		//
			ConfigGPIO.GPIOS.PoD4 = 1;
		MAP_GPIOPinTypeGPIOInput(GPIO_PORTD_BASE, GPIO_PIN_4);
		GPIOIntTypeSet(GPIO_PORTD_BASE,GPIO_PIN_4,GPIO_HIGH_LEVEL);
		Mask[3] += GPIO_INT_PIN_4;
		}
		break;
	}
#endif
#ifdef USEPORTDPIN5
	case PD5:{
		if(!ConfigGPIO.GPIOS.PoD5){
		//
		// Enable pin PD5 for GPIOInput
		//
			ConfigGPIO.GPIOS.PoD5 = 1;
		MAP_GPIOPinTypeGPIOInput(GPIO_PORTD_BASE, GPIO_PIN_5);
		GPIOIntTypeSet(GPIO_PORTD_BASE,GPIO_PIN_5,GPIO_HIGH_LEVEL);
		Mask[3] += GPIO_INT_PIN_5;
		}
		break;
	}
#endif
#ifdef USEPORTDPIN6
	case PD6:{
		if(!ConfigGPIO.GPIOS.PoD6){
		//
		// Enable pin PD6 for GPIOInput
		//
			ConfigGPIO.GPIOS.PoD6 = 1;
		MAP_GPIOPinTypeGPIOInput(GPIO_PORTD_BASE, GPIO_PIN_6);
		GPIOIntTypeSet(GPIO_PORTD_BASE,GPIO_PIN_6,GPIO_HIGH_LEVEL);
		Mask[3] += GPIO_INT_PIN_6;
		}
		break;
	}
#endif
#ifdef USEPORTDPIN7
	case PD7:{
		if(!ConfigGPIO.GPIOS.PoD7){
		//
		// Enable pin PD7 for GPIOInput
		//

		//
		//First open the lock and select the bits we want to modify in the GPIO commit register.
		//
		HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
		HWREG(GPIO_PORTD_BASE + GPIO_O_CR) = 0x80;

		//
		//Now modify the configuration of the pins that we unlocked.
		//
		ConfigGPIO.GPIOS.PoD7 = 1;
		MAP_GPIOPinTypeGPIOInput(GPIO_PORTD_BASE, GPIO_PIN_7);
		GPIOIntTypeSet(GPIO_PORTD_BASE,GPIO_PIN_7,GPIO_HIGH_LEVEL);
		Mask[3] += GPIO_INT_PIN_7;
		}
		break;
	}
#endif
#endif
#ifdef USEPORTE
	//Puerto E
#ifdef USEPORTEPIN0
	case PE0:{
		if(!ConfigGPIO.GPIOS.PoE0){
		//
		// Enable pin PE0 for GPIOInput
		//
		ConfigGPIO.GPIOS.PoE0 = 1;
		MAP_GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_0);
		GPIOIntTypeSet(GPIO_PORTE_BASE,GPIO_PIN_0,GPIO_HIGH_LEVEL);
		Mask[4] += GPIO_INT_PIN_0;
		}
		break;
	}
#endif
#ifdef USEPORTEPIN1
	case PE1:{
		if(!ConfigGPIO.GPIOS.PoE1){
		//
		// Enable pin PE1 for GPIOInput
		//
			ConfigGPIO.GPIOS.PoE1 = 1;
		MAP_GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_1);
		GPIOIntTypeSet(GPIO_PORTE_BASE,GPIO_PIN_1,GPIO_HIGH_LEVEL);
		Mask[4] += GPIO_INT_PIN_1;
		}
		break;
	}
#endif
#ifdef USEPORTEPIN2
	case PE2:{
		if(!ConfigGPIO.GPIOS.PoE2){
		//
		// Enable pin PE2 for GPIOInput
		//
			ConfigGPIO.GPIOS.PoE2 = 1;
		MAP_GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_2);
		GPIOIntTypeSet(GPIO_PORTE_BASE,GPIO_PIN_2,GPIO_HIGH_LEVEL);
		Mask[4] += GPIO_INT_PIN_2;
		}

		//	break;
	}
#endif
#ifdef USEPORTEPIN3
	case PE3:{
		if(!ConfigGPIO.GPIOS.PoE3){
		// Enable pin PE3 for GPIOInput
		//
			ConfigGPIO.GPIOS.PoE3 = 1;
		MAP_GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_3);
		GPIOIntTypeSet(GPIO_PORTE_BASE,GPIO_PIN_3,GPIO_HIGH_LEVEL);
		Mask[4] += GPIO_INT_PIN_3;
		}
		break;
	}
#endif
#ifdef USEPORTEPIN4
	case PE4:{
		if(!ConfigGPIO.GPIOS.PoE4){
		//
		// Enable pin PE4 for GPIOInput
		//
			ConfigGPIO.GPIOS.PoE4 = 1;
		MAP_GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_4);
		GPIOIntTypeSet(GPIO_PORTE_BASE,GPIO_PIN_4,GPIO_HIGH_LEVEL);
		Mask[4] += GPIO_INT_PIN_4;
		}
		break;
	}
#endif
#ifdef USEPORTEPIN5
	case PE5:{
		if(!ConfigGPIO.GPIOS.PoE5){
		//
		// Enable pin PE5 for GPIOInput
		//
			ConfigGPIO.GPIOS.PoE5 = 1;
		MAP_GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_5);
		GPIOIntTypeSet(GPIO_PORTE_BASE,GPIO_PIN_5,GPIO_HIGH_LEVEL);
		Mask[4] += GPIO_INT_PIN_5;
		}
		break;
	}
#endif
#endif
#ifdef USEPORTF
	//Puerto F
#ifdef USEPORTFPIN0
	case PF0:{
		if(!ConfigGPIO.GPIOS.PoF0){
		//
		// Enable pin PF0 for GPIOInput
		//

		//
		//First open the lock and select the bits we want to modify in the GPIO commit register.
		//
		HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
		HWREG(GPIO_PORTF_BASE + GPIO_O_CR) = 0x1;

		//
		//Now modify the configuration of the pins that we unlocked.
		//
		ConfigGPIO.GPIOS.PoF0 = 1;
		MAP_GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_0);
		GPIOIntTypeSet(GPIO_PORTF_BASE,GPIO_PIN_0,GPIO_HIGH_LEVEL);
		Mask[5] += GPIO_INT_PIN_0;
		}
		break;
	}
#endif
#ifdef USEPORTFPIN1
	case PF1:{
		if(!ConfigGPIO.GPIOS.PoF1){
		//
		// Enable pin PF1 for GPIOInput
		//
			ConfigGPIO.GPIOS.PoF1 = 1;
		MAP_GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_1);
		GPIOIntTypeSet(GPIO_PORTF_BASE,GPIO_PIN_1,GPIO_HIGH_LEVEL);
		Mask[5] += GPIO_INT_PIN_1;
		}
		break;
	}
#endif
#ifdef USEPORTFPIN2
	case PF2:{
		if(!ConfigGPIO.GPIOS.PoF2){
		//
		// Enable pin PF2 for GPIOInput
		//
			ConfigGPIO.GPIOS.PoF2 = 1;
		MAP_GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_2);
		GPIOIntTypeSet(GPIO_PORTF_BASE,GPIO_PIN_2,GPIO_HIGH_LEVEL);
		Mask[5] += GPIO_INT_PIN_2;
		}
		break;
	}
#endif
#ifdef USEPORTFPIN3
	case PF3:{
		if(!ConfigGPIO.GPIOS.PoF3){
		//
		// Enable pin PF3 for GPIOInput
		//
			ConfigGPIO.GPIOS.PoF3 = 1;
		MAP_GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_3);
		GPIOIntTypeSet(GPIO_PORTF_BASE,GPIO_PIN_3,GPIO_HIGH_LEVEL);
		Mask[5] += GPIO_INT_PIN_3;
		}
		break;
	}
#endif
#ifdef USEPORTFPIN4
	case PF4:{
		if(!ConfigGPIO.GPIOS.PoF4){
		//
		// Enable pin PF4 for GPIOInput
		//
			ConfigGPIO.GPIOS.PoF4 = 1;
		MAP_GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_4);
		GPIOIntTypeSet(GPIO_PORTF_BASE,GPIO_PIN_4,GPIO_HIGH_LEVEL);
		Mask[5] += GPIO_INT_PIN_4;
		}
		break;
	}
#endif
#endif
	default: break;

    }
	GPIOIntClear(GPIO_PORTA_BASE,0x0F);
	GPIOIntClear(GPIO_PORTB_BASE,0x0F);
	GPIOIntClear(GPIO_PORTC_BASE,0x0F);
	GPIOIntClear(GPIO_PORTD_BASE,0x0F);
	GPIOIntClear(GPIO_PORTE_BASE,0x0F);
	GPIOIntClear(GPIO_PORTF_BASE,0x0F);
	GPIOIntDisable(GPIO_PORTA_BASE,0x0F);
	GPIOIntDisable(GPIO_PORTB_BASE,0x0F);
	GPIOIntDisable(GPIO_PORTC_BASE,0x0F);
	GPIOIntDisable(GPIO_PORTD_BASE,0x0F);
	GPIOIntDisable(GPIO_PORTE_BASE,0x0F);
	GPIOIntDisable(GPIO_PORTF_BASE,0x0F);

#ifdef USEPORTA
	//Habilitacion de las interrupciones:
	//Puerto A con algo configurado
	if(ConfigGPIO.PortGpio[0] >0){

		//Primero deshabilita configura habilita
		 //IntEnable(INT_GPIOA);
		GPIOIntEnable(GPIO_PORTA_BASE,Mask[0]);
		//GPIOPadConfigSet(GPIO_PORTA_BASE,Mask[0],GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPD);
		GPIOIntRegister(GPIO_PORTA_BASE,TOFProcess);
		//GPIOIntTypeSet(GPIO_PORTA_BASE,Mask[0],GPIO_RISING_EDGE);


	}
#endif

#ifdef USEPORTB
	//Puerto B con algo configurado
	if(ConfigGPIO.PortGpio[1] >0){
	//	GPIOIntTypeSet(GPIO_PORTB_BASE,Mask[1],GPIO_PIN_TYPE_STD_WPD);
		GPIOIntRegister(GPIO_PORTB_BASE,TOFProcess);
		GPIOIntEnable(GPIO_PORTB_BASE,Mask[1]);

	}
#endif
#ifdef USEPORTC
	//Puerto C con algo configurado
	if(ConfigGPIO.PortGpio[2] >0){
		GPIOIntEnable(GPIO_PORTC_BASE,Mask[2]);
		GPIOIntRegister(GPIO_PORTC_BASE,TOFProcess);
	}
#endif
#ifdef USEPORTD
	//Puerto D con algo configurado
	if(ConfigGPIO.PortGpio[3] >0){
		GPIOIntEnable(GPIO_PORTD_BASE,Mask[3]);
		GPIOIntRegister(GPIO_PORTD_BASE,TOFProcess);
	}
#endif
#ifdef USEPORTE
	//Puerto E con algo configurado
	if(ConfigGPIO.PortGpio[4] >0){
		GPIOIntEnable(GPIO_PORTE_BASE,Mask[4]);
		GPIOIntRegister(GPIO_PORTE_BASE,TOFProcess);
	}
#endif
#ifdef USEPORTF
	//Puerto F con algo configurado
	if(ConfigGPIO.PortGpio[5] >0){
		GPIOIntEnable(GPIO_PORTF_BASE,Mask[5]);
		GPIOIntRegister(GPIO_PORTF_BASE,TOFProcess);
	}
#endif
//	IntMasterEnable();



}
コード例 #17
0
//*****************************************************************************
//
// Main 'C' Language entry point.
//
//*****************************************************************************
int
main(void)
{
    float fTemperature, fPressure, fAltitude;
    int32_t i32IntegerPart;
    int32_t i32FractionPart;
    tContext sContext;
    uint32_t ui32SysClock;
    char pcBuf[15];

    //
    // Setup the system clock to run at 40 Mhz from PLL with crystal reference
    //
    ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                           SYSCTL_OSC_MAIN |
                                           SYSCTL_USE_PLL |
                                           SYSCTL_CFG_VCO_480), 40000000);

    //
    // Configure the device pins.
    //
    PinoutSet();

    //
    // Initialize the display driver.
    //
    Kentec320x240x16_SSD2119Init(ui32SysClock);

    //
    // Initialize the graphics context.
    //
    GrContextInit(&sContext, &g_sKentec320x240x16_SSD2119);

    //
    // Draw the application frame.
    //
    FrameDraw(&sContext, "bmp180");

    //
    // Flush any cached drawing operations.
    //
    GrFlush(&sContext);

    //
    // Enable UART0
    //
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

    //
    // Initialize the UART for console I/O.
    //
    UARTStdioConfig(0, 115200, ui32SysClock);

    //
    // Print the welcome message to the terminal.
    //
    UARTprintf("\033[2JBMP180 Example\n");

    //
    // The I2C3 peripheral must be enabled before use.
    //
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C3);

    //
    // Configure the pin muxing for I2C3 functions on port G4 and G5.
    // This step is not necessary if your part does not support pin muxing.
    //
    MAP_GPIOPinConfigure(GPIO_PG4_I2C3SCL);
    MAP_GPIOPinConfigure(GPIO_PG5_I2C3SDA);

    //
    // Select the I2C function for these pins.  This function will also
    // configure the GPIO pins pins for I2C operation, setting them to
    // open-drain operation with weak pull-ups.  Consult the data sheet
    // to see which functions are allocated per pin.
    //
    MAP_GPIOPinTypeI2CSCL(GPIO_PORTG_BASE, GPIO_PIN_4);
    MAP_GPIOPinTypeI2C(GPIO_PORTG_BASE, GPIO_PIN_5);

    //
    // Enable interrupts to the processor.
    //
    MAP_IntMasterEnable();

    //
    // Initialize I2C3 peripheral.
    //
    I2CMInit(&g_sI2CInst, I2C3_BASE, INT_I2C3, 0xff, 0xff,
             ui32SysClock);

    //
    // Initialize the BMP180
    //
    BMP180Init(&g_sBMP180Inst, &g_sI2CInst, BMP180_I2C_ADDRESS,
               BMP180AppCallback, &g_sBMP180Inst);

    //
    // Wait for initialization callback to indicate reset request is complete.
    //
    while(g_vui8DataFlag == 0)
    {
        //
        // Wait for I2C Transactions to complete.
        //
    }

    //
    // Reset the data ready flag
    //
    g_vui8DataFlag = 0;

    //
    // Enable the system ticks at 10 hz.
    //
    MAP_SysTickPeriodSet(ui32SysClock / (10 * 3));
    MAP_SysTickIntEnable();
    MAP_SysTickEnable();

    //
    // Configure PQ4 to control the blue LED.
    //
    MAP_GPIOPinTypeGPIOOutput(GPIO_PORTQ_BASE, GPIO_PIN_4);

    //
    // Print temperature, pressure and altitude labels once on the LCD.
    //
    GrStringDraw(&sContext, "Temperature", 11,
                 ((GrContextDpyWidthGet(&sContext) / 2) - 96),
                 ((GrContextDpyHeightGet(&sContext) - 32) / 2) - 24, 1);
    GrStringDraw(&sContext, "Pressure", 8,
                 ((GrContextDpyWidthGet(&sContext) / 2) - 63),
                 (GrContextDpyHeightGet(&sContext) - 32) / 2, 1);
    GrStringDraw(&sContext, "Altitude", 8,
                 ((GrContextDpyWidthGet(&sContext) / 2) - 59),
                 ((GrContextDpyHeightGet(&sContext) - 32) / 2) + 24, 1);

    //
    // Begin the data collection and printing.  Loop Forever.
    //
    while(1)
    {
        //
        // Read the data from the BMP180 over I2C.  This command starts a
        // temperature measurement.  Then polls until temperature is ready.
        // Then automatically starts a pressure measurement and polls for that
        // to complete.  When both measurement are complete and in the local
        // buffer then the application callback is called from the I2C
        // interrupt context.  Polling is done on I2C interrupts allowing
        // processor to continue doing other tasks as needed.
        //
        BMP180DataRead(&g_sBMP180Inst, BMP180AppCallback, &g_sBMP180Inst);
        while(g_vui8DataFlag == 0)
        {
            //
            // Wait for the new data set to be available.
            //
        }

        //
        // Reset the data ready flag.
        //
        g_vui8DataFlag = 0;

        //
        // Get a local copy of the latest temperature data in float format.
        //
        BMP180DataTemperatureGetFloat(&g_sBMP180Inst, &fTemperature);

        //
        // Convert the floats to an integer part and fraction part for easy
        // print.
        //
        i32IntegerPart = (int32_t) fTemperature;
        i32FractionPart =(int32_t) (fTemperature * 1000.0f);
        i32FractionPart = i32FractionPart - (i32IntegerPart * 1000);
        if(i32FractionPart < 0)
        {
            i32FractionPart *= -1;
        }

        //
        // Print temperature with three digits of decimal precision to LCD and
        // terminal.
        //
        usnprintf(pcBuf, sizeof(pcBuf), "%03d.%03d ", i32IntegerPart,
                                                     i32FractionPart);
        GrStringDraw(&sContext, pcBuf, 8,
                     ((GrContextDpyWidthGet(&sContext) / 2) + 16),
                     ((GrContextDpyHeightGet(&sContext) - 32) / 2) - 24, 1);
        UARTprintf("Temperature %3d.%03d\t\t", i32IntegerPart,
                                               i32FractionPart);

        //
        // Get a local copy of the latest air pressure data in float format.
        //
        BMP180DataPressureGetFloat(&g_sBMP180Inst, &fPressure);

        //
        // Convert the floats to an integer part and fraction part for easy
        // print.
        //
        i32IntegerPart = (int32_t) fPressure;
        i32FractionPart =(int32_t) (fPressure * 1000.0f);
        i32FractionPart = i32FractionPart - (i32IntegerPart * 1000);
        if(i32FractionPart < 0)
        {
            i32FractionPart *= -1;
        }

        //
        // Print Pressure with three digits of decimal precision to LCD and
        // terminal.
        //
        usnprintf(pcBuf, sizeof(pcBuf), "%3d.%03d ", i32IntegerPart,
                                                     i32FractionPart);
        GrStringDraw(&sContext, pcBuf, -1,
                     ((GrContextDpyWidthGet(&sContext) / 2) + 16),
                     (GrContextDpyHeightGet(&sContext) - 32) / 2, 1);
        UARTprintf("Pressure %3d.%03d\t\t", i32IntegerPart, i32FractionPart);

        //
        // Calculate the altitude.
        //
        fAltitude = 44330.0f * (1.0f - powf(fPressure / 101325.0f,
                                            1.0f / 5.255f));

        //
        // Convert the floats to an integer part and fraction part for easy
        // print.
        //
        i32IntegerPart = (int32_t) fAltitude;
        i32FractionPart =(int32_t) (fAltitude * 1000.0f);
        i32FractionPart = i32FractionPart - (i32IntegerPart * 1000);
        if(i32FractionPart < 0)
        {
            i32FractionPart *= -1;
        }

        //
        // Print altitude with three digits of decimal precision to LCD and
        // terminal.
        //
        usnprintf(pcBuf, sizeof(pcBuf), "%3d.%03d ", i32IntegerPart,
                                                     i32FractionPart);
        GrStringDraw(&sContext, pcBuf, 8,
                     ((GrContextDpyWidthGet(&sContext) / 2) + 16),
                     ((GrContextDpyHeightGet(&sContext) - 32) / 2) + 24, 1);
        UARTprintf("Altitude %3d.%03d", i32IntegerPart, i32FractionPart);

        //
        // Print new line.
        //
        UARTprintf("\n");

        //
        // Delay to keep printing speed reasonable. About 100 milliseconds.
        //
        MAP_SysCtlDelay(ui32SysClock / (10 * 3));
    }
}
コード例 #18
0
void delay(unsigned long msec){
	MAP_SysCtlDelay(ulClockMS*msec);
}
コード例 #19
0
void configureADC()
{
	MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
	MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
	MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);

	MAP_SysCtlDelay(2);

	// Disable sequencer 0
	MAP_ADCSequenceDisable(ADC0_BASE, 3);

	//
	// Configure GPIO Pin
	//
	MAP_GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_7);

	//  **************************
	// Configure timer
	//  **************************
	MAP_TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC);

	// Load timer for periodic sampling of ADC
	MAP_TimerLoadSet(TIMER1_BASE, TIMER_A, g_ui32SysClock/SAMPLING_RATE);

	// Enable ADC triggering
	MAP_TimerControlTrigger(TIMER1_BASE, TIMER_A, true);

	// Trigger ADC on timer A timeout
	MAP_TimerADCEventSet(TIMER1_BASE, TIMER_ADC_TIMEOUT_A);

	// **************************
	// Configure ADC
	// **************************
	// Clear the interrupt raw status bit (should be done early
	// on, because it can take several cycles to clear.)
	MAP_ADCIntClear(ADC0_BASE, 3);

	// ADC0, Seq 0, Timer triggered, Priority 0
	MAP_ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_TIMER, 0);
	//	MAP_ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);

	/*// Set all 8 sequencer steps to sample from analog channel 5 (PD7)
	int i;
	for(i = 0; i < 1; i++)
	{
	  MAP_ADCSequenceStepConfigure(ADC0_BASE, 0, i, ADC_CTL_CH5 | ADC_CTL_IE | ADC_CTL_END);
	}

	// Configure step 7 to trigger interrupt, and be the end of sequence
//	MAP_ADCSequenceStepConfigure(ADC0_BASE, 0, 7, ADC_CTL_CH5 | ADC_CTL_IE | ADC_CTL_END);
	 */
	MAP_ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH4 | ADC_CTL_IE | ADC_CTL_END);

	MAP_ADCSequenceEnable(ADC0_BASE, 3);

	// Enable interrupts when sample conversion complete
	MAP_ADCIntEnable(ADC0_BASE, 3);

	// Enable NVIC interrupt for ADC0 SS0
	MAP_IntEnable(INT_ADC0SS3);

	MAP_IntMasterEnable();

	MAP_TimerEnable(TIMER1_BASE, TIMER_A);
}
コード例 #20
0
ファイル: qs-logger.c プロジェクト: PhamVanNhi/ECE5770
//*****************************************************************************
//
// Initialize and operate the data logger.
//
//*****************************************************************************
int
main(void)
{
    tContext sDisplayContext, sBufferContext;
    uint32_t ui32HibIntStatus, ui32SysClock, ui32LastTickCount;
    bool bSkipSplash;
    uint8_t ui8ButtonState, ui8ButtonChanged;
    uint_fast8_t ui8X, ui8Y;


    //
    // Enable lazy stacking for interrupt handlers.  This allows floating-point
    // instructions to be used within interrupt handlers, but at the expense of
    // extra stack usage.
    //
    MAP_FPULazyStackingEnable();

    //
    // Set the clocking to run at 50 MHz.
    //
    MAP_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
                       SYSCTL_OSC_MAIN);
    ui32SysClock = MAP_SysCtlClockGet();

    //
    // Initialize locals.
    //
    bSkipSplash = false;
    ui32LastTickCount = 0;

    //
    // Initialize the data acquisition module.  This initializes the ADC
    // hardware.
    //
    AcquireInit();

    //
    // Enable access to  the hibernate peripheral.  If the hibernate peripheral
    // was already running then this will have no effect.
    //
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_HIBERNATE);

    //
    // Check to see if the hiberate module is already active and if so then
    // read the saved configuration state.  If both are okay, then proceed
    // to check and see if we are logging data using sleep mode.
    //
    if(HibernateIsActive() && !GetSavedState(&g_sConfigState))
    {
        //
        // Read the status of the hibernate module.
        //
        ui32HibIntStatus = HibernateIntStatus(1);

        //
        // If this is a pin wake, that means the user pressed the select
        // button and we should terminate the sleep logging.  In this case
        // we will fall out of this conditional section, and go through the
        // normal startup below, but skipping the splash screen so the user
        // gets immediate response.
        //
        if(ui32HibIntStatus & HIBERNATE_INT_PIN_WAKE)
        {
            //
            // Clear the interrupt flag so it is not seen again until another
            // wake.
            //
            HibernateIntClear(HIBERNATE_INT_PIN_WAKE);
            bSkipSplash = true;
        }

        //
        // Otherwise if we are waking from hibernate and it was not a pin
        // wake, then it must be from RTC match.  Check to see if we are
        // sleep logging and if so then go through an abbreviated startup
        // in order to collect the data and go back to sleep.
        //
        else if(g_sConfigState.ui32SleepLogging &&
                (ui32HibIntStatus & HIBERNATE_INT_RTC_MATCH_0))
        {
            //
            // Start logger and pass the configuration.  The logger should
            // configure itself to take one sample.
            //
            AcquireStart(&g_sConfigState);
            g_iLoggerState = eSTATE_LOGGING;

            //
            // Enter a forever loop to run the acquisition.  This will run
            // until a new sample has been taken and stored.
            //
            while(!AcquireRun())
            {
            }

            //
            // Getting here means that a data acquisition was performed and we
            // can now go back to sleep.  Save the configuration and then
            // activate the hibernate.
            //
            SetSavedState(&g_sConfigState);

            //
            // Set wake condition on pin-wake or RTC match.  Then put the
            // processor in hibernation.
            //
            HibernateWakeSet(HIBERNATE_WAKE_PIN | HIBERNATE_WAKE_RTC);
            HibernateRequest();

            //
            // Hibernating takes a finite amount of time to occur, so wait
            // here forever until hibernate activates and the processor
            // power is removed.
            //
            for(;;)
            {
            }
        }

        //
        // Otherwise, this was not a pin wake, and we were not sleep logging,
        // so just fall out of this conditional and go through the normal
        // startup below.
        //
    }
    else
    {
        //
        // In this case, either the hibernate module was not already active, or
        // the saved configuration was not valid.  Initialize the configuration
        // to the default state and then go through the normal startup below.
        //
        GetDefaultState(&g_sConfigState);
    }

    //
    // Enable the Hibernate module to run.
    //
    HibernateEnableExpClk(SysCtlClockGet());

    //
    // The hibernate peripheral trim register must be set per silicon
    // erratum 2.1
    //
    HibernateRTCTrimSet(0x7FFF);

    //
    // Start the RTC running.  If it was already running then this will have
    // no effect.
    //
    HibernateRTCEnable();

    //
    // In case we were sleep logging and are now finished (due to user
    // pressing select button), then disable sleep logging so it doesnt
    // try to start up again.
    //
    g_sConfigState.ui32SleepLogging = 0;
    SetSavedState(&g_sConfigState);

    //
    // Initialize the display driver.
    //
    CFAL96x64x16Init();

    //
    // Initialize the buttons driver.
    //
    ButtonsInit();

    //
    // Pass the restored state to the menu system.
    //
    MenuSetState(&g_sConfigState);

    //
    // Enable the USB peripheral
    //
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0);

    //
    // Configure the required pins for USB operation.
    //
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
    MAP_GPIOPinConfigure(GPIO_PG4_USB0EPEN);
    MAP_GPIOPinTypeUSBDigital(GPIO_PORTG_BASE, GPIO_PIN_4);
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL);
    MAP_GPIOPinTypeUSBAnalog(GPIO_PORTL_BASE, GPIO_PIN_6 | GPIO_PIN_7);
    MAP_GPIOPinTypeUSBAnalog(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // Erratum workaround for silicon revision A1.  VBUS must have pull-down.
    //
    if(CLASS_IS_BLIZZARD && REVISION_IS_A1)
    {
        HWREG(GPIO_PORTB_BASE + GPIO_O_PDR) |= GPIO_PIN_1;
    }

    //
    // Initialize the USB stack mode and pass in a mode callback.
    //
    USBStackModeSet(0, eUSBModeOTG, ModeCallback);

    //
    // Initialize the stack to be used with USB stick.
    //
    USBStickInit();

    //
    // Initialize the stack to be used as a serial device.
    //
    USBSerialInit();

    //
    // Initialize the USB controller for dual mode operation with a 2ms polling
    // rate.
    //
    USBOTGModeInit(0, 2000, g_pui8HCDPool, HCD_MEMORY_SIZE);

    //
    // Initialize the menus module.  This module will control the user
    // interface menuing system.
    //
    MenuInit(WidgetActivated);

    //
    // Configure SysTick to periodically interrupt.
    //
    g_ui32TickCount = 0;
    MAP_SysTickPeriodSet(ui32SysClock / CLOCK_RATE);
    MAP_SysTickIntEnable();
    MAP_SysTickEnable();

    //
    // Initialize the display context and another context that is used
    // as an offscreen drawing buffer for display animation effect
    //
    GrContextInit(&sDisplayContext, &g_sCFAL96x64x16);
    GrContextInit(&sBufferContext, &g_sOffscreenDisplayA);

    //
    // Show the splash screen if we are not skipping it.  The only reason to
    // skip it is if the application was in sleep-logging mode and the user
    // just waked it up with the select button.
    //
    if(!bSkipSplash)
    {
        const uint8_t *pui8SplashLogo = g_pui8Image_TI_Black;

        //
        // Draw the TI logo on the display.  Use an animation effect where the
        // logo will "slide" onto the screen.  Allow select button to break
        // out of animation.
        //
        for(ui8X = 0; ui8X < 96; ui8X++)
        {
            if(ButtonsPoll(0, 0) & SELECT_BUTTON)
            {
                break;
            }
            GrImageDraw(&sDisplayContext, pui8SplashLogo, 95 - ui8X, 0);
        }

        //
        // Leave the logo on the screen for a long duration.  Monitor the
        // buttons so that if the user presses the select button, the logo
        // display is terminated and the application starts immediately.
        //
        while(g_ui32TickCount < 400)
        {
            if(ButtonsPoll(0, 0) & SELECT_BUTTON)
            {
                break;
            }
        }

        //
        // Extended splash sequence
        //
        if(ButtonsPoll(0, 0) & UP_BUTTON)
        {
            for(ui8X = 0; ui8X < 96; ui8X += 4)
            {
                GrImageDraw(&sDisplayContext,
                            g_ppui8Image_Splash[(ui8X / 4) & 3],
                            (int32_t)ui8X - 96L, 0);
                GrImageDraw(&sDisplayContext, pui8SplashLogo, ui8X, 0);
                MAP_SysCtlDelay(ui32SysClock / 12);
            }
            MAP_SysCtlDelay(ui32SysClock / 3);
            pui8SplashLogo = g_ppui8Image_Splash[4];
            GrImageDraw(&sDisplayContext, pui8SplashLogo, 0, 0);
            MAP_SysCtlDelay(ui32SysClock / 12);
        }

        //
        // Draw the initial menu into the offscreen buffer.
        //
        SlideMenuDraw(&g_sMenuWidget, &sBufferContext, 0);

        //
        // Now, draw both the TI logo splash screen (from above) and the initial
        // menu on the screen at the same time, moving the coordinates so that
        // the logo "slides" off the display and the menu "slides" onto the
        // display.
        //
        for(ui8Y = 0; ui8Y < 64; ui8Y++)
        {
            GrImageDraw(&sDisplayContext, pui8SplashLogo, 0, -ui8Y);
            GrImageDraw(&sDisplayContext, g_pui8OffscreenBufA, 0, 63 - ui8Y);
        }
    }

    //
    // Add the menu widget to the widget tree and send an initial paint
    // request.
    //
    WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sMenuWidget);
    WidgetPaint(WIDGET_ROOT);

    //
    // Set the focus handle to the menu widget.  Any button events will be
    // sent to this widget
    //
    g_ui32KeyFocusWidgetHandle = (uint32_t)&g_sMenuWidget;

    //
    // Forever loop to run the application
    //
    while(1)
    {

        //
        // Each time the timer tick occurs, process any button events.
        //
        if(g_ui32TickCount != ui32LastTickCount)
        {
            //
            // Remember last tick count
            //
            ui32LastTickCount = g_ui32TickCount;

            //
            // Read the debounced state of the buttons.
            //
            ui8ButtonState = ButtonsPoll(&ui8ButtonChanged, 0);

            //
            // Pass any button presses through to the widget message
            // processing mechanism.  The widget that has the button event
            // focus (probably the menu widget) will catch these button events.
            //
            if(BUTTON_PRESSED(SELECT_BUTTON, ui8ButtonState, ui8ButtonChanged))
            {
                SendWidgetKeyMessage(WIDGET_MSG_KEY_SELECT);
            }
            if(BUTTON_PRESSED(UP_BUTTON, ui8ButtonState, ui8ButtonChanged))
            {
                SendWidgetKeyMessage(WIDGET_MSG_KEY_UP);
            }
            if(BUTTON_PRESSED(DOWN_BUTTON, ui8ButtonState, ui8ButtonChanged))
            {
                SendWidgetKeyMessage(WIDGET_MSG_KEY_DOWN);
            }
            if(BUTTON_PRESSED(LEFT_BUTTON, ui8ButtonState, ui8ButtonChanged))
            {
                SendWidgetKeyMessage(WIDGET_MSG_KEY_LEFT);
            }
            if(BUTTON_PRESSED(RIGHT_BUTTON, ui8ButtonState, ui8ButtonChanged))
            {
                SendWidgetKeyMessage(WIDGET_MSG_KEY_RIGHT);
            }
        }

        //
        // Tell the OTG library code how much time has passed in milliseconds
        // since the last call.
        //
        USBOTGMain(GetTickms());

        //
        // Call functions as needed to keep the host or device mode running.
        //
        if(g_iCurrentUSBMode == eUSBModeDevice)
        {
            USBSerialRun();
        }
        else if(g_iCurrentUSBMode == eUSBModeHost)
        {
            USBStickRun();
        }

        //
        // If in the logging state, then call the logger run function.  This
        // keeps the data acquisition running.
        //
        if((g_iLoggerState == eSTATE_LOGGING) ||
           (g_iLoggerState == eSTATE_VIEWING))
        {
            if(AcquireRun() && g_sConfigState.ui32SleepLogging)
            {
                //
                // If sleep logging is enabled, then at this point we have
                // stored the first data item, now save the state and start
                // hibernation.  Wait for the power to be cut.
                //
                SetSavedState(&g_sConfigState);
                HibernateWakeSet(HIBERNATE_WAKE_PIN | HIBERNATE_WAKE_RTC);
                HibernateRequest();
                for(;;)
                {
                }
            }

            //
            // If viewing instead of logging then request a repaint to keep
            // the viewing window updated.
            //
            if(g_iLoggerState == eSTATE_VIEWING)
            {
                WidgetPaint(WIDGET_ROOT);
            }
        }

        //
        // If in the saving state, then save data from flash storage to
        // USB stick.
        //
        if(g_iLoggerState == eSTATE_SAVING)
        {
            //
            // Save data from flash to USB
            //
            FlashStoreSave();

            //
            // Return to idle state
            //
            g_iLoggerState = eSTATE_IDLE;
        }

        //
        // If in the erasing state, then erase the data stored in flash.
        //
        if(g_iLoggerState == eSTATE_ERASING)
        {
            //
            // Save data from flash to USB
            //
            FlashStoreErase();

            //
            // Return to idle state
            //
            g_iLoggerState = eSTATE_IDLE;
        }

        //
        // If in the flash reporting state, then show the report of the amount
        // of used and free flash memory.
        //
        if(g_iLoggerState == eSTATE_FREEFLASH)
        {
            //
            // Report free flash space
            //
            FlashStoreReport();

            //
            // Return to idle state
            //
            g_iLoggerState = eSTATE_IDLE;
        }

        //
        // If we are exiting the clock setting widget, that means that control
        // needs to be given back to the menu system.
        //
        if(g_iLoggerState == eSTATE_CLOCKEXIT)
        {
            //
            // Give the button event focus back to the menu system
            //
            g_ui32KeyFocusWidgetHandle = (uint32_t)&g_sMenuWidget;

            //
            // Send a button event to the menu widget that means the left
            // key was pressed.  This signals the menu widget to deactivate
            // the current child widget (which was the clock setting wigdet).
            // This will cause the menu widget to slide the clock set widget
            // off the screen and resume control of the display.
            //
            SendWidgetKeyMessage(WIDGET_MSG_KEY_LEFT);
            g_iLoggerState = eSTATE_IDLE;
        }

        //
        // Process any new messages that are in the widget queue.  This keeps
        // the user interface running.
        //
        WidgetMessageQueueProcess();
    }
}
コード例 #21
0
ファイル: test1.c プロジェクト: GenaNiv/tiva-c-projects
//*****************************************************************************
//
// This example demonstrates how to send a string of data to the UART.
//
//*****************************************************************************
int
main(void)
{
	uint32_t ui32_Period, ui32_PWM=0, ui32_PWM_step = 40, ui32_PWM_min=2000, ui32_PWM_max=4000;
	uint32_t ui32_sw1;
    uint32_t ui32_sw2;
    //
    // Enable lazy stacking for interrupt handlers.  This allows floating-point
    // instructions to be used within interrupt handlers, but at the expense of
    // extra stack usage.
    //
    //MAP_FPUEnable();
    //MAP_FPULazyStackingEnable();

    //
    // Set the clocking to run directly from the crystal.
    //
    MAP_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    //
    // Enable the GPIO port that is used for the on-board LED.
    //
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

    //
    // Enable the GPIO pins for the LED (PF2).
    //
    MAP_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);
    
    // Configure UART
    InitConsole();

    
    // -----------------------------------------------------------------
    // Configure PWM for servo control
    // -----------------------------------------------------------------
    // follow page 1240 of the datasheet:
    ui32_Period = (MAP_SysCtlClockGet()/8) / 50; //PWM frequency 50HZ, T=20ms
    // GOTO middle of servo in the beginning
    ui32_PWM = ui32_PWM_min + (ui32_PWM_max - ui32_PWM_min) / 2;
    ui32_PWM_max = ui32_Period*.1;
    ui32_PWM_min = ui32_Period*.05;
    
    //Configure PWM Clock to match system
	MAP_SysCtlPWMClockSet(SYSCTL_PWMDIV_8);
    
    // Enable system clock for PWM0 module
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
  
    // Enable the GPIO port that is used for the PWM outputs
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    
    //Configure PB5,PB5 Pins as PWM
    MAP_GPIOPinConfigure(GPIO_PB4_M0PWM2);
    MAP_GPIOPinConfigure(GPIO_PB5_M0PWM3);
    MAP_GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_4);
    MAP_GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_5);
    
    //Configure PWM Options
    MAP_PWMGenConfigure(PWM0_BASE, PWM_GEN_1 , PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
    
    //
    // Set the PWM period to 50Hz.  To calculate the appropriate parameter
    // use the following equation: N = (1 / f) * SysClk.  Where N is the
    // function parameter, f is the desired frequency, and SysClk is the
    // system clock frequency.
    // In this case you get: (1 / 50Hz) * 16MHz/8div = 40000 cycles.  Note that
    // the maximum period you can set is 2^16 - 1.
    // TODO: modify this calculation to use the clock frequency that you are
    // using.
    //
    PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, ui32_Period);
    
    //Set PWM duty - 25% and 75%
    PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2, ui32_PWM);
    PWMPulseWidthSet(PWM0_BASE, PWM_OUT_3, ui32_PWM);
    
    // Enable the PWM generator
    MAP_PWMGenEnable(PWM0_BASE, PWM_GEN_1);

    // Turn on the Output pins
    MAP_PWMOutputState(PWM0_BASE, PWM_OUT_2_BIT | PWM_OUT_3_BIT, true);
    
    
    // -----------------------------------------------------------------
    // Enable PORTF and Configure SW1 and SW2 as input
    // -----------------------------------------------------------------
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    GPIO_PORTF_LOCK_R = 0x4C4F434B;   // unlock GPIO Port F
    GPIO_PORTF_CR_R = 0x1F;           // allow changes to PF4-0
    MAP_GPIOPadConfigSet(GPIO_PORTF_BASE, (GPIO_PIN_4 | GPIO_PIN_0), GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
    MAP_GPIODirModeSet(GPIO_PORTF_BASE, (GPIO_PIN_4 | GPIO_PIN_0), GPIO_DIR_MODE_IN);

    //
    // Loop forever echoing data through the UART.
    //
    while(1)
    {
		// Get buttons:
		ui32_sw1 = MAP_GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_4);
		ui32_sw2 = MAP_GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_0);
		// if pressing SW1 on LaunchPad TM4C123G
		if( ui32_sw1 == 0 )
		{
			if(ui32_PWM >= ui32_PWM_min+ui32_PWM_step) {
				ui32_PWM -= ui32_PWM_step;
			}
		}
		if( ui32_sw2 == 0 )
		{
			if(ui32_PWM <= ui32_PWM_max-ui32_PWM_step) {
				ui32_PWM += ui32_PWM_step;
			}
		}
		
		UARTprintf("Period: %d, PWM: %d\n", ui32_Period, ui32_PWM);
		MAP_SysCtlDelay(2000000);
		
		MAP_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2 , ui32_Period - ui32_PWM);
		MAP_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_3 , ui32_PWM);
    }
}