コード例 #1
0
//*****************************************************************************
//
// Configure the UART and its pins.  This must be called before UARTprintf().
//
//*****************************************************************************
void ConfigureUART(void) {
	//
	// Enable the GPIO Peripheral used by the UART.
	//
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

	//
	// Enable UART0
	//
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

	//
	// Configure GPIO Pins for UART mode.
	//
	ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
	ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
	ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

	//
	// Use the internal 16MHz oscillator as the UART clock source.
	//
	UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);

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

	// Configure URAT4
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);

	//
	// Enable UART0
	//
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART4);

	ROM_GPIOPinConfigure(GPIO_PC4_U4RX);
	ROM_GPIOPinConfigure(GPIO_PC5_U4TX);
	ROM_GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_4 | GPIO_PIN_5);

	//
	// Configure the UART for 115,200, 8-N-1 operation.
	//
	UARTConfigSetExpClk(UART4_BASE, ROM_SysCtlClockGet(), 115200,
			(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
	UARTFlowControlSet(UART4_BASE, UART_FLOWCONTROL_NONE);

	//
	// Enable the UART interrupt.
	//
	UARTIntDisable(UART4_BASE, 0xFFFFFFFF);
	UARTIntEnable(UART4_BASE, UART_INT_RX | UART_INT_RT);
	IntEnable(INT_UART4);
}
コード例 #2
0
ファイル: pybuart.c プロジェクト: jasongwq/micropython
// assumes init parameters have been set up correctly
bool uart_init2(pyb_uart_obj_t *self) {
    uint uartPerh;

    switch (self->uart_id) {
    case PYB_UART_0:
        self->reg = UARTA0_BASE;
        uartPerh = PRCM_UARTA0;
        MAP_UARTIntRegister(UARTA0_BASE, UART0IntHandler);
        MAP_IntPrioritySet(INT_UARTA0, INT_PRIORITY_LVL_3);
        break;
    case PYB_UART_1:
        self->reg = UARTA1_BASE;
        uartPerh = PRCM_UARTA1;
        MAP_UARTIntRegister(UARTA1_BASE, UART1IntHandler);
        MAP_IntPrioritySet(INT_UARTA1, INT_PRIORITY_LVL_3);
        break;
    default:
        return false;
    }

    // Enable the peripheral clock
    MAP_PRCMPeripheralClkEnable(uartPerh, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK);

    // Reset the uart
    MAP_PRCMPeripheralReset(uartPerh);

    // Initialize the UART
    MAP_UARTConfigSetExpClk(self->reg, MAP_PRCMPeripheralClockGet(uartPerh),
                            self->baudrate, self->config);

    // Enbale the FIFO
    MAP_UARTFIFOEnable(self->reg);

    // Configure the FIFO interrupt levels
    MAP_UARTFIFOLevelSet(self->reg, UART_FIFO_TX4_8, UART_FIFO_RX4_8);
    
    // Configure the flow control mode
    UARTFlowControlSet(self->reg, self->flowcontrol);

    // Enable the RX and RX timeout interrupts
    MAP_UARTIntEnable(self->reg, UART_INT_RX | UART_INT_RT);

    self->enabled = true;

    return true;
}
コード例 #3
0
//*****************************************************************************
//
// This example demonstrates how to send a string of data to the UART.
//
//*****************************************************************************
int
main(void)
{
    uint32_t ui32SysClock;
    tContext sContext;

    //
    // Run from the PLL at 120 MHz.
    //
    ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                           SYSCTL_OSC_MAIN |
                                           SYSCTL_USE_PLL |
                                           SYSCTL_CFG_VCO_480), 120000000);

    //
    // 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, "ble-btool");

    //
    // PJ0, 1, 4, 5 are used for UART3.
    //
    ROM_GPIOPinConfigure(GPIO_PJ0_U3RX);
    ROM_GPIOPinConfigure(GPIO_PJ1_U3TX);
    ROM_GPIOPinConfigure(GPIO_PJ4_U3RTS);
    ROM_GPIOPinConfigure(GPIO_PJ5_U3CTS);
    ROM_GPIOPinTypeUART(GPIO_PORTJ_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5);

    //
    // Display UART configuration on the display.
    //
    GrStringDraw(&sContext, "Use BTool on PC",  -1,  70, 40, 0);
    GrStringDraw(&sContext, "Port:",       -1,  70, 70, 0);
    GrStringDraw(&sContext, "Baud:",       -1,  70, 95, 0);
    GrStringDraw(&sContext, "Data:",       -1,  70, 120, 0);
    GrStringDraw(&sContext, "Parity:",     -1,  70, 145, 0);
    GrStringDraw(&sContext, "Stop:",       -1,  70, 170, 0);
    GrStringDraw(&sContext, "Flow:",       -1,  70, 195, 0);
    GrStringDraw(&sContext, "Uart 0",      -1, 150, 70, 0);
    GrStringDraw(&sContext, "115,200 bps", -1, 150, 95, 0);
    GrStringDraw(&sContext, "8 Bit",       -1, 150, 120, 0);
    GrStringDraw(&sContext, "None",        -1, 150, 145, 0);
    GrStringDraw(&sContext, "1 Bit",       -1, 150, 170, 0);
    GrStringDraw(&sContext, "CTS/RTS",     -1, 150, 195, 0);

    //
    // Enable the (non-GPIO) peripherals used by this example.  PinoutSet()
    // already enabled GPIO Port A.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART3);

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

    //
    // Configure the UART0 for 115,200, 8-N-1 operation.
    //
    ROM_UARTConfigSetExpClk(UART0_BASE, ui32SysClock, 115200,
                            (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                             UART_CONFIG_PAR_NONE));

    //
    // Configure the UART3 for 115,200, 8-N-1 operation.
    //
    ROM_UARTConfigSetExpClk(UART3_BASE, ui32SysClock, 115200,
                            (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                             UART_CONFIG_PAR_NONE));

    //
    // Configure the UART3 with flow control.
    //
    UARTFlowControlSet(UART3_BASE, UART_FLOWCONTROL_TX | UART_FLOWCONTROL_RX);

    //
    // Enable the UART interrupt.
    //
    ROM_IntEnable(INT_UART0);
    ROM_IntEnable(INT_UART3);
    ROM_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
    ROM_UARTIntEnable(UART3_BASE, UART_INT_RX | UART_INT_RT);

    //
    // Loop forever passing data between UART0 and UART3.
    //
    while(1)
    {
    }
}
コード例 #4
0
Fd_t uart_Open(char *ifName, unsigned long flags)
{
	/* Configure CS (PE0) and nHIB (PE4) lines */
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
	ROM_GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_4);
	ROM_GPIOPinWrite(GPIO_PORTE_BASE,GPIO_PIN_4, PIN_LOW);


	/* configuring UART interface */
	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);

	GPIOPinConfigure(GPIO_PB0_U1RX);
	GPIOPinConfigure(GPIO_PB1_U1TX);
	ROM_GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);

	GPIOPinConfigure(GPIO_PC4_U1RTS);
	GPIOPinConfigure(GPIO_PC5_U1CTS);
	ROM_GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_4 | GPIO_PIN_5);

	GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_0, GPIO_STRENGTH_2MA,
				GPIO_PIN_TYPE_STD_WPU);
	/* configure with baud rate 115200 */
	ROM_UARTConfigSetExpClk(UART1_BASE, ROM_SysCtlClockGet(), 115200,
	                            (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
	                             UART_CONFIG_PAR_NONE));

    UARTFlowControlSet(UART1_BASE, UART_FLOWCONTROL_TX | UART_FLOWCONTROL_RX);

    UARTFIFOLevelSet(UART1_BASE, UART_FIFO_TX1_8, UART_FIFO_RX1_8);

    ROM_UARTEnable(UART1_BASE);
    ROM_UARTFIFOEnable(UART1_BASE);

    ROM_IntEnable(INT_UART1);
    ROM_UARTIntEnable(UART1_BASE, UART_INT_RX);
    ROM_UARTIntDisable(UART1_BASE, UART_INT_TX | UART_INT_RT);


	/* configure host IRQ line */
	GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_2);
	GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_STRENGTH_2MA,
			GPIO_PIN_TYPE_STD_WPD);
	GPIOIntTypeSet(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_RISING_EDGE);
	GPIOIntClear(GPIO_PORTB_BASE,GPIO_PIN_2);
	GPIOIntDisable(GPIO_PORTB_BASE,GPIO_PIN_2);
	ROM_IntEnable(INT_GPIOB);
	ROM_IntMasterEnable();

	IntIsMasked = FALSE;

	/* Enable WLAN interrupt */
	CC3100_InterruptEnable();

	/* 50 ms delay */
	ROM_SysCtlDelay((ROM_SysCtlClockGet()/(3*1000))*50 );


	return NONOS_RET_OK;
}
コード例 #5
0
   /* success.                                                          */
int BTPSAPI HCITR_COMOpen(HCI_COMMDriverInformation_t *COMMDriverInformation, HCITR_COMDataCallback_t COMDataCallback, unsigned long CallbackParameter)
{
   int ret_val;

   /* First, make sure that the port is not already open and make sure  */
   /* that valid COMM Driver Information was specified.                 */
   if((!HCITransportOpen) && (COMMDriverInformation) && (COMDataCallback))
   {
      /* Initialize the return value for success.                       */
      ret_val               = TRANSPORT_ID;

      /* Note the COM Callback information.                             */
      _COMDataCallback      = COMDataCallback;
      _COMCallbackParameter = CallbackParameter;

      /* Initialize the UART Context Structure.                         */
      BTPS_MemInitialize(&UartContext, 0, sizeof(UartContext_t));

      UartContext.Base         = HCI_UART_BASE;
      UartContext.IntBase      = HCI_UART_INT;
      UartContext.ID           = 1;
      UartContext.FlowInfo     = UART_CONTEXT_FLAG_FLOW_CONTROL_ENABLED;
      UartContext.XOnLimit     = DEFAULT_XON_LIMIT;
      UartContext.XOffLimit    = DEFAULT_XOFF_LIMIT;
      UartContext.RxBufferSize = DEFAULT_INPUT_BUFFER_SIZE;
      UartContext.RxBytesFree  = DEFAULT_INPUT_BUFFER_SIZE;
      UartContext.TxBufferSize = DEFAULT_OUTPUT_BUFFER_SIZE;
      UartContext.TxBytesFree  = DEFAULT_OUTPUT_BUFFER_SIZE;

      /* Flag that the Rx Thread should not delete itself.              */
      RxThreadDeleted          = FALSE;

      /* Check to see if this is the first time that the port has been  */
      /* opened.                                                        */
      if(!Handle)
      {
         /* Configure the UART module and the GPIO pins used by the     */
         /* UART.                                                       */
         MAP_SysCtlPeripheralEnable(HCI_UART_GPIO_PERIPH);
         MAP_SysCtlPeripheralEnable(HCI_UART_RTS_GPIO_PERIPH);
         MAP_SysCtlPeripheralEnable(HCI_UART_CTS_GPIO_PERIPH);
         MAP_SysCtlPeripheralEnable(HCI_UART_PERIPH);

         MAP_GPIOPinConfigure(HCI_PIN_CONFIGURE_UART_RX);
         MAP_GPIOPinConfigure(HCI_PIN_CONFIGURE_UART_TX);
         MAP_GPIOPinConfigure(HCI_PIN_CONFIGURE_UART_RTS);
         MAP_GPIOPinConfigure(HCI_PIN_CONFIGURE_UART_CTS);

         MAP_GPIOPinTypeUART(HCI_UART_GPIO_BASE, HCI_UART_PIN_RX | HCI_UART_PIN_TX);
         MAP_GPIOPinTypeUART(HCI_UART_RTS_GPIO_BASE, HCI_UART_PIN_RTS);
         MAP_GPIOPinTypeUART(HCI_UART_CTS_GPIO_BASE, HCI_UART_PIN_CTS);

         UARTFlowControlSet(UartContext.Base, UART_FLOWCONTROL_RX | UART_FLOWCONTROL_TX);

         /* Create an Event that will be used to signal that data has   */
         /* arrived.                                                    */
         RxDataEvent = BTPS_CreateEvent(FALSE);
         if(RxDataEvent)
         {
            /* Create a thread that will process the received data.     */
            Handle = BTPS_CreateThread(RxThread, 1600, NULL);
            if(!Handle)
            {
               BTPS_CloseEvent(RxDataEvent);
               ret_val = HCITR_ERROR_UNABLE_TO_OPEN_TRANSPORT;
            }
         }
         else
            ret_val = HCITR_ERROR_UNABLE_TO_OPEN_TRANSPORT;
      }

      /* If there was no error, then continue to setup the port.        */
      if(ret_val != HCITR_ERROR_UNABLE_TO_OPEN_TRANSPORT)
      {
         /* Configure UART Baud Rate and Interrupts.                    */
         MAP_UARTConfigSetExpClk(UartContext.Base, MAP_SysCtlClockGet(), COMMDriverInformation->BaudRate, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));

         /* SafeRTOS requires RTOS-aware int handlers to be priority    */
         /* value 5 or greater                                          */
         MAP_IntPrioritySet(UartContext.IntBase, 6 << 5);

         MAP_IntEnable(UartContext.IntBase);
         MAP_UARTIntEnable(UartContext.Base, UART_INT_RX | UART_INT_RT);
         UartContext.Flags |= UART_CONTEXT_FLAG_RX_FLOW_ENABLED;

         /* Clear any data that is in the Buffer.                       */
         FlushRxFIFO(UartContext.Base);

         /* Bring the Bluetooth Device out of Reset.                    */
         MAP_GPIOPinWrite(HCI_RESET_BASE, HCI_RESET_PIN, HCI_RESET_PIN);

         /* Check to see if we need to delay after opening the COM Port.*/
         if(COMMDriverInformation->InitializationDelay)
            BTPS_Delay(COMMDriverInformation->InitializationDelay);

         /* Flag that the HCI Transport is open.                        */
         HCITransportOpen = 1;
      }
   }
   else
      ret_val = HCITR_ERROR_UNABLE_TO_OPEN_TRANSPORT;

   return(ret_val);
}