コード例 #1
0
ファイル: hal_uart_isr.c プロジェクト: ndksys01/FinalProject
/*************************************************************************************************
 * @fn      HalUARTOpenIsr()
 *
 * @brief   Open a port based on the configuration
 *
 * @param   port   - UART port
 *          config - contains configuration information
 *          cBack  - Call back function where events will be reported back
 *
 * @return  Status of the function call
 *************************************************************************************************/
uint8 HalUARTOpenIsr(uint8 port, halUARTCfg_t *config)
{
  if (uartRecord.configured)
  {
    HalUARTClose(port);
  }

  if (config->baudRate > HAL_UART_BR_115200)
  {
    return HAL_UART_BAUDRATE_ERROR;
  }

  if (((uartRecord.rx.pBuffer = osal_mem_alloc(config->rx.maxBufSize)) == NULL) ||
      ((uartRecord.tx.pBuffer = osal_mem_alloc(config->tx.maxBufSize)) == NULL))
  {
    if (uartRecord.rx.pBuffer != NULL)
    {
      osal_mem_free(uartRecord.rx.pBuffer);
      uartRecord.rx.pBuffer = NULL;
    }

    return HAL_UART_MEM_FAIL;
  }
  
  if(config->flowControl)
  {
    IOCPinConfigPeriphOutput(GPIO_D_BASE, GPIO_PIN_3, IOC_MUX_OUT_SEL_UART1_RTS);
    GPIOPinTypeUARTOutput(GPIO_D_BASE, GPIO_PIN_3);
    IOCPinConfigPeriphInput(GPIO_B_BASE, GPIO_PIN_0, IOC_UARTCTS_UART1);
    GPIOPinTypeUARTInput(GPIO_B_BASE, GPIO_PIN_0);
  }
  
  IntEnable(HAL_UART_INT_CTRL);

  uartRecord.configured = TRUE;
  uartRecord.baudRate = config->baudRate;
  uartRecord.flowControl = config->flowControl;
  uartRecord.flowControlThreshold = (config->flowControlThreshold > config->rx.maxBufSize) ? 0 :
                                     config->flowControlThreshold;
  uartRecord.idleTimeout = config->idleTimeout;
  uartRecord.rx.maxBufSize = config->rx.maxBufSize;
  uartRecord.tx.maxBufSize = config->tx.maxBufSize;
  uartRecord.intEnable = config->intEnable;
  uartRecord.callBackFunc = config->callBackFunc;

  UARTConfigSetExpClk(HAL_UART_PORT, SysCtrlClockGet(), UBRRTable[uartRecord.baudRate],
                         (UART_CONFIG_WLEN_8 | UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_ONE));

  /* FIFO level set to 1/8th for both RX and TX which is 2 bytes */
  UARTFIFOLevelSet(HAL_UART_PORT, UART_FIFO_TX1_8, UART_FIFO_RX1_8);
  UARTFIFOEnable(HAL_UART_PORT);

  /* Clear and enable UART TX, RX, CTS and Recieve Timeout interrupt */
  UARTIntClear(HAL_UART_PORT, (UART_INT_RX | UART_INT_TX | UART_INT_CTS | UART_INT_RT ));
  UARTIntEnable(HAL_UART_PORT, (UART_INT_RX | UART_INT_TX | UART_INT_CTS | UART_INT_RT ));
  
  if(config->flowControl)
  {
    /* Enable hardware flow control by enabling CTS and RTS */
    HWREG(HAL_UART_PORT + UART_O_CTL) |= (UART_CTL_CTSEN | UART_CTL_RTSEN );
  }
  UARTEnable(HAL_UART_PORT);

  return HAL_UART_SUCCESS;
}
コード例 #2
0
int
main(void)
{
	display[0] = '\0';
	display2[0] = '\0';
    	// Set the clocking to run directly from the crystal.
    	SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_8MHZ);

    	// Initialize the OLED display and write status.
    	RIT128x96x4Init(1000000);
	RIT128x96x4StringDraw("----------------------", 0, 50, 15);

    	// Enable the peripherals used by this example.

    	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);		
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
		
	// Status
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
	GPIOPadConfigSet(GPIO_PORTF_BASE,GPIO_PIN_0,GPIO_STRENGTH_4MA,GPIO_PIN_TYPE_STD);
	GPIODirModeSet(GPIO_PORTF_BASE,GPIO_PIN_0,GPIO_DIR_MODE_OUT);
		
	//PB1
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
	GPIOPadConfigSet(GPIO_PORTB_BASE,GPIO_PIN_1,GPIO_STRENGTH_4MA,GPIO_PIN_TYPE_STD);
	GPIODirModeSet(GPIO_PORTB_BASE,GPIO_PIN_1,GPIO_DIR_MODE_IN);
		
	GPIOPortIntRegister(GPIO_PORTB_BASE, PortBIntHandler);
	GPIOIntTypeSet(GPIO_PORTB_BASE, GPIO_PIN_1, GPIO_BOTH_EDGES);
	GPIOPinIntEnable(GPIO_PORTB_BASE, GPIO_PIN_1);
		
	IntPrioritySet(INT_GPIOB,0x80);
	SysTickIntRegister(SysTickHandler);                  
	SysTickPeriodSet(SysCtlClockGet()/10000);	// 0.1ms
	SysTickIntEnable();
	waitTime = 0;					// initialize
	waitTime2 = 0;
	SysTickEnable();


    	// Enable processor interrupts.
    	IntMasterEnable();

    	// Set GPIO A0 and A1 as UART pins.
    	GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
	GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_2 | GPIO_PIN_3);

    	// Configure the UART for 115,200, 8-N-1 operation.
    	UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 9600,
                        (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                         UART_CONFIG_PAR_NONE));
												 
	UARTConfigSetExpClk(UART1_BASE, SysCtlClockGet(), 9600,
                  	(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                         UART_CONFIG_PAR_NONE));

   	 // Enable the UART interrupt.
    	IntEnable(INT_UART0);
   	UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
		IntEnable(INT_UART1);
    	UARTIntEnable(UART1_BASE, UART_INT_RX | UART_INT_RT);



    	while(1)
   	{
    	}
}
コード例 #3
0
//*****************************************************************************
//
// The main code for the application.  It sets up the peripherals, displays the
// splash screens, and then manages the interaction between the game and the
// screen saver.
//
//*****************************************************************************
int
main(void)
{
    //
    // If running on Rev A2 silicon, turn the LDO voltage up to 2.75V.  This is
    // a workaround to allow the PLL to operate reliably.
    //
    if(REVISION_IS_A2)
    {
        SysCtlLDOSet(SYSCTL_LDO_2_75V);
    }

    //
    // Set the clocking to run at 50MHz from the PLL.
    //
    SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_8MHZ);
    SysCtlPWMClockSet(SYSCTL_PWMDIV_8);

    //
    // Get the system clock speed.
    //
    g_ulSystemClock = SysCtlClockGet();

    //
    // Enable the peripherals used by the application.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

    //
    // Configure the GPIOs used to read the state of the on-board push buttons.
    //
    GPIOPinTypeGPIOInput(GPIO_PORTE_BASE,
                         GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
    GPIOPadConfigSet(GPIO_PORTE_BASE,
                     GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3,
                     GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
    GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_1);
    GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_STRENGTH_2MA,
                     GPIO_PIN_TYPE_STD_WPU);

    //
    // Configure the LED, speaker, and UART GPIOs as required.
    //
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_1);
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_0);
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, 0);

    //
    // Intialize the Ethernet Controller and TCP/IP Stack.
    //
    EnetInit();

    //
    // Configure the first UART for 115,200, 8-N-1 operation.
    //
    UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
                        (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                         UART_CONFIG_PAR_NONE));
    UARTEnable(UART0_BASE);

    //
    // Send a welcome message to the UART.
    //
    UARTCharPut(UART0_BASE, 'W');
    UARTCharPut(UART0_BASE, 'e');
    UARTCharPut(UART0_BASE, 'l');
    UARTCharPut(UART0_BASE, 'c');
    UARTCharPut(UART0_BASE, 'o');
    UARTCharPut(UART0_BASE, 'm');
    UARTCharPut(UART0_BASE, 'e');
    UARTCharPut(UART0_BASE, '\r');
    UARTCharPut(UART0_BASE, '\n');

    //
    // Initialize the OSRAM OLED display.
    //
    RIT128x96x4Init(3500000);

    //
    // Initialize the PWM for generating music and sound effects.
    //
    AudioOn();

    //
    // Configure SysTick to periodically interrupt.
    //
    SysTickPeriodSet(g_ulSystemClock / CLOCK_RATE);
    SysTickIntEnable();
    SysTickEnable();

    //
    // Delay for a bit to allow the initial display flash to subside.
    //
    Delay(CLOCK_RATE / 4);

    //
    // Play the intro music.
    //
    AudioPlaySong(g_pusIntro, sizeof(g_pusIntro) / 2);

    //
    // Display the Texas Instruments logo for five seconds (or twelve seconds
    // if built using gcc).
    //
#if defined(gcc)
    DisplayLogo(g_pucTILogo, 120, 42, 12 * CLOCK_RATE);
#else
    DisplayLogo(g_pucTILogo, 120, 42, 5 * CLOCK_RATE);
#endif

    //
    // Display the Code Composer Studio logo for five seconds.
    //
#if defined(ccs)
    DisplayLogo(g_pucCodeComposer, 128, 34, 5 * CLOCK_RATE);
#endif

    //
    // Display the Keil/ARM logo for five seconds.
    //
#if defined(rvmdk) || defined(__ARMCC_VERSION)
    DisplayLogo(g_pucKeilLogo, 128, 40, 5 * CLOCK_RATE);
#endif

    //
    // Display the IAR logo for five seconds.
    //
#if defined(ewarm)
    DisplayLogo(g_pucIarLogo, 102, 61, 5 * CLOCK_RATE);
#endif

    //
    // Display the CodeSourcery logo for five seconds.
    //
#if defined(sourcerygxx)
    DisplayLogo(g_pucCodeSourceryLogo, 128, 34, 5 * CLOCK_RATE);
#endif

    //
    // Display the CodeRed logo for five seconds.
    //
#if defined(codered)
    DisplayLogo(g_pucCodeRedLogo, 128, 32, 5 * CLOCK_RATE);
#endif

    //
    // Throw away any button presses that may have occurred while the splash
    // screens were being displayed.
    //
    HWREGBITW(&g_ulFlags, FLAG_BUTTON_PRESS) = 0;

    //
    // Loop forever.
    //
    while(1)
    {
        //
        // Display the main screen.
        //
        if(MainScreen())
        {
            //
            // The button was pressed, so start the game.
            //
            PlayGame();
        }
        else
        {
            //
            // The button was not pressed during the timeout period, so start
            // the screen saver.
            //
            ScreenSaver();
        }
    }
}
コード例 #4
0
ファイル: uart_echo.c プロジェクト: EranSegal/ek-lm4f230H5QR
int InitUART(unsigned long ulBase, unsigned long ulUARTClk,unsigned long ulBaud, unsigned long ulConfig)
{
		
	if(ulBase == UART0_BASE)
	{
		//
		// Enable the peripherals used by this example.
		//
		SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);		
		SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);		

		/* Set GPIO A0 and A1 as peripheral function.  They are used to output the UART signals. */
		GPIODirModeSet( GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1, GPIO_DIR_MODE_HW );

		//Enable GPIO for UART0
		//PA0-> U0RX 
		//PA1-> U0Tx 
		GPIOPinConfigure(GPIO_PA0_U0RX);		
		GPIOPinConfigure(GPIO_PA1_U0TX);	
		
		//
		// Set GPIO A0 and A1 as UART pins.
		//
		GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
		
		//
		// Configure COM0 Controp the UART for 19,200, 8-N-1 operation.
		//
		//UARTConfigSetExpClk(ulBase, ulUARTClk, ulBaud,ulConfig);
		#if defined(stabilizition)
		//
		// Configure the UART for 19,200, 8-N-1 operation. 
		// Mux Must to get EVEN PAR bin from the Engine
		//
		UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
							(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
							 UART_CONFIG_PAR_EVEN));
		#else
		UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 460800,
							(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
							 UART_CONFIG_PAR_NONE));
		#endif
		/* We don't want to use the fifo.  This is for test purposes to generate as many interrupts as possible. */
		HWREG( UART0_BASE + UART_O_LCR_H ) &= ~mainFIFO_SET;

		/* Enable Tx interrupts. */
		HWREG( UART0_BASE + UART_O_IM ) |= UART_INT_TX;
		HWREG( UART0_BASE + UART_O_IM ) |= UART_INT_RX;
		//IntPrioritySet( INT_UART0, configKERNEL_INTERRUPT_PRIORITY );
		IntEnable( INT_UART0 );
		//
		// Enable the UART interrupt.
		//
		//IntEnable(INT_UART0);
		//UARTFIFOLevelSet(UART0_BASE,UART_FIFO_TX1_8,UART_FIFO_RX1_8);
		//UARTIntRegister(UART0_BASE,UART0IntHandler);
		//UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_TX | UART_INT_RT);

		return 0;

	}
	else
	if(ulBase == UART1_BASE)
	{
	    //
	    // Enable the peripherals used by this example.
	    //
	    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);	    
	    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);		

		/* Set GPIO A0 and A1 as peripheral function.  They are used to output the UART signals. */
		GPIODirModeSet( GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1, GPIO_DIR_MODE_HW );

		// Set B 0 and 1 to alternative use
		//GPIODirModeSet(GPIO_PORTB_BASE, GPIO_PIN_0, GPIO_DIR_MODE_HW); 		
		//GPIODirModeSet(GPIO_PORTB_BASE, GPIO_PIN_1, GPIO_DIR_MODE_HW);//GPIO_DIR_MODE_HW	

		//Enable GPIO for UART1 
		//PB0-> U1RX 
		//PB1-> U1Tx 
		GPIOPinConfigure(GPIO_PB0_U1RX);		
		GPIOPinConfigure(GPIO_PB1_U1TX);	

	    //
	    // Set GPIO A0 and A1 as UART pins.
	    //
	    GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);

	    //
	    // Configure COM1 OMAP the UART for 115,200, 8-N-1 operation.
	    //

		UARTConfigSetExpClk(UART1_BASE, SysCtlClockGet(), 9600,
							(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
							 UART_CONFIG_PAR_NONE));

		/* We don't want to use the fifo.  This is for test purposes to generate as many interrupts as possible. */
		HWREG( UART1_BASE + UART_O_LCR_H ) &= ~mainFIFO_SET;

		/* Enable Tx interrupts. */
		HWREG( UART1_BASE + UART_O_IM ) |= UART_INT_TX;
		HWREG( UART1_BASE + UART_O_IM ) |= UART_INT_RX;
		//IntPrioritySet( INT_UART0, configKERNEL_INTERRUPT_PRIORITY );
		IntEnable( INT_UART1 );

	    //
	    // Enable the UART interrupt.
	    //
		//IntEnable(INT_UART1);
		//UARTFIFOLevelSet(UART1_BASE,UART_FIFO_TX1_8,UART_FIFO_RX1_8);
		//UARTIntRegister(UART1_BASE,UART1IntHandler);
		//UARTIntEnable(UART1_BASE, UART_INT_RX | UART_INT_TX | UART_INT_RT);


		return 0;
	}
	else
		return -1;

	
}
コード例 #5
0
ファイル: uart_polled.c プロジェクト: ndksys01/FinalProject
//*****************************************************************************
//
// Configure the UART and perform reads and writes using polled I/O.
//
//*****************************************************************************
int
main(void)
{
    char cThisChar;

    //
    // Set the clocking to run directly from the external crystal/oscillator.
    // (no ext 32k osc, no internal osc)
    //
    SysCtrlClockSet(false, false, SYS_CTRL_SYSDIV_32MHZ);

    //
    // Set IO clock to the same as system clock
    //
    SysCtrlIOClockSet(SYS_CTRL_SYSDIV_32MHZ);
   
    //
    // Enable UART peripheral module
    //
    SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_UART0);

    //
    // Disable UART function
    //
    UARTDisable(UART0_BASE);

    //
    // Disable all UART module interrupts
    //
    UARTIntDisable(UART0_BASE, 0x1FFF);

    //
    // Set IO clock as UART clock source
    //
    UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);

    //
    // Map UART signals to the correct GPIO pins and configure them as
    // hardware controlled.
    //
    IOCPinConfigPeriphOutput(EXAMPLE_GPIO_BASE, EXAMPLE_PIN_UART_TXD, IOC_MUX_OUT_SEL_UART0_TXD);
    GPIOPinTypeUARTOutput(EXAMPLE_GPIO_BASE, EXAMPLE_PIN_UART_TXD); 
    IOCPinConfigPeriphInput(EXAMPLE_GPIO_BASE, EXAMPLE_PIN_UART_RXD, IOC_UARTRXD_UART0);
    GPIOPinTypeUARTInput(EXAMPLE_GPIO_BASE, EXAMPLE_PIN_UART_RXD);
     
    //
    // Configure the UART for 115,200, 8-N-1 operation.
    // This function uses SysCtrlClockGet() to get the system clock
    // frequency.  This could be also be a variable or hard coded value
    // instead of a function call.
    //
    UARTConfigSetExpClk(UART0_BASE, SysCtrlClockGet(), 115200,
                        (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                         UART_CONFIG_PAR_NONE));
    UARTEnable(UART0_BASE);
    
    //
    // Put a character to show start of example.  This will display on the
    // terminal.
    //
    UARTCharPut(UART0_BASE, '!');

    //
    // Enter a loop to read characters from the UART, and write them back
    // (echo).  When a line end is received, the loop terminates.
    //
    do
    {
        //
        // Read a character using the blocking read function.  This function
        // will not return until a character is available.
        //
        cThisChar = UARTCharGet(UART0_BASE);

        //
        // Write the same character using the blocking write function.  This
        // function will not return until there was space in the FIFO and
        // the character is written.
        //
        UARTCharPut(UART0_BASE, cThisChar);

    //
    // Stay in the loop until either a CR or LF is received.
    //
    } while((cThisChar != '\n') && (cThisChar != '\r'));

    //
    // Put a character to show the end of the example.  This will display on
    // the terminal.
    //
    UARTCharPut(UART0_BASE, '@');

    //
    // Enter an infinite loop.
    //
    while(1)
    {
    }    
}
void Startup(void) {
  
  //STEP 1: OLED and PWM setup
  unsigned long ulPeriod;
  SysCtlPWMClockSet(SYSCTL_PWMDIV_1); 
  SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
  GPIOPinTypePWM(GPIO_PORTG_BASE, GPIO_PIN_1);
  ulPeriod = SysCtlClockGet() / 4000;
  PWMGenConfigure(PWM0_BASE, PWM_GEN_0,PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
  PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, ulPeriod);
  PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, ulPeriod / 16);
  PWMGenEnable(PWM0_BASE, PWM_GEN_0); 
  
  //STEP 3: Button pad setup 
  TrainState = 0;
  GPIOPortIntUnregister(GPIO_PORTE_BASE);
  GPIOPortIntRegister(GPIO_PORTE_BASE,IntGPIOe);
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);    
  GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, 0xF);
  GPIOPadConfigSet(GPIO_PORTE_BASE, 0xF , GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);
  GPIOIntTypeSet(GPIO_PORTE_BASE, 0xF , GPIO_FALLING_EDGE);
  GPIOPinIntEnable(GPIO_PORTE_BASE, 0xF );
  IntEnable(INT_GPIOE);
  
 IntPrioritySet( INT_UART0, configKERNEL_INTERRUPT_PRIORITY);
  
  //STEP 4: Frequency count setup
  tempCount = 0;
  frequencyCount = 0;
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);       
  GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_3);
  GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_3, GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);
  GPIOPortIntUnregister(GPIO_PORTF_BASE);
  GPIOPortIntRegister(GPIO_PORTF_BASE,IntGPIOf);
  GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_3, GPIO_RISING_EDGE);
  GPIOPinIntEnable(GPIO_PORTF_BASE, GPIO_PIN_3);
  IntEnable(INT_GPIOF);
  //IntPrioritySet( INT_GPIOF, 10);
  
  //STEP 5: UART setup  
  SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
  GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
  UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
                      (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                       UART_CONFIG_PAR_NONE));
  IntEnable(INT_UART0); 
  UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
  
 // IntPrioritySet( INT_UART0, configKERNEL_INTERRUPT_PRIORITY);
  
  //STEP 6: pin setup  
  /*SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
  GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, PORT_DATA);*/
  
  //STEP 7: ADC SETUP
  SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
  
  ADCSequenceDisable(ADC0_BASE,0);
  ADCSequenceDisable(ADC0_BASE,1);
  ADCSequenceDisable(ADC0_BASE,2);
  ADCSequenceDisable(ADC0_BASE,3);
  
  GPIOPinTypeADC(ADC0_BASE, 0xF); 
  
  ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);   
  ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0); 
  ADCSequenceConfigure(ADC0_BASE, 2, ADC_TRIGGER_PROCESSOR, 0); 
  ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
  
  ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END);
  ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END);
  ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END);
  ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END);
  
  ADCSequenceEnable(ADC0_BASE, 0);
  ADCSequenceEnable(ADC0_BASE, 1);
  ADCSequenceEnable(ADC0_BASE, 2);
  ADCSequenceEnable(ADC0_BASE, 3);
  
   ADCIntClear(ADC0_BASE, 0);
   ADCIntClear(ADC0_BASE, 1);
    ADCIntClear(ADC0_BASE, 2);
  ADCIntClear(ADC0_BASE, 3);
  
  ADCIntEnable(ADC0_BASE, 0);
  ADCIntEnable(ADC0_BASE, 1);
  ADCIntEnable(ADC0_BASE, 2);
   ADCIntEnable(ADC0_BASE, 3);
  
 
  //IntEnable(INT_ADC0);
  //IntPrioritySet(INT_ADC, 50);
  
  //IntEnable(INT_ADC0);
  //ADCIntClear(ADC0_BASE, 0);
  
 
  
  return;
}
コード例 #7
0
int main(void)
{

	SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // Enable the GPIO A ports
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); // Enable the GPIO E ports
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART4);

	GPIOPinConfigure(GPIO_PE4_M0PWM4);
	GPIOPinTypePWM(GPIO_PORTE_BASE, GPIO_PIN_4);

	GPIOPinConfigure(GPIO_PC4_U4RX);
	GPIOPinConfigure(GPIO_PC5_U4TX );

	GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_4 | GPIO_PIN_5);

	GPIOPinConfigure(GPIO_PE5_M0PWM5);
	GPIOPinTypePWM(GPIO_PORTE_BASE, GPIO_PIN_5);

	PWMGenConfigure(PWM0_BASE, PWM_GEN_2, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
	PWMGenPeriodSet(PWM0_BASE, PWM_GEN_2, 6400000);
	PWMPulseWidthSet(PWM0_BASE, PWM_OUT_4, PWMGenPeriodGet(PWM0_BASE, PWM_GEN_2) / 1.25);
	PWMOutputState(PWM0_BASE, PWM_OUT_4_BIT, true);
	PWMGenEnable(PWM0_BASE, PWM_GEN_2);

	PWMGenConfigure(PWM0_BASE, PWM_GEN_2, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
	PWMGenPeriodSet(PWM0_BASE, PWM_GEN_2, 6400000);
	PWMPulseWidthSet(PWM0_BASE, PWM_OUT_5, PWMGenPeriodGet(PWM0_BASE, PWM_GEN_2) / 1.25);
	PWMOutputState(PWM0_BASE, PWM_OUT_5_BIT, true);
	PWMGenEnable(PWM0_BASE, PWM_GEN_2);





	GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_6|GPIO_PIN_7); 

	GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_6|GPIO_PIN_7,68); 


	UARTConfigSetExpClk(UART4_BASE, SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
	UARTEnable(UART4_BASE);

	UARTCharPut(UART4_BASE,'a');
	while(1)
	{
		SysCtlDelay(4000000*10);
		temp = 1;
		UARTSend((uint8_t *)"Fast",4);
		PWMPulseWidthSet(PWM0_BASE, PWM_OUT_4, PWMGenPeriodGet(PWM0_BASE, PWM_GEN_2) / 1.25);
		PWMPulseWidthSet(PWM0_BASE, PWM_OUT_5, PWMGenPeriodGet(PWM0_BASE, PWM_GEN_2) / 1.25);
		SysCtlDelay(4000000*10);
		temp = 0;
		UARTSend((uint8_t *)"Slow",4);
		PWMPulseWidthSet(PWM0_BASE, PWM_OUT_4, PWMGenPeriodGet(PWM0_BASE, PWM_GEN_2) / 3);
		PWMPulseWidthSet(PWM0_BASE, PWM_OUT_5, PWMGenPeriodGet(PWM0_BASE, PWM_GEN_2) / 3);

	}
}
コード例 #8
0
ファイル: main.c プロジェクト: joseomar/Proyectos_CCS-TI
int
main(void)
{
	char cThisChar;
			/* Result code */

	unsigned long ulResetCause;

	//SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
	SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
				SYSCTL_XTAL_16MHZ);
	unsigned long g=SysCtlClockGet();

	FPUEnable();
	FPUStackingEnable();
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
	GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
	ulResetCause = SysCtlResetCauseGet();
	SysCtlResetCauseClear(ulResetCause);
	HibernateEnableExpClk(SysCtlClockGet());
	ButtonsInit();
	SysTickPeriodSet(SysCtlClockGet() / APP_SYSTICKS_PER_SEC);
	SysTickEnable();
	SysTickIntEnable();
	IntMasterEnable();

	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART4);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
	GPIOPinConfigure(GPIO_PC4_U4RX);
	GPIOPinConfigure(GPIO_PC5_U4TX);
	GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_4 | GPIO_PIN_5);
	UARTConfigSetExpClk(UART4_BASE, SysCtlClockGet(), 115200,
			(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
					UART_CONFIG_PAR_NONE));

	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
	GPIOPinConfigure(GPIO_PB0_U1RX);
	GPIOPinConfigure(GPIO_PB1_U1TX);

	GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);

	UARTConfigSetExpClk(UART1_BASE, SysCtlClockGet(), 9600, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
						UART_CONFIG_PAR_NONE));

	//Orden al PGS de que me devuelva solo un mensaje..
	for(i=0; i<sizeof(buferA); i++){
			UARTCharPut(UART1_BASE, buferA[i]);}

	GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0);

	rc = f_mount(0, &Fatfs);					//registra un area de trabajo
	rc = f_open(&Fil, "BuffGPS.TXT", FA_WRITE | FA_CREATE_ALWAYS);	//abre o crea un archivo


	do {


    int contador1=0;
    cThisChar='0';

    	do{

    	cThisChar=UARTCharGet(UART1_BASE);
		BuffGPS[contador1]=cThisChar;
		contador1=contador1+1;

    	} while((cThisChar != '\n'));

    	cThisChar='0';

		for(i=0; i<sizeof(cuaternion); i++){
			UARTCharPut(UART4_BASE, cuaternion[i]);}

				do{

		    	cThisChar=UARTCharGet(UART4_BASE);
		    	BuffGPS[contador1]=cThisChar;
				contador1=contador1+1;

					} while((cThisChar != '\n'));

		rc = f_write(&Fil, &BuffGPS, contador1, &bwGPS);
		rc = f_sync(&Fil);
		contador1=0;

		//while(UARTCharsAvail(UART1_BASE)==false){;}
	}

	while(1);
}
コード例 #9
0
ファイル: main.c プロジェクト: gvb/quickstart
/**
 * Initialize the processor hardware.
 *
 * \req \req_init The \program \shall initialize the hardware.
 */
void prvSetupHardware(void)
{
	/*
	 * If running on Rev A2 silicon, turn the LDO voltage up to 2.75V.
	 * This is a workaround to allow the PLL to operate reliably.
	 */
	if( REVISION_IS_A2 ) {
		SysCtlLDOSet( SYSCTL_LDO_2_75V );
	}

	/**
	 * Set the clocking to run from the PLL at 50 MHz
	 */
#if (PART == LM3S8962)

	SysCtlClockSet(
		SYSCTL_SYSDIV_4
		| SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ );

#elif (PART == LM3S9B96)

	SysCtlClockSet(
		SYSCTL_SYSDIV_4
		| SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ );

	/* 80MHz operation, change FreeRTOSConfig.h too */
 /* 	SysCtlClockSet(
		SYSCTL_SYSDIV_2_5
		| SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ );
*/

#elif (PART == LM3S2110)
	//
	// Set the clocking to run directly from the PLL at 25MHz.
	//
	SysCtlClockSet(SYSCTL_SYSDIV_8 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
		       SYSCTL_XTAL_8MHZ);
#endif

	/*
	 * Initialize the ARM peripherals that are used.  All the GPIOs
	 * are initialized because the processor I/O page references
	 * all of them.
	 */
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);

	SysCtlPeripheralEnable(SYSCTL_PERIPH_WDOG0);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM);

#if (PART != LM3S2110)
	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
#endif

#if (PART==LM3S8962)
	/*
	 * Configure the GPIOs used to read the on-board buttons.
	 */
	GPIOPinTypeGPIOInput(GPIO_PORTE_BASE,
		GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
	GPIOPadConfigSet(GPIO_PORTE_BASE,
		GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3,
		GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
	GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_1);
	GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_STRENGTH_2MA,
		GPIO_PIN_TYPE_STD_WPU);

	/*
	 * Configure the LED and speaker GPIOs.
	 */
	GPIOPinTypePWM(GPIO_PORTG_BASE, GPIO_PIN_1);
	GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_0);
	GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, 0);
#endif

	/*
	 * UART0 is our debug ("spew") I/O.  Configure it for 115200,
	 * 8-N-1 operation.
	 */
	GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
	UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
		( UART_CONFIG_WLEN_8
		| UART_CONFIG_STOP_ONE
		| UART_CONFIG_PAR_NONE ));
}
コード例 #10
0
ファイル: main.c プロジェクト: CS308-2016/DrowsinessDetector
int main(void) {

	uint32_t ui32ADC0Value[4];

	ui32TempSet = 25;

	// Set System CLock
	SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
	// Enaable UART
	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
	// Enable GPIO
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
	// Enable ADC Peripheral
	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);

	//Allow the ADC12 to run at its default rate of 1Msps.
	ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);

	//our code will average all four samples of temperature sensor data	ta on sequencer 1 to calculate the temperature, so all four sequencer steps will measure the temperature sensor
	ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_TS);
	ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_TS);
	ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_TS);
	ADCSequenceStepConfigure(ADC0_BASE,1,3,ADC_CTL_TS|ADC_CTL_IE|ADC_CTL_END);

	//enable ADC sequencer 1.
	ADCSequenceEnable(ADC0_BASE, 1);

	GPIOPinConfigure(GPIO_PA0_U0RX);
	GPIOPinConfigure(GPIO_PA1_U0TX);
	GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

	IntMasterEnable();
	IntEnable(INT_UART0);
	UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);

	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
	GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2|GPIO_PIN_1|GPIO_PIN_3);

	// Set bit rate fr serial communication
	UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));



	while (1)
	{
		//indication that the ADC conversion process is complete
		ADCIntClear(ADC0_BASE, 1);
		//trigger the ADC conversion with software
		ADCProcessorTrigger(ADC0_BASE, 1);
		//wait for the conversion to complete
		while(!ADCIntStatus(ADC0_BASE, 1, false))
		{
		}
		//read the ADC value from the ADC Sample Sequencer 1 FIFO
		ADCSequenceDataGet(ADC0_BASE, 1, ui32ADC0Value);
		ui32TempAvg = (ui32ADC0Value[0] + ui32ADC0Value[1] + ui32ADC0Value[2] + ui32ADC0Value[3] + 2)/4;


		ui32TempValueC = (1475 - ((2475 * ui32TempAvg)) / 4096)/10;
		ui32TempValueF = ((ui32TempValueC * 9) + 160) / 5;

		print_temp(ui32TempValueC);
		SysCtlDelay(SysCtlClockGet() / 3); //delay ~1 sec
		if(ui32TempValueC < ui32TempSet)
			GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 8);
		else
			GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 2);
	}
}
コード例 #11
0
//*****************************************************************************
//
// Demonstrate the use of the boot loader.
//
//*****************************************************************************
int
main(void)
{
    //
    // Set the clocking to run directly from the crystal.
    //
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_6MHZ);

    //
    // Enable the UART and GPIO modules.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

    //
    // Make the UART pins be peripheral controlled.
    //
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // Configure the UART for 115,200, 8-N-1 operation.
    //
    UARTConfigSetExpClk(UART0_BASE, 6000000, 115200,
                        (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                         UART_CONFIG_PAR_NONE));

    //
    // Initialize the OLED display.
    //
    Display96x16x1Init(false);

    //
    // Indicate what is happening.
    //
    Display96x16x1StringDraw("Boot Loader Two", 0, 0);
    Display96x16x1StringDraw("press select", 0, 1);

    //
    // Enable the GPIO pin to read the select button.
    //
    GPIODirModeSet(GPIO_PORTC_BASE, GPIO_PIN_4, GPIO_DIR_MODE_IN);
    GPIOPadConfigSet(GPIO_PORTC_BASE, GPIO_PIN_4, GPIO_STRENGTH_2MA,
                     GPIO_PIN_TYPE_STD_WPU);

    //
    // Wait until the select button has been pressed.
    //
    while(GPIOPinRead(GPIO_PORTC_BASE, GPIO_PIN_4) != 0)
    {
    }

    //
    // Drain any data that may be in the UART fifo.
    //
    while(UARTCharsAvail(UART0_BASE))
    {
        UARTCharGet(UART0_BASE);
    }

    //
    // Indicate that the boot loader is being called.
    //
    Display96x16x1StringDraw("awaiting update", 0, 1);

    //
    // Call the boot loader so that it will listen for an update on the UART.
    //
    (*((void (*)(void))(*(unsigned long *)0x2c)))();

    //
    // The boot loader should take control, so this should never be reached.
    // Just in case, loop forever.
    //
    while(1)
    {
    }
}
コード例 #12
0
ファイル: uart_echo.c プロジェクト: vortex314/projects
//*****************************************************************************
//
// This example demonstrates how to send a string of data to the UART.
//
//*****************************************************************************
int main(void) {
	//
	// 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.
	//
	FPUEnable();
	FPULazyStackingEnable();

	//
	// Set the clocking to run directly from the crystal.
	//
	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.
	//
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

	//
	// Enable the GPIO pins for the LED (PF2).
	//
	GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);

	//
	// Enable the peripherals used by this example.
	//
	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

	//
	// Enable processor interrupts.
	//
	IntMasterEnable();

	//
	// Set GPIO A0 and A1 as UART pins.
	//
	GPIOPinConfigure(GPIO_PA0_U0RX);
	GPIOPinConfigure(GPIO_PA1_U0TX);
	GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

	//
	// Configure the UART for 115,200, 8-N-1 operation.
	//
	UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
			(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));

	//
	// Enable the UART interrupt.
	//
	IntEnable(INT_UART0);
	UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);

	//
	// Prompt for text to be entered.
	//
	UARTSend((unsigned char *) "Enter text: ", 14);

	//
	// Loop forever echoing data through the UART.
	//
	while (1) {
	}
}
コード例 #13
0
ファイル: keypad.c プロジェクト: phuongtg/micro2-1
int main(void) {
  SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);

  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);

  SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);//1024hz = 15625
  SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
  GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE, GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6);
  GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_3);
  GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7);
  GPIOPinConfigure(GPIO_PB1_U1TX);
  GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_1);
  UARTConfigSetExpClk(b1, SysCtlClockGet(), 9600, UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE);
  UARTEnable(b1);

  GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1);


  GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, (GPIO_PIN_0 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_1));
  GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7);
  frequency = SysCtlClockGet()/2;

  changeCursorUnderscore();
  toggleLED();


  //Clear Display
  clearDisplay();
  //putPhrase("Hello World!");
  //Timer Configuration
  TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
  TimerLoadSet(TIMER0_BASE, TIMER_A, frequency);
  TimerControlEvent(TIMER0_BASE, TIMER_A, TIMER_EVENT_POS_EDGE);
  TimerEnable(TIMER0_BASE, TIMER_A);

  //Timer Interrupt Enable
  TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
  TimerIntRegister(TIMER0_BASE, TIMER_A, timer_interrupt);


  while(1){
    if(flag = 1){  
    //Reset the line read
      code = 0;

    //Turn on the scan for a line
      if(counter == 0) GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_3, 0x8);
      if(counter == 1) GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_4, 0x10);
      if(counter == 2) GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5, 0x20);
      if(counter == 3) GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_6, 0x40);

    //Check which button on the line was pressed
      if(GPIOPinRead(GPIO_PORTA_BASE, GPIO_PIN_5) == 0x20) {
        code = 1;
        temp = log_code;
      }
      if(GPIOPinRead(GPIO_PORTA_BASE, GPIO_PIN_6) == 0x40) {
        code = 2;
        temp = log_code;
      }
      if(GPIOPinRead(GPIO_PORTA_BASE, GPIO_PIN_7) == 0x80) {
        code = 3;
        temp = log_code;
      }

    //Turn off the scan for a line
      if(counter == 0) GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_3, 0x0);
      if(counter == 1) GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_4, 0x0);
      if(counter == 2) GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5, 0x0);
      if(counter == 3) GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_6, 0x0);

    //Check the next line on the next run and if overflows, reset


    //Calculate the index_code for the lookup table
      index_code = temp + code;
      key_char = lookup_table[index_code];
      log_code = log_code + 4;
      if(log_code > 12){
        log_code = 0;
      }

      counter++;
      if(counter > 3) counter = 0;
      if(key_char != 'x'){
        //toggleLED();
        putChar(key_char);
      //SysCtlDelay(100000);
        index_code = 0;
      }
      flag = 0;
    }
  }

}
コード例 #14
0
ファイル: main.c プロジェクト: cmonr/tm4c1233h6pm-fw
int main(void)
{
    // Clock (80MHz)
    SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);
    
    
    // GPIO
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1);
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 0);

    
    // UART
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200, (UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_ONE | UART_CONFIG_WLEN_8));
    
    UARTEnable(UART0_BASE);
    

    // I2C
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
    GPIOPinConfigure(GPIO_PB2_I2C0SCL);
    GPIOPinConfigure(GPIO_PB3_I2C0SDA);
    GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);
    GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);
    I2CMasterInitExpClk(I2C0_BASE, SysCtlClockGet(), false);
    
    I2CMasterEnable(I2C0_BASE);
    

    
    // Scan for addresses
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_PIN_1);
    
    printf("Scan started\r\n");

    for(i=0; i<255; i++)
    {
        I2CMasterSlaveAddrSet(I2C0_BASE, i>>1, false);
        I2CMasterDataPut(I2C0_BASE, 0);
        I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_SEND);

        SysCtlDelay(SysCtlClockGet()/10000);

        if (I2CMasterErr(I2C0_BASE) ==  I2C_MASTER_ERR_NONE)
        {
            printf("x%02X\r\n", i);
        }
        else
        {
            //printf(" N\r\n");
        }
    }

    printf("\r\nScan complete\r\n\r\n");

    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 0);



    while(1);
}
コード例 #15
0
//*****************************************************************************
//
// This example demonstrates how to send a string of data to the UART.
//
//*****************************************************************************
int
main(void)
{
    //
    // Set the clocking to run directly from the crystal.
    //
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_8MHZ);

    //
    // Initialize the OLED display and write status.
    //
    RIT128x96x4Init(1000000);
    RIT128x96x4StringDraw("UART Echo",            36,  0, 15);
    RIT128x96x4StringDraw("Port:   Uart 0",       12, 16, 15);
    RIT128x96x4StringDraw("Baud:   115,200 bps",  12, 24, 15);
    RIT128x96x4StringDraw("Data:   8 Bit",        12, 32, 15);
    RIT128x96x4StringDraw("Parity: None",         12, 40, 15);
    RIT128x96x4StringDraw("Stop:   1 Bit",        12, 48, 15);

    //
    // Enable the peripherals used by this example.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

    //
    // Enable processor interrupts.
    //
    IntMasterEnable();

    //
    // Set GPIO A0 and A1 as UART pins.
    //
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // Configure the UART for 115,200, 8-N-1 operation.
    //
    UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
                        (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                         UART_CONFIG_PAR_NONE));

    //
    // Enable the UART interrupt.
    //
    IntEnable(INT_UART0);
    UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);

    //
    // Prompt for text to be entered.
    //
    UARTSend((unsigned char *)"Enter text: ", 12);

    //
    // Loop forever echoing data through the UART.
    //
    while(1)
    {
    }
}
コード例 #16
0
ファイル: main.c プロジェクト: idaohang/launchpad-gps
int main(void) {
    // Status of Hibernation module
    uint32_t ui32Status = 0;
    // Length of time to hibernate
    uint32_t hibernationTime = 600;

    g_ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
            SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |
            SYSCTL_CFG_VCO_480), 120000000);


    //*************************************************************************
    //! I/O config and setup
    //*************************************************************************

    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);	// UART
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART7);	// UART
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);	// UART0
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);	// UART7
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);	// SSI
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);	// GPIO
    SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI2);		// SSI
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK);	// GPIO
    SysCtlPeripheralEnable(SYSCTL_PERIPH_HIBERNATE);// Hibernation

    // UART0 and UART7
    GPIOPinConfigure(GPIO_PA0_U0RX);
    GPIOPinConfigure(GPIO_PC4_U7RX);
    GPIOPinConfigure(GPIO_PA1_U0TX);
    GPIOPinConfigure(GPIO_PC5_U7TX);

    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_4 | GPIO_PIN_5);

    // LED indicators
    GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // SD Card Detect (PK3) and GPS Pulse Per Second (PK2)
    //
    GPIOPinTypeGPIOInput(GPIO_PORTK_BASE, GPIO_PIN_2|GPIO_PIN_3);
    // Pulse Per Second input pin config as weak pull-down
    GPIOPadConfigSet(GPIO_PORTK_BASE,GPIO_PIN_2,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPD);
    // Pulse Per Second input pin config as rising edge triggered interrupt
    GPIOIntTypeSet(GPIO_PORTK_BASE,GPIO_PIN_2,GPIO_RISING_EDGE);
    // Register Port K as interrupt
    GPIOIntRegister(GPIO_PORTK_BASE, PortKIntHandler);
    // Enable Port K pin 2 interrupt
    GPIOIntEnable(GPIO_PORTK_BASE, GPIO_INT_PIN_2);
    //
    // Disable PPS pin interrupt by default
    //
    if(IntIsEnabled(INT_GPIOK)) {
            IntDisable(INT_GPIOK);
    }

    GPIOPinConfigure(GPIO_PD0_SSI2XDAT1);
    GPIOPinConfigure(GPIO_PD1_SSI2XDAT0);
    GPIOPinConfigure(GPIO_PD2_SSI2FSS);
    GPIOPinConfigure(GPIO_PD3_SSI2CLK);

    // SD Card Detect (CD) - weak pull-up input
    GPIOPadConfigSet(GPIO_PORTK_BASE, GPIO_PIN_3, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);

    // Debug UART output config
    UARTConfigSetExpClk(UART0_BASE, g_ui32SysClock, 115200,
            (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));

    // GPS UART input config
    UARTConfigSetExpClk(UART7_BASE, g_ui32SysClock, 9600,
            (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));

    //
    // Configure SysTick for a 100Hz interrupt.
    //
    SysTickPeriodSet(g_ui32SysClock / 100);
    SysTickIntEnable();
    SysTickEnable();

    //
    // Floating point enable
    //
    FPUEnable();
    FPULazyStackingEnable();

    //
    // Clear user LEDs
    //
    GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0 | GPIO_PIN_1, 0x00);

    //*************************************************************************
    //! Hibernation mode checks and setup
    //*************************************************************************

    //
    // Check to see if Hibernation module is already active, which could mean
    // that the processor is waking from a hibernation.
    //
    if(HibernateIsActive()) {
        //
        // Read the status bits to see what caused the wake.  Clear the wake
        // source so that the device can be put into hibernation again.
        //
        ui32Status = HibernateIntStatus(0);
        HibernateIntClear(ui32Status);

        //
        // Wake was due to RTC match.
        //
        if(ui32Status & HIBERNATE_INT_RTC_MATCH_0) {
            //
            // TODO: add IMU check
            //
        }
        //
        // Wake was due to the External Wake pin.
        //
        else if(ui32Status & HIBERNATE_INT_PIN_WAKE) {
            //
            // Switch off low power mode
            //
            lowPowerOn = 0;
        }
    }

    //
    // Configure Hibernate module clock.
    //
    HibernateEnableExpClk(g_ui32SysClock);

    //
    // If the wake was not due to the above sources, then it was a system
    // reset.
    //
    if(!(ui32Status & (HIBERNATE_INT_PIN_WAKE | HIBERNATE_INT_RTC_MATCH_0))) {
        //
        // Configure the module clock source.
        //
        HibernateClockConfig(HIBERNATE_OSC_LOWDRIVE);
    }

    //
    // Enable PPS for a single data log. Interrupt on next PPS logic high.
    //
    ppsDataLog();

    //
    // Enable RTC mode.
    //
    HibernateRTCEnable();

    //
    // Loop forever
    //
    while(1) {
        //
        // If low power mode is set (default), hibernate again
        // If not, spin in nested while(1) for faster updates from PPS pin ints.
        //
        if(lowPowerOn) {
            lowPowerMode(hibernationTime);
        }
        else {
            if(!IntIsEnabled(INT_GPIOK)) {
                    IntEnable(INT_GPIOK);
            }
            while(1) {
            }
        }
    }
} // End function main
コード例 #17
0
/*
 * portno从0开始编号
 */
sys_cfg_err_t sys_cfg_uart(struct uart_param *cfgdata, int portno)
{
    unsigned long base;
    unsigned long cfg;
    
    /* portno, cfgdata->databits, cfgdata->stopbits, cfgdata->paritybit */
    if (portno>=UART_PORT_NUM || NULL==cfgdata) {
        return SYS_CFG_PARAM_ERR;
    }

    /* 对波特率进行检查的代码还未编写!!! */
    if (cfgdata->databits < UART_DATA_BITS_MIN
            || cfgdata->databits > UART_DATA_BITS_MAX
            || cfgdata->stopbits < UART_STOP_BITS_MIN
            || cfgdata->stopbits > UART_STOP_BITS_MIN) {
        return SYS_CFG_DATA_ERR;
    }

    switch (portno) {
    case 0:
        base = UART0_BASE;
        break;
    case 1:
        base = UART1_BASE;
        break;
    case 2: /* UART_PORT_NUM - 1 */
        base = UART2_BASE;
        break;

    default: /* 这种情况不应该出现, 现在只是做简单的处理 */
        return SYS_CFG_PARAM_ERR;
    }

    cfg = 0;
    switch (cfgdata->databits) {
    case 5: /* UART_DATA_BITS_MIN */
        cfg |= UART_CONFIG_WLEN_5;
        break;
    case 6:
        cfg |= UART_CONFIG_WLEN_6;
        break;
    case 7:
        cfg |= UART_CONFIG_WLEN_7;
        break;
    case 8: /* UART_DATA_BITS_MAX */
        cfg |= UART_CONFIG_WLEN_8;
        break;
    default: /* 这种情况不应该出现, 现在只是做简单的处理 */
        return SYS_CFG_PARAM_ERR;
    }

    if (1 == cfgdata->stopbits)
        cfg |= UART_CONFIG_STOP_ONE;
    else if (2 == cfgdata->stopbits)
        cfg |= UART_CONFIG_STOP_TWO;
    else
        return SYS_CFG_PARAM_ERR;

    switch (cfgdata->paritybit) {
    case UART_PAR_NONE:
        cfg |= UART_CONFIG_PAR_NONE;
        break;
    case UART_PAR_EVEN:
        cfg |= UART_CONFIG_PAR_EVEN;
        break;
    case UART_PAR_ODD:
        cfg |= UART_CONFIG_PAR_ODD;
        break;
    case UART_PAR_ONE:
        cfg |= UART_CONFIG_PAR_ONE;
        break;
    case UART_PAR_ZERO:
        cfg |= UART_CONFIG_PAR_ZERO;
        break;
    default:
        return SYS_CFG_PARAM_ERR;
    }

    // Configure the UART for 115,200, 8-N-1 operation.
    // This function uses SysCtlClockGet() to get the system clock
    // frequency.  This could be also be a variable or hard coded value
    // instead of a function call.
    UARTConfigSetExpClk(base, SysCtlClockGet(), cfgdata->baudrate, cfg);
    return SYS_CFG_SUCC;    
}
コード例 #18
0
ファイル: lab5.c プロジェクト: Jesse-Millwood/EGR424-Lab5
// Functions
void SAD_Initialize(DriverRegisters* sadreg, role_t setRole, unsigned short setBaud)
{
    #ifdef SAD_DEBUG
    RIT128x96x4Init(1000000);
    
    #endif
    
    // initializing these values is messy but works for now
    sadreg->hs_baud.validbauds[0] = 1200;
    sadreg->hs_baud.validbauds[1] = 2400;
    sadreg->hs_baud.validbauds[2] = 9600;
    sadreg->hs_baud.validbauds[3] = 38400;
    // Initialize global flags and vars
    //UARTRX_FLAG = 0;
    //SYSTICKINT_FLAG = 0;
    //GLOBALTIME.hours = 0;
    //GLOBALTIME.mins = 0;
    //GLOBALTIME.seconds = 0;
    //GLOBALTIME.milisecs = 0;
    // set relevent structure attributes based on provided parameters
    sadreg->role = setRole;
    sadreg->txbaud = setBaud;
    // Based on the role, set the initial state for the state machine
    //sadreg->state = (sadreg->role == TXER) ? HANDSHAKE_TX : HANDSHAKE_RX;
    // Initialize the hand shake counter to 0
    //sadreg->hs_cnt = 0;
    // Initialize the circle buffer
    //init_cbuff(&sadreg->circbuf);
    SAD_timerinit(sadreg);
    // Initialize rx baud to 0
    //sadreg->rxbaud = 0;
    // Initialize hand shake baude pointer
    //sadreg->hs_baud.currentbaudchoice = 0;
    // Initialize tx baud to first element in valid baud rates array
     //sadreg->txbaud = sadreg->hs_baud.validbauds[sadreg->hs_baud.currentbaudchoice];

     
    // Use Systick timer
    SysTickIntRegister(&SysTickTimerHandler);
    SysTickPeriodSet(sadreg->timer.limit); // set to rollover every 1ms
    SysTickIntEnable();
    SysTickEnable();
    
    // Initialize HW Timer
    /* SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); */
    /* TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); */
    /* TimerLoadSet(TIMER0_BASE, TIMER_A, SysCtlClockGet()); */
    /* IntEnable(INT_TIMER0A); */
    /* TimerEnable(TIMER0_BASE, TIMER_A); */
    

    // Initialize UART0
    // UART0_TX : PA1
    // UART0_RX : PA0
    // Enable UART Peripherals
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    // Set GPIO A0 and A1 as UART pins.
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    // Configure the UART for 115,200, 8-N-1 operation.
    UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
                        (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                         UART_CONFIG_PAR_NONE));
    // Enable the UART interrupt.
    IntEnable(INT_UART0);
    UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);

    // Initialize UART1
    // UART1_TX : PD3
    // UART1_RX : PD2
    // disable fifos
    // Enable UART Peripherals
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    // Set GPIO A0 and A1 as UART pins.
    GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_2 | GPIO_PIN_3);
    // Configure the UART for SADreg baud, 8-N-1 operation.
    UARTConfigSetExpClk(UART1_BASE, SysCtlClockGet(), sadreg->txbaud,
                        (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                         UART_CONFIG_PAR_NONE));
    // Disable fifos, fifo is of depth 1, 
    //UARTFIFODisable(UART1_BASE); 
    // Enable the UART interrupt.
    IntEnable(INT_UART1);
    UARTIntEnable(UART1_BASE, UART_INT_RX | UART_INT_RT);

    // Enable processor interrupts.
    IntMasterEnable();
}
コード例 #19
0
ファイル: main.c プロジェクト: cmonr/tm4c1233h6pm-fw
int main(void)
{ 
    unsigned int i = 0;

    // Clock (80MHz)
    SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);
    
    
    // GPIO
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2);
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 0);

    
    // UART (Serial)
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200, (UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_ONE | UART_CONFIG_WLEN_8));

    UARTEnable(UART0_BASE);
    UARTFIFODisable(UART0_BASE);
  
    
    /*I2CInit();

    // PCA9557
    i2c_buff[0] = 0x03;
    i2c_buff[1] = 0x00; // 0: Output   1: Input
    I2CWrite(0x18, i2c_buff, 2);  // IO Direction

    i2c_buff[0] = 0x02;
    i2c_buff[1] = 0x00;
    I2CWrite(0x18, i2c_buff, 2);  // IO Polarity

    i2c_buff[0] = 0x01;
    i2c_buff[1] = 0x8F;
    I2CWrite(0x18, i2c_buff, 2);  // Output H/L
*/


    //initLEDs();
    //initMotors();
    //initEncoders();
    initServos();
    //initBluetooth();
    
    //invertMotor(0);
    //invertMotor(1);
    //invertEncoder(0);

    

    // Do some tests
    //setMotor(0, 0.85);
    //setMotor(1, 0.85);
    setServoLimits(5, 0.35, 0.85);


    // Enable Interrupts
    IntMasterEnable();


    while(1)
    {

        //for(i=0; i<12; i++)
        //{
            setServo(5, 0.0);
            toggleRed();
            SysCtlDelay(SysCtlClockGet());
        //    printf("%d\r\n", i*5);
            
            setServo(5, 0.6);
            toggleRed();
            SysCtlDelay(SysCtlClockGet());


        //}



        // LED On
       /* toggleRed();

        printf("0:% 6ld  1:% 6ld\r\n", readEnc(0), readEnc(1));

        SysCtlDelay(SysCtlClockGet() / 3 / 5);


        if (i == 10)  // 5 Seconds
        {
           i2c_buff[0] = 0x01;
           i2c_buff[1] = 0x0F | 0x00;
           I2CWrite(0x18, i2c_buff, 2);  // Output H/L
        }

        i++;
*/

        /*I2CMasterSlaveAddrSet(I2C0_BASE, 0x18, false);  // Set Outputs Directions
        I2CMasterDataPut(I2C0_BASE, 0x01);             
        I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);
        while(I2CMasterBusy(I2C0_BASE));
        I2CMasterDataPut(I2C0_BASE, 0x00);            
        I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
        while(I2CMasterBusy(I2C0_BASE));


        I2CMasterSlaveAddrSet(I2C0_BASE, 0x18, false);  // Set Outputs Directions
        I2CMasterDataPut(I2C0_BASE, 0x01);             
        I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);
        while(I2CMasterBusy(I2C0_BASE));
        I2CMasterDataPut(I2C0_BASE, 0xF0);            
        I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
        while(I2CMasterBusy(I2C0_BASE));
        */


        //UART1Write("A\r\n", 3);
        //UARTCharPut(UART1_BASE, 'B');
        
        //UART1WriteChar(UARTCharGet(UART0_BASE));
        
       /* 
        for (i=0; i<8; i++)
        {
            unsigned char tmp;  
          
            i2c_buff[0] = 0x84 | (i << 4);
            I2CWrite(0x48, i2c_buff, 1);
            if (I2CMasterErr(I2C0_BASE))
                printf("Err: %d\r\n", (unsigned int) I2CMasterErr(I2C0_BASE));

            I2CRead(0x48, &tmp, 1);
            if (I2CMasterErr(I2C0_BASE))
                printf("Err: %d\r\n", (unsigned int) I2CMasterErr(I2C0_BASE));


            printf("% 3d ", tmp);
        }*/

       /* toggleRed();

        for(i=0; i<=100; i++)
        {
            setMotor(0, 0.01 * i);
            setMotor(1, 0.01 * i);
            setMotor(2, 0.01 * i);
            setMotor(3, 0.01 * i);
            printf("%d\r\n", i);
            SysCtlDelay(SysCtlClockGet() / 3 / 100);
        }

        toggleRed();

        for(; i>0; i--)
        {
            setMotor(0, 0.01 * i);
            setMotor(1, 0.01 * i);
            setMotor(2, 0.01 * i);
            setMotor(3, 0.01 * i);
            printf("%d\r\n", i);
            SysCtlDelay(SysCtlClockGet() / 3 / 100);
        }*/


        
        //printf("%d\r\n", (unsigned int) (((ADCRead(3) >> 4) - 45) * 0.45));
        //setServo(0, (((ADCRead(3) >> 4) - 45) * 0.45) / 100.0);

/*
        I2CMasterSlaveAddrSet(I2C0_BASE, 0x18, false);  // Set Outputs Directions
        I2CMasterDataPut(I2C0_BASE, 0x01);             
        I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);
        while(I2CMasterBusy(I2C0_BASE));
        if (GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_4) == 0)
            I2CMasterDataPut(I2C0_BASE, 0x80);            
        else
            I2CMasterDataPut(I2C0_BASE, 0x70);            
        I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
        while(I2CMasterBusy(I2C0_BASE));*/


        /*I2CMasterSlaveAddrSet(I2C0_BASE, 0x18, false);
        I2CMasterDataPut(I2C0_BASE, 0x00);
        I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_SEND);
        while(I2CMasterBusy(I2C0_BASE));

        I2CMasterSlaveAddrSet(I2C0_BASE, 0x18, true);
        I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);
        while(I2CMasterBusy(I2C0_BASE));

        if( (I2CMasterDataGet(I2C0_BASE) & 0x01) != 0)
            toggleBlue();*/
    }


}
コード例 #20
0
ファイル: quad_uart.c プロジェクト: KondorSoft/UWB-Quadcopter
void quad_uart_init() {
	
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART2);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART3);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART4);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART6);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

    GPIOPinConfigure(GPIO_PA0_U0RX); // USB Serial Receive Line
    GPIOPinConfigure(GPIO_PA1_U0TX); // USB Serial Transmit Line



    GPIOPinConfigure(GPIO_PB0_U1RX); // Universal Sonar Receive Linx
    GPIOPinConfigure(GPIO_PB1_U1TX); // Transmit Line Sonar 1
    GPIOPinConfigure(GPIO_PD7_U2TX); // Transmit Line Sonar 2
    GPIOPinConfigure(GPIO_PC7_U3TX); // Transmit Line Sonar 3
    GPIOPinConfigure(GPIO_PC5_U4TX); // Transmit Line Sonar 4
    GPIOPinConfigure(GPIO_PD5_U6TX); // Transmit Line Sonar 5



    // Set the pin types
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_5 | GPIO_PIN_7);
    GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_5 | GPIO_PIN_7);

    UARTEnable(UART0_BASE);
    UARTEnable(UART1_BASE);

    // Set the UART clock to have a baud rate of 115200
    UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
        (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));

    // The sonars use a 9600 baud rate for serial data, but we are using 
    // gpio with interrupts instead.
    UARTConfigSetExpClk(UART1_BASE, SysCtlClockGet(), 9600,
        (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));


    UARTConfigSetExpClk(UART2_BASE, SysCtlClockGet(), 115200,
        (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));


    UARTConfigSetExpClk(UART3_BASE, SysCtlClockGet(), 115200,
        (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));


    UARTConfigSetExpClk(UART4_BASE, SysCtlClockGet(), 115200,
        (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));


    UARTConfigSetExpClk(UART6_BASE, SysCtlClockGet(), 115200,
        (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));


}