int cppmain() { init(); resetMicros(); enableMessaging(); // Set up the pins int i; for (i = 0; i < 12; i++) pinMode(legPins[i], OUTPUT_SERVO); pinMode(BLUE_LED, OUTPUT); // We will use WTIMER0 for the interrupts ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER0); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_WTIMER0); ROM_TimerConfigure(WTIMER0_BASE, (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_PERIODIC)); // Set up the stag walking timer interrupt ROM_TimerPrescaleSet(WTIMER0_BASE, TIMER_A, 79999); // 1 ms per tick TimerIntRegister(WTIMER0_BASE, TIMER_A, stagInterrupt); ROM_TimerLoadSet(WTIMER0_BASE, TIMER_A, 50); // 50 ms per cylce ROM_TimerIntEnable(WTIMER0_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerEnable(WTIMER0_BASE, TIMER_A); ROM_IntPrioritySet(INT_WTIMER0A, 0x20); // Set general sensor/status interrupt ROM_TimerPrescaleSet(WTIMER0_BASE, TIMER_B, 79999); // 1 ms per tick TimerIntRegister(WTIMER0_BASE, TIMER_B, statusInterrupt); ROM_TimerLoadSet(WTIMER0_BASE, TIMER_B, 500); // 500 ms per cycle ROM_TimerIntEnable(WTIMER0_BASE, TIMER_TIMB_TIMEOUT); ROM_TimerEnable(WTIMER0_BASE, TIMER_B); ROM_IntPrioritySet(INT_WTIMER0A, 0x40); uint16_t msgLength; uint16_t msgFlags; MessageType msgType; // Main message handing loop bool z = true; while (1) { digitalWrite(BLUE_LED, z); z = !z; switch (getMessage(&msgType, &msgLength, &msgFlags, g_msgBody)) { case 0: // Success handleMessage(msgType, msgLength, g_msgBody); break; case 1: // Timeout //sendError(TIMEOUT_ERROR); break; case 2: // CRC Error sendError(CRC_ERROR); break; } //delay(10000); } }
void enableUART(uint8_t UART, unsigned long baudRate) { // We must unlock PD7 to use UART2 if (UART == 2) { // GPIO Port D Lock Register is at 0x40007520 HWREG(0x40007520) = GPIO_LOCK_KEY; // GPIO Port D Control Register is at 0x40007524 HWREG(0x40007524) = 0x80; } // Enable the UART peripheral in SysCtl ROM_SysCtlPeripheralEnable(SysCtlGPIOs[UARTPins[UART][0] / 8]); ROM_SysCtlPeripheralSleepEnable(SysCtlGPIOs[UARTPins[UART][0] / 8]); ROM_SysCtlPeripheralEnable(SysCtlUARTs[UART]); ROM_SysCtlPeripheralSleepEnable(SysCtlUARTs[UART]); // Configure the associated GPIO pins for UART ROM_GPIOPinConfigure(UARTPins[UART][2]); ROM_GPIOPinConfigure(UARTPins[UART][3]); ROM_GPIOPinTypeUART(GPIO[UARTPins[UART][0] / 8], bit8[UARTPins[UART][0] % 8] | bit8[UARTPins[UART][1] % 8]); // Configure the UART ROM_UARTConfigSetExpClk(UARTBASE[UART], ROM_SysCtlClockGet(), baudRate, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); ROM_UARTFIFOEnable(UARTBASE[UART]); // Configure the UART receive (rx) interrupt ROM_UARTIntEnable(UARTBASE[UART], UART_INT_RX); UARTFIFOLevelSet(UARTBASE[UART], UART_FIFO_TX4_8, UART_FIFO_RX4_8); UARTIntRegister(UARTBASE[UART], rxInterrupts[UART]); ROM_IntPrioritySet(UART_INTs[UART], 0x00); // Enable the UART ROM_UARTEnable(UARTBASE[UART]); }
//***************************************************************************** // // 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) { } }
//***************************************************************************** // // This is the main loop that runs the application. // //***************************************************************************** int main(void) { // // Turn on stacking of FPU registers if FPU is used in the ISR. // FPULazyStackingEnable(); // // Set the clocking to run from the PLL at 40MHz. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Set the system tick to fire 100 times per second. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND); ROM_SysTickIntEnable(); ROM_SysTickEnable(); // // Enable the Debug UART. // ConfigureUART(); // // Print the welcome message to the terminal. // UARTprintf("\033[2JAir Mouse Application\n"); // // Configure desired interrupt priorities. This makes certain that the DCM // is fed data at a consistent rate. Lower numbers equal higher priority. // ROM_IntPrioritySet(INT_I2C3, 0x00); ROM_IntPrioritySet(INT_GPIOB, 0x10); ROM_IntPrioritySet(FAULT_SYSTICK, 0x20); ROM_IntPrioritySet(INT_UART1, 0x60); ROM_IntPrioritySet(INT_UART0, 0x70); ROM_IntPrioritySet(INT_WTIMER5B, 0x80); // // Configure the USB D+ and D- pins. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); ROM_GPIOPinTypeUSBAnalog(GPIO_PORTD_BASE, GPIO_PIN_5 | GPIO_PIN_4); // // Pass the USB library our device information, initialize the USB // controller and connect the device to the bus. // USBDHIDMouseCompositeInit(0, &g_sMouseDevice, &g_psCompDevices[0]); USBDHIDKeyboardCompositeInit(0, &g_sKeyboardDevice, &g_psCompDevices[1]); // // Set the USB stack mode to Force Device mode. // USBStackModeSet(0, eUSBModeForceDevice, 0); // // Pass the device information to the USB library and place the device // on the bus. // USBDCompositeInit(0, &g_sCompDevice, DESCRIPTOR_DATA_SIZE, g_pui8DescriptorData); // // User Interface Init // ButtonsInit(); RGBInit(0); RGBEnable(); // // Initialize the motion sub system. // MotionInit(); // // Initialize the Radio Systems. // LPRFInit(); // // Drop into the main loop. // while(1) { // // Check for and handle timer tick events. // if(HWREGBITW(&g_ui32Events, USB_TICK_EVENT) == 1) { // // Clear the Tick event flag. Set in SysTick interrupt handler. // HWREGBITW(&g_ui32Events, USB_TICK_EVENT) = 0; // // Each tick period handle wired mouse and keyboard. // if(HWREGBITW(&g_ui32USBFlags, FLAG_CONNECTED) == 1) { MouseMoveHandler(); KeyboardMain(); } } // // Check for LPRF tick events. LPRF Ticks are slower since UART to // RNP is much slower data connection than the USB. // if(HWREGBITW(&g_ui32Events, LPRF_TICK_EVENT) == 1) { // // Clear the event flag. // HWREGBITW(&g_ui32Events, LPRF_TICK_EVENT) = 0; // // Perform the LPRF Main task handling // LPRFMain(); } // // Check for and handle motion events. // if((HWREGBITW(&g_ui32Events, MOTION_EVENT) == 1) || (HWREGBITW(&g_ui32Events, MOTION_ERROR_EVENT) == 1)) { // // Clear the motion event flag. Set in the Motion I2C interrupt // handler when an I2C transaction to get sensor data is complete. // HWREGBITW(&g_ui32Events, MOTION_EVENT) = 0; // // Process the motion data that has been captured // MotionMain(); } } }
//***************************************************************************** // // 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) { } }
//***************************************************************************** // // This example demonstrates how to send a string of data to the UART. // //***************************************************************************** int main(void) { // // Set the clocking to run at 80 MHz from the PLL. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Enable the peripherals used by this example. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); // // Compute the bit time for 115,200 baud. // g_ulBitTime = (ROM_SysCtlClockGet() / 115200) - 1; // // Configure the SoftUART for 8-N-1 operation. // SoftUARTInit(&g_sUART); SoftUARTRxGPIOSet(&g_sUART, GPIO_PORTA_BASE, GPIO_PIN_0); SoftUARTTxGPIOSet(&g_sUART, GPIO_PORTA_BASE, GPIO_PIN_1); SoftUARTRxBufferSet(&g_sUART, g_pusRxBuffer, sizeof(g_pusRxBuffer) / sizeof(g_pusRxBuffer[0])); SoftUARTTxBufferSet(&g_sUART, g_pucTxBuffer, sizeof(g_pucTxBuffer)); SoftUARTCallbackSet(&g_sUART, SoftUARTIntHandler); SoftUARTConfigSet(&g_sUART, (SOFTUART_CONFIG_WLEN_8 | SOFTUART_CONFIG_STOP_ONE | SOFTUART_CONFIG_PAR_NONE)); // // Configure the timer for the SoftUART transmitter. // ROM_TimerConfigure(TIMER0_BASE, (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_PERIODIC)); ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, g_ulBitTime); ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT | TIMER_TIMB_TIMEOUT); ROM_TimerEnable(TIMER0_BASE, TIMER_A); // // Set the priorities of the interrupts associated with the SoftUART. The // receiver is higher priority than the transmitter, and the receiver edge // interrupt is higher priority than the receiver timer interrupt. // ROM_IntPrioritySet(INT_GPIOA, 0x00); ROM_IntPrioritySet(INT_TIMER0B, 0x40); ROM_IntPrioritySet(INT_TIMER0A, 0x80); // // Enable the interrupts associated with the SoftUART. // ROM_IntEnable(INT_TIMER0A); ROM_IntEnable(INT_TIMER0B); ROM_IntEnable(INT_GPIOA); // // Prompt for text to be entered. // UARTSend((unsigned char *)"\033[2JEnter text: ", 16); // // Enable the SoftUART interrupt. // SoftUARTIntEnable(&g_sUART, SOFTUART_INT_RX | SOFTUART_INT_RT); // // Loop forever echoing data through the UART. // while(1) { // // Wait until there are characters available in the receive buffer. // while(g_ulFlag == 0) { } g_ulFlag = 0; // // Loop while there are characters in the receive buffer. // while(SoftUARTCharsAvail(&g_sUART)) { // // Read the next character from the UART and write it back to the // UART. // SoftUARTCharPutNonBlocking(&g_sUART, SoftUARTCharGetNonBlocking(&g_sUART)); } } }
//***************************************************************************** // // 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 example demonstrates how to send a string of data to the UART. // //***************************************************************************** int main(void) { tRectangle sRect; tContext sContext; // // Set the clocking to run at 50 MHz from the PLL. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Initialize the display driver. // CFAL96x64x16Init(); // // Initialize the graphics context. // GrContextInit(&sContext, &g_sCFAL96x64x16); // // Fill the top part of the screen with blue to create the banner. // sRect.sXMin = 0; sRect.sYMin = 0; sRect.sXMax = GrContextDpyWidthGet(&sContext) - 1; sRect.sYMax = 9; GrContextForegroundSet(&sContext, ClrDarkBlue); GrRectFill(&sContext, &sRect); // // Change foreground for white text. // GrContextForegroundSet(&sContext, ClrWhite); // // Put the application name in the middle of the banner. // GrContextFontSet(&sContext, g_pFontFixed6x8); GrStringDrawCentered(&sContext, "softuart-echo", -1, GrContextDpyWidthGet(&sContext) / 2, 4, 0); // // Initialize the display and write some instructions. // GrStringDrawCentered(&sContext, "Connect a", -1, GrContextDpyWidthGet(&sContext) / 2, 20, false); GrStringDrawCentered(&sContext, "terminal", -1, GrContextDpyWidthGet(&sContext) / 2, 30, false); GrStringDrawCentered(&sContext, "to UART0.", -1, GrContextDpyWidthGet(&sContext) / 2, 40, false); GrStringDrawCentered(&sContext, "115000,N,8,1", -1, GrContextDpyWidthGet(&sContext) / 2, 50, false); // // Enable the peripherals used by this example. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); // // Compute the bit time for 115,200 baud. // g_ulBitTime = (ROM_SysCtlClockGet() / 115200) - 1; // // Configure the SoftUART for 8-N-1 operation. // SoftUARTInit(&g_sUART); SoftUARTRxGPIOSet(&g_sUART, GPIO_PORTA_BASE, GPIO_PIN_0); SoftUARTTxGPIOSet(&g_sUART, GPIO_PORTA_BASE, GPIO_PIN_1); SoftUARTRxBufferSet(&g_sUART, g_pusRxBuffer, sizeof(g_pusRxBuffer) / sizeof(g_pusRxBuffer[0])); SoftUARTTxBufferSet(&g_sUART, g_pucTxBuffer, sizeof(g_pucTxBuffer)); SoftUARTCallbackSet(&g_sUART, SoftUARTIntHandler); SoftUARTConfigSet(&g_sUART, (SOFTUART_CONFIG_WLEN_8 | SOFTUART_CONFIG_STOP_ONE | SOFTUART_CONFIG_PAR_NONE)); // // Configure the timer for the SoftUART transmitter. // ROM_TimerConfigure(TIMER0_BASE, (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_PERIODIC)); ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, g_ulBitTime); ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT | TIMER_TIMB_TIMEOUT); ROM_TimerEnable(TIMER0_BASE, TIMER_A); // // Set the priorities of the interrupts associated with the SoftUART. The // receiver is higher priority than the transmitter, and the receiver edge // interrupt is higher priority than the receiver timer interrupt. // ROM_IntPrioritySet(INT_GPIOA, 0x00); ROM_IntPrioritySet(INT_TIMER0B, 0x40); ROM_IntPrioritySet(INT_TIMER0A, 0x80); // // Enable the interrupts associated with the SoftUART. // ROM_IntEnable(INT_TIMER0A); ROM_IntEnable(INT_TIMER0B); ROM_IntEnable(INT_GPIOA); // // Prompt for text to be entered. // UARTSend((unsigned char *)"\033[2JEnter text: ", 16); // // Enable the SoftUART interrupt. // SoftUARTIntEnable(&g_sUART, SOFTUART_INT_RX | SOFTUART_INT_RT); // // Loop forever echoing data through the UART. // while(1) { // // Wait until there are characters available in the receive buffer. // while(g_ulFlag == 0) { } g_ulFlag = 0; // // Loop while there are characters in the receive buffer. // while(SoftUARTCharsAvail(&g_sUART)) { // // Read the next character from the UART and write it back to the // UART. // SoftUARTCharPutNonBlocking(&g_sUART, SoftUARTCharGetNonBlocking(&g_sUART)); } } }
//***************************************************************************** // // 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) { } }
//***************************************************************************** // // 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) { } }
//-----------------Program------------------------------------------// int main() { // specifies a system reset when using external reset pin SysCtlResetBehaviorSet(SYSCTL_ONRST_EXT_SYS); //------------------set sys clock to 120 MHZ ------------------------// g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ| SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), g_freq); //-----------------Enable Periph-------------------------------------// ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOM); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART3); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART7); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_PERIODIC); ROM_TimerLoadSet(TIMER0_BASE, TIMER_B, g_freq/12000); ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMB_TIMEOUT); ROM_UARTIntEnable(UART3_BASE,UART_INT_RX); ROM_IntPrioritySet(INT_UART3, 0); ROM_IntPrioritySet(INT_TIMER0B,1); ROM_IntEnable(INT_UART3); ROM_IntEnable(INT_TIMER0B); //-------------Set Pins ---------------------------// ROM_GPIOPinTypeGPIOOutput(GPIO_PORTM_BASE, GPIO_PIN_4); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTM_BASE, GPIO_PIN_5); ROM_GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_4 | GPIO_PIN_5); ROM_GPIOPinTypeUART(GPIO_PORTJ_BASE, GPIO_PIN_0 | GPIO_PIN_1); ROM_GPIOPinConfigure(GPIO_PC4_U7RX); ROM_GPIOPinConfigure(GPIO_PC5_U7TX); ROM_GPIOPinConfigure(GPIO_PJ0_U3RX); ROM_GPIOPinConfigure(GPIO_PJ1_U3TX); ROM_UARTConfigSetExpClk(UART3_BASE, g_ui32SysClock, 1000000, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE| UART_CONFIG_PAR_NONE)); ROM_UARTConfigSetExpClk(UART7_BASE, g_ui32SysClock, 1000000, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); ROM_TimerEnable(TIMER0_BASE, TIMER_B); ROM_UARTEnable(UART3_BASE); ROM_UARTEnable(UART7_BASE); ROM_GPIOPinWrite(GPIO_PORTM_BASE, GPIO_PIN_4, GPIO_PIN_4); ROM_IntMasterEnable(); uart_parser_payload_write_pos = 0; uart_parser_state = RX_PREABLE0; char write_buf[2]; char* w_buf = write_buf; g_ui32Counter = 0; // ---------------------MAIN LOOP -----------------------------------// while(1) { DymxlReadDataBlocking(36,2,1); // need to turn timer off eventually state =!state; if(state) ROM_GPIOPinWrite(GPIO_PORTM_BASE, GPIO_PIN_4| GPIO_PIN_5, GPIO_PIN_4); else ROM_GPIOPinWrite(GPIO_PORTM_BASE, GPIO_PIN_4| GPIO_PIN_5, GPIO_PIN_5); } return 0; }
//***************************************************************************** // // Main 'C' Language entry point. // //***************************************************************************** int main(void) { float fAmbient; int32_t i32IntegerPart, i32FractionPart; uint8_t ui8Mask; // // Setup the system clock to run at 40 Mhz from PLL with crystal reference // ROM_SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); // // Enable the peripherals used by this example. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); // // Initialize the UART and its pins. // ConfigureUART(); // // Print the welcome message to the terminal. // UARTprintf("\033[2JISL29023 Example\n"); // // Set the color to a white approximation. // g_pui32Colors[RED] = 0x8000; g_pui32Colors[BLUE] = 0x8000; g_pui32Colors[GREEN] = 0x8000; // // Initialize RGB driver. Use a default intensity and blink rate. // RGBInit(0); RGBColorSet(g_pui32Colors); RGBIntensitySet(0.5f); RGBEnable(); // // The I2C3 peripheral must be enabled before use. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C3); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); // // Configure the pin muxing for I2C3 functions on port D0 and D1. // This step is not necessary if your part does not support pin muxing. // ROM_GPIOPinConfigure(GPIO_PD0_I2C3SCL); ROM_GPIOPinConfigure(GPIO_PD1_I2C3SDA); // // Select the I2C function for these pins. This function will also // configure the GPIO pins pins for I2C operation, setting them to // open-drain operation with weak pull-ups. Consult the data sheet // to see which functions are allocated per pin. // GPIOPinTypeI2CSCL(GPIO_PORTD_BASE, GPIO_PIN_0); ROM_GPIOPinTypeI2C(GPIO_PORTD_BASE, GPIO_PIN_1); // // Configure and Enable the GPIO interrupt. Used for INT signal from the // ISL29023 // ROM_GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_5); GPIOIntEnable(GPIO_PORTE_BASE, GPIO_PIN_5); ROM_GPIOIntTypeSet(GPIO_PORTE_BASE, GPIO_PIN_5, GPIO_FALLING_EDGE); ROM_IntEnable(INT_GPIOE); // // Keep only some parts of the systems running while in sleep mode. // GPIOE is for the ISL29023 interrupt pin. // UART0 is the virtual serial port // TIMER0, TIMER1 and WTIMER5 are used by the RGB driver // I2C3 is the I2C interface to the ISL29023 // ROM_SysCtlPeripheralClockGating(true); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOE); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART0); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_TIMER0); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_TIMER1); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_I2C3); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_WTIMER5); // // Configure desired interrupt priorities. Setting the I2C interrupt to be // of more priority than SysTick and the GPIO interrupt means those // interrupt routines can use the I2CM_DRV Application context does not use // I2CM_DRV API and GPIO and SysTick are at the same priority level. This // prevents re-entrancy problems with I2CM_DRV but keeps the MCU in sleep // state as much as possible. UART is at least priority so it can operate // in the background. // ROM_IntPrioritySet(INT_I2C3, 0x00); ROM_IntPrioritySet(FAULT_SYSTICK, 0x40); ROM_IntPrioritySet(INT_GPIOE, 0x80); ROM_IntPrioritySet(INT_UART0, 0x80); // // Enable interrupts to the processor. // ROM_IntMasterEnable(); // // Initialize I2C3 peripheral. // I2CMInit(&g_sI2CInst, I2C3_BASE, INT_I2C3, 0xff, 0xff, ROM_SysCtlClockGet()); // // Initialize the ISL29023 Driver. // ISL29023Init(&g_sISL29023Inst, &g_sI2CInst, ISL29023_I2C_ADDRESS, ISL29023AppCallback, &g_sISL29023Inst); // // Wait for transaction to complete // ISL29023AppI2CWait(__FILE__, __LINE__); // // Configure the ISL29023 to measure ambient light continuously. Set a 8 // sample persistence before the INT pin is asserted. Clears the INT flag. // Persistence setting of 8 is sufficient to ignore camera flashes. // ui8Mask = (ISL29023_CMD_I_OP_MODE_M | ISL29023_CMD_I_INT_PERSIST_M | ISL29023_CMD_I_INT_FLAG_M); ISL29023ReadModifyWrite(&g_sISL29023Inst, ISL29023_O_CMD_I, ~ui8Mask, (ISL29023_CMD_I_OP_MODE_ALS_CONT | ISL29023_CMD_I_INT_PERSIST_8), ISL29023AppCallback, &g_sISL29023Inst); // // Wait for transaction to complete // ISL29023AppI2CWait(__FILE__, __LINE__); // // Configure the upper threshold to 80% of maximum value // g_sISL29023Inst.pui8Data[1] = 0xCC; g_sISL29023Inst.pui8Data[2] = 0xCC; ISL29023Write(&g_sISL29023Inst, ISL29023_O_INT_HT_LSB, g_sISL29023Inst.pui8Data, 2, ISL29023AppCallback, &g_sISL29023Inst); // // Wait for transaction to complete // ISL29023AppI2CWait(__FILE__, __LINE__); // // Configure the lower threshold to 20% of maximum value // g_sISL29023Inst.pui8Data[1] = 0x33; g_sISL29023Inst.pui8Data[2] = 0x33; ISL29023Write(&g_sISL29023Inst, ISL29023_O_INT_LT_LSB, g_sISL29023Inst.pui8Data, 2, ISL29023AppCallback, &g_sISL29023Inst); // // Wait for transaction to complete // ISL29023AppI2CWait(__FILE__, __LINE__); // //Configure and enable SysTick Timer // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND); ROM_SysTickIntEnable(); ROM_SysTickEnable(); // // After all the init and config we start blink the LED // RGBBlinkRateSet(1.0f); // // Loop Forever // while(1) { ROM_SysCtlSleep(); if(g_vui8DataFlag) { g_vui8DataFlag = 0; // // Get a local floating point copy of the latest light data // ISL29023DataLightVisibleGetFloat(&g_sISL29023Inst, &fAmbient); // // Perform the conversion from float to a printable set of integers // i32IntegerPart = (int32_t)fAmbient; i32FractionPart = (int32_t)(fAmbient * 1000.0f); i32FractionPart = i32FractionPart - (i32IntegerPart * 1000); if(i32FractionPart < 0) { i32FractionPart *= -1; } // // Print the temperature as integer and fraction parts. // UARTprintf("Visible Lux: %3d.%03d\n", i32IntegerPart, i32FractionPart); // // Check if the intensity of light has crossed a threshold. If so // then adjust range of sensor readings to track intensity. // if(g_vui8IntensityFlag) { // // Disable the low priority interrupts leaving only the I2C // interrupt enabled. // ROM_IntPriorityMaskSet(0x40); // // Reset the intensity trigger flag. // g_vui8IntensityFlag = 0; // // Adjust the lux range. // ISL29023AppAdjustRange(&g_sISL29023Inst); // // Now we must manually clear the flag in the ISL29023 // register. // ISL29023Read(&g_sISL29023Inst, ISL29023_O_CMD_I, g_sISL29023Inst.pui8Data, 1, ISL29023AppCallback, &g_sISL29023Inst); // // Wait for transaction to complete // ISL29023AppI2CWait(__FILE__, __LINE__); // // Disable priority masking so all interrupts are enabled. // ROM_IntPriorityMaskSet(0); } } } }
void timers_init(void) { unsigned long ulDACPeriod, ulPktPeriod, ulTempoPeriod, ulPollPeriod; // Initialise the output buffer int i; for (i = 0; i < BUFFER_SIZE; i++) { oBuff[i] = 0x8000; } // Open file pointers for (i = 0; i < 16; i++) { sdcard_openFile(&fPtrs[i], i); } // Configure the Tempo LED ROM_GPIOPinTypeGPIOOutput(LED_TEMPO); ROM_GPIOPinWrite(LED_TEMPO, 0x00); // Configure the DAC output timer - Timer 0 ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); ulDACPeriod = (ROM_SysCtlClockGet() / 44100); // 44.1 kHz for DAC samples ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, ulDACPeriod); // Set up interrupt ROM_IntPrioritySet(INT_TIMER0A, 0x00); ROM_IntEnable(INT_TIMER0A); ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); // Enable Timer ROM_TimerEnable(TIMER0_BASE, TIMER_A); // Configure the SD Card buffer timer - Timer 1 ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); ROM_TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC); ulPktPeriod = (ROM_SysCtlClockGet() / BUFFERUPDATE_FREQ); // 100 Hz for DAC samples ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, ulPktPeriod); // Set up interrupt ROM_IntPrioritySet(INT_TIMER1A, 0x40); ROM_IntEnable(INT_TIMER1A); ROM_TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT); // Enable Timer ROM_TimerEnable(TIMER1_BASE, TIMER_A); // Configure the Tempo timer - Timer 2 ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2); ROM_TimerConfigure(TIMER2_BASE, TIMER_CFG_PERIODIC); ulTempoPeriod = (ROM_SysCtlClockGet() / TEMPO_FREQUENCY); ROM_TimerLoadSet(TIMER2_BASE, TIMER_A, ulTempoPeriod); // Set up interrupt ROM_IntPrioritySet(INT_TIMER2A, 0x20); ROM_IntEnable(INT_TIMER2A); ROM_TimerIntEnable(TIMER2_BASE, TIMER_TIMA_TIMEOUT); // Enable Timer ROM_TimerEnable(TIMER2_BASE, TIMER_A); // Configure the poll timer ulPollPeriod = (ROM_SysCtlClockGet() / POLL_FREQUENCY); ROM_TimerLoadSet(TIMER2_BASE, TIMER_B, ulPollPeriod); // Set up interrupt ROM_IntPrioritySet(INT_TIMER2B, 0x20); ROM_IntEnable(INT_TIMER2B); ROM_TimerIntEnable(TIMER2_BASE, TIMER_TIMB_TIMEOUT); // Enable Timer ROM_TimerEnable(TIMER2_BASE, TIMER_B); }