void Timer0IntHandler(void){ // Used to countdown from entered time // Clear the timer interrupt. ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT); // Check if time has been reached if(g_countdownTime == 0){ ROM_IntMasterDisable(); UARTprintf("Time's Up!\n\n"); ROM_IntMasterEnable(); ROM_TimerEnable(TIMER1_BASE, TIMER_A); ROM_TimerIntDisable(TIMER0_BASE, TIMER_A); return; } // Turn on LED ROM_GPIOPinWrite(GPIO_PORTF_BASE, LED_RED, LED_RED); ROM_TimerEnable(TIMER2_BASE, TIMER_A); // Update the interrupt status on the display. ROM_IntMasterDisable(); UARTprintf(" %i\n",g_countdownTime); ROM_IntMasterEnable(); // Decrement counter g_countdownTime--; // Turn off LED //ROM_GPIOPinWrite(GPIO_PORTF_BASE, LED_RED, 0); }
//***************************************************************************** // // The interrupt handler for the first timer interrupt. // //***************************************************************************** void Timer0IntHandler(void) { char cOne, cTwo; // // Clear the timer interrupt. // ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT); // // Toggle the flag for the first timer. // HWREGBITW(&g_ui32Flags, 0) ^= 1; // // Use the flags to Toggle the LED for this timer // GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, g_ui32Flags << 1); // // Update the interrupt status on the display. // ROM_IntMasterDisable(); cOne = HWREGBITW(&g_ui32Flags, 0) ? '1' : '0'; cTwo = HWREGBITW(&g_ui32Flags, 1) ? '1' : '0'; UARTprintf("\rT1: %c T2: %c", cOne, cTwo); ROM_IntMasterEnable(); }
//***************************************************************************** // // 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) { } }
//***************************************************************************** // // This function is called to start an acquisition running. It determines // which channels are to be logged, enables the ADC sequencers, and computes // the first RTC match value. This will start the acquisition running. // //***************************************************************************** void AcquireStart() { unsigned long ulIdx; ulIdx = ulSelectedMask; g_ulNumItems = 0; while(ulIdx) { if(ulIdx & 1) { g_ulNumItems++; } ulIdx >>= 1; } //USBStickOpenLogFile(0); ROM_ADCSequenceEnable(ADC0_BASE,SEQUENCER); //ROM_ADCSequenceDataGet(ADC0_BASE,SEQUENCER,&g_ulADCData[0]); ROM_ADCIntClear(ADC0_BASE,SEQUENCER); ROM_ADCIntEnable(ADC0_BASE,SEQUENCER); ROM_IntEnable(INT_ADC0SS2); ROM_TimerEnable(TIMER0_BASE, TIMER_A); //ROM_IntEnable(INT_TIMER1A); //ROM_TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT); //ROM_TimerEnable(TIMER1_BASE, TIMER_A); ROM_IntMasterEnable(); }
void board_init(void) { uint32_t clockfreq; ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); board_configure_led(); console_init(); board_spi_init(); board_systick_init(); board_watchdog_init(); timer_example_timer_init(); clockfreq = ROM_SysCtlClockGet(); delayloopspermicrosecond = (ROM_SysCtlClockGet() / (uint32_t) 1e6) / 3; delayloopspermillisecond = (ROM_SysCtlClockGet() / (uint32_t) 1e3) / 3; console_printtext("\n\n\n***** TM4C scheduler *****\n"); console_printtext("** System clock: %d MHz **\n", ROM_SysCtlClockGet() / (uint32_t) 1e6); console_printtext("* Type 'help' for commands *\n"); if (clockfreq < 3e6) console_printtext("WARNING: System clock is below 3 MHz, board timing might be inaccurate!\n"); else console_printtext("\n"); ROM_IntMasterEnable(); }
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); }
//***************************************************************************** // // Given a destination buffer and a tStat pointer, this function will produce a // formatted "request string" that can be used in the Exosite_Write function. // //***************************************************************************** void StatRequestFormat(tStat *psStat, char *pcRequestBuffer) { if((psStat->eValueType) == STRING) { // // Disable interrupts to avoid changes to the string during the copy // operation. // ROM_IntMasterDisable(); usprintf(pcRequestBuffer, "%s=%s", psStat->pcCloudAlias, StatStringVal(*psStat)); ROM_IntMasterEnable(); } else if((psStat->eValueType) == INT) { usprintf(pcRequestBuffer, "%s=%d", psStat->pcCloudAlias, StatIntVal(*psStat)); } else if((psStat->eValueType) == HEX) { usprintf(pcRequestBuffer, "%s=0x%x", psStat->pcCloudAlias, StatIntVal(*psStat)); } }
// * enc_2_int_init *********************************************************** // * setup interrupt from qei * // * Assumes system clock already configured * // **************************************************************************** void enc_2_int_init(void) { ROM_IntMasterEnable(); // enable NVIC interrupts ROM_QEIIntEnable(ENC_2_BASE, ENC_2_INT_FLAGS); // enable interrupt signal(s) ROM_IntEnable(ENC_2_INTVECT); // enable NVIC vector for our module // interrupt now active, remember to clear on interrupt }
//Initialize as a slave void TwoWire::begin(uint8_t address) { if(i2cModule == NOT_ACTIVE) { i2cModule = BOOST_PACK_WIRE; } ROM_SysCtlPeripheralEnable(g_uli2cPeriph[i2cModule]); ROM_GPIOPinConfigure(g_uli2cConfig[i2cModule][0]); ROM_GPIOPinConfigure(g_uli2cConfig[i2cModule][1]); ROM_GPIOPinTypeI2C(g_uli2cBase[i2cModule], g_uli2cSDAPins[i2cModule]); ROM_GPIOPinTypeI2CSCL(g_uli2cBase[i2cModule], g_uli2cSCLPins[i2cModule]); slaveAddress = address; //Enable slave interrupts ROM_IntEnable(g_uli2cInt[i2cModule]); I2CSlaveIntEnableEx(SLAVE_BASE, I2C_SLAVE_INT_DATA | I2C_SLAVE_INT_STOP); HWREG(SLAVE_BASE + I2C_O_SICR) = I2C_SICR_DATAIC | I2C_SICR_STARTIC | I2C_SICR_STOPIC; //Setup as a slave device ROM_I2CMasterDisable(MASTER_BASE); I2CSlaveEnable(SLAVE_BASE); I2CSlaveInit(SLAVE_BASE, address); ROM_IntMasterEnable(); }
/** * Initalize the RS232 port. * */ void uart0_init(unsigned long ubr) { ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // // Enable the GPIO port that is used for the on-board LED. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // // Enable the GPIO pins for the LED (PF2). // ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2); ROM_IntMasterEnable(); GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); ROM_UARTConfigSetExpClk(UART0_BASE, ROM_SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); ROM_IntEnable(INT_UART0); ROM_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT); }
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); }
// * svm_int_init ************************************************************* // * setup counter reload interrupt from pwm generator for svm * // * Assumes system clock already configured * // **************************************************************************** void svm_int_init(void) { ROM_IntMasterEnable(); // enable NVIC interrupts ROM_PWMIntEnable(SVM_PWM_BASE, SVM_PWM_INT_GEN); // enable interrupt assertion from our specific generator in module ROM_PWMGenIntTrigEnable(SVM_PWM_BASE, SVM_PWM_GEN, PWM_INT_CNT_LOAD); // enable counter load interrupt from our generator ROM_IntEnable(SVM_PWM_GEN_INTVECT); // enable NVIC vector for our generator // load interrupt for our generator is now active }
//***************************************************************************** // // PoC2Repeater // //***************************************************************************** int main(void) { // Set the clocking to run directly from the crystal at 120MHz. g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // Enable the peripherals ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART7); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION); // Enable the GPIO pins for the LEDs (PN0 and PN1). ROM_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_1); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_0); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_4); // ButtonsInit ROM_GPIODirModeSet(GPIO_PORTJ_BASE, ALL_BUTTONS, GPIO_DIR_MODE_IN); MAP_GPIOPadConfigSet(GPIO_PORTJ_BASE, ALL_BUTTONS, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // Enable processor interrupts. ROM_IntMasterEnable(); // Set GPIO PC4 and PC5 as UART pins. GPIOPinConfigure(GPIO_PC4_U7RX); GPIOPinConfigure(GPIO_PC5_U7TX); ROM_GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_4 | GPIO_PIN_5); // Configure the UART for 115,200, 8-N-1 operation. ROM_UARTConfigSetExpClk(UART7_BASE, g_ui32SysClock, 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); // Enable the UART interrupt. ROM_IntEnable(INT_UART7); ROM_UARTIntEnable(UART7_BASE, UART_INT_RX | UART_INT_RT); // Reset message info for(uint8_t i = 0; i < MSG; i++) message[i] = 0; // Loop forever echoing data through the UART. while(1) { } }
//***************************************************************************** // // Delay for 5 us. // //***************************************************************************** void delayFiveMicroseconds(uint32_t g_ui32SysClock) { // // Delay for 5 us. The value of the number provided to SysCtlDelay // is the number of loops (3 assembly instructions each) to iterate through. // Interrupts are disabled temporarily to ensure the pulse length is 5us. // ROM_IntMasterDisable(); ROM_SysCtlDelay(g_ui32SysClock / 3 / 200000); ROM_IntMasterEnable(); }
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); }
void setup() { //--------------------- GENERAL --------------------- // 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_FPUEnable(); 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); ROM_IntMasterEnable(); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_6); //--------------------- UART --------------------- ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // Configure the UART for 115,200, 8-N-1 operation. ROM_UARTConfigSetExpClk(UART0_BASE, ROM_SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); // Enable the UART interrupt. ROM_IntEnable(INT_UART0); ROM_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT); //--------------------- SSI --------------------- SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0); GPIOPinConfigure(GPIO_PA2_SSI0CLK); GPIOPinConfigure(GPIO_PA3_SSI0FSS); GPIOPinConfigure(GPIO_PA4_SSI0RX); GPIOPinConfigure(GPIO_PA5_SSI0TX); GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_5 | GPIO_PIN_4 | GPIO_PIN_3 | GPIO_PIN_2); SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0, SSI_MODE_MASTER, 10000, 8); SSIEnable(SSI0_BASE); }
//***************************************************************************** // // This example demonstrates how to send a string of data to the UART. // //***************************************************************************** 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); // // Enable the peripherals used by this example. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // // Enable processor interrupts. // ROM_IntMasterEnable(); // // Set GPIO A0 and A1 as UART pins. // GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // Configure the UART for 115,200, 8-N-1 operation. // ROM_UARTConfigSetExpClk(UART0_BASE, ROM_SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); // // Enable the UART interrupt. // ROM_IntEnable(INT_UART0); ROM_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT); // // Prompt for text to be entered. // UARTSend((unsigned char *)"\033[2JEnter text: ", 16); // // Loop forever echoing data through the UART. // while(1) { } }
//函数创建区 //----------------------------------------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(); }
// 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){} }
/**************************************************************** * This interrupt handler is set up by AcquireInit to check * for the events that begin a data logging. This is when the voltage * exceeds a changeable threshold or * the accelerometer z-axis changes g by more than 0.5. *****************************************************************/ void MonitorShockISR() { ROM_TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT); // // Toggle the flag for the second timer. // HWREGBITW(&g_ui32Flags, 1) ^= 1; // If ADC has not converted yet, exit ISR. if (!ADCIntStatus(ADC1_BASE, 3, false)) { return; } ADCIntClear(ADC1_BASE, 3); ADCSequenceDataGet(ADC1_BASE, 3, puiADC1Buffer); ADCProcessorTrigger(ADC1_BASE, 3); if (first_entry) { first_entry = false; prev1_value = ReadAccel(puiADC1Buffer[0]); } else { puiADC1Buffer[0] = ReadAccel(puiADC1Buffer[0]); // Shock monitor detects a change of more than 2.4g if (abs((int)puiADC1Buffer[0] - prev1_value) > 240) { // UARTprintf("Shock! : %d \r",puiADC1Buffer[0]); MonitorStop(); // Start LED ROM_TimerEnable(TIMER2_BASE, TIMER_A); // Start logging waveform. ROM_IntMasterDisable(); psuiConfig->isShocked = true; ROM_IntMasterEnable(); } else { ROM_IntMasterDisable(); psuiConfig->isShocked = false; ROM_IntMasterEnable(); } prev1_value = puiADC1Buffer[0]; } }
// 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 HardwareSerial::begin(unsigned long baud) { // // Initialize the UART. // ROM_SysCtlPeripheralEnable(g_ulUARTInt[uartModule]); //TODO:Add functionality for PinConfigure with variable uartModule ROM_GPIOPinConfigure(GPIO_PA0_U0RX); ROM_GPIOPinConfigure(GPIO_PA1_U0TX); ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // Only allow a single instance to be opened. // ASSERT(g_ulUARTBase[uartModule] == 0); // // Check to make sure the UART peripheral is present. // if(!ROM_SysCtlPeripheralPresent(g_ulUARTPeriph[uartModule])) { return; } ROM_SysCtlPeripheralEnable(g_ulUARTPeriph[uartModule]); ROM_UARTConfigSetExpClk(g_ulUARTBase[uartModule], ROM_SysCtlClockGet(), baud, (UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_ONE | UART_CONFIG_WLEN_8)); // // Set the UART to interrupt whenever the TX FIFO is almost empty or // when any character is received. // ROM_UARTFIFOLevelSet(g_ulUARTBase[uartModule], UART_FIFO_TX1_8, UART_FIFO_RX1_8); flushAll(); ROM_UARTIntDisable(g_ulUARTBase[uartModule], 0xFFFFFFFF); ROM_UARTIntEnable(g_ulUARTBase[uartModule], UART_INT_RX | UART_INT_RT); ROM_IntMasterEnable(); ROM_IntEnable(g_ulUARTInt[uartModule]); // // Enable the UART operation. // ROM_UARTEnable(g_ulUARTBase[uartModule]); }
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 HardwareSerial::end() { unsigned long ulInt = ROM_IntMasterDisable(); flushAll(); // // If interrupts were enabled when we turned them off, turn them // back on again. // if(!ulInt) { ROM_IntMasterEnable(); } ROM_IntDisable(g_ulUARTInt[uartModule]); ROM_UARTIntDisable(UART_BASE, UART_INT_RX | UART_INT_RT); }
//***************************************************************************** // This example demonstrates how to use serial command parser //***************************************************************************** int main(void) { // 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_FPUEnable(); 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); // Enable the GPIO port that is used for the on-board LED. ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // Enable the GPIO pins for the LED (PF2). ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2); // Enable the peripherals used by this example. ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // configure UART initUART(); // Enable processor interrupts. ROM_IntMasterEnable(); // Prompt for text to be entered. UARTSend((uint8_t *)"\033[2JEnter text: ", 16); // Loop forever echoing data through the UART. while(1) { //if(RingBufUsed(&g_tBuffRx) > 4) //{ //for(int i=4; i>0; i--) //{ //ROM_UARTCharPutNonBlocking(UART0_BASE,RingBufReadOne(&g_tBuffRx)); //} //} UARTParse(); } }
//***************************************************************************** // // The interrupt handler for the first timer interrupt. // //***************************************************************************** void Timer0IntHandler(void) { // // Clear the timer interrupt. // ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT); // // Toggle the flag for the first timer. // HWREGBITW(&g_ulFlags, 0) ^= 1; // // Update the interrupt status on the display. // ROM_IntMasterDisable(); UARTprintf("\rT1: %d T2: %d", HWREGBITW(&g_ulFlags, 0) ? 1 : 0, HWREGBITW(&g_ulFlags, 1) ? 1 : 0); ROM_IntMasterEnable(); }
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); }
void Timer1IntHandler(void){ // Clear the timer interrupt. ROM_TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT); // Toggle the flag for the second timer. // From current understanding, XOR on the second bit of &g_ui32Flags HWREGBITW(&g_ui32Flags, 2) ^= 1; // Use the flags to Toggle the LED for this timer ROM_GPIOPinWrite(GPIO_PORTF_BASE, LED_BLUE, g_ui32Flags); // Update the interrupt status on the display. ROM_IntMasterDisable(); if (HWREGBITW(&g_ui32Flags, 2)){ UARTprintf("BLUE LED ON\n"); } else{ UARTprintf("BLUE LED OFF\n"); } ROM_IntMasterEnable(); }
//***************************************************************************** // // The interrupt handler for the first timer interrupt. // //***************************************************************************** void Timer0IntHandler(void) { // // Clear the timer interrupt. // ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT); // // Toggle the flag for the first timer. // HWREGBITW(&g_ulFlags, 0) ^= 1; // // Update the interrupt status on the display. // ROM_IntMasterDisable(); GrStringDraw(&g_sContext, (HWREGBITW(&g_ulFlags, 0) ? "1" : "0"), -1, 68, 26, 1); ROM_IntMasterEnable(); }