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); }
//***************************************************************************** // // 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)); } }
//***************************************************************************** // // 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(); }
//***************************************************************************** // // 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(); }
/**************************************************************** * 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]; } }
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); }
char stop() { ROM_IntMasterDisable(); ROM_IntDisable(INT_TIMER0A); ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerIntDisable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerDisable(TIMER0_BASE, TIMER_A); ROM_GPIOPinIntClear(GPIO_PORTB_BASE, 0xff); ROM_GPIOPinIntDisable(GPIO_PORTB_BASE, 0xff); ROM_IntDisable(INT_GPIOB); ROM_IntPendClear(INT_TIMER0A); ROM_IntPendClear(INT_GPIOB); sampling = SAMPLING_OFF; tick = 0; led(0,1,0); return STATE_GET_COMMAND; }
/* * ======== callback ======== * Watchdog interrupt callback function. It toggles and LED, and if a button * has not been pressed, clears the watchdog interrupt flag. */ void vINMD_watchdog_callback(UArg handle) { ERROR_CODE eEC; eEC = eBSP_debugger_detect(); if(eEC == ER_OK) { System_printf("****!!!!SYS HALT!!!!****\r\n"); System_printf("Watchdog Bark!\r\n"); System_flush(); vDEBUG_ASSERT("Watchdog Bark!",0); } else { vDEBUG("Watchdog Bark!"); vDEBUG("****!!!!SYS RESET!!!!****\r\n"); ROM_IntMasterDisable(); ROM_SysCtlReset(); } }
//***************************************************************************** // // 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 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(); }
int gpio_init_int(gpio_t pin, gpio_mode_t mode, gpio_flank_t flank, gpio_cb_t cb, void *arg) { const uint8_t port_num = _port_num(pin); const uint32_t port_addr = _port_base[port_num]; const uint32_t icr_reg_addr = port_addr + GPIO_ICR_R_OFF; const uint8_t pin_num = _pin_num(pin); const uint8_t pin_bit = 1<<pin_num; const unsigned int int_num = _int_assign[port_num]; const uint32_t sysctl_port_base = _sysctl_port_base[port_num]; ROM_SysCtlPeripheralEnable(sysctl_port_base); gpio_config[port_num][pin_num].cb = cb; gpio_config[port_num][pin_num].arg = arg; DEBUG("init int pin:%d, int num %d, port addr %" PRIx32 "\n", pin_num, int_num, port_addr); ROM_GPIODirModeSet(port_addr, 1<<pin_num, GPIO_DIR_MODE_IN); ROM_GPIOPadConfigSet(port_addr, 1<<pin_num, GPIO_STRENGTH_2MA, TYPE(mode)); ROM_IntMasterDisable(); HWREG(icr_reg_addr) = pin_bit; ROM_GPIOIntTypeSet(port_addr, pin_bit, flank); HWREG(port_addr+GPIO_LOCK_R_OFF) = GPIO_LOCK_KEY; HWREG(port_addr+GPIO_CR_R_OFF) |= pin_bit; HWREG(port_addr+GPIO_DEN_R_OFF) |= pin_bit; HWREG(port_addr+GPIO_LOCK_R_OFF) = 0; gpio_irq_enable(pin); ROM_IntEnable(int_num); ROM_IntMasterEnable(); return 0; }
//***************************************************************************** // // Handles CDC driver notifications related to control and setup of the device. // // \param pvCBData is the client-supplied callback pointer for this channel. // \param ui32Event identifies the event we are being notified about. // \param ui32MsgValue is an event-specific value. // \param pvMsgData is an event-specific pointer. // // This function is called by the CDC driver to perform control-related // operations on behalf of the USB host. These functions include setting // and querying the serial communication parameters, setting handshake line // states and sending break conditions. // // \return The return value is event-specific. // //***************************************************************************** uint32_t ControlHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgValue, void *pvMsgData) { uint32_t ui32IntsOff; // // Which event are we being asked to process? // switch(ui32Event) { // // We are connected to a host and communication is now possible. // case USB_EVENT_CONNECTED: g_bUSBConfigured = true; // // Flush our buffers. // USBBufferFlush(&g_sTxBuffer); USBBufferFlush(&g_sRxBuffer); // // Tell the main loop to update the display. // ui32IntsOff = ROM_IntMasterDisable(); g_pcStatus = "Connected"; g_ui32Flags |= COMMAND_STATUS_UPDATE; if(!ui32IntsOff) { ROM_IntMasterEnable(); } break; // // The host has disconnected. // case USB_EVENT_DISCONNECTED: g_bUSBConfigured = false; ui32IntsOff = ROM_IntMasterDisable(); g_pcStatus = "Disconnected"; g_ui32Flags |= COMMAND_STATUS_UPDATE; if(!ui32IntsOff) { ROM_IntMasterEnable(); } break; // // Return the current serial communication parameters. // case USBD_CDC_EVENT_GET_LINE_CODING: GetLineCoding(pvMsgData); break; // // Set the current serial communication parameters. // case USBD_CDC_EVENT_SET_LINE_CODING: SetLineCoding(pvMsgData); break; // // Set the current serial communication parameters. // case USBD_CDC_EVENT_SET_CONTROL_LINE_STATE: SetControlLineState((uint16_t)ui32MsgValue); break; // // Send a break condition on the serial line. // case USBD_CDC_EVENT_SEND_BREAK: SendBreak(true); break; // // Clear the break condition on the serial line. // case USBD_CDC_EVENT_CLEAR_BREAK: SendBreak(false); break; // // Ignore SUSPEND and RESUME for now. // case USB_EVENT_SUSPEND: case USB_EVENT_RESUME: break; // // We don't expect to receive any other events. Ignore any that show // up in a release build or hang in a debug build. // default: #ifdef DEBUG while(1); #else break; #endif } return(0); }
//***************************************************************************** // // This is the main application entry function. // //***************************************************************************** int main(void) { uint32_t ui32TxCount; uint32_t ui32RxCount; tRectangle sRect; char pcBuffer[16]; uint32_t ui32Fullness; // // 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(); // // Set the clocking to run from the PLL at 50MHz // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Configure the required pins for USB operation. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG); ROM_GPIOPinConfigure(GPIO_PG4_USB0EPEN); ROM_GPIOPinTypeUSBDigital(GPIO_PORTG_BASE, GPIO_PIN_4); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL); ROM_GPIOPinTypeUSBAnalog(GPIO_PORTL_BASE, GPIO_PIN_6 | GPIO_PIN_7); ROM_GPIOPinTypeUSBAnalog(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // Erratum workaround for silicon revision A1. VBUS must have pull-down. // if(CLASS_IS_BLIZZARD && REVISION_IS_A1) { HWREG(GPIO_PORTB_BASE + GPIO_O_PDR) |= GPIO_PIN_1; } // // Not configured initially. // g_bUSBConfigured = false; // // Initialize the display driver. // CFAL96x64x16Init(); // // Initialize the graphics context. // GrContextInit(&g_sContext, &g_sCFAL96x64x16); // // Fill the top 15 rows of the screen with blue to create the banner. // sRect.i16XMin = 0; sRect.i16YMin = 0; sRect.i16XMax = GrContextDpyWidthGet(&g_sContext) - 1; sRect.i16YMax = 9; GrContextForegroundSet(&g_sContext, ClrDarkBlue); GrRectFill(&g_sContext, &sRect); // // Put a white box around the banner. // GrContextForegroundSet(&g_sContext, ClrWhite); GrRectDraw(&g_sContext, &sRect); // // Put the application name in the middle of the banner. // GrContextFontSet(&g_sContext, g_psFontFixed6x8); GrStringDrawCentered(&g_sContext, "usb-dev-serial", -1, GrContextDpyWidthGet(&g_sContext) / 2, 4, 0); // // Show the various static text elements on the color STN display. // GrStringDraw(&g_sContext, "Tx #",-1, 0, 12, false); GrStringDraw(&g_sContext, "Tx buf", -1, 0, 22, false); GrStringDraw(&g_sContext, "Rx #", -1, 0, 32, false); GrStringDraw(&g_sContext, "Rx buf", -1, 0, 42, false); DrawBufferMeter(&g_sContext, 40, 22); DrawBufferMeter(&g_sContext, 40, 42); // // Enable the UART that we will be redirecting. // ROM_SysCtlPeripheralEnable(USB_UART_PERIPH); // // Enable and configure the UART RX and TX pins // ROM_SysCtlPeripheralEnable(TX_GPIO_PERIPH); ROM_SysCtlPeripheralEnable(RX_GPIO_PERIPH); ROM_GPIOPinTypeUART(TX_GPIO_BASE, TX_GPIO_PIN); ROM_GPIOPinTypeUART(RX_GPIO_BASE, RX_GPIO_PIN); // // TODO: Add code to configure handshake GPIOs if required. // // // Set the default UART configuration. // ROM_UARTConfigSetExpClk(USB_UART_BASE, ROM_SysCtlClockGet(), DEFAULT_BIT_RATE, DEFAULT_UART_CONFIG); ROM_UARTFIFOLevelSet(USB_UART_BASE, UART_FIFO_TX4_8, UART_FIFO_RX4_8); // // Configure and enable UART interrupts. // ROM_UARTIntClear(USB_UART_BASE, ROM_UARTIntStatus(USB_UART_BASE, false)); ROM_UARTIntEnable(USB_UART_BASE, (UART_INT_OE | UART_INT_BE | UART_INT_PE | UART_INT_FE | UART_INT_RT | UART_INT_TX | UART_INT_RX)); // // Enable the system tick. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND); ROM_SysTickIntEnable(); ROM_SysTickEnable(); // // Tell the user what we are up to. // DisplayStatus(&g_sContext, " Configuring... "); // // Initialize the transmit and receive buffers. // USBBufferInit(&g_sTxBuffer); USBBufferInit(&g_sRxBuffer); // // Set the USB stack mode to Device mode with VBUS monitoring. // USBStackModeSet(0, eUSBModeDevice, 0); // // Pass our device information to the USB library and place the device // on the bus. // USBDCDCInit(0, &g_sCDCDevice); // // Wait for initial configuration to complete. // DisplayStatus(&g_sContext, "Waiting for host"); // // Clear our local byte counters. // ui32RxCount = 0; ui32TxCount = 0; // // Enable interrupts now that the application is ready to start. // ROM_IntEnable(USB_UART_INT); // // Main application loop. // while(1) { // // Have we been asked to update the status display? // if(g_ui32Flags & COMMAND_STATUS_UPDATE) { // // Clear the command flag // ROM_IntMasterDisable(); g_ui32Flags &= ~COMMAND_STATUS_UPDATE; ROM_IntMasterEnable(); DisplayStatus(&g_sContext, g_pcStatus); } // // Has there been any transmit traffic since we last checked? // if(ui32TxCount != g_ui32UARTTxCount) { // // Take a snapshot of the latest transmit count. // ui32TxCount = g_ui32UARTTxCount; // // Update the display of bytes transmitted by the UART. // usnprintf(pcBuffer, 16, "%d ", ui32TxCount); GrStringDraw(&g_sContext, pcBuffer, -1, 40, 12, true); // // Update the RX buffer fullness. Remember that the buffers are // named relative to the USB whereas the status display is from // the UART's perspective. The USB's receive buffer is the UART's // transmit buffer. // ui32Fullness = ((USBBufferDataAvailable(&g_sRxBuffer) * 100) / UART_BUFFER_SIZE); UpdateBufferMeter(&g_sContext, ui32Fullness, 40, 22); } // // Has there been any receive traffic since we last checked? // if(ui32RxCount != g_ui32UARTRxCount) { // // Take a snapshot of the latest receive count. // ui32RxCount = g_ui32UARTRxCount; // // Update the display of bytes received by the UART. // usnprintf(pcBuffer, 16, "%d ", ui32RxCount); GrStringDraw(&g_sContext, pcBuffer, -1, 40, 32, true); // // Update the TX buffer fullness. Remember that the buffers are // named relative to the USB whereas the status display is from // the UART's perspective. The USB's transmit buffer is the UART's // receive buffer. // ui32Fullness = ((USBBufferDataAvailable(&g_sTxBuffer) * 100) / UART_BUFFER_SIZE); UpdateBufferMeter(&g_sContext, ui32Fullness, 40, 42); } } }
//***************************************************************************** // // This is the main example program. It checks to see that the interrupts are // processed in the correct order when they have identical priorities, // increasing priorities, and decreasing priorities. This exercises interrupt // preemption and tail chaining. // //***************************************************************************** int main(void) { uint_fast8_t ui8Error; uint32_t ui32SysClock; // // Run from the PLL at 120 MHz. // ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // // Configure the device pins. // PinoutSet(); // // Initialize the display driver. // Kentec320x240x16_SSD2119Init(ui32SysClock); // // Initialize the graphics context. // GrContextInit(&g_sContext, &g_sKentec320x240x16_SSD2119); // // Draw the application frame. // FrameDraw(&g_sContext, "interrupts"); // // Put the status header text on the display. // GrContextFontSet(&g_sContext, g_psFontCm20); GrStringDrawCentered(&g_sContext, "Active: Pending: ", -1, GrContextDpyWidthGet(&g_sContext) / 2, 150, 0); // // Configure the B3, L1 and L0 to be outputs to indicate entry/exit of one // of the interrupt handlers. // GPIOPinTypeGPIOOutput(GPIO_A_BASE, GPIO_A_PIN); GPIOPinTypeGPIOOutput(GPIO_B_BASE, GPIO_B_PIN); GPIOPinTypeGPIOOutput(GPIO_C_BASE, GPIO_C_PIN); GPIOPinWrite(GPIO_A_BASE, GPIO_A_PIN, 0); GPIOPinWrite(GPIO_B_BASE, GPIO_B_PIN, 0); GPIOPinWrite(GPIO_C_BASE, GPIO_C_PIN, 0); // // Set up and enable the SysTick timer. It will be used as a reference // for delay loops in the interrupt handlers. The SysTick timer period // will be set up for 100 times per second. // ROM_SysTickPeriodSet(ui32SysClock / 100); ROM_SysTickEnable(); // // Reset the error indicator. // ui8Error = 0; // // Enable interrupts to the processor. // ROM_IntMasterEnable(); // // Enable the interrupts. // ROM_IntEnable(INT_GPIOA); ROM_IntEnable(INT_GPIOB); ROM_IntEnable(INT_GPIOC); // // Indicate that the equal interrupt priority test is beginning. // GrStringDrawCentered(&g_sContext, "Equal Priority", -1, GrContextDpyWidthGet(&g_sContext) / 2, 60, 1); // // Set the interrupt priorities so they are all equal. // ROM_IntPrioritySet(INT_GPIOA, 0x00); ROM_IntPrioritySet(INT_GPIOB, 0x00); ROM_IntPrioritySet(INT_GPIOC, 0x00); // // Reset the interrupt flags. // g_ui32GPIOa = 0; g_ui32GPIOb = 0; g_ui32GPIOc = 0; g_ui32Index = 1; // // Trigger the interrupt for GPIO C. // HWREG(NVIC_SW_TRIG) = INT_GPIOC - 16; // // Put the current interrupt state on the LCD. // DisplayIntStatus(); // // Verify that the interrupts were processed in the correct order. // if((g_ui32GPIOa != 3) || (g_ui32GPIOb != 2) || (g_ui32GPIOc != 1)) { ui8Error |= 1; } // // Wait two seconds. // Delay(2); // // Indicate that the decreasing interrupt priority test is beginning. // GrStringDrawCentered(&g_sContext, " Decreasing Priority ", -1, GrContextDpyWidthGet(&g_sContext) / 2, 60, 1); // // Set the interrupt priorities so that they are decreasing (i.e. C > B > // A). // ROM_IntPrioritySet(INT_GPIOA, 0x80); ROM_IntPrioritySet(INT_GPIOB, 0x40); ROM_IntPrioritySet(INT_GPIOC, 0x00); // // Reset the interrupt flags. // g_ui32GPIOa = 0; g_ui32GPIOb = 0; g_ui32GPIOc = 0; g_ui32Index = 1; // // Trigger the interrupt for GPIO C. // HWREG(NVIC_SW_TRIG) = INT_GPIOC - 16; // // Put the current interrupt state on the display. // DisplayIntStatus(); // // Verify that the interrupts were processed in the correct order. // if((g_ui32GPIOa != 3) || (g_ui32GPIOb != 2) || (g_ui32GPIOc != 1)) { ui8Error |= 2; } // // Wait two seconds. // Delay(2); // // Indicate that the increasing interrupt priority test is beginning. // GrStringDrawCentered(&g_sContext, " Increasing Priority ", -1, GrContextDpyWidthGet(&g_sContext) / 2, 60, 1); // // Set the interrupt priorities so that they are increasing (i.e. C < B < // A). // ROM_IntPrioritySet(INT_GPIOA, 0x00); ROM_IntPrioritySet(INT_GPIOB, 0x40); ROM_IntPrioritySet(INT_GPIOC, 0x80); // // Reset the interrupt flags. // g_ui32GPIOa = 0; g_ui32GPIOb = 0; g_ui32GPIOc = 0; g_ui32Index = 1; // // Trigger the interrupt for GPIO C. // HWREG(NVIC_SW_TRIG) = INT_GPIOC - 16; // // Put the current interrupt state on the display. // DisplayIntStatus(); // // Verify that the interrupts were processed in the correct order. // if((g_ui32GPIOa != 1) || (g_ui32GPIOb != 2) || (g_ui32GPIOc != 3)) { ui8Error |= 4; } // // Wait two seconds. // Delay(2); // // Disable the interrupts. // ROM_IntDisable(INT_GPIOA); ROM_IntDisable(INT_GPIOB); ROM_IntDisable(INT_GPIOC); // // Disable interrupts to the processor. // ROM_IntMasterDisable(); // // Print out the test results. // GrStringDrawCentered(&g_sContext, " Interrupt Priority ", -1, GrContextDpyWidthGet(&g_sContext) / 2, 60, 1); if(ui8Error) { GrStringDrawCentered(&g_sContext, " Equal: P Inc: P Dec: P ", -1, GrContextDpyWidthGet(&g_sContext) / 2, 150, 1); if(ui8Error & 1) { GrStringDrawCentered(&g_sContext, " F ", -1, 113, 150, 1); } if(ui8Error & 2) { GrStringDrawCentered(&g_sContext, " F ", -1, 187, 150, 1); } if(ui8Error & 4) { GrStringDrawCentered(&g_sContext, " F ", -1, 272, 150, 1); } } else { GrStringDrawCentered(&g_sContext, " Success! ", -1, GrContextDpyWidthGet(&g_sContext) / 2, 150, 1); } // // Flush the display. // GrFlush(&g_sContext); // // Loop forever. // while(1) { } }
void UARTSendData() { //Sends read data through UART //TODO int i; float avg_temp; float min_temp = 5000; float max_temp = 0; float std_dev_temp; float avg_prox; uint32_t min_prox = 5000; uint32_t max_prox = 0; float std_dev_prox; float avg_light; uint32_t min_light = 500000; uint32_t max_light = 0; float std_dev_light; if (HWREGBITW(&g_ui32PrintFlags, 0)) { //Clock reading is ready HWREGBITW(&g_ui32PrintFlags, 0) = 0; //Reset flag ROM_IntMasterDisable(); UARTprintf("\033[1;1HDays:Hours:Minutes:Seconds: %02d:%02d:%02d:%02d", RTC_Days, RTC_Hours % 24, RTC_Minutes % 60, RTC_Seconds % 60); ROM_IntMasterEnable(); } if (HWREGBITW(&g_ui32PrintFlags, 1)) { //Temp readings are ready HWREGBITW(&g_ui32PrintFlags, 1) = 0; //Reset flag //Print temp data for (i = 0; i < 50; i++) { //Calculate min, max, and mean avg_temp += g_temp_data[i]; min_temp = g_temp_data[i] < min_temp ? g_temp_data[i] : min_temp; max_temp = g_temp_data[i] > max_temp ? g_temp_data[i] : max_temp; } avg_temp = avg_temp / 50; for (i = 0; i < 50; i++) { //Calculate standard deviation std_dev_temp += (g_temp_data[i] - avg_temp) * (g_temp_data[i] - avg_temp); } std_dev_temp = std_dev_temp / 50; std_dev_temp = sqrt(std_dev_temp); //std_dev_temp = std_dev_temp * 100; ROM_IntMasterDisable(); /*UARTprintf("\n\n+------------------------------------------------------------------------+\n"); UARTprintf( "| Temperature |\n"); UARTprintf( "+------------------+-------------------+------------------+--------------+\n"); UARTprintf( "| Min | Max | Mean | Std. Dev. |\n"); UARTprintf( "+------------------+-------------------+------------------+--------------+\n"); UARTprintf( "| %d.%02d | %d.%02d | %d.%02d | %d.%03d |\n", (uint32_t) min_temp, (uint32_t) ((int) (min_temp * 100) % (int) min_temp * 100) / 100, (uint32_t) max_temp, (uint32_t) ((int) (max_temp * 100) % (int) max_temp * 100) / 100, (uint32_t) avg_temp, (uint32_t) ((int) (avg_temp * 100) % (int) avg_temp * 100) / 100, (uint32_t) std_dev_temp, (uint32_t) ((int) (std_dev_temp * 100) % (int) std_dev_temp * 100) / 100); UARTprintf( "+------------------+-------------------+------------------+--------------+");*/ //UARTprintf("\033[3;1H+-----------------+------------------+-------------------+------------------+--------------+\n"); //UARTprintf("| Sensor | Min | Max | Mean | Std. Dev. |\n"); //UARTprintf("+-----------------+------------------+-------------------+------------------+--------------+\n"); UARTprintf("\033[6;1HMin Temp = %d.%02d\n", (uint32_t) min_temp, (uint32_t) ((int) (min_temp * 100) % (int) min_temp * 100) / 100); UARTprintf("Max Temp = %d.%02d\n", (uint32_t) max_temp, (uint32_t) ((int) (max_temp * 100) % (int) max_temp * 100) / 100); UARTprintf("Mean Temp = %d.%02d\n", (uint32_t) avg_temp, (uint32_t) ((int) (avg_temp * 100) % (int) avg_temp * 100) / 100); UARTprintf("Std. Dev. Temp = %d.%03d" , (uint32_t) std_dev_temp, (uint32_t) ((int) (std_dev_temp * 100) % (int) std_dev_temp * 100) / 100); ROM_IntMasterEnable(); } //ROM_SysCtlDelay(g_ui32SysClock / 3 / 400000); //Delay for 2us if (HWREGBITW(&g_ui32PrintFlags, 2)) { //Proximity readings are ready HWREGBITW(&g_ui32PrintFlags, 2) = 0; //Reset flag //Print proximity data for (i = 0; i < 20; i++) { //Calculate min, max, and mean avg_prox += g_prox_data[i]; min_prox = g_prox_data[i] < min_prox ? g_prox_data[i] : min_prox; max_prox = g_prox_data[i] > max_prox ? g_prox_data[i] : max_prox; } avg_prox = (float) avg_prox / 20; for (i = 0; i < 20; i++) { //Calculate standard deviation std_dev_prox += ((float) g_prox_data[i] - avg_prox) * ((float) g_prox_data[i] - avg_prox); } std_dev_prox = std_dev_prox / 20; std_dev_prox = sqrt(std_dev_prox); ROM_IntMasterDisable(); UARTprintf("\033[11;1HMin Prox = %d\n", min_prox); UARTprintf("Max Prox = %d\n", max_prox); UARTprintf("Mean Prox = %d.%02d\n", (uint32_t) avg_prox, (uint32_t) ((int) (avg_prox * 100) % (int) avg_prox * 100) / 100); UARTprintf("Std. Dev. Prox = %d.%03d" , (uint32_t) std_dev_prox, (uint32_t) ((int) (std_dev_prox * 100) % (int) std_dev_prox * 100) / 100); ROM_IntMasterEnable(); } if (HWREGBITW(&g_ui32PrintFlags, 3)) { //light readings are ready HWREGBITW(&g_ui32PrintFlags, 3) = 0; //Reset flag //Print light data for (i = 0; i < 100; i++) { //Calculate min, max, and mean avg_light += g_light_data[i]; min_light = g_light_data[i] < min_light ? g_light_data[i] : min_light; max_light = g_light_data[i] > max_light ? g_light_data[i] : max_light; } avg_light = (float) avg_light / 100; for (i = 0; i < 100; i++) { //Calculate standard deviation std_dev_light += ((float) g_light_data[i] - avg_light) * ((float) g_light_data[i] - avg_light); } std_dev_light = std_dev_light / 100; std_dev_light = sqrt(std_dev_light); ROM_IntMasterDisable(); UARTprintf("\033[16;1H\033[0JMin Light = %d\n", min_light); UARTprintf("Max Light = %d\n", max_light); UARTprintf("Mean Light = %d.%02d\n", (uint32_t) avg_light, (uint32_t) ((int) (avg_light * 100) % (int) avg_light * 100) / 100); UARTprintf("Std. Dev. Light = %d.%03d" , (uint32_t) std_dev_light, (uint32_t) ((int) (std_dev_light * 100) % (int) std_dev_light * 100) / 100); ROM_IntMasterEnable(); } }
//***************************************************************************** // // This is the main application entry function. // //***************************************************************************** int main(void) { uint32_t ui32TxCount; uint32_t ui32RxCount; //uint32_t ui32Loop; // // 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(); // // Set the clocking to run from the PLL at 50MHz // #if 1 ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Configure the required pins for USB operation. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); ROM_GPIOPinTypeUSBAnalog(GPIO_PORTD_BASE, GPIO_PIN_5 | GPIO_PIN_4); //ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / 100); /* This code taken from: http://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/t/311237.aspx */ #else #include "hw_nvic.h" FlashErase(0x00000000); ROM_IntMasterDisable(); ROM_SysTickIntDisable(); ROM_SysTickDisable(); uint32_t ui32SysClock; ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); ui32SysClock = ROM_SysCtlClockGet(); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); ROM_GPIOPinTypeUSBAnalog(GPIO_PORTD_BASE, GPIO_PIN_4 | GPIO_PIN_5); ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / 100); HWREG(NVIC_DIS0) = 0xffffffff; HWREG(NVIC_DIS1) = 0xffffffff; HWREG(NVIC_DIS2) = 0xffffffff; HWREG(NVIC_DIS3) = 0xffffffff; HWREG(NVIC_DIS4) = 0xffffffff; int ui32Addr; for(ui32Addr = NVIC_PRI0; ui32Addr <= NVIC_PRI34; ui32Addr+=4) { HWREG(ui32Addr) = 0; } HWREG(NVIC_SYS_PRI1) = 0; HWREG(NVIC_SYS_PRI2) = 0; HWREG(NVIC_SYS_PRI3) = 0; ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0); ROM_SysCtlPeripheralReset(SYSCTL_PERIPH_USB0); ROM_SysCtlUSBPLLEnable(); ROM_SysCtlDelay(ui32SysClock*2 / 3); ROM_IntMasterEnable(); ROM_UpdateUSB(0); while(1) { } #endif #define BOOTLOADER_TEST 0 #if BOOTLOADER_TEST #include "hw_nvic.h" //ROM_UpdateUART(); // May need to do the following here: // 0. See if this will cause bootloader to start //ROM_FlashErase(0); //ROM_UpdateUSB(0); #define SYSTICKS_PER_SECOND 100 uint32_t ui32SysClock = ROM_SysCtlClockGet(); ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND); ROM_SysTickIntEnable(); ROM_SysTickEnable(); //USBDCDTerm(0); // Disable all interrupts ROM_IntMasterDisable(); ROM_SysTickIntDisable(); ROM_SysTickDisable(); HWREG(NVIC_DIS0) = 0xffffffff; HWREG(NVIC_DIS1) = 0xffffffff; HWREG(NVIC_DIS2) = 0xffffffff; HWREG(NVIC_DIS3) = 0xffffffff; HWREG(NVIC_DIS4) = 0xffffffff; int ui32Addr; for(ui32Addr = NVIC_PRI0; ui32Addr <= NVIC_PRI34; ui32Addr+=4) { HWREG(ui32Addr) = 0; } HWREG(NVIC_SYS_PRI1) = 0; HWREG(NVIC_SYS_PRI2) = 0; HWREG(NVIC_SYS_PRI3) = 0; // 1. Enable USB PLL //ROM_SysCtlUSBPLLEnable(); // 2. Enable USB controller ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0); ROM_SysCtlPeripheralReset(SYSCTL_PERIPH_USB0); //USBClockEnable(USB0_BASE, 8, USB_CLOCK_INTERNAL); //HWREG(USB0_BASE + USB_O_CC) = (8 - 1) | USB_CLOCK_INTERNAL; ROM_SysCtlUSBPLLEnable(); // 3. Enable USB D+ D- pins // 4. Activate USB DFU ROM_SysCtlDelay(ui32SysClock * 2 / 3); ROM_IntMasterEnable(); // Re-enable interrupts at NVIC level ROM_UpdateUSB(0); // 5. Should never get here since update is in progress #endif // BOOTLOADER_TEST // // Enable the GPIO port that is used for the on-board LED. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); // gjs Our board uses GPIOB for LEDs // gjs original ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // // Enable the GPIO pins for the LED (PF2 & PF3). // ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_0|GPIO_PIN_1); // gjs original ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3|GPIO_PIN_2); // // Not configured initially. // g_bUSBConfigured = false; // // Enable the UART that we will be redirecting. // ROM_SysCtlPeripheralEnable(USB_UART_PERIPH); // // Enable and configure the UART RX and TX pins // ROM_SysCtlPeripheralEnable(TX_GPIO_PERIPH); ROM_SysCtlPeripheralEnable(RX_GPIO_PERIPH); ROM_GPIOPinTypeUART(TX_GPIO_BASE, TX_GPIO_PIN); ROM_GPIOPinTypeUART(RX_GPIO_BASE, RX_GPIO_PIN); // // TODO: Add code to configure handshake GPIOs if required. // // // Set the default UART configuration. // ROM_UARTConfigSetExpClk(USB_UART_BASE, ROM_SysCtlClockGet(), DEFAULT_BIT_RATE, DEFAULT_UART_CONFIG); ROM_UARTFIFOLevelSet(USB_UART_BASE, UART_FIFO_TX4_8, UART_FIFO_RX4_8); // // Configure and enable UART interrupts. // ROM_UARTIntClear(USB_UART_BASE, ROM_UARTIntStatus(USB_UART_BASE, false)); ROM_UARTIntEnable(USB_UART_BASE, (UART_INT_OE | UART_INT_BE | UART_INT_PE | UART_INT_FE | UART_INT_RT | UART_INT_TX | UART_INT_RX)); // // Enable the system tick. // #if 0 ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND); ROM_SysTickIntEnable(); ROM_SysTickEnable(); #endif // // Initialize the transmit and receive buffers. // USBBufferInit(&g_sTxBuffer); USBBufferInit(&g_sRxBuffer); // // Set the USB stack mode to Device mode with VBUS monitoring. // USBStackModeSet(0, eUSBModeDevice, 0); // // Pass our device information to the USB library and place the device // on the bus. // USBDCDCInit(0, &g_sCDCDevice); // // Clear our local byte counters. // ui32RxCount = 0; ui32TxCount = 0; // // Enable interrupts now that the application is ready to start. // ROM_IntEnable(USB_UART_INT); // Enable FreeRTOS mainA(); // FreeRTOS. Will not return #if 0 // // Main application loop. // while(1) { // // Have we been asked to update the status display? // if(g_ui32Flags & COMMAND_STATUS_UPDATE) { // // Clear the command flag // ROM_IntMasterDisable(); g_ui32Flags &= ~COMMAND_STATUS_UPDATE; ROM_IntMasterEnable(); } // // Has there been any transmit traffic since we last checked? // if(ui32TxCount != g_ui32UARTTxCount) { // // Turn on the Green LED. // // gjs ROM_UARTCharPutNonBlocking(USB_UART_BASE, 'b'); #if 1 if (ui32TxCount & 1) { GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0, GPIO_PIN_0); } else { GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0, 0); } #else if (1 || g_ui32UARTTxCount & 0x01) { GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, GPIO_PIN_3); } else { //GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, 0); } // // Delay for a bit. // for(uint32_t ui32Loop = 0; ui32Loop < 150000; ui32Loop++) { } // // Turn off the Green LED. // GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, 0); #endif // // Take a snapshot of the latest transmit count. // ui32TxCount = g_ui32UARTTxCount; } // // Has there been any receive traffic since we last checked? // if(ui32RxCount != g_ui32UARTRxCount) { // // Turn on the Blue LED. // #if 1 if (ui32RxCount & 1) { GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_1, GPIO_PIN_1); } else { GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_1, 0); } #else GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2); // // Delay for a bit. // for(uint32_t ui32Loop = 0; ui32Loop < 150000; ui32Loop++) { } // // Turn off the Blue LED. // GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0); #endif // // Take a snapshot of the latest receive count. // ui32RxCount = g_ui32UARTRxCount; } } #endif }
//***************************************************************************** // // This is the main example program. It checks to see that the interrupts are // processed in the correct order when they have identical priorities, // increasing priorities, and decreasing priorities. This exercises interrupt // preemption and tail chaining. // //***************************************************************************** int main(void) { uint32_t ui32Error; // // 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(); // // 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_GPIOE); // // Initialize the UART. // ConfigureUART(); UARTprintf("\033[2JInterrupts\n"); // // Configure the PB0-PB2 to be outputs to indicate entry/exit of one // of the interrupt handlers. // ROM_GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3); ROM_GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, 0); // // Set up and enable the SysTick timer. It will be used as a reference // for delay loops in the interrupt handlers. The SysTick timer period // will be set up for one second. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet()); ROM_SysTickEnable(); // // Reset the error indicator. // ui32Error = 0; // // Enable interrupts to the processor. // ROM_IntMasterEnable(); // // Enable the interrupts. // ROM_IntEnable(INT_GPIOA); ROM_IntEnable(INT_GPIOB); ROM_IntEnable(INT_GPIOC); // // Indicate that the equal interrupt priority test is beginning. // UARTprintf("\nEqual Priority\n"); // // Set the interrupt priorities so they are all equal. // ROM_IntPrioritySet(INT_GPIOA, 0x00); ROM_IntPrioritySet(INT_GPIOB, 0x00); ROM_IntPrioritySet(INT_GPIOC, 0x00); // // Reset the interrupt flags. // g_ui32GPIOa = 0; g_ui32GPIOb = 0; g_ui32GPIOc = 0; g_ui32Index = 1; // // Trigger the interrupt for GPIO C. // HWREG(NVIC_SW_TRIG) = INT_GPIOC - 16; // // Put the current interrupt state on the LCD. // DisplayIntStatus(); // // Verify that the interrupts were processed in the correct order. // if((g_ui32GPIOa != 3) || (g_ui32GPIOb != 2) || (g_ui32GPIOc != 1)) { ui32Error |= 1; } // // Wait two seconds. // Delay(2); // // Indicate that the decreasing interrupt priority test is beginning. // UARTprintf("\nDecreasing Priority\n"); // // Set the interrupt priorities so that they are decreasing (i.e. C > B > // A). // ROM_IntPrioritySet(INT_GPIOA, 0x80); ROM_IntPrioritySet(INT_GPIOB, 0x40); ROM_IntPrioritySet(INT_GPIOC, 0x00); // // Reset the interrupt flags. // g_ui32GPIOa = 0; g_ui32GPIOb = 0; g_ui32GPIOc = 0; g_ui32Index = 1; // // Trigger the interrupt for GPIO C. // HWREG(NVIC_SW_TRIG) = INT_GPIOC - 16; // // Put the current interrupt state on the UART. // DisplayIntStatus(); // // Verify that the interrupts were processed in the correct order. // if((g_ui32GPIOa != 3) || (g_ui32GPIOb != 2) || (g_ui32GPIOc != 1)) { ui32Error |= 2; } // // Wait two seconds. // Delay(2); // // Indicate that the increasing interrupt priority test is beginning. // UARTprintf("\nIncreasing Priority\n"); // // Set the interrupt priorities so that they are increasing (i.e. C < B < // A). // ROM_IntPrioritySet(INT_GPIOA, 0x00); ROM_IntPrioritySet(INT_GPIOB, 0x40); ROM_IntPrioritySet(INT_GPIOC, 0x80); // // Reset the interrupt flags. // g_ui32GPIOa = 0; g_ui32GPIOb = 0; g_ui32GPIOc = 0; g_ui32Index = 1; // // Trigger the interrupt for GPIO C. // HWREG(NVIC_SW_TRIG) = INT_GPIOC - 16; // // Put the current interrupt state on the UART. // DisplayIntStatus(); // // Verify that the interrupts were processed in the correct order. // if((g_ui32GPIOa != 1) || (g_ui32GPIOb != 2) || (g_ui32GPIOc != 3)) { ui32Error |= 4; } // // Wait two seconds. // Delay(2); // // Disable the interrupts. // ROM_IntDisable(INT_GPIOA); ROM_IntDisable(INT_GPIOB); ROM_IntDisable(INT_GPIOC); // // Disable interrupts to the processor. // ROM_IntMasterDisable(); // // Print out the test results. // UARTprintf("\nInterrupt Priority =: %s >: %s <: %s\n", (ui32Error & 1) ? "Fail" : "Pass", (ui32Error & 2) ? "Fail" : "Pass", (ui32Error & 4) ? "Fail" : "Pass"); // // Loop forever. // while(1) { } }
void Timer0A_ISR(void) { unsigned long timer; int i; unsigned char all_steps_completed; float tmp; unsigned char endstop_bits; unsigned char endstops[4]; TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT); ROM_IntMasterDisable(); if (cur_block == NULL) { if (num_blocks > 0 && blk_queue[blk_queue_head].status == BLOCK_QUEUED && blk_queue[blk_queue_head].recalculate == 0) { cur_block = &blk_queue[blk_queue_head]; cur_block->status = BLOCK_RUNNING; step_rate = cur_block->initial_rate; acceleration_time=0; if (!motors_enabled) motor_enable(); if (endstop_triggered()) { endstop_bits = ROM_GPIOPinRead(ENDSTOP_PORT, ENDSTOP_ALLPINS); endstops[X] = ( (endstop_bits & XLIM_PIN) == 0)?1:0; endstops[Y] = ( (endstop_bits & YLIM_PIN) == 0)?1:0; endstops[Z] = ( (endstop_bits & ZLIM_PIN) == 0)?1:0; for (i=0;i<3;i++) if (cur_block->dir[i]<0 && cur_block->steps[i] > 0 && endstops[i] ) cur_block->status = BLOCK_ABORTED; } } else { cur_block = NULL; timer=calculate_timer(MIN_STEP_RATE); ROM_TimerLoadSet(TIMER0_BASE,TIMER_A, timer); ROM_TimerEnable(TIMER0_BASE, TIMER_A); ROM_IntMasterEnable(); return ; } } //if an endstop is hit, the block is aborted. if (cur_block->status == BLOCK_ABORTED ) { cur_block->status = BLOCK_ABORTED_RDY; cur_block = NULL; //dump the buffer num_blocks=0; blk_queue_head=0; blk_queue_tail=0; step_events_completed=0; for (i=0;i<4;i++) cur_steps[i]=0; timer=calculate_timer(MIN_STEP_RATE); ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, timer); ROM_TimerEnable(TIMER0_BASE, TIMER_A); ROM_IntMasterEnable(); return; } if (step_events_completed <= (cur_block->accelerate_until)) { step_rate = (unsigned long)((float)acceleration_time/80000000 * (float)(cur_block->acceleration_rate)) + cur_block->initial_rate; if (step_rate >(cur_block->nominal_rate)) step_rate=cur_block->nominal_rate; // printf("accel %d %d", acceleration_time, cur_block->acceleration_rate); } else if (step_events_completed > (cur_block->decelerate_after) && step_rate > cur_block->final_rate) { step_rate = peak_rate - (unsigned long)((float)acceleration_time/80000000 * (float)(cur_block->acceleration_rate)); if (step_rate < cur_block->final_rate) step_rate = cur_block->final_rate; // printf("decel %d %d ",deceleration_time, timer ); } timer=calculate_timer(step_rate); if (step_events_completed == cur_block->decelerate_after) { acceleration_time = 0; peak_rate = step_rate; } acceleration_time += timer; step_events_completed++; all_steps_completed = 1; for (i=0;i<4;i++) { // if (i==1) // printf(" %d %d > 0 && %d > %d\r\n", i, cur_block->steps[i], step_events_completed*(cur_block->steps[i])/(cur_block->step_event_count), cur_steps[i]); if (cur_block->steps[i] > 0 && lround(step_events_completed*(cur_block->steps[i])/(cur_block->step_event_count)) > cur_steps[i]) { //printf("step %d ", i); motor_step(i,cur_block->dir[i]); cur_steps[i]++; // printf("cursteps %d\r\n", cur_steps[i]); } if (cur_steps[i] < (cur_block->steps[i])) all_steps_completed=0; } // printf("step_event_completd: %d blk_event_count: %d\r\n", step_events_completed, cur_block->step_event_count); if (step_events_completed < cur_block->step_event_count || !all_steps_completed ) { ROM_TimerConfigure(TIMER0_BASE,TIMER_CFG_ONE_SHOT); ROM_TimerLoadSet(TIMER0_BASE,TIMER_A, timer); ROM_TimerEnable(TIMER0_BASE,TIMER_A); } else { //ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0x00); cur_block->status=BLOCK_COMPLETED; cur_block = NULL; blk_queue_head++; if (blk_queue_head >= BLOCK_QUEUE_SIZE) blk_queue_head = 0; num_blocks--; step_events_completed =0; for (i=0;i<4;i++) cur_steps[i]=0; //printf("%d block completed. Rescheduling timer for next block.\r\n",num_blocks); ROM_TimerConfigure(TIMER0_BASE,TIMER_CFG_ONE_SHOT); timer=calculate_timer(cur_block->final_rate); ROM_TimerLoadSet(TIMER0_BASE,TIMER_A, timer); ROM_TimerEnable(TIMER0_BASE, TIMER_A); } /*ROM_TimerConfigure(TIMER0_BASE,TIMER_CFG_ONE_SHOT); timer=calculate_timer(cur_block->final_rate); ROM_TimerLoadSet(TIMER0_BASE,TIMER_A, timer); ROM_TimerEnable(TIMER0_BASE, TIMER_A); */ motor_unstep(); // printf("step_events: %d, step_rate: %d, timer: %d\r\n",step_events_completed, step_rate,timer); ROM_IntMasterEnable(); }
//***************************************************************************** // // This is the main example program. It checks to see that the interrupts are // processed in the correct order when they have identical priorities, // increasing priorities, and decreasing priorities. This exercises interrupt // preemption and tail chaining. // //***************************************************************************** int main(void) { unsigned long ulError; // // 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_GPIOB); // // Initialize the UART. // 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[2JInterrupts\n"); // // Configure the F0, D1 and D2 to be outputs to indicate entry/exit of one // of the interrupt handlers. // ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2); ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2, 0); // // Set up and enable the SysTick timer. It will be used as a reference // for delay loops in the interrupt handlers. The SysTick timer period // will be set up for one second. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet()); ROM_SysTickEnable(); // // Reset the error indicator. // ulError = 0; // // Enable interrupts to the processor. // ROM_IntMasterEnable(); // // Enable the interrupts. // ROM_IntEnable(INT_GPIOA); ROM_IntEnable(INT_GPIOB); ROM_IntEnable(INT_GPIOC); // // Indicate that the equal interrupt priority test is beginning. // UARTprintf("\nEqual Priority\n"); // // Set the interrupt priorities so they are all equal. // ROM_IntPrioritySet(INT_GPIOA, 0x00); ROM_IntPrioritySet(INT_GPIOB, 0x00); ROM_IntPrioritySet(INT_GPIOC, 0x00); // // Reset the interrupt flags. // g_ulGPIOa = 0; g_ulGPIOb = 0; g_ulGPIOc = 0; g_ulIndex = 1; // // Trigger the interrupt for GPIO C. // HWREG(NVIC_SW_TRIG) = INT_GPIOC - 16; // // Put the current interrupt state on the LCD. // DisplayIntStatus(); // // Verify that the interrupts were processed in the correct order. // if((g_ulGPIOa != 3) || (g_ulGPIOb != 2) || (g_ulGPIOc != 1)) { ulError |= 1; } // // Wait two seconds. // Delay(2); // // Indicate that the decreasing interrupt priority test is beginning. // UARTprintf("\nDecreasing Priority\n"); // // Set the interrupt priorities so that they are decreasing (i.e. C > B > // A). // ROM_IntPrioritySet(INT_GPIOA, 0x80); ROM_IntPrioritySet(INT_GPIOB, 0x40); ROM_IntPrioritySet(INT_GPIOC, 0x00); // // Reset the interrupt flags. // g_ulGPIOa = 0; g_ulGPIOb = 0; g_ulGPIOc = 0; g_ulIndex = 1; // // Trigger the interrupt for GPIO C. // HWREG(NVIC_SW_TRIG) = INT_GPIOC - 16; // // Put the current interrupt state on the UART. // DisplayIntStatus(); // // Verify that the interrupts were processed in the correct order. // if((g_ulGPIOa != 3) || (g_ulGPIOb != 2) || (g_ulGPIOc != 1)) { ulError |= 2; } // // Wait two seconds. // Delay(2); // // Indicate that the increasing interrupt priority test is beginning. // UARTprintf("\nIncreasing Priority\n"); // // Set the interrupt priorities so that they are increasing (i.e. C < B < // A). // ROM_IntPrioritySet(INT_GPIOA, 0x00); ROM_IntPrioritySet(INT_GPIOB, 0x40); ROM_IntPrioritySet(INT_GPIOC, 0x80); // // Reset the interrupt flags. // g_ulGPIOa = 0; g_ulGPIOb = 0; g_ulGPIOc = 0; g_ulIndex = 1; // // Trigger the interrupt for GPIO C. // HWREG(NVIC_SW_TRIG) = INT_GPIOC - 16; // // Put the current interrupt state on the UART. // DisplayIntStatus(); // // Verify that the interrupts were processed in the correct order. // if((g_ulGPIOa != 1) || (g_ulGPIOb != 2) || (g_ulGPIOc != 3)) { ulError |= 4; } // // Wait two seconds. // Delay(2); // // Disable the interrupts. // ROM_IntDisable(INT_GPIOA); ROM_IntDisable(INT_GPIOB); ROM_IntDisable(INT_GPIOC); // // Disable interrupts to the processor. // ROM_IntMasterDisable(); // // Print out the test results. // UARTprintf("\nInterrupt Priority =: %s >: %s <: %s\n", (ulError & 1) ? "Fail" : "Pass", (ulError & 2) ? "Fail" : "Pass", (ulError & 4) ? "Fail" : "Pass"); // // Finished. // while(1) { } }
//***************************************************************************** // // This is the main example program. It checks to see that the interrupts are // processed in the correct order when they have identical priorities, // increasing priorities, and decreasing priorities. This exercises interrupt // preemption and tail chaining. // //***************************************************************************** int main(void) { tRectangle sRect; uint_fast8_t ui8Error; // // 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(); // // 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_GPIOD); // // Initialize the display driver. // CFAL96x64x16Init(); // // Initialize the graphics context and find the middle X coordinate. // GrContextInit(&g_sContext, &g_sCFAL96x64x16); // // Fill the top part of the screen with blue to create the banner. // sRect.i16XMin = 0; sRect.i16YMin = 0; sRect.i16XMax = GrContextDpyWidthGet(&g_sContext) - 1; sRect.i16YMax = 9; GrContextForegroundSet(&g_sContext, ClrDarkBlue); GrRectFill(&g_sContext, &sRect); // // Change foreground for white text. // GrContextForegroundSet(&g_sContext, ClrWhite); // // Put the application name in the middle of the banner. // GrContextFontSet(&g_sContext, g_psFontFixed6x8); GrStringDrawCentered(&g_sContext, "interrupts", -1, GrContextDpyWidthGet(&g_sContext) / 2, 4, 0); GrContextFontSet(&g_sContext, g_psFontFixed6x8); // // Put the status header text on the display. // GrStringDraw(&g_sContext, "Active:", -1, 6, 32, 0); GrStringDraw(&g_sContext, "Pending:", -1, 0, 44, 0); // // Configure the PB0-PB2 to be outputs to indicate entry/exit of one // of the interrupt handlers. // ROM_GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_3); ROM_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2, 0); // // Set up and enable the SysTick timer. It will be used as a reference // for delay loops in the interrupt handlers. The SysTick timer period // will be set up for one second. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet()); ROM_SysTickEnable(); // // Reset the error indicator. // ui8Error = 0; // // Enable interrupts to the processor. // ROM_IntMasterEnable(); // // Enable the interrupts. // ROM_IntEnable(INT_GPIOA); ROM_IntEnable(INT_GPIOB); ROM_IntEnable(INT_GPIOC); // // Indicate that the equal interrupt priority test is beginning. // GrStringDrawCentered(&g_sContext, "Equal Pri", -1, GrContextDpyWidthGet(&g_sContext) / 2, 20, 1); // // Set the interrupt priorities so they are all equal. // ROM_IntPrioritySet(INT_GPIOA, 0x00); ROM_IntPrioritySet(INT_GPIOB, 0x00); ROM_IntPrioritySet(INT_GPIOC, 0x00); // // Reset the interrupt flags. // g_ui32GPIOa = 0; g_ui32GPIOb = 0; g_ui32GPIOc = 0; g_ui32Index = 1; // // Trigger the interrupt for GPIO C. // HWREG(NVIC_SW_TRIG) = INT_GPIOC - 16; // // Put the current interrupt state on the LCD. // DisplayIntStatus(); // // Verify that the interrupts were processed in the correct order. // if((g_ui32GPIOa != 3) || (g_ui32GPIOb != 2) || (g_ui32GPIOc != 1)) { ui8Error |= 1; } // // Wait two seconds. // Delay(2); // // Indicate that the decreasing interrupt priority test is beginning. // GrStringDrawCentered(&g_sContext, " Decreasing Pri ", -1, GrContextDpyWidthGet(&g_sContext) / 2, 20, 1); // // Set the interrupt priorities so that they are decreasing (i.e. C > B > // A). // ROM_IntPrioritySet(INT_GPIOA, 0x80); ROM_IntPrioritySet(INT_GPIOB, 0x40); ROM_IntPrioritySet(INT_GPIOC, 0x00); // // Reset the interrupt flags. // g_ui32GPIOa = 0; g_ui32GPIOb = 0; g_ui32GPIOc = 0; g_ui32Index = 1; // // Trigger the interrupt for GPIO C. // HWREG(NVIC_SW_TRIG) = INT_GPIOC - 16; // // Put the current interrupt state on the CSTN. // DisplayIntStatus(); // // Verify that the interrupts were processed in the correct order. // if((g_ui32GPIOa != 3) || (g_ui32GPIOb != 2) || (g_ui32GPIOc != 1)) { ui8Error |= 2; } // // Wait two seconds. // Delay(2); // // Indicate that the increasing interrupt priority test is beginning. // GrStringDrawCentered(&g_sContext, " Increasing Pri ", -1, GrContextDpyWidthGet(&g_sContext) / 2, 20, 1); // // Set the interrupt priorities so that they are increasing (i.e. C < B < // A). // ROM_IntPrioritySet(INT_GPIOA, 0x00); ROM_IntPrioritySet(INT_GPIOB, 0x40); ROM_IntPrioritySet(INT_GPIOC, 0x80); // // Reset the interrupt flags. // g_ui32GPIOa = 0; g_ui32GPIOb = 0; g_ui32GPIOc = 0; g_ui32Index = 1; // // Trigger the interrupt for GPIO C. // HWREG(NVIC_SW_TRIG) = INT_GPIOC - 16; // // Put the current interrupt state on the CSTN. // DisplayIntStatus(); // // Verify that the interrupts were processed in the correct order. // if((g_ui32GPIOa != 1) || (g_ui32GPIOb != 2) || (g_ui32GPIOc != 3)) { ui8Error |= 4; } // // Wait two seconds. // Delay(2); // // Disable the interrupts. // ROM_IntDisable(INT_GPIOA); ROM_IntDisable(INT_GPIOB); ROM_IntDisable(INT_GPIOC); // // Disable interrupts to the processor. // ROM_IntMasterDisable(); // // Print out results if error occurred. // if(ui8Error) { GrStringDraw(&g_sContext, "Equal: P ", -1, 0, 32, 1); GrStringDraw(&g_sContext, " Inc: P ", -1, 0, 44, 1); GrStringDraw(&g_sContext, " Dec: P ", -1, 0, 56, 1); if(ui8Error & 1) { GrStringDraw(&g_sContext, "F ", -1, 42, 32, 1); } if(ui8Error & 2) { GrStringDraw(&g_sContext, "F ", -1, 42, 44, 1); } if(ui8Error & 4) { GrStringDraw(&g_sContext, "F ", -1, 42, 56, 1); } } else { GrStringDrawCentered(&g_sContext, " Success! ", -1, GrContextDpyWidthGet(&g_sContext) / 2, 20, 1); } // // Flush the display. // GrFlush(&g_sContext); // // Loop forever. // while(1) { } }
void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) { uint32_t lm4fMode, i; uint8_t bit = digitalPinToBitMask(interruptNum); uint8_t port = digitalPinToPort(interruptNum); uint32_t portBase = (uint32_t) portBASERegister(port); switch(mode) { case LOW: lm4fMode = GPIO_LOW_LEVEL; break; case CHANGE: lm4fMode = GPIO_BOTH_EDGES; break; case RISING: lm4fMode = GPIO_RISING_EDGE; break; case FALLING: lm4fMode = GPIO_FALLING_EDGE; break; default: return; } ROM_IntMasterDisable(); GPIOIntClear(portBase, bit); ROM_GPIOIntTypeSet(portBase, bit, lm4fMode); GPIOIntEnable(portBase, bit); for (i=0; i<8; i++, bit>>=1) { if ((bit & 0x1) == 1) break; } switch(portBase) { case GPIO_PORTA_BASE: cbFuncsA[i] = userFunc; ROM_IntEnable(INT_GPIOA); break; case GPIO_PORTB_BASE: cbFuncsB[i] = userFunc; ROM_IntEnable(INT_GPIOB); break; case GPIO_PORTC_BASE: cbFuncsC[i] = userFunc; ROM_IntEnable(INT_GPIOC); break; case GPIO_PORTD_BASE: cbFuncsD[i] = userFunc; ROM_IntEnable(INT_GPIOD); break; case GPIO_PORTE_BASE: cbFuncsE[i] = userFunc; ROM_IntEnable(INT_GPIOE); break; case GPIO_PORTF_BASE: cbFuncsF[i] = userFunc; ROM_IntEnable(INT_GPIOF); break; case GPIO_PORTG_BASE: cbFuncsG[i] = userFunc; ROM_IntEnable(INT_GPIOG); break; case GPIO_PORTH_BASE: cbFuncsH[i] = userFunc; ROM_IntEnable(INT_GPIOH); break; case GPIO_PORTJ_BASE: cbFuncsJ[i] = userFunc; ROM_IntEnable(INT_GPIOJ); break; case GPIO_PORTK_BASE: cbFuncsK[i] = userFunc; ROM_IntEnable(INT_GPIOK); break; case GPIO_PORTL_BASE: cbFuncsL[i] = userFunc; ROM_IntEnable(INT_GPIOL); break; case GPIO_PORTM_BASE: cbFuncsM[i] = userFunc; ROM_IntEnable(INT_GPIOM); break; case GPIO_PORTN_BASE: cbFuncsN[i] = userFunc; ROM_IntEnable(INT_GPION); break; case GPIO_PORTP_BASE: cbFuncsP[i] = userFunc; ROM_IntEnable(INT_GPIOP0); ROM_IntEnable(INT_GPIOP1); ROM_IntEnable(INT_GPIOP2); ROM_IntEnable(INT_GPIOP3); ROM_IntEnable(INT_GPIOP4); ROM_IntEnable(INT_GPIOP5); ROM_IntEnable(INT_GPIOP6); ROM_IntEnable(INT_GPIOP7); break; case GPIO_PORTQ_BASE: cbFuncsQ[i] = userFunc; ROM_IntEnable(INT_GPIOQ0); ROM_IntEnable(INT_GPIOQ1); ROM_IntEnable(INT_GPIOQ2); ROM_IntEnable(INT_GPIOQ3); ROM_IntEnable(INT_GPIOQ4); ROM_IntEnable(INT_GPIOQ5); ROM_IntEnable(INT_GPIOQ6); ROM_IntEnable(INT_GPIOQ7); break; #ifdef TARGET_IS_SNOWFLAKE_RA0 case GPIO_PORTR_BASE: cbFuncsR[i] = userFunc; ROM_IntEnable(INT_GPIOR); break; case GPIO_PORTS_BASE: cbFuncsS[i] = userFunc; ROM_IntEnable(INT_GPIOS); break; case GPIO_PORTT_BASE: cbFuncsT[i] = userFunc; ROM_IntEnable(INT_GPIOT); break; #endif } ROM_IntMasterEnable(); }
//***************************************************************************** // // This is the main application entry function. // //***************************************************************************** int main(void) { unsigned long ulTxCount; unsigned long ulRxCount; unsigned long ulLoop; // // 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(); // // Set the clocking to run from the PLL at 50MHz // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Configure the required pins for USB operation. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); ROM_GPIOPinTypeUSBAnalog(GPIO_PORTD_BASE, GPIO_PIN_5 | GPIO_PIN_4); // // 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 & PF3). // ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3|GPIO_PIN_2); // // Not configured initially. // g_bUSBConfigured = false; // // Enable the UART that we will be redirecting. // ROM_SysCtlPeripheralEnable(USB_UART_PERIPH); // // Enable and configure the UART RX and TX pins // ROM_SysCtlPeripheralEnable(TX_GPIO_PERIPH); ROM_SysCtlPeripheralEnable(RX_GPIO_PERIPH); ROM_GPIOPinTypeUART(TX_GPIO_BASE, TX_GPIO_PIN); ROM_GPIOPinTypeUART(RX_GPIO_BASE, RX_GPIO_PIN); // // TODO: Add code to configure handshake GPIOs if required. // // // Set the default UART configuration. // ROM_UARTConfigSetExpClk(USB_UART_BASE, ROM_SysCtlClockGet(), DEFAULT_BIT_RATE, DEFAULT_UART_CONFIG); ROM_UARTFIFOLevelSet(USB_UART_BASE, UART_FIFO_TX4_8, UART_FIFO_RX4_8); // // Configure and enable UART interrupts. // ROM_UARTIntClear(USB_UART_BASE, ROM_UARTIntStatus(USB_UART_BASE, false)); ROM_UARTIntEnable(USB_UART_BASE, (UART_INT_OE | UART_INT_BE | UART_INT_PE | UART_INT_FE | UART_INT_RT | UART_INT_TX | UART_INT_RX)); // // Enable the system tick. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND); ROM_SysTickIntEnable(); ROM_SysTickEnable(); // // Initialize the transmit and receive buffers. // USBBufferInit((tUSBBuffer *)&g_sTxBuffer); USBBufferInit((tUSBBuffer *)&g_sRxBuffer); // // Set the USB stack mode to Device mode with VBUS monitoring. // USBStackModeSet(0, USB_MODE_DEVICE, 0); // // Pass our device information to the USB library and place the device // on the bus. // USBDCDCInit(0, (tUSBDCDCDevice *)&g_sCDCDevice); // // Clear our local byte counters. // ulRxCount = 0; ulTxCount = 0; // // Enable interrupts now that the application is ready to start. // ROM_IntEnable(USB_UART_INT); // // Main application loop. // while(1) { // // Have we been asked to update the status display? // if(g_ulFlags & COMMAND_STATUS_UPDATE) { // // Clear the command flag // ROM_IntMasterDisable(); g_ulFlags &= ~COMMAND_STATUS_UPDATE; ROM_IntMasterEnable(); } // // Has there been any transmit traffic since we last checked? // if(ulTxCount != g_ulUARTTxCount) { // // Turn on the Green LED. // GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, GPIO_PIN_3); // // Delay for a bit. // for(ulLoop = 0; ulLoop < 150000; ulLoop++) { } // // Turn off the Green LED. // GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, 0); // // Take a snapshot of the latest transmit count. // ulTxCount = g_ulUARTTxCount; } // // Has there been any receive traffic since we last checked? // if(ulRxCount != g_ulUARTRxCount) { // // Turn on the Blue LED. // GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2); // // Delay for a bit. // for(ulLoop = 0; ulLoop < 150000; ulLoop++) { } // // Turn off the Blue LED. // GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0); // // Take a snapshot of the latest receive count. // ulRxCount = g_ulUARTRxCount; } } }
//***************************************************************************** // // This is the main example program. It checks to see that the interrupts are // processed in the correct order when they have identical priorities, // increasing priorities, and decreasing priorities. This exercises interrupt // preemption and tail chaining. // //***************************************************************************** int main(void) { uint_fast8_t ui8Error; // // Run from the PLL at 120 MHz. // g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // // Configure the device pins. // PinoutSet(false, false); // // Configure the UART. // ConfigureUART(); // // Configure the B3, L1 and L0 to be outputs to indicate entry/exit of one // of the interrupt handlers. // GPIOPinTypeGPIOOutput(GPIO_A_BASE, GPIO_A_PIN); GPIOPinTypeGPIOOutput(GPIO_B_BASE, GPIO_B_PIN); GPIOPinTypeGPIOOutput(GPIO_C_BASE, GPIO_C_PIN); GPIOPinWrite(GPIO_A_BASE, GPIO_A_PIN, 0); GPIOPinWrite(GPIO_B_BASE, GPIO_B_PIN, 0); GPIOPinWrite(GPIO_C_BASE, GPIO_C_PIN, 0); // // Set up and enable the SysTick timer. It will be used as a reference // for delay loops in the interrupt handlers. The SysTick timer period // will be set up for 100 times per second. // ROM_SysTickPeriodSet(g_ui32SysClock / 100); ROM_SysTickEnable(); // // Reset the error indicator. // ui8Error = 0; // // Enable interrupts to the processor. // ROM_IntMasterEnable(); // // Enable the interrupts. // ROM_IntEnable(INT_GPIOA); ROM_IntEnable(INT_GPIOB); ROM_IntEnable(INT_GPIOC); // // Indicate that the equal interrupt priority test is beginning. // g_ui32IntMode = EQUAL_PRIORITY; // // Set the interrupt priorities so they are all equal. // ROM_IntPrioritySet(INT_GPIOA, 0x00); ROM_IntPrioritySet(INT_GPIOB, 0x00); ROM_IntPrioritySet(INT_GPIOC, 0x00); // // Reset the interrupt flags. // g_ui32GPIOa = 0; g_ui32GPIOb = 0; g_ui32GPIOc = 0; g_ui32Index = 1; // // Trigger the interrupt for GPIO C. // HWREG(NVIC_SW_TRIG) = INT_GPIOC - 16; // // Put the current interrupt state on the LCD. // DisplayIntStatus(); // // Verify that the interrupts were processed in the correct order. // if((g_ui32GPIOa != 3) || (g_ui32GPIOb != 2) || (g_ui32GPIOc != 1)) { ui8Error |= 1; } // // Wait two seconds. // Delay(2); // // Indicate that the decreasing interrupt priority test is beginning. // g_ui32IntMode = DECREASING_PRIORITY; // // Set the interrupt priorities so that they are decreasing (i.e. C > B > // A). // ROM_IntPrioritySet(INT_GPIOA, 0x80); ROM_IntPrioritySet(INT_GPIOB, 0x40); ROM_IntPrioritySet(INT_GPIOC, 0x00); // // Reset the interrupt flags. // g_ui32GPIOa = 0; g_ui32GPIOb = 0; g_ui32GPIOc = 0; g_ui32Index = 1; // // Trigger the interrupt for GPIO C. // HWREG(NVIC_SW_TRIG) = INT_GPIOC - 16; // // Put the current interrupt state on the UART. // DisplayIntStatus(); // // Verify that the interrupts were processed in the correct order. // if((g_ui32GPIOa != 3) || (g_ui32GPIOb != 2) || (g_ui32GPIOc != 1)) { ui8Error |= 2; } // // Wait two seconds. // Delay(2); // // Indicate that the increasing interrupt priority test is beginning. // g_ui32IntMode = INCREASING_PRIORITY; // // Set the interrupt priorities so that they are increasing (i.e. C < B < // A). // ROM_IntPrioritySet(INT_GPIOA, 0x00); ROM_IntPrioritySet(INT_GPIOB, 0x40); ROM_IntPrioritySet(INT_GPIOC, 0x80); // // Reset the interrupt flags. // g_ui32GPIOa = 0; g_ui32GPIOb = 0; g_ui32GPIOc = 0; g_ui32Index = 1; // // Trigger the interrupt for GPIO C. // HWREG(NVIC_SW_TRIG) = INT_GPIOC - 16; // // Put the current interrupt state on the UART. // DisplayIntStatus(); // // Verify that the interrupts were processed in the correct order. // if((g_ui32GPIOa != 1) || (g_ui32GPIOb != 2) || (g_ui32GPIOc != 3)) { ui8Error |= 4; } // // Wait two seconds. // Delay(2); // // Disable the interrupts. // ROM_IntDisable(INT_GPIOA); ROM_IntDisable(INT_GPIOB); ROM_IntDisable(INT_GPIOC); // // Disable interrupts to the processor. // ROM_IntMasterDisable(); // // Print out the test results. // UARTprintf("\033[2J\033[H"); UARTprintf("Interrupts example\n\n"); if(ui8Error) { if(ui8Error & 1) { UARTprintf("Equal Priority Fail!\n"); } if(ui8Error & 2) { UARTprintf("Decreasing Priority Fail!\n"); } if(ui8Error & 4) { UARTprintf("Increasing Priority Fail!\n"); } } else { UARTprintf("Success!"); } // // Loop forever. // while(1) { } }