//***************************************************************************** // // Initializes the RemoTI UART driver interface to a remote network processor. // // \param ui32Base is the base address of the UART peripheral to be used. // Caller must call SysCtlPeripheralEnable for this UART peripheral prior to // calling this init funciton. // // This function will initialize the ring buffers used for transmit and receive // of data to and from the RNP. It also configures the UART peripheral for a // default setting. Enables receive interrupts. Transmit interrupts are // enabled when a transmit is in progress. Master interrupt enable must be // turned on by the application. // // \note Users of this driver are also responsible to assign // RemoTIUARTIntHandler() as the interrupt routine associated with the UART // peripheral of choice. // // \return None. // //***************************************************************************** void RemoTIUARTInit(uint32_t ui32Base) { // // Save the UART peripheral base address for later use. // g_ui32UARTBase = ui32Base; // // Initialize the TX and RX ring buffers for storage of our data. // RingBufInit(&g_rbRemoTIRxRingBuf, g_pui8RxBuf, REMOTI_UART_TX_BUF_SIZE); RingBufInit(&g_rbRemoTITxRingBuf, g_pui8TxBuf, REMOTI_UART_TX_BUF_SIZE); // // Configure UART clock settings. // UARTConfigSetExpClk(ui32Base, SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_ONE | UART_FLOWCONTROL_NONE)); // // Configure the UART FIFO. Enable the UART and Enable RX interrupts. // UARTFIFOLevelSet(ui32Base, UART_FIFO_TX1_8, UART_FIFO_RX1_8); UARTEnable(ui32Base); UARTFIFODisable(ui32Base); UARTIntEnable(ui32Base, UART_INT_RX); }
int zigbee_init(unsigned long baud) { int result; charZigbee.TxQueueLength = 10; charZigbee.RxQueueLength = 20; charZigbee.QueueWait = 0; charZigbee.PortBase = UART2_BASE; result = prepare_device(&charZigbee); if(result){ printf("Zigbee queue creation fail\n"); return result; } SysCtlPeripheralEnable(SYSCTL_PERIPH_UART2); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG); GPIOPinTypeUART(GPIO_PORTG_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTConfigSetExpClk(UART2_BASE, SysCtlClockGet(), baud, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); IntRegister(INT_UART2, zigbee_isr); UARTIntDisable(UART2_BASE, 0xFFFFFFFF); IntPrioritySet(INT_UART2,configKERNEL_INTERRUPT_PRIORITY); IntEnable(INT_UART2); UARTEnable(UART2_BASE); UARTFIFODisable(UART2_BASE); UARTIntEnable(UART2_BASE, UART_INT_TX | UART_INT_RX); return result; }
//***************************************************************************** // Initilizes hardware //***************************************************************************** void InitCortexHardware(void) { // // Enable FPU // FPUEnable(); FPULazyStackingEnable(); // Set clocking to 50 MHz, due to REV_A1 being a total ass. SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Configure UART0 for 115200-8n1 // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC); UARTStdioConfig(0, 115200, 16000000); UARTFIFODisable(UART0_BASE); UARTIntEnable(UART0_BASE, UART_INT_RX); UARTprintf("\n\nSystem initializing.\n"); // // Enable SysTick for periodic Interrupts // systick is used by command line process // SysTickEnable(); SysTickPeriodSet(SysCtlClockGet()/(SYSTICK_TIME/10)); SysTickIntEnable(); UARTprintf("- Systick timer enabled.\n"); // // Configure Heartbeat led // SysCtlPeripheralEnable(HEARTBEAT_CTRL_PORT); GPIOPinTypeGPIOOutput(HEARTBEAT_BASE_PORT, HEARTBEAT_PIN); GPIOPinWrite(HEARTBEAT_BASE_PORT, HEARTBEAT_PIN, 0xFF); UARTprintf("- GPIO enabled. \n"); // // Enable UART interrupts // IntMasterEnable(); IntEnable(INT_UART0); UARTprintf("- Interrupts enabled.\n"); }
void UART_Enable(tUART* uart) { // Enable Pin Port Pin_Init(uart -> tx_pin); Pin_Init(uart -> rx_pin); // Set GPIO Pin Mux GPIOPinTypeUART(pins[uart -> tx_pin].port.base, pins[uart -> tx_pin].offset); GPIOPinTypeUART(pins[uart -> rx_pin].port.base, pins[uart -> rx_pin].offset); GPIOPinConfigure(uart -> tx_pin_mux); GPIOPinConfigure(uart -> rx_pin_mux); // Enable UART UARTEnable(uart -> base); // Disable internal FIFOs UARTFIFODisable(uart -> base); }
void uart_init() { // reset local variables memset(&uart_vars,0,sizeof(uart_vars_t)); // 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. GPIO-A pin 0 and 1 IOCPinConfigPeriphOutput(GPIO_A_BASE, PIN_UART_TXD, IOC_MUX_OUT_SEL_UART0_TXD); GPIOPinTypeUARTOutput(GPIO_A_BASE, PIN_UART_TXD); IOCPinConfigPeriphInput(GPIO_A_BASE, PIN_UART_RXD, IOC_UARTRXD_UART0); GPIOPinTypeUARTInput(GPIO_A_BASE, 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, SysCtrlIOClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); // Enable UART hardware UARTEnable(UART0_BASE); // Disable FIFO as we only one 1byte buffer UARTFIFODisable(UART0_BASE); // Raise interrupt at end of tx (not by fifo) UARTTxIntModeSet(UART0_BASE, UART_TXINT_MODE_EOT); // Register isr in the nvic and enable isr at the nvic UARTIntRegister(UART0_BASE, uart_isr_private); // Enable the UART0 interrupt IntEnable(INT_UART0); }
void Uart::enable(uint32_t baudrate) { // Get GpioConfig structures GpioConfig& rx = rx_.getGpioConfig(); GpioConfig& tx = tx_.getGpioConfig(); // Store baudrate in configuration if (baudrate != 0) { config_.baudrate = baudrate; } // Enable peripheral except in deep sleep modes (e.g. LPM1, LPM2, LPM3) SysCtrlPeripheralEnable(config_.peripheral); SysCtrlPeripheralSleepEnable(config_.peripheral); SysCtrlPeripheralDeepSleepDisable(config_.peripheral); // Disable peripheral previous to configuring it UARTDisable(config_.peripheral); // Set IO clock as UART clock source UARTClockSourceSet(config_.base, config_.clock); // Configure the UART RX and TX pins IOCPinConfigPeriphInput(rx.port, rx.pin, rx.ioc); IOCPinConfigPeriphOutput(tx.port, tx.pin, tx.ioc); // Configure the UART GPIOs GPIOPinTypeUARTInput(rx.port, rx.pin); GPIOPinTypeUARTOutput(tx.port, tx.pin); // Configure the UART UARTConfigSetExpClk(config_.base, SysCtrlIOClockGet(), config_.baudrate, config_.mode); // Disable FIFO as we only use a one-byte buffer UARTFIFODisable(config_.base); // Raise an interrupt at the end of transmission UARTTxIntModeSet(config_.base, UART_TXINT_MODE_EOT); // Enable UART hardware UARTEnable(config_.base); }
void Uart::enable(uint32_t baudrate, uint32_t config, uint32_t mode) { // Store the UART baudrate, configuration and mode baudrate_ = baudrate; config_ = config; mode_ = mode; // Enable peripheral except in deep sleep modes (e.g. LPM1, LPM2, LPM3) SysCtrlPeripheralEnable(uart_.peripheral); SysCtrlPeripheralSleepEnable(uart_.peripheral); SysCtrlPeripheralDeepSleepDisable(uart_.peripheral); // Disable peripheral previous to configuring it UARTDisable(uart_.peripheral); // Set IO clock as UART clock source UARTClockSourceSet(uart_.base, uart_.clock); // Configure the UART RX and TX pins IOCPinConfigPeriphInput(rx_.getPort(), rx_.getPin(), rx_.getIoc()); IOCPinConfigPeriphOutput(tx_.getPort(), tx_.getPin(), tx_.getIoc()); // Configure the UART GPIOs GPIOPinTypeUARTInput(rx_.getPort(), rx_.getPin()); GPIOPinTypeUARTOutput(tx_.getPort(), tx_.getPin()); // Configure the UART UARTConfigSetExpClk(uart_.base, SysCtrlIOClockGet(), baudrate_, config_); // Disable FIFO as we only use a one-byte buffer UARTFIFODisable(uart_.base); // Raise an interrupt at the end of transmission UARTTxIntModeSet(uart_.base, mode_); // Enable UART hardware UARTEnable(uart_.base); }
void Terminal(void) { char data; if (OSSemCreate(0,&sUART) != ALLOC_EVENT_OK) { // Oh Oh // Não deveria entrar aqui !!! BlockTask(th6); }; if (OSMutexCreate(&mutexTx,6) != ALLOC_EVENT_OK) { // Oh Oh // Não deveria entrar aqui !!! BlockTask(th6); }; if (OSQueueCreate(64, &qUART) != ALLOC_EVENT_OK) { // Oh Oh // Não deveria entrar aqui !!! BlockTask(th6); }; // // Enable the peripherals used by this example. // The UART itself needs to be enabled, as well as the GPIO port // containing the pins that will be used. // SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // // Configure the GPIO pin muxing for the UART function. // This is only necessary if your part supports GPIO pin function muxing. // Study the data sheet to see which functions are allocated per pin. // TODO: change this to select the port/pin you are using // GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); // // Since GPIO A0 and A1 are used for the UART function, they must be // configured for use as a peripheral function (instead of GPIO). // TODO: change this to match the port/pin you are using // GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // 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(UART0_BASE, SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); UARTFIFODisable(UART0_BASE); // // Enable the UART interrupt. // ROM_IntEnable(INT_UART0); ROM_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT); // // Put a character to show start of example. This will display on the // terminal. // UARTPutString(UART0_BASE, "Iniciou!\n\r\n\r"); while(1) { if(!OSQueuePend(qUART, (INT8U*)&data, 0)) { if (data != 13) { UARTPutChar(UART0_BASE, data); }else { UARTPutString(UART0_BASE, "\n\r"); } } } }
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();*/ } }