void timerInit() { #ifdef TARGET_IS_BLIZZARD_RB1 // // Run at system clock at 80MHz // MAP_SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ| SYSCTL_OSC_MAIN); #else // // Run at system clock at 120MHz // MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ|SYSCTL_OSC_MAIN|SYSCTL_USE_PLL|SYSCTL_CFG_VCO_480), F_CPU); #endif // // SysTick is used for delay() and delayMicroseconds() // MAP_SysTickPeriodSet(F_CPU / SYSTICKHZ); MAP_SysTickEnable(); MAP_IntPrioritySet(FAULT_SYSTICK, SYSTICK_INT_PRIORITY); MAP_SysTickIntEnable(); MAP_IntMasterEnable(); // PIOSC is used during Deep Sleep mode for wakeup MAP_SysCtlPIOSCCalibrate(SYSCTL_PIOSC_CAL_FACT); // Factory-supplied calibration used }
/** * Hardware setup * Initializes pins, clocks, etc */ void HAL_setup(void){/*{{{*/ //Configure clock to run at 120MHz //configCPU_CLOCK_HZ = 120MHz //Needs to be set for FreeRTOS g_syshz = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000L); MAP_SysCtlMOSCConfigSet(SYSCTL_MOSC_HIGHFREQ); //Enable all GPIOs MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOM); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOP); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOQ); init_ethernet(); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); //Configure reset pin for XBD MAP_GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE, RESET_PIN); //Reset XBD xbd_reset(true); //Configure UART MAP_GPIOPinConfigure(GPIO_PA0_U0RX); MAP_GPIOPinConfigure(GPIO_PA1_U0TX); MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); MAP_UARTConfigSetExpClk(UART0_BASE, g_syshz, 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); // //Configure measurement stuff measure_setup(); //Configure xbd i2c comm i2c_comm_setup(); //Setup watchdog watchdog_setup(); //Unreset XBD xbd_reset(false); }/*}}}*/
int rt_hw_cpu_init(void) { MAP_IntMasterDisable(); IntRegister(FAULT_HARD, HardFault_Handler); IntRegister(FAULT_PENDSV, PendSV_Handler); IntRegister(FAULT_SYSTICK, SysTick_Handler); // Enable lazy stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. MAP_FPULazyStackingEnable(); // Set the clocking to run directly from the external crystal/oscillator. // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the // crystal on your board. SysClock = MAP_SysCtlClockFreqSet( (SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), SYS_CLOCK_DEFAULT); MAP_SysTickDisable(); MAP_SysTickPeriodSet(SysClock/ RT_TICK_PER_SECOND - 1); MAP_SysTickIntEnable(); MAP_SysTickEnable(); return 0; }
//***************************************************************************** // // Generic configuration is handled in this function. // // This function is called by the start up code to perform any configuration // necessary before calling the update routine. It is responsible for setting // the system clock to the expected rate and setting flash programming // parameters prior to calling ConfigureUSBInterface() to set up the USB // hardware. // // \return None. // //***************************************************************************** void UpdaterMain(void) { // // Make sure NVIC points at the correct vector table. // HWREG(NVIC_VTABLE) = 0; // // Run from the PLL at 120 MHz. // g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // // 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(); // // Configure the USB interface and power the bus. // ConfigureUSBInterface(); // // Call the updater function. This will attempt to load a new image // into flash from a USB memory stick. // UpdaterUSB(); }
//***************************************************************************** // // PoC2Repeater // //***************************************************************************** int main(void) { // Set the clocking to run directly from the crystal at 120MHz. g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // Enable the peripherals ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART7); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION); // Enable the GPIO pins for the LEDs (PN0 and PN1). ROM_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_1); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_0); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_4); // ButtonsInit ROM_GPIODirModeSet(GPIO_PORTJ_BASE, ALL_BUTTONS, GPIO_DIR_MODE_IN); MAP_GPIOPadConfigSet(GPIO_PORTJ_BASE, ALL_BUTTONS, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // Enable processor interrupts. ROM_IntMasterEnable(); // Set GPIO PC4 and PC5 as UART pins. GPIOPinConfigure(GPIO_PC4_U7RX); GPIOPinConfigure(GPIO_PC5_U7TX); ROM_GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_4 | GPIO_PIN_5); // Configure the UART for 115,200, 8-N-1 operation. ROM_UARTConfigSetExpClk(UART7_BASE, g_ui32SysClock, 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); // Enable the UART interrupt. ROM_IntEnable(INT_UART7); ROM_UARTIntEnable(UART7_BASE, UART_INT_RX | UART_INT_RT); // Reset message info for(uint8_t i = 0; i < MSG; i++) message[i] = 0; // Loop forever echoing data through the UART. while(1) { } }
//***************************************************************************** // // Print "Hello World!" to the UART on the Intelligent UART Module. // //***************************************************************************** int main(void) { // // Run from the PLL at 120 MHz. // g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // // Configure the device pins. // PinoutSet(false, false); // // Enable the GPIO pins for the LED D1 (PN1). // ROM_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_1); // // Initialize the UART. // ConfigureUART(); // // Hello! // UARTprintf("Hello, world!\n"); // // We are finished. Hang around flashing D1. // while(1) { // // Turn on D1. // LEDWrite(CLP_D1, 1); // // Delay for a bit. // SysCtlDelay(g_ui32SysClock / 10 / 3); // // Turn off D1. // LEDWrite(CLP_D1, 0); // // Delay for a bit. // SysCtlDelay(g_ui32SysClock / 10 / 3); } }
int main(void) { // Run from the PLL at 120 MHz. g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), configCPU_CLOCK_HZ); // Initialize the device pinout appropriately for this board. pin_init(); // // Initialize the UART and write status. // ConfigureUART(); // Make sure the main oscillator is enabled because this is required by // the PHY. The system must have a 25MHz crystal attached to the OSC // pins. The SYSCTL_MOSC_HIGHFREQ parameter is used when the crystal // frequency is 10MHz or higher. SysCtlMOSCConfigSet(SYSCTL_MOSC_HIGHFREQ); // Create the LED task. if (LEDTaskInit() != 0) { while (1) { } } // Create the lwIP tasks. if (lwIPTaskInit() != 0) { while (1) { } } // Create the hello world task. /*if (hello_world_init() != 0) { while (1) { } }*/ UARTprintf("FreeRTOS + Lwip\n"); // Start the scheduler. This should not return. vTaskStartScheduler(); // In case the scheduler returns for some reason, loop forever. while (1) { } }
//***************************************************************************** // // Print "Hello World!" to the display on the Intelligent Display Module. // //***************************************************************************** int main(void) { tContext sContext; uint32_t ui32SysClock; // // 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, "hello"); // // Say hello using the Computer Modern 40 point font. // GrContextFontSet(&sContext, g_psFontCm40); GrStringDrawCentered(&sContext, "Hello World!", -1, GrContextDpyWidthGet(&sContext) / 2, ((GrContextDpyHeightGet(&sContext) - 32) / 2) + 24, 0); // // Flush any cached drawing operations. // GrFlush(&sContext); // // We are finished. Hang around doing nothing. // while(1) { } }
int main() { ROM_SysCtlPeripheralEnable(SPI_LED_SYSCTL); ROM_GPIOPinTypeGPIOOutput(SPI_LED_BASE, SPI_LED_ERROR|SPI_LED_BUSY); clockFreq = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); ROM_SysCtlPeripheralEnable(COCO_CS_SYSCTL); ROM_GPIOPinTypeGPIOOutput(COCO_CS_BASE, COCO_CS); ROM_GPIOPinWrite(COCO_CS_BASE, COCO_CS, COCO_CS); uart_init(clockFreq); disk_initialize(0); ROM_GPIOPinWrite(SPI_LED_BASE, SPI_LED_ERROR|SPI_LED_BUSY, SPI_LED_BUSY); if ((res = f_mount(0, &fatfs_obj))) { ROM_GPIOPinWrite(SPI_LED_BASE, SPI_LED_ERROR|SPI_LED_BUSY, SPI_LED_ERROR); UART_printstr("Mount failed!\r\n"); while (1); } setAddr(0x413000); for (int i=0; i < 4*128; i++) setData(f88[i]); setAddr(0x420000); if ((res = f_open(&fil_obj, "/dod.rom", FA_READ)) != FR_OK) { ROM_GPIOPinWrite(SPI_LED_BASE, SPI_LED_ERROR|SPI_LED_BUSY, SPI_LED_ERROR); UART_printstr("Can't open test file.\r\n"); while (1); } programRom(&fil_obj); f_close(&fil_obj); ROM_GPIOPinWrite(SPI_LED_BASE, SPI_LED_ERROR|SPI_LED_BUSY, 0); while (1); }
/** * This function will initial LPC40xx board. */ void rt_hw_board_init() { MAP_IntMasterDisable(); IntRegister(FAULT_HARD, HardFault_Handler); IntRegister(FAULT_PENDSV, PendSV_Handler); IntRegister(FAULT_SYSTICK, SysTick_Handler); // // Enable lazy stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // MAP_FPULazyStackingEnable(); // // Set the clocking to run directly from the external crystal/oscillator. // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the // crystal on your board. // SysClock = MAP_SysCtlClockFreqSet( (SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), SYS_CLOCK_DEFAULT); MAP_SysTickDisable(); MAP_SysTickPeriodSet(SysClock/ RT_TICK_PER_SECOND - 1); MAP_SysTickIntEnable(); MAP_SysTickEnable(); /* set pend exception priority */ //IntPrioritySet(FAULT_PENDSV, (1 << 5) - 1); /*init uart device*/ rt_hw_uart_init(); //redirect RTT stdio to CONSOLE device rt_console_set_device(RT_CONSOLE_DEVICE_NAME); // // Enable interrupts to the processor. // MAP_IntMasterEnable(); }
void initClk() { /*The FPU should be enabled because some compilers will use floating- * point registers, even for non-floating-point code. If the FPU is not * enabled this will cause a fault. This also ensures that floating- * point operations could be added to this application and would work * correctly and use the hardware floating-point unit. Finally, lazy * stacking is enabled 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 system clock to 60MHz via the PLL, knowing that there is a // 25MHz crystal on the board. // g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); }
//***************************************************************************** // // Main application entry point. // //***************************************************************************** int main(void) { int_fast32_t i32IPart[16], i32FPart[16]; uint_fast32_t ui32Idx, ui32CompDCMStarted; float pfData[16]; float *pfAccel, *pfGyro, *pfMag, *pfEulers, *pfQuaternion; // // Initialize convenience pointers that clean up and clarify the code // meaning. We want all the data in a single contiguous array so that // we can make our pretty printing easier later. // pfAccel = pfData; pfGyro = pfData + 3; pfMag = pfData + 6; pfEulers = pfData + 9; pfQuaternion = pfData + 12; // // Configure the system frequency. // g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // // Configure the device pins for this board. // PinoutSet(false, false); // // Initialize the UART. // ConfigureUART(); // // Print the welcome message to the terminal. // UARTprintf("\033[2JMPU9150 Complimentary DCM Example\n"); // // The I2C7 peripheral must be enabled before use. // // For BoosterPack 2 interface use I2C8. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C7); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); // // Configure the pin muxing for I2C7 functions on port D0 and D1. // This step is not necessary if your part does not support pin muxing. // // For BoosterPack 2 interface use PA2 and PA3. // ROM_GPIOPinConfigure(GPIO_PD0_I2C7SCL); ROM_GPIOPinConfigure(GPIO_PD1_I2C7SDA); // // 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. // // For BoosterPack 2 interface use PA2 and PA3. // GPIOPinTypeI2CSCL(GPIO_PORTD_BASE, GPIO_PIN_0); ROM_GPIOPinTypeI2C(GPIO_PORTD_BASE, GPIO_PIN_1); // // Configure and Enable the GPIO interrupt. Used for INT signal from the // MPU9150. // // For BoosterPack 2 interface change this to PM7. // ROM_GPIOPinTypeGPIOInput(GPIO_PORTM_BASE, GPIO_PIN_3); GPIOIntEnable(GPIO_PORTM_BASE, GPIO_PIN_3); ROM_GPIOIntTypeSet(GPIO_PORTM_BASE, GPIO_PIN_3, GPIO_FALLING_EDGE); ROM_IntEnable(INT_GPIOM); // // Keep only some parts of the systems running while in sleep mode. // GPIOM is for the MPU9150 interrupt pin. // UART0 is the virtual serial port // I2C7 is the I2C interface to the ISL29023 // // For BoosterPack 2 Interface change this to I2C8. // ROM_SysCtlPeripheralClockGating(true); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOM); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART0); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_I2C7); // // Enable interrupts to the processor. // ROM_IntMasterEnable(); // // Initialize I2C7 peripheral. // // For BoosterPack 2 use I2C8. // I2CMInit(&g_sI2CInst, I2C7_BASE, INT_I2C7, 0xff, 0xff, g_ui32SysClock); // // Turn on the LED to show a transaction is starting. // LEDWrite(CLP_D3 | CLP_D4, CLP_D3); // // Initialize the MPU9150 Driver. // MPU9150Init(&g_sMPU9150Inst, &g_sI2CInst, MPU9150_I2C_ADDRESS, MPU9150AppCallback, &g_sMPU9150Inst); // // Wait for transaction to complete // MPU9150AppI2CWait(__FILE__, __LINE__); // // Turn on the LED to show a transaction is starting. // LEDWrite(CLP_D3 | CLP_D4, CLP_D3); // // Write application specifice sensor configuration such as filter settings // and sensor range settings. // g_sMPU9150Inst.pui8Data[0] = MPU9150_CONFIG_DLPF_CFG_94_98; g_sMPU9150Inst.pui8Data[1] = MPU9150_GYRO_CONFIG_FS_SEL_250; g_sMPU9150Inst.pui8Data[2] = (MPU9150_ACCEL_CONFIG_ACCEL_HPF_5HZ | MPU9150_ACCEL_CONFIG_AFS_SEL_2G); MPU9150Write(&g_sMPU9150Inst, MPU9150_O_CONFIG, g_sMPU9150Inst.pui8Data, 3, MPU9150AppCallback, &g_sMPU9150Inst); // // Wait for transaction to complete // MPU9150AppI2CWait(__FILE__, __LINE__); // // Turn on the LED to show a transaction is starting. // LEDWrite(CLP_D3 | CLP_D4, CLP_D3); // // Configure the data ready interrupt pin output of the MPU9150. // g_sMPU9150Inst.pui8Data[0] = MPU9150_INT_PIN_CFG_INT_LEVEL | MPU9150_INT_PIN_CFG_INT_RD_CLEAR | MPU9150_INT_PIN_CFG_LATCH_INT_EN; g_sMPU9150Inst.pui8Data[1] = MPU9150_INT_ENABLE_DATA_RDY_EN; MPU9150Write(&g_sMPU9150Inst, MPU9150_O_INT_PIN_CFG, g_sMPU9150Inst.pui8Data, 2, MPU9150AppCallback, &g_sMPU9150Inst); // // Wait for transaction to complete // MPU9150AppI2CWait(__FILE__, __LINE__); // // Initialize the DCM system. 50 hz sample rate. // accel weight = .2, gyro weight = .8, mag weight = .2 // CompDCMInit(&g_sCompDCMInst, 1.0f / 50.0f, 0.2f, 0.6f, 0.2f); // // Print the basic outline of our data table. Done once and then kept as we // print only the data. // UARTprintf("\033[2J\033[H"); UARTprintf("MPU9150 9-Axis Simple Data Application Example\n\n"); UARTprintf("\033[20GX\033[31G|\033[43GY\033[54G|\033[66GZ\n\n"); UARTprintf("Accel\033[8G|\033[31G|\033[54G|\n\n"); UARTprintf("Gyro\033[8G|\033[31G|\033[54G|\n\n"); UARTprintf("Mag\033[8G|\033[31G|\033[54G|\n\n"); UARTprintf("\n\033[20GRoll\033[31G|\033[43GPitch\033[54G|\033[66GYaw\n\n"); UARTprintf("Eulers\033[8G|\033[31G|\033[54G|\n\n"); UARTprintf("\n\033[17GQ1\033[26G|\033[35GQ2\033[44G|\033[53GQ3\033[62G|" "\033[71GQ4\n\n"); UARTprintf("Q\033[8G|\033[26G|\033[44G|\033[62G|\n\n"); ui32CompDCMStarted = 0; while(1) { // // Go to sleep mode while waiting for data ready. // while(!g_vui8I2CDoneFlag) { ROM_SysCtlSleep(); } // // Clear the flag // g_vui8I2CDoneFlag = 0; // // Get floating point version of the Accel Data in m/s^2. // MPU9150DataAccelGetFloat(&g_sMPU9150Inst, pfAccel, pfAccel + 1, pfAccel + 2); // // Get floating point version of angular velocities in rad/sec // MPU9150DataGyroGetFloat(&g_sMPU9150Inst, pfGyro, pfGyro + 1, pfGyro + 2); // // Get floating point version of magnetic fields strength in tesla // MPU9150DataMagnetoGetFloat(&g_sMPU9150Inst, pfMag, pfMag + 1, pfMag + 2); // // Check if this is our first data ever. // if(ui32CompDCMStarted == 0) { // // Set flag indicating that DCM is started. // Perform the seeding of the DCM with the first data set. // ui32CompDCMStarted = 1; CompDCMMagnetoUpdate(&g_sCompDCMInst, pfMag[0], pfMag[1], pfMag[2]); CompDCMAccelUpdate(&g_sCompDCMInst, pfAccel[0], pfAccel[1], pfAccel[2]); CompDCMGyroUpdate(&g_sCompDCMInst, pfGyro[0], pfGyro[1], pfGyro[2]); CompDCMStart(&g_sCompDCMInst); } else { // // DCM Is already started. Perform the incremental update. // CompDCMMagnetoUpdate(&g_sCompDCMInst, pfMag[0], pfMag[1], pfMag[2]); CompDCMAccelUpdate(&g_sCompDCMInst, pfAccel[0], pfAccel[1], pfAccel[2]); CompDCMGyroUpdate(&g_sCompDCMInst, -pfGyro[0], -pfGyro[1], -pfGyro[2]); CompDCMUpdate(&g_sCompDCMInst); } // // Increment the skip counter. Skip counter is used so we do not // overflow the UART with data. // g_ui32PrintSkipCounter++; if(g_ui32PrintSkipCounter >= PRINT_SKIP_COUNT) { // // Reset skip counter. // g_ui32PrintSkipCounter = 0; // // Get Euler data. (Roll Pitch Yaw) // CompDCMComputeEulers(&g_sCompDCMInst, pfEulers, pfEulers + 1, pfEulers + 2); // // Get Quaternions. // CompDCMComputeQuaternion(&g_sCompDCMInst, pfQuaternion); // // convert mag data to micro-tesla for better human interpretation. // pfMag[0] *= 1e6; pfMag[1] *= 1e6; pfMag[2] *= 1e6; // // Convert Eulers to degrees. 180/PI = 57.29... // Convert Yaw to 0 to 360 to approximate compass headings. // pfEulers[0] *= 57.295779513082320876798154814105f; pfEulers[1] *= 57.295779513082320876798154814105f; pfEulers[2] *= 57.295779513082320876798154814105f; if(pfEulers[2] < 0) { pfEulers[2] += 360.0f; } // // Now drop back to using the data as a single array for the // purpose of decomposing the float into a integer part and a // fraction (decimal) part. // for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { // // Conver float value to a integer truncating the decimal part. // i32IPart[ui32Idx] = (int32_t) pfData[ui32Idx]; // // Multiply by 1000 to preserve first three decimal values. // Truncates at the 3rd decimal place. // i32FPart[ui32Idx] = (int32_t) (pfData[ui32Idx] * 1000.0f); // // Subtract off the integer part from this newly formed decimal // part. // i32FPart[ui32Idx] = i32FPart[ui32Idx] - (i32IPart[ui32Idx] * 1000); // // make the decimal part a positive number for display. // if(i32FPart[ui32Idx] < 0) { i32FPart[ui32Idx] *= -1; } } // // Print the acceleration numbers in the table. // UARTprintf("\033[5;17H%3d.%03d", i32IPart[0], i32FPart[0]); UARTprintf("\033[5;40H%3d.%03d", i32IPart[1], i32FPart[1]); UARTprintf("\033[5;63H%3d.%03d", i32IPart[2], i32FPart[2]); // // Print the angular velocities in the table. // UARTprintf("\033[7;17H%3d.%03d", i32IPart[3], i32FPart[3]); UARTprintf("\033[7;40H%3d.%03d", i32IPart[4], i32FPart[4]); UARTprintf("\033[7;63H%3d.%03d", i32IPart[5], i32FPart[5]); // // Print the magnetic data in the table. // UARTprintf("\033[9;17H%3d.%03d", i32IPart[6], i32FPart[6]); UARTprintf("\033[9;40H%3d.%03d", i32IPart[7], i32FPart[7]); UARTprintf("\033[9;63H%3d.%03d", i32IPart[8], i32FPart[8]); // // Print the Eulers in a table. // UARTprintf("\033[14;17H%3d.%03d", i32IPart[9], i32FPart[9]); UARTprintf("\033[14;40H%3d.%03d", i32IPart[10], i32FPart[10]); UARTprintf("\033[14;63H%3d.%03d", i32IPart[11], i32FPart[11]); // // Print the quaternions in a table format. // UARTprintf("\033[19;14H%3d.%03d", i32IPart[12], i32FPart[12]); UARTprintf("\033[19;32H%3d.%03d", i32IPart[13], i32FPart[13]); UARTprintf("\033[19;50H%3d.%03d", i32IPart[14], i32FPart[14]); UARTprintf("\033[19;68H%3d.%03d", i32IPart[15], i32FPart[15]); } } }
//***************************************************************************** // // This is the main example program. It checks to see that the interrupts are // processed in the correct order when they have identical priorities, // increasing priorities, and decreasing priorities. This exercises interrupt // preemption and tail chaining. // //***************************************************************************** int main(void) { uint_fast8_t ui8Error; uint32_t ui32SysClock; // // 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(&g_sContext, &g_sKentec320x240x16_SSD2119); // // Draw the application frame. // FrameDraw(&g_sContext, "interrupts"); // // Put the status header text on the display. // GrContextFontSet(&g_sContext, g_psFontCm20); GrStringDrawCentered(&g_sContext, "Active: Pending: ", -1, GrContextDpyWidthGet(&g_sContext) / 2, 150, 0); // // Configure the B3, L1 and L0 to be outputs to indicate entry/exit of one // of the interrupt handlers. // GPIOPinTypeGPIOOutput(GPIO_A_BASE, GPIO_A_PIN); GPIOPinTypeGPIOOutput(GPIO_B_BASE, GPIO_B_PIN); GPIOPinTypeGPIOOutput(GPIO_C_BASE, GPIO_C_PIN); GPIOPinWrite(GPIO_A_BASE, GPIO_A_PIN, 0); GPIOPinWrite(GPIO_B_BASE, GPIO_B_PIN, 0); GPIOPinWrite(GPIO_C_BASE, GPIO_C_PIN, 0); // // Set up and enable the SysTick timer. It will be used as a reference // for delay loops in the interrupt handlers. The SysTick timer period // will be set up for 100 times per second. // ROM_SysTickPeriodSet(ui32SysClock / 100); ROM_SysTickEnable(); // // Reset the error indicator. // ui8Error = 0; // // Enable interrupts to the processor. // ROM_IntMasterEnable(); // // Enable the interrupts. // ROM_IntEnable(INT_GPIOA); ROM_IntEnable(INT_GPIOB); ROM_IntEnable(INT_GPIOC); // // Indicate that the equal interrupt priority test is beginning. // GrStringDrawCentered(&g_sContext, "Equal Priority", -1, GrContextDpyWidthGet(&g_sContext) / 2, 60, 1); // // Set the interrupt priorities so they are all equal. // ROM_IntPrioritySet(INT_GPIOA, 0x00); ROM_IntPrioritySet(INT_GPIOB, 0x00); ROM_IntPrioritySet(INT_GPIOC, 0x00); // // Reset the interrupt flags. // g_ui32GPIOa = 0; g_ui32GPIOb = 0; g_ui32GPIOc = 0; g_ui32Index = 1; // // Trigger the interrupt for GPIO C. // HWREG(NVIC_SW_TRIG) = INT_GPIOC - 16; // // Put the current interrupt state on the LCD. // DisplayIntStatus(); // // Verify that the interrupts were processed in the correct order. // if((g_ui32GPIOa != 3) || (g_ui32GPIOb != 2) || (g_ui32GPIOc != 1)) { ui8Error |= 1; } // // Wait two seconds. // Delay(2); // // Indicate that the decreasing interrupt priority test is beginning. // GrStringDrawCentered(&g_sContext, " Decreasing Priority ", -1, GrContextDpyWidthGet(&g_sContext) / 2, 60, 1); // // Set the interrupt priorities so that they are decreasing (i.e. C > B > // A). // ROM_IntPrioritySet(INT_GPIOA, 0x80); ROM_IntPrioritySet(INT_GPIOB, 0x40); ROM_IntPrioritySet(INT_GPIOC, 0x00); // // Reset the interrupt flags. // g_ui32GPIOa = 0; g_ui32GPIOb = 0; g_ui32GPIOc = 0; g_ui32Index = 1; // // Trigger the interrupt for GPIO C. // HWREG(NVIC_SW_TRIG) = INT_GPIOC - 16; // // Put the current interrupt state on the display. // DisplayIntStatus(); // // Verify that the interrupts were processed in the correct order. // if((g_ui32GPIOa != 3) || (g_ui32GPIOb != 2) || (g_ui32GPIOc != 1)) { ui8Error |= 2; } // // Wait two seconds. // Delay(2); // // Indicate that the increasing interrupt priority test is beginning. // GrStringDrawCentered(&g_sContext, " Increasing Priority ", -1, GrContextDpyWidthGet(&g_sContext) / 2, 60, 1); // // Set the interrupt priorities so that they are increasing (i.e. C < B < // A). // ROM_IntPrioritySet(INT_GPIOA, 0x00); ROM_IntPrioritySet(INT_GPIOB, 0x40); ROM_IntPrioritySet(INT_GPIOC, 0x80); // // Reset the interrupt flags. // g_ui32GPIOa = 0; g_ui32GPIOb = 0; g_ui32GPIOc = 0; g_ui32Index = 1; // // Trigger the interrupt for GPIO C. // HWREG(NVIC_SW_TRIG) = INT_GPIOC - 16; // // Put the current interrupt state on the display. // DisplayIntStatus(); // // Verify that the interrupts were processed in the correct order. // if((g_ui32GPIOa != 1) || (g_ui32GPIOb != 2) || (g_ui32GPIOc != 3)) { ui8Error |= 4; } // // Wait two seconds. // Delay(2); // // Disable the interrupts. // ROM_IntDisable(INT_GPIOA); ROM_IntDisable(INT_GPIOB); ROM_IntDisable(INT_GPIOC); // // Disable interrupts to the processor. // ROM_IntMasterDisable(); // // Print out the test results. // GrStringDrawCentered(&g_sContext, " Interrupt Priority ", -1, GrContextDpyWidthGet(&g_sContext) / 2, 60, 1); if(ui8Error) { GrStringDrawCentered(&g_sContext, " Equal: P Inc: P Dec: P ", -1, GrContextDpyWidthGet(&g_sContext) / 2, 150, 1); if(ui8Error & 1) { GrStringDrawCentered(&g_sContext, " F ", -1, 113, 150, 1); } if(ui8Error & 2) { GrStringDrawCentered(&g_sContext, " F ", -1, 187, 150, 1); } if(ui8Error & 4) { GrStringDrawCentered(&g_sContext, " F ", -1, 272, 150, 1); } } else { GrStringDrawCentered(&g_sContext, " Success! ", -1, GrContextDpyWidthGet(&g_sContext) / 2, 150, 1); } // // Flush the display. // GrFlush(&g_sContext); // // Loop forever. // while(1) { } }
//***************************************************************************** // // This example encrypts blocks of plaintext using TDES in CBC mode. It // does the encryption first without uDMA and then with uDMA. The results // are checked after each operation. // //***************************************************************************** int main(void) { uint32_t pui32CipherText[16], ui32Errors, ui32Idx, ui32SysClock; // // 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(false, false); // // Initialize local variables. // ui32Errors = 0; for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { pui32CipherText[ui32Idx] = 0; } // // Enable stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // ROM_FPUStackingEnable(); // // Enable DES interrupts. // ROM_IntEnable(INT_DES0); // // Enable debug output on UART0 and print a welcome message. // ConfigureUART(); UARTprintf("Starting TDES CBC encryption demo.\n"); // // Enable the uDMA module. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); // // Setup the control table. // ROM_uDMAEnable(); ROM_uDMAControlBaseSet(g_psDMAControlTable); // // Initialize the CCM and DES modules. // if(!DESInit()) { UARTprintf("Initialization of the DES module failed.\n"); ui32Errors |= 0x00000001; } // // Perform the encryption without uDMA. // UARTprintf("Performing encryption without uDMA.\n"); TDESCBCEncrypt(g_pui32TDESPlainText, pui32CipherText, g_pui32TDESKey, 64, g_pui32TDESIV, false); // // Check the result. // for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { if(pui32CipherText[ui32Idx] != g_pui32TDESCipherText[ui32Idx]) { UARTprintf("Ciphertext mismatch on word %d. Exp: 0x%x, Act: " "0x%x\n", ui32Idx, g_pui32TDESCipherText[ui32Idx], pui32CipherText[ui32Idx]); ui32Errors |= (ui32Idx << 16) | 0x00000002; } } // // Clear the array containing the ciphertext. // for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { pui32CipherText[ui32Idx] = 0; } // // Perform the encryption with uDMA. // UARTprintf("Performing encryption with uDMA.\n"); TDESCBCEncrypt(g_pui32TDESPlainText, pui32CipherText, g_pui32TDESKey, 64, g_pui32TDESIV, true); // // Check the result. // for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { if(pui32CipherText[ui32Idx] != g_pui32TDESCipherText[ui32Idx]) { UARTprintf("Ciphertext mismatch on word %d. Exp: 0x%x, Act: " "0x%x\n", ui32Idx, g_pui32TDESCipherText[ui32Idx], pui32CipherText[ui32Idx]); ui32Errors |= (ui32Idx << 16) | 0x00000004; } } // // Finished. // if(ui32Errors) { UARTprintf("Demo failed with error code 0x%x.\n", ui32Errors); LEDWrite(CLP_D3 | CLP_D4, CLP_D4); } else { UARTprintf("Demo completed successfully.\n"); LEDWrite(CLP_D3 | CLP_D4, CLP_D3); } while(1) { } }
//***************************************************************************** // // This is the main loop that runs the application. // //***************************************************************************** int main(void) { uint8_t ui8ButtonsChanged, ui8Buttons; uint32_t ui32SysClock; // // Set the clocking to run from the PLL at 120MHz // ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_25MHZ | SYSCTL_CFG_VCO_480), 120000000); // // Configure the device pins. // PinoutSet(); // // Configure the buttons driver. // ButtonsInit(ALL_BUTTONS); // // Initialize the display driver. // Kentec320x240x16_SSD2119Init(ui32SysClock); // // Initialize the graphics context. // GrContextInit(&g_sContext, &g_sKentec320x240x16_SSD2119); // // Draw the application frame. // FrameDraw(&g_sContext, "usb-dev-gamepad"); // // Default status is disconnected. // DisplayStatus(&g_sContext, "Disconnected"); // // Not configured initially. // g_iGamepadState = eStateNotConfigured; // // Initialize the USB stack for device mode. // USBStackModeSet(0, eUSBModeDevice, 0); // // Pass the device information to the USB library and place the device // on the bus. // USBDHIDGamepadInit(0, &g_sGamepadDevice); // // Zero out the initial report. // g_sReport.ui8Buttons = 0; g_sReport.i8XPos = 0; g_sReport.i8YPos = 0; // // Initialize the touch screen driver. // TouchScreenInit(ui32SysClock); // // Set the touch screen event handler. // TouchScreenCallbackSet(TSHandler); // // The main loop starts here. We begin by waiting for a host connection // then drop into the main gamepad handling section. If the host // disconnects, we return to the top and wait for a new connection. // while(1) { // // Wait here until USB device is connected to a host. // if(g_iGamepadState == eStateIdle) { // // See if the buttons updated. // ButtonsPoll(&ui8ButtonsChanged, &ui8Buttons); g_sReport.ui8Buttons = 0; // // Set button 1 if up button pressed. // if(ui8Buttons & UP_BUTTON) { g_sReport.ui8Buttons |= 0x01; } // // Set button 2 if down button pressed. // if(ui8Buttons & DOWN_BUTTON) { g_sReport.ui8Buttons |= 0x02; } // // Set button 3 if select button pressed. // if(ui8Buttons & SELECT_BUTTON) { g_sReport.ui8Buttons |= 0x04; } if(ui8ButtonsChanged) { g_bUpdate = true; } // // Send the report if there was an update. // if(g_bUpdate) { g_bUpdate = false; USBDHIDGamepadSendReport(&g_sGamepadDevice, &g_sReport, sizeof(g_sReport)); // // Now sending data but protect this from an interrupt since // it can change in interrupt context as well. // IntMasterDisable(); g_iGamepadState = eStateSending; IntMasterEnable(); } } } }
//***************************************************************************** // // This example generates hashes from a random block of data and empty block. // //***************************************************************************** int main(void) { uint32_t pui32HashResult[5], ui32Errors, ui32Vector, ui32Idx, ui32SysClock; // // 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(false, false); // // Initialize local variables. // ui32Errors = 0; // // Enable SHA interrupts. // ROM_IntEnable(INT_SHA0); // // Enable debug output on UART0 and print a welcome message. // ConfigureUART(); UARTprintf("Starting SHA1 hash encryption demo.\n"); // // Enable the uDMA module. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); // // Setup the control table. // ROM_uDMAEnable(); ROM_uDMAControlBaseSet(g_psDMAControlTable); // // Initialize the CCM and SHAMD5 modules. // if(!SHAMD5Init()) { UARTprintf("Initialization of the SHA module failed.\n"); ui32Errors |= 0x00000001; } // // Run tests without uDMA. // for(ui32Vector = 0; ui32Vector < 3; ui32Vector++) { UARTprintf("Running test #%d without uDMA\n", ui32Vector); // // Generate the hash. // SHA1HashGenerate(g_pui32RandomData, g_psSHA1TestVectors[ui32Vector].ui32DataLength, pui32HashResult, false); // // Check the result. // for(ui32Idx = 0; ui32Idx < 5; ui32Idx++) { if(pui32HashResult[ui32Idx] != g_psSHA1TestVectors[ui32Vector].pui32HashResult[ui32Idx]) { UARTprintf("Hash result mismatch - Exp: 0x%x, Act: 0x%x\n", g_psSHA1TestVectors[ui32Vector]. pui32HashResult[ui32Idx], pui32HashResult[0]); ui32Errors |= ((ui32Idx << 16) | 0x2); } } } // // Run tests with uDMA. // for(ui32Vector = 0; ui32Vector < 3; ui32Vector++) { UARTprintf("Running test #%d with uDMA\n", ui32Vector); // // Generate the hash. // SHA1HashGenerate(g_pui32RandomData, g_psSHA1TestVectors[ui32Vector].ui32DataLength, pui32HashResult, true); // // Check the result. // for(ui32Idx = 0; ui32Idx < 5; ui32Idx++) { if(pui32HashResult[ui32Idx] != g_psSHA1TestVectors[ui32Vector].pui32HashResult[ui32Idx]) { UARTprintf("Hash result mismatch - Exp: 0x%x, Act: 0x%x\n", g_psSHA1TestVectors[ui32Vector]. pui32HashResult[ui32Idx], pui32HashResult[0]); ui32Errors |= ((ui32Idx << 16) | 0x3); } } } // // Finished. // if(ui32Errors) { UARTprintf("Demo failed with error code 0x%x.\n", ui32Errors); LEDWrite(CLP_D3 | CLP_D4, CLP_D4); } else { UARTprintf("Demo completed successfully.\n"); LEDWrite(CLP_D3 | CLP_D4, CLP_D3); } while(1) { } }
//***************************************************************************** // // The main application loop. // //***************************************************************************** int main(void) { int32_t i32Status, i32Idx; uint32_t ui32SysClock, ui32PLLRate; #ifdef USE_ULPI uint32_t ui32Setting; #endif ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // // Set the part pin out appropriately for this device. // PinoutSet(); #ifdef USE_ULPI // // Switch the USB ULPI Pins over. // USBULPIPinoutSet(); // // Enable USB ULPI with high speed support. // ui32Setting = USBLIB_FEATURE_ULPI_HS; USBOTGFeatureSet(0, USBLIB_FEATURE_USBULPI, &ui32Setting); // // Setting the PLL frequency to zero tells the USB library to use the // external USB clock. // ui32PLLRate = 0; #else // // Save the PLL rate used by this application. // ui32PLLRate = 480000000; #endif // // Initialize the hub port status. // for(i32Idx = 0; i32Idx < NUM_HUB_STATUS; i32Idx++) { g_psHubStatus[i32Idx].bConnected = false; } // // Enable Clocking to the USB controller. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0); // // Enable Interrupts // ROM_IntMasterEnable(); // // Initialize the USB stack mode and pass in a mode callback. // USBStackModeSet(0, eUSBModeHost, 0); // // Register the host class drivers. // USBHCDRegisterDrivers(0, g_ppHostClassDrivers, g_ui32NumHostClassDrivers); // // Open the Keyboard interface. // KeyboardOpen(); MSCOpen(ui32SysClock); // // Open a hub instance and provide it with the memory required to hold // configuration descriptors for each attached device. // USBHHubOpen(HubCallback); // // 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); // // Tell the USB library the CPU clock and the PLL frequency. // USBOTGFeatureSet(0, USBLIB_FEATURE_CPUCLK, &ui32SysClock); USBOTGFeatureSet(0, USBLIB_FEATURE_USBPLL, &ui32PLLRate); // // Initialize the USB controller for Host mode. // USBHCDInit(0, g_pui8HCDPool, sizeof(g_pui8HCDPool)); // // Initialize the display driver. // Kentec320x240x16_SSD2119Init(ui32SysClock); // // Initialize the graphics context. // GrContextInit(&g_sContext, &g_sKentec320x240x16_SSD2119); // // Draw the application frame. // FrameDraw(&g_sContext, "usb-host-hub"); // // Calculate the number of characters that will fit on a line. // Make sure to leave a small border for the text box. // g_ui32CharsPerLine = (GrContextDpyWidthGet(&g_sContext) - 16) / GrFontMaxWidthGet(g_psFontFixed6x8); // // Calculate the number of lines per usable text screen. This requires // taking off space for the top and bottom banners and adding a small bit // for a border. // g_ui32LinesPerScreen = (GrContextDpyHeightGet(&g_sContext) - (2*(DISPLAY_BANNER_HEIGHT + 1)))/ GrFontHeightGet(g_psFontFixed6x8); // // Initial update of the screen. // UpdateStatus(0); UpdateStatus(1); UpdateStatus(2); UpdateStatus(3); g_ui32CmdIdx = 0; g_ui32CurrentLine = 0; // // Initialize the file system. // FileInit(); // // The main loop for the application. // while(1) { // // Print a prompt to the console. Show the CWD. // WriteString("> "); // // Is there a command waiting to be processed? // while((g_ui32Flags & FLAG_CMD_READY) == 0) { // // Call the YSB library to let non-interrupt code run. // USBHCDMain(); // // Call the keyboard and mass storage main routines. // KeyboardMain(); MSCMain(); } // // Pass the line from the user to the command processor. // It will be parsed and valid commands executed. // i32Status = CmdLineProcess(g_pcCmdBuf); // // Handle the case of bad command. // if(i32Status == CMDLINE_BAD_CMD) { WriteString("Bad command!\n"); } // // Handle the case of too many arguments. // else if(i32Status == CMDLINE_TOO_MANY_ARGS) { WriteString("Too many arguments for command processor!\n"); } // // Otherwise the command was executed. Print the error // code if one was returned. // else if(i32Status != 0) { WriteString("Command returned error code\n"); WriteString((char *)StringFromFresult((FRESULT)i32Status)); WriteString("\n"); } // // Reset the command flag and the command index. // g_ui32Flags &= ~FLAG_CMD_READY; g_ui32CmdIdx = 0; } }
//***************************************************************************** // // A simple demonstration of the features of the TivaWare Graphics Library. // //***************************************************************************** int main(void) { tContext sContext; uint32_t ui32SysClock; // // 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); // // Set graphics library text rendering defaults. // GrLibInit(&GRLIB_INIT_STRUCT); // // Set the string table and the default language. // GrStringTableSet(STRING_TABLE); // // Set the default language. // ChangeLanguage(GrLangEnUS); // // Initialize the graphics context. // GrContextInit(&sContext, &g_sKentec320x240x16_SSD2119); // // Draw the application frame. // FrameDraw(&sContext, "lang-demo"); // // Load the static strings from the string table. These strings are // independent of the language in use but we store them in the string // table nonetheless since (a) we may be using codepage remapping in // which case it would be difficult to hardcode them into the app source // anyway (ASCII or ISO8859-1 text would not render properly with the // remapped custom font) and (b) even if we're not using codepage remapping, // we may have generated a custom font from the string table output and // we want to make sure that all glyphs required by the application are // present in that font. If we hardcode some text in the application // source and don't put it in the string table, we run the risk of having // characters missing in the font. // GrStringGet(STR_ENGLISH, g_pcEnglish, MAX_LANGUAGE_NAME_LEN); GrStringGet(STR_DEUTSCH, g_pcDeutsch, MAX_LANGUAGE_NAME_LEN); GrStringGet(STR_ESPANOL, g_pcEspanol, MAX_LANGUAGE_NAME_LEN); GrStringGet(STR_ITALIANO, g_pcItaliano, MAX_LANGUAGE_NAME_LEN); GrStringGet(STR_CHINESE, g_pcChinese, MAX_LANGUAGE_NAME_LEN); GrStringGet(STR_KOREAN, g_pcKorean, MAX_LANGUAGE_NAME_LEN); GrStringGet(STR_JAPANESE, g_pcJapanese, MAX_LANGUAGE_NAME_LEN); GrStringGet(STR_PLUS, g_pcPlus, 2); GrStringGet(STR_MINUS, g_pcMinus, 2); // // Initialize the touch screen driver and have it route its messages to the // widget tree. // TouchScreenInit(ui32SysClock); TouchScreenCallbackSet(WidgetPointerMessage); // // Add the title block and the previous and next buttons to the widget // tree. // WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sPrevious); WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sTitle); WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sNext); // // Add the first panel to the widget tree. // g_ui32Panel = 0; WidgetAdd(WIDGET_ROOT, (tWidget *)g_psPanels); // // Set the string for the title. // CanvasTextSet(&g_sTitle, g_pcTitle); // // Issue the initial paint request to the widgets. // WidgetPaint(WIDGET_ROOT); // // Loop forever, processing widget messages. // while(1) { // // Process any messages in the widget message queue. // WidgetMessageQueueProcess(); } }
//***************************************************************************** // // This is the main application entry function. // //***************************************************************************** int main(void) { uint32_t ui32TxCount, ui32RxCount, ui32Fullness, ui32SysClock, ui32PLLRate; tRectangle sRect; char pcBuffer[16]; #ifdef USE_ULPI uint32_t ui32Setting; #endif // // Set the system clock to run at 120MHz from the PLL. // ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // // Configure the device pins. // PinoutSet(); #ifdef USE_ULPI // // Switch the USB ULPI Pins over. // USBULPIPinoutSet(); // // Enable USB ULPI with high speed support. // ui32Setting = USBLIB_FEATURE_ULPI_HS; USBOTGFeatureSet(0, USBLIB_FEATURE_USBULPI, &ui32Setting); // // Setting the PLL frequency to zero tells the USB library to use the // external USB clock. // ui32PLLRate = 0; #else // // Save the PLL rate used by this application. // ui32PLLRate = 480000000; #endif // // Enable the system tick. // ROM_SysTickPeriodSet(ui32SysClock / TICKS_PER_SECOND); ROM_SysTickIntEnable(); ROM_SysTickEnable(); // // Not configured initially. // g_ui32Flags = 0; // // Initialize the display driver. // Kentec320x240x16_SSD2119Init(ui32SysClock); // // Initialize the graphics context. // GrContextInit(&g_sContext, &g_sKentec320x240x16_SSD2119); // // Draw the application frame. // FrameDraw(&g_sContext, "usb-dev-serial"); // // Fill the top 15 rows of the screen with blue to create the banner. // sRect.i16XMin = 0; sRect.i16YMin = 0; sRect.i16XMax = GrContextDpyWidthGet(&g_sContext) - 1; sRect.i16YMax = 23; GrContextForegroundSet(&g_sContext, ClrDarkBlue); GrRectFill(&g_sContext, &sRect); // // Put a white box around the banner. // GrContextForegroundSet(&g_sContext, ClrWhite); GrRectDraw(&g_sContext, &sRect); // // Show the various static text elements on the color STN display. // GrContextFontSet(&g_sContext, TEXT_FONT); GrStringDraw(&g_sContext, "Tx bytes:", -1, 8, 80, false); GrStringDraw(&g_sContext, "Tx buffer:", -1, 8, 105, false); GrStringDraw(&g_sContext, "Rx bytes:", -1, 8, 160, false); GrStringDraw(&g_sContext, "Rx buffer:", -1, 8, 185, false); DrawBufferMeter(&g_sContext, 150, 105); DrawBufferMeter(&g_sContext, 150, 185); // // Enable the UART that we will be redirecting. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); // // Change the UART clock to the 16 MHz PIOSC. // UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC); // // Set the default UART configuration. // ROM_UARTConfigSetExpClk(UART0_BASE, UART_CLOCK, DEFAULT_BIT_RATE, DEFAULT_UART_CONFIG); ROM_UARTFIFOLevelSet(UART0_BASE, UART_FIFO_TX4_8, UART_FIFO_RX4_8); // // Configure and enable UART interrupts. // ROM_UARTIntClear(UART0_BASE, ROM_UARTIntStatus(UART0_BASE, false)); ROM_UARTIntEnable(UART0_BASE, (UART_INT_OE | UART_INT_BE | UART_INT_PE | UART_INT_FE | UART_INT_RT | UART_INT_TX | UART_INT_RX)); // // Tell the user what we are up to. // DisplayStatus(&g_sContext, " Configuring USB... "); // // 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); // // Tell the USB library the CPU clock and the PLL frequency. This is a // new requirement for TM4C129 devices. // USBDCDFeatureSet(0, USBLIB_FEATURE_CPUCLK, &ui32SysClock); USBDCDFeatureSet(0, USBLIB_FEATURE_USBPLL, &ui32PLLRate); // // Pass our device information to the USB library and place the device // on the bus. // USBDCDCInit(0, (tUSBDCDCDevice *)&g_sCDCDevice); // // Wait for initial configuration to complete. // DisplayStatus(&g_sContext, " Waiting for host... "); // // Clear our local byte counters. // ui32RxCount = 0; ui32TxCount = 0; g_ui32UARTTxCount = 0; g_ui32UARTRxCount = 0; #ifdef DEBUG g_ui32UARTRxErrors = 0; #endif // // Enable interrupts now that the application is ready to start. // ROM_IntEnable(INT_UART0); // // Main application loop. // while(1) { // // Have we been asked to update the status display? // if(HWREGBITW(&g_ui32Flags, FLAG_STATUS_UPDATE)) { // // Clear the command flag // HWREGBITW(&g_ui32Flags, FLAG_STATUS_UPDATE) = 0; DisplayStatus(&g_sContext, g_pcStatus); } // // Has there been any transmit traffic since we last checked? // if(ui32TxCount != g_ui32UARTTxCount) { // // Take a snapshot of the latest transmit count. // ui32TxCount = g_ui32UARTTxCount; // // Update the display of bytes transmitted by the UART. // usnprintf(pcBuffer, 16, "%d ", ui32TxCount); GrStringDraw(&g_sContext, pcBuffer, -1, 150, 80, true); // // Update the RX buffer fullness. Remember that the buffers are // named relative to the USB whereas the status display is from // the UART's perspective. The USB's receive buffer is the UART's // transmit buffer. // ui32Fullness = ((USBBufferDataAvailable(&g_sRxBuffer) * 100) / UART_BUFFER_SIZE); UpdateBufferMeter(&g_sContext, ui32Fullness, 150, 105); } // // Has there been any receive traffic since we last checked? // if(ui32RxCount != g_ui32UARTRxCount) { // // Take a snapshot of the latest receive count. // ui32RxCount = g_ui32UARTRxCount; // // Update the display of bytes received by the UART. // usnprintf(pcBuffer, 16, "%d ", ui32RxCount); GrStringDraw(&g_sContext, pcBuffer, -1, 150, 160, true); // // Update the TX buffer fullness. Remember that the buffers are // named relative to the USB whereas the status display is from // the UART's perspective. The USB's transmit buffer is the UART's // receive buffer. // ui32Fullness = ((USBBufferDataAvailable(&g_sTxBuffer) * 100) / UART_BUFFER_SIZE); UpdateBufferMeter(&g_sContext, ui32Fullness, 150, 185); } } }
//***************************************************************************** // // This example demonstrates the use of the watchdog timer. // //***************************************************************************** int main(void) { // // Set the clocking to run directly from the crystal at 120MHz. // g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // // Initialize the buttons driver. // ButtonsInit(); // // Enable the peripherals used by this example. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_WDOG0); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION); // // Enable processor interrupts. // ROM_IntMasterEnable(); // // Set GPIO PN0 as an output. This drives an LED on the board that will // toggle when a watchdog interrupt is processed. // ROM_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0); ROM_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0); // // Enable the watchdog interrupt. // ROM_IntEnable(INT_WATCHDOG); // // Set the period of the watchdog timer to 1 second. // ROM_WatchdogReloadSet(WATCHDOG0_BASE, g_ui32SysClock); // // Enable reset generation from the watchdog timer. // ROM_WatchdogResetEnable(WATCHDOG0_BASE); // // Enable the watchdog timer. // ROM_WatchdogEnable(WATCHDOG0_BASE); // // Loop forever while the LED winks as watchdog interrupts are handled. // while(1) { // // Poll for the select button pressed // uint8_t ui8Buttons = ButtonsPoll(0, 0); if(ui8Buttons & USR_SW1) { SW1ButtonPressed(); while(1) { } } } }
//***************************************************************************** // // Toggle the JTAG pins between JTAG and GPIO mode with a push button selecting // between the two. // //***************************************************************************** int main(void) { uint32_t ui32Mode; // // Set the clocking to run directly from the crystal at 120MHz. // g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // // Enable the peripherals used by this application. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION); // // Initialize the button driver. // ButtonsInit(); // // Set up a SysTick Interrupt to handle polling and debouncing for our // buttons. // SysTickPeriodSet(g_ui32SysClock / 100); SysTickIntEnable(); SysTickEnable(); IntMasterEnable(); // // Configure the LEDs as outputs and turn them on in the JTAG state. // ROM_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0 | GPIO_PIN_1); ROM_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0 | GPIO_PIN_1, GPIO_PIN_0); // // Set the global and local indicator of pin mode to zero, meaning JTAG. // g_ui32Mode = 0; ui32Mode = 0; // // Initialize the UART, clear the terminal, print banner. // ConfigureUART(); UARTprintf("\033[2J\033[H"); UARTprintf("GPIO <-> JTAG\n"); // // Indicate that the pins start out as JTAG. // UARTprintf("Pins are JTAG\n"); // // Loop forever. This loop simply exists to display on the UART the // current state of PC0-3; the handling of changing the JTAG pins to and // from GPIO mode is done in GPIO Interrupt Handler. // while(1) { // // Wait until the pin mode changes. // while(g_ui32Mode == ui32Mode) { } // // Save the new mode locally so that a subsequent pin mode change can // be detected. // ui32Mode = g_ui32Mode; // // See what the new pin mode was changed to. // if(ui32Mode == 0) { // // Indicate that PC0-3 are currently JTAG pins. // UARTprintf("Pins are JTAG\n"); } else { // // Indicate that PC0-3 are currently GPIO pins. // UARTprintf("Pins are GPIO\n"); } } }
//***************************************************************************** // // This example encrypts a block of payload using AES128 in CCM mode. It // does the encryption first without uDMA and then with uDMA. The results // are checked after each operation. // //***************************************************************************** int main(void) { uint32_t pui32CipherText[16], pui32Tag[4], ui32Errors, ui32Idx; uint32_t ui32PayloadLength, ui32TagLength; uint32_t ui32NonceLength, ui32AuthDataLength; uint32_t *pui32Nonce, *pui32AuthData, ui32SysClock; uint32_t *pui32Key, *pui32Payload, *pui32ExpCipherText; uint32_t ui32Keysize; uint8_t ui8Vector; uint8_t *pui8ExpTag, *pui8Tag; 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, "aes-ccm-encrypt"); // // Show some instructions on the display // GrContextFontSet(&sContext, g_psFontCm20); GrStringDrawCentered(&sContext, "Connect a terminal to", -1, GrContextDpyWidthGet(&sContext) / 2, 60, false); GrStringDrawCentered(&sContext, "UART0 (115200,N,8,1)", -1, GrContextDpyWidthGet(&sContext) / 2, 80, false); GrStringDrawCentered(&sContext, "for more information.", -1, GrContextDpyWidthGet(&sContext) / 2, 100, false); // // Initialize local variables. // ui32Errors = 0; for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { pui32CipherText[ui32Idx] = 0; } for(ui32Idx = 0; ui32Idx < 4; ui32Idx++) { pui32Tag[ui32Idx] = 0; } pui8Tag = (uint8_t *)pui32Tag; // // Enable stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // ROM_FPUStackingEnable(); // // Configure the system clock to run off the internal 16MHz oscillator. // MAP_SysCtlClockFreqSet(SYSCTL_OSC_INT | SYSCTL_USE_OSC, 16000000); // // Enable AES interrupts. // ROM_IntEnable(INT_AES0); // // Enable debug output on UART0 and print a welcome message. // ConfigureUART(); UARTprintf("Starting AES CCM encryption demo.\n"); GrStringDrawCentered(&sContext, "Starting demo...", -1, GrContextDpyWidthGet(&sContext) / 2, 140, false); // // Enable the uDMA module. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); // // Setup the control table. // ROM_uDMAEnable(); ROM_uDMAControlBaseSet(g_psDMAControlTable); // // Initialize the CCM and AES modules. // if(!AESInit()) { UARTprintf("Initialization of the AES module failed.\n"); ui32Errors |= 0x00000001; } // // Loop through all the given vectors. // for(ui8Vector = 0; (ui8Vector < (sizeof(g_psAESCCMTestVectors) / sizeof(g_psAESCCMTestVectors[0]))) && (ui32Errors == 0); ui8Vector++) { UARTprintf("Starting vector #%d\n", ui8Vector); // // Get the current vector's data members. // ui32Keysize = g_psAESCCMTestVectors[ui8Vector].ui32KeySize; pui32Key = g_psAESCCMTestVectors[ui8Vector].pui32Key; pui32Payload = g_psAESCCMTestVectors[ui8Vector].pui32Payload; ui32PayloadLength = g_psAESCCMTestVectors[ui8Vector].ui32PayloadLength; pui32AuthData = g_psAESCCMTestVectors[ui8Vector].pui32AuthData; ui32AuthDataLength = g_psAESCCMTestVectors[ui8Vector].ui32AuthDataLength; pui32ExpCipherText = g_psAESCCMTestVectors[ui8Vector].pui32CipherText; pui8ExpTag = (uint8_t *)g_psAESCCMTestVectors[ui8Vector].pui32Tag; ui32TagLength = g_psAESCCMTestVectors[ui8Vector].ui32TagLength; pui32Nonce = g_psAESCCMTestVectors[ui8Vector].pui32Nonce; ui32NonceLength = g_psAESCCMTestVectors[ui8Vector].ui32NonceLength; // // Perform the encryption without uDMA. // UARTprintf("Performing encryption without uDMA.\n"); AESCCMEncrypt(ui32Keysize, pui32Key, pui32Payload, pui32CipherText, ui32PayloadLength, pui32Nonce, ui32NonceLength, pui32AuthData, ui32AuthDataLength, pui32Tag, ui32TagLength, false); // // Check the result. // for(ui32Idx = 0; ui32Idx < (ui32PayloadLength / 4); ui32Idx++) { if(pui32CipherText[ui32Idx] != pui32ExpCipherText[ui32Idx]) { UARTprintf("Ciphertext mismatch on word %d. Exp: 0x%x, Act: " "0x%x\n", ui32Idx, pui32ExpCipherText[ui32Idx], pui32CipherText[ui32Idx]); ui32Errors |= (ui32Idx << 16) | 0x00000002; } } for(ui32Idx = 0; ui32Idx < ui32TagLength; ui32Idx++) { if(pui8Tag[ui32Idx] != pui8ExpTag[ui32Idx]) { UARTprintf("Tag mismatch on byte %d. Exp: 0x%x, Act: " "0x%x\n", ui32Idx, pui8ExpTag[ui32Idx], pui8Tag[ui32Idx]); ui32Errors |= (ui32Idx << 16) | 0x00000004; } } // // Clear the array containing the ciphertext. // for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { pui32CipherText[ui32Idx] = 0; } for(ui32Idx = 0; ui32Idx < 4; ui32Idx++) { pui32Tag[ui32Idx] = 0; } // // Perform the encryption with uDMA. // UARTprintf("Performing encryption with uDMA.\n"); AESCCMEncrypt(ui32Keysize, pui32Key, pui32Payload, pui32CipherText, ui32PayloadLength, pui32Nonce, ui32NonceLength, pui32AuthData, ui32AuthDataLength, pui32Tag, ui32TagLength, true); // // Check the result. // for(ui32Idx = 0; ui32Idx < (ui32PayloadLength / 4); ui32Idx++) { if(pui32CipherText[ui32Idx] != pui32ExpCipherText[ui32Idx]) { UARTprintf("Ciphertext mismatch on word %d. Exp: 0x%x, Act: " "0x%x\n", ui32Idx, pui32ExpCipherText[ui32Idx], pui32CipherText[ui32Idx]); ui32Errors |= (ui32Idx << 16) | 0x00000002; } } for(ui32Idx = 0; ui32Idx < ui32TagLength; ui32Idx++) { if(pui8Tag[ui32Idx] != pui8ExpTag[ui32Idx]) { UARTprintf("Tag mismatch on byte %d. Exp: 0x%x, Act: " "0x%x\n", ui32Idx, pui8ExpTag[ui32Idx], pui8Tag[ui32Idx]); ui32Errors |= (ui32Idx << 16) | 0x00000004; } } // // Clear the array containing the ciphertext. // for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { pui32CipherText[ui32Idx] = 0; } for(ui32Idx = 0; ui32Idx < 4; ui32Idx++) { pui32Tag[ui32Idx] = 0; } } // // Finished. // if(ui32Errors) { UARTprintf("Demo failed with error code 0x%x.\n", ui32Errors); GrStringDrawCentered(&sContext, "Demo failed.", -1, GrContextDpyWidthGet(&sContext) / 2, 180, false); } else { UARTprintf("Demo completed successfully.\n"); GrStringDrawCentered(&sContext, "Demo passed.", -1, GrContextDpyWidthGet(&sContext) / 2, 180, false); } while(1) { } }
//***************************************************************************** // // This is the main example program. It checks to see that the interrupts are // processed in the correct order when they have identical priorities, // increasing priorities, and decreasing priorities. This exercises interrupt // preemption and tail chaining. // //***************************************************************************** int main(void) { uint_fast8_t ui8Error; // // Run from the PLL at 120 MHz. // g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // // Configure the device pins. // PinoutSet(false, false); // // Configure the UART. // ConfigureUART(); // // Configure the B3, L1 and L0 to be outputs to indicate entry/exit of one // of the interrupt handlers. // GPIOPinTypeGPIOOutput(GPIO_A_BASE, GPIO_A_PIN); GPIOPinTypeGPIOOutput(GPIO_B_BASE, GPIO_B_PIN); GPIOPinTypeGPIOOutput(GPIO_C_BASE, GPIO_C_PIN); GPIOPinWrite(GPIO_A_BASE, GPIO_A_PIN, 0); GPIOPinWrite(GPIO_B_BASE, GPIO_B_PIN, 0); GPIOPinWrite(GPIO_C_BASE, GPIO_C_PIN, 0); // // Set up and enable the SysTick timer. It will be used as a reference // for delay loops in the interrupt handlers. The SysTick timer period // will be set up for 100 times per second. // ROM_SysTickPeriodSet(g_ui32SysClock / 100); ROM_SysTickEnable(); // // Reset the error indicator. // ui8Error = 0; // // Enable interrupts to the processor. // ROM_IntMasterEnable(); // // Enable the interrupts. // ROM_IntEnable(INT_GPIOA); ROM_IntEnable(INT_GPIOB); ROM_IntEnable(INT_GPIOC); // // Indicate that the equal interrupt priority test is beginning. // g_ui32IntMode = EQUAL_PRIORITY; // // Set the interrupt priorities so they are all equal. // ROM_IntPrioritySet(INT_GPIOA, 0x00); ROM_IntPrioritySet(INT_GPIOB, 0x00); ROM_IntPrioritySet(INT_GPIOC, 0x00); // // Reset the interrupt flags. // g_ui32GPIOa = 0; g_ui32GPIOb = 0; g_ui32GPIOc = 0; g_ui32Index = 1; // // Trigger the interrupt for GPIO C. // HWREG(NVIC_SW_TRIG) = INT_GPIOC - 16; // // Put the current interrupt state on the LCD. // DisplayIntStatus(); // // Verify that the interrupts were processed in the correct order. // if((g_ui32GPIOa != 3) || (g_ui32GPIOb != 2) || (g_ui32GPIOc != 1)) { ui8Error |= 1; } // // Wait two seconds. // Delay(2); // // Indicate that the decreasing interrupt priority test is beginning. // g_ui32IntMode = DECREASING_PRIORITY; // // Set the interrupt priorities so that they are decreasing (i.e. C > B > // A). // ROM_IntPrioritySet(INT_GPIOA, 0x80); ROM_IntPrioritySet(INT_GPIOB, 0x40); ROM_IntPrioritySet(INT_GPIOC, 0x00); // // Reset the interrupt flags. // g_ui32GPIOa = 0; g_ui32GPIOb = 0; g_ui32GPIOc = 0; g_ui32Index = 1; // // Trigger the interrupt for GPIO C. // HWREG(NVIC_SW_TRIG) = INT_GPIOC - 16; // // Put the current interrupt state on the UART. // DisplayIntStatus(); // // Verify that the interrupts were processed in the correct order. // if((g_ui32GPIOa != 3) || (g_ui32GPIOb != 2) || (g_ui32GPIOc != 1)) { ui8Error |= 2; } // // Wait two seconds. // Delay(2); // // Indicate that the increasing interrupt priority test is beginning. // g_ui32IntMode = INCREASING_PRIORITY; // // Set the interrupt priorities so that they are increasing (i.e. C < B < // A). // ROM_IntPrioritySet(INT_GPIOA, 0x00); ROM_IntPrioritySet(INT_GPIOB, 0x40); ROM_IntPrioritySet(INT_GPIOC, 0x80); // // Reset the interrupt flags. // g_ui32GPIOa = 0; g_ui32GPIOb = 0; g_ui32GPIOc = 0; g_ui32Index = 1; // // Trigger the interrupt for GPIO C. // HWREG(NVIC_SW_TRIG) = INT_GPIOC - 16; // // Put the current interrupt state on the UART. // DisplayIntStatus(); // // Verify that the interrupts were processed in the correct order. // if((g_ui32GPIOa != 1) || (g_ui32GPIOb != 2) || (g_ui32GPIOc != 3)) { ui8Error |= 4; } // // Wait two seconds. // Delay(2); // // Disable the interrupts. // ROM_IntDisable(INT_GPIOA); ROM_IntDisable(INT_GPIOB); ROM_IntDisable(INT_GPIOC); // // Disable interrupts to the processor. // ROM_IntMasterDisable(); // // Print out the test results. // UARTprintf("\033[2J\033[H"); UARTprintf("Interrupts example\n\n"); if(ui8Error) { if(ui8Error & 1) { UARTprintf("Equal Priority Fail!\n"); } if(ui8Error & 2) { UARTprintf("Decreasing Priority Fail!\n"); } if(ui8Error & 4) { UARTprintf("Increasing Priority Fail!\n"); } } else { UARTprintf("Success!"); } // // Loop forever. // while(1) { } }
//-----------------Program------------------------------------------// int main() { // specifies a system reset when using external reset pin SysCtlResetBehaviorSet(SYSCTL_ONRST_EXT_SYS); //------------------set sys clock to 120 MHZ ------------------------// g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ| SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), g_freq); //-----------------Enable Periph-------------------------------------// ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOM); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART3); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART7); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_PERIODIC); ROM_TimerLoadSet(TIMER0_BASE, TIMER_B, g_freq/12000); ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMB_TIMEOUT); ROM_UARTIntEnable(UART3_BASE,UART_INT_RX); ROM_IntPrioritySet(INT_UART3, 0); ROM_IntPrioritySet(INT_TIMER0B,1); ROM_IntEnable(INT_UART3); ROM_IntEnable(INT_TIMER0B); //-------------Set Pins ---------------------------// ROM_GPIOPinTypeGPIOOutput(GPIO_PORTM_BASE, GPIO_PIN_4); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTM_BASE, GPIO_PIN_5); ROM_GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_4 | GPIO_PIN_5); ROM_GPIOPinTypeUART(GPIO_PORTJ_BASE, GPIO_PIN_0 | GPIO_PIN_1); ROM_GPIOPinConfigure(GPIO_PC4_U7RX); ROM_GPIOPinConfigure(GPIO_PC5_U7TX); ROM_GPIOPinConfigure(GPIO_PJ0_U3RX); ROM_GPIOPinConfigure(GPIO_PJ1_U3TX); ROM_UARTConfigSetExpClk(UART3_BASE, g_ui32SysClock, 1000000, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE| UART_CONFIG_PAR_NONE)); ROM_UARTConfigSetExpClk(UART7_BASE, g_ui32SysClock, 1000000, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); ROM_TimerEnable(TIMER0_BASE, TIMER_B); ROM_UARTEnable(UART3_BASE); ROM_UARTEnable(UART7_BASE); ROM_GPIOPinWrite(GPIO_PORTM_BASE, GPIO_PIN_4, GPIO_PIN_4); ROM_IntMasterEnable(); uart_parser_payload_write_pos = 0; uart_parser_state = RX_PREABLE0; char write_buf[2]; char* w_buf = write_buf; g_ui32Counter = 0; // ---------------------MAIN LOOP -----------------------------------// while(1) { DymxlReadDataBlocking(36,2,1); // need to turn timer off eventually state =!state; if(state) ROM_GPIOPinWrite(GPIO_PORTM_BASE, GPIO_PIN_4| GPIO_PIN_5, GPIO_PIN_4); else ROM_GPIOPinWrite(GPIO_PORTM_BASE, GPIO_PIN_4| GPIO_PIN_5, GPIO_PIN_5); } return 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) { } }
//***************************************************************************** // // A simple demonstration of the features of the TivaWare Graphics Library. // //***************************************************************************** int main(void) { tContext sContext; tRectangle sRect; // // The FPU should be enabled because some compilers will use floating- // point registers, even for non-floating-point code. If the FPU is not // enabled this will cause a fault. This also ensures that floating- // point operations could be added to this application and would work // correctly and use the hardware floating-point unit. Finally, lazy // stacking is enabled for interrupt handlers. This allows floating- // point instructions to be used within interrupt handlers, but at the // expense of extra stack usage. // FPUEnable(); FPULazyStackingEnable(); // // Run from the PLL at 120 MHz. // g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // // Initialize the display driver. // Kentec320x240x16_SSD2119Init(g_ui32SysClock); // // Initialize the graphics context. // GrContextInit(&sContext, &g_sKentec320x240x16_SSD2119); // // Fill the top 24 rows of the screen with blue to create the banner. // sRect.i16XMin = 0; sRect.i16YMin = 0; sRect.i16XMax = GrContextDpyWidthGet(&sContext) - 1; sRect.i16YMax = 23; GrContextForegroundSet(&sContext, ClrDarkBlue); GrRectFill(&sContext, &sRect); // // Put a white box around the banner. // GrContextForegroundSet(&sContext, ClrWhite); GrRectDraw(&sContext, &sRect); // // Put the application name in the middle of the banner. // GrContextFontSet(&sContext, &g_sFontCm20); GrStringDrawCentered(&sContext, "grlib demo", -1, GrContextDpyWidthGet(&sContext) / 2, 8, 0); // // Configure and enable uDMA // SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); SysCtlDelay(10); uDMAControlBaseSet(&psDMAControlTable[0]); uDMAEnable(); // // Initialize the touch screen driver and have it route its messages to the // widget tree. // TouchScreenInit(g_ui32SysClock); TouchScreenCallbackSet(WidgetPointerMessage); // // Add the title block and the previous and next buttons to the widget // tree. // WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sPrevious); WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sTitle); WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sNext); // // Add the first panel to the widget tree. // g_ui32Panel = 0; WidgetAdd(WIDGET_ROOT, (tWidget *)g_psPanels); CanvasTextSet(&g_sTitle, g_pcPanei32Names[0]); // // Issue the initial paint request to the widgets. // WidgetPaint(WIDGET_ROOT); // // Loop forever handling widget messages. // while(1) { // // Process any messages in the widget message queue. // WidgetMessageQueueProcess(); } }
//***************************************************************************** // // Performs calibration of the touch screen. // //***************************************************************************** int main(void) { int32_t i32Idx, i32X1, i32Y1, i32X2, i32Y2, i32Count, ppi32Points[3][4]; uint32_t ui32SysClock; char pcBuffer[32]; tContext sContext; tRectangle sRect; // // 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, "calibrate"); // // Print the instructions across the middle of the screen in white with a // 20 point small-caps font. // GrContextForegroundSet(&sContext, ClrWhite); GrContextFontSet(&sContext, g_psFontCmsc20); GrStringDrawCentered(&sContext, "Touch the box", -1, GrContextDpyWidthGet(&sContext) / 2, (GrContextDpyHeightGet(&sContext) / 2) - 10, 0); // // Set the points used for calibration based on the size of the screen. // ppi32Points[0][0] = GrContextDpyWidthGet(&sContext) / 10; ppi32Points[0][1] = (GrContextDpyHeightGet(&sContext) * 2) / 10; ppi32Points[1][0] = GrContextDpyWidthGet(&sContext) / 2; ppi32Points[1][1] = (GrContextDpyHeightGet(&sContext) * 9) / 10; ppi32Points[2][0] = (GrContextDpyWidthGet(&sContext) * 9) / 10; ppi32Points[2][1] = GrContextDpyHeightGet(&sContext) / 2; // // Initialize the touch screen driver. // TouchScreenInit(ui32SysClock); // // Loop through the calibration points. // for(i32Idx = 0; i32Idx < 3; i32Idx++) { // // Fill a white box around the calibration point. // GrContextForegroundSet(&sContext, ClrWhite); sRect.i16XMin = ppi32Points[i32Idx][0] - 5; sRect.i16YMin = ppi32Points[i32Idx][1] - 5; sRect.i16XMax = ppi32Points[i32Idx][0] + 5; sRect.i16YMax = ppi32Points[i32Idx][1] + 5; GrRectFill(&sContext, &sRect); // // Flush any cached drawing operations. // GrFlush(&sContext); // // Initialize the raw sample accumulators and the sample count. // i32X1 = 0; i32Y1 = 0; i32Count = -5; // // Loop forever. This loop is explicitly broken out of when the pen is // lifted. // while(1) { // // Grab the current raw touch screen position. // i32X2 = g_i16TouchX; i32Y2 = g_i16TouchY; // // See if the pen is up or down. // if((i32X2 < g_i16TouchMin) || (i32Y2 < g_i16TouchMin)) { // // The pen is up, so see if any samples have been accumulated. // if(i32Count > 0) { // // The pen has just been lifted from the screen, so break // out of the controlling while loop. // break; } // // Reset the accumulators and sample count. // i32X1 = 0; i32Y1 = 0; i32Count = -5; // // Grab the next sample. // continue; } // // Increment the count of samples. // i32Count++; // // If the sample count is greater than zero, add this sample to the // accumulators. // if(i32Count > 0) { i32X1 += i32X2; i32Y1 += i32Y2; } } // // Save the averaged raw ADC reading for this calibration point. // ppi32Points[i32Idx][2] = i32X1 / i32Count; ppi32Points[i32Idx][3] = i32Y1 / i32Count; // // Erase the box around this calibration point. // GrContextForegroundSet(&sContext, ClrBlack); GrRectFill(&sContext, &sRect); } // // Clear the screen. // sRect.i16XMin = 0; sRect.i16YMin = 0; sRect.i16XMax = GrContextDpyWidthGet(&sContext) - 1; sRect.i16YMax = GrContextDpyHeightGet(&sContext) - 1; GrRectFill(&sContext, &sRect); // // Indicate that the calibration data is being displayed. // GrContextForegroundSet(&sContext, ClrWhite); GrStringDraw(&sContext, "Calibration data:", -1, 16, 32, 0); // // Compute and display the M0 calibration value. // usprintf(pcBuffer, "M0 = %d", (((ppi32Points[0][0] - ppi32Points[2][0]) * (ppi32Points[1][3] - ppi32Points[2][3])) - ((ppi32Points[1][0] - ppi32Points[2][0]) * (ppi32Points[0][3] - ppi32Points[2][3])))); GrStringDraw(&sContext, pcBuffer, -1, 16, 72, 0); // // Compute and display the M1 calibration value. // usprintf(pcBuffer, "M1 = %d", (((ppi32Points[0][2] - ppi32Points[2][2]) * (ppi32Points[1][0] - ppi32Points[2][0])) - ((ppi32Points[0][0] - ppi32Points[2][0]) * (ppi32Points[1][2] - ppi32Points[2][2])))); GrStringDraw(&sContext, pcBuffer, -1, 16, 92, 0); // // Compute and display the M2 calibration value. // usprintf(pcBuffer, "M2 = %d", ((((ppi32Points[2][2] * ppi32Points[1][0]) - (ppi32Points[1][2] * ppi32Points[2][0])) * ppi32Points[0][3]) + (((ppi32Points[0][2] * ppi32Points[2][0]) - (ppi32Points[2][2] * ppi32Points[0][0])) * ppi32Points[1][3]) + (((ppi32Points[1][2] * ppi32Points[0][0]) - (ppi32Points[0][2] * ppi32Points[1][0])) * ppi32Points[2][3]))); GrStringDraw(&sContext, pcBuffer, -1, 16, 112, 0); // // Compute and display the M3 calibration value. // usprintf(pcBuffer, "M3 = %d", (((ppi32Points[0][1] - ppi32Points[2][1]) * (ppi32Points[1][3] - ppi32Points[2][3])) - ((ppi32Points[1][1] - ppi32Points[2][1]) * (ppi32Points[0][3] - ppi32Points[2][3])))); GrStringDraw(&sContext, pcBuffer, -1, 16, 132, 0); // // Compute and display the M4 calibration value. // usprintf(pcBuffer, "M4 = %d", (((ppi32Points[0][2] - ppi32Points[2][2]) * (ppi32Points[1][1] - ppi32Points[2][1])) - ((ppi32Points[0][1] - ppi32Points[2][1]) * (ppi32Points[1][2] - ppi32Points[2][2])))); GrStringDraw(&sContext, pcBuffer, -1, 16, 152, 0); // // Compute and display the M5 calibration value. // usprintf(pcBuffer, "M5 = %d", ((((ppi32Points[2][2] * ppi32Points[1][1]) - (ppi32Points[1][2] * ppi32Points[2][1])) * ppi32Points[0][3]) + (((ppi32Points[0][2] * ppi32Points[2][1]) - (ppi32Points[2][2] * ppi32Points[0][1])) * ppi32Points[1][3]) + (((ppi32Points[1][2] * ppi32Points[0][1]) - (ppi32Points[0][2] * ppi32Points[1][1])) * ppi32Points[2][3]))); GrStringDraw(&sContext, pcBuffer, -1, 16, 172, 0); // // Compute and display the M6 calibration value. // usprintf(pcBuffer, "M6 = %d", (((ppi32Points[0][2] - ppi32Points[2][2]) * (ppi32Points[1][3] - ppi32Points[2][3])) - ((ppi32Points[1][2] - ppi32Points[2][2]) * (ppi32Points[0][3] - ppi32Points[2][3])))); GrStringDraw(&sContext, pcBuffer, -1, 16, 192, 0); // // Flush any cached drawing operations. // GrFlush(&sContext); // // The calibration is complete. Sit around and wait for a reset. // while(1) { } }
//***************************************************************************** // // Main 'C' Language entry point. // //***************************************************************************** int main(void) { float fTemperature, fPressure, fAltitude; int32_t i32IntegerPart; int32_t i32FractionPart; tContext sContext; uint32_t ui32SysClock; char pcBuf[15]; // // Setup the system clock to run at 40 Mhz from PLL with crystal reference // ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 40000000); // // Configure the device pins. // PinoutSet(); // // Initialize the display driver. // Kentec320x240x16_SSD2119Init(ui32SysClock); // // Initialize the graphics context. // GrContextInit(&sContext, &g_sKentec320x240x16_SSD2119); // // Draw the application frame. // FrameDraw(&sContext, "bmp180"); // // Flush any cached drawing operations. // GrFlush(&sContext); // // Enable UART0 // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); // // Initialize the UART for console I/O. // UARTStdioConfig(0, 115200, ui32SysClock); // // Print the welcome message to the terminal. // UARTprintf("\033[2JBMP180 Example\n"); // // The I2C3 peripheral must be enabled before use. // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C3); // // Configure the pin muxing for I2C3 functions on port G4 and G5. // This step is not necessary if your part does not support pin muxing. // MAP_GPIOPinConfigure(GPIO_PG4_I2C3SCL); MAP_GPIOPinConfigure(GPIO_PG5_I2C3SDA); // // Select the I2C function for these pins. This function will also // configure the GPIO pins pins for I2C operation, setting them to // open-drain operation with weak pull-ups. Consult the data sheet // to see which functions are allocated per pin. // MAP_GPIOPinTypeI2CSCL(GPIO_PORTG_BASE, GPIO_PIN_4); MAP_GPIOPinTypeI2C(GPIO_PORTG_BASE, GPIO_PIN_5); // // Enable interrupts to the processor. // MAP_IntMasterEnable(); // // Initialize I2C3 peripheral. // I2CMInit(&g_sI2CInst, I2C3_BASE, INT_I2C3, 0xff, 0xff, ui32SysClock); // // Initialize the BMP180 // BMP180Init(&g_sBMP180Inst, &g_sI2CInst, BMP180_I2C_ADDRESS, BMP180AppCallback, &g_sBMP180Inst); // // Wait for initialization callback to indicate reset request is complete. // while(g_vui8DataFlag == 0) { // // Wait for I2C Transactions to complete. // } // // Reset the data ready flag // g_vui8DataFlag = 0; // // Enable the system ticks at 10 hz. // MAP_SysTickPeriodSet(ui32SysClock / (10 * 3)); MAP_SysTickIntEnable(); MAP_SysTickEnable(); // // Configure PQ4 to control the blue LED. // MAP_GPIOPinTypeGPIOOutput(GPIO_PORTQ_BASE, GPIO_PIN_4); // // Print temperature, pressure and altitude labels once on the LCD. // GrStringDraw(&sContext, "Temperature", 11, ((GrContextDpyWidthGet(&sContext) / 2) - 96), ((GrContextDpyHeightGet(&sContext) - 32) / 2) - 24, 1); GrStringDraw(&sContext, "Pressure", 8, ((GrContextDpyWidthGet(&sContext) / 2) - 63), (GrContextDpyHeightGet(&sContext) - 32) / 2, 1); GrStringDraw(&sContext, "Altitude", 8, ((GrContextDpyWidthGet(&sContext) / 2) - 59), ((GrContextDpyHeightGet(&sContext) - 32) / 2) + 24, 1); // // Begin the data collection and printing. Loop Forever. // while(1) { // // Read the data from the BMP180 over I2C. This command starts a // temperature measurement. Then polls until temperature is ready. // Then automatically starts a pressure measurement and polls for that // to complete. When both measurement are complete and in the local // buffer then the application callback is called from the I2C // interrupt context. Polling is done on I2C interrupts allowing // processor to continue doing other tasks as needed. // BMP180DataRead(&g_sBMP180Inst, BMP180AppCallback, &g_sBMP180Inst); while(g_vui8DataFlag == 0) { // // Wait for the new data set to be available. // } // // Reset the data ready flag. // g_vui8DataFlag = 0; // // Get a local copy of the latest temperature data in float format. // BMP180DataTemperatureGetFloat(&g_sBMP180Inst, &fTemperature); // // Convert the floats to an integer part and fraction part for easy // print. // i32IntegerPart = (int32_t) fTemperature; i32FractionPart =(int32_t) (fTemperature * 1000.0f); i32FractionPart = i32FractionPart - (i32IntegerPart * 1000); if(i32FractionPart < 0) { i32FractionPart *= -1; } // // Print temperature with three digits of decimal precision to LCD and // terminal. // usnprintf(pcBuf, sizeof(pcBuf), "%03d.%03d ", i32IntegerPart, i32FractionPart); GrStringDraw(&sContext, pcBuf, 8, ((GrContextDpyWidthGet(&sContext) / 2) + 16), ((GrContextDpyHeightGet(&sContext) - 32) / 2) - 24, 1); UARTprintf("Temperature %3d.%03d\t\t", i32IntegerPart, i32FractionPart); // // Get a local copy of the latest air pressure data in float format. // BMP180DataPressureGetFloat(&g_sBMP180Inst, &fPressure); // // Convert the floats to an integer part and fraction part for easy // print. // i32IntegerPart = (int32_t) fPressure; i32FractionPart =(int32_t) (fPressure * 1000.0f); i32FractionPart = i32FractionPart - (i32IntegerPart * 1000); if(i32FractionPart < 0) { i32FractionPart *= -1; } // // Print Pressure with three digits of decimal precision to LCD and // terminal. // usnprintf(pcBuf, sizeof(pcBuf), "%3d.%03d ", i32IntegerPart, i32FractionPart); GrStringDraw(&sContext, pcBuf, -1, ((GrContextDpyWidthGet(&sContext) / 2) + 16), (GrContextDpyHeightGet(&sContext) - 32) / 2, 1); UARTprintf("Pressure %3d.%03d\t\t", i32IntegerPart, i32FractionPart); // // Calculate the altitude. // fAltitude = 44330.0f * (1.0f - powf(fPressure / 101325.0f, 1.0f / 5.255f)); // // Convert the floats to an integer part and fraction part for easy // print. // i32IntegerPart = (int32_t) fAltitude; i32FractionPart =(int32_t) (fAltitude * 1000.0f); i32FractionPart = i32FractionPart - (i32IntegerPart * 1000); if(i32FractionPart < 0) { i32FractionPart *= -1; } // // Print altitude with three digits of decimal precision to LCD and // terminal. // usnprintf(pcBuf, sizeof(pcBuf), "%3d.%03d ", i32IntegerPart, i32FractionPart); GrStringDraw(&sContext, pcBuf, 8, ((GrContextDpyWidthGet(&sContext) / 2) + 16), ((GrContextDpyHeightGet(&sContext) - 32) / 2) + 24, 1); UARTprintf("Altitude %3d.%03d", i32IntegerPart, i32FractionPart); // // Print new line. // UARTprintf("\n"); // // Delay to keep printing speed reasonable. About 100 milliseconds. // MAP_SysCtlDelay(ui32SysClock / (10 * 3)); } }
//***************************************************************************** // // 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 at 120MHz. // g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // // Enable the GPIO port that is used for the on-board LED. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION); // // Enable the GPIO pins for the LED (PN0). // ROM_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0); // // Enable the peripherals used by this example. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // // Enable processor interrupts. // ROM_IntMasterEnable(); // // Set GPIO A0 and A1 as UART pins. // GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // Configure the UART for 115,200, 8-N-1 operation. // ROM_UARTConfigSetExpClk(UART0_BASE, g_ui32SysClock, 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); // // Enable the UART interrupt. // ROM_IntEnable(INT_UART0); ROM_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT); // // Prompt for text to be entered. // UARTSend((uint8_t *)"\033[2JEnter text: ", 16); // // Loop forever echoing data through the UART. // while(1) { } }
//***************************************************************************** // // This example decrypts blocks ciphertext using AES128 and AES256 in GCM // mode. It does the decryption first without uDMA and then with uDMA. // The results are checked after each operation. // //***************************************************************************** int main(void) { uint32_t pui32PlainText[64], pui32Tag[4], pui32Y0[4], ui32Errors, ui32Idx; uint32_t *pui32Key, ui32IVLength, *pui32IV, ui32DataLength; uint32_t *pui32ExpPlainText, ui32AuthDataLength, *pui32AuthData; uint32_t *pui32CipherText, *pui32ExpTag; uint32_t ui32KeySize; uint32_t ui32SysClock; uint8_t ui8Vector; 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, "aes-gcm-decrypt"); // // Show some instructions on the display // GrContextFontSet(&sContext, g_psFontCm20); GrContextForegroundSet(&sContext, ClrWhite); GrStringDrawCentered(&sContext, "Connect a terminal to", -1, GrContextDpyWidthGet(&sContext) / 2, 60, false); GrStringDrawCentered(&sContext, "UART0 (115200,N,8,1)", -1, GrContextDpyWidthGet(&sContext) / 2, 80, false); GrStringDrawCentered(&sContext, "for more information.", -1, GrContextDpyWidthGet(&sContext) / 2, 100, false); // // Initialize local variables. // ui32Errors = 0; for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { pui32PlainText[ui32Idx] = 0; } for(ui32Idx = 0; ui32Idx < 4; ui32Idx++) { pui32Tag[ui32Idx] = 0; } // // Enable stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // ROM_FPUStackingEnable(); // // Enable AES interrupts. // ROM_IntEnable(INT_AES0); // // Enable debug output on UART0 and print a welcome message. // ConfigureUART(); UARTprintf("Starting AES GCM decryption demo.\n"); GrStringDrawCentered(&sContext, "Starting demo...", -1, GrContextDpyWidthGet(&sContext) / 2, 140, false); // // Enable the uDMA module. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); // // Setup the control table. // ROM_uDMAEnable(); ROM_uDMAControlBaseSet(g_psDMAControlTable); // // Initialize the CCM and AES modules. // if(!AESInit()) { UARTprintf("Initialization of the AES module failed.\n"); ui32Errors |= 0x00000001; } // // Loop through all the given vectors. // for(ui8Vector = 0; (ui8Vector < (sizeof(g_psAESGCMTestVectors) / sizeof(g_psAESGCMTestVectors[0]))) && (ui32Errors == 0); ui8Vector++) { UARTprintf("Starting vector #%d\n", ui8Vector); // // Get the current vector's data members. // ui32KeySize = g_psAESGCMTestVectors[ui8Vector].ui32KeySize; pui32Key = g_psAESGCMTestVectors[ui8Vector].pui32Key; ui32IVLength = g_psAESGCMTestVectors[ui8Vector].ui32IVLength; pui32IV = g_psAESGCMTestVectors[ui8Vector].pui32IV; ui32DataLength = g_psAESGCMTestVectors[ui8Vector].ui32DataLength; pui32ExpPlainText = g_psAESGCMTestVectors[ui8Vector].pui32PlainText; ui32AuthDataLength = g_psAESGCMTestVectors[ui8Vector].ui32AuthDataLength; pui32AuthData = g_psAESGCMTestVectors[ui8Vector].pui32AuthData; pui32CipherText = g_psAESGCMTestVectors[ui8Vector].pui32CipherText; pui32ExpTag = g_psAESGCMTestVectors[ui8Vector].pui32Tag; // // If both the data lengths are zero, then it's a special case. // if((ui32DataLength == 0) && (ui32AuthDataLength == 0)) { UARTprintf("Performing decryption without uDMA.\n"); // // Figure out the value of Y0 depending on the IV length. // AESGCMY0Get(ui32KeySize, pui32IV, ui32IVLength, pui32Key, pui32Y0); // // Perform the basic encryption. // AESECBEncrypt(ui32KeySize, pui32Y0, pui32Tag, pui32Key, 16); } else { // // Figure out the value of Y0 depending on the IV length. // AESGCMY0Get(ui32KeySize, pui32IV, ui32IVLength, pui32Key, pui32Y0); // // Perform the decryption without uDMA. // UARTprintf("Performing decryption without uDMA.\n"); AESGCMDecrypt(ui32KeySize, pui32CipherText, pui32PlainText, ui32DataLength, pui32Key, pui32Y0, pui32AuthData, ui32AuthDataLength, pui32Tag, false); } // // Check the results. // for(ui32Idx = 0; ui32Idx < (ui32DataLength / 4); ui32Idx++) { if(pui32ExpPlainText[ui32Idx] != pui32PlainText[ui32Idx]) { UARTprintf("Plaintext mismatch on word %d. Exp: 0x%x, Act: " "0x%x\n", ui32Idx, pui32ExpPlainText[ui32Idx], pui32PlainText[ui32Idx]); ui32Errors |= (ui32Idx << 16) | 0x00000002; } } for(ui32Idx = 0; ui32Idx < 4; ui32Idx++) { if(pui32ExpTag[ui32Idx] != pui32Tag[ui32Idx]) { UARTprintf("Tag mismatch on word %d. Exp: 0x%x, Act: 0x%x\n", ui32Idx, pui32ExpTag[ui32Idx], pui32Tag[ui32Idx]); ui32Errors |= (ui32Idx << 16) | 0x00000003; } } // // Clear the arrays containing the ciphertext and tag to ensure things // are working correctly. // for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { pui32PlainText[ui32Idx] = 0; } for(ui32Idx = 0; ui32Idx < 4; ui32Idx++) { pui32Tag[ui32Idx] = 0; } // // Only use DMA with the vectors that have data. // if((ui32DataLength != 0) || (ui32AuthDataLength != 0)) { // // Perform the decryption with uDMA. // UARTprintf("Performing decryption with uDMA.\n"); AESGCMDecrypt(ui32KeySize, pui32CipherText, pui32PlainText, ui32DataLength, pui32Key, pui32Y0, pui32AuthData, ui32AuthDataLength, pui32Tag, true); // // Check the result. // for(ui32Idx = 0; ui32Idx < (ui32DataLength / 4); ui32Idx++) { if(pui32ExpPlainText[ui32Idx] != pui32PlainText[ui32Idx]) { UARTprintf("Plaintext mismatch on word %d. Exp: 0x%x, " "Act: 0x%x\n", ui32Idx, pui32ExpPlainText[ui32Idx], pui32PlainText[ui32Idx]); ui32Errors |= (ui32Idx << 16) | 0x00000002; } } for(ui32Idx = 0; ui32Idx < 4; ui32Idx++) { if(pui32ExpTag[ui32Idx] != pui32Tag[ui32Idx]) { UARTprintf("Tag mismatch on word %d. Exp: 0x%x, Act: " "0x%x\n", ui32Idx, pui32ExpTag[ui32Idx], pui32Tag[ui32Idx]); ui32Errors |= (ui32Idx << 16) | 0x00000003; } } } } // // Finished. // if(ui32Errors) { UARTprintf("Demo failed with error code 0x%x.\n", ui32Errors); GrStringDrawCentered(&sContext, "Demo failed.", -1, GrContextDpyWidthGet(&sContext) / 2, 180, false); } else { UARTprintf("Demo completed successfully.\n"); GrStringDrawCentered(&sContext, "Demo passed.", -1, GrContextDpyWidthGet(&sContext) / 2, 180, false); } // // Wait forever. // while(1) { } }