bool initializeUartChannel(uint8_t channel, uint8_t uartPort, uint32_t baudRate, uint32_t cpuSpeedHz, uint32_t flags) { if (channel >= UART_NUMBER_OF_CHANNELS || uartPort >= UART_COUNT) { return false; } if (uart2UartChannelData[uartPort] != 0) { return false; } if (!(flags & UART_FLAGS_RECEIVE) && !(flags & UART_FLAGS_SEND)) { return false; } uint32_t uartBase; uint32_t uartInterruptId; uint32_t uartPeripheralSysCtl; switch (uartPort) { #ifdef DEBUG case UART_0: { uartBase = UART0_BASE; uartInterruptId = INT_UART0; uartPeripheralSysCtl = SYSCTL_PERIPH_UART0; ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); ROM_GPIOPinConfigure(GPIO_PA0_U0RX); ROM_GPIOPinConfigure(GPIO_PA1_U0TX); ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); break; } #endif case UART_1: { uartBase = UART1_BASE; uartInterruptId = INT_UART1; uartPeripheralSysCtl = SYSCTL_PERIPH_UART1; ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1); ROM_GPIOPinConfigure(GPIO_PB0_U1RX); ROM_GPIOPinConfigure(GPIO_PB1_U1TX); ROM_GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1); break; } case UART_2: { uartBase = UART2_BASE; uartInterruptId = INT_UART2; uartPeripheralSysCtl = SYSCTL_PERIPH_UART2; ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART2); ROM_GPIOPinConfigure(GPIO_PD6_U2RX); ROM_GPIOPinConfigure(GPIO_PD7_U2TX); ROM_GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_6 | GPIO_PIN_7); break; } case UART_3: { uartBase = UART3_BASE; uartInterruptId = INT_UART3; uartPeripheralSysCtl = SYSCTL_PERIPH_UART3; ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART3); ROM_GPIOPinConfigure(GPIO_PC6_U3RX); ROM_GPIOPinConfigure(GPIO_PC7_U3TX); ROM_GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_6 | GPIO_PIN_7); break; } case UART_4: { uartBase = UART4_BASE; uartInterruptId = INT_UART4; uartPeripheralSysCtl = SYSCTL_PERIPH_UART4; ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART4); ROM_GPIOPinConfigure(GPIO_PC4_U4RX); ROM_GPIOPinConfigure(GPIO_PC5_U4TX); ROM_GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_4 | GPIO_PIN_5); break; } default: { return false; } } UARTClockSourceSet(uartBase, UART_CLOCK_PIOSC); if(!MAP_SysCtlPeripheralPresent(uartPeripheralSysCtl)) { return false; } MAP_SysCtlPeripheralEnable(uartPeripheralSysCtl); MAP_UARTConfigSetExpClk(uartBase, cpuSpeedHz, baudRate, (UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_ONE | UART_CONFIG_WLEN_8)); MAP_UARTFIFOLevelSet(uartBase, UART_FIFO_TX1_8, UART_FIFO_RX1_8); MAP_UARTIntDisable(uartBase, 0xFFFFFFFF); if (flags & UART_FLAGS_RECEIVE) { MAP_UARTIntEnable(uartBase, UART_INT_RX | UART_INT_RT); } if (flags & UART_FLAGS_SEND) { MAP_UARTIntEnable(uartBase, UART_INT_TX); } MAP_IntEnable(uartInterruptId); MAP_UARTEnable(uartBase); uartChannelData[channel].base = uartBase; uartChannelData[channel].interruptId = uartInterruptId; uartChannelData[channel].writeBuffer.isEmpty = true; uart2UartChannelData[uartPort] = &uartChannelData[channel]; return true; }
int main(void) { // setup the system clock to run at 80 MHz from the external crystal: ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // enable peripherals to operate when CPU is in sleep: ROM_SysCtlPeripheralClockGating(true); // enable all of the GPIOs: ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOA); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOB); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOC); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOD); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOE); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOF); // setup pins connected to RGB LED: ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3); //setup the UART console InitConsole(); // Test either the interrupts on a simple pushbutton to turn-on a led: // 1- interrupt with static allocation on the vector table // 2- interrupt with dynamic allocation on the vector table // 2- interrupt with dynamic allocation on the vector table // setup pin connected to SW1 and SW2 // Unlock PF0 so we can change it to a GPIO input // Once we have enabled (unlocked) the commit register then re-lock it // to prevent further changes. PF0 is muxed with NMI thus a special case. HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY; HWREG(GPIO_PORTF_BASE + GPIO_O_CR) |= 0x01; HWREG(GPIO_PORTF_BASE + GPIO_O_AFSEL) |= 0x000; HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = 0; //Configures pin(s) for use as GPIO inputs ROM_GPIOPinTypeGPIOInput(GPIO_PORTF_BASE,GPIO_PIN_4 | GPIO_PIN_0); //Sets the pad configuration for the specified pin(s). ROM_GPIOPadConfigSet(GPIO_PORTF_BASE,GPIO_PIN_4 | GPIO_PIN_0,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU); // Make PORT F pin 0,4 high level triggered interrupts. ROM_GPIOIntTypeSet(GPIO_PORTF_BASE,GPIO_PIN_4 | GPIO_PIN_0,GPIO_BOTH_EDGES); //dynamic allocation on the vector table of GPIO_PORTF_isr interrupt handler GPIOIntRegister(GPIO_PORTF_BASE, GPIO_PORTF_isr); //Enables the specified GPIO interrupt IntEnable(INT_GPIOF); GPIOIntEnable(GPIO_PORTF_BASE,GPIO_INT_PIN_4 | GPIO_INT_PIN_0); IntMasterEnable(); uint8_t PORTF_status; //uint32_t ui32Loop = 0; // // Loop forever // while(1) { uint8_t PORTF_status=GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_0 | GPIO_PIN_4); /* if(GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_4)) { ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 ,0); } else { ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 , GPIO_PIN_1); } */ /* // // Turn on the red LED . // ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 , GPIO_PIN_1); ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_7, GPIO_PIN_7); // // Delay for a bit. // for(ui32Loop = 0; ui32Loop < 2000000; ui32Loop++) { } // // Turn on the green LED. // ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 , GPIO_PIN_2); ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_7, 0); // // Delay for a bit. // for(ui32Loop = 0; ui32Loop < 2000000; ui32Loop++) { } // // Turn on the blue LED. // ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 , GPIO_PIN_3); // // Delay for a bit. // for(ui32Loop = 0; ui32Loop < 2000000; ui32Loop++) { } */ } }
//***************************************************************************** // // This example encrypts blocks of plaintext using TDES in CBC mode. It // does the encryption first without uDMA and then with uDMA. The results // are checked after each operation. // //***************************************************************************** int main(void) { uint32_t pui32CipherText[16], ui32Errors, ui32Idx, 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(false, false); // // Initialize local variables. // ui32Errors = 0; for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { pui32CipherText[ui32Idx] = 0; } // // Enable stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // ROM_FPUStackingEnable(); // // Enable DES interrupts. // ROM_IntEnable(INT_DES0); // // Enable debug output on UART0 and print a welcome message. // ConfigureUART(); UARTprintf("Starting TDES CBC encryption demo.\n"); // // Enable the uDMA module. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); // // Setup the control table. // ROM_uDMAEnable(); ROM_uDMAControlBaseSet(g_psDMAControlTable); // // Initialize the CCM and DES modules. // if(!DESInit()) { UARTprintf("Initialization of the DES module failed.\n"); ui32Errors |= 0x00000001; } // // Perform the encryption without uDMA. // UARTprintf("Performing encryption without uDMA.\n"); TDESCBCEncrypt(g_pui32TDESPlainText, pui32CipherText, g_pui32TDESKey, 64, g_pui32TDESIV, false); // // Check the result. // for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { if(pui32CipherText[ui32Idx] != g_pui32TDESCipherText[ui32Idx]) { UARTprintf("Ciphertext mismatch on word %d. Exp: 0x%x, Act: " "0x%x\n", ui32Idx, g_pui32TDESCipherText[ui32Idx], pui32CipherText[ui32Idx]); ui32Errors |= (ui32Idx << 16) | 0x00000002; } } // // Clear the array containing the ciphertext. // for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { pui32CipherText[ui32Idx] = 0; } // // Perform the encryption with uDMA. // UARTprintf("Performing encryption with uDMA.\n"); TDESCBCEncrypt(g_pui32TDESPlainText, pui32CipherText, g_pui32TDESKey, 64, g_pui32TDESIV, true); // // Check the result. // for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { if(pui32CipherText[ui32Idx] != g_pui32TDESCipherText[ui32Idx]) { UARTprintf("Ciphertext mismatch on word %d. Exp: 0x%x, Act: " "0x%x\n", ui32Idx, g_pui32TDESCipherText[ui32Idx], pui32CipherText[ui32Idx]); ui32Errors |= (ui32Idx << 16) | 0x00000004; } } // // Finished. // if(ui32Errors) { UARTprintf("Demo failed with error code 0x%x.\n", ui32Errors); LEDWrite(CLP_D3 | CLP_D4, CLP_D4); } else { UARTprintf("Demo completed successfully.\n"); LEDWrite(CLP_D3 | CLP_D4, CLP_D3); } while(1) { } }
//***************************************************************************** // // Initializes the UART1 peripheral and sets up the TX and RX uDMA channels. // The UART is configured for loopback mode so that any data sent on TX will be // received on RX. The uDMA channels are configured so that the TX channel // will copy data from a buffer to the UART TX output. And the uDMA RX channel // will receive any incoming data into a pair of buffers in ping-pong mode. // //***************************************************************************** void InitUART1Transfer(void) { unsigned int uIdx; // // Fill the TX buffer with a simple data pattern. // for(uIdx = 0; uIdx < UART_TXBUF_SIZE; uIdx++) { g_ui8TxBuf[uIdx] = uIdx; } // // Enable the UART peripheral, and configure it to operate even if the CPU // is in sleep. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART1); // // Configure the UART communication parameters. // ROM_UARTConfigSetExpClk(UART1_BASE, ROM_SysCtlClockGet(), 115200, UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE); // // Set both the TX and RX trigger thresholds to 4. This will be used by // the uDMA controller to signal when more data should be transferred. The // uDMA TX and RX channels will be configured so that it can transfer 4 // bytes in a burst when the UART is ready to transfer more data. // ROM_UARTFIFOLevelSet(UART1_BASE, UART_FIFO_TX4_8, UART_FIFO_RX4_8); // // Enable the UART for operation, and enable the uDMA interface for both TX // and RX channels. // ROM_UARTEnable(UART1_BASE); ROM_UARTDMAEnable(UART1_BASE, UART_DMA_RX | UART_DMA_TX); // // This register write will set the UART to operate in loopback mode. Any // data sent on the TX output will be received on the RX input. // HWREG(UART1_BASE + UART_O_CTL) |= UART_CTL_LBE; // // Enable the UART peripheral interrupts. Note that no UART interrupts // were enabled, but the uDMA controller will cause an interrupt on the // UART interrupt signal when a uDMA transfer is complete. // ROM_IntEnable(INT_UART1); // // Put the attributes in a known state for the uDMA UART1RX channel. These // should already be disabled by default. // ROM_uDMAChannelAttributeDisable(UDMA_CHANNEL_UART1RX, UDMA_ATTR_ALTSELECT | UDMA_ATTR_USEBURST | UDMA_ATTR_HIGH_PRIORITY | UDMA_ATTR_REQMASK); // // Configure the control parameters for the primary control structure for // the UART RX channel. The primary contol structure is used for the "A" // part of the ping-pong receive. The transfer data size is 8 bits, the // source address does not increment since it will be reading from a // register. The destination address increment is byte 8-bit bytes. The // arbitration size is set to 4 to match the RX FIFO trigger threshold. // The uDMA controller will use a 4 byte burst transfer if possible. This // will be somewhat more effecient that single byte transfers. // ROM_uDMAChannelControlSet(UDMA_CHANNEL_UART1RX | UDMA_PRI_SELECT, UDMA_SIZE_8 | UDMA_SRC_INC_NONE | UDMA_DST_INC_8 | UDMA_ARB_4); // // Configure the control parameters for the alternate control structure for // the UART RX channel. The alternate contol structure is used for the "B" // part of the ping-pong receive. The configuration is identical to the // primary/A control structure. // ROM_uDMAChannelControlSet(UDMA_CHANNEL_UART1RX | UDMA_ALT_SELECT, UDMA_SIZE_8 | UDMA_SRC_INC_NONE | UDMA_DST_INC_8 | UDMA_ARB_4); // // Set up the transfer parameters for the UART RX primary control // structure. The mode is set to ping-pong, the transfer source is the // UART data register, and the destination is the receive "A" buffer. The // transfer size is set to match the size of the buffer. // ROM_uDMAChannelTransferSet(UDMA_CHANNEL_UART1RX | UDMA_PRI_SELECT, UDMA_MODE_PINGPONG, (void *)(UART1_BASE + UART_O_DR), g_ui8RxBufA, sizeof(g_ui8RxBufA)); // // Set up the transfer parameters for the UART RX alternate control // structure. The mode is set to ping-pong, the transfer source is the // UART data register, and the destination is the receive "B" buffer. The // transfer size is set to match the size of the buffer. // ROM_uDMAChannelTransferSet(UDMA_CHANNEL_UART1RX | UDMA_ALT_SELECT, UDMA_MODE_PINGPONG, (void *)(UART1_BASE + UART_O_DR), g_ui8RxBufB, sizeof(g_ui8RxBufB)); // // Put the attributes in a known state for the uDMA UART1TX channel. These // should already be disabled by default. // ROM_uDMAChannelAttributeDisable(UDMA_CHANNEL_UART1TX, UDMA_ATTR_ALTSELECT | UDMA_ATTR_HIGH_PRIORITY | UDMA_ATTR_REQMASK); // // Set the USEBURST attribute for the uDMA UART TX channel. This will // force the controller to always use a burst when transferring data from // the TX buffer to the UART. This is somewhat more effecient bus usage // than the default which allows single or burst transfers. // ROM_uDMAChannelAttributeEnable(UDMA_CHANNEL_UART1TX, UDMA_ATTR_USEBURST); // // Configure the control parameters for the UART TX. The uDMA UART TX // channel is used to transfer a block of data from a buffer to the UART. // The data size is 8 bits. The source address increment is 8-bit bytes // since the data is coming from a buffer. The destination increment is // none since the data is to be written to the UART data register. The // arbitration size is set to 4, which matches the UART TX FIFO trigger // threshold. // ROM_uDMAChannelControlSet(UDMA_CHANNEL_UART1TX | UDMA_PRI_SELECT, UDMA_SIZE_8 | UDMA_SRC_INC_8 | UDMA_DST_INC_NONE | UDMA_ARB_4); // // Set up the transfer parameters for the uDMA UART TX channel. This will // configure the transfer source and destination and the transfer size. // Basic mode is used because the peripheral is making the uDMA transfer // request. The source is the TX buffer and the destination is the UART // data register. // ROM_uDMAChannelTransferSet(UDMA_CHANNEL_UART1TX | UDMA_PRI_SELECT, UDMA_MODE_BASIC, g_ui8TxBuf, (void *)(UART1_BASE + UART_O_DR), sizeof(g_ui8TxBuf)); // // Now both the uDMA UART TX and RX channels are primed to start a // transfer. As soon as the channels are enabled, the peripheral will // issue a transfer request and the data transfers will begin. // ROM_uDMAChannelEnable(UDMA_CHANNEL_UART1RX); ROM_uDMAChannelEnable(UDMA_CHANNEL_UART1TX); }
//***************************************************************************** // // This is the main loop that runs the application. // //***************************************************************************** int main(void) { // // Set the clocking to run from the PLL at 50MHz. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Enable 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[2JMouse device application\n"); // // Set the system tick to fire 100 times per second. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND); ROM_SysTickIntEnable(); ROM_SysTickEnable(); // // Set the USB stack mode to Device mode with VBUS monitoring. // USBStackModeSet(0, USB_MODE_DEVICE, 0); // // Pass the USB library our device information, initialize the USB // controller and connect the device to the bus. // USBDHIDMouseInit(0, (tUSBDHIDMouseDevice *)&g_sMouseDevice); // // Drop into the main loop. // while(1) { // // Tell the user what we are doing. // UARTprintf("Waiting for host...\n"); // // Wait for USB configuration to complete. // while(!g_bConnected) { } // // Update the status. // UARTprintf("Host connected...\n"); // // Now keep processing the mouse as long as the host is connected. // while(g_bConnected) { // // If it is time to move the mouse then do so. // if(HWREGBITW(&g_ulCommands, TICK_EVENT) == 1) { HWREGBITW(&g_ulCommands, TICK_EVENT) = 0; MoveHandler(); } } // // Update the status. // UARTprintf("Host disconnected...\n"); } }
//**************************************************************************** // // This is the main loop that runs the application. // //**************************************************************************** int main(void) { // // Set the clocking to run from the PLL at 50MHz. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | 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(); // // Configure and enable uDMA // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); SysCtlDelay(10); ROM_uDMAControlBaseSet(&sDMAControlTable[0]); ROM_uDMAEnable(); // // Initialize the idle timeout and reset all flags. // g_ulIdleTimeout = 0; g_ulFlags = 0; g_eMSCState = MSC_DEV_DISCONNECTED; // // Pass the USB library our device information, initialize the USB // controller and connect the device to the bus. // g_psCompDevices[0].pvInstance = USBDMSCInit(0, (tUSBDMSCDevice *)&g_sMSCDevice); g_psCompDevices[1].pvInstance = USBDCDCCompositeInit(0, (tUSBDCDCDevice *)&g_sCDCDevice); // // Set the USB stack mode to Device mode with VBUS monitoring. // USBStackModeSet(0, USB_MODE_DEVICE, 0); // // Pass the device information to the USB library and place the device // on the bus. // USBDCompositeInit(0, &g_sCompDevice, DESCRIPTOR_DATA_SIZE, g_pucDescriptorData); SerialInit(); disk_initialize(0); // // Drop into the main loop. // while(1) { // // Allow the main serial routine to run. // SerialMain(); switch(g_eMSCState) { case MSC_DEV_READ: { // // Update the screen if necessary. // if(g_ulFlags & FLAG_UPDATE_STATUS) { g_ulFlags &= ~FLAG_UPDATE_STATUS; } // // If there is no activity then return to the idle state. // if(g_ulIdleTimeout == 0) { g_eMSCState = MSC_DEV_IDLE; } break; } case MSC_DEV_WRITE: { // // Update the screen if necessary. // if(g_ulFlags & FLAG_UPDATE_STATUS) { g_ulFlags &= ~FLAG_UPDATE_STATUS; } // // If there is no activity then return to the idle state. // if(g_ulIdleTimeout == 0) { g_eMSCState = MSC_DEV_IDLE; } break; } case MSC_DEV_DISCONNECTED: { // // Update the screen if necessary. // if(g_ulFlags & FLAG_UPDATE_STATUS) { g_ulFlags &= ~FLAG_UPDATE_STATUS; } break; } case MSC_DEV_IDLE: { break; } default: { break; } } } }
//***************************************************************************** // // This example application demonstrates the use of the timers to generate // periodic interrupts. // //***************************************************************************** int main(void) { tRectangle sRect; // // 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); // // 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, "timers", -1, GrContextDpyWidthGet(&g_sContext) / 2, 4, 0); // // Initialize timer status display. // GrContextFontSet(&g_sContext, g_psFontFixed6x8); GrStringDraw(&g_sContext, "Timer 0:", -1, 16, 26, 0); GrStringDraw(&g_sContext, "Timer 1:", -1, 16, 36, 0); // // Enable the peripherals used by this example. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); // // Enable processor interrupts. // ROM_IntMasterEnable(); // // Configure the two 32-bit periodic timers. // ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); ROM_TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC); ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, ROM_SysCtlClockGet()); ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, ROM_SysCtlClockGet() / 2); // // Setup the interrupts for the timer timeouts. // ROM_IntEnable(INT_TIMER0A); ROM_IntEnable(INT_TIMER1A); ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT); // // Enable the timers. // ROM_TimerEnable(TIMER0_BASE, TIMER_A); ROM_TimerEnable(TIMER1_BASE, TIMER_A); // // Loop forever while the timers run. // while(1) { } }
//***************************************************************************** // // This example encrypts blocks ciphertext using AES128 in GCM mode. It // does the encryption first without uDMA and then with uDMA. The results // are checked after each operation. // //***************************************************************************** int main(void) { uint32_t pui32CipherText[64], pui32Tag[4], pui32Y0[4], ui32Errors, ui32Idx; uint32_t *pui32Key, ui32IVLength, *pui32IV, ui32DataLength; uint32_t *pui32ExpCipherText, ui32AuthDataLength, *pui32AuthData; uint32_t *pui32PlainText, *pui32ExpTag; uint8_t ui8Vector; uint32_t ui32KeySize; uint32_t ui32SysClock; tContext sContext; // // 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(&sContext, &g_sKentec320x240x16_SSD2119); // // Draw the application frame. // FrameDraw(&sContext, "aes-gcm-encrypt"); // // Show some instructions on the display // GrContextFontSet(&sContext, g_psFontCm20); GrContextForegroundSet(&sContext, ClrWhite); GrStringDrawCentered(&sContext, "Connect a terminal to", -1, GrContextDpyWidthGet(&sContext) / 2, 60, false); GrStringDrawCentered(&sContext, "UART0 (115200,N,8,1)", -1, GrContextDpyWidthGet(&sContext) / 2, 80, false); GrStringDrawCentered(&sContext, "for more information.", -1, GrContextDpyWidthGet(&sContext) / 2, 100, false); // // Initialize local variables. // ui32Errors = 0; for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { pui32CipherText[ui32Idx] = 0; } for(ui32Idx = 0; ui32Idx < 4; ui32Idx++) { pui32Tag[ui32Idx] = 0; } // // Enable stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // ROM_FPUStackingEnable(); // // Enable AES interrupts. // ROM_IntEnable(INT_AES0); // // Enable debug output on UART0 and print a welcome message. // ConfigureUART(); UARTprintf("Starting AES GCM encryption demo.\n"); GrStringDrawCentered(&sContext, "Starting demo...", -1, GrContextDpyWidthGet(&sContext) / 2, 140, false); // // Enable the uDMA module. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); // // Setup the control table. // ROM_uDMAEnable(); ROM_uDMAControlBaseSet(g_psDMAControlTable); // // Initialize the CCM and AES modules. // if(!AESInit()) { UARTprintf("Initialization of the AES module failed.\n"); ui32Errors |= 0x00000001; } // // Loop through all the given vectors. // for(ui8Vector = 0; (ui8Vector < (sizeof(g_psAESGCMTestVectors) / sizeof(g_psAESGCMTestVectors[0]))) && (ui32Errors == 0); ui8Vector++) { UARTprintf("Starting vector #%d\n", ui8Vector); // // Get the current vector's data members. // ui32KeySize = g_psAESGCMTestVectors[ui8Vector].ui32KeySize; pui32Key = g_psAESGCMTestVectors[ui8Vector].pui32Key; ui32IVLength = g_psAESGCMTestVectors[ui8Vector].ui32IVLength; pui32IV = g_psAESGCMTestVectors[ui8Vector].pui32IV; ui32DataLength = g_psAESGCMTestVectors[ui8Vector].ui32DataLength; pui32PlainText = g_psAESGCMTestVectors[ui8Vector].pui32PlainText; ui32AuthDataLength = g_psAESGCMTestVectors[ui8Vector].ui32AuthDataLength; pui32AuthData = g_psAESGCMTestVectors[ui8Vector].pui32AuthData; pui32ExpCipherText = g_psAESGCMTestVectors[ui8Vector].pui32CipherText; pui32ExpTag = g_psAESGCMTestVectors[ui8Vector].pui32Tag; // // If both the data lengths are zero, then it's a special case. // if((ui32DataLength == 0) && (ui32AuthDataLength == 0)) { UARTprintf("Performing encryption without uDMA.\n"); // // Figure out the value of Y0 depending on the IV length. // AESGCMY0Get(ui32KeySize, pui32IV, ui32IVLength, pui32Key, pui32Y0); // // Perform the basic encryption. // AESECBEncrypt(ui32KeySize, pui32Y0, pui32Tag, pui32Key, 16); } else { // // Figure out the value of Y0 depending on the IV length. // AESGCMY0Get(ui32KeySize, pui32IV, ui32IVLength, pui32Key, pui32Y0); // // Perform the encryption without uDMA. // UARTprintf("Performing encryption without uDMA.\n"); AESGCMEncrypt(ui32KeySize, pui32PlainText, pui32CipherText, ui32DataLength, pui32Key, pui32Y0, pui32AuthData, ui32AuthDataLength, pui32Tag, false); } // // Check the results. // for(ui32Idx = 0; ui32Idx < (ui32DataLength / 4); ui32Idx++) { if(pui32ExpCipherText[ui32Idx] != pui32CipherText[ui32Idx]) { UARTprintf("Ciphertext mismatch on word %d. Exp: 0x%x, Act: " "0x%x\n", ui32Idx, pui32ExpCipherText[ui32Idx], pui32CipherText[ui32Idx]); ui32Errors |= (ui32Idx << 16) | 0x00000002; } } for(ui32Idx = 0; ui32Idx < 4; ui32Idx++) { if(pui32ExpTag[ui32Idx] != pui32Tag[ui32Idx]) { UARTprintf("Tag mismatch on word %d. Exp: 0x%x, Act: 0x%x\n", ui32Idx, pui32ExpTag[ui32Idx], pui32Tag[ui32Idx]); ui32Errors |= (ui32Idx << 16) | 0x00000003; } } // // Clear the arrays containing the ciphertext and tag to ensure things // are working correctly. // for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { pui32CipherText[ui32Idx] = 0; } for(ui32Idx = 0; ui32Idx < 4; ui32Idx++) { pui32Tag[ui32Idx] = 0; } // // Only use DMA with the vectors that have data. // if((ui32DataLength != 0) || (ui32AuthDataLength != 0)) { // // Perform the encryption with uDMA. // UARTprintf("Performing encryption with uDMA.\n"); AESGCMEncrypt(ui32KeySize, pui32PlainText, pui32CipherText, ui32DataLength, pui32Key, pui32Y0, pui32AuthData, ui32AuthDataLength, pui32Tag, true); // // Check the result. // for(ui32Idx = 0; ui32Idx < (ui32DataLength / 4); ui32Idx++) { if(pui32ExpCipherText[ui32Idx] != pui32CipherText[ui32Idx]) { UARTprintf("Ciphertext mismatch on word %d. Exp: 0x%x, " "Act: 0x%x\n", ui32Idx, pui32ExpCipherText[ui32Idx], pui32CipherText[ui32Idx]); ui32Errors |= (ui32Idx << 16) | 0x00000002; } } for(ui32Idx = 0; ui32Idx < 4; ui32Idx++) { if(pui32ExpTag[ui32Idx] != pui32Tag[ui32Idx]) { UARTprintf("Tag mismatch on word %d. Exp: 0x%x, Act: " "0x%x\n", ui32Idx, pui32ExpTag[ui32Idx], pui32Tag[ui32Idx]); ui32Errors |= (ui32Idx << 16) | 0x00000003; } } } } // // Finished. // if(ui32Errors) { UARTprintf("Demo failed with error code 0x%x.\n", ui32Errors); GrStringDrawCentered(&sContext, "Demo failed.", -1, GrContextDpyWidthGet(&sContext) / 2, 180, false); } else { UARTprintf("Demo completed successfully.\n"); GrStringDrawCentered(&sContext, "Demo passed.", -1, GrContextDpyWidthGet(&sContext) / 2, 180, false); } // // Wait forever. // while(1) { } }
//***************************************************************************** // // Print "Hello World!" to the UART on the evaluation board. // //***************************************************************************** int main(void) { //volatile 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 directly from the crystal. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); // // 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_2); // // Initialize the UART. // ConfigureUART(); // // Hello! // UARTprintf("Hello, world!\n"); // // We are finished. Hang around doing nothing. // while(1) { // // Turn on the BLUE LED. // GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2); // // Delay for a bit. // SysCtlDelay(SysCtlClockGet() / 10 / 3); // // Turn off the BLUE LED. // GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0); // // Delay for a bit. // SysCtlDelay(SysCtlClockGet() / 10 / 3); } }
//***************************************************************************** // // Demonstrate the use of the USB stick update example. // //***************************************************************************** int main(void) { unsigned long ulCount; // // 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 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("\n\nUSB Stick Update Demo\n---------------------\n\n"); // // Enable the GPIO module which the select button is attached to. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); // // Indicate what is happening. // UARTprintf("Press the user button to start the USB stick updater\n\n"); // // Enable the GPIO pin to read the select button. // ROM_GPIODirModeSet(GPIO_PORTB_BASE, GPIO_PIN_4, GPIO_DIR_MODE_IN); ROM_GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_4, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // // Wait for the pullup to take effect or the next loop will exist too soon. // SysCtlDelay(1000); // // Wait until the select button has been pressed for ~40ms (in order to // debounce the press). // ulCount = 0; while(1) { // // See if the button is pressed. // if(ROM_GPIOPinRead(GPIO_PORTB_BASE, GPIO_PIN_4) == 0) { // // Increment the count since the button is pressed. // ulCount++; // // If the count has reached 4, then the button has been debounced // as being pressed. // if(ulCount == 4) { break; } } else { // // Reset the count since the button is not pressed. // ulCount = 0; } // // Delay for approximately 10ms. // SysCtlDelay(16000000 / (3 * 100)); } // // Wait until the select button has been released for ~40ms (in order to // debounce the release). // ulCount = 0; while(1) { // // See if the button is pressed. // if(ROM_GPIOPinRead(GPIO_PORTB_BASE, GPIO_PIN_4) != 0) { // // Increment the count since the button is released. // ulCount++; // // If the count has reached 4, then the button has been debounced // as being released. // if(ulCount == 4) { break; } } else { // // Reset the count since the button is pressed. // ulCount = 0; } // // Delay for approximately 10ms. // SysCtlDelay(16000000 / (3 * 100)); } // // Indicate that the updater is being called. // UARTprintf("The USB stick updater is now running and looking for a\n" "USB memory stick\n\n"); // // Wait for the entire message above to transmit before continuing // while(UARTBusy(UART0_BASE)) { } // // Call the updater so that it will search for an update on a memory stick. // (*((void (*)(void))(*(unsigned long *)0x2c)))(); // // The updater should take control, so this should never be reached. // Just in case, loop forever. // while(1) { } }
/** * Enable Port and set GPIO to output */ void enable_lcd() { ROM_SysCtlPeripheralEnable( LCD_PERIPHERAL ); ROM_GPIOPinTypeGPIOOutput( LCD_PORT, LCD_CS | LCD_SCL | LCD_SI | LCD_RST ); }
//***************************************************************************** // // This is the main loop that runs the application. // //***************************************************************************** int main(void) { unsigned long ulButton, ulPrevious, ulLastTickCount; tBoolean bLastSuspend; // // Set the clocking to run from the PLL at 50MHz. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Enable USB pins // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); GPIOPinTypeUSBAnalog(GPIO_PORTD_BASE, GPIO_PIN_4 | GPIO_PIN_5); // // Enable 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[2JKeyboard device application\n"); // // Enable the GPIO that is used for the on-board push button. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ROM_GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_4); ROM_GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_4, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // // Enable the GPIO that is used for the on-board LED. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1); ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 0); // // Not configured initially. // g_bConnected = false; g_bSuspended = false; bLastSuspend = false; // // Set the USB stack mode to Device mode with VBUS monitoring. // USBStackModeSet(0, USB_MODE_DEVICE, 0); // // Pass our device information to the USB HID device class driver, // initialize the USB // controller and connect the device to the bus. // USBDHIDKeyboardInit(0, &g_sKeyboardDevice); // // Set the system tick to fire 100 times per second. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND); ROM_SysTickIntEnable(); ROM_SysTickEnable(); // // The main loop starts here. We begin by waiting for a host connection // then drop into the main keyboard handling section. If the host // disconnects, we return to the top and wait for a new connection. // ulPrevious = 1; setup(); while(1) { // // Tell the user what we are doing and provide some basic instructions. // UARTprintf("Waiting for host...\n"); // // Wait for USB configuration to complete. // while(!g_bConnected) { } // // Update the status. // UARTprintf("Host connected...\n"); // // Enter the idle state. // g_eKeyboardState = STATE_IDLE; // // Assume that the bus is not currently suspended if we have just been // configured. // bLastSuspend = false; // // Keep transferring characters from the UART to the USB host for as // long as we are connected to the host. // while(g_bConnected) { // // Remember the current time. // ulLastTickCount = g_ulSysTickCount; // // Has the suspend state changed since last time we checked? // if(bLastSuspend != g_bSuspended) { // // Yes - the state changed so update the display. // bLastSuspend = g_bSuspended; UARTprintf(bLastSuspend ? "Bus suspended...\n" : "Host connected...\n"); } // // See if the button was just pressed. // ulButton = num; if(ulButton != ulPrevious) { // // If the bus is suspended then resume it. Otherwise, type // some "random" characters. // if(g_bSuspended) { // // We are suspended so request a remote wakeup. // USBDHIDKeyboardRemoteWakeupRequest( (void *)&g_sKeyboardDevice); } else { char s[2] = {0x30+num,0}; SendString(s); } } ulPrevious = ulButton; // // Wait for at least 1 system tick to have gone by before we poll // the buttons again. // while(g_ulSysTickCount == ulLastTickCount) { // // Hang around doing nothing. // } } // // Dropping out of the previous loop indicates that the host has // disconnected so go back and wait for reconnection. // if(g_bConnected == false) { UARTprintf("Host disconnected...\n"); } } }
//***************************************************************************** // // This is the main loop that runs the application. // //***************************************************************************** int main(void) { tRectangle sRect; // // Set the clocking to run directly from the crystal. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); // // Enable the USB mux GPIO. // ROM_SysCtlPeripheralEnable(USB_MUX_GPIO_PERIPH); // // The LM3S3748 board uses a USB mux that must be switched to use the // host connector and not the device connecter. // ROM_GPIOPinTypeGPIOOutput(USB_MUX_GPIO_BASE, USB_MUX_GPIO_PIN); ROM_GPIOPinWrite(USB_MUX_GPIO_BASE, USB_MUX_GPIO_PIN, USB_MUX_SEL_DEVICE); // // Configure SysTick for a 100Hz interrupt. The FatFs driver wants a 10 ms // tick. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / 100); ROM_SysTickEnable(); ROM_SysTickIntEnable(); // // Configure and enable uDMA // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); SysCtlDelay(10); uDMAControlBaseSet(&sDMAControlTable[0]); uDMAEnable(); // // Initialize the display driver. // Formike128x128x16Init(); // // Turn on the backlight. // Formike128x128x16BacklightOn(); // // Initialize the graphics context. // GrContextInit(&g_sContext, &g_sFormike128x128x16); // // Fill the top 15 rows of the screen with blue to create the banner. // sRect.sXMin = 0; sRect.sYMin = 0; sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1; sRect.sYMax = DISPLAY_BANNER_HEIGHT; 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_pFontFixed6x8); GrStringDrawCentered(&g_sContext, "usb_dev_msc", -1, GrContextDpyWidthGet(&g_sContext) / 2, 7, 0); // // Initialize the idle timeout and reset all flags. // g_ulIdleTimeout = 0; g_ulFlags = 0; // // Initialize the state to idle. // g_eMSCState = MSC_DEV_IDLE; // // Draw the status bar and set it to idle. // UpdateStatus("Idle", 1); // // Pass our device information to the USB library and place the device // on the bus. // USBDMSCInit(0, (tUSBDMSCDevice *)&g_sMSCDevice); // // Drop into the main loop. // while(1) { switch(g_eMSCState) { case MSC_DEV_READ: { // // Update the screen if necessary. // if(g_ulFlags & FLAG_UPDATE_STATUS) { UpdateStatus("Reading", 0); g_ulFlags &= ~FLAG_UPDATE_STATUS; } // // If there is no activity then return to the idle state. // if(g_ulIdleTimeout == 0) { UpdateStatus("Idle ", 0); g_eMSCState = MSC_DEV_IDLE; } break; } case MSC_DEV_WRITE: { // // Update the screen if necessary. // if(g_ulFlags & FLAG_UPDATE_STATUS) { UpdateStatus("Writing", 0); g_ulFlags &= ~FLAG_UPDATE_STATUS; } // // If there is no activity then return to the idle state. // if(g_ulIdleTimeout == 0) { UpdateStatus("Idle ", 0); g_eMSCState = MSC_DEV_IDLE; } break; } case MSC_DEV_IDLE: default: { break; } } } }
// After a certain number of edges are captured, the application prints out // the results and compares the elapsed time between edges to the expected // value. // // Note that the "B" timer is used because on some devices the "A" timer does // not work correctly with the uDMA controller. Refer to the chip errata for // details. // //***************************************************************************** int main(void) { unsigned long ulIdx; unsigned short usTimerElapsed; //unsigned short usTimerErr; // // Set the clocking to run directly from the crystal. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Initialize the UART and write a status message. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); ROM_UARTConfigSetExpClk(UART0_BASE, ROM_SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_EVEN)); //UARTStdioInit(0); //UARTprintf("\033[2JuDMA edge capture timer example\n\n"); //UARTprintf("This example requires that PD0 and PD7 be jumpered together" // "\n\n"); // // Create a signal source that can be used as an input for the CCP1 pin. // SetupSignalSource(); // // Enable the GPIO port used for the CCP1 input. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); // // Configure the Timer0 CCP1 function to use PD7 // GPIOPinConfigure(GPIO_PB2_CCP3); GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_2); // // Set up Timer0B for edge-timer mode, positive edge // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); TimerConfigure(TIMER1_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_B_CAP_TIME); TimerControlEvent(TIMER1_BASE, TIMER_B, TIMER_EVENT_BOTH_EDGES); TimerLoadSet(TIMER1_BASE, TIMER_B, 0xffff); // // Enable the uDMA peripheral // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); // // Enable the uDMA controller error interrupt. This interrupt will occur // if there is a bus error during a transfer. // ROM_IntEnable(INT_UDMAERR); // // Enable the uDMA controller. // ROM_uDMAEnable(); // // Point at the control table to use for channel control structures. // ROM_uDMAControlBaseSet(ucControlTable); // // Put the attributes in a known state for the uDMA Timer0B channel. These // should already be disabled by default. // ROM_uDMAChannelAttributeDisable(UDMA_CHANNEL_TMR1B, UDMA_ATTR_ALTSELECT | UDMA_ATTR_USEBURST | UDMA_ATTR_HIGH_PRIORITY | UDMA_ATTR_REQMASK); // // Configure DMA channel for Timer0B to transfer 16-bit values, 1 at a // time. The source is fixed and the destination increments by 16-bits // (2 bytes) at a time. // ROM_uDMAChannelControlSet(UDMA_CHANNEL_TMR1B | UDMA_PRI_SELECT, UDMA_SIZE_16 | UDMA_SRC_INC_NONE | UDMA_DST_INC_16 | UDMA_ARB_1); // // Set up the transfer parameters for the Timer0B primary control // structure. The mode is set to basic, the transfer source is the // Timer0B register, and the destination is a memory buffer. The // transfer size is set to a fixed number of capture events. // ROM_uDMAChannelTransferSet(UDMA_CHANNEL_TMR1B | UDMA_PRI_SELECT, UDMA_MODE_BASIC, (void *)(TIMER1_BASE + TIMER_O_TBR), g_usTimerBuf, MAX_TIMER_EVENTS); // // Enable the timer capture event interrupt. Note that this signal is // used to trigger the DMA request and not an actual interrupt. // Start the capture timer running and enable its interrupt channel. // The timer interrupt channel is used by the uDMA controller. // //UARTprintf("Starting timer and uDMA\n"); TimerIntEnable(TIMER1_BASE, TIMER_CAPB_EVENT); TimerEnable(TIMER1_BASE, TIMER_B); IntEnable(INT_TIMER1B); // // Now enable the DMA channel for Timer0B. It should now start performing // transfers whenever there is a rising edge detected on the CCP1 pin. // ROM_uDMAChannelEnable(UDMA_CHANNEL_TMR1B); // // Enable processor interrupts. // ROM_IntMasterEnable(); // // Wait for the transfer to complete. // //UARTprintf("Waiting for transfers to complete\n"); while(!g_bDoneFlag) { } // // Check for the expected number of occurrences of the interrupt handler, // and that there are no DMA errors // if(g_uluDMAErrCount != 0) { //UARTprintf("\nuDMA errors were detected!!!\n\n"); } if(g_ulTimer0BIntCount != 1) { //UARTprintf("\nUnexpected number of interrupts occurrred (%d)!!!\n\n", // g_ulTimer0BIntCount); } // // Display the timer values that were captured using the edge capture timer // with uDMA. Compare the difference between stored values to the PWM // period and make sure they match. This verifies that the edge capture // DMA transfers were occurring with the correct timing. // //UARTprintf("\n Captured\n"); //UARTprintf("Event Value Difference Status\n"); //UARTprintf("----- -------- ---------- ------\n"); const unsigned char nbColonnes = '1'; UARTSend(&nbColonnes,1); for(ulIdx = 1; ulIdx < MAX_TIMER_EVENTS; ulIdx++) { // // Due to timer erratum, when the timer rolls past 0 as it counts // down, it will trigger an additional DMA transfer even though there // was not an edge capture. This will appear in the data buffer as // a duplicate value - the value will be the same as the prior capture // value. Therefore, in this example we skip past the duplicated // value. // if(g_usTimerBuf[ulIdx] == g_usTimerBuf[ulIdx - 1]) { const unsigned char dup = '$'; UARTSend(&dup,1); //UARTprintf(" %2u 0x%04X skipped duplicate\n", ulIdx, // g_usTimerBuf[ulIdx]); continue; } // // Compute the difference between adjacent captured values, and then // compare that to the expected timeout period. // usTimerElapsed = g_usTimerBuf[ulIdx - 1] - g_usTimerBuf[ulIdx]; //usTimerErr = usTimerElapsed > TIMEOUT_VAL ? // usTimerElapsed - TIMEOUT_VAL : // TIMEOUT_VAL - usTimerElapsed; // // Print the captured value and the difference from the previous // unsigned char data[10]; itoa(usTimerElapsed,data); UARTSend(data,10); //UARTprintf(" %2u 0x%04X %8u ", ulIdx, g_usTimerBuf[ulIdx], // usTimerElapsed); // // Print error status based on the deviation from expected difference // between samples (calculated above). Allow for a difference of up // to 1 cycle. Any more than that is considered an error. // //if(usTimerErr > 1) //{ // UARTprintf(" ERROR\n"); //} //else //{ // UARTprintf(" OK\n"); //} } const unsigned char fin = '\n'; UARTSend(&fin,1); // // End of application // while(1) { } }
int main(void) { ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_EEPROM0); if(ROM_EEPROMInit() == EEPROM_INIT_ERROR) { if(ROM_EEPROMInit() != EEPROM_INIT_ERROR) EEPROMMassErase(); } timerInit(); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOM); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOP); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOQ); #ifdef TARGET_IS_SNOWFLAKE_RA0 ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOR); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOS); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOT); #endif //Unlock and commit NMI pins PD7 and PF0 HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = 0x4C4F434B; HWREG(GPIO_PORTF_BASE + GPIO_O_CR) |= 0x1; HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = 0x4C4F434B; HWREG(GPIO_PORTD_BASE + GPIO_O_CR) |= 0x80; setup(); for (;;) { loop(); if (serialEventRun) serialEventRun(); } }
//***************************************************************************** // // This is the main loop that runs the application. // //***************************************************************************** int main(void) { // // Set the clocking to run from the PLL at 50MHz. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Enable the peripherals used by this example. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH); // // Enable 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[2JHost Keyboard Application\n"); // // Configure SysTick for a 100Hz interrupt. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / TICKS_PER_SECOND); ROM_SysTickEnable(); ROM_SysTickIntEnable(); // // Enable Clocking to the USB controller. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0); // // Configure the power pins for host controller. // GPIOPinConfigure(GPIO_PH3_USB0EPEN); GPIOPinConfigure(GPIO_PH4_USB0PFLT); ROM_GPIOPinTypeUSBDigital(GPIO_PORTH_BASE, GPIO_PIN_3 | GPIO_PIN_4); // // Initially wait for device connection. // g_eUSBState = STATE_NO_DEVICE; // // Initialize the USB stack mode and pass in a mode callback. // USBStackModeSet(0, USB_MODE_OTG, ModeCallback); // // Register the host class drivers. // USBHCDRegisterDrivers(0, g_ppHostClassDrivers, g_ulNumHostClassDrivers); // // Open an instance of the keyboard driver. The keyboard does not need // to be present at this time, this just save a place for it and allows // the applications to be notified when a keyboard is present. // g_ulKeyboardInstance = USBHKeyboardOpen(KeyboardCallback, g_pucBuffer, KEYBOARD_MEMORY_SIZE); // // Initialize the power configuration. This sets the power enable signal // to be active high and does not enable the power fault. // USBHCDPowerConfigInit(0, USBHCD_VBUS_AUTO_HIGH | USBHCD_VBUS_FILTER); // // Initialize the USB controller for OTG operation with a 2ms polling // rate. // USBOTGModeInit(0, 2000, g_pHCDPool, HCD_MEMORY_SIZE); // // The main loop for the application. // while(1) { // // Tell the OTG state machine how much time has passed in // milliseconds since the last call. // USBOTGMain(GetTickms()); switch(g_eUSBState) { // // This state is entered when they keyboard is first detected. // case STATE_KEYBOARD_INIT: { // // Initialized the newly connected keyboard. // USBHKeyboardInit(g_ulKeyboardInstance); // // Proceed to the keyboard connected state. // g_eUSBState = STATE_KEYBOARD_CONNECTED; USBHKeyboardModifierSet(g_ulKeyboardInstance, g_ulModifiers); break; } case STATE_KEYBOARD_UPDATE: { // // If the application detected a change that required an // update to be sent to the keyboard to change the modifier // state then call it and return to the connected state. // g_eUSBState = STATE_KEYBOARD_CONNECTED; USBHKeyboardModifierSet(g_ulKeyboardInstance, g_ulModifiers); break; } case STATE_KEYBOARD_CONNECTED: { // // Nothing is currently done in the main loop when the keyboard // is connected. // break; } case STATE_UNKNOWN_DEVICE: { // // Nothing to do as the device is unknown. // break; } case STATE_NO_DEVICE: { // // Nothing is currently done in the main loop when the keyboard // is not connected. // break; } default: { break; } } } }
int main(void) { Init_Sys(); ROM_IntMasterEnable(); DBG_Init(); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // LEDs ROM_GPIOPinTypeGPIOOutput(RED_GPIO_BASE, RED_GPIO_PIN); GPIOPinWrite(RED_GPIO_BASE, RED_GPIO_PIN, 0); ROM_GPIOPinTypeGPIOOutput(GREEN_GPIO_BASE, GREEN_GPIO_PIN); GPIOPinWrite(GREEN_GPIO_BASE, GREEN_GPIO_PIN, 0); ROM_GPIOPinTypeGPIOOutput(BLUE_GPIO_BASE, BLUE_GPIO_PIN); GPIOPinWrite(BLUE_GPIO_BASE, BLUE_GPIO_PIN, 0); // dbg_putstr("\033[2JInitializing...\r\n"); dbg_putstr("\033[2JInitializing C app...\r\n"); dbg_putstr("Ready:\r\n"); static uint16_t heartbeat_ctr = 0; while(1) { char cmdbfr[64]; if(dbg_getline_nb(cmdbfr, 64) > 0) { GPIOPinWrite(RED_GPIO_BASE, RED_GPIO_PIN, RED_GPIO_PIN); dbg_printf("\r\nEntered: %s\r\n", cmdbfr); } if(rx_led_ctr > 0) { --rx_led_ctr; GPIOPinWrite(BLUE_GPIO_BASE, BLUE_GPIO_PIN, BLUE_GPIO_PIN); } else { GPIOPinWrite(BLUE_GPIO_BASE, BLUE_GPIO_PIN, 0); } // Blink heartbeat LED if(heartbeat_ctr > 0) { --heartbeat_ctr; } else { if(GPIOPinRead(GREEN_GPIO_BASE, GREEN_GPIO_PIN)) { GPIOPinWrite(GREEN_GPIO_BASE, GREEN_GPIO_PIN, 0); heartbeat_ctr = 200; } else { GPIOPinWrite(GREEN_GPIO_BASE, GREEN_GPIO_PIN, GREEN_GPIO_PIN); heartbeat_ctr = 1; } } ROM_SysCtlDelay(ROM_SysCtlClockGet()/(1000*3)); } }
//***************************************************************************** // // This is the main loop that runs the application. // //***************************************************************************** int main(void) { // // Set the clocking to run from the PLL at 50MHz. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Enable 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[2JMouse device application\n"); // Configure USB pins, according to // http://forum.stellarisiti.com/topic/353-work-around-stellaris-launchpad-usb-serial-example-not-enumerating-correctly/?p=1544 // Enable the GPIO port so we can configure it SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); // Setup the port to be in USB analog mode. Routes incoming signals to // on-chip USB PHY GPIOPinTypeUSBAnalog(GPIO_PORTD_BASE, GPIO_PIN_4 | GPIO_PIN_5); // // Set the system tick to fire 100 times per second. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND); ROM_SysTickIntEnable(); ROM_SysTickEnable(); // // Set the USB stack mode to Device mode with VBUS monitoring. // USBStackModeSet(0, USB_MODE_DEVICE, 0); // // Pass the USB library our device information, initialize the USB // controller and connect the device to the bus. // USBDHIDMouseInit(0, (tUSBDHIDMouseDevice *)&g_sMouseDevice); // // Drop into the main loop. // while(1) { // // Tell the user what we are doing. // UARTprintf("Waiting for host...\n"); // // Wait for USB configuration to complete. // while(!g_bConnected) { } // // Update the status. // UARTprintf("Host connected...\n"); // // Now keep processing the mouse as long as the host is connected. // while(g_bConnected) { // // If it is time to move the mouse then do so. // if(HWREGBITW(&g_ulCommands, TICK_EVENT) == 1) { HWREGBITW(&g_ulCommands, TICK_EVENT) = 0; MoveHandler(); } } // // Update the status. // UARTprintf("Host disconnected...\n"); } }
//***************************************************************************** // // The program main function. It performs initialization, then runs a loop to // process USB activities and operate the user interface. // //***************************************************************************** int main(void) { uint32_t ui32DriveTimeout; // // 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 system clock to run at 50MHz from the PLL. // 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); // // Configure SysTick for a 100Hz interrupt. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / TICKS_PER_SECOND); ROM_SysTickEnable(); ROM_SysTickIntEnable(); // // Enable the uDMA controller and set up the control table base. // The uDMA controller is used by the USB library. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); ROM_uDMAEnable(); ROM_uDMAControlBaseSet(g_psDMAControlTable); // // Enable Interrupts // ROM_IntMasterEnable(); // // Initialize the display driver. // CFAL96x64x16Init(); // // Initialize the buttons driver. // ButtonsInit(); // // Initialize two offscreen displays and assign the palette. These // buffers are used by the slide menu widget to allow animation effects. // GrOffScreen4BPPInit(&g_sOffscreenDisplayA, g_pui8OffscreenBufA, 96, 64); GrOffScreen4BPPPaletteSet(&g_sOffscreenDisplayA, g_pui32Palette, 0, NUM_PALETTE_ENTRIES); GrOffScreen4BPPInit(&g_sOffscreenDisplayB, g_pui8OffscreenBufB, 96, 64); GrOffScreen4BPPPaletteSet(&g_sOffscreenDisplayB, g_pui32Palette, 0, NUM_PALETTE_ENTRIES); // // Show an initial status screen // g_pcStatusLines[0] = "Waiting"; g_pcStatusLines[1] = "for device"; ShowStatusScreen(g_pcStatusLines, 2); // // Add the compile-time defined widgets to the widget tree. // WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sFileMenuWidget); // // Initially wait for device connection. // g_eState = STATE_NO_DEVICE; // // Initialize the USB stack for host mode. // USBStackModeSet(0, eUSBModeHost, 0); // // Register the host class drivers. // USBHCDRegisterDrivers(0, g_ppHostClassDrivers, g_ui32NumHostClassDrivers); // // Open an instance of the mass storage class driver. // g_psMSCInstance = USBHMSCDriveOpen(0, MSCCallback); // // Initialize the drive timeout. // ui32DriveTimeout = USBMSC_DRIVE_RETRY; // // Initialize the power configuration. This sets the power enable signal // to be active high and does not enable the power fault. // USBHCDPowerConfigInit(0, USBHCD_VBUS_AUTO_HIGH | USBHCD_VBUS_FILTER); // // Initialize the USB controller for host operation. // USBHCDInit(0, g_pui8HCDPool, HCD_MEMORY_SIZE); // // Initialize the file system. // FileInit(); // // Enter an infinite loop to run the user interface and process USB // events. // while(1) { uint32_t ui32LastTickCount = 0; // // Call the USB stack to keep it running. // USBHCDMain(); // // Process any messages in the widget message queue. This keeps the // display UI running. // WidgetMessageQueueProcess(); // // Take action based on the application state. // switch(g_eState) { // // A device has enumerated. // case STATE_DEVICE_ENUM: { // // Check to see if the device is ready. If not then stay // in this state and we will check it again on the next pass. // if(USBHMSCDriveReady(g_psMSCInstance) != 0) { // // Wait about 500ms before attempting to check if the // device is ready again. // ROM_SysCtlDelay(ROM_SysCtlClockGet()/(3)); // // Decrement the retry count. // ui32DriveTimeout--; // // If the timeout is hit then go to the // STATE_TIMEOUT_DEVICE state. // if(ui32DriveTimeout == 0) { g_eState = STATE_TIMEOUT_DEVICE; } break; } // // Getting here means the device is ready. // Reset the CWD to the root directory. // g_pcCwdBuf[0] = '/'; g_pcCwdBuf[1] = 0; // // Set the initial directory level to the root // g_ui32Level = 0; // // We need to reset the indexes of the root menu to 0, so that // it will start at the top of the file list, and reset the // slide menu widget to start with the root menu. // g_psFileMenus[g_ui32Level].ui32CenterIndex = 0; g_psFileMenus[g_ui32Level].ui32FocusIndex = 0; SlideMenuMenuSet(&g_sFileMenuWidget, &g_psFileMenus[g_ui32Level]); // // Initiate a directory change to the root. This will // populate a menu structure representing the root directory. // if(ProcessDirChange("/", g_ui32Level)) { // // If there were no errors reported, we are ready for // MSC operation. // g_eState = STATE_DEVICE_READY; // // Set the Device Present flag. // g_ui32Flags = FLAGS_DEVICE_PRESENT; // // Request a repaint so the file menu will be shown // WidgetPaint(WIDGET_ROOT); } break; } // // If there is no device then just wait for one. // case STATE_NO_DEVICE: { if(g_ui32Flags == FLAGS_DEVICE_PRESENT) { // // Show waiting message on screen // g_pcStatusLines[0] = "Waiting"; g_pcStatusLines[1] = "for device"; ShowStatusScreen(g_pcStatusLines, 2); // // Clear the Device Present flag. // g_ui32Flags &= ~FLAGS_DEVICE_PRESENT; } break; } // // An unknown device was connected. // case STATE_UNKNOWN_DEVICE: { // // If this is a new device then change the status. // if((g_ui32Flags & FLAGS_DEVICE_PRESENT) == 0) { // // Clear the screen and indicate that an unknown device // is present. // g_pcStatusLines[0] = "Unknown"; g_pcStatusLines[1] = "device"; ShowStatusScreen(g_pcStatusLines, 2); } // // Set the Device Present flag. // g_ui32Flags = FLAGS_DEVICE_PRESENT; break; } // // The connected mass storage device is not reporting ready. // case STATE_TIMEOUT_DEVICE: { // // If this is the first time in this state then print a // message. // if((g_ui32Flags & FLAGS_DEVICE_PRESENT) == 0) { // // // Clear the screen and indicate that an unknown device // is present. // g_pcStatusLines[0] = "Device"; g_pcStatusLines[1] = "Timeout"; ShowStatusScreen(g_pcStatusLines, 2); } // // Set the Device Present flag. // g_ui32Flags = FLAGS_DEVICE_PRESENT; break; } // // The device is ready and in use. // case STATE_DEVICE_READY: { // // Process occurrence of timer tick. Check for user input // once each tick. // if(g_ui32SysTickCount != ui32LastTickCount) { uint8_t ui8ButtonState; uint8_t ui8ButtonChanged; ui32LastTickCount = g_ui32SysTickCount; // // Get the current debounced state of the buttons. // ui8ButtonState = ButtonsPoll(&ui8ButtonChanged, 0); // // If select button or right button is pressed, then we // are trying to descend into another directory // if(BUTTON_PRESSED(SELECT_BUTTON, ui8ButtonState, ui8ButtonChanged) || BUTTON_PRESSED(RIGHT_BUTTON, ui8ButtonState, ui8ButtonChanged)) { uint32_t ui32NewLevel; uint32_t ui32ItemIdx; char *pcItemName; // // Get a pointer to the current menu for this CWD. // tSlideMenu *psMenu = &g_psFileMenus[g_ui32Level]; // // Get the highlighted index in the current file list. // This is the currently highlighted file or dir // on the display. Then get the name of the file at // this index. // ui32ItemIdx = SlideMenuFocusItemGet(psMenu); pcItemName = psMenu->psSlideMenuItems[ui32ItemIdx].pcText; // // Make sure we are not yet past the maximum tree // depth. // if(g_ui32Level < MAX_SUBDIR_DEPTH) { // // Potential new level is one greater than the // current level. // ui32NewLevel = g_ui32Level + 1; // // Process the directory change to the new // directory. This function will populate a menu // structure with the files and subdirs in the new // directory. // if(ProcessDirChange(pcItemName, ui32NewLevel)) { // // If the change was successful, then update // the level. // g_ui32Level = ui32NewLevel; // // Now that all the prep is done, send the // KEY_RIGHT message to the widget and it will // "slide" from the previous file list to the // new file list of the CWD. // SendWidgetKeyMessage(WIDGET_MSG_KEY_RIGHT); } } } // // If the UP button is pressed, just pass it to the widget // which will handle scrolling the list of files. // if(BUTTON_PRESSED(UP_BUTTON, ui8ButtonState, ui8ButtonChanged)) { SendWidgetKeyMessage(WIDGET_MSG_KEY_UP); } // // If the DOWN button is pressed, just pass it to the widget // which will handle scrolling the list of files. // if(BUTTON_PRESSED(DOWN_BUTTON, ui8ButtonState, ui8ButtonChanged)) { SendWidgetKeyMessage(WIDGET_MSG_KEY_DOWN); } // // If the LEFT button is pressed, then we are attempting // to go up a level in the file system. // if(BUTTON_PRESSED(LEFT_BUTTON, ui8ButtonState, ui8ButtonChanged)) { uint32_t ui32NewLevel; // // Make sure we are not already at the top of the // directory tree (at root). // if(g_ui32Level) { // // Potential new level is one less than the // current level. // ui32NewLevel = g_ui32Level - 1; // // Process the directory change to the new // directory. This function will populate a menu // structure with the files and subdirs in the new // directory. // if(ProcessDirChange("..", ui32NewLevel)) { // // If the change was successful, then update // the level. // g_ui32Level = ui32NewLevel; // // Now that all the prep is done, send the // KEY_LEFT message to the widget and it will // "slide" from the previous file list to the // new file list of the CWD. // SendWidgetKeyMessage(WIDGET_MSG_KEY_LEFT); } } } } break; } // // Something has caused a power fault. // case STATE_POWER_FAULT: { // // Clear the screen and show a power fault indication. // g_pcStatusLines[0] = "Power"; g_pcStatusLines[1] = "fault"; ShowStatusScreen(g_pcStatusLines, 2); break; } default: { break; } } } }
//***************************************************************************** // // Run the hibernate example. Use a loop to put the microcontroller into // hibernate mode, and to wake up based on time. Also allow the user to cause // it to hibernate and/or wake up based on button presses. // //***************************************************************************** int main(void) { uint32_t ui32Idx; uint32_t ui32Status = 0; uint32_t ui32HibernateCount = 0; tContext sContext; tRectangle sRect; // // 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); // // Initialize the UART. // ConfigureUART(); // // Initialize the OLED display // CFAL96x64x16Init(); // // Initialize the graphics context. // GrContextInit(&sContext, &g_sCFAL96x64x16); // // Fill the top 24 rows of the screen with blue to create the banner. // sRect.i16XMin = 0; sRect.i16YMin = 0; sRect.i16XMax = GrContextDpyWidthGet(&sContext) - 1; sRect.i16YMax = 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_psFontFixed6x8); GrStringDrawCentered(&sContext, "hibernate", -1, GrContextDpyWidthGet(&sContext) / 2, 4, 0); // // Initialize the buttons driver // ButtonsInit(); // // Set up systick to generate interrupts at 100 Hz. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / 100); ROM_SysTickIntEnable(); ROM_SysTickEnable(); // // Enable the Hibernation module. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_HIBERNATE); // // Print wake cause message on display. // GrStringDrawCentered(&sContext, "Wake due to:", -1, GrContextDpyWidthGet(&sContext) / 2, Row(2) + 4, true); // // Check to see if Hibernation module is already active, which could mean // that the processor is waking from a hibernation. // if(HibernateIsActive()) { // // Read the status bits to see what caused the wake. // ui32Status = HibernateIntStatus(0); HibernateIntClear(ui32Status); // // Wake was due to the push button. // if(ui32Status & HIBERNATE_INT_PIN_WAKE) { GrStringDrawCentered(&sContext, "BUTTON", -1, GrContextDpyWidthGet(&sContext) / 2, Row(3) + 4, true); } // // Wake was due to RTC match // else if(ui32Status & HIBERNATE_INT_RTC_MATCH_0) { GrStringDrawCentered(&sContext, "TIMEOUT", -1, GrContextDpyWidthGet(&sContext) / 2, Row(3) + 4, true); } // // Wake is due to neither button nor RTC, so it must have been a hard // reset. // else { GrStringDrawCentered(&sContext, "RESET", -1, GrContextDpyWidthGet(&sContext) / 2, Row(3) + 4, true); } // // If the wake is due to button or RTC, then read the first location // from the battery backed memory, as the hibernation count. // if(ui32Status & (HIBERNATE_INT_PIN_WAKE | HIBERNATE_INT_RTC_MATCH_0)) { HibernateDataGet(&ui32HibernateCount, 1); } } // // Enable the Hibernation module. This should always be called, even if // the module was already enabled, because this function also initializes // some timing parameters. // HibernateEnableExpClk(ROM_SysCtlClockGet()); // // If the wake was not due to button or RTC match, then it was a reset. // if(!(ui32Status & (HIBERNATE_INT_PIN_WAKE | HIBERNATE_INT_RTC_MATCH_0))) { // // Configure the module clock source. // HibernateClockConfig(HIBERNATE_OSC_LOWDRIVE); // // Finish the wake cause message. // GrStringDrawCentered(&sContext, "RESET", -1, GrContextDpyWidthGet(&sContext) / 2, Row(3) + 4, true); // // Wait a couple of seconds in case we need to break in with the // debugger. // SysTickWait(3 * 100); // // Allow time for the crystal to power up. This line is separated from // the above to make it clear this is still needed, even if the above // delay is removed. // SysTickWait(15); } // // Print the count of times that hibernate has occurred. // usnprintf(g_pcBuf, sizeof(g_pcBuf), "Hib count=%4u", ui32HibernateCount); GrStringDrawCentered(&sContext, g_pcBuf, -1, GrContextDpyWidthGet(&sContext) / 2, Row(1) + 4, true); // // Print messages on the screen about hibernation. // GrStringDrawCentered(&sContext, "Select to Hib", -1, GrContextDpyWidthGet(&sContext) / 2, Row(4) + 4, true); GrStringDrawCentered(&sContext, "Wake in 5 s,", -1, GrContextDpyWidthGet(&sContext) / 2, Row(5) + 4, true); GrStringDrawCentered(&sContext, "or press Select", -1, GrContextDpyWidthGet(&sContext) / 2, Row(6) + 4, true); GrStringDrawCentered(&sContext, "for immed. wake.", -1, GrContextDpyWidthGet(&sContext) / 2, Row(7) + 4, true); // // Clear the button pressed flag, in case it was held down at the // beginning. // bSelectPressed = 0; // // Wait for user to press the button. // while(!bSelectPressed) { // // Wait a bit before looping again. // SysTickWait(10); } // // Tell user to release the button. // GrStringDrawCentered(&sContext, " ", -1, GrContextDpyWidthGet(&sContext) / 2, Row(4) + 4, true); GrStringDrawCentered(&sContext, " ", -1, GrContextDpyWidthGet(&sContext) / 2, Row(5) + 4, true); GrStringDrawCentered(&sContext, " ", -1, GrContextDpyWidthGet(&sContext) / 2, Row(6) + 4, true); GrStringDrawCentered(&sContext, " ", -1, GrContextDpyWidthGet(&sContext) / 2, Row(7) + 4, true); GrStringDrawCentered(&sContext, "Release the", -1, GrContextDpyWidthGet(&sContext) / 2, Row(5) + 4, true); GrStringDrawCentered(&sContext, "button.", -1, GrContextDpyWidthGet(&sContext) / 2, Row(6) + 4, true); GrStringDrawCentered(&sContext, " ", -1, GrContextDpyWidthGet(&sContext) / 2, Row(7) + 4, true); // // Wait for user to release the button. // while(bSelectPressed) { } // // If hibernation count is very large, it may be that there was already // a value in the hibernate memory, so reset the count. // ui32HibernateCount = (ui32HibernateCount > 10000) ? 0 : ui32HibernateCount; // // Increment the hibernation count, and store it in the battery backed // memory. // ui32HibernateCount++; HibernateDataSet(&ui32HibernateCount, 1); // // Clear and enable the RTC and set the match registers to 5 seconds in the // future. Set both to same, though they could be set differently, the // first to match will cause a wake. // HibernateRTCSet(0); HibernateRTCEnable(); HibernateRTCMatchSet(0, 5); // // Set wake condition on pin or RTC match. Board will wake when 5 seconds // elapses, or when the button is pressed. // HibernateWakeSet(HIBERNATE_WAKE_PIN | HIBERNATE_WAKE_RTC); // // Request hibernation. // HibernateRequest(); // // Give it time to activate, it should never get past this wait. // SysTickWait(100); // // Should not have got here, something is wrong. Print an error message to // the user. // sRect.i16XMin = 0; sRect.i16XMax = 95; sRect.i16YMin = 0; sRect.i16YMax = 63; GrContextForegroundSet(&sContext, ClrBlack); GrRectFill(&sContext, &sRect); GrContextForegroundSet(&sContext, ClrWhite); ui32Idx = 0; while(g_pcErrorText[ui32Idx]) { GrStringDraw(&sContext, g_pcErrorText[ui32Idx], -1, Col(0), Row(ui32Idx), true); ui32Idx++; } // // Wait for the user to press the button, then restart the app. // bSelectPressed = 0; while(!bSelectPressed) { } // // Reset the processor. // ROM_SysCtlReset(); // // Finished. // while(1) { } }
//***************************************************************************** // // Main application entry function. // //***************************************************************************** int main(void) { tBoolean bRetcode; smplStatus_t eRetcode; // // Set the system clock to run at 50MHz from the PLL // MAP_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // NB: We don't call PinoutSet() in this testcase since the EM header // expansion board doesn't currently have an I2C ID EEPROM. If we did // call PinoutSet() this would configure all the EPI pins for SDRAM and // we don't want to do this. // g_eDaughterType = DAUGHTER_NONE; // // Enable peripherals required to drive the LCD. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH); // // Configure SysTick for a 10Hz interrupt. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / TICKS_PER_SECOND); ROM_SysTickEnable(); ROM_SysTickIntEnable(); // // Initialize the display driver. // Kitronix320x240x16_SSD2119Init(); // // Initialize the touch screen driver. // TouchScreenInit(); // // Set the touch screen event handler. // TouchScreenCallbackSet(WidgetPointerMessage); // // Add the compile-time defined widgets to the widget tree. // WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sHeading); // // Initialize the status string. // UpdateStatus("Initializing..."); // // Paint the widget tree to make sure they all appear on the display. // WidgetPaint(WIDGET_ROOT); // // Initialize the SimpliciTI BSP. // BSP_Init(); // // Set the SimpliciTI device address using the current Ethernet MAC address // to ensure something like uniqueness. // bRetcode = SetSimpliciTIAddress(); // // Did we have a problem with the address? // if(!bRetcode) { // // Yes - make sure the display is updated then hang the app. // WidgetMessageQueueProcess(); while(1) { // // MAC address is not set so hang the app. // } } // // Turn on both our LEDs // SetLED(1, true); SetLED(2, true); UpdateStatus("Waiting..."); // // Initialize the SimpliciTI stack but don't set any receive callback. // while(1) { eRetcode = SMPL_Init((uint8_t (*)(linkID_t))0); if(eRetcode == SMPL_SUCCESS) { break; } ToggleLED(1); ToggleLED(2); SPIN_ABOUT_A_SECOND; } // // Tell the user what's up. // UpdateStatus("Range Extender active."); // // Do nothing after this - the SimpliciTI stack code handles all the // access point function required. // while(1) { // // Process the widget message queue. // WidgetMessageQueueProcess(); } }
//***************************************************************************** // // This is the main loop that runs the application. // //***************************************************************************** int main(void) { 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 USB pins SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); GPIOPinTypeUSBAnalog(GPIO_PORTD_BASE, GPIO_PIN_4 | GPIO_PIN_5); // Set the system tick to fire 100 times per second. ROM_SysTickEnable(); ROM_SysTickIntEnable(); ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND); // Initialize the on board buttons ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // Right button is muxed so you need to unlock and configure HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY_DD; HWREG(GPIO_PORTF_BASE + GPIO_O_CR) |= 0x01; HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = 0; ROM_GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_4 |GPIO_PIN_0); ROM_GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_4 |GPIO_PIN_0, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // Enable Output Status Light ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3); // Set initial LED Status to RED to indicate not connected ROM_GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 2); // Set the USB stack mode to Device mode with VBUS monitoring. USBStackModeSet(0, USB_MODE_DEVICE, 0); // Pass the USB library our device information, initialize the USB // controller and connect the device to the bus. USBDHIDCustomHidInit(0, (tUSBDHIDCustomHidDevice *)&g_sCustomHidDevice); // Drop into the main loop. while(1) { // Wait for USB configuration to complete. while(!g_bConnected) { ROM_GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 2); } // Update the status to green when connected. ROM_GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 8); // Now keep processing the customhid as long as the host is connected. while(g_bConnected) { // If it is time to check the buttons and send a customhid report then do so. if(HWREGBITW(&g_ulCommands, TICK_EVENT) == 1) { HWREGBITW(&g_ulCommands, TICK_EVENT) = 0; CustomHidChangeHandler(); } } } }
//***************************************************************************** // // This example demonstrates how to use the uDMA controller to transfer data // between memory buffers and to and from a peripheral, in this case a UART. // The uDMA controller is configured to repeatedly transfer a block of data // from one memory buffer to another. It is also set up to repeatedly copy a // block of data from a buffer to the UART output. The UART data is looped // back so the same data is received, and the uDMA controlled is configured to // continuously receive the UART data using ping-pong buffers. // // The processor is put to sleep when it is not doing anything, and this allows // collection of CPU usage data to see how much CPU is being used while the // data transfers are ongoing. // //***************************************************************************** int main(void) { static uint32_t ui32PrevSeconds; static uint32_t ui32PrevXferCount; static uint32_t ui32PrevUARTCount = 0; uint32_t ui32XfersCompleted; uint32_t ui32BytesTransferred; // // 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 50 MHz. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Enable peripherals to operate when CPU is in sleep. // ROM_SysCtlPeripheralClockGating(true); // // Enable the GPIO port that is used for the on-board LED. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // // Enable the GPIO pins for the LED (PF2). // ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2); // // Initialize the UART. // ConfigureUART(); UARTprintf("\033[2JuDMA Example\n"); // // Show the clock frequency on the display. // UARTprintf("Tiva C Series @ %u MHz\n\n", ROM_SysCtlClockGet() / 1000000); // // Show statistics headings. // UARTprintf("CPU Memory UART Remaining\n"); UARTprintf("Usage Transfers Transfers Time\n"); // // Configure SysTick to occur 100 times per second, to use as a time // reference. Enable SysTick to generate interrupts. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND); ROM_SysTickIntEnable(); ROM_SysTickEnable(); // // Initialize the CPU usage measurement routine. // CPUUsageInit(ROM_SysCtlClockGet(), SYSTICKS_PER_SECOND, 2); // // Enable the uDMA controller at the system level. Enable it to continue // to run while the processor is in sleep. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UDMA); // // Enable the uDMA controller error interrupt. This interrupt will occur // if there is a bus error during a transfer. // ROM_IntEnable(INT_UDMAERR); // // Enable the uDMA controller. // ROM_uDMAEnable(); // // Point at the control table to use for channel control structures. // ROM_uDMAControlBaseSet(ui8ControlTable); // // Initialize the uDMA memory to memory transfers. // InitSWTransfer(); // // Initialize the uDMA UART transfers. // InitUART1Transfer(); // // Remember the current SysTick seconds count. // ui32PrevSeconds = g_ui32Seconds; // // Remember the current count of memory buffer transfers. // ui32PrevXferCount = g_ui32MemXferCount; // // Loop until the button is pressed. The processor is put to sleep // in this loop so that CPU utilization can be measured. // while(1) { // // Check to see if one second has elapsed. If so, the make some // updates. // if(g_ui32Seconds != ui32PrevSeconds) { // // Turn on the LED as a heartbeat // GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2); // // Print a message to the display showing the CPU usage percent. // The fractional part of the percent value is ignored. // UARTprintf("\r%3d%% ", g_ui32CPUUsage >> 16); // // Remember the new seconds count. // ui32PrevSeconds = g_ui32Seconds; // // Calculate how many memory transfers have occurred since the last // second. // ui32XfersCompleted = g_ui32MemXferCount - ui32PrevXferCount; // // Remember the new transfer count. // ui32PrevXferCount = g_ui32MemXferCount; // // Compute how many bytes were transferred in the memory transfer // since the last second. // ui32BytesTransferred = ui32XfersCompleted * MEM_BUFFER_SIZE * 4; // // Print a message showing the memory transfer rate. // if(ui32BytesTransferred >= 100000000) { UARTprintf("%3d MB/s ", ui32BytesTransferred / 1000000); } else if(ui32BytesTransferred >= 10000000) { UARTprintf("%2d.%01d MB/s ", ui32BytesTransferred / 1000000, (ui32BytesTransferred % 1000000) / 100000); } else if(ui32BytesTransferred >= 1000000) { UARTprintf("%1d.%02d MB/s ", ui32BytesTransferred / 1000000, (ui32BytesTransferred % 1000000) / 10000); } else if(ui32BytesTransferred >= 100000) { UARTprintf("%3d KB/s ", ui32BytesTransferred / 1000); } else if(ui32BytesTransferred >= 10000) { UARTprintf("%2d.%01d KB/s ", ui32BytesTransferred / 1000, (ui32BytesTransferred % 1000) / 100); } else if(ui32BytesTransferred >= 1000) { UARTprintf("%1d.%02d KB/s ", ui32BytesTransferred / 1000, (ui32BytesTransferred % 1000) / 10); } else if(ui32BytesTransferred >= 100) { UARTprintf("%3d B/s ", ui32BytesTransferred); } else if(ui32BytesTransferred >= 10) { UARTprintf("%2d B/s ", ui32BytesTransferred); } else { UARTprintf("%1d B/s ", ui32BytesTransferred); } // // Calculate how many UART transfers have occurred since the last // second. // ui32XfersCompleted = (g_ui32RxBufACount + g_ui32RxBufBCount - ui32PrevUARTCount); // // Remember the new UART transfer count. // ui32PrevUARTCount = g_ui32RxBufACount + g_ui32RxBufBCount; // // Compute how many bytes were transferred by the UART. The number // of bytes received is multiplied by 2 so that the TX bytes // transferred are also accounted for. // ui32BytesTransferred = ui32XfersCompleted * UART_RXBUF_SIZE * 2; // // Print a message showing the UART transfer rate. // if(ui32BytesTransferred >= 1000000) { UARTprintf("%1d.%02d MB/s ", ui32BytesTransferred / 1000000, (ui32BytesTransferred % 1000000) / 10000); } else if(ui32BytesTransferred >= 100000) { UARTprintf("%3d KB/s ", ui32BytesTransferred / 1000); } else if(ui32BytesTransferred >= 10000) { UARTprintf("%2d.%01d KB/s ", ui32BytesTransferred / 1000, (ui32BytesTransferred % 1000) / 100); } else if(ui32BytesTransferred >= 1000) { UARTprintf("%1d.%02d KB/s ", ui32BytesTransferred / 1000, (ui32BytesTransferred % 1000) / 10); } else if(ui32BytesTransferred >= 100) { UARTprintf("%3d B/s ", ui32BytesTransferred); } else if(ui32BytesTransferred >= 10) { UARTprintf("%2d B/s ", ui32BytesTransferred); } else { UARTprintf("%1d B/s ", ui32BytesTransferred); } // // Print a spinning line to make it more apparent that there is // something happening. // UARTprintf("%2ds", 10 - ui32PrevSeconds); // // Turn off the LED. // GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0); } // // Put the processor to sleep if there is nothing to do. This allows // the CPU usage routine to measure the number of free CPU cycles. // If the processor is sleeping a lot, it can be hard to connect to // the target with the debugger. // ROM_SysCtlSleep(); // // See if we have run int32_t enough and exit the loop if so. // if(g_ui32Seconds >= 10) { break; } }
//***************************************************************************** // // This is the main application entry function. // //***************************************************************************** int main(void) { unsigned long ulTxCount; unsigned long ulRxCount; // // Set the clocking to run from the PLL at 50MHz // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Enable 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[2JBulk device application\n"); // // Not configured initially. // g_bUSBConfigured = false; // // Enable the system tick. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND); ROM_SysTickIntEnable(); ROM_SysTickEnable(); // // 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, USB_MODE_DEVICE, 0); // // Pass our device information to the USB library and place the device // on the bus. // USBDBulkInit(0, &g_sBulkDevice); // // Wait for initial configuration to complete. // UARTprintf("Waiting for host...\n"); // // Clear our local byte counters. // ulRxCount = 0; ulTxCount = 0; // // Main application loop. // while(1) { // // See if any data has been transferred. // if((ulTxCount != g_ulTxCount) || (ulRxCount != g_ulRxCount)) { // // Take a snapshot of the latest transmit and receive counts. // ulTxCount = g_ulTxCount; ulRxCount = g_ulRxCount; // // Update the display of bytes transferred. // UARTprintf("\rTx: %d Rx: %d", ulTxCount, ulRxCount); } } }
//***************************************************************************** // //! Initializes the SDRAM. //! //! \param ulEPIDivider is the EPI clock divider to use. //! \param ulConfig is the SDRAM interface configuration. //! \param ulRefresh is the refresh count in core clocks (0-2047). //! //! This function must be called prior to ExtRAMAlloc() or ExtRAMFree(). It //! configures the Stellaris microcontroller EPI block for SDRAM access and //! initializes the SDRAM heap (if SDRAM is found). The parameter \e ulConfig //! is the logical OR of several sets of choices: //! //! The processor core frequency must be specified with one of the following: //! //! - \b EPI_SDRAM_CORE_FREQ_0_15 - core clock is 0 MHz < clk <= 15 MHz //! - \b EPI_SDRAM_CORE_FREQ_15_30 - core clock is 15 MHz < clk <= 30 MHz //! - \b EPI_SDRAM_CORE_FREQ_30_50 - core clock is 30 MHz < clk <= 50 MHz //! - \b EPI_SDRAM_CORE_FREQ_50_100 - core clock is 50 MHz < clk <= 100 MHz //! //! The low power mode is specified with one of the following: //! //! - \b EPI_SDRAM_LOW_POWER - enter low power, self-refresh state //! - \b EPI_SDRAM_FULL_POWER - normal operating state //! //! The SDRAM device size is specified with one of the following: //! //! - \b EPI_SDRAM_SIZE_64MBIT - 64 Mbit device (8 MB) //! - \b EPI_SDRAM_SIZE_128MBIT - 128 Mbit device (16 MB) //! - \b EPI_SDRAM_SIZE_256MBIT - 256 Mbit device (32 MB) //! - \b EPI_SDRAM_SIZE_512MBIT - 512 Mbit device (64 MB) //! //! The parameter \e ulRefresh sets the refresh counter in units of core //! clock ticks. It is an 11-bit value with a range of 0 - 2047 counts. //! //! \return Returns \b true on success of \b false if no SDRAM is found or //! any other error occurs. // //***************************************************************************** tBoolean SDRAMInit(unsigned long ulEPIDivider, unsigned long ulConfig, unsigned long ulRefresh) { // // Enable the EPI peripheral // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_EPI0); // // Configure the GPIO for communication with SDRAM. // #ifdef EPI_PORTA_PINS ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_GPIOPadConfigSet(GPIO_PORTA_BASE, EPI_PORTA_PINS, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); ROM_GPIODirModeSet(GPIO_PORTA_BASE, EPI_PORTA_PINS, GPIO_DIR_MODE_HW); #endif #ifdef EPI_GPIOB_PINS ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_GPIOPadConfigSet(GPIO_PORTB_BASE, EPI_GPIOB_PINS, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); ROM_GPIODirModeSet(GPIO_PORTB_BASE, EPI_GPIOB_PINS, GPIO_DIR_MODE_HW); #endif #ifdef EPI_PORTC_PINS ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); ROM_GPIOPadConfigSet(GPIO_PORTC_BASE, EPI_PORTC_PINS, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); ROM_GPIODirModeSet(GPIO_PORTC_BASE, EPI_PORTC_PINS, GPIO_DIR_MODE_HW); #endif #ifdef EPI_PORTD_PINS ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); ROM_GPIOPadConfigSet(GPIO_PORTD_BASE, EPI_PORTD_PINS, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); ROM_GPIODirModeSet(GPIO_PORTD_BASE, EPI_PORTD_PINS, GPIO_DIR_MODE_HW); #endif #ifdef EPI_PORTE_PINS ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); ROM_GPIOPadConfigSet(GPIO_PORTE_BASE, EPI_PORTE_PINS, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); ROM_GPIODirModeSet(GPIO_PORTE_BASE, EPI_PORTE_PINS, GPIO_DIR_MODE_HW); #endif #ifdef EPI_PORTF_PINS ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ROM_GPIOPadConfigSet(GPIO_PORTF_BASE, EPI_PORTF_PINS, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); ROM_GPIODirModeSet(GPIO_PORTF_BASE, EPI_PORTF_PINS, GPIO_DIR_MODE_HW); #endif #ifdef EPI_PORTG_PINS ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG); ROM_GPIOPadConfigSet(GPIO_PORTG_BASE, EPI_PORTG_PINS, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); ROM_GPIODirModeSet(GPIO_PORTG_BASE, EPI_PORTG_PINS, GPIO_DIR_MODE_HW); #endif #ifdef EPI_PORTH_PINS ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH); ROM_GPIOPadConfigSet(GPIO_PORTH_BASE, EPI_PORTH_PINS, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); ROM_GPIODirModeSet(GPIO_PORTH_BASE, EPI_PORTH_PINS, GPIO_DIR_MODE_HW); #endif #ifdef EPI_PORTJ_PINS ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ); ROM_GPIOPadConfigSet(GPIO_PORTJ_BASE, EPI_PORTJ_PINS, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); ROM_GPIODirModeSet(GPIO_PORTJ_BASE, EPI_PORTJ_PINS, GPIO_DIR_MODE_HW); #endif #if defined(EPI_CLK_PORT) && defined(EPI_CLK_PIN) ROM_GPIOPadConfigSet(EPI_CLK_PORT, EPI_CLK_PIN, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD_WPU); #endif // // Set the EPI divider. // EPIDividerSet(EPI0_BASE, ulEPIDivider); // // Select SDRAM mode. // EPIModeSet(EPI0_BASE, EPI_MODE_SDRAM); // // Configure SDRAM mode. // EPIConfigSDRAMSet(EPI0_BASE, ulConfig, ulRefresh); // // Set the address map. // EPIAddressMapSet(EPI0_BASE, EPI_ADDR_RAM_SIZE_256MB | EPI_ADDR_RAM_BASE_6); // // Set the EPI mem pointer to the base of EPI mem // g_pusEPIMem = (unsigned short *)0x60000000; // // Wait for the EPI initialization to complete. // while(HWREG(EPI0_BASE + EPI_O_STAT) & EPI_STAT_INITSEQ) { // // Wait for SDRAM initialization to complete. // } // // At this point, the SDRAM should be accessible. We attempt a couple // of writes then read back the memory to see if it seems to be there. // g_pusEPIMem[0] = 0xABCD; g_pusEPIMem[1] = 0x5AA5; // // Read back the patterns we just wrote to make sure they are valid. Note // that we declared g_pusEPIMem as volatile so the compiler should not // optimize these reads out of the image. // if((g_pusEPIMem[0] == 0xABCD) && (g_pusEPIMem[1] == 0x5AA5)) { // // The memory appears to be there so remember that we found it. // g_bSDRAMPresent = true; // // Now set up the heap that ExtRAMAlloc() and ExtRAMFree() will use. // bpool((void *)g_pusEPIMem, SDRAM_SIZE_BYTES); } // // If we get this far, the SDRAM heap has been successfully initialized. // return(g_bSDRAMPresent); }
//***************************************************************************** // // This is the main loop that runs the application. // //***************************************************************************** int main(void) { tRectangle sRect; tUSBMode eLastMode; char *pcString; // // 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 system clock to run at 50MHz from the PLL. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Initially wait for device connection. // g_eUSBState = STATE_NO_DEVICE; eLastMode = eUSBModeOTG; g_eCurrentUSBMode = eUSBModeOTG; // // Enable Clocking to the USB controller. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0); // // 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); // // Configure SysTick for a 100Hz interrupt. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / TICKS_PER_SECOND); ROM_SysTickEnable(); ROM_SysTickIntEnable(); // // Enable Interrupts // ROM_IntMasterEnable(); // // Configure UART0 for debug output. // ConfigureUART(); // // Initialize the USB stack mode and pass in a mode callback. // USBStackModeSet(0, eUSBModeOTG, ModeCallback); // // Register the host class drivers. // USBHCDRegisterDrivers(0, g_ppHostClassDrivers, g_ui32NumHostClassDrivers); // // Open an instance of the keyboard driver. The keyboard does not need // to be present at this time, this just save a place for it and allows // the applications to be notified when a keyboard is present. // g_psKeyboardInstance = USBHKeyboardOpen(KeyboardCallback, g_pui8Buffer, KEYBOARD_MEMORY_SIZE); // // Initialize the power configuration. This sets the power enable signal // to be active high and does not enable the power fault. // USBHCDPowerConfigInit(0, USBHCD_VBUS_AUTO_HIGH | USBHCD_VBUS_FILTER); // // Initialize the USB controller for OTG operation with a 2ms polling // rate. // USBOTGModeInit(0, 2000, g_pui8HCDPool, HCD_MEMORY_SIZE); // // Initialize the display driver. // CFAL96x64x16Init(); // // Initialize the graphics context. // 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 = (2 * DISPLAY_BANNER_HEIGHT) - 1; GrContextForegroundSet(&g_sContext, DISPLAY_BANNER_BG); GrRectFill(&g_sContext, &sRect); // // Change foreground for white text. // GrContextForegroundSet(&g_sContext, DISPLAY_TEXT_FG); // // Put the application name in the middle of the banner. // GrContextFontSet(&g_sContext, g_psFontFixed6x8); GrStringDrawCentered(&g_sContext, "usb-host-", -1, GrContextDpyWidthGet(&g_sContext) / 2, 4, 0); GrStringDrawCentered(&g_sContext, "keyboard", -1, GrContextDpyWidthGet(&g_sContext) / 2, 14, 0); // // Calculate the number of characters that will fit on a line. // Make sure to leave a small border for the text box. // g_ui32CharsPerLine = (GrContextDpyWidthGet(&g_sContext) - 4) / GrFontMaxWidthGet(g_psFontFixed6x8); // // Calculate the number of lines per usable text screen. This requires // taking off space for the top and bottom banners and adding a small bit // for a border. // g_ui32LinesPerScreen = (GrContextDpyHeightGet(&g_sContext) - (3*(DISPLAY_BANNER_HEIGHT + 1)))/ GrFontHeightGet(g_psFontFixed6x8); // // Open and instance of the keyboard class driver. // UARTprintf("Host Keyboard Application\n"); // // Initial update of the screen. // UpdateStatus(); // // The main loop for the application. // while(1) { // // Tell the OTG library code how much time has passed in // milliseconds since the last call. // USBOTGMain(GetTickms()); // // Has the USB mode changed since last time we checked? // if(g_eCurrentUSBMode != eLastMode) { // // Remember the new mode. // eLastMode = g_eCurrentUSBMode; switch(eLastMode) { case eUSBModeHost: pcString = "HOST"; break; case eUSBModeDevice: pcString = "DEVICE"; break; case eUSBModeNone: pcString = "NONE"; break; default: pcString = "UNKNOWN"; break; } UARTprintf("USB mode changed to %s\n", pcString); } switch(g_eUSBState) { // // This state is entered when they keyboard is first detected. // case STATE_KEYBOARD_INIT: { // // Initialized the newly connected keyboard. // USBHKeyboardInit(g_psKeyboardInstance); // // Proceed to the keyboard connected state. // g_eUSBState = STATE_KEYBOARD_CONNECTED; // // Update the screen now that the keyboard has been // initialized. // UpdateStatus(); USBHKeyboardModifierSet(g_psKeyboardInstance, g_ui32Modifiers); break; } case STATE_KEYBOARD_UPDATE: { // // If the application detected a change that required an // update to be sent to the keyboard to change the modifier // state then call it and return to the connected state. // g_eUSBState = STATE_KEYBOARD_CONNECTED; USBHKeyboardModifierSet(g_psKeyboardInstance, g_ui32Modifiers); break; } case STATE_KEYBOARD_CONNECTED: { // // Nothing is currently done in the main loop when the keyboard // is connected. // break; } case STATE_UNKNOWN_DEVICE: { // // Nothing to do as the device is unknown. // break; } case STATE_NO_DEVICE: { // // Nothing is currently done in the main loop when the keyboard // is not connected. // break; } default: { break; } } } }
//***************************************************************************** // // Initialize the DES and CCM modules. // //***************************************************************************** bool DESInit(void) { uint32_t ui32Loop; // // Check that the CCM peripheral is present. // if(!ROM_SysCtlPeripheralPresent(SYSCTL_PERIPH_CCM0)) { UARTprintf("No CCM peripheral found!\n"); // // Return failure. // return(false); } // // The hardware is available, enable it. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_CCM0); // // Wait for the peripheral to be ready. // ui32Loop = 0; while(!ROM_SysCtlPeripheralReady(SYSCTL_PERIPH_CCM0)) { // // Increment our poll counter. // ui32Loop++; if(ui32Loop > CCM_LOOP_TIMEOUT) { // // Timed out, notify and spin. // UARTprintf("Time out on CCM ready after enable.\n"); // // Return failure. // return(false); } } // // Reset the peripheral to ensure we are starting from a known condition. // ROM_SysCtlPeripheralReset(SYSCTL_PERIPH_CCM0); // // Wait for the peripheral to be ready again. // ui32Loop = 0; while(!ROM_SysCtlPeripheralReady(SYSCTL_PERIPH_CCM0)) { // // Increment our poll counter. // ui32Loop++; if(ui32Loop > CCM_LOOP_TIMEOUT) { // // Timed out, spin. // UARTprintf("Time out on CCM ready after reset.\n"); // // Return failure. // return(false); } } // // Return initialization success. // return(true); }
//***************************************************************************** // // Main application entry function. // //***************************************************************************** int main(void) { tBoolean bRetcode; smplStatus_t eRetcode; ioctlScanChan_t sScan; freqEntry_t pFreq[NWK_FREQ_TBL_SIZE]; tBoolean bFirstTimeThrough; unsigned long ulLoop; uint8_t ucLast; // // Set the system clock to run at 50MHz from the PLL // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // NB: We don't call PinoutSet() in this testcase since the EM header // expansion board doesn't currently have an I2C ID EEPROM. If we did // call PinoutSet() this would configure all the EPI pins for SDRAM and // we don't want to do this. // g_eDaughterType = DAUGHTER_NONE; // // Enable peripherals required to drive the LCD. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH); // // Configure SysTick for a 10Hz interrupt. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / TICKS_PER_SECOND); ROM_SysTickEnable(); ROM_SysTickIntEnable(); // // Initialize the display driver. // Kitronix320x240x16_SSD2119Init(); // // Initialize the touch screen driver. // TouchScreenInit(); // // Set the touch screen event handler. // TouchScreenCallbackSet(WidgetPointerMessage); // // Add the compile-time defined widgets to the widget tree. // WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sHeading); // // Initialize the status string. // UpdateStatus("Initializing..."); // // Paint the widget tree to make sure they all appear on the display. // WidgetPaint(WIDGET_ROOT); // // Initialize the SimpliciTI BSP. // BSP_Init(); // // Set the SimpliciTI device address using the current Ethernet MAC address // to ensure something like uniqueness. // bRetcode = SetSimpliciTIAddress(); // // Did we have a problem with the address? // if(!bRetcode) { // // Yes - make sure the display is updated then hang the app. // WidgetMessageQueueProcess(); while(1) { // // MAC address is not set so hang the app. // } } // // Turn on both our LEDs // SetLED(1, true); SetLED(2, true); UpdateStatus("Joining network..."); // // Initialize the SimpliciTI stack but don't set any receive callback. // while(1) { eRetcode = SMPL_Init((uint8_t (*)(linkID_t))0); if(eRetcode == SMPL_SUCCESS) { break; } ToggleLED(1); ToggleLED(2); SPIN_ABOUT_A_SECOND; } // // Tell the user what's up. // UpdateStatus("Sniffing..."); // // Set up for our first sniff. // sScan.freq = pFreq; bFirstTimeThrough = true; ucLast = 0xFF; // // Keep sniffing forever. // while (1) { // // Wait a while. // SPIN_ABOUT_A_QUARTER_SECOND; // // Scan for the active channel. // SMPL_Ioctl(IOCTL_OBJ_FREQ, IOCTL_ACT_SCAN, &sScan); // // Did we find a signal? // if (1 == sScan.numChan) { if (bFirstTimeThrough) { // // Set the initial LED state. // SetLED(1, false); SetLED(2, true); // // Wait a while. // for(ulLoop = 0; ulLoop < 15; ulLoop--) { // // Toggle both LEDs and wait a bit. // ToggleLED(1); ToggleLED(2); SPIN_ABOUT_A_QUARTER_SECOND; } bFirstTimeThrough = false; } // // Has the channel changed since the last time we updated the // display? // if(pFreq[0].logicalChan != ucLast) { // // Remember the channel we just detected. // ucLast = pFreq[0].logicalChan; // // Tell the user which channel we found to be active. // UpdateStatus("Active channel is %d.", pFreq[0].logicalChan); // // Set the "LEDs" to mimic the behavior of the MSP430 versions // of this application. // switch(pFreq[0].logicalChan) { case 0: { /* GREEN OFF */ /* RED OFF */ SetLED(1, false); SetLED(2, false); break; } case 1: { /* GREEN OFF */ /* RED ON */ SetLED(1, false); SetLED(2, true); break; } case 2: { /* GREEN ON */ /* RED OFF */ SetLED(1, true); SetLED(2, false); break; } case 3: { /* GREEN ON */ /* RED ON */ SetLED(1, true); SetLED(2, true); break; } case 4: { /* blink them both... */ SetLED(1, false); SetLED(2, false); SPIN_ABOUT_A_QUARTER_SECOND; SetLED(1, true); SetLED(2, true); SPIN_ABOUT_A_QUARTER_SECOND; SetLED(1, false); SetLED(2, false); } } } } } }
//***************************************************************************** // // This example demonstrates how to send a string of data to the UART. // //***************************************************************************** int main(void) { // // Enable lazy stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // ROM_FPUEnable(); ROM_FPULazyStackingEnable(); // // Set the clocking to run directly from the crystal. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Enable the GPIO port that is used for the on-board LED. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // // Enable the GPIO pins for the LED (PF2). // ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2); // // Enable the peripherals used by this example. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // // Enable processor interrupts. // ROM_IntMasterEnable(); // // Set GPIO A0 and A1 as UART pins. // GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // Configure the UART for 115,200, 8-N-1 operation. // ROM_UARTConfigSetExpClk(UART0_BASE, ROM_SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); // // Enable the UART interrupt. // ROM_IntEnable(INT_UART0); ROM_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT); // // Prompt for text to be entered. // UARTSend((uint8_t *)"\033[2JEnter text: ", 16); // // Loop forever echoing data through the UART. // while(1) { } }
//***************************************************************************** // //! Configures the device pins for the standard usages on the EK-TM4C1294XL. //! //! \param bEthernet is a boolean used to determine function of Ethernet pins. //! If true Ethernet pins are configured as Ethernet LEDs. If false GPIO are //! available for application use. //! \param bUSB is a boolean used to determine function of USB pins. If true USB //! pins are configured for USB use. If false then USB pins are available for //! application use as GPIO. //! //! This function enables the GPIO modules and configures the device pins for //! the default, standard usages on the EK-TM4C1294XL. Applications that //! require alternate configurations of the device pins can either not call //! this function and take full responsibility for configuring all the device //! pins, or can reconfigure the required device pins after calling this //! function. //! //! \return None. // //***************************************************************************** void PinoutSet(bool bEthernet, bool bUSB) { // // Enable all the GPIO peripherals. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOM); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOP); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOQ); // // PA0-1 are used for UART0. // ROM_GPIOPinConfigure(GPIO_PA0_U0RX); ROM_GPIOPinConfigure(GPIO_PA1_U0TX); ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // PB0-1/PD6/PL6-7 are used for USB. // PQ4 can be used as a power fault detect on this board but it is not // the hardware peripheral power fault input pin. // if(bUSB) { HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY; HWREG(GPIO_PORTD_BASE + GPIO_O_CR) = 0xff; ROM_GPIOPinConfigure(GPIO_PD6_USB0EPEN); ROM_GPIOPinTypeUSBAnalog(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1); ROM_GPIOPinTypeUSBDigital(GPIO_PORTD_BASE, GPIO_PIN_6); ROM_GPIOPinTypeUSBAnalog(GPIO_PORTL_BASE, GPIO_PIN_6 | GPIO_PIN_7); ROM_GPIOPinTypeGPIOInput(GPIO_PORTQ_BASE, GPIO_PIN_4); } else { // // Keep the default config for most pins used by USB. // Add a pull down to PD6 to turn off the TPS2052 switch // ROM_GPIOPinTypeGPIOInput(GPIO_PORTD_BASE, GPIO_PIN_6); MAP_GPIOPadConfigSet(GPIO_PORTD_BASE, GPIO_PIN_6, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPD); } // // PF0/PF4 are used for Ethernet LEDs. // if(bEthernet) { // // this app wants to configure for ethernet LED function. // ROM_GPIOPinConfigure(GPIO_PF0_EN0LED0); ROM_GPIOPinConfigure(GPIO_PF4_EN0LED1); GPIOPinTypeEthernetLED(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_4); } else { // // This app does not want Ethernet LED function so configure as // standard outputs for LED driving. // ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_4); // // Default the LEDs to OFF. // ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_4, 0); MAP_GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_4, GPIO_STRENGTH_12MA, GPIO_PIN_TYPE_STD); } // // PJ0 and J1 are used for user buttons // ROM_GPIOPinTypeGPIOInput(GPIO_PORTJ_BASE, GPIO_PIN_0 | GPIO_PIN_1); ROM_GPIOPinWrite(GPIO_PORTJ_BASE, GPIO_PIN_0 | GPIO_PIN_1, 0); // // PN0 and PN1 are used for USER LEDs. // ROM_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0 | GPIO_PIN_1); MAP_GPIOPadConfigSet(GPIO_PORTN_BASE, GPIO_PIN_0 | GPIO_PIN_1, GPIO_STRENGTH_12MA, GPIO_PIN_TYPE_STD); // // Default the LEDs to OFF. // ROM_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0 | GPIO_PIN_1, 0); }