void confADC(){ SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); // Habilita ADC0 SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_ADC0); ADCSequenceDisable(ADC0_BASE,0); // Deshabilita el secuenciador 1 del ADC0 para su configuracion HWREG(ADC0_BASE + ADC_O_PC) = (ADC_PC_SR_500K); // usar en lugar de SysCtlADCSpeedSet ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_TIMER, 0);// Disparo de muestreo por instrucciones de Timer ADCHardwareOversampleConfigure(ADC0_BASE, 64); //SobreMuestreo de 64 muestras // Configuramos los 4 conversores del secuenciador 1 para muestreo del sensor de temperatura ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH0); //Sequencer Step 0: Samples Channel PE3 ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH1); //Sequencer Step 1: Samples Channel PE2 ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_CTL_CH2 | ADC_CTL_IE | ADC_CTL_END); //Sequencer Step 2: Samples Channel PE1 IntPrioritySet(INT_ADC0SS0,5<<5); // Tras configurar el secuenciador, se vuelve a habilitar ADCSequenceEnable(ADC0_BASE, 0); //Asociamos la funcion a la interrupcion ADCIntRegister(ADC0_BASE, 0,ADCIntHandler); //Activamos las interrupciones ADCIntEnable(ADC0_BASE,0); }
void confGPIO(){ //Inicializa el puerto F (LEDs) --> No hace falta si usamos la libreria RGB // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3); //ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0); //LEDS APAGADOS ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOE); //Inicializa los LEDs usando libreria RGB RGBInit(1); SysCtlPeripheralSleepEnable(GREEN_TIMER_PERIPH); SysCtlPeripheralSleepEnable(BLUE_TIMER_PERIPH); RGBEnable(); //Inicializamos los botones y su interrupción SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ButtonsInit(); GPIOIntClear(GPIO_PORTF_BASE, GPIO_INT_PIN_0|GPIO_INT_PIN_4); GPIOIntRegister(GPIO_PORTF_BASE,ButtonHandler); GPIOIntTypeSet(GPIO_PORTF_BASE,GPIO_INT_PIN_0|GPIO_INT_PIN_4, GPIO_BOTH_EDGES); GPIOIntEnable(GPIO_PORTF_BASE, GPIO_INT_PIN_0|GPIO_INT_PIN_4); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOF); }
void initHW(void) { volatile unsigned long ulLoop; //initHW(); SysCtlClockSet( SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); // Enable the ports SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // Inputs : // PE0 : Up button // PE1 : Down button // PE2 : Left button // PE3 : Right button // PF1 : Select button // GPIODirModeSet(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, GPIO_DIR_MODE_IN); GPIOPadConfigSet(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); GPIODirModeSet(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_DIR_MODE_IN); GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // Outputs: // PF0 : Status LED GPIODirModeSet(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_DIR_MODE_OUT); GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD); GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, 1); // Enable edge triggered interrupt on select button // Clear the interrupt just in case GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_FALLING_EDGE); GPIOPinIntEnable(GPIO_PORTF_BASE, GPIO_PIN_1 ); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOF); // Enable the interrupt for port F IntEnable(INT_GPIOF); // Global interrupt enable IntMasterEnable(); // a short delay to ensure stable IO before running the rest of the program for (ulLoop = 0; ulLoop < 200; ulLoop++) { } }
void confTimer(){ //Inicializamos el TIMER2 para el ADC como Trigger a una frecuencia de 10Hz SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_TIMER2); TimerControlStall(TIMER2_BASE,TIMER_A,true); TimerConfigure(TIMER2_BASE, TIMER_CFG_PERIODIC); uint32_t ui32Period = SysCtlClockGet() *0.1; TimerLoadSet(TIMER2_BASE, TIMER_A, ui32Period -1); TimerControlTrigger(TIMER2_BASE,TIMER_A,true); TimerEnable(TIMER2_BASE, TIMER_A); //Inicializamos el TIMER4 para la pulsación larga con un periodo de 2 segundos SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER4); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_TIMER4); TimerConfigure(TIMER4_BASE, TIMER_CFG_ONE_SHOT); ui32Period = (SysCtlClockGet() *2) ; TimerLoadSet(TIMER4_BASE, TIMER_A, ui32Period -1); IntEnable(INT_TIMER4A); TimerIntRegister(TIMER4_BASE,TIMER_A,timerBotonHandler); IntPrioritySet(INT_TIMER4A,5<<5); TimerIntEnable(TIMER4_BASE, TIMER_TIMA_TIMEOUT); }
//***************************************************************************** // // Main application entry point. // //***************************************************************************** int main(void) { int_fast32_t i32IPart[16], i32FPart[16]; uint_fast32_t ui32Idx, ui32CompDCMStarted; float pfData[16]; float *pfAccel, *pfGyro, *pfMag, *pfEulers, *pfQuaternion; // // Initialize convenience pointers that clean up and clarify the code // meaning. We want all the data in a single contiguous array so that // we can make our pretty printing easier later. // pfAccel = pfData; pfGyro = pfData + 3; pfMag = pfData + 6; pfEulers = pfData + 9; pfQuaternion = pfData + 12; // // Setup the system clock to run at 40 Mhz from PLL with crystal reference // SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); // // Enable port B used for motion interrupt. // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); // // Initialize the UART. // ConfigureUART(); // // Print the welcome message to the terminal. // UARTprintf("\033[2JMPU9150 Raw Example\n"); // // Set the color to a purple approximation. // g_pui32Colors[RED] = 0x8000; g_pui32Colors[BLUE] = 0x8000; g_pui32Colors[GREEN] = 0x0000; // // Initialize RGB driver. // RGBInit(0); RGBColorSet(g_pui32Colors); RGBIntensitySet(0.5f); RGBEnable(); // // The I2C3 peripheral must be enabled before use. // SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C3); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); // // Configure the pin muxing for I2C3 functions on port D0 and D1. // GPIOPinConfigure(GPIO_PD0_I2C3SCL); GPIOPinConfigure(GPIO_PD1_I2C3SDA); // // Select the I2C function for these pins. This function will also // configure the GPIO pins pins for I2C operation, setting them to // open-drain operation with weak pull-ups. Consult the data sheet // to see which functions are allocated per pin. // GPIOPinTypeI2CSCL(GPIO_PORTD_BASE, GPIO_PIN_0); GPIOPinTypeI2C(GPIO_PORTD_BASE, GPIO_PIN_1); // // Configure and Enable the GPIO interrupt. Used for INT signal from the // MPU9150 // GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_2); GPIOIntEnable(GPIO_PORTB_BASE, GPIO_PIN_2); GPIOIntTypeSet(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_FALLING_EDGE); IntEnable(INT_GPIOB); // // Keep only some parts of the systems running while in sleep mode. // GPIOB is for the MPU9150 interrupt pin. // UART0 is the virtual serial port // TIMER0, TIMER1 and WTIMER5 are used by the RGB driver // I2C3 is the I2C interface to the ISL29023 // SysCtlPeripheralClockGating(true); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOB); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART0); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_TIMER0); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_TIMER1); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_I2C3); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_WTIMER5); // // Enable interrupts to the processor. // IntMasterEnable(); // // Initialize I2C3 peripheral. // I2CMInit(&g_sI2CInst, I2C3_BASE, INT_I2C3, 0xff, 0xff, SysCtlClockGet()); // // Initialize the MPU9150 Driver. // MPU9150Init(&g_sMPU9150Inst, &g_sI2CInst, MPU9150_I2C_ADDRESS, MPU9150AppCallback, &g_sMPU9150Inst); // // Wait for transaction to complete // MPU9150AppI2CWait(__FILE__, __LINE__); // // Write application specifice sensor configuration such as filter settings // and sensor range settings. // g_sMPU9150Inst.pui8Data[0] = MPU9150_CONFIG_DLPF_CFG_94_98; g_sMPU9150Inst.pui8Data[1] = MPU9150_GYRO_CONFIG_FS_SEL_250; g_sMPU9150Inst.pui8Data[2] = (MPU9150_ACCEL_CONFIG_ACCEL_HPF_5HZ | MPU9150_ACCEL_CONFIG_AFS_SEL_2G); MPU9150Write(&g_sMPU9150Inst, MPU9150_O_CONFIG, g_sMPU9150Inst.pui8Data, 3, MPU9150AppCallback, &g_sMPU9150Inst); // // Wait for transaction to complete // MPU9150AppI2CWait(__FILE__, __LINE__); // // Configure the data ready interrupt pin output of the MPU9150. // g_sMPU9150Inst.pui8Data[0] = MPU9150_INT_PIN_CFG_INT_LEVEL | MPU9150_INT_PIN_CFG_INT_RD_CLEAR | MPU9150_INT_PIN_CFG_LATCH_INT_EN; g_sMPU9150Inst.pui8Data[1] = MPU9150_INT_ENABLE_DATA_RDY_EN; MPU9150Write(&g_sMPU9150Inst, MPU9150_O_INT_PIN_CFG, g_sMPU9150Inst.pui8Data, 2, MPU9150AppCallback, &g_sMPU9150Inst); // // Wait for transaction to complete // MPU9150AppI2CWait(__FILE__, __LINE__); // // Initialize the DCM system. 50 hz sample rate. // accel weight = .2, gyro weight = .8, mag weight = .2 // CompDCMInit(&g_sCompDCMInst, 1.0f / 50.0f, 0.2f, 0.6f, 0.2f); UARTprintf("\033[2J\033[H"); UARTprintf("MPU9150 9-Axis Simple Data Application Example\n\n"); UARTprintf("\033[20GX\033[31G|\033[43GY\033[54G|\033[66GZ\n\n"); UARTprintf("Accel\033[8G|\033[31G|\033[54G|\n\n"); UARTprintf("Gyro\033[8G|\033[31G|\033[54G|\n\n"); UARTprintf("Mag\033[8G|\033[31G|\033[54G|\n\n"); UARTprintf("\n\033[20GRoll\033[31G|\033[43GPitch\033[54G|\033[66GYaw\n\n"); UARTprintf("Eulers\033[8G|\033[31G|\033[54G|\n\n"); UARTprintf("\n\033[17GQ1\033[26G|\033[35GQ2\033[44G|\033[53GQ3\033[62G|" "\033[71GQ4\n\n"); UARTprintf("Q\033[8G|\033[26G|\033[44G|\033[62G|\n\n"); // // Enable blinking indicates config finished successfully // RGBBlinkRateSet(1.0f); ui32CompDCMStarted = 0; while(1) { // // Go to sleep mode while waiting for data ready. // while(!g_vui8I2CDoneFlag) { SysCtlSleep(); } // // Clear the flag // g_vui8I2CDoneFlag = 0; // // Get floating point version of the Accel Data in m/s^2. // MPU9150DataAccelGetFloat(&g_sMPU9150Inst, pfAccel, pfAccel + 1, pfAccel + 2); // // Get floating point version of angular velocities in rad/sec // MPU9150DataGyroGetFloat(&g_sMPU9150Inst, pfGyro, pfGyro + 1, pfGyro + 2); // // Get floating point version of magnetic fields strength in tesla // MPU9150DataMagnetoGetFloat(&g_sMPU9150Inst, pfMag, pfMag + 1, pfMag + 2); // // Check if this is our first data ever. // if(ui32CompDCMStarted == 0) { // // Set flag indicating that DCM is started. // Perform the seeding of the DCM with the first data set. // ui32CompDCMStarted = 1; CompDCMMagnetoUpdate(&g_sCompDCMInst, pfMag[0], pfMag[1], pfMag[2]); CompDCMAccelUpdate(&g_sCompDCMInst, pfAccel[0], pfAccel[1], pfAccel[2]); CompDCMGyroUpdate(&g_sCompDCMInst, pfGyro[0], pfGyro[1], pfGyro[2]); CompDCMStart(&g_sCompDCMInst); } else { // // DCM Is already started. Perform the incremental update. // CompDCMMagnetoUpdate(&g_sCompDCMInst, pfMag[0], pfMag[1], pfMag[2]); CompDCMAccelUpdate(&g_sCompDCMInst, pfAccel[0], pfAccel[1], pfAccel[2]); CompDCMGyroUpdate(&g_sCompDCMInst, -pfGyro[0], -pfGyro[1], -pfGyro[2]); CompDCMUpdate(&g_sCompDCMInst); } // // Increment the skip counter. Skip counter is used so we do not // overflow the UART with data. // g_ui32PrintSkipCounter++; if(g_ui32PrintSkipCounter >= PRINT_SKIP_COUNT) { // // Reset skip counter. // g_ui32PrintSkipCounter = 0; // // Get Euler data. (Roll Pitch Yaw) // CompDCMComputeEulers(&g_sCompDCMInst, pfEulers, pfEulers + 1, pfEulers + 2); // // Get Quaternions. // CompDCMComputeQuaternion(&g_sCompDCMInst, pfQuaternion); // // convert mag data to micro-tesla for better human interpretation. // pfMag[0] *= 1e6; pfMag[1] *= 1e6; pfMag[2] *= 1e6; // // Convert Eulers to degrees. 180/PI = 57.29... // Convert Yaw to 0 to 360 to approximate compass headings. // pfEulers[0] *= 57.295779513082320876798154814105f; pfEulers[1] *= 57.295779513082320876798154814105f; pfEulers[2] *= 57.295779513082320876798154814105f; if(pfEulers[2] < 0) { pfEulers[2] += 360.0f; } // // Now drop back to using the data as a single array for the // purpose of decomposing the float into a integer part and a // fraction (decimal) part. // for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { // // Conver float value to a integer truncating the decimal part. // i32IPart[ui32Idx] = (int32_t) pfData[ui32Idx]; // // Multiply by 1000 to preserve first three decimal values. // Truncates at the 3rd decimal place. // i32FPart[ui32Idx] = (int32_t) (pfData[ui32Idx] * 1000.0f); // // Subtract off the integer part from this newly formed decimal // part. // i32FPart[ui32Idx] = i32FPart[ui32Idx] - (i32IPart[ui32Idx] * 1000); // // make the decimal part a positive number for display. // if(i32FPart[ui32Idx] < 0) { i32FPart[ui32Idx] *= -1; } } // // Print the acceleration numbers in the table. // UARTprintf("\033[5;17H%3d.%03d", i32IPart[0], i32FPart[0]); UARTprintf("\033[5;40H%3d.%03d", i32IPart[1], i32FPart[1]); UARTprintf("\033[5;63H%3d.%03d", i32IPart[2], i32FPart[2]); // // Print the angular velocities in the table. // UARTprintf("\033[7;17H%3d.%03d", i32IPart[3], i32FPart[3]); UARTprintf("\033[7;40H%3d.%03d", i32IPart[4], i32FPart[4]); UARTprintf("\033[7;63H%3d.%03d", i32IPart[5], i32FPart[5]); // // Print the magnetic data in the table. // UARTprintf("\033[9;17H%3d.%03d", i32IPart[6], i32FPart[6]); UARTprintf("\033[9;40H%3d.%03d", i32IPart[7], i32FPart[7]); UARTprintf("\033[9;63H%3d.%03d", i32IPart[8], i32FPart[8]); // // Print the Eulers in a table. // UARTprintf("\033[14;17H%3d.%03d", i32IPart[9], i32FPart[9]); UARTprintf("\033[14;40H%3d.%03d", i32IPart[10], i32FPart[10]); UARTprintf("\033[14;63H%3d.%03d", i32IPart[11], i32FPart[11]); // // Print the quaternions in a table format. // UARTprintf("\033[19;14H%3d.%03d", i32IPart[12], i32FPart[12]); UARTprintf("\033[19;32H%3d.%03d", i32IPart[13], i32FPart[13]); UARTprintf("\033[19;50H%3d.%03d", i32IPart[14], i32FPart[14]); UARTprintf("\033[19;68H%3d.%03d", i32IPart[15], i32FPart[15]); } } }
void sleepEnablePeripherals(){ SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOA); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOB); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOC); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOD); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOE); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_SSI0); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_I2C1); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_I2C2); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART5); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART1); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART3); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_TIMER0); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_TIMER1); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOF); SysCtlPeripheralClockGating(true); }
void InitUartInterface(uint32_t sys_clock) { uart_rx_read_index = 0; uart_rx_write_index = 0; const uint32_t dma_rx_primary = UDMA_CHANNEL_UART1RX | UDMA_PRI_SELECT; SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART1); //921600 //460800 uint32_t uart_config = UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE; UARTConfigSetExpClk(UART1_BASE, sys_clock, 921600, uart_config); GPIOPinConfigure(GPIO_PB0_U1RX); GPIOPinConfigure(GPIO_PB1_U1TX); GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTFIFOLevelSet(UART1_BASE, UART_FIFO_TX4_8, UART_FIFO_RX4_8); UARTEnable(UART1_BASE); //UARTDMAEnable(UART1_BASE, UART_DMA_RX | UART_DMA_TX); UARTDMAEnable(UART1_BASE, UART_DMA_RX); // Put the attributes in a known state for the uDMA UART1RX channel. These // should already be disabled by default. uint32_t dma_config = UDMA_ATTR_ALTSELECT | UDMA_ATTR_USEBURST | UDMA_ATTR_HIGH_PRIORITY | UDMA_ATTR_REQMASK; uDMAChannelAttributeDisable(UDMA_CHANNEL_UART1RX, dma_config); uint32_t dma_control = UDMA_SIZE_8 | UDMA_SRC_INC_NONE | UDMA_DST_INC_8 | UDMA_ARB_4; uDMAChannelControlSet(dma_rx_primary, dma_control); uDMAChannelTransferSet(dma_rx_primary, UDMA_MODE_BASIC, (void *)(UART1_BASE + UART_O_DR), &uart_rx_buf[uart_rx_write_index], UART_RX_BLOCK_SIZE); // Put the attributes in a known state for the uDMA UART1TX channel. These // should already be disabled by default. // uDMAChannelAttributeDisable(UDMA_CHANNEL_UART1TX, // UDMA_ATTR_ALTSELECT | // UDMA_ATTR_HIGH_PRIORITY | // UDMA_ATTR_REQMASK); // Set the USEBURST attribute for the uDMA UART TX channel. This will // force the controller to always use a burst when transferring data from // the TX buffer to the UART. This is somewhat more effecient bus usage // than the default which allows single or burst transfers. //uDMAChannelAttributeEnable(UDMA_CHANNEL_UART1TX, UDMA_ATTR_USEBURST); // Configure the control parameters for the UART TX. The uDMA UART TX // channel is used to transfer a block of data from a buffer to the UART. // The data size is 8 bits. The source address increment is 8-bit bytes // since the data is coming from a buffer. The destination increment is // none since the data is to be written to the UART data register. The // arbitration size is set to 4, which matches the UART TX FIFO trigger // threshold. // uDMAChannelControlSet(UDMA_CHANNEL_UART1TX | UDMA_PRI_SELECT, // UDMA_SIZE_8 | UDMA_SRC_INC_8 | // UDMA_DST_INC_NONE | // UDMA_ARB_4); // Set up the transfer parameters for the uDMA UART TX channel. This will // configure the transfer source and destination and the transfer size. // Basic mode is used because the peripheral is making the uDMA transfer // request. The source is the TX buffer and the destination is the UART // data register. // uDMAChannelTransferSet(UDMA_CHANNEL_UART1TX | UDMA_PRI_SELECT, // UDMA_MODE_BASIC, g_ui8TxBuf, // (void *)(UART1_BASE + UART_O_DR), // sizeof(g_ui8TxBuf)); // Now both the uDMA UART TX and RX channels are primed to start a // transfer. As soon as the channels are enabled, the peripheral will // issue a transfer request and the data transfers will begin. uDMAChannelEnable(UDMA_CHANNEL_UART1RX); //uDMAChannelEnable(UDMA_CHANNEL_UART1TX); // Enable the UART DMA TX/RX interrupts. //UARTIntEnable(UART1_BASE, UART_INT_DMATX | UART_INT_DMATX); UARTIntEnable(UART1_BASE, UART_INT_DMARX); IntEnable(INT_UART1); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); MAP_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); MAP_TimerLoadSet(TIMER0_BASE, TIMER_A, sys_clock / 2000); MAP_IntEnable(INT_TIMER0A); MAP_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); MAP_TimerEnable(TIMER0_BASE, TIMER_A); MAP_IntPrioritySet(INT_TIMER0A, 0xC0); }
//***************************************************************************** // //! Initializes the user interface. //! //! This function initializes the user interface modules (on-board and serial), //! preparing them to operate and control the motor drive. //! //! \return None. // //***************************************************************************** void UIInit(void) { unsigned long ulSysTickVal; // // Enable the GPIO peripherals needed for the button and LEDs // SysCtlPeripheralEnable(USER_BUTTON_GPIO_PERIPH); SysCtlPeripheralEnable(LED_GPIO_PERIPH); // // Set up button GPIO as input, and LEDs as outputs, and turn them off // GPIODirModeSet(USER_BUTTON_PORT, USER_BUTTON_PIN, GPIO_DIR_MODE_IN); GPIODirModeSet(STATUS_LED_PORT, STATUS_LED_PIN, GPIO_DIR_MODE_OUT); GPIODirModeSet(MODE_LED_PORT, MODE_LED_PIN, GPIO_DIR_MODE_OUT); GPIOPinWrite(STATUS_LED_PORT, STATUS_LED_PIN, 0); GPIOPinWrite(MODE_LED_PORT, MODE_LED_PIN, 0); // // Set up the LED blinking function // BlinkInit(STATUS_LED, STATUS_LED_PORT, STATUS_LED_PIN); BlinkInit(MODE_LED, MODE_LED_PORT, MODE_LED_PIN); BlinkStart(MODE_LED, UI_INT_RATE / 2, UI_INT_RATE / 2, eUIMode + 1); // // Enable the ADC peripheral, needed for potentiometer // SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_ADC0); // // Set the ADC to run at the maximum rate of 500 ksamples. // HWREG(SYSCTL_RCGC0) |= 0x00000200; HWREG(SYSCTL_SCGC0) |= 0x00000200; // // Program sequencer for collecting ADC sample for potentiometer // position, bus voltage, and temperature sensor. // ADCSequenceConfigure(ADC0_BASE, UI_ADC_SEQUENCER, ADC_TRIGGER_PROCESSOR, UI_ADC_PRIORITY); ADCSequenceStepConfigure(ADC0_BASE, UI_ADC_SEQUENCER, 0, POT_ADC_CHAN); ADCSequenceStepConfigure(ADC0_BASE, UI_ADC_SEQUENCER, 1, BUSV_ADC_CHAN); ADCSequenceStepConfigure(ADC0_BASE, UI_ADC_SEQUENCER, 2, ADC_CTL_TS | ADC_CTL_END); ADCSequenceEnable(ADC0_BASE, UI_ADC_SEQUENCER); ADCProcessorTrigger(ADC0_BASE, UI_ADC_SEQUENCER); // take initial sample // // initialize the lower level, // positioner, which handles computing all the motion control // StepperInit(); // // Get a pointer to the stepper status. // pStepperStatus = StepperGetMotorStatus(); // // Force an update of all the parameters (sets defaults). // UISetPWMFreq(); UISetChopperBlanking(); UISetMotorParms(); UISetControlMode(); UISetDecayMode(); UISetStepMode(); UISetFixedOnTime(); // // Initialize the flash parameter block driver. // FlashPBInit(FLASH_PB_START, FLASH_PB_END, FLASH_PB_SIZE); // // Initialize the serial user interface. // UISerialInit(); IntPrioritySet(INT_UART0, UI_SER_INT_PRI); // // Make sure that the UART doesnt get put to sleep // SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART0); // // Initialize the on-board user interface. // UIOnboardInit(GPIOPinRead(USER_BUTTON_PORT, USER_BUTTON_PIN), 0); // // Initialize the processor usage routine. // CPUUsageInit(SysCtlClockGet(), UI_INT_RATE, 2); // // Configure SysTick to provide a periodic user interface interrupt. // SysTickPeriodSet(SysCtlClockGet() / UI_INT_RATE); SysTickIntEnable(); SysTickEnable(); IntPrioritySet(FAULT_SYSTICK, SYSTICK_INT_PRI); // // A delay is needed to let the current sense line discharge after // reset, before the current fault parameter is configured. The // two loops below let the systick roll around once before proceeding. // ulSysTickVal = SysTickValueGet(); // // Wait for systick to reach 0 and roll over to top. // while(SysTickValueGet() <= ulSysTickVal) { } // // Wait for systick to get back to the starting value. // while(SysTickValueGet() > ulSysTickVal) { } // // Now set the current fault parameter (after the delay above). // UISetFaultParms(); // // Load stored parameters from flash, if any are available. // UIParamLoad(); }
void camera_init() { Serial_puts(UART_DEBUG_MODULE, "inside \"camera_init\"\r\n", 100); // Calculate the PWM clock frequency camera_PWMClockFreq = SysCtlClockGet() / CAMERA_CLOCK_DIV; DEBUG_LINE("camera_init"); // Enable the PWM peripheral SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0); // Enable the GPIO port SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); // Configure PD0 as the PWM output for the drive motor GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_7); GPIOPinConfigure(GPIO_PB7_M0PWM1); GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_4); GPIOPinConfigure(GPIO_PB4_M0PWM2); // Set the camera clock pulse period PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN); PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, CAMERA_SAMPLE_PERIOD - 1); PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, (CAMERA_SAMPLE_PERIOD / 2) - 1); // Set the camera enable pulse period PWMGenConfigure(PWM0_BASE, PWM_GEN_1, PWM_GEN_MODE_DOWN); PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, (CAMERA_SAMPLE_PERIOD * CAMERA_SAMPLES) - 1); PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2, ((CAMERA_SAMPLE_PERIOD / 2) * 2) - 1); DEBUG_LINE("camera_init"); // Enable the PWM output PWMOutputState(PWM0_BASE, PWM_OUT_1_BIT | PWM_OUT_2_BIT, true); PWMGenEnable(PWM0_BASE, PWM_GEN_0); PWMGenEnable(PWM0_BASE, PWM_GEN_1); PWMSyncTimeBase(PWM0_BASE, PWM_GEN_0_BIT | PWM_GEN_1_BIT); // Enable PWM trigger on zero count on Generator 0 PWMGenIntTrigEnable(PWM0_BASE, PWM_GEN_0, PWM_TR_CNT_ZERO); // PWM_TR_CNT_ZERO/PWM_TR_CNT_LOAD // Trigger an interrupt on GEN1 load (to setup the uDMA transfer on a consistent time boundary) PWMGenIntTrigEnable(PWM0_BASE, PWM_GEN_1, PWM_INT_CNT_LOAD); DEBUG_LINE("camera_init"); /******************************************** * ADC CONFIGURATION * ******************************************** */ // Enable ADC0 module SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); DEBUG_LINE("camera_init"); ADCClockConfigSet(ADC0_BASE, ADC_CLOCK_SRC_PIOSC | ADC_CLOCK_RATE_FULL, 1); DEBUG_LINE("camera_init"); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); // Camera Far GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3); // Camera Near GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_2); DEBUG_LINE("camera_init"); // Configure and enable the ADC sequence; single sample ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PWM0, 0); ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END); ADCSequenceEnable(ADC0_BASE, 3); DEBUG_LINE("camera_init"); ADCSequenceDMAEnable(ADC0_BASE, 3); DEBUG_LINE("camera_init"); // Start writing into the first buffer camera_DBSelected = 0; current_Camera = FAR; // Expose the other buffer camera_buffer = camera_DoubleBuffer[1]; /******************************************** * uDMA CONFIGURATION * ******************************************** */ // Enable the uDMA for normal and sleep operation SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UDMA); uDMAEnable(); DEBUG_LINE("camera_init"); // Set the position of the uDMA control table uDMAControlBaseSet(uDMAControlTable); // Put the uDMA table entry for ADC3 into a known state uDMAChannelAttributeDisable(UDMA_CHANNEL_ADC3, UDMA_ATTR_USEBURST | UDMA_ATTR_ALTSELECT | UDMA_ATTR_HIGH_PRIORITY | UDMA_ATTR_REQMASK); // Configure the primary and alternate uDMA channel structures uDMAChannelControlSet(UDMA_CHANNEL_ADC3 | UDMA_PRI_SELECT, UDMA_SIZE_16 | UDMA_SRC_INC_NONE | UDMA_DST_INC_16 | UDMA_ARB_1); uDMAChannelControlSet(UDMA_CHANNEL_ADC3 | UDMA_ALT_SELECT, UDMA_SIZE_16 | UDMA_SRC_INC_NONE | UDMA_DST_INC_16 | UDMA_ARB_1); // Configure the primary and alternate transfers for ping-pong operation uDMAChannelTransferSet(UDMA_CHANNEL_ADC3 | UDMA_PRI_SELECT, UDMA_MODE_PINGPONG, (void*) (ADC0_BASE + ADC_O_SSFIFO3), camera_DoubleBuffer[0], CAMERA_SAMPLES); uDMAChannelTransferSet(UDMA_CHANNEL_ADC3 | UDMA_ALT_SELECT, UDMA_MODE_PINGPONG, (void*) (ADC0_BASE + ADC_O_SSFIFO3), camera_DoubleBuffer[1], CAMERA_SAMPLES); DEBUG_LINE("camera_init"); // Enable the ADC3 uDMA channel uDMAChannelEnable(UDMA_CHANNEL_ADC3); // Enable interrupts // IntEnable(INT_ADC0SS3); // ADCIntEnableEx(ADC0_BASE, ADC_INT_DMA_SS3); IntEnable(INT_PWM0_1); PWMIntEnable(PWM0_BASE, PWM_INT_GEN_1); DEBUG_LINE("camera_init"); }
// ***************************************************************************** // InitialiseHW // Setup the processor // ***************************************************************************** void InitialiseHW ( void ) { // If running on Rev A2 silicon, turn the LDO voltage up to 2.75V. This is // a workaround to allow the PLL to operate reliably. // if(REVISION_IS_A2) { SysCtlLDOSet(SYSCTL_LDO_2_75V); } // 50 MHz SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); // Enable Peripherals SysCtlPeripheralEnable(SYSCTL_PERIPH_ETH); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH); SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1); // Set interrupt priority levels IntPrioritySet(INT_ETH, 0x20); IntPrioritySet(FAULT_SYSTICK, 0x40); // // Enable the peripherals that should continue to run when the processor // is sleeping. // SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOA); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOB); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOC); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOD); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOE); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOF); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOG); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOH); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART0); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART1); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_ETH); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_TIMER0); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_TIMER1); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_TIMER2); // // Enable peripheral clock gating. Note that this is required in order to // measure the the processor usage. // SysCtlPeripheralClockGating(true); // Grab the Config from Flash SysConfigInit(); AdcInit(); pwmInit(); RelayInit(); //usrand(0x23482937); // Note (From the DriverLib) : // It takes five clock cycles after the write to enable a peripheral // before the the peripheral is actually enabled. During this time, attempts // to access the peripheral result in a bus fault. Care should be taken // to ensure that the peripheral is not accessed during this brief time // period. #ifdef SERIAL_ENABLED Serial_Init(); #endif #ifdef UPNP_ENABLED UPnPInit(); #endif Ethernet_Init(); #ifdef LOGIC_ENABLED LogicStartStop(true); #endif #ifdef SOLDERBRIDGES_ENABLED SB_Init(); ExtGpio_Init(); SolderBridge_StartScan(); ExtGpio_Scan(); #endif #ifdef SPLASHPIXEL_ENABLED SP_Init(); #endif // Set up the GPIO as specified by the user UserGpioInit(); // Most, if not all M3's have a SysTick which you can use for scheduling your code SysTickPeriodSet(SysCtlClockGet() / SYSTICKHZ); SysTickEnable(); SysTickIntEnable(); }