//***************************************************************************** // // This example application demonstrates the use of the timers to generate // periodic interrupts. // //***************************************************************************** int main(void) { // // 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[2JTimers example\n"); UARTprintf("T1: 0 T2: 0"); // // Enable the peripherals used by this example. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); // // Enable processor interrupts. // ROM_IntMasterEnable(); // // Configure the two 32-bit periodic timers. // ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); ROM_TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC); ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, ROM_SysCtlClockGet()); ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, ROM_SysCtlClockGet() / 2); // // Setup the interrupts for the timer timeouts. // ROM_IntEnable(INT_TIMER0A); ROM_IntEnable(INT_TIMER1A); ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT); // // Enable the timers. // ROM_TimerEnable(TIMER0_BASE, TIMER_A); ROM_TimerEnable(TIMER1_BASE, TIMER_A); // // Loop forever while the timers run. // while(1) { } }
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); } }
// Main ---------------------------------------------------------------------------------------------- int main(void){ // Enable lazy stacking ROM_FPULazyStackingEnable(); // 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. ConfigureUART(); UARTprintf("Timers example\n"); // Enable LEDs ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, LED_RED|LED_BLUE|LED_GREEN); // Enable the peripherals used by this example. ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2); // Enable processor interrupts. ROM_IntMasterEnable(); // Configure the two 32-bit periodic timers. ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); ROM_TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC); ROM_TimerConfigure(TIMER2_BASE, TIMER_CFG_PERIODIC); ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, ROM_SysCtlClockGet()); ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, ROM_SysCtlClockGet()*2); // Blue should blink 2 times as much as red ROM_TimerLoadSet(TIMER2_BASE, TIMER_A, ROM_SysCtlClockGet()*3); // Green should blink 3 times as much as red // Setup the interrupts for the timer timeouts. ROM_IntEnable(INT_TIMER0A); ROM_IntEnable(INT_TIMER1A); ROM_IntEnable(INT_TIMER2A); ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerIntEnable(TIMER2_BASE, TIMER_TIMA_TIMEOUT); // Enable the timers. ROM_TimerEnable(TIMER0_BASE, TIMER_A); ROM_TimerEnable(TIMER1_BASE, TIMER_A); ROM_TimerEnable(TIMER2_BASE, TIMER_A); // Loop forever while the timers run. while(1){} }
void BPMTimerSetUp() { ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); // timer 0 SysCtlDelay(3); // // Enable processor interrupts. // //IntPrioritySet(INT_TIMER0A_TM4C123, 2); // // Configure the two 32-bit periodic timers. // ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, ROM_SysCtlClockGet()/500); //ROM_SysCtlClockGet()/100000 //ROM_SysCtlClockGet()/500 // Setup the interrupts for the timer timeouts. ROM_IntEnable(INT_TIMER0A); ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); // // Enable the timers. // ROM_TimerEnable(TIMER0_BASE, TIMER_A); }
void Timer1A_Interrupt_Init(void){ ROM_TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT); ROM_IntEnable(INT_TIMER1A); }
//***************************************************************************** // // Initialize the IO used in this demo // //***************************************************************************** void io_init(void) { // // Configure Port F0 for as an output for the status LED. // ROM_GPIOPinTypeGPIOOutput(LED_PORT_BASE, LED_PIN); // // Initialize LED to OFF (0) // ROM_GPIOPinWrite(LED_PORT_BASE, LED_PIN, 0); // // Enable the peripherals used by this example. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2); // // Configure the timer used to pace the animation. // ROM_TimerConfigure(TIMER2_BASE, TIMER_CFG_PERIODIC); // // Setup the interrupts for the timer timeouts. // ROM_IntEnable(INT_TIMER2A); ROM_TimerIntEnable(TIMER2_BASE, TIMER_TIMA_TIMEOUT); // // Set the timer for the current animation speed. This enables the // timer as a side effect. // io_set_timer(g_ulAnimSpeed); }
void setup() { ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); 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_FPULazyStackingEnable(); ROM_FPUEnable(); uart_setup(); sd_init(); dac_setup(); keycontrol_setup(); initConfig(); tick_setup(); soundoutcontrol_setup(); setupADC(); setupUSBStore(); initSampleBlocks(); ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); ROM_IntMasterEnable(); DEBUG_PRINT("Setup complete\n", NULL); }
// Main ---------------------------------------------------------------------------------------------- int main(void){ // Enable lazy stacking ROM_FPULazyStackingEnable(); // Set the clocking to run directly from the crystal. ROM_SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); // Initialize the UART and write status. ConfigureUART(); UARTprintf("--Countdown Example--\n"); // Initialize LEDs ConfigureLEDs(); // Enable the peripherals used by this example. ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2); // Enable processor interrupts. ROM_IntMasterEnable(); // Configure the two 32-bit periodic timers. ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); ROM_TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC); ROM_TimerConfigure(TIMER2_BASE, TIMER_CFG_ONE_SHOT); ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, ROM_SysCtlClockGet()); ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, ROM_SysCtlClockGet()/20); ROM_TimerLoadSet(TIMER2_BASE, TIMER_A, ROM_SysCtlClockGet()/10); // Setup the interrupts for the timer timeouts. ROM_IntEnable(INT_TIMER0A); ROM_IntEnable(INT_TIMER1A); ROM_IntEnable(INT_TIMER2A); ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerIntEnable(TIMER2_BASE, TIMER_TIMA_TIMEOUT); // Enable the timers. ROM_TimerEnable(TIMER0_BASE, TIMER_A); UARTprintf("Time Left: \n"); // Loop forever while the timers run. while(1){} }
void timerInit() { #if F_CPU >= 80000000 ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ| SYSCTL_OSC_MAIN); #elif F_CPU >= 50000000 ROM_SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ| SYSCTL_OSC_MAIN); #elif F_CPU >= 40000000 ROM_SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ| SYSCTL_OSC_MAIN); #elif F_CPU >= 25000000 ROM_SysCtlClockSet(SYSCTL_SYSDIV_8|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ| SYSCTL_OSC_MAIN); #elif F_CPU >= 16200000 ROM_SysCtlClockSet(SYSCTL_SYSDIV_1|SYSCTL_USE_OSC|SYSCTL_XTAL_16MHZ| SYSCTL_OSC_MAIN); //NOT PLL #elif F_CPU >= 16100000 ROM_SysCtlClockSet(SYSCTL_SYSDIV_1|SYSCTL_USE_OSC|SYSCTL_OSC_INT| SYSCTL_OSC_MAIN); //NOT PLL, INT OSC #elif F_CPU >= 16000000 ROM_SysCtlClockSet(SYSCTL_SYSDIV_12_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ| SYSCTL_OSC_MAIN); #elif F_CPU >= 10000000 ROM_SysCtlClockSet(SYSCTL_SYSDIV_20|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ| SYSCTL_OSC_MAIN); #elif F_CPU >= 8000000 ROM_SysCtlClockSet(SYSCTL_SYSDIV_25|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ| SYSCTL_OSC_MAIN); #else ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ| SYSCTL_OSC_MAIN); #endif // // SysTick is used for delay() and delayMicroseconds() // // ROM_SysTickPeriodSet(0x00FFFFFF); ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / TICKS_PER_SECOND); ROM_SysTickEnable(); // //Initialize Timer5 to be used as time-tracker since beginning of time // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER5); //not tied to launchpad pin ROM_TimerConfigure(TIMER5_BASE, TIMER_CFG_PERIODIC_UP); ROM_TimerLoadSet(TIMER5_BASE, TIMER_A, ROM_SysCtlClockGet()/1000); ROM_IntEnable(INT_TIMER5A); ROM_TimerIntEnable(TIMER5_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerEnable(TIMER5_BASE, TIMER_A); ROM_IntMasterEnable(); }
// Start the timers and interrupt frequency void servoStart(void) { ROM_SysCtlPeripheralEnable(SERVO_TIMER_PERIPH); ROM_IntMasterEnable(); ROM_TimerConfigure(SERVO_TIMER, TIMER_CFG_PERIODIC); ROM_TimerLoadSet(SERVO_TIMER, SERVO_TIMER_A, (ROM_SysCtlClockGet() / 1000000) * SERVO_TIMER_RESOLUTION); ROM_IntEnable(SERVO_TIMER_INTERRUPT); ROM_TimerIntEnable(SERVO_TIMER, SERVO_TIMER_TRIGGER); ROM_TimerEnable(SERVO_TIMER, SERVO_TIMER_A); }
void delay(unsigned long nTime) { ROM_TimerLoadSet(WTIMER5_BASE, TIMER_A, nTime * 10); ROM_TimerIntEnable(WTIMER5_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerEnable(WTIMER5_BASE, TIMER_A); ROM_SysCtlSleep(); ROM_TimerIntDisable(WTIMER5_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerDisable(WTIMER5_BASE, TIMER_A); }
//***************************************************************************** // //! Initializes the sound driver. //! //! \param ui32SysClock is the frequency of the system clock. //! //! This function initializes the sound driver, preparing it to output sound //! data to the speaker. //! //! The system clock should be as high as possible; lower clock rates reduces //! the quality of the produced sound. For the best quality sound, the system //! should be clocked at 120 MHz. //! //! \note In order for the sound driver to function properly, the sound driver //! interrupt handler (SoundIntHandler()) must be installed into the vector //! table for the timer 5 subtimer A interrupt. //! //! \return None. // //***************************************************************************** void SoundInit(uint32_t ui32SysClock) { // // Enable the peripherals used by the sound driver. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER5); // // Compute the PWM period based on the system clock. // g_sSoundState.ui32Period = ui32SysClock / 64000; // // Set the default volume. // g_sSoundState.i32Volume = 255; // // Configure the timer to run in PWM mode. // if((HWREG(TIMER5_BASE + TIMER_O_CTL) & TIMER_CTL_TBEN) == 0) { ROM_TimerConfigure(TIMER5_BASE, (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PWM | TIMER_CFG_B_PERIODIC)); } ROM_TimerLoadSet(TIMER5_BASE, TIMER_A, g_sSoundState.ui32Period - 1); ROM_TimerMatchSet(TIMER5_BASE, TIMER_A, g_sSoundState.ui32Period); ROM_TimerControlLevel(TIMER5_BASE, TIMER_A, true); // // Update the timer values on timeouts and not immediately. // TimerUpdateMode(TIMER5_BASE, TIMER_A, TIMER_UP_LOAD_TIMEOUT | TIMER_UP_MATCH_TIMEOUT); // // Configure the timer to generate an interrupt at every time-out event. // ROM_TimerIntEnable(TIMER5_BASE, TIMER_CAPA_EVENT); // // Enable the timer. At this point, the timer generates an interrupt // every 15.625 us. // ROM_TimerEnable(TIMER5_BASE, TIMER_A); ROM_IntEnable(INT_TIMER5A); // // Clear the sound flags. // g_sSoundState.ui32Flags = 0; }
void initializeTimer(void) { timerSeconds = 0; ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); // invoke timer once a second ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, ROM_SysCtlClockGet()); ROM_IntEnable(INT_TIMER0A); ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerEnable(TIMER0_BASE, TIMER_A); }
ServoClass::ServoClass() { ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ| SYSCTL_OSC_MAIN); // Initialize variables of the class g_ulPeriod = 0; for(int il_iter = 0; il_iter < SERVOS_PER_TIMER; il_iter++) { g_ulServoPins[il_iter] = INVALID_SERVO_PIN; g_ulServoPulse[il_iter] = DEFAULT_SERVO_PULSE_WIDTH; } g_iServoNo = 0; g_ulPulseWidth = 0; g_ulTicksPerMicrosecond = 0; setRefresh(); // for(int il_iter = 0; il_iter < SERVOS_PER_TIMER; il_iter++) // { // if (g_ulServoPins[il_iter] != INVALID_SERVO_PIN) // { // pinMode(g_ulServoPins[il_iter], OUTPUT); // digitalWrite(g_ulServoPins[il_iter], LOW); // } // } // Enable TIMER ROM_SysCtlPeripheralEnable(SERVO_TIMER_PERIPH); // Enable processor interrupts. ROM_IntMasterEnable(); // Configure the TIMER ROM_TimerConfigure(SERVO_TIMER, SERVO_TIME_CFG); // Calculate the number of timer counts/microsecond g_ulTicksPerMicrosecond = ROM_SysCtlClockGet() / 1000000; g_ulPeriod = g_ulTicksPerMicrosecond * REFRESH_INTERVAL; // 20ms = Standard Servo refresh delay // Initially load the timer with 20ms interval time ROM_TimerLoadSet(SERVO_TIMER, SERVO_TIMER_A, g_ulPeriod); // Setup the interrupt for the TIMER1A timeout. ROM_IntEnable(SERVO_TIMER_INTERRUPT); ROM_TimerIntEnable(SERVO_TIMER, SERVO_TIMER_TRIGGER); // Enable the timer. ROM_TimerEnable(SERVO_TIMER, SERVO_TIMER_A); }
//***************************************************************************** // //! Initializes the Timer and GPIO functionality associated with the RGB LED //! //! \param ui32Enable enables RGB immediately if set. //! //! This function must be called during application initialization to //! configure the GPIO pins to which the LEDs are attached. It enables //! the port used by the LEDs and configures each color's Timer. It optionally //! enables the RGB LED by configuring the GPIO pins and starting the timers. //! //! \return None. // //***************************************************************************** void RGBInit(uint32_t ui32Enable) { // // Enable the GPIO Port and Timer for each LED // ROM_SysCtlPeripheralEnable(RED_GPIO_PERIPH); ROM_SysCtlPeripheralEnable(RED_TIMER_PERIPH); ROM_SysCtlPeripheralEnable(GREEN_GPIO_PERIPH); ROM_SysCtlPeripheralEnable(GREEN_TIMER_PERIPH); ROM_SysCtlPeripheralEnable(BLUE_GPIO_PERIPH); ROM_SysCtlPeripheralEnable(BLUE_TIMER_PERIPH); // // Configure each timer for output mode // HWREG(GREEN_TIMER_BASE + TIMER_O_CFG) = 0x04; HWREG(GREEN_TIMER_BASE + TIMER_O_TAMR) = 0x0A; HWREG(GREEN_TIMER_BASE + TIMER_O_TAILR) = 0xFFFF; HWREG(BLUE_TIMER_BASE + TIMER_O_CFG) = 0x04; HWREG(BLUE_TIMER_BASE + TIMER_O_TBMR) = 0x0A; HWREG(BLUE_TIMER_BASE + TIMER_O_TBILR) = 0xFFFF; HWREG(RED_TIMER_BASE + TIMER_O_CFG) = 0x04; HWREG(RED_TIMER_BASE + TIMER_O_TBMR) = 0x0A; HWREG(RED_TIMER_BASE + TIMER_O_TBILR) = 0xFFFF; // // Invert the output signals. // HWREG(RED_TIMER_BASE + TIMER_O_CTL) |= 0x4000; HWREG(GREEN_TIMER_BASE + TIMER_O_CTL) |= 0x40; HWREG(BLUE_TIMER_BASE + TIMER_O_CTL) |= 0x4000; if(ui32Enable) { RGBEnable(); } // // Setup the blink functionality // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER5); ROM_TimerConfigure(WTIMER5_BASE, TIMER_CFG_B_PERIODIC | TIMER_CFG_SPLIT_PAIR); ROM_TimerLoadSet64(WTIMER5_BASE, 0xFFFFFFFFFFFFFFFF); ROM_IntEnable(INT_WTIMER5B); ROM_TimerIntEnable(WTIMER5_BASE, TIMER_TIMB_TIMEOUT); }
//函数创建区 //----------------------------------------Start------------------------------------------- void Init_Timer() { ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, ROM_SysCtlClockGet()/100);//10ms周期中断,由100决定 如果为1为1s定时 GPIOIntRegister(INT_TIMER0A, Timer0AIntHandler); ROM_IntEnable(INT_TIMER0A); ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerEnable(TIMER0_BASE, TIMER_A); ROM_IntMasterEnable(); }
/*---------------------------------------------------------------------------*/ void clock_init(void) { SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); TimerLoadSet(TIMER0_BASE, TIMER_A, ROM_SysCtlClockGet()/1000); TimerControlStall(TIMER0_BASE,TIMER_A,true); TimerEnable(TIMER0_BASE, TIMER_A); ROM_IntEnable(INT_TIMER0A); ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerEnable(TIMER0_BASE, TIMER_A); count = 0; }
void delay(uint32_t nTime) { ROM_TimerLoadSet(WTIMER5_BASE, TIMER_A, nTime * 10); ROM_TimerIntEnable(WTIMER5_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerEnable(WTIMER5_BASE, TIMER_A); ROM_SysCtlSleep(); // Make sure the timer finished, go back to sleep if it didn't // (Another interrupt may have woken up the system) while (ROM_TimerValueGet(WTIMER5_BASE, TIMER_A) != nTime * 10) ROM_SysCtlSleep(); ROM_TimerIntDisable(WTIMER5_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerDisable(WTIMER5_BASE, TIMER_A); }
void initTimer0(int interval, gyro *G){ // // 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(); volatile int tick = 0; tick = (ROM_SysCtlClockGet() / 1000) * interval; // // Enable the GPIO port that is used for the on-board LED. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // // Enable the GPIO pins for the LED (PF1 & PF2). // ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2 | GPIO_PIN_1); // // Enable the peripherals used by this example. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); // // Configure the two 32-bit periodic timers. // ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); /// imposta il time_out ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, tick); G->tick = (float) interval / 1000; // // Setup the interrupts for the timer timeouts. // ROM_IntEnable(INT_TIMER0A); //ROM_IntEnable(INT_TIMER1A); ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); //ROM_TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT); // // Enable the timers. // ROM_TimerEnable(TIMER0_BASE, TIMER_A); }
/** Configures timer. @see timers example in EK-LM4F120XL StellarisWare package @note On the LM4F120XL, there are 16/32 bit timers or "wide" timers featuring 32/64bit. We use a standard timer. @param seconds period of the timer. Maximum is 0xFFFFFFFF / SysCtlClockGet(); or about 171 sec if using 25MHz main clock @return 0 if success; -1 if illegal parameter */ int16_t initTimer(uint8_t seconds) { #define TIMER_MAX_SECONDS (0xFFFFFFFF / SysCtlClockGet()) if ((seconds > TIMER_MAX_SECONDS) || (seconds == 0)) return -1; ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2); ROM_TimerConfigure(TIMER2_BASE, TIMER_CFG_PERIODIC); // Full width (32 bit for Timer 2) periodic timer ROM_TimerLoadSet(TIMER2_BASE, TIMER_A, (ROM_SysCtlClockGet() * seconds)); // for once per second ROM_IntEnable(INT_TIMER2A); ROM_TimerIntEnable(TIMER2_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerEnable(TIMER2_BASE, TIMER_A); return 0; }
void init_Timer1B(void) { ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); ROM_TimerConfigure(TIMER1_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_PERIODIC); ROM_TimerLoadSet(TIMER1_BASE, TIMER_B, ROM_SysCtlClockGet() / 2000); ROM_IntMasterEnable(); ROM_TimerIntEnable(TIMER1_BASE, TIMER_TIMB_TIMEOUT); ROM_IntEnable(INT_TIMER1B); timeCounter = 0; ROM_TimerEnable(TIMER1_BASE, TIMER_B); }
void delay(unsigned int milli) { delay_count = milli; if (delay_count > 50000) { milli = 50000; delay_count -= milli; } else { milli = delay_count; delay_count = 0; } // 80000000 ticks/s = 80000 ticks/ms7 ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, milli*80000); delay_stat = DELAY_RUNNING; ROM_TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerEnable(TIMER1_BASE, TIMER_A); }
void OneMsTaskTimer::start(uint32_t timer_index) { uint32_t load = (F_CPU / 1000); //// !!!! count = 0; overflowing = 0; // Base address for first timer g_ulBase = getTimerBase(timerToOffset(timer_index)); timerAB = TIMER_A << timerToAB(timer_index); //Setup interrupts for duration, interrupting at 1kHz ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0+ timer_index); ROM_IntMasterEnable(); ROM_TimerConfigure(g_ulBase, TIMER_CFG_PERIODIC); ROM_TimerLoadSet(g_ulBase, TIMER_A, F_CPU/1000); // Setup the interrupts for the timer timeouts. TimerIntRegister(g_ulBase, TIMER_A, OneMsTaskTimer_int); ROM_IntEnable(INT_TIMER0A+timer_index); ROM_TimerIntEnable(g_ulBase, TIMER_TIMA_TIMEOUT); ROM_TimerEnable(g_ulBase, TIMER_A); }
//------------------------------------ Timer init --------------------------------- void ir_timer_init(void) { // The Timer0 peripheral must be enabled for use. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); // // The Timer0 peripheral must be enabled for use. // When configured for a pair of half-width timers, each timer is separately configured. // ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_ONE_SHOT); // Calculate the number of timer counts/microsecond ulCountsPerMicrosecond = ROM_SysCtlClockGet() / 10000; // 0.10ms = timeout delay ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, ulCountsPerMicrosecond); ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT); TimerIntRegister(TIMER0_BASE, TIMER_A, Timer0AIntHandler ); // // Configure the Timer0 interrupt for timer timeout. // ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); // // Enable the Timer0 interrupt on the processor (NVIC). // ROM_IntEnable(INT_TIMER0A); gulTicks = 0; // // Enable Timer0A. // ROM_TimerEnable(TIMER0_BASE, TIMER_A); }
void motor_init() { unsigned long timer; //configure timer0 for one shot intervals and assign interrupt routine ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); ROM_TimerConfigure(TIMER0_BASE,TIMER_CFG_ONE_SHOT); ROM_TimerControlStall(TIMER0_BASE, TIMER_A, true); TimerIntRegister(TIMER0_BASE, TIMER_A, Timer0A_ISR); ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); //setup RGB led outputs. ROM_SysCtlPeripheralEnable(LED_PERIPH); ROM_GPIOPinTypeGPIOOutput(LED_PORT, LED_R | LED_G | LED_B ); //enable peripherals used for motor ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); //set motor pins to outputs ROM_GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, MOTOR_PORTA_PINS ); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, MOTOR_PORTB_PINS ); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, MOTOR_PORTD_PINS ); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, MOTOR_PORTE_PINS ); //make sure motors are disabled and step pins are low motor_disable(); motor_unstep(); //start the timer. the ISR will run at the minimum rate //interval until there is a block to execute. timer=calculate_timer(MIN_STEP_RATE); ROM_TimerLoadSet(TIMER0_BASE,TIMER_A, timer); ROM_TimerEnable(TIMER0_BASE,TIMER_A); }
void throttleHome() { uint8_t msg[3]; int i; if (!LIMIT_SW_THROTTLE_DOWN_ON) { ROM_TimerIntDisable(WTIMER2_BASE, TIMER_CAPB_EVENT);//disable manual mode msg[0] = START_BYTE; msg[1] = HOME_CMD; msg[2] = 0; for (i=0;i<3;i++) ROM_UARTCharPut(UART_THROTTLE,msg[i]); ROM_TimerLoadSet(TIMER2_BASE, TIMER_A,ROM_SysCtlClockGet()*5); ROM_TimerEnable(TIMER2_BASE, TIMER_A); while ((!LIMIT_SW_THROTTLE_DOWN_ON) && (!flagTimeout)); ROM_TimerIntEnable(WTIMER2_BASE, TIMER_CAPB_EVENT); } }
void tone(uint8_t _pin, unsigned int frequency, unsigned long duration) { uint8_t port = digitalPinToPort(_pin); if (port == NOT_A_PORT) return; if (tone_state == 0 || _pin == current_pin) { //Setup PWM current_pin = _pin; tone_timer = digitalPinToTimer(_pin); uint32_t timerBase = getTimerBase(timerToOffset(tone_timer)); tone_state = 1; g_duration = duration; PWMWrite(_pin, 256, 128, frequency); //Setup interrupts for duration, interrupting at 1kHz ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER4); ROM_IntMasterEnable(); ROM_TimerConfigure(TIMER4_BASE, TIMER_CFG_PERIODIC); ROM_TimerLoadSet(TIMER4_BASE, TIMER_A, ROM_SysCtlClockGet()/1000); ROM_IntEnable(INT_TIMER4A); ROM_TimerIntEnable(TIMER4_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerEnable(TIMER4_BASE, TIMER_A); } }
int main() { ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, LED_BLUE); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); ROM_IntMasterEnable(); ROM_TimerDisable(TIMER0_BASE, TIMER_A); ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, ROM_SysCtlClockGet()); ROM_IntEnable(INT_TIMER0A); ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); TimerIntRegister(TIMER0_BASE, TIMER_A, Timer0AIntHandler); ROM_GPIOPinWrite(GPIO_PORTF_BASE, LED_BLUE, led_value); ROM_TimerEnable(TIMER0_BASE, TIMER_A); while(1) {} }
char run() { unsigned long period = (SysCtlClockGet() / multi2hz(interval)) / 2; stop(); led(1,0,0); clear_buf(); if (mode == MODE_INTERVAL) { ROM_IntEnable(INT_TIMER0A); ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, period - 1); ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); if (trigger == TRIGGER_IMMEDIATE) { ROM_TimerEnable(TIMER0_BASE, TIMER_A); } else if (trigger == TRIGGER_PIN_RISING) { ROM_GPIOIntTypeSet(GPIO_PORTB_BASE, trigger_pins, GPIO_RISING_EDGE); ROM_GPIOPinIntClear(GPIO_PORTB_BASE, 0xff); ROM_GPIOPinIntEnable(GPIO_PORTB_BASE, trigger_pins); ROM_IntEnable(INT_GPIOB); } else if (trigger == TRIGGER_PIN_FALLING) { ROM_GPIOIntTypeSet(GPIO_PORTB_BASE, trigger_pins, GPIO_FALLING_EDGE); ROM_GPIOPinIntClear(GPIO_PORTB_BASE, 0xff); ROM_GPIOPinIntEnable(GPIO_PORTB_BASE, trigger_pins); ROM_IntEnable(INT_GPIOB); } else if (trigger == TRIGGER_PIN_BOTH) { ROM_GPIOIntTypeSet(GPIO_PORTB_BASE, 1, GPIO_BOTH_EDGES); ROM_GPIOPinIntClear(GPIO_PORTB_BASE, 0xff); ROM_GPIOPinIntEnable(GPIO_PORTB_BASE, trigger_pins); ROM_IntEnable(INT_GPIOB); } } else if (mode == MODE_EVENT) { if (trigger == TRIGGER_PIN_FALLING) { ROM_GPIOIntTypeSet(GPIO_PORTB_BASE, trigger_pins, GPIO_FALLING_EDGE); ROM_GPIOPinIntClear(GPIO_PORTB_BASE, 0xff); ROM_GPIOPinIntEnable(GPIO_PORTB_BASE, trigger_pins); ROM_IntEnable(INT_GPIOB); } else if (trigger == TRIGGER_PIN_RISING) { ROM_GPIOIntTypeSet(GPIO_PORTB_BASE, trigger_pins, GPIO_RISING_EDGE); ROM_GPIOPinIntClear(GPIO_PORTB_BASE, 0xff); ROM_GPIOPinIntEnable(GPIO_PORTB_BASE, trigger_pins); ROM_IntEnable(INT_GPIOB); } else if (trigger == TRIGGER_PIN_BOTH) { ROM_GPIOIntTypeSet(GPIO_PORTB_BASE, trigger_pins, GPIO_BOTH_EDGES); ROM_GPIOPinIntClear(GPIO_PORTB_BASE, 0xff); ROM_GPIOPinIntEnable(GPIO_PORTB_BASE, trigger_pins); ROM_IntEnable(INT_GPIOB); } HWREG(NVIC_ST_CURRENT) = 0; } ROM_IntMasterEnable(); sampling = SAMPLING_ON; return STATE_GET_COMMAND; }
//***************************************************************************** // // This example demonstrates how to send a string of data to the UART. // //***************************************************************************** int main(void) { // // Set the clocking to run at 80 MHz from the PLL. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Enable the peripherals used by this example. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); // // Compute the bit time for 115,200 baud. // g_ulBitTime = (ROM_SysCtlClockGet() / 115200) - 1; // // Configure the SoftUART for 8-N-1 operation. // SoftUARTInit(&g_sUART); SoftUARTRxGPIOSet(&g_sUART, GPIO_PORTA_BASE, GPIO_PIN_0); SoftUARTTxGPIOSet(&g_sUART, GPIO_PORTA_BASE, GPIO_PIN_1); SoftUARTRxBufferSet(&g_sUART, g_pusRxBuffer, sizeof(g_pusRxBuffer) / sizeof(g_pusRxBuffer[0])); SoftUARTTxBufferSet(&g_sUART, g_pucTxBuffer, sizeof(g_pucTxBuffer)); SoftUARTCallbackSet(&g_sUART, SoftUARTIntHandler); SoftUARTConfigSet(&g_sUART, (SOFTUART_CONFIG_WLEN_8 | SOFTUART_CONFIG_STOP_ONE | SOFTUART_CONFIG_PAR_NONE)); // // Configure the timer for the SoftUART transmitter. // ROM_TimerConfigure(TIMER0_BASE, (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_PERIODIC)); ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, g_ulBitTime); ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT | TIMER_TIMB_TIMEOUT); ROM_TimerEnable(TIMER0_BASE, TIMER_A); // // Set the priorities of the interrupts associated with the SoftUART. The // receiver is higher priority than the transmitter, and the receiver edge // interrupt is higher priority than the receiver timer interrupt. // ROM_IntPrioritySet(INT_GPIOA, 0x00); ROM_IntPrioritySet(INT_TIMER0B, 0x40); ROM_IntPrioritySet(INT_TIMER0A, 0x80); // // Enable the interrupts associated with the SoftUART. // ROM_IntEnable(INT_TIMER0A); ROM_IntEnable(INT_TIMER0B); ROM_IntEnable(INT_GPIOA); // // Prompt for text to be entered. // UARTSend((unsigned char *)"\033[2JEnter text: ", 16); // // Enable the SoftUART interrupt. // SoftUARTIntEnable(&g_sUART, SOFTUART_INT_RX | SOFTUART_INT_RT); // // Loop forever echoing data through the UART. // while(1) { // // Wait until there are characters available in the receive buffer. // while(g_ulFlag == 0) { } g_ulFlag = 0; // // Loop while there are characters in the receive buffer. // while(SoftUARTCharsAvail(&g_sUART)) { // // Read the next character from the UART and write it back to the // UART. // SoftUARTCharPutNonBlocking(&g_sUART, SoftUARTCharGetNonBlocking(&g_sUART)); } } }