//***************************************************************************** // // Delay for the specified number of seconds. Depending upon the current // SysTick value, the delay will be between N-1 and N seconds (i.e. N-1 full // seconds are guaranteed, along with the remainder of the current second). // //***************************************************************************** void Delay(uint32_t ui32Seconds) { uint8_t ui8Loop; // // Loop while there are more seconds to wait. // while(ui32Seconds--) { for(ui8Loop = 0; ui8Loop < 100; ui8Loop++) { // // Wait until the SysTick value is less than 1000. // while(ROM_SysTickValueGet() > 1000) { } // // Wait until the SysTick value is greater than 1000. // while(ROM_SysTickValueGet() < 1000) { } } } }
//***************************************************************************** // // This function is called to handle the GPIO edge interrupt from the // quadrature encoder. // //***************************************************************************** void EncoderIntHandler(void) { unsigned long ulNow; // // Save the time. // ulNow = ROM_SysTickValueGet(); // // Clear the encoder interrupt. // ROM_GPIOPinIntClear(QEI_PHA_PORT, QEI_PHA_PIN); // // Determine the number of system clocks between the previous edge and this // edge. // if(g_ulEncoderPrevious > ulNow) { g_ulEncoderClocks = g_ulEncoderPrevious - ulNow; } else { g_ulEncoderClocks = (16777216 - ulNow) + g_ulEncoderPrevious; } // // Save the time of the current edge as the time of the previous edge. // g_ulEncoderPrevious = ulNow; // // Indicate that an edge has been seen. // HWREGBITH(&g_usEncoderFlags, ENCODER_FLAG_EDGE) = 1; // // If the previous edge time was valid, then indicate that the time between // edges is also now valid. // if(HWREGBITH(&g_usEncoderFlags, ENCODER_FLAG_PREVIOUS) == 1) { HWREGBITH(&g_usEncoderFlags, ENCODER_FLAG_VALID) = 1; } // // Indicate that the previous edge time is valid. // HWREGBITH(&g_usEncoderFlags, ENCODER_FLAG_PREVIOUS) = 1; }
//***************************************************************************** // // Delay for the specified number of seconds. Depending upon the current // SysTick value, the delay will be between N-1 and N seconds (i.e. N-1 full // seconds are guaranteed, along with the remainder of the current second). // //***************************************************************************** void Delay(unsigned long ulSeconds) { // // Loop while there are more seconds to wait. // while(ulSeconds--) { // // Wait until the SysTick value is less than 1000. // while(ROM_SysTickValueGet() > 1000) { } // // Wait until the SysTick value is greater than 1000. // while(ROM_SysTickValueGet() < 1000) { } } }
int main_simple(void) { static uint32_t g_ui32SrcBuf[MEM_BUFFER_SIZE]; static uint32_t g_ui32DstBuf[MEM_BUFFER_SIZE]; /* Set up clock for 120MHz */ MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); /* Set up SysTick timer */ ROM_SysTickPeriodSet(0xffffffff); ROM_SysTickEnable(); /* Enable interrupts */ ROM_IntMasterEnable(); init_dma_memcpy(UDMA_CHANNEL_SW); { /* Scope out the counter */ uint_fast16_t ui16Idx; /* Fill source buffer with varying numbers */ for(ui16Idx = 0; ui16Idx < MEM_BUFFER_SIZE; ui16Idx++) { g_ui32SrcBuf[ui16Idx] = ui16Idx; } } void *cbfn_ptr[2] = {&set_udma_txfer_done, NULL}; volatile unsigned int t0 = (ROM_SysTickValueGet()); dma_memcpy( g_ui32DstBuf, g_ui32SrcBuf, MEM_BUFFER_SIZE, UDMA_CHANNEL_SW, cbfn_ptr[0] ); /* Wait for udma txfer to complete */ while (!udma_txfer_done); volatile unsigned int t1 = (ROM_SysTickValueGet()); memcpy(g_ui32DstBuf, g_ui32SrcBuf, MEM_BUFFER_SIZE); volatile unsigned int t2 = (ROM_SysTickValueGet()); t2 = t1 - t2; /* Calc time taken for memcpy */ t1 = t0 - t1; /* Calc time taken for dma_memcpy */ volatile uint32_t count_past_dma = 0; /* Wait around compare txfer times */ while (1){ count_past_dma++; } return 0; }
//***************************************************************************** // // This function is called to handle the GPIO edge interrupt from the // quadrature encoder. // //***************************************************************************** void QEI1IntHandler(void) { unsigned long ulNow; // // Save the time. // ulNow = ROM_SysTickValueGet(); // // Clear the encoder interrupt. // GPIOPinIntClear(QEI_ROLL_PHA_PORT, QEI_ROLL_PHA_PIN); ulstatus1 = QEIIntStatus(QEI1_BASE,false); if ( (ulstatus1 & QEI_INTDIR) == QEI_INTDIR) { // // clear Interrupt Bit QEIIntClear(QEI1_BASE, QEI_INTDIR); // //code for Direction change //.............. } if ( (ulstatus1 & QEI_INTINDEX) == QEI_INTINDEX) { // // clear Interrupt Bit QEIIntClear(QEI1_BASE, QEI_INTINDEX); // //code for Index change //.............. } if ( (ulstatus1 & QEI_INTERROR) == QEI_INTERROR) { // // clear Interrupt Bit QEIIntClear(QEI1_BASE, QEI_INTERROR); // //code for Phase ERROR //.............. } // // Determine the number of system clocks between the previous edge and this // edge. // if(g_ulEncoder1Previous > ulNow) { g_ulEncoder1Clocks = g_ulEncoder1Previous - ulNow; } else { g_ulEncoder1Clocks = (SYSCLK_80MHZ - ulNow) + g_ulEncoder1Previous; } // // Save the time of the current edge as the time of the previous edge. // g_ulEncoder1Previous = ulNow; // // Indicate that an edge has been seen. // HWREGBITH(&g_usEncoder1Flags, ENCODER_FLAG_EDGE) = 1; // // If the previous edge time was valid, then indicate that the time between // edges is also now valid. // if(HWREGBITH(&g_usEncoder1Flags, ENCODER_FLAG_PREVIOUS) == 1) { HWREGBITH(&g_usEncoder1Flags, ENCODER_FLAG_VALID) = 1; } // // Indicate that the previous edge time is valid. // HWREGBITH(&g_usEncoder1Flags, ENCODER_FLAG_PREVIOUS) = 1; }