int cppmain() { init(); resetMicros(); enableMessaging(); // Set up the pins int i; for (i = 0; i < 12; i++) pinMode(legPins[i], OUTPUT_SERVO); pinMode(BLUE_LED, OUTPUT); // We will use WTIMER0 for the interrupts ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER0); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_WTIMER0); ROM_TimerConfigure(WTIMER0_BASE, (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_PERIODIC)); // Set up the stag walking timer interrupt ROM_TimerPrescaleSet(WTIMER0_BASE, TIMER_A, 79999); // 1 ms per tick TimerIntRegister(WTIMER0_BASE, TIMER_A, stagInterrupt); ROM_TimerLoadSet(WTIMER0_BASE, TIMER_A, 50); // 50 ms per cylce ROM_TimerIntEnable(WTIMER0_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerEnable(WTIMER0_BASE, TIMER_A); ROM_IntPrioritySet(INT_WTIMER0A, 0x20); // Set general sensor/status interrupt ROM_TimerPrescaleSet(WTIMER0_BASE, TIMER_B, 79999); // 1 ms per tick TimerIntRegister(WTIMER0_BASE, TIMER_B, statusInterrupt); ROM_TimerLoadSet(WTIMER0_BASE, TIMER_B, 500); // 500 ms per cycle ROM_TimerIntEnable(WTIMER0_BASE, TIMER_TIMB_TIMEOUT); ROM_TimerEnable(WTIMER0_BASE, TIMER_B); ROM_IntPrioritySet(INT_WTIMER0A, 0x40); uint16_t msgLength; uint16_t msgFlags; MessageType msgType; // Main message handing loop bool z = true; while (1) { digitalWrite(BLUE_LED, z); z = !z; switch (getMessage(&msgType, &msgLength, &msgFlags, g_msgBody)) { case 0: // Success handleMessage(msgType, msgLength, g_msgBody); break; case 1: // Timeout //sendError(TIMEOUT_ERROR); break; case 2: // CRC Error sendError(CRC_ERROR); break; } //delay(10000); } }
//***************************************************************************** // //! Initializes the touch screen driver. //! //! \param ui32SysClock is the frequency of the system clock. //! //! This function initializes the touch screen driver, beginning the process of //! reading from the touch screen. This driver uses the following hardware //! resources: //! //! - ADC 0 sample sequence 3 //! - Timer 5 subtimer B //! //! \return None. // //***************************************************************************** void TouchScreenInit(uint32_t ui32SysClock) { // // Set the initial state of the touch screen driver's state machine. // g_ui32TSState = TS_STATE_INIT; // // There is no touch screen handler initially. // g_pfnTSHandler = 0; // // Enable the peripherals used by the touch screen interface. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER5); // // Configure the ADC sample sequence used to read the touch screen reading. // ROM_ADCHardwareOversampleConfigure(ADC0_BASE, 4); ROM_ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_TIMER, 0); ROM_ADCSequenceStepConfigure(ADC0_BASE, 3, 0, TS_YP_ADC | ADC_CTL_END | ADC_CTL_IE); ROM_ADCSequenceEnable(ADC0_BASE, 3); // // Enable the ADC sample sequence interrupt. // ROM_ADCIntEnable(ADC0_BASE, 3); ROM_IntEnable(INT_ADC0SS3); // // Configure the timer to trigger the sampling of the touch screen // every 2.5 milliseconds. // if((HWREG(TIMER5_BASE + TIMER_O_CTL) & TIMER_CTL_TAEN) == 0) { ROM_TimerConfigure(TIMER5_BASE, (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PWM | TIMER_CFG_B_PERIODIC)); } ROM_TimerPrescaleSet(TIMER5_BASE, TIMER_B, 255); ROM_TimerLoadSet(TIMER5_BASE, TIMER_B, ((ui32SysClock / 256) / 400) - 1); TimerControlTrigger(TIMER5_BASE, TIMER_B, true); // // Enable the timer. At this point, the touch screen state machine will // sample and run every 2.5 ms. // ROM_TimerEnable(TIMER5_BASE, TIMER_B); }
void ping0InitPeriph( void ) { // // Disable timer and set parameters // ROM_TimerDisable( TIMER_BASE_PING0, TIMER_PING0 ); ROM_TimerPrescaleSet( TIMER_BASE_PING0, TIMER_PING0, 0 ); ROM_TimerPrescaleMatchSet( TIMER_BASE_PING0, TIMER_PING0, 0 ); ROM_TimerControlStall( TIMER_BASE_PING0, TIMER_PING0, false ); IntPrioritySet( TIMER_INT_PING0, 0x40 ); // set to a middle priority group // // Register inerrupt // TimerIntRegister( TIMER_BASE_PING0, TIMER_PING0, &ping0Int ); }
//***************************************************************************** // // Configure the timer and its pins for measuring the length of // ultrasonic sensor echo pulse. // //***************************************************************************** void ConfigureDistancePulseTimer() { // // Enable Timer 4 // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER4); // // Configure timer 4A as a 16-bit event capture up-counter // ROM_TimerConfigure(TIMER4_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_TIME_UP); // // Set prescaler to 255. This essentially makes // the 16-bit timer a 24-bit timer. // ROM_TimerPrescaleSet(TIMER4_BASE, TIMER_A, 0xFF); // // The timer should capture events on both rising and falling edges // ROM_TimerControlEvent(TIMER4_BASE, TIMER_A, TIMER_EVENT_BOTH_EDGES); }