static void initDMA() { // Init DMA ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); ROM_uDMAEnable(); ROM_uDMAControlBaseSet(g_sDMAControlTable); uDMAChannelAttributeDisable(UDMA_CHANNEL_ETH0TX, UDMA_ATTR_ALL); uDMAChannelControlSet(UDMA_CHANNEL_ETH0TX, UDMA_SIZE_32 | UDMA_SRC_INC_32 | UDMA_DST_INC_NONE | UDMA_ARB_8); }
void msc_init() { // // Configure and enable uDMA // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); ROM_GPIOPinTypeUSBAnalog(GPIO_PORTD_BASE, GPIO_PIN_5 | GPIO_PIN_4); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); SysCtlDelay(10); ROM_uDMAControlBaseSet(&sDMAControlTable[0]); ROM_uDMAEnable(); // // Initialize the idle timeout and reset all flags. // g_ulIdleTimeout = 0; g_ulFlags = 0; g_eMSCState = MSC_DEV_DISCONNECTED; // // Set the USB stack mode to Device mode with VBUS monitoring. // USBStackModeSet(0, USB_MODE_DEVICE, 0); // // Pass our device information to the USB library and place the device // on the bus. // USBDMSCInit(0, (tUSBDMSCDevice *)&g_sMSCDevice); // // Determine whether or not an SDCard is installed. If not, print a // warning and have the user install one and restart. // disk_initialize(0); }
//***************************************************************************** // // This example demonstrates how to use the uDMA controller to transfer data // between memory buffers and to and from a peripheral, in this case a UART. // The uDMA controller is configured to repeatedly transfer a block of data // from one memory buffer to another. It is also set up to repeatedly copy a // block of data from a buffer to the UART output. The UART data is looped // back so the same data is received, and the uDMA controlled is configured to // continuously receive the UART data using ping-pong buffers. // // The processor is put to sleep when it is not doing anything, and this allows // collection of CPU usage data to see how much CPU is being used while the // data transfers are ongoing. // //***************************************************************************** int main(void) { static uint32_t ui32PrevSeconds; static uint32_t ui32PrevXferCount; static uint32_t ui32PrevUARTCount = 0; uint32_t ui32XfersCompleted; uint32_t ui32BytesTransferred; // // 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 50 MHz. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Enable peripherals to operate when CPU is in sleep. // ROM_SysCtlPeripheralClockGating(true); // // Enable the GPIO port that is used for the on-board LED. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // // Enable the GPIO pins for the LED (PF2). // ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2); // // Initialize the UART. // ConfigureUART(); UARTprintf("\033[2JuDMA Example\n"); // // Show the clock frequency on the display. // UARTprintf("Tiva C Series @ %u MHz\n\n", ROM_SysCtlClockGet() / 1000000); // // Show statistics headings. // UARTprintf("CPU Memory UART Remaining\n"); UARTprintf("Usage Transfers Transfers Time\n"); // // Configure SysTick to occur 100 times per second, to use as a time // reference. Enable SysTick to generate interrupts. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND); ROM_SysTickIntEnable(); ROM_SysTickEnable(); // // Initialize the CPU usage measurement routine. // CPUUsageInit(ROM_SysCtlClockGet(), SYSTICKS_PER_SECOND, 2); // // Enable the uDMA controller at the system level. Enable it to continue // to run while the processor is in sleep. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UDMA); // // Enable the uDMA controller error interrupt. This interrupt will occur // if there is a bus error during a transfer. // ROM_IntEnable(INT_UDMAERR); // // Enable the uDMA controller. // ROM_uDMAEnable(); // // Point at the control table to use for channel control structures. // ROM_uDMAControlBaseSet(ui8ControlTable); // // Initialize the uDMA memory to memory transfers. // InitSWTransfer(); // // Initialize the uDMA UART transfers. // InitUART1Transfer(); // // Remember the current SysTick seconds count. // ui32PrevSeconds = g_ui32Seconds; // // Remember the current count of memory buffer transfers. // ui32PrevXferCount = g_ui32MemXferCount; // // Loop until the button is pressed. The processor is put to sleep // in this loop so that CPU utilization can be measured. // while(1) { // // Check to see if one second has elapsed. If so, the make some // updates. // if(g_ui32Seconds != ui32PrevSeconds) { // // Turn on the LED as a heartbeat // GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2); // // Print a message to the display showing the CPU usage percent. // The fractional part of the percent value is ignored. // UARTprintf("\r%3d%% ", g_ui32CPUUsage >> 16); // // Remember the new seconds count. // ui32PrevSeconds = g_ui32Seconds; // // Calculate how many memory transfers have occurred since the last // second. // ui32XfersCompleted = g_ui32MemXferCount - ui32PrevXferCount; // // Remember the new transfer count. // ui32PrevXferCount = g_ui32MemXferCount; // // Compute how many bytes were transferred in the memory transfer // since the last second. // ui32BytesTransferred = ui32XfersCompleted * MEM_BUFFER_SIZE * 4; // // Print a message showing the memory transfer rate. // if(ui32BytesTransferred >= 100000000) { UARTprintf("%3d MB/s ", ui32BytesTransferred / 1000000); } else if(ui32BytesTransferred >= 10000000) { UARTprintf("%2d.%01d MB/s ", ui32BytesTransferred / 1000000, (ui32BytesTransferred % 1000000) / 100000); } else if(ui32BytesTransferred >= 1000000) { UARTprintf("%1d.%02d MB/s ", ui32BytesTransferred / 1000000, (ui32BytesTransferred % 1000000) / 10000); } else if(ui32BytesTransferred >= 100000) { UARTprintf("%3d KB/s ", ui32BytesTransferred / 1000); } else if(ui32BytesTransferred >= 10000) { UARTprintf("%2d.%01d KB/s ", ui32BytesTransferred / 1000, (ui32BytesTransferred % 1000) / 100); } else if(ui32BytesTransferred >= 1000) { UARTprintf("%1d.%02d KB/s ", ui32BytesTransferred / 1000, (ui32BytesTransferred % 1000) / 10); } else if(ui32BytesTransferred >= 100) { UARTprintf("%3d B/s ", ui32BytesTransferred); } else if(ui32BytesTransferred >= 10) { UARTprintf("%2d B/s ", ui32BytesTransferred); } else { UARTprintf("%1d B/s ", ui32BytesTransferred); } // // Calculate how many UART transfers have occurred since the last // second. // ui32XfersCompleted = (g_ui32RxBufACount + g_ui32RxBufBCount - ui32PrevUARTCount); // // Remember the new UART transfer count. // ui32PrevUARTCount = g_ui32RxBufACount + g_ui32RxBufBCount; // // Compute how many bytes were transferred by the UART. The number // of bytes received is multiplied by 2 so that the TX bytes // transferred are also accounted for. // ui32BytesTransferred = ui32XfersCompleted * UART_RXBUF_SIZE * 2; // // Print a message showing the UART transfer rate. // if(ui32BytesTransferred >= 1000000) { UARTprintf("%1d.%02d MB/s ", ui32BytesTransferred / 1000000, (ui32BytesTransferred % 1000000) / 10000); } else if(ui32BytesTransferred >= 100000) { UARTprintf("%3d KB/s ", ui32BytesTransferred / 1000); } else if(ui32BytesTransferred >= 10000) { UARTprintf("%2d.%01d KB/s ", ui32BytesTransferred / 1000, (ui32BytesTransferred % 1000) / 100); } else if(ui32BytesTransferred >= 1000) { UARTprintf("%1d.%02d KB/s ", ui32BytesTransferred / 1000, (ui32BytesTransferred % 1000) / 10); } else if(ui32BytesTransferred >= 100) { UARTprintf("%3d B/s ", ui32BytesTransferred); } else if(ui32BytesTransferred >= 10) { UARTprintf("%2d B/s ", ui32BytesTransferred); } else { UARTprintf("%1d B/s ", ui32BytesTransferred); } // // Print a spinning line to make it more apparent that there is // something happening. // UARTprintf("%2ds", 10 - ui32PrevSeconds); // // Turn off the LED. // GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0); } // // Put the processor to sleep if there is nothing to do. This allows // the CPU usage routine to measure the number of free CPU cycles. // If the processor is sleeping a lot, it can be hard to connect to // the target with the debugger. // ROM_SysCtlSleep(); // // See if we have run int32_t enough and exit the loop if so. // if(g_ui32Seconds >= 10) { break; } }
//***************************************************************************** // // 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; } } } }
void Hardware_Init(void) { // Initially wait for device connection. g_eState = STATE_NO_DEVICE; g_eUIState = STATE_NO_DEVICE; // Set the clocking to run from the PLL at 50MHz. ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // Initialize the UART. ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTStdioInit(0); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_4 | GPIO_PIN_5); UARTprintf("\n\nUSB Android ADK Firmware for EvalBot by [email protected]\n"); /* Configure EvalBot available Buttons (User Switch 1, 2 ...) */ // Enable the GPIO pin to read the select button. ROM_SysCtlPeripheralEnable(USER_SW1_SYSCTL_PERIPH); ROM_GPIODirModeSet(USER_SW1_PORT_BASE, USER_SW1_PIN, GPIO_DIR_MODE_IN); ROM_GPIOPadConfigSet(USER_SW1_PORT_BASE, USER_SW1_PIN, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // Enable the GPIO pin to read the select button. ROM_SysCtlPeripheralEnable(USER_SW2_SYSCTL_PERIPH); ROM_GPIODirModeSet(USER_SW2_PORT_BASE, USER_SW2_PIN, GPIO_DIR_MODE_IN); ROM_GPIOPadConfigSet(USER_SW2_PORT_BASE, USER_SW2_PIN, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // Enable the GPIO pin to read the select button. // Enable the GPIO ports used for the bump sensors. ROM_SysCtlPeripheralEnable(BUMP_L_SW3_SYSCTL_PERIPH); ROM_GPIODirModeSet(BUMP_L_SW3_PORT_BASE, BUMP_L_SW3_PIN, GPIO_DIR_MODE_IN); ROM_GPIOPadConfigSet(BUMP_L_SW3_PORT_BASE, BUMP_L_SW3_PIN, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // Enable the GPIO pin to read the select button. ROM_SysCtlPeripheralEnable(BUMP_R_SW4_SYSCTL_PERIPH); ROM_GPIODirModeSet(BUMP_R_SW4_PORT_BASE, BUMP_R_SW4_PIN, GPIO_DIR_MODE_IN); ROM_GPIOPadConfigSet(BUMP_R_SW4_PORT_BASE, BUMP_R_SW4_PIN, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // Enable the GPIO pin for the LED1 (PF4) & LED2 (PF5) // Set the direction as output, and enable the GPIO pin for digital function. ROM_SysCtlPeripheralEnable(LED1_SYSCTL_PERIPH); GPIOPinTypeGPIOOutput(LED1_PORT_BASE, LED1_PIN); ROM_SysCtlPeripheralEnable(LED2_SYSCTL_PERIPH); GPIOPinTypeGPIOOutput(LED2_PORT_BASE, LED2_PIN); // Configure SysTick for a 1KHz interrupt. ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / TICKS_PER_SECOND); ROM_SysTickEnable(); ROM_SysTickIntEnable(); // Enable Clocking to the USB controller. ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0); // Set the USB pins to be controlled by the USB controller. ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0); GPIOPinConfigure(GPIO_PA6_USB0EPEN); ROM_GPIOPinTypeUSBDigital(GPIO_PORTA_BASE, GPIO_PIN_6); // Enable the GPIO pin for the USB HOST / DEVICE Selection (PB0). Set the direction as output, and // enable the GPIO pin for digital function. GPIO_PORTB_DIR_R |= GPIO_PIN_0; GPIO_PORTB_DEN_R |= GPIO_PIN_0; // PB0 = GND =USB HOST Enabled. GPIO_PORTB_DATA_R &= ~(GPIO_PIN_0); // Enable the uDMA controller and set up the control table base. ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); ROM_uDMAEnable(); ROM_uDMAControlBaseSet(g_sDMAControlTable); // Initialize the USB stack mode and pass in a mode callback. USBStackModeSet(0, USB_MODE_OTG, ModeCallback); // Register the host class drivers. USBHCDRegisterDrivers(0, g_ppHostClassDrivers, NUM_CLASS_DRIVERS); // 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 OTG operation with a 250ms polling // rate. // Warning if this delay is higher it cannot connect correctly to Android ADK. USBOTGModeInit(0, 250, g_pHCDPool, HCD_MEMORY_SIZE); }
//***************************************************************************** // // 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; tContext sContext; // // Run from the PLL at 120 MHz. // ui32SysClock = 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, "tdes-cbc-encrypt"); // // 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++) { 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"); 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 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); 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 example decrypts a block of payload using AES128 in CCM mode. It // does the decryption first without uDMA and then with uDMA. The results // are checked after each operation. // //***************************************************************************** int main(void) { uint32_t pui32Payload[16], pui32Tag[4], ui32Errors, ui32Idx; uint32_t ui32PayloadLength, ui32TagLength; uint32_t ui32NonceLength, ui32AuthDataLength; uint32_t *pui32Nonce, *pui32AuthData, ui32SysClock; uint32_t *pui32Key, *pui32ExpPayload, *pui32CipherText; uint8_t ui8Vector; uint8_t *pui8ExpTag, *pui8Tag; tContext sContext; // // Run from the PLL at 120 MHz. // ui32SysClock = 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, "aes128-ccm-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++) { pui32Payload[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. // ROM_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 AES128 CCM 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_psAESCCMTestVectors) / sizeof(g_psAESCCMTestVectors[0]))) && (ui32Errors == 0); ui8Vector++) { UARTprintf("Starting vector #%d\n", ui8Vector); // // Get the current vector's data members. // pui32Key = g_psAESCCMTestVectors[ui8Vector].pui32Key; pui32ExpPayload = g_psAESCCMTestVectors[ui8Vector].pui32Payload; ui32PayloadLength = g_psAESCCMTestVectors[ui8Vector].ui32PayloadLength; pui32AuthData = g_psAESCCMTestVectors[ui8Vector].pui32AuthData; ui32AuthDataLength = g_psAESCCMTestVectors[ui8Vector].ui32AuthDataLength; pui32CipherText = 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 decryption without uDMA. // UARTprintf("Performing decryption without uDMA.\n"); AES128CCMDecrypt(pui32Key, pui32CipherText, pui32Payload, ui32PayloadLength, pui32Nonce, ui32NonceLength, pui32AuthData, ui32AuthDataLength, pui32Tag, ui32TagLength, false); // // Check the result. // for(ui32Idx = 0; ui32Idx < (ui32PayloadLength / 4); ui32Idx++) { if(pui32Payload[ui32Idx] != pui32ExpPayload[ui32Idx]) { UARTprintf("Payload mismatch on word %d. Exp: 0x%x, Act: " "0x%x\n", ui32Idx, pui32ExpPayload[ui32Idx], pui32Payload[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++) { pui32Payload[ui32Idx] = 0; } for(ui32Idx = 0; ui32Idx < 4; ui32Idx++) { pui32Tag[ui32Idx] = 0; } // // Perform the decryption with uDMA. // UARTprintf("Performing decryption with uDMA.\n"); AES128CCMDecrypt(pui32Key, pui32CipherText, pui32Payload, ui32PayloadLength, pui32Nonce, ui32NonceLength, pui32AuthData, ui32AuthDataLength, pui32Tag, ui32TagLength, true); // // Check the result. // for(ui32Idx = 0; ui32Idx < (ui32PayloadLength / 4); ui32Idx++) { if(pui32Payload[ui32Idx] != pui32ExpPayload[ui32Idx]) { UARTprintf("Payload mismatch on word %d. Exp: 0x%x, Act: " "0x%x\n", ui32Idx, pui32ExpPayload[ui32Idx], pui32Payload[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++) { pui32Payload[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) { } }
//***************************************************************************** // // The program main function. It performs initialization, then runs // a command processing loop to read commands from the console. // //***************************************************************************** int main(void) { uint32_t ui32DriveTimeout; uint32_t ui32SysClock; tContext sContext; // // Run from the PLL at 120 MHz. // ui32SysClock = 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, "usb-host-msc"); // // Configure SysTick for a 100Hz interrupt. // ROM_SysTickPeriodSet(ui32SysClock / TICKS_PER_SECOND); ROM_SysTickEnable(); ROM_SysTickIntEnable(); // // Enable the uDMA controller and set up the control table base. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); ROM_uDMAEnable(); ROM_uDMAControlBaseSet(g_sDMAControlTable); // // Initialize the touch screen driver. // TouchScreenInit(ui32SysClock); // // Set the touch screen event handler. // TouchScreenCallbackSet(WidgetPointerMessage); // // Add the compile-time defined widgets to the widget tree. // WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sBackground); // // Set some initial strings. // ListBoxTextAdd(&g_sDirList, "Waiting for device..."); // // Issue the initial paint request to the widgets then immediately call // the widget manager to process the paint message. This ensures that the // display is drawn as quickly as possible and saves the delay we would // otherwise experience if we processed the paint message after mounting // and reading the SD card. // WidgetPaint(WIDGET_ROOT); WidgetMessageQueueProcess(); // // 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_pHCDPool, HCD_MEMORY_SIZE); // // Initialize the file system. // FileInit(); // // Enter an (almost) infinite loop for reading and processing commands from // the user. // while(1) { // // Call the USB stack to keep it running. // USBHCDMain(); // // Process any messages in the widget message queue. This keeps the // display UI running. // WidgetMessageQueueProcess(); switch(g_eState) { case STATE_DEVICE_ENUM: { // // Take it easy on the Mass storage device if it is slow to // start up after connecting. // if(USBHMSCDriveReady(g_psMSCInstance) != 0) { // // Wait about 500ms before attempting to check if the // device is ready again. // ROM_SysCtlDelay(ui32SysClock / (3 * 2)); // // 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_cCwdBuf[0] = '/'; g_cCwdBuf[1] = 0; // // Set the initial directory level to the root // g_ui32Level = 0; // // Fill the list box with the files and directories found. // if(!PopulateFileListBox(true)) { // // 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; break; } // // If there is no device then just wait for one. // case STATE_NO_DEVICE: { if(g_ui32Flags == FLAGS_DEVICE_PRESENT) { // // Empty the list box on the display. // ListBoxClear(&g_sDirList); ListBoxTextAdd(&g_sDirList, "Waiting for device..."); WidgetPaint((tWidget *)&g_sDirList); // // 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. // ListBoxClear(&g_sDirList); ListBoxTextAdd(&g_sDirList, "Unknown device."); WidgetPaint((tWidget *)&g_sDirList); } // // 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. // ListBoxClear(&g_sDirList); ListBoxTextAdd(&g_sDirList, "Device Timeout."); WidgetPaint((tWidget *)&g_sDirList); } // // Set the Device Present flag. // g_ui32Flags = FLAGS_DEVICE_PRESENT; break; } // // Something has caused a power fault. // case STATE_POWER_FAULT: { break; } default: { break; } } } }
//***************************************************************************** // // This example demonstrates how to use the uDMA controller to transfer data // between memory buffers and to and from a peripheral, in this case a UART. // The uDMA controller is configured to repeatedly transfer a block of data // from one memory buffer to another. It is also set up to repeatedly copy a // block of data from a buffer to the UART output. The UART data is looped // back so the same data is received, and the uDMA controlled is configured to // continuously receive the UART data using ping-pong buffers. // // The processor is put to sleep when it is not doing anything, and this allows // collection of CPU usage data to see how much CPU is being used while the // data transfers are ongoing. // //***************************************************************************** int main(void) { static unsigned long ulPrevSeconds; static unsigned long ulPrevXferCount; static unsigned long ulPrevUARTCount = 0; static char cStrBuf[40]; tRectangle sRect; unsigned long ulCenterX; unsigned long ulXfersCompleted; unsigned long ulBytesTransferred; // // Set the clocking to run from the PLL at 50 MHz. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Set the device pinout appropriately for this board. // PinoutSet(); // // Enable peripherals to operate when CPU is in sleep. // ROM_SysCtlPeripheralClockGating(true); // // Initialize the display driver. // Kitronix320x240x16_SSD2119Init(); // // Initialize the graphics context and find the middle X coordinate. // GrContextInit(&g_sContext, &g_sKitronix320x240x16_SSD2119); // // Get the center X coordinate of the screen, since it is used a lot. // ulCenterX = GrContextDpyWidthGet(&g_sContext) / 2; // // Fill the top 15 rows of the screen with blue to create the banner. // sRect.sXMin = 0; sRect.sYMin = 0; sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1; sRect.sYMax = 23; GrContextForegroundSet(&g_sContext, ClrDarkBlue); GrRectFill(&g_sContext, &sRect); // // Put a white box around the banner. // GrContextForegroundSet(&g_sContext, ClrWhite); GrRectDraw(&g_sContext, &sRect); // // Put the application name in the middle of the banner. // GrContextFontSet(&g_sContext, g_pFontCm20); GrStringDrawCentered(&g_sContext, "udma-demo", -1, ulCenterX, 11, 0); // // Show the clock frequency on the display. // GrContextFontSet(&g_sContext, g_pFontCmss18b); usnprintf(cStrBuf, sizeof(cStrBuf), "Stellaris @ %u MHz", SysCtlClockGet() / 1000000); GrStringDrawCentered(&g_sContext, cStrBuf, -1, ulCenterX, 40, 0); // // Show static text and field labels on the display. // GrStringDrawCentered(&g_sContext, "uDMA Mem Transfers", -1, ulCenterX, 62, 0); GrStringDrawCentered(&g_sContext, "uDMA UART Transfers", -1, ulCenterX, 84, 0); // // Configure SysTick to occur 100 times per second, to use as a time // reference. Enable SysTick to generate interrupts. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND); ROM_SysTickIntEnable(); ROM_SysTickEnable(); // // Initialize the CPU usage measurement routine. // CPUUsageInit(SysCtlClockGet(), SYSTICKS_PER_SECOND, 2); // // Enable the uDMA controller at the system level. Enable it to continue // to run while the processor is in sleep. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UDMA); // // Enable the uDMA controller error interrupt. This interrupt will occur // if there is a bus error during a transfer. // ROM_IntEnable(INT_UDMAERR); // // Enable the uDMA controller. // ROM_uDMAEnable(); // // Point at the control table to use for channel control structures. // ROM_uDMAControlBaseSet(ucControlTable); // // Initialize the uDMA memory to memory transfers. // InitSWTransfer(); // // Initialize the uDMA UART transfers. // InitUART0Transfer(); // // Remember the current SysTick seconds count. // ulPrevSeconds = g_ulSeconds; // // Remember the current count of memory buffer transfers. // ulPrevXferCount = g_ulMemXferCount; // // Loop until the button is pressed. The processor is put to sleep // in this loop so that CPU utilization can be measured. // while(1) { // // Check to see if one second has elapsed. If so, the make some // updates. // if(g_ulSeconds != ulPrevSeconds) { // // Print a message to the display showing the CPU usage percent. // The fractional part of the percent value is ignored. // usnprintf(cStrBuf, sizeof(cStrBuf), "CPU utilization %2u%%", g_ulCPUUsage >> 16); GrStringDrawCentered(&g_sContext, cStrBuf, -1, ulCenterX, 160, 1); // // Tell the user how many seconds we have to go before ending. // usnprintf(cStrBuf, sizeof(cStrBuf), " Test ends in %d seconds ", 10 - g_ulSeconds); GrStringDrawCentered(&g_sContext, cStrBuf, -1, ulCenterX, 120, 1); // // Remember the new seconds count. // ulPrevSeconds = g_ulSeconds; // // Calculate how many memory transfers have occurred since the last // second. // ulXfersCompleted = g_ulMemXferCount - ulPrevXferCount; // // Remember the new transfer count. // ulPrevXferCount = g_ulMemXferCount; // // Compute how many bytes were transferred in the memory transfer // since the last second. // ulBytesTransferred = ulXfersCompleted * MEM_BUFFER_SIZE * 4; // // Print a message to the display showing the memory transfer rate. // usnprintf(cStrBuf, sizeof(cStrBuf), " %8u Bytes/Sec ", ulBytesTransferred); GrStringDrawCentered(&g_sContext, cStrBuf, -1, ulCenterX, 182, 1); // // Calculate how many UART transfers have occurred since the last // second. // ulXfersCompleted = (g_ulRxBufACount + g_ulRxBufBCount - ulPrevUARTCount); // // Remember the new UART transfer count. // ulPrevUARTCount = g_ulRxBufACount + g_ulRxBufBCount; // // Compute how many bytes were transferred by the UART. The number // of bytes received is multiplied by 2 so that the TX bytes // transferred are also accounted for. // ulBytesTransferred = ulXfersCompleted * UART_RXBUF_SIZE * 2; // // Print a message to the display showing the UART transfer rate. // usnprintf(cStrBuf, sizeof(cStrBuf), " %8u Bytes/Sec ", ulBytesTransferred); GrStringDrawCentered(&g_sContext, cStrBuf, -1, ulCenterX, 204, 1); } // // Put the processor to sleep if there is nothing to do. This allows // the CPU usage routine to measure the number of free CPU cycles. // If the processor is sleeping a lot, it can be hard to connect to // the target with the debugger. // SysCtlSleep(); // // See if we have run long enough and exit the loop if so. // if(g_ulSeconds >= 10) { break; } }
//***************************************************************************** // // This is the main loop that runs the application. // //***************************************************************************** int main(void) { uint32_t ui32Read, ui32Write; // // Run from the PLL at 120 MHz. // g_ui32SysClock = 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(g_ui32SysClock); // // Initialize the graphics context. // GrContextInit(&g_sContext, &g_sKentec320x240x16_SSD2119); // // Draw the application frame. // FrameDraw(&g_sContext, "usb-dev-msc"); // // Place the static status text on the display. // GrStringDrawCentered(&g_sContext, "Status", -1, 160, 58, false); GrStringDrawCentered(&g_sContext, "Bytes Read", -1, 160, 118, false); GrStringDrawCentered(&g_sContext, "Bytes Written", -1, 160, 178, false); GrContextForegroundSet(&g_sContext, ClrGray); UpdateCount(0, 138); UpdateCount(0, 198); // // Configure SysTick for a 100Hz interrupt. This is to detect idle state // every 10ms after a state change. // ROM_SysTickPeriodSet(g_ui32SysClock / 100); ROM_SysTickEnable(); ROM_SysTickIntEnable(); // // Configure and enable uDMA // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); SysCtlDelay(10); ROM_uDMAControlBaseSet(&psDMAControlTable[0]); ROM_uDMAEnable(); // // Initialize the idle timeout and reset all flags. // g_ui32IdleTimeout = 0; g_ui32Flags = 0; // // Initialize the state to idle. // g_eMSCState = MSC_DEV_DISCONNECTED; // // Draw the status bar and set it to idle. // UpdateStatus("Disconnected"); // // Enable the USB controller. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0); // // Enable the SSI3 used by SPI flash. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI3); ROM_SysCtlPeripheralReset(SYSCTL_PERIPH_SSI3); // // 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. // USBDMSCInit(0, (tUSBDMSCDevice*)&g_sMSCDevice); // // Initialize the SD card, if present. This prevents it from interfering // with accesses to the SPI flash. // disk_initialize(0); // // Initialize MX66L51235F Flash memory. // MX66L51235FInit(g_ui32SysClock); // // Drop into the main loop. // ui32Read = g_ui32ReadCount; ui32Write = g_ui32WriteCount; while(1) { switch(g_eMSCState) { case MSC_DEV_READ: { // // Update the screen if necessary. // if(g_ui32Flags & FLAG_UPDATE_STATUS) { UpdateStatus(" Reading "); g_ui32Flags &= ~FLAG_UPDATE_STATUS; } // // If there is no activity then return to the idle state. // if(g_ui32IdleTimeout == 0) { UpdateStatus(" Idle "); g_eMSCState = MSC_DEV_IDLE; } break; } case MSC_DEV_WRITE: { // // Update the screen if necessary. // if(g_ui32Flags & FLAG_UPDATE_STATUS) { UpdateStatus(" Writing "); g_ui32Flags &= ~FLAG_UPDATE_STATUS; } // // If there is no activity then return to the idle state. // if(g_ui32IdleTimeout == 0) { UpdateStatus(" Idle "); g_eMSCState = MSC_DEV_IDLE; } break; } case MSC_DEV_DISCONNECTED: { // // Update the screen if necessary. // if(g_ui32Flags & FLAG_UPDATE_STATUS) { UpdateStatus(" Disconnected "); g_ui32Flags &= ~FLAG_UPDATE_STATUS; } break; } case MSC_DEV_IDLE: { break; } default: { break; } } // // Update the read count if it has changed. // if(g_ui32ReadCount != ui32Read) { ui32Read = g_ui32ReadCount; UpdateCount(ui32Read, 138); } // // Update the write count if it has changed. // if(g_ui32WriteCount != ui32Write) { ui32Write = g_ui32WriteCount; UpdateCount(ui32Write, 198); } } }
// After a certain number of edges are captured, the application prints out // the results and compares the elapsed time between edges to the expected // value. // // Note that the "B" timer is used because on some devices the "A" timer does // not work correctly with the uDMA controller. Refer to the chip errata for // details. // //***************************************************************************** int main(void) { unsigned long ulIdx; unsigned short usTimerElapsed; //unsigned short usTimerErr; // // Set the clocking to run directly from the crystal. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Initialize the UART and write a status message. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); ROM_UARTConfigSetExpClk(UART0_BASE, ROM_SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_EVEN)); //UARTStdioInit(0); //UARTprintf("\033[2JuDMA edge capture timer example\n\n"); //UARTprintf("This example requires that PD0 and PD7 be jumpered together" // "\n\n"); // // Create a signal source that can be used as an input for the CCP1 pin. // SetupSignalSource(); // // Enable the GPIO port used for the CCP1 input. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); // // Configure the Timer0 CCP1 function to use PD7 // GPIOPinConfigure(GPIO_PB2_CCP3); GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_2); // // Set up Timer0B for edge-timer mode, positive edge // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); TimerConfigure(TIMER1_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_B_CAP_TIME); TimerControlEvent(TIMER1_BASE, TIMER_B, TIMER_EVENT_BOTH_EDGES); TimerLoadSet(TIMER1_BASE, TIMER_B, 0xffff); // // Enable the uDMA peripheral // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); // // Enable the uDMA controller error interrupt. This interrupt will occur // if there is a bus error during a transfer. // ROM_IntEnable(INT_UDMAERR); // // Enable the uDMA controller. // ROM_uDMAEnable(); // // Point at the control table to use for channel control structures. // ROM_uDMAControlBaseSet(ucControlTable); // // Put the attributes in a known state for the uDMA Timer0B channel. These // should already be disabled by default. // ROM_uDMAChannelAttributeDisable(UDMA_CHANNEL_TMR1B, UDMA_ATTR_ALTSELECT | UDMA_ATTR_USEBURST | UDMA_ATTR_HIGH_PRIORITY | UDMA_ATTR_REQMASK); // // Configure DMA channel for Timer0B to transfer 16-bit values, 1 at a // time. The source is fixed and the destination increments by 16-bits // (2 bytes) at a time. // ROM_uDMAChannelControlSet(UDMA_CHANNEL_TMR1B | UDMA_PRI_SELECT, UDMA_SIZE_16 | UDMA_SRC_INC_NONE | UDMA_DST_INC_16 | UDMA_ARB_1); // // Set up the transfer parameters for the Timer0B primary control // structure. The mode is set to basic, the transfer source is the // Timer0B register, and the destination is a memory buffer. The // transfer size is set to a fixed number of capture events. // ROM_uDMAChannelTransferSet(UDMA_CHANNEL_TMR1B | UDMA_PRI_SELECT, UDMA_MODE_BASIC, (void *)(TIMER1_BASE + TIMER_O_TBR), g_usTimerBuf, MAX_TIMER_EVENTS); // // Enable the timer capture event interrupt. Note that this signal is // used to trigger the DMA request and not an actual interrupt. // Start the capture timer running and enable its interrupt channel. // The timer interrupt channel is used by the uDMA controller. // //UARTprintf("Starting timer and uDMA\n"); TimerIntEnable(TIMER1_BASE, TIMER_CAPB_EVENT); TimerEnable(TIMER1_BASE, TIMER_B); IntEnable(INT_TIMER1B); // // Now enable the DMA channel for Timer0B. It should now start performing // transfers whenever there is a rising edge detected on the CCP1 pin. // ROM_uDMAChannelEnable(UDMA_CHANNEL_TMR1B); // // Enable processor interrupts. // ROM_IntMasterEnable(); // // Wait for the transfer to complete. // //UARTprintf("Waiting for transfers to complete\n"); while(!g_bDoneFlag) { } // // Check for the expected number of occurrences of the interrupt handler, // and that there are no DMA errors // if(g_uluDMAErrCount != 0) { //UARTprintf("\nuDMA errors were detected!!!\n\n"); } if(g_ulTimer0BIntCount != 1) { //UARTprintf("\nUnexpected number of interrupts occurrred (%d)!!!\n\n", // g_ulTimer0BIntCount); } // // Display the timer values that were captured using the edge capture timer // with uDMA. Compare the difference between stored values to the PWM // period and make sure they match. This verifies that the edge capture // DMA transfers were occurring with the correct timing. // //UARTprintf("\n Captured\n"); //UARTprintf("Event Value Difference Status\n"); //UARTprintf("----- -------- ---------- ------\n"); const unsigned char nbColonnes = '1'; UARTSend(&nbColonnes,1); for(ulIdx = 1; ulIdx < MAX_TIMER_EVENTS; ulIdx++) { // // Due to timer erratum, when the timer rolls past 0 as it counts // down, it will trigger an additional DMA transfer even though there // was not an edge capture. This will appear in the data buffer as // a duplicate value - the value will be the same as the prior capture // value. Therefore, in this example we skip past the duplicated // value. // if(g_usTimerBuf[ulIdx] == g_usTimerBuf[ulIdx - 1]) { const unsigned char dup = '$'; UARTSend(&dup,1); //UARTprintf(" %2u 0x%04X skipped duplicate\n", ulIdx, // g_usTimerBuf[ulIdx]); continue; } // // Compute the difference between adjacent captured values, and then // compare that to the expected timeout period. // usTimerElapsed = g_usTimerBuf[ulIdx - 1] - g_usTimerBuf[ulIdx]; //usTimerErr = usTimerElapsed > TIMEOUT_VAL ? // usTimerElapsed - TIMEOUT_VAL : // TIMEOUT_VAL - usTimerElapsed; // // Print the captured value and the difference from the previous // unsigned char data[10]; itoa(usTimerElapsed,data); UARTSend(data,10); //UARTprintf(" %2u 0x%04X %8u ", ulIdx, g_usTimerBuf[ulIdx], // usTimerElapsed); // // Print error status based on the deviation from expected difference // between samples (calculated above). Allow for a difference of up // to 1 cycle. Any more than that is considered an error. // //if(usTimerErr > 1) //{ // UARTprintf(" ERROR\n"); //} //else //{ // UARTprintf(" OK\n"); //} } const unsigned char fin = '\n'; UARTSend(&fin,1); // // End of application // while(1) { } }
//**************************************************************************** // // This is the main loop that runs the application. // //**************************************************************************** int main(void) { // // Set the clocking to run from the PLL at 50MHz. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Set the system tick to fire 100 times per second. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND); ROM_SysTickIntEnable(); ROM_SysTickEnable(); // // Configure and enable uDMA // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); SysCtlDelay(10); ROM_uDMAControlBaseSet(&sDMAControlTable[0]); ROM_uDMAEnable(); // // Initialize the idle timeout and reset all flags. // g_ulIdleTimeout = 0; g_ulFlags = 0; g_eMSCState = MSC_DEV_DISCONNECTED; // // Pass the USB library our device information, initialize the USB // controller and connect the device to the bus. // g_psCompDevices[0].pvInstance = USBDMSCInit(0, (tUSBDMSCDevice *)&g_sMSCDevice); g_psCompDevices[1].pvInstance = USBDCDCCompositeInit(0, (tUSBDCDCDevice *)&g_sCDCDevice); // // Set the USB stack mode to Device mode with VBUS monitoring. // USBStackModeSet(0, USB_MODE_DEVICE, 0); // // Pass the device information to the USB library and place the device // on the bus. // USBDCompositeInit(0, &g_sCompDevice, DESCRIPTOR_DATA_SIZE, g_pucDescriptorData); SerialInit(); disk_initialize(0); // // Drop into the main loop. // while(1) { // // Allow the main serial routine to run. // SerialMain(); switch(g_eMSCState) { case MSC_DEV_READ: { // // Update the screen if necessary. // if(g_ulFlags & FLAG_UPDATE_STATUS) { g_ulFlags &= ~FLAG_UPDATE_STATUS; } // // If there is no activity then return to the idle state. // if(g_ulIdleTimeout == 0) { g_eMSCState = MSC_DEV_IDLE; } break; } case MSC_DEV_WRITE: { // // Update the screen if necessary. // if(g_ulFlags & FLAG_UPDATE_STATUS) { g_ulFlags &= ~FLAG_UPDATE_STATUS; } // // If there is no activity then return to the idle state. // if(g_ulIdleTimeout == 0) { g_eMSCState = MSC_DEV_IDLE; } break; } case MSC_DEV_DISCONNECTED: { // // Update the screen if necessary. // if(g_ulFlags & FLAG_UPDATE_STATUS) { g_ulFlags &= ~FLAG_UPDATE_STATUS; } break; } case MSC_DEV_IDLE: { break; } default: { break; } } } }
//***************************************************************************** // // This example demonstrates how to use the uDMA controller to transfer data // between memory buffers and to and from a peripheral, in this case a UART. // The uDMA controller is configured to repeatedly transfer a block of data // from one memory buffer to another. It is also set up to repeatedly copy a // block of data from a buffer to the UART output. The UART data is looped // back so the same data is received, and the uDMA controlled is configured to // continuously receive the UART data using ping-pong buffers. // // The processor is put to sleep when it is not doing anything, and this allows // collection of CPU usage data to see how much CPU is being used while the // data transfers are ongoing. // //***************************************************************************** int main(void) { static unsigned long ulPrevSeconds; static unsigned long ulPrevXferCount; static unsigned long ulPrevUARTCount = 0; unsigned long ulXfersCompleted; unsigned long ulBytesTransferred; unsigned long ulButton; // // Set the clocking to run from the PLL at 50 MHz. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Enable peripherals to operate when CPU is in sleep. // ROM_SysCtlPeripheralClockGating(true); // // Set the push button as an input with a pull-up. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_GPIODirModeSet(GPIO_PORTB_BASE, GPIO_PIN_4, GPIO_DIR_MODE_IN); ROM_GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_4, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // // Initialize the UART. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART0); GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTStdioInit(0); UARTprintf("\033[2JuDMA Example\n"); // // Show the clock frequency and exit instructions. // UARTprintf("Stellaris @ %u MHz\n", ROM_SysCtlClockGet() / 1000000); UARTprintf("Press button to use debugger.\n\n"); // // Show statistics headings. // UARTprintf("CPU Memory UART\n"); UARTprintf("Usage Transfers Transfers\n"); // // Configure SysTick to occur 100 times per second, to use as a time // reference. Enable SysTick to generate interrupts. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND); ROM_SysTickIntEnable(); ROM_SysTickEnable(); // // Initialize the CPU usage measurement routine. // CPUUsageInit(ROM_SysCtlClockGet(), SYSTICKS_PER_SECOND, 2); // // Enable the uDMA controller at the system level. Enable it to continue // to run while the processor is in sleep. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UDMA); // // Enable the uDMA controller error interrupt. This interrupt will occur // if there is a bus error during a transfer. // ROM_IntEnable(INT_UDMAERR); // // Enable the uDMA controller. // ROM_uDMAEnable(); // // Point at the control table to use for channel control structures. // ROM_uDMAControlBaseSet(ucControlTable); // // Initialize the uDMA memory to memory transfers. // InitSWTransfer(); // // Initialize the uDMA UART transfers. // InitUART1Transfer(); // // Remember the current SysTick seconds count. // ulPrevSeconds = g_ulSeconds; // // Remember the current count of memory buffer transfers. // ulPrevXferCount = g_ulMemXferCount; // // Loop until the button is pressed. The processor is put to sleep // in this loop so that CPU utilization can be measured. When the // processor is sleeping a lot, it can be hard to connect to the target // with the debugger. Pressing the button will cause this loop to exit // and the processor will no longer sleep. // while(1) { // // Check for the select button press. If the button is pressed, // then exit this loop. // ulButton = ROM_GPIOPinRead(GPIO_PORTB_BASE, GPIO_PIN_4); if(!ulButton) { break; } // // Check to see if one second has elapsed. If so, the make some // updates. // if(g_ulSeconds != ulPrevSeconds) { // // Print a message to the display showing the CPU usage percent. // The fractional part of the percent value is ignored. // UARTprintf("\r%3d%% ", g_ulCPUUsage >> 16); // // Remember the new seconds count. // ulPrevSeconds = g_ulSeconds; // // Calculate how many memory transfers have occurred since the last // second. // ulXfersCompleted = g_ulMemXferCount - ulPrevXferCount; // // Remember the new transfer count. // ulPrevXferCount = g_ulMemXferCount; // // Compute how many bytes were transferred in the memory transfer // since the last second. // ulBytesTransferred = ulXfersCompleted * MEM_BUFFER_SIZE * 4; // // Print a message showing the memory transfer rate. // if(ulBytesTransferred >= 100000000) { UARTprintf("%3d MB/s ", ulBytesTransferred / 1000000); } else if(ulBytesTransferred >= 10000000) { UARTprintf("%2d.%01d MB/s ", ulBytesTransferred / 1000000, (ulBytesTransferred % 1000000) / 100000); } else if(ulBytesTransferred >= 1000000) { UARTprintf("%1d.%02d MB/s ", ulBytesTransferred / 1000000, (ulBytesTransferred % 1000000) / 10000); } else if(ulBytesTransferred >= 100000) { UARTprintf("%3d KB/s ", ulBytesTransferred / 1000); } else if(ulBytesTransferred >= 10000) { UARTprintf("%2d.%01d KB/s ", ulBytesTransferred / 1000, (ulBytesTransferred % 1000) / 100); } else if(ulBytesTransferred >= 1000) { UARTprintf("%1d.%02d KB/s ", ulBytesTransferred / 1000, (ulBytesTransferred % 1000) / 10); } else if(ulBytesTransferred >= 100) { UARTprintf("%3d B/s ", ulBytesTransferred); } else if(ulBytesTransferred >= 10) { UARTprintf("%2d B/s ", ulBytesTransferred); } else { UARTprintf("%1d B/s ", ulBytesTransferred); } // // Calculate how many UART transfers have occurred since the last // second. // ulXfersCompleted = (g_ulRxBufACount + g_ulRxBufBCount - ulPrevUARTCount); // // Remember the new UART transfer count. // ulPrevUARTCount = g_ulRxBufACount + g_ulRxBufBCount; // // Compute how many bytes were transferred by the UART. The number // of bytes received is multiplied by 2 so that the TX bytes // transferred are also accounted for. // ulBytesTransferred = ulXfersCompleted * UART_RXBUF_SIZE * 2; // // Print a message showing the UART transfer rate. // if(ulBytesTransferred >= 1000000) { UARTprintf("%1d.%02d MB/s ", ulBytesTransferred / 1000000, (ulBytesTransferred % 1000000) / 10000); } else if(ulBytesTransferred >= 100000) { UARTprintf("%3d KB/s ", ulBytesTransferred / 1000); } else if(ulBytesTransferred >= 10000) { UARTprintf("%2d.%01d KB/s ", ulBytesTransferred / 1000, (ulBytesTransferred % 1000) / 100); } else if(ulBytesTransferred >= 1000) { UARTprintf("%1d.%02d KB/s ", ulBytesTransferred / 1000, (ulBytesTransferred % 1000) / 10); } else if(ulBytesTransferred >= 100) { UARTprintf("%3d B/s ", ulBytesTransferred); } else if(ulBytesTransferred >= 10) { UARTprintf("%2d B/s ", ulBytesTransferred); } else { UARTprintf("%1d B/s ", ulBytesTransferred); } // // Print a spinning line to make it more apparent that there is // something happening. // UARTprintf("%c", g_pcTwirl[ulPrevSeconds % 4]); } // // Put the processor to sleep if there is nothing to do. This allows // the CPU usage routine to measure the number of free CPU cycles. // If the processor is sleeping a lot, it can be hard to connect to // the target with the debugger. // ROM_SysCtlSleep(); }
//***************************************************************************** // // A simple demonstration of the features of the Stellaris Graphics Library. // //***************************************************************************** int main(void) { tContext sContext; tRectangle sRect; // // Set the clocking to run from the PLL. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Set the device pinout appropriately for this board. // PinoutSet(); // // Initialize the display driver. // Kitronix320x240x16_SSD2119Init(); // // Initialize the graphics context. // GrContextInit(&sContext, &g_sKitronix320x240x16_SSD2119); // // Fill the top 24 rows of the screen with blue to create the banner. // sRect.sXMin = 0; sRect.sYMin = 0; sRect.sXMax = GrContextDpyWidthGet(&sContext) - 1; sRect.sYMax = 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_pFontCm20); GrStringDrawCentered(&sContext, "grlib demo", -1, GrContextDpyWidthGet(&sContext) / 2, 8, 0); // // Configure and enable uDMA // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); SysCtlDelay(10); ROM_uDMAControlBaseSet(&sDMAControlTable[0]); ROM_uDMAEnable(); // // Initialize the sound driver. // SoundInit(0); // // Initialize the touch screen driver and have it route its messages to the // widget tree. // TouchScreenInit(); 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_ulPanel = 0; WidgetAdd(WIDGET_ROOT, (tWidget *)g_psPanels); CanvasTextSet(&g_sTitle, g_pcPanelNames[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(); } }
//***************************************************************************** // // This example performs a CRC-32 operation on an array of data using a // number of starting seeds. // //***************************************************************************** int main(void) { uint32_t ui32Result, 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; // // Enable debug output on UART0 and print a welcome message. // ConfigureUART(); UARTprintf("\033[2J\033[H"); UARTprintf("Starting CRC-32 demo.\n"); // // Enable the uDMA module. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); // // Setup the control table. // ROM_uDMAEnable(); ROM_uDMAControlBaseSet(g_psDMAControlTable); // // Initialize the CRC and CCM modules. // if(!CRCInit()) { UARTprintf("Initialization of the CRC module failed.\n"); ui32Errors |= 0x00000001; } // // Run through the test vectors. // for(ui32Idx = 0; ui32Idx < (sizeof(g_psCRC4C11DB7TestVectors) / sizeof(tCRCTestVector)); ui32Idx++) { UARTprintf("Starting vector #%d\n", ui32Idx); // // Generate the checksum without uDMA. // UARTprintf("Generating CRC-32 checksum without uDMA.\n"); ui32Result = CRC32DataProcess(g_pui32RandomData, (sizeof(g_pui32RandomData) / 4), g_psCRC4C11DB7TestVectors[ui32Idx].ui32Seed, false); if(ui32Result != g_psCRC4C11DB7TestVectors[ui32Idx].ui32Result) { UARTprintf("CRC result mismatch - Exp: 0x%08x, Act: 0x%08x\n", g_psCRC4C11DB7TestVectors[ui32Idx].ui32Result, ui32Result); } // // Generate the checksum with uDMA. // UARTprintf("Generating CRC-32 checksum with uDMA.\n"); ui32Result = CRC32DataProcess(g_pui32RandomData, (sizeof(g_pui32RandomData) / 4), g_psCRC4C11DB7TestVectors[ui32Idx].ui32Seed, true); if(ui32Result != g_psCRC4C11DB7TestVectors[ui32Idx].ui32Result) { UARTprintf("CRC result mismatch - Exp: 0x%08x, Act: 0x%08x\n", g_psCRC4C11DB7TestVectors[ui32Idx].ui32Result, ui32Result); } } // // 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 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) { } }
//***************************************************************************** // // The program main function. It performs initialization, then handles wav // file playback. // //***************************************************************************** int main(void) { int nStatus; // // Set the system clock to run at 80MHz from the PLL. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Give bget some memory to work with. // bpool(g_pulHeap, sizeof(g_pulHeap)); // // Set the device pin out appropriately for this board. // PinoutSet(); // // Configure the relevant pins such that UART0 owns them. // ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // Open the UART for I/O // UARTStdioInit(0); UARTprintf("i2s_speex_enc\n"); // // Configure and enable uDMA // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); SysCtlDelay(10); ROM_uDMAControlBaseSet(&sDMAControlTable[0]); ROM_uDMAEnable(); // // Enable Interrupts // ROM_IntMasterEnable(); // // Configure the I2S peripheral. // SoundInit(1); // // Set the format of the play back in the sound driver. // SoundSetFormat(AUDIO_RATE, AUDIO_BITS, AUDIO_CHANNELS); // // Print out some header information to the serial console. // UARTprintf("\ni2s_speex_enc Stellaris Example\n"); UARTprintf("Streaming at %d %d bit ",SoundSampleRateGet(), AUDIO_BITS); if(AUDIO_CHANNELS == 2) { UARTprintf("Stereo\n"); } else { UARTprintf("Mono\n"); } // // Set the initial volume. // SoundVolumeSet(INITIAL_VOLUME_PERCENT); // // Initialize the Speex decoder. // SpeexDecodeInit(); // // Set the default quality to 2. // g_iQuality = 2; // // Initialize the Speex encoder to Complexity of 1 and Quality 2. // SpeexEncodeInit(AUDIO_RATE, 1, g_iQuality); // // Initialize the audio buffers. // InitBuffers(); // // Initialize the applications global state flags. // g_ulFlags = 0; // // Kick off a request for a buffer play back and advance the encoder // pointer. // SoundBufferRead(g_pucRecBuffer, RECORD_BUFFER_INC, RecordBufferCallback); g_pucEncode += RECORD_BUFFER_INC; // // Kick off a second request for a buffer play back and advance the encode // pointer. // SoundBufferRead(&g_pucRecBuffer[RECORD_BUFFER_INC], RECORD_BUFFER_INC, RecordBufferCallback); g_pucEncode += RECORD_BUFFER_INC; // // The rest of the handling occurs at interrupt time so the main loop will // simply stall here. // while(1) { // // Print a prompt to the console. Show the CWD. // UARTprintf("\n> "); // // Get a line of text from the user. // UARTgets(g_cCmdBuf, sizeof(g_cCmdBuf)); // // Pass the line from the user to the command processor. // It will be parsed and valid commands executed. // nStatus = CmdLineProcess(g_cCmdBuf); // // Handle the case of bad command. // if(nStatus == CMDLINE_BAD_CMD) { UARTprintf("Bad command!\n"); } // // Handle the case of too many arguments. // else if(nStatus == CMDLINE_TOO_MANY_ARGS) { UARTprintf("Too many arguments for command processor!\n"); } // // Otherwise the command was executed. Print the error // code if one was returned. // else if(nStatus != 0) { UARTprintf("Command returned error code \n"); } } }
//***************************************************************************** // // This is the main loop that runs the application. // //***************************************************************************** int main(void) { tRectangle sRect; uint_fast32_t ui32Retcode; // // 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 SysTick for a 100Hz interrupt. The FatFs driver wants a 10 ms // tick. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / 100); ROM_SysTickEnable(); ROM_SysTickIntEnable(); // // Configure and enable uDMA // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); SysCtlDelay(10); ROM_uDMAControlBaseSet(&sDMAControlTable[0]); ROM_uDMAEnable(); // // Initialize the display driver. // CFAL96x64x16Init(); // // Initialize the graphics context. // GrContextInit(&g_sContext, &g_sCFAL96x64x16); // // 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 = DISPLAY_BANNER_HEIGHT - 1; GrContextForegroundSet(&g_sContext, ClrDarkBlue); GrRectFill(&g_sContext, &sRect); // // Put a white box around the banner. // GrContextForegroundSet(&g_sContext, ClrWhite); GrRectDraw(&g_sContext, &sRect); // // Put the application name in the middle of the banner. // GrContextFontSet(&g_sContext, g_psFontFixed6x8); GrStringDrawCentered(&g_sContext, "usb-dev-msc", -1, GrContextDpyWidthGet(&g_sContext) / 2, 5, 0); // // Initialize the idle timeout and reset all flags. // g_ui32IdleTimeout = 0; g_ui32Flags = 0; // // Initialize the state to idle. // g_eMSCState = MSC_DEV_DISCONNECTED; // // Draw the status bar and set it to idle. // UpdateStatus("Disconnected", 1); // // Enable the USB controller. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0); // // Set the USB pins to be controlled by the USB controller. // 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); // // 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. // USBDMSCInit(0, &g_sMSCDevice); // // Determine whether or not an SDCard is installed. If not, print a // warning and have the user install one and restart. // ui32Retcode = disk_initialize(0); GrContextFontSet(&g_sContext, g_psFontFixed6x8); if(ui32Retcode != RES_OK) { GrStringDrawCentered(&g_sContext, "No SDCard Found", -1, GrContextDpyWidthGet(&g_sContext) / 2, 16, 0); GrStringDrawCentered(&g_sContext, "Please insert", -1, GrContextDpyWidthGet(&g_sContext) / 2, 26, 0); GrStringDrawCentered(&g_sContext, "a card and", -1, GrContextDpyWidthGet(&g_sContext) / 2, 36, 0); GrStringDrawCentered(&g_sContext, "reset the board.", -1, GrContextDpyWidthGet(&g_sContext) / 2, 46, 0); } else { GrStringDrawCentered(&g_sContext, "SDCard Found", -1, GrContextDpyWidthGet(&g_sContext) / 2, 30, 0); } // // Drop into the main loop. // while(1) { switch(g_eMSCState) { case MSC_DEV_READ: { // // Update the screen if necessary. // if(g_ui32Flags & FLAG_UPDATE_STATUS) { UpdateStatus("Reading", 0); g_ui32Flags &= ~FLAG_UPDATE_STATUS; } // // If there is no activity then return to the idle state. // if(g_ui32IdleTimeout == 0) { UpdateStatus("Idle", 0); g_eMSCState = MSC_DEV_IDLE; } break; } case MSC_DEV_WRITE: { // // Update the screen if necessary. // if(g_ui32Flags & FLAG_UPDATE_STATUS) { UpdateStatus("Writing", 0); g_ui32Flags &= ~FLAG_UPDATE_STATUS; } // // If there is no activity then return to the idle state. // if(g_ui32IdleTimeout == 0) { UpdateStatus("Idle", 0); g_eMSCState = MSC_DEV_IDLE; } break; } case MSC_DEV_DISCONNECTED: { // // Update the screen if necessary. // if(g_ui32Flags & FLAG_UPDATE_STATUS) { UpdateStatus("Disconnected", 0); g_ui32Flags &= ~FLAG_UPDATE_STATUS; } break; } case MSC_DEV_IDLE: { break; } default: { break; } } } }
//***************************************************************************** // // 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 = 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, "grlib-demo"); // // Configure and enable uDMA // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); SysCtlDelay(10); ROM_uDMAControlBaseSet(&psDMAControlTable[0]); ROM_uDMAEnable(); // // Initialize the sound driver. // SoundInit(ui32SysClock); SoundVolumeSet(128); SoundStart(g_pi16AudioBuffer, AUDIO_SIZE, 64000, SoundCallback); // // 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); CanvasTextSet(&g_sTitle, g_pcPanelNames[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(); // // See if the first half of the sound buffer needs to be filled. // if(HWREGBITW(&g_ui32Flags, FLAG_PING) == 1) { // // generate new audio into the first half of the sound buffer. // GenerateAudio(g_pi16AudioBuffer, AUDIO_SIZE / 2); // // Clear the flag for the first half of the sound buffer. // HWREGBITW(&g_ui32Flags, FLAG_PING) = 0; } // // See if the second half of the sound buffer needs to be filled. // if(HWREGBITW(&g_ui32Flags, FLAG_PONG) == 1) { // // generate new audio into the second half of the sound buffer. // GenerateAudio(g_pi16AudioBuffer + (AUDIO_SIZE / 2), AUDIO_SIZE / 2); // // Clear the flag for the second half of the sound buffer. // HWREGBITW(&g_ui32Flags, FLAG_PONG) = 0; } } }
/* Main function * * - Initialise device and any global variables * - Enable Interrupts * - Start endless loop */ void main(void) { unsigned long ulRetcode; // Initialise the device clock to 80MHz ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN ); // Enable SysTick for FatFS at 10ms intervals ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / 100); ROM_SysTickEnable(); ROM_SysTickIntEnable(); // // Configure and enable uDMA // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); SysCtlDelay(10); ROM_uDMAControlBaseSet(&sDMAControlTable[0]); ROM_uDMAEnable(); // // Enable the USB controller. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0); // // Set the USB pins to be controlled by the USB controller. ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); ROM_GPIOPinTypeUSBAnalog(GPIO_PORTD_BASE, GPIO_PIN_4 | GPIO_PIN_5); // Initialize the idle timeout and reset all flags. // g_ulIdleTimeout = 0; g_ulFlags = 0; // // Initialize the state to idle. // g_eMSCState = MSC_DEV_DISCONNECTED; // // Set the USB stack mode to Device mode with VBUS monitoring. // USBStackModeSet(0, USB_MODE_DEVICE, 0); // // Pass our device information to the USB library and place the device // on the bus. // USBDMSCInit(0, (tUSBDMSCDevice *)&g_sMSCDevice); // // Determine whether or not an SDCard is installed. If not, print a // warning and have the user install one and restart. // ulRetcode = disk_initialize(0); // Enable Global interrupts ROM_IntMasterEnable(); // Enable floating point arithmetic unit, but disable stacking ROM_FPUEnable(); ROM_FPUStackingDisable(); // Initialise GPIO - All ports enabled ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // Unlock NMI pins for GPIO usage (PD7 + PF0) HWREG(GPIO_PORTD_BASE + 0x520) = 0x4C4F434B; HWREG(GPIO_PORTF_BASE + 0x520) = 0x4C4F434B; HWREG(GPIO_PORTD_BASE + 0x524) = 0x000000FF; HWREG(GPIO_PORTF_BASE + 0x524) = 0x000000FF; HWREG(GPIO_PORTD_BASE + 0x520) = 0x00000000; HWREG(GPIO_PORTF_BASE + 0x520) = 0x00000000; // Initialise GPIO Expander (probably not happening) // Initialise Buttons btn_init(); // Initialise FX fx_init(); // Initialise ADC adc_init(); // Initialise DAC dac_init(); // Initialise SD Card and Mass storage sdcard_init(); // Initialise UART for debugging uart_init(); // Initialise Timers timers_init(); for(;;) { // Endless Loop ADCProcessorTrigger(ADC0_BASE, 0); SysCtlDelay(SysCtlClockGet() / 120); // 25ms } }
//***************************************************************************** // // 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) { } }
void SSI3DMASlaveClass::configureDMA() { //Enable uDMA ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UDMA); //Register DMA interrupt to handler IntRegister(INT_UDMAERR, uDMAErrorHandler); //Enable interrupt ROM_IntEnable(INT_UDMAERR); // Enable the uDMA controller. ROM_uDMAEnable(); // Point at the control table to use for channel control structures. ROM_uDMAControlBaseSet(pui8ControlTable); //Assign DMA channels to SSI3 ROM_uDMAChannelAssign(UDMA_CH14_SSI3RX); ROM_uDMAChannelAssign(UDMA_CH15_SSI3TX); // Put the attributes in a known state for the uDMA SSI0RX channel. These // should already be disabled by default. ROM_uDMAChannelAttributeDisable(UDMA_CH14_SSI3RX, UDMA_ATTR_USEBURST | UDMA_ATTR_ALTSELECT | (UDMA_ATTR_HIGH_PRIORITY | UDMA_ATTR_REQMASK)); // Configure the control parameters for the primary control structure for // the SSIORX channel. ROM_uDMAChannelControlSet(UDMA_CH14_SSI3RX | UDMA_PRI_SELECT, UDMA_SIZE_8 | UDMA_SRC_INC_NONE | UDMA_DST_INC_8 | UDMA_ARB_4); //Enable DMA channel to write in the next buffer position ROM_uDMAChannelTransferSet(UDMA_CH14_SSI3RX | UDMA_PRI_SELECT, UDMA_MODE_BASIC, (void *)(SSI3_BASE + SSI_O_DR), g_ui8SSIRxBuf[g_ui8RxWriteIndex], sizeof(g_ui8SSIRxBuf[g_ui8RxWriteIndex])); // Configure TX // // Put the attributes in a known state for the uDMA SSI0TX channel. These // should already be disabled by default. // ROM_uDMAChannelAttributeDisable(UDMA_CH15_SSI3TX, UDMA_ATTR_ALTSELECT | UDMA_ATTR_HIGH_PRIORITY | UDMA_ATTR_REQMASK); // // // // Configure the control parameters for the primary control structure for // // the SSIORX channel. // // // ROM_uDMAChannelControlSet(UDMA_CH15_SSI3TX | UDMA_PRI_SELECT, // UDMA_SIZE_8 | UDMA_SRC_INC_NONE | UDMA_DST_INC_NONE | // UDMA_ARB_4); // // //Configure TX to always write 0xFF? // g_ui8SSITxBuf[0] = 0xFF; // // //Enable DMA channel to write in the next buffer position // ROM_uDMAChannelTransferSet(UDMA_CH15_SSI3TX | UDMA_PRI_SELECT, // UDMA_MODE_BASIC, g_ui8SSITxBuf, // (void *)(SSI3_BASE + SSI_O_DR), // sizeof(g_ui8SSITxBuf)); ROM_uDMAChannelEnable(UDMA_CH14_SSI3RX); // ROM_uDMAChannelEnable(UDMA_CH15_SSI3TX); // // // // Enable the SSI3 DMA TX/RX interrupts. // // // ROM_SSIIntEnable(SSI3_BASE, SSI_DMARX); // // // // // Enable the SSI3 peripheral interrupts. // // // ROM_IntEnable(INT_SSI3); }
//***************************************************************************** // // 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) { } }
//***************************************************************************** // // This example application demonstrates the use of a periodic timer to // request DMA transfers. // // Timer0 is used as the periodic timer that requests DMA transfers. // Timer1 is a free running counter that is used as the source data for // DMA transfers. The captured counter values from Timer1 are copied by // uDMA into a buffer. // //***************************************************************************** int main(void) { unsigned long ulIdx; unsigned long ulThisTimerVal; unsigned long ulPrevTimerVal; unsigned long ulTimerElapsed; unsigned long ulTimerErr; // // Set the clocking to run directly from the crystal. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Initialize the UART and write status. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTStdioInit(0); UARTprintf("\033[2JuDMA periodic timer example\n\n"); // // Enable the timers used by this example. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); // // Enable the uDMA peripheral // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); // // Enable the uDMA controller error interrupt. This interrupt will occur // if there is a bus error during a transfer. // ROM_IntEnable(INT_UDMAERR); // // Enable the uDMA controller. // ROM_uDMAEnable(); // // Point at the control table to use for channel control structures. // ROM_uDMAControlBaseSet(ucControlTable); // // Enable processor interrupts. // ROM_IntMasterEnable(); // // Configure one of the timers as free running 32-bit counter. Its // value will be used as a time reference. // ROM_TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC); ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, ~0); ROM_TimerEnable(TIMER1_BASE, TIMER_A); // // Configure the 32-bit periodic timer. // ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, TIMEOUT_VAL - 1); // // Enable the timer master interrupt. The timer interrupt will actually // be generated by the uDMA controller when the timer channel transfer is // complete. The interrupts on the timer (TimerIntEnable) do not need // to be configured. // ROM_IntEnable(INT_TIMER0A); // // Put the attributes in a known state for the uDMA Timer0A channel. These // should already be disabled by default. // ROM_uDMAChannelAttributeDisable(UDMA_CHANNEL_TMR0A, UDMA_ATTR_ALTSELECT | UDMA_ATTR_USEBURST | UDMA_ATTR_HIGH_PRIORITY | UDMA_ATTR_REQMASK); // // Set up the DMA channel for Timer 0A. Set it up to transfer single // 32-bit words at a time. The source is non-incrementing, the // destination is incrementing. // ROM_uDMAChannelControlSet(UDMA_CHANNEL_TMR0A | UDMA_PRI_SELECT, UDMA_SIZE_32 | UDMA_SRC_INC_NONE | UDMA_DST_INC_32 | UDMA_ARB_1); // // Set up the transfer for Timer 0A DMA channel. Basic mode is used, // which means that one transfer will occur per timer request (timeout). // The amount transferred per timeout is determined by the arbitration // size (see function above). The source will be the value of free running // Timer1, and the destination is a memory buffer. Thus, the value of the // free running Timer1 will be stored in a buffer every time the periodic // Timer0 times out. // ROM_uDMAChannelTransferSet(UDMA_CHANNEL_TMR0A | UDMA_PRI_SELECT, UDMA_MODE_BASIC, (void *)(TIMER1_BASE + TIMER_O_TAV), g_ulTimerBuf, MAX_TIMER_EVENTS); // // Enable the timers and the DMA channel. // UARTprintf("Using timeout value of %u\n", TIMEOUT_VAL); UARTprintf("Starting timer and uDMA\n"); TimerEnable(TIMER0_BASE, TIMER_A); uDMAChannelEnable(UDMA_CHANNEL_TMR0A); // // Wait for the transfer to complete. // UARTprintf("Waiting for transfers to complete\n"); while(!g_bDoneFlag) { } // // Check for the expected number of occurrences of the interrupt handler, // and that there are no DMA errors // if(g_uluDMAErrCount != 0) { UARTprintf("\nuDMA errors were detected!!!\n\n"); } if(g_ulTimer0AIntCount != 1) { UARTprintf("\nUnexpected number of interrupts occurrred (%d)!!!\n\n", g_ulTimer0AIntCount); } // // Display the timer values that were transferred using timer triggered // uDMA. Compare the difference between stored values to the timer // period and make sure they match. This verifies that the periodic // DMA transfers were occuring with the correct timing. // UARTprintf("\n Captured\n"); UARTprintf("Event Value Difference Status\n"); UARTprintf("----- ---------- ---------- ------\n"); for(ulIdx = 1; ulIdx < MAX_TIMER_EVENTS; ulIdx++) { // // Compute the difference between adjacent captured values, and then // compare that to the expected timeout period. // ulThisTimerVal = g_ulTimerBuf[ulIdx]; ulPrevTimerVal = g_ulTimerBuf[ulIdx - 1]; ulTimerElapsed = ulThisTimerVal > ulPrevTimerVal ? ulThisTimerVal - ulPrevTimerVal : ulPrevTimerVal - ulThisTimerVal; ulTimerErr = ulTimerElapsed > TIMEOUT_VAL ? ulTimerElapsed - TIMEOUT_VAL : TIMEOUT_VAL - ulTimerElapsed; // // Print the captured value and the difference from the previous // UARTprintf(" %2u 0x%08X %8u ", ulIdx, ulThisTimerVal, ulTimerElapsed); // // Print error status based on the deviation from expected difference // between samples (calculated above). Allow for a difference of up // to 1 cycle. Any more than that is considered an error. // if(ulTimerErr > 1) { UARTprintf(" ERROR\n"); } else { UARTprintf(" OK\n"); } } // // End of application // while(1) { } }
//***************************************************************************** // // This example encrypts blocks of plaintext using AES128 in ECB 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; uint32_t ui32Keysize; uint32_t *pui32CipherTextExp; tContext sContext; uint8_t ui8Loop; // // 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-ecb-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; } // // 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 ECB 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; } // // Perform the same operation with 128bit key first, then 256bit key. // for(ui8Loop = 0; ui8Loop < 2; ui8Loop++) { ui32Keysize = (ui8Loop == 0)?AES_CFG_KEY_SIZE_128BIT:AES_CFG_KEY_SIZE_256BIT; UARTprintf("\nKey Size: %sbit\n", ((ui8Loop == 0)?"128":"256")); // // Clear the array containing the cipher text. // for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { pui32CipherText[ui32Idx] = 0; } // // Perform the encryption without uDMA. // UARTprintf("Performing encryption without uDMA.\n"); AESECBEncrypt(ui32Keysize, g_pui32AESPlainText, pui32CipherText, (ui8Loop == 0)?g_pui32AES128Key:g_pui32AES256Key, 64, false); // // Check the result. // pui32CipherTextExp = (ui8Loop == 0)?g_pui32AES128CipherText: g_pui32AES256CipherText; for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { if(pui32CipherText[ui32Idx] != pui32CipherTextExp[ui32Idx]) { UARTprintf("Ciphertext mismatch on word %d. Exp: 0x%x, Act: " "0x%x\n", ui32Idx, pui32CipherTextExp[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"); AESECBEncrypt(ui32Keysize, g_pui32AESPlainText, pui32CipherText, (ui8Loop == 0)?g_pui32AES128Key:g_pui32AES256Key, 64, true); // // Check the result. // for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { if(pui32CipherText[ui32Idx] != pui32CipherTextExp[ui32Idx]) { UARTprintf("Ciphertext mismatch on word %d. Exp: 0x%x, Act: " "0x%x\n", ui32Idx, pui32CipherTextExp[ui32Idx], pui32CipherText[ui32Idx]); ui32Errors |= (ui32Idx << 16) | 0x00000004; } } } // // 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) { } }