//***************************************************************************** // // 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; } }
//***************************************************************************** // //! Main function for uDMA Application //! //! \param none //! //! \return none //! //***************************************************************************** void main() { static unsigned long ulPrevSeconds; static unsigned long ulPrevUARTCount = 0; unsigned long ulXfersCompleted; unsigned long ulBytesAvg=0; int iCount=0; // // Initailizing the board // BoardInit(); // // Muxing for Enabling UART_TX and UART_RX. // PinMuxConfig(); // // Initialising the Terminal. // InitTerm(); // // Display Welcome Message // DisplayBanner(); // // SysTick Enabling // SysTickIntRegister(SysTickHandler); SysTickPeriodSet(SYSTICK_RELOAD_VALUE); SysTickEnable(); // // uDMA Initialization // UDMAInit(); // // Register interrupt handler for UART // MAP_UARTIntRegister(UARTA0_BASE,UART0IntHandler); UART_PRINT("Completed DMA Initialization \n\r\n\r"); // // Auto DMA Transfer // UART_PRINT("Starting Auto DMA Transfer \n\r"); InitSWTransfer(); // // Scatter Gather DMA Transfer // UART_PRINT("Starting Scatter Gather DMA Operation\n\r"); InitSGTransfer(); while(!Done){} MAP_UtilsDelay(80000000); // // Ping Pong UART Transfer // InitUART0Transfer(); // // Remember the current SysTick seconds count. // ulPrevSeconds = g_ulSeconds; while(1) { // // Check to see if one second has elapsed. If so, the make some // updates. // if(g_ulSeconds != ulPrevSeconds) { uiCount++; // // Remember the new seconds count. // ulPrevSeconds = g_ulSeconds; // // 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. // ulBytesTransferred[iCount] = (ulXfersCompleted * UART_RXBUF_SIZE ); iCount++; // // Print a message to the display showing the memory transfer rate. // if(UARTDone) { MAP_PRCMPeripheralReset(PRCM_UARTA0); MAP_PRCMPeripheralClkEnable(PRCM_UARTA0,PRCM_RUN_MODE_CLK); UARTConfigSetExpClk(CONSOLE,SYSCLK, UART_BAUD_RATE, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); } } // // See if we have run long enough and exit the loop if so. // if(g_ulSeconds >= 6 && UARTDone) { break; } } // // Compute average Bytes Transfer Rate for the past 5 seconds // for(iCount=1;iCount<=5;iCount++) { ulBytesAvg += ulBytesTransferred[iCount]; } ulBytesAvg=ulBytesAvg/5; UART_PRINT("\n\r"); UART_PRINT("\n\r"); UART_PRINT("\n\rCompleted Ping Pong Transfer from Memory to UART " "Peripheral \n\r"); UART_PRINT(" \n\rTransfer Rate is %lu Bytes/Sec \n\r", ulBytesAvg); UART_PRINT("\n\rTest Ended\n\r"); return ; }