void lcd_init() { ROM_SysCtlPeripheralEnable(LCD_PORTENABLE); ROM_GPIOPinTypeGPIOOutput(LCD_PORT, (LCD_RS | LCD_E | LCD_D4 | LCD_D5 | LCD_D6 | LCD_D7)); // Please refer to the HLCD_D44780 datasheet for how these initializations work! ROM_SysCtlDelay(ROM_SysCtlClockGet()/3/2); ROM_GPIOPinWrite(LCD_PORT, LCD_RS, 0x00); ROM_GPIOPinWrite(LCD_PORT, LCD_D4 | LCD_D5 | LCD_D6 | LCD_D7, 0x30); ROM_GPIOPinWrite(LCD_PORT, LCD_E, 0x02);ROM_SysCtlDelay((20e-6)*ROM_SysCtlClockGet()/3); ROM_GPIOPinWrite(LCD_PORT, LCD_E, 0x00); ROM_SysCtlDelay((50e-3)*ROM_SysCtlClockGet()/3); ROM_GPIOPinWrite(LCD_PORT, LCD_D4 | LCD_D5 | LCD_D6 | LCD_D7, 0x30); ROM_GPIOPinWrite(LCD_PORT, LCD_E, 0x02);ROM_SysCtlDelay((20e-6)*ROM_SysCtlClockGet()/3);ROM_GPIOPinWrite(LCD_PORT, LCD_E, 0x00); ROM_SysCtlDelay((50e-3)*ROM_SysCtlClockGet()/3); ROM_GPIOPinWrite(LCD_PORT, LCD_D4 | LCD_D5 | LCD_D6 | LCD_D7, 0x30); ROM_GPIOPinWrite(LCD_PORT, LCD_E, 0x02);ROM_SysCtlDelay((20e-6)*ROM_SysCtlClockGet()/3); ROM_GPIOPinWrite(LCD_PORT, LCD_E, 0x00); ROM_SysCtlDelay((10e-3)*ROM_SysCtlClockGet()/3); ROM_GPIOPinWrite(LCD_PORT, LCD_D4 | LCD_D5 | LCD_D6 | LCD_D7, 0x20); ROM_GPIOPinWrite(LCD_PORT, LCD_E, 0x02);ROM_SysCtlDelay((20e-6)*ROM_SysCtlClockGet()/3); ROM_GPIOPinWrite(LCD_PORT, LCD_E, 0x00); ROM_SysCtlDelay((10e-3)*ROM_SysCtlClockGet()/3); lcd_command(LCD_CLEARDISPLAY); // Clear the screen. lcd_command(0x06); // Cursor moves right. lcd_command(LCD_DISPLAYCONTROL | LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF); // Don't show any cursor, turn on LCD. }
/* * pollOptode() tells the Optode to "do_sample." Data is received * via the UART3 interrupt handler. */ void pollOptode() { //send "do_sample\n\r" to Optode UARTSendOptode(UART3_BASE, (char *)"do_sample\n\r"); //SEE OPTODE MANUAL PAGES 17-19 TO LEARN MORE ABOUT RESPONSE TIMES //AND ABOUT XON XOFF HANDSHAKES //give optode time to respond ROM_SysCtlDelay(ONESEC); ROM_SysCtlDelay(ONESEC); }
//Initialize as a master void TwoWire::begin(void) { if(i2cModule == NOT_ACTIVE) { i2cModule = BOOST_PACK_WIRE; } ROM_SysCtlPeripheralEnable(g_uli2cPeriph[i2cModule]); //Configure GPIO pins for I2C operation ROM_GPIOPinConfigure(g_uli2cConfig[i2cModule][0]); ROM_GPIOPinConfigure(g_uli2cConfig[i2cModule][1]); ROM_GPIOPinTypeI2C(g_uli2cBase[i2cModule], g_uli2cSDAPins[i2cModule]); ROM_GPIOPinTypeI2CSCL(g_uli2cBase[i2cModule], g_uli2cSCLPins[i2cModule]); ROM_I2CMasterInitExpClk(MASTER_BASE, F_CPU, speedMode);//Bus speed if(speedMode==I2C_SPEED_FASTMODE_PLUS)//Force 1Mhz { uint32_t ui32TPR = ((F_CPU + (2 * 10 * 1000000l) - 1) / (2 * 10 * 1000000l)) - 1; HWREG(MASTER_BASE + I2C_O_MTPR) = ui32TPR; } //force a stop condition if(!ROM_GPIOPinRead(g_uli2cBase[i2cModule], g_uli2cSCLPins[i2cModule])) forceStop(); //Handle any startup issues by pulsing SCL if(ROM_I2CMasterBusBusy(MASTER_BASE) || ROM_I2CMasterErr(MASTER_BASE) || !ROM_GPIOPinRead(g_uli2cBase[i2cModule], g_uli2cSCLPins[i2cModule])) { uint8_t doI = 0; ROM_GPIOPinTypeGPIOOutput(g_uli2cBase[i2cModule], g_uli2cSCLPins[i2cModule]); unsigned long mask = 0; do { for(unsigned long i = 0; i < 10 ; i++) { if(speedMode==I2C_SPEED_FASTMODE_PLUS) ROM_SysCtlDelay(F_CPU/1000000/3);//1000Hz=desired frequency, delay iteration=3 cycles else if(speedMode==I2C_SPEED_FASTMODE) ROM_SysCtlDelay(F_CPU/400000/3);//400Hz=desired frequency, delay iteration=3 cycles else ROM_SysCtlDelay(F_CPU/100000/3);//100Hz=desired frequency, delay iteration=3 cycles mask = (i%2) ? g_uli2cSCLPins[i2cModule] : 0; ROM_GPIOPinWrite(g_uli2cBase[i2cModule], g_uli2cSCLPins[i2cModule], mask); } doI++; } while(ROM_I2CMasterBusBusy(MASTER_BASE) && doI < 100); ROM_GPIOPinTypeI2CSCL(g_uli2cBase[i2cModule], g_uli2cSCLPins[i2cModule]); if(!ROM_GPIOPinRead(g_uli2cBase[i2cModule], g_uli2cSCLPins[i2cModule])) forceStop(); } }
void lcd_command(unsigned char command) { ROM_GPIOPinWrite(LCD_PORT, LCD_D4 | LCD_D5 | LCD_D6 | LCD_D7, (command & 0xf0) ); ROM_GPIOPinWrite(LCD_PORT, LCD_RS, 0x00); ROM_GPIOPinWrite(LCD_PORT, LCD_E, 0x02);ROM_SysCtlDelay((20e-6)*ROM_SysCtlClockGet()/3); ROM_GPIOPinWrite(LCD_PORT, LCD_E, 0x00); ROM_SysCtlDelay((100e-6)*ROM_SysCtlClockGet()/3); ROM_GPIOPinWrite(LCD_PORT, LCD_D4 | LCD_D5 | LCD_D6 | LCD_D7, (command & 0x0f) << 4 ); ROM_GPIOPinWrite(LCD_PORT, LCD_RS, 0x00); ROM_GPIOPinWrite(LCD_PORT, LCD_E, 0x02);ROM_SysCtlDelay((20e-6)*ROM_SysCtlClockGet()/3); ROM_GPIOPinWrite(LCD_PORT, LCD_E, 0x00); ROM_SysCtlDelay((5e-3)*ROM_SysCtlClockGet()/3); }
int main() { ROM_SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, LED_RED|LED_BLUE|LED_GREEN); for (;;) { // set the red LED pin high, others low ROM_GPIOPinWrite(GPIO_PORTF_BASE, LED_RED|LED_GREEN|LED_BLUE, LED_RED); ROM_SysCtlDelay(4000000); ROM_GPIOPinWrite(GPIO_PORTF_BASE, LED_RED|LED_GREEN|LED_BLUE, 0); ROM_SysCtlDelay(5000000); } }
void signalUnhandleError(void) { while (1) { ROM_GPIOPinWrite(LED_PORT_BASE, LED_ALL, LED_RED); ROM_SysCtlDelay(2000000); ROM_GPIOPinWrite(LED_PORT_BASE, LED_ALL, LED_GREEN); ROM_SysCtlDelay(2000000); ROM_GPIOPinWrite(LED_PORT_BASE, LED_ALL, LED_BLUE); ROM_SysCtlDelay(2000000); } }
void lcd_write(unsigned char inputData) { ROM_GPIOPinWrite(LCD_PORT, LCD_D4 | LCD_D5 | LCD_D6 | LCD_D7, (inputData & 0xf0) ); ROM_GPIOPinWrite(LCD_PORT, LCD_RS, 0x01); ROM_GPIOPinWrite(LCD_PORT, LCD_E, 0x02); ROM_SysCtlDelay((20e-6)*ROM_SysCtlClockGet()/3); ROM_GPIOPinWrite(LCD_PORT, LCD_E, 0x00); ROM_SysCtlDelay((100e-6)*ROM_SysCtlClockGet()/3); ROM_GPIOPinWrite(LCD_PORT, LCD_D4 | LCD_D5 | LCD_D6 | LCD_D7, (inputData & 0x0f) << 4 ); ROM_GPIOPinWrite(LCD_PORT, LCD_RS, 0x01); ROM_GPIOPinWrite(LCD_PORT, LCD_E, 0x02); ROM_SysCtlDelay((20e-6)*ROM_SysCtlClockGet()/3); ROM_GPIOPinWrite(LCD_PORT, LCD_E, 0x00); ROM_SysCtlDelay((5e-3)*ROM_SysCtlClockGet()/3); }
// Main ---------------------------------------------------------------------------------------------- int main(void){ // Enable lazy stacking ROM_FPULazyStackingEnable(); // Set the system clock to run at 40Mhz off PLL with external crystal as reference. ROM_SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); // Initialize the UART and write status. ConfigureUART(); UARTprintf("ISL29023 Example\n"); // Enable LEDs ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, LED_RED|LED_BLUE|LED_GREEN); // Enable I2C3 ConfigureI2C3(); // Create struct tISL29023 islSensHub; // Create print variables uint32_t printValue[2]; ISL29023ChangeSettings(ISL29023_COMMANDII_RANGE64k, ISL29023_COMMANDII_RES16, &islSensHub); while(1){ // Get ALS ISL29023GetALS(&islSensHub); FloatToPrint(islSensHub.alsVal, printValue); UARTprintf("ALS: %d.%03d |.| ",printValue[0],printValue[1]); // Get IR ISL29023GetIR(&islSensHub); FloatToPrint(islSensHub.irVal, printValue); UARTprintf("IR: %d.%03d\n",printValue[0],printValue[1]); // Blink LED ROM_GPIOPinWrite(GPIO_PORTF_BASE, LED_RED|LED_GREEN|LED_BLUE, LED_GREEN); ROM_SysCtlDelay(ROM_SysCtlClockGet()/3/10); // Delay for 100ms (1/10s) :: ClockGet()/3 = 1second ROM_GPIOPinWrite(GPIO_PORTF_BASE, LED_RED|LED_GREEN|LED_BLUE, 0); // Delay for second ROM_SysCtlDelay(ROM_SysCtlClockGet()/3); } }
int main0(void){ // "Embedded Systems: Real Time Interfacing to ARM Cortex M Microcontrollers", // ISBN: 978-1463590154, Jonathan Valvano, copyright (c) 2014, Volume 2, Program 11.2 UINT8 IsDHCP = 0; _NetCfgIpV4Args_t ipV4; SlSockAddrIn_t Addr; UINT16 AddrSize = 0; INT16 SockID = 0; UINT32 data; unsigned char len = sizeof(_NetCfgIpV4Args_t); initClk(); // PLL 50 MHz, ADC needs PPL active 15 ADC0_InitSWTriggerSeq3(7); // Ain7 is on PD0 16 sl_Start(0, 0, 0); // Initializing the CC3100 device 17 WlanConnect(); // connect to AP 18 sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&IsDHCP,&len, // 19 (unsigned char *)&ipV4); // 20 Addr.sin_family = SL_AF_INET; // 21 Addr.sin_port = sl_Htons((UINT16)PORT_NUM); // 22 Addr.sin_addr.s_addr = sl_Htonl((UINT32)IP_ADDR); // 23 AddrSize = sizeof(SlSockAddrIn_t); // 24 SockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0); // 25 while(1){ uBuf[0] = ATYPE; // analog data type 26 uBuf[1] = '='; // 27 data = ADC0_InSeq3(); // 0 to 4095, Ain7 is on PD0 28 Int2Str(data,(char*)&uBuf[2]); // 6 digit number 29 sl_SendTo(SockID, uBuf, BUF_SIZE, 0, // 30 (SlSockAddr_t *)&Addr, AddrSize); // 31 ROM_SysCtlDelay(ROM_SysCtlClockGet() / 25); // 40ms 32 } }
void system_Process_System_State(void) { switch (system_GetState()) { case SYSTEM_POWER_UP: break; case SYSTEM_INITIALIZE: break; case SYSTEM_CALIB_SENSOR: break; case SYSTEM_SAVE_CALIB_SENSOR: break; case SYSTEM_ESTIMATE_MOTOR_MODEL: ProcessSpeedControl(); break; case SYSTEM_SAVE_MOTOR_MODEL: break; case SYSTEM_WAIT_TO_RUN: break; case SYSTEM_RUN_SOLVE_MAZE: pid_Wallfollow_process(); ProcessSpeedControl(); break; case SYSTEM_RUN_IMAGE_PROCESSING: LED1_ON(); ProcessSpeedControl(); break; case SYSTEM_ERROR: speed_Enable_Hbridge(false); system_Enable_BoostCircuit(false); IntMasterDisable(); while (1) { LED1_ON(); LED2_ON(); LED3_ON(); ROM_SysCtlDelay(ROM_SysCtlClockGet() / 3); LED1_OFF(); LED2_OFF(); LED3_OFF(); ROM_SysCtlDelay(ROM_SysCtlClockGet() / 3); } // break; } }
/* * @brief: Read all 3 axes of HMC5883L * @param[in]: ptr output to individual axes * @param[out]: none */ void hmc5883l_ReadXYZ(int16_t *x, int16_t *y, int16_t *z){ uint8_t b[6]; i2c_WriteByte(I2C_ID_HMC5883L, HMC5883L_RA_MODE, HMC5883L_MODE_SINGLE); ROM_SysCtlDelay(6*(ROM_SysCtlClockGet()/3000)); i2c_ReadBuf(I2C_ID_HMC5883L, HMC5883L_DATA, 6, b); *x = ((int16_t)(((uint16_t)b[0]<<8) | (uint16_t)b[1]))*xyz_comp_num[0]/xyz_comp_den[0]; *y = ((int16_t)(((uint16_t)b[2]<<8) | (uint16_t)b[3]))*xyz_comp_num[1]/xyz_comp_den[1]; *z = ((int16_t)(((uint16_t)b[4]<<8) | (uint16_t)b[5]))*xyz_comp_num[2]/xyz_comp_den[2]; }
void delay_ms(uint32_t ui32Ms) { // 1 clock cycle = 1 / SysCtlClockGet() second // 1 SysCtlDelay = 3 clock cycle = 3 / SysCtlClockGet() second // 1 second = SysCtlClockGet() / 3 // 0.001 second = 1 ms = SysCtlClockGet() / 3 / 1000 ROM_SysCtlDelay(ui32Ms * (ROM_SysCtlClockGet() / 3 / 1000)); }
int I2CRead(unsigned char slave, unsigned char address, unsigned int len, unsigned char * readdata, unsigned int readcnt) { unsigned long ulToRead; // Start with a dummy write to get the address set in the EEPROM. ROM_I2CMasterSlaveAddrSet(I2C_MASTER_BASE, slave, false); // Place the address to be written in the data register. ROM_I2CMasterDataPut(I2C_MASTER_BASE, address); // Perform a single send, writing the address as the only byte. ROM_I2CMasterControl(I2C_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_START); // Wait until the current byte has been transferred. if(!WaitI2CFinished()) { return(false); } // Put the I2C master into receive mode. ROM_I2CMasterSlaveAddrSet(I2C_MASTER_BASE, slave, true); // Start the receive. ROM_I2CMasterControl(I2C_MASTER_BASE, ((readcnt > 1) ? I2C_MASTER_CMD_BURST_RECEIVE_START : I2C_MASTER_CMD_SINGLE_RECEIVE)); // Receive the required number of bytes. ulToRead = readcnt; while(ulToRead) { // Wait until the current byte has been read. while(ROM_I2CMasterIntStatus(I2C_MASTER_BASE, false) == 0){} // Fixes I2C transactions.. ? ROM_SysCtlDelay(1000); // Clear pending interrupt notification. ROM_I2CMasterIntClear(I2C_MASTER_BASE); // Read the received character. *readdata++ = ROM_I2CMasterDataGet(I2C_MASTER_BASE); ulToRead--; // Set up for the next byte if any more remain. if(ulToRead) { ROM_I2CMasterControl(I2C_MASTER_BASE, ((ulToRead == 1) ? I2C_MASTER_CMD_BURST_RECEIVE_FINISH : I2C_MASTER_CMD_BURST_RECEIVE_CONT)); } } return(readcnt - ulToRead); }
//***************************************************************************** // // Delay for 5 us. // //***************************************************************************** void delayFiveMicroseconds(uint32_t g_ui32SysClock) { // // Delay for 5 us. The value of the number provided to SysCtlDelay // is the number of loops (3 assembly instructions each) to iterate through. // Interrupts are disabled temporarily to ensure the pulse length is 5us. // ROM_IntMasterDisable(); ROM_SysCtlDelay(g_ui32SysClock / 3 / 200000); ROM_IntMasterEnable(); }
static inline void shift_bit(shiftbrite* sb, uint16_t val) { if( val ) { ROM_GPIOPinWrite( sb->data_pin.port, sb->data_pin.pin, sb->data_pin.pin ); } else { ROM_GPIOPinWrite( sb->data_pin.port, sb->data_pin.pin, ~sb->data_pin.pin ); } ROM_SysCtlDelay(5); pulse(sb->clock_pin); }
void system_Process_System_State(void) { switch (system_GetState()) { case SYSTEM_POWER_UP: break; case SYSTEM_INITIALIZE: break; case SYSTEM_ESTIMATE_MOTOR_MODEL: break; case SYSTEM_SAVE_MOTOR_MODEL: break; case SYSTEM_WAIT_TO_RUN: break; case SYSTEM_RUN_BALANCE: loop(); break; case SYSTEM_RUN_IMAGE_PROCESSING: LED1_ON(); break; case SYSTEM_ERROR: speed_Enable_Hbridge(false); system_Enable_BoostCircuit(false); IntMasterDisable(); while (1) { LED1_ON(); LED2_ON(); LED3_ON(); ROM_SysCtlDelay(ROM_SysCtlClockGet() / 3); LED1_OFF(); LED2_OFF(); LED3_OFF(); ROM_SysCtlDelay(ROM_SysCtlClockGet() / 3); } } }
//Initialize as a master void TwoWire::begin(void) { pinMode(RED_LED, OUTPUT); if(i2cModule == NOT_ACTIVE) { i2cModule = BOOST_PACK_WIRE; } ROM_SysCtlPeripheralEnable(g_uli2cPeriph[i2cModule]); //Configure GPIO pins for I2C operation ROM_GPIOPinConfigure(g_uli2cConfig[i2cModule][0]); ROM_GPIOPinConfigure(g_uli2cConfig[i2cModule][1]); ROM_GPIOPinTypeI2C(g_uli2cBase[i2cModule], g_uli2cSDAPins[i2cModule]); ROM_GPIOPinTypeI2CSCL(g_uli2cBase[i2cModule], g_uli2cSCLPins[i2cModule]); ROM_I2CMasterInitExpClk(MASTER_BASE, F_CPU, false);//max bus speed=400kHz for gyroscope //force a stop condition if(!ROM_GPIOPinRead(g_uli2cBase[i2cModule], g_uli2cSCLPins[i2cModule])) forceStop(); //Handle any startup issues by pulsing SCL if(ROM_I2CMasterBusBusy(MASTER_BASE) || ROM_I2CMasterErr(MASTER_BASE) || !ROM_GPIOPinRead(g_uli2cBase[i2cModule], g_uli2cSCLPins[i2cModule])){ uint8_t doI = 0; ROM_GPIOPinTypeGPIOOutput(g_uli2cBase[i2cModule], g_uli2cSCLPins[i2cModule]); unsigned long mask = 0; do{ for(unsigned long i = 0; i < 10 ; i++) { ROM_SysCtlDelay(F_CPU/100000/3);//100Hz=desired frequency, delay iteration=3 cycles mask = (i%2) ? g_uli2cSCLPins[i2cModule] : 0; ROM_GPIOPinWrite(g_uli2cBase[i2cModule], g_uli2cSCLPins[i2cModule], mask); } doI++; }while(ROM_I2CMasterBusBusy(MASTER_BASE) && doI < 100); ROM_GPIOPinTypeI2CSCL(g_uli2cBase[i2cModule], g_uli2cSCLPins[i2cModule]); if(!ROM_GPIOPinRead(g_uli2cBase[i2cModule], g_uli2cSCLPins[i2cModule])) forceStop(); } }
//***************************************************************************** // // SHT21 Application error handler. // //***************************************************************************** void SHT21AppErrorHandler(char *pcFilename, uint_fast32_t ui32Line) { uint32_t ui32LEDState; // // Set terminal color to red and print error status and locations. // UARTprintf("\033[31;1m"); UARTprintf("Error: %d, File: %s, Line: %d\n" "See I2C status definitions in utils\\i2cm_drv.h\n", g_vui8ErrorFlag, pcFilename, ui32Line); // // Return terminal color to normal. // UARTprintf("\033[0m"); // // Read the initial LED state and clear the CLP_D2 LED. // LEDRead(&ui32LEDState); ui32LEDState &= ~CLP_D2; // // Go to sleep wait for interventions. A more robust application could // attempt corrective actions here. // while(1) { // // Toggle LED D1 to indicate the error. // ui32LEDState ^= CLP_D1; LEDWrite(CLP_D1 | CLP_D2, ui32LEDState); // // Do Nothing. // ROM_SysCtlDelay(g_ui32SysClock / (10 * 3)); } }
void BattSenseISR(void) { uint32_t ADCResult, BatteryVoltage; ROM_ADCIntClear(ADC0_BASE, 3); ROM_ADCSequenceDataGet(ADC0_BASE, 3, (uint32_t *)&ADCResult); BatteryVoltage = ((float)ADCResult) / 4096 * 3.3 * (220 + 680) / 220; #warning CHECK BATT SENSE #if 0 if (BatteryVoltage < (float)11.0) { HBridgeEnable(); throttleStop(); while(1) { LED3_TOGGLE; ROM_SysCtlDelay(ROM_SysCtlClockGet()/3); } } #endif }
void LED_Loop() { LED_B_ON; ROM_SysCtlDelay((ROM_SysCtlClockGet())/3/2); LED_R_ON; ROM_SysCtlDelay((ROM_SysCtlClockGet())/3/2); LED_G_ON; ROM_SysCtlDelay((ROM_SysCtlClockGet())/3/2); LED_B_OFF; ROM_SysCtlDelay((ROM_SysCtlClockGet())/3/2); LED_R_OFF; ROM_SysCtlDelay((ROM_SysCtlClockGet())/3/2); LED_G_OFF; ROM_SysCtlDelay((ROM_SysCtlClockGet())/3/2); }
static tBoolean WaitI2CFinished(void) { // Wait until the current byte has been transferred. while(ROM_I2CMasterIntStatus(I2C_MASTER_BASE, false) == 0){} if(ROM_I2CMasterErr(I2C_MASTER_BASE) != I2C_MASTER_ERR_NONE) { ROM_I2CMasterIntClear(I2C_MASTER_BASE); return(false); } // Clear any interrupts set. while(ROM_I2CMasterIntStatus(I2C_MASTER_BASE, false)) { ROM_I2CMasterIntClear(I2C_MASTER_BASE); } // Fixes I2C transactions.. ? ROM_SysCtlDelay(10000); return(true); }
/** * Initialize the lcd */ void lcd_init() { enable_lcd(); setPin( LCD_PORT, LCD_RST, 0 ); setPin( LCD_PORT, LCD_RST, 1 ); ROM_SysCtlDelay( 500 ); spi_command( SLEEPOUT ); spi_command( BSTRON ); spi_command( COLMOD ); spi_command( MADCTL ); spi_data( 0xC0 ); spi_command( SETCON ); spi_data( 0x40 ); spi_command( DISPON ); setPin( LCD_PORT, LCD_CS, 0 ); lcd_clear(); }
void init_usart(void) { /* Enable UART0 clock */ SYSCTL_RCGC1_R |= SYSCTL_RCGC1_UART0; /* Enable GPIOA clock */ SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOA; ROM_SysCtlDelay(1); /* Alternate functions UART */ GPIO_PORTA_PCTL_R |= (1 << 4) | (1 << 0); /* Set to output */ GPIO_PORTA_DIR_R &= ~(GPIO_PIN_1 | GPIO_PIN_0); /* Set PA0 and PA1 to alternate function */ GPIO_PORTA_AFSEL_R |= GPIO_PIN_1 | GPIO_PIN_0; /* Digital pins */ GPIO_PORTA_DEN_R |= GPIO_PIN_1 | GPIO_PIN_0; /* Disable UART */ UART0_CTL_R &= ~(UART_CTL_UARTEN); usart_baud(115200); /* Enable FIFO, 8-bit words */ UART0_LCRH_R = UART_LCRH_FEN | UART_LCRH_WLEN_8; /* Use system clock */ UART0_CC_R = UART_CC_CS_SYSCLK; /* Enable UART */ UART0_CTL_R |= UART_CTL_UARTEN | UART_CTL_RXE | UART_CTL_TXE; usart_ready = 1; }
//***************************************************************************** // // This is the main application entry function. // //***************************************************************************** int main(void) { uint32_t ui32TxCount; uint32_t ui32RxCount; //uint32_t ui32Loop; // // 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. // ROM_FPULazyStackingEnable(); // // Set the clocking to run from the PLL at 50MHz // #if 1 ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Configure the required pins for USB operation. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); ROM_GPIOPinTypeUSBAnalog(GPIO_PORTD_BASE, GPIO_PIN_5 | GPIO_PIN_4); //ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / 100); /* This code taken from: http://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/t/311237.aspx */ #else #include "hw_nvic.h" FlashErase(0x00000000); ROM_IntMasterDisable(); ROM_SysTickIntDisable(); ROM_SysTickDisable(); uint32_t ui32SysClock; ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); ui32SysClock = ROM_SysCtlClockGet(); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); ROM_GPIOPinTypeUSBAnalog(GPIO_PORTD_BASE, GPIO_PIN_4 | GPIO_PIN_5); ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / 100); HWREG(NVIC_DIS0) = 0xffffffff; HWREG(NVIC_DIS1) = 0xffffffff; HWREG(NVIC_DIS2) = 0xffffffff; HWREG(NVIC_DIS3) = 0xffffffff; HWREG(NVIC_DIS4) = 0xffffffff; int ui32Addr; for(ui32Addr = NVIC_PRI0; ui32Addr <= NVIC_PRI34; ui32Addr+=4) { HWREG(ui32Addr) = 0; } HWREG(NVIC_SYS_PRI1) = 0; HWREG(NVIC_SYS_PRI2) = 0; HWREG(NVIC_SYS_PRI3) = 0; ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0); ROM_SysCtlPeripheralReset(SYSCTL_PERIPH_USB0); ROM_SysCtlUSBPLLEnable(); ROM_SysCtlDelay(ui32SysClock*2 / 3); ROM_IntMasterEnable(); ROM_UpdateUSB(0); while(1) { } #endif #define BOOTLOADER_TEST 0 #if BOOTLOADER_TEST #include "hw_nvic.h" //ROM_UpdateUART(); // May need to do the following here: // 0. See if this will cause bootloader to start //ROM_FlashErase(0); //ROM_UpdateUSB(0); #define SYSTICKS_PER_SECOND 100 uint32_t ui32SysClock = ROM_SysCtlClockGet(); ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND); ROM_SysTickIntEnable(); ROM_SysTickEnable(); //USBDCDTerm(0); // Disable all interrupts ROM_IntMasterDisable(); ROM_SysTickIntDisable(); ROM_SysTickDisable(); HWREG(NVIC_DIS0) = 0xffffffff; HWREG(NVIC_DIS1) = 0xffffffff; HWREG(NVIC_DIS2) = 0xffffffff; HWREG(NVIC_DIS3) = 0xffffffff; HWREG(NVIC_DIS4) = 0xffffffff; int ui32Addr; for(ui32Addr = NVIC_PRI0; ui32Addr <= NVIC_PRI34; ui32Addr+=4) { HWREG(ui32Addr) = 0; } HWREG(NVIC_SYS_PRI1) = 0; HWREG(NVIC_SYS_PRI2) = 0; HWREG(NVIC_SYS_PRI3) = 0; // 1. Enable USB PLL //ROM_SysCtlUSBPLLEnable(); // 2. Enable USB controller ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0); ROM_SysCtlPeripheralReset(SYSCTL_PERIPH_USB0); //USBClockEnable(USB0_BASE, 8, USB_CLOCK_INTERNAL); //HWREG(USB0_BASE + USB_O_CC) = (8 - 1) | USB_CLOCK_INTERNAL; ROM_SysCtlUSBPLLEnable(); // 3. Enable USB D+ D- pins // 4. Activate USB DFU ROM_SysCtlDelay(ui32SysClock * 2 / 3); ROM_IntMasterEnable(); // Re-enable interrupts at NVIC level ROM_UpdateUSB(0); // 5. Should never get here since update is in progress #endif // BOOTLOADER_TEST // // Enable the GPIO port that is used for the on-board LED. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); // gjs Our board uses GPIOB for LEDs // gjs original ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // // Enable the GPIO pins for the LED (PF2 & PF3). // ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_0|GPIO_PIN_1); // gjs original ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3|GPIO_PIN_2); // // Not configured initially. // g_bUSBConfigured = false; // // Enable the UART that we will be redirecting. // ROM_SysCtlPeripheralEnable(USB_UART_PERIPH); // // Enable and configure the UART RX and TX pins // ROM_SysCtlPeripheralEnable(TX_GPIO_PERIPH); ROM_SysCtlPeripheralEnable(RX_GPIO_PERIPH); ROM_GPIOPinTypeUART(TX_GPIO_BASE, TX_GPIO_PIN); ROM_GPIOPinTypeUART(RX_GPIO_BASE, RX_GPIO_PIN); // // TODO: Add code to configure handshake GPIOs if required. // // // Set the default UART configuration. // ROM_UARTConfigSetExpClk(USB_UART_BASE, ROM_SysCtlClockGet(), DEFAULT_BIT_RATE, DEFAULT_UART_CONFIG); ROM_UARTFIFOLevelSet(USB_UART_BASE, UART_FIFO_TX4_8, UART_FIFO_RX4_8); // // Configure and enable UART interrupts. // ROM_UARTIntClear(USB_UART_BASE, ROM_UARTIntStatus(USB_UART_BASE, false)); ROM_UARTIntEnable(USB_UART_BASE, (UART_INT_OE | UART_INT_BE | UART_INT_PE | UART_INT_FE | UART_INT_RT | UART_INT_TX | UART_INT_RX)); // // Enable the system tick. // #if 0 ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND); ROM_SysTickIntEnable(); ROM_SysTickEnable(); #endif // // Initialize the transmit and receive buffers. // USBBufferInit(&g_sTxBuffer); USBBufferInit(&g_sRxBuffer); // // Set the USB stack mode to Device mode with VBUS monitoring. // USBStackModeSet(0, eUSBModeDevice, 0); // // Pass our device information to the USB library and place the device // on the bus. // USBDCDCInit(0, &g_sCDCDevice); // // Clear our local byte counters. // ui32RxCount = 0; ui32TxCount = 0; // // Enable interrupts now that the application is ready to start. // ROM_IntEnable(USB_UART_INT); // Enable FreeRTOS mainA(); // FreeRTOS. Will not return #if 0 // // Main application loop. // while(1) { // // Have we been asked to update the status display? // if(g_ui32Flags & COMMAND_STATUS_UPDATE) { // // Clear the command flag // ROM_IntMasterDisable(); g_ui32Flags &= ~COMMAND_STATUS_UPDATE; ROM_IntMasterEnable(); } // // Has there been any transmit traffic since we last checked? // if(ui32TxCount != g_ui32UARTTxCount) { // // Turn on the Green LED. // // gjs ROM_UARTCharPutNonBlocking(USB_UART_BASE, 'b'); #if 1 if (ui32TxCount & 1) { GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0, GPIO_PIN_0); } else { GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0, 0); } #else if (1 || g_ui32UARTTxCount & 0x01) { GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, GPIO_PIN_3); } else { //GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, 0); } // // Delay for a bit. // for(uint32_t ui32Loop = 0; ui32Loop < 150000; ui32Loop++) { } // // Turn off the Green LED. // GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, 0); #endif // // Take a snapshot of the latest transmit count. // ui32TxCount = g_ui32UARTTxCount; } // // Has there been any receive traffic since we last checked? // if(ui32RxCount != g_ui32UARTRxCount) { // // Turn on the Blue LED. // #if 1 if (ui32RxCount & 1) { GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_1, GPIO_PIN_1); } else { GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_1, 0); } #else GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2); // // Delay for a bit. // for(uint32_t ui32Loop = 0; ui32Loop < 150000; ui32Loop++) { } // // Turn off the Blue LED. // GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0); #endif // // Take a snapshot of the latest receive count. // ui32RxCount = g_ui32UARTRxCount; } } #endif }
//***************************************************************************** // // Main 'C' Language entry point. // //***************************************************************************** int main(void) { float fTemperature, fPressure, fAltitude; int32_t i32IntegerPart; int32_t i32FractionPart; // // Setup the system clock to run at 40 MHz from PLL with crystal reference // ROM_SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); // // Initialize the UART. // ConfigureUART(); // // Print the welcome message to the terminal. // UARTprintf("\033[2JBMP180 Example\n"); // // Set the color to a white approximation. // g_pui32Colors[RED] = 0x8000; g_pui32Colors[BLUE] = 0x8000; g_pui32Colors[GREEN] = 0x8000; // // Initialize RGB driver. Use a default intensity and blink rate. // RGBInit(0); RGBColorSet(g_pui32Colors); RGBIntensitySet(0.5f); RGBEnable(); // // The I2C3 peripheral must be enabled before use. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C3); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); // // Configure the pin muxing for I2C3 functions on port D0 and D1. // This step is not necessary if your part does not support pin muxing. // ROM_GPIOPinConfigure(GPIO_PD0_I2C3SCL); ROM_GPIOPinConfigure(GPIO_PD1_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. // GPIOPinTypeI2CSCL(GPIO_PORTD_BASE, GPIO_PIN_0); ROM_GPIOPinTypeI2C(GPIO_PORTD_BASE, GPIO_PIN_1); // // Initialize the GPIO for the LED. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1); ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 0x00); // // Enable interrupts to the processor. // ROM_IntMasterEnable(); // // Initialize the I2C3 peripheral. // I2CMInit(&g_sI2CInst, I2C3_BASE, INT_I2C3, 0xff, 0xff, ROM_SysCtlClockGet()); // // 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. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / (10 * 3)); ROM_SysTickIntEnable(); ROM_SysTickEnable(); // // After all the init and config we start blink the LED // RGBBlinkRateSet(1.0f); // // 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. // 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. // 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. // UARTprintf("Altitude %3d.%03d", i32IntegerPart, i32FractionPart); // // Print new line. // UARTprintf("\n"); // // Delay to keep printing speed reasonable. About 100 milliseconds. // ROM_SysCtlDelay(ROM_SysCtlClockGet() / (10 * 3)); }//while end }
//***************************************************************************** // // The program main function. It performs initialization, then runs a loop to // process USB activities and operate the user interface. // //***************************************************************************** int main(void) { uint32_t ui32DriveTimeout; // // 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. // ROM_FPULazyStackingEnable(); // // Set the system clock to run at 50MHz from the PLL. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Configure the required pins for USB operation. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG); ROM_GPIOPinConfigure(GPIO_PG4_USB0EPEN); ROM_GPIOPinTypeUSBDigital(GPIO_PORTG_BASE, GPIO_PIN_4); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL); ROM_GPIOPinTypeUSBAnalog(GPIO_PORTL_BASE, GPIO_PIN_6 | GPIO_PIN_7); ROM_GPIOPinTypeUSBAnalog(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // Configure SysTick for a 100Hz interrupt. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / TICKS_PER_SECOND); ROM_SysTickEnable(); ROM_SysTickIntEnable(); // // Enable the uDMA controller and set up the control table base. // The uDMA controller is used by the USB library. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); ROM_uDMAEnable(); ROM_uDMAControlBaseSet(g_psDMAControlTable); // // Enable Interrupts // ROM_IntMasterEnable(); // // Initialize the display driver. // CFAL96x64x16Init(); // // Initialize the buttons driver. // ButtonsInit(); // // Initialize two offscreen displays and assign the palette. These // buffers are used by the slide menu widget to allow animation effects. // GrOffScreen4BPPInit(&g_sOffscreenDisplayA, g_pui8OffscreenBufA, 96, 64); GrOffScreen4BPPPaletteSet(&g_sOffscreenDisplayA, g_pui32Palette, 0, NUM_PALETTE_ENTRIES); GrOffScreen4BPPInit(&g_sOffscreenDisplayB, g_pui8OffscreenBufB, 96, 64); GrOffScreen4BPPPaletteSet(&g_sOffscreenDisplayB, g_pui32Palette, 0, NUM_PALETTE_ENTRIES); // // Show an initial status screen // g_pcStatusLines[0] = "Waiting"; g_pcStatusLines[1] = "for device"; ShowStatusScreen(g_pcStatusLines, 2); // // Add the compile-time defined widgets to the widget tree. // WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sFileMenuWidget); // // Initially wait for device connection. // g_eState = STATE_NO_DEVICE; // // Initialize the USB stack for host mode. // USBStackModeSet(0, eUSBModeHost, 0); // // Register the host class drivers. // USBHCDRegisterDrivers(0, g_ppHostClassDrivers, g_ui32NumHostClassDrivers); // // Open an instance of the mass storage class driver. // g_psMSCInstance = USBHMSCDriveOpen(0, MSCCallback); // // Initialize the drive timeout. // ui32DriveTimeout = USBMSC_DRIVE_RETRY; // // Initialize the power configuration. This sets the power enable signal // to be active high and does not enable the power fault. // USBHCDPowerConfigInit(0, USBHCD_VBUS_AUTO_HIGH | USBHCD_VBUS_FILTER); // // Initialize the USB controller for host operation. // USBHCDInit(0, g_pui8HCDPool, HCD_MEMORY_SIZE); // // Initialize the file system. // FileInit(); // // Enter an infinite loop to run the user interface and process USB // events. // while(1) { uint32_t ui32LastTickCount = 0; // // Call the USB stack to keep it running. // USBHCDMain(); // // Process any messages in the widget message queue. This keeps the // display UI running. // WidgetMessageQueueProcess(); // // Take action based on the application state. // switch(g_eState) { // // A device has enumerated. // case STATE_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. // ROM_SysCtlDelay(ROM_SysCtlClockGet()/(3)); // // Decrement the retry count. // ui32DriveTimeout--; // // If the timeout is hit then go to the // STATE_TIMEOUT_DEVICE state. // if(ui32DriveTimeout == 0) { g_eState = STATE_TIMEOUT_DEVICE; } break; } // // Getting here means the device is ready. // Reset the CWD to the root directory. // g_pcCwdBuf[0] = '/'; g_pcCwdBuf[1] = 0; // // Set the initial directory level to the root // g_ui32Level = 0; // // We need to reset the indexes of the root menu to 0, so that // it will start at the top of the file list, and reset the // slide menu widget to start with the root menu. // g_psFileMenus[g_ui32Level].ui32CenterIndex = 0; g_psFileMenus[g_ui32Level].ui32FocusIndex = 0; SlideMenuMenuSet(&g_sFileMenuWidget, &g_psFileMenus[g_ui32Level]); // // Initiate a directory change to the root. This will // populate a menu structure representing the root directory. // if(ProcessDirChange("/", g_ui32Level)) { // // If there were no errors reported, we are ready for // MSC operation. // g_eState = STATE_DEVICE_READY; // // Set the Device Present flag. // g_ui32Flags = FLAGS_DEVICE_PRESENT; // // Request a repaint so the file menu will be shown // WidgetPaint(WIDGET_ROOT); } break; } // // If there is no device then just wait for one. // case STATE_NO_DEVICE: { if(g_ui32Flags == FLAGS_DEVICE_PRESENT) { // // Show waiting message on screen // g_pcStatusLines[0] = "Waiting"; g_pcStatusLines[1] = "for device"; ShowStatusScreen(g_pcStatusLines, 2); // // Clear the Device Present flag. // g_ui32Flags &= ~FLAGS_DEVICE_PRESENT; } break; } // // An unknown device was connected. // case STATE_UNKNOWN_DEVICE: { // // If this is a new device then change the status. // if((g_ui32Flags & FLAGS_DEVICE_PRESENT) == 0) { // // Clear the screen and indicate that an unknown device // is present. // g_pcStatusLines[0] = "Unknown"; g_pcStatusLines[1] = "device"; ShowStatusScreen(g_pcStatusLines, 2); } // // Set the Device Present flag. // g_ui32Flags = FLAGS_DEVICE_PRESENT; break; } // // The connected mass storage device is not reporting ready. // case STATE_TIMEOUT_DEVICE: { // // If this is the first time in this state then print a // message. // if((g_ui32Flags & FLAGS_DEVICE_PRESENT) == 0) { // // // Clear the screen and indicate that an unknown device // is present. // g_pcStatusLines[0] = "Device"; g_pcStatusLines[1] = "Timeout"; ShowStatusScreen(g_pcStatusLines, 2); } // // Set the Device Present flag. // g_ui32Flags = FLAGS_DEVICE_PRESENT; break; } // // The device is ready and in use. // case STATE_DEVICE_READY: { // // Process occurrence of timer tick. Check for user input // once each tick. // if(g_ui32SysTickCount != ui32LastTickCount) { uint8_t ui8ButtonState; uint8_t ui8ButtonChanged; ui32LastTickCount = g_ui32SysTickCount; // // Get the current debounced state of the buttons. // ui8ButtonState = ButtonsPoll(&ui8ButtonChanged, 0); // // If select button or right button is pressed, then we // are trying to descend into another directory // if(BUTTON_PRESSED(SELECT_BUTTON, ui8ButtonState, ui8ButtonChanged) || BUTTON_PRESSED(RIGHT_BUTTON, ui8ButtonState, ui8ButtonChanged)) { uint32_t ui32NewLevel; uint32_t ui32ItemIdx; char *pcItemName; // // Get a pointer to the current menu for this CWD. // tSlideMenu *psMenu = &g_psFileMenus[g_ui32Level]; // // Get the highlighted index in the current file list. // This is the currently highlighted file or dir // on the display. Then get the name of the file at // this index. // ui32ItemIdx = SlideMenuFocusItemGet(psMenu); pcItemName = psMenu->psSlideMenuItems[ui32ItemIdx].pcText; // // Make sure we are not yet past the maximum tree // depth. // if(g_ui32Level < MAX_SUBDIR_DEPTH) { // // Potential new level is one greater than the // current level. // ui32NewLevel = g_ui32Level + 1; // // Process the directory change to the new // directory. This function will populate a menu // structure with the files and subdirs in the new // directory. // if(ProcessDirChange(pcItemName, ui32NewLevel)) { // // If the change was successful, then update // the level. // g_ui32Level = ui32NewLevel; // // Now that all the prep is done, send the // KEY_RIGHT message to the widget and it will // "slide" from the previous file list to the // new file list of the CWD. // SendWidgetKeyMessage(WIDGET_MSG_KEY_RIGHT); } } } // // If the UP button is pressed, just pass it to the widget // which will handle scrolling the list of files. // if(BUTTON_PRESSED(UP_BUTTON, ui8ButtonState, ui8ButtonChanged)) { SendWidgetKeyMessage(WIDGET_MSG_KEY_UP); } // // If the DOWN button is pressed, just pass it to the widget // which will handle scrolling the list of files. // if(BUTTON_PRESSED(DOWN_BUTTON, ui8ButtonState, ui8ButtonChanged)) { SendWidgetKeyMessage(WIDGET_MSG_KEY_DOWN); } // // If the LEFT button is pressed, then we are attempting // to go up a level in the file system. // if(BUTTON_PRESSED(LEFT_BUTTON, ui8ButtonState, ui8ButtonChanged)) { uint32_t ui32NewLevel; // // Make sure we are not already at the top of the // directory tree (at root). // if(g_ui32Level) { // // Potential new level is one less than the // current level. // ui32NewLevel = g_ui32Level - 1; // // Process the directory change to the new // directory. This function will populate a menu // structure with the files and subdirs in the new // directory. // if(ProcessDirChange("..", ui32NewLevel)) { // // If the change was successful, then update // the level. // g_ui32Level = ui32NewLevel; // // Now that all the prep is done, send the // KEY_LEFT message to the widget and it will // "slide" from the previous file list to the // new file list of the CWD. // SendWidgetKeyMessage(WIDGET_MSG_KEY_LEFT); } } } } break; } // // Something has caused a power fault. // case STATE_POWER_FAULT: { // // Clear the screen and show a power fault indication. // g_pcStatusLines[0] = "Power"; g_pcStatusLines[1] = "fault"; ShowStatusScreen(g_pcStatusLines, 2); break; } default: { break; } } } }
static void wait(void) { ROM_SysCtlDelay(10000000); }
//***************************************************************************** // // A simple application demonstrating use of the boot loader, // //***************************************************************************** int main(void) { tRectangle sRect; tContext sContext; unsigned long ulSysClock; // // 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. // ROM_FPULazyStackingEnable(); // // Set the system clock to run at 50MHz from the PLL // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); ulSysClock = ROM_SysCtlClockGet(); // // Initialize the peripherals that each of the boot loader flavors // supports. Since this example is intended for use with any of the // boot loaders and we don't know which is actually in use, we cover all // bases and initialize for serial, Ethernet and USB use here. // SetupForUART(); SetupForUSB(); // // Initialize the buttons driver. // ButtonsInit(); // // Initialize the display driver. // CFAL96x64x16Init(); // // Initialize the graphics context. // GrContextInit(&sContext, &g_sCFAL96x64x16); // // Fill the top part of the screen with blue to create the banner. // sRect.sXMin = 0; sRect.sYMin = 0; sRect.sXMax = GrContextDpyWidthGet(&sContext) - 1; sRect.sYMax = 9; GrContextForegroundSet(&sContext, ClrDarkBlue); GrRectFill(&sContext, &sRect); // // Change foreground for white text. // GrContextForegroundSet(&sContext, ClrWhite); // // Put the application name in the middle of the banner. // GrContextFontSet(&sContext, g_pFontFixed6x8); GrStringDrawCentered(&sContext, "boot-demo2", -1, GrContextDpyWidthGet(&sContext) / 2, 4, 0); GrStringDrawCentered(&sContext, "Press select", -1, GrContextDpyWidthGet(&sContext) / 2, 20, false); GrStringDrawCentered(&sContext, "button to", -1, GrContextDpyWidthGet(&sContext) / 2, 30, false); GrStringDrawCentered(&sContext, "update.", -1, GrContextDpyWidthGet(&sContext) / 2, 40, false); // // Wait for select button to be pressed. // while ((ButtonsPoll(0, 0) & SELECT_BUTTON) == 0) { ROM_SysCtlDelay(ulSysClock / 1000); } GrStringDrawCentered(&sContext, " ", -1, GrContextDpyWidthGet(&sContext) / 2, 20, true); GrStringDrawCentered(&sContext, " Updating... ", -1, GrContextDpyWidthGet(&sContext) / 2, 30, true); GrStringDrawCentered(&sContext, " ", -1, GrContextDpyWidthGet(&sContext) / 2, 40, true); // // Transfer control to the boot loader. // JumpToBootLoader(); // // The previous function never returns but we need to stick in a return // code here to keep the compiler from generating a warning. // return(0); }
void LED_Init() { ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOM); ROM_SysCtlDelay(5); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTM_BASE, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2); }
int main2(void) { UINT8 IsDHCP = 0; int32_t i32CommandStatus; _NetCfgIpV4Args_t ipV4; unsigned char len = sizeof(_NetCfgIpV4Args_t); int Status = 0; /* Stop WDT */ stopWDT(); /* Initialize the system clock of MCU */ initClk(); Board_Init(); // initialize LaunchPad I/O and PD1 LED ConfigureUART(); // Initialize the UART. UARTprintf("Section 11.4 IoT example, Volume 2 Real-time interfacing\n"); UARTprintf("This application is configured to measure analog signals from Ain7=PD0\n"); UARTprintf(" and send UDP packets to IP: %d.%d.%d.%d Port: %d\n\n", SL_IPV4_BYTE(IP_ADDR,3), SL_IPV4_BYTE(IP_ADDR,2), SL_IPV4_BYTE(IP_ADDR,1), SL_IPV4_BYTE(IP_ADDR,0),PORT_NUM); /* Initializing the CC3100 device */ sl_Start(0, 0, 0); /* Connecting to WLAN AP - Set with static parameters defined at the top After this call we will be connected and have IP address */ WlanConnect(); /* Read the IP parameter */ sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&IsDHCP,&len, (unsigned char *)&ipV4); //Print the IP UARTprintf("This node is at IP: %d.%d.%d.%d\n", SL_IPV4_BYTE(ipV4.ipV4,3), SL_IPV4_BYTE(ipV4.ipV4,2), SL_IPV4_BYTE(ipV4.ipV4,1), SL_IPV4_BYTE(ipV4.ipV4,0)); // // Loop forever waiting for commands from PC... // while(1) { // // Print prompt for user. // UARTprintf("\n>"); // // Peek to see if a full command is ready for processing. // while(UARTPeek('\r') == -1) { // // Approximately 1 millisecond delay. // ROM_SysCtlDelay(ROM_SysCtlClockGet() / 3000); } // // A '\r' was detected so get the line of text from the receive buffer. // UARTgets(g_cInput,sizeof(g_cInput)); // // Pass the line from the user to the command processor. // It will be parsed and valid commands executed. // i32CommandStatus = CmdLineProcess(g_cInput); // // Handle the case of bad command. // if(i32CommandStatus == CMDLINE_BAD_CMD) { UARTprintf(" Bad command. Try again.\n"); } // // Handle the case of too many arguments. // else if(i32CommandStatus == CMDLINE_TOO_MANY_ARGS) { UARTprintf(" Too many arguments for command. Try again.\n"); } // // Handle the case of too few arguments. // else if(i32CommandStatus == CMDLINE_TOO_FEW_ARGS) { UARTprintf(" Too few arguments for command. Try again.\n"); } // // Handle the case of too few arguments. // else if(i32CommandStatus == CMDLINE_INVALID_ARG) { UARTprintf(" Invalid command argument(s). Try again.\n"); } } }