//***************************************************************************** // // The callback function that is called by the sound driver to indicate that // half of the sound buffer has been played. // //***************************************************************************** void SoundCallback(uint32_t ui32Half) { // // See which half of the sound buffer has been played. // if(ui32Half == 0) { // // The first half of the sound buffer needs to be filled. // HWREGBITW(&g_ui32Flags, FLAG_PING) = 1; } else { // // The second half of the sound buffer needs to be filled. // HWREGBITW(&g_ui32Flags, FLAG_PONG) = 1; } }
//***************************************************************************** // // Delay for a multiple of the system tick clock rate. // //***************************************************************************** static void Delay(unsigned long ulCount) { // // Loop while there are more clock ticks to wait for. // while(ulCount--) { // // Wait until a SysTick interrupt has occurred. // while(!HWREGBITW(&g_ulFlags, FLAG_CLOCK_TICK)) { } // // Clear the SysTick interrupt flag. // HWREGBITW(&g_ulFlags, FLAG_CLOCK_TICK) = 0; } }
void DataReadyIntHandler(void) { uint8_t p = ROM_GPIOPinIntStatus(ADS_DRY_PORT, true) & 0xFF; MAP_IntDisable(INT_GPIOC); MAP_GPIOPinIntDisable(ADS_DRY_PORT, ADS_DRY_PIN); GPIOPinIntClear(ADS_DRY_PORT, p); HWREGBITW(&g_ulFlags, FLAG_ADS_INT) = 1; }
//! Initialize the OLED display. //! \param ulFrequency specifies the SSI Clock Frequency to be used. //OLED初始化 void OLED_Init(unsigned long ulFrequency) { unsigned long ulIdx; // // Enable the SSI0 and GPIO port blocks as they are needed by this driver. // SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIO_OLEDDC); // // Configure the SSI0CLK and SSIOTX pins for SSI operation. // GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_5); GPIOPadConfigSet(GPIO_PORTA_BASE, GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_5, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD_WPU); // // Configure the GPIO port pin used as a D/Cn signal for OLED device, // and the port pin used to enable power to the OLED panel. // GPIOPinTypeGPIOOutput(GPIO_OLEDDC_BASE, GPIO_OLEDDC_PIN | GPIO_OLEDEN_PIN); GPIOPadConfigSet(GPIO_OLEDDC_BASE, GPIO_OLEDDC_PIN | GPIO_OLEDEN_PIN, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD); GPIOPinWrite(GPIO_OLEDDC_BASE, GPIO_OLEDDC_PIN | GPIO_OLEDEN_PIN, GPIO_OLEDDC_PIN | GPIO_OLEDEN_PIN); HWREGBITW(&g_ulSSIFlags, FLAG_DC_HIGH) = 1; // // Configure and enable the SSI0 port for master mode. // OLED_Enable(ulFrequency); // // Clear the frame buffer. // OLED_Clear(); // // Initialize the SSD1329 controller. Loop through the initialization // sequence array, sending each command "string" to the controller. // for(ulIdx = 0; ulIdx < sizeof(OLED_INIT_CMD); ulIdx += OLED_INIT_CMD[ulIdx] + 1) { // // Send this command. // RITWriteCommand(OLED_INIT_CMD + ulIdx + 1, OLED_INIT_CMD[ulIdx] - 1); } }
//***************************************************************************** // // This function delays for the specified number of milliseconds. // //***************************************************************************** static void Delay(unsigned long ulNumMS) { // // Loop one time per millisecond. // for(; ulNumMS != 0; ulNumMS--) { // // Clear the tick flag. // HWREGBITW(&g_ulFlags, FLAG_TICK) = 0; // // Wait until the tick flag is set. // while(HWREGBITW(&g_ulFlags, FLAG_TICK) == 0) { } } }
//***************************************************************************** // // The interrupt handler for the first timer interrupt. // //***************************************************************************** void Timer0IntHandler(void) { // // Clear the timer interrupt. // ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT); // // Toggle the flag for the first timer. // HWREGBITW(&g_ui32Flags, 0) ^= 1; // // Update the interrupt status on the display. // ROM_IntMasterDisable(); GrStringDraw(&g_sContext, (HWREGBITW(&g_ui32Flags, 0) ? "1" : "0"), -1, 68, 26, 1); ROM_IntMasterEnable(); }
//**************************************************************************** // // Generic event handler for the composite device. // //**************************************************************************** unsigned long EventHandler(void *pvCBData, unsigned long ulEvent, unsigned long ulMsgData, void *pvMsgData) { switch(ulEvent) { // // The host has connected to us and configured the device. // case USB_EVENT_CONNECTED: { // // Now connected. // HWREGBITW(&g_ulFlags, FLAG_CONNECTED) = 1; break; } // // Handle the disconnect state. // case USB_EVENT_DISCONNECTED: { // // No longer connected. // HWREGBITW(&g_ulFlags, FLAG_CONNECTED) = 0; break; } default: { break; } } return(0); }
//***************************************************************************** // // TCP connect // // This function attempts to connect to a TCP endpoint. // // \return None. // //***************************************************************************** err_t EthClientTCPConnect(uint32_t ui32Port) { err_t eTCPReturnCode; // // Enable the TCP timer function calls. // HWREGBITW(&g_sEnet.ui32Flags, FLAG_TIMER_TCP_EN) = 1; if(g_sEnet.psTCP) { // // Initially clear out all of the TCP callbacks. // tcp_sent(g_sEnet.psTCP, NULL); tcp_recv(g_sEnet.psTCP, NULL); tcp_err(g_sEnet.psTCP, NULL); // // Make sure there is no lingering TCP connection. // tcp_close(g_sEnet.psTCP); } // // Create a new TCP socket. // g_sEnet.psTCP = tcp_new(); // // Check if you need to go through a proxy. // if(g_sEnet.pcProxyName != 0) { // // Attempt to connect through the proxy server. // eTCPReturnCode = tcp_connect(g_sEnet.psTCP, &g_sEnet.sServerIP, ui32Port, TCPConnected); } else { // // Attempt to connect to the server directly. // eTCPReturnCode = tcp_connect(g_sEnet.psTCP, &g_sEnet.sServerIP, ui32Port, TCPConnected); } return(eTCPReturnCode); }
//***************************************************************************** // // This function sets the position and comparison of the reverse soft limit // switch. // //***************************************************************************** void LimitPositionReverseSet(long lPosition, unsigned long ulLessThan) { // // Save the positino of the reverse limit switch. // g_lLimitReverse = lPosition; // // Save the comparison flag. // HWREGBITW(&g_ulLimitFlags, LIMIT_FLAG_REV_LT) = ulLessThan ? 1 : 0; }
//***************************************************************************** // // This function sets the position and comparison of the forward soft limit // switch. // //***************************************************************************** void LimitPositionForwardSet(long lPosition, unsigned long ulLessThan) { // // Save the position of the forward limit switch. // g_lLimitForward = lPosition; // // Save the comparison flag. // HWREGBITW(&g_ulLimitFlags, LIMIT_FLAG_FWD_LT) = ulLessThan ? 1 : 0; }
//***************************************************************************** // // In this particular example, this function merely updates an interrupt // count and sets a flag which tells the main loop to update the display. // // TODO: Update or remove this function as required by your specific // application. // //***************************************************************************** void ProcessInterrupt(void) { // // Update our interrupt counter. // g_ui32IntCount++; // // Toggle the interrupt flag telling the main loop to update the display. // HWREGBITW(&g_ui32Flags, 0) ^= 1; }
//**************************************************************************** // // This is the interrupt handler for the SysTick interrupt. It is called // periodically and updates a global tick counter then sets a flag to tell the // main loop to move the mouse. // //**************************************************************************** void SysTickHandler(void) { // // Increment the current tick count. // g_ulSysTickCount++; // // Set a tick event for the mouse device. // HWREGBITW(&g_ulFlags, FLAG_MOVE_UPDATE) = 1; }
//***************************************************************************** // // The interrupt handler for the SysTick interrupt. // //***************************************************************************** void SysTickIntHandler(void) { // // Increment the system tick count. // g_ui32TickCounter++; // // Indicate that a SysTick interrupt has occurred. // HWREGBITW(&g_ui32Flags, FLAG_SYSTICK) = 1; }
//***************************************************************************** // // This function is called by SysTick once every millisecond. // //***************************************************************************** void SysTickIntHandler(void) { unsigned long ulButtons, ulIdx; // // Set the flag that indicates that a timer tick has occurred. // HWREGBITW(&g_ulFlags, FLAG_TICK) = 1; // // Increment the count of ticks. // g_ulTickCount++; // // Call the CAN periodic tick function. // CANTick(); // // Call the push button periodic tick function. // ulButtons = ButtonsTick(); // // Set the appropriate button press flags if the corresponding button was // pressed. // for(ulIdx = 0; ulIdx < (sizeof(g_ppulButtonMap) / sizeof(g_ppulButtonMap[0])); ulIdx++) { if(ulButtons & g_ppulButtonMap[ulIdx][0]) { HWREGBITW(&g_ulFlags, g_ppulButtonMap[ulIdx][1]) = 1; } } }
//adc ISR function void adcIsr(UArg a0) { // Pop sample from FIFO to allow clearing ADC_IRQ event singleSample = AUXADCReadFifo(); printf ("ADC: %d\r\n",singleSample); // Clear ADC_IRQ flag. Note: Missing driver for this. HWREGBITW(AUX_EVCTL_BASE + AUX_EVCTL_O_EVTOMCUFLAGSCLR, AUX_EVCTL_EVTOMCUFLAGSCLR_ADC_IRQ_BITN) = 1; // Post semaphore to wakeup task Semaphore_post(hSem); }
//***************************************************************************** // //! Disables the sound output. //! //! This function disables the sound output, muting the speaker and cancelling //! any playback that may be in progress. //! //! \return None. // //***************************************************************************** void SoundDisable(void) { // // Cancel any song or sound effect playback that may be in progress. // g_pusMusic = 0; // // Indicate that there are no more pending transfers. // HWREGBITW(&g_ulDMAFlags, FLAG_TX_PENDING) = 0; }
//**************************************************************************** // // This function handles notification messages from the mouse device driver. // //**************************************************************************** unsigned long MouseHandler(void *pvCBData, unsigned long ulEvent, unsigned long ulMsgData, void *pvMsgData) { switch(ulEvent) { // // The USB host has connected to and configured the device. // case USB_EVENT_CONNECTED: { g_eMouseState = MOUSE_STATE_IDLE; HWREGBITW(&g_ulFlags, FLAG_CONNECTED) = 1; break; } // // The USB host has disconnected from the device. // case USB_EVENT_DISCONNECTED: { HWREGBITW(&g_ulFlags, FLAG_CONNECTED) = 0; g_eMouseState = MOUSE_STATE_UNCONFIGURED; break; } // // A report was sent to the host. We are not free to send another. // case USB_EVENT_TX_COMPLETE: { g_eMouseState = MOUSE_STATE_IDLE; break; } } return(0); }
//***************************************************************************** // // Initialize the Ethernet client // // This function initializes all the Ethernet components to not configured. // This tells the SysTick interrupt which timer modules to call. // // \return None. // //***************************************************************************** void EthClientInit(tEventFunction pfnEvent) { uint32_t ui32User0, ui32User1; // // Initialize all the Ethernet components to not configured. This tells // the SysTick interrupt which timer modules to call. // HWREGBITW(&g_sEnet.ui32Flags, FLAG_TIMER_DHCP_EN) = 0; HWREGBITW(&g_sEnet.ui32Flags, FLAG_TIMER_DNS_EN) = 0; HWREGBITW(&g_sEnet.ui32Flags, FLAG_TIMER_TCP_EN) = 0; g_sEnet.eState = iEthNoConnection; g_sEnet.pfnEvent = pfnEvent; // // Convert the 24/24 split MAC address from NV ram into a 32/16 split MAC // address needed to program the hardware registers, then program the MAC // address into the Ethernet Controller registers. // FlashUserGet(&ui32User0, &ui32User1); g_sEnet.pui8MACAddr[0] = ((ui32User0 >> 0) & 0xff); g_sEnet.pui8MACAddr[1] = ((ui32User0 >> 8) & 0xff); g_sEnet.pui8MACAddr[2] = ((ui32User0 >> 16) & 0xff); g_sEnet.pui8MACAddr[3] = ((ui32User1 >> 0) & 0xff); g_sEnet.pui8MACAddr[4] = ((ui32User1 >> 8) & 0xff); g_sEnet.pui8MACAddr[5] = ((ui32User1 >> 16) & 0xff); lwIPInit(g_ui32SysClock, g_sEnet.pui8MACAddr, 0, 0, 0, IPADDR_USE_DHCP); // // Start lwIP tick interrupt. // HWREGBITW(&g_sEnet.ui32Flags, FLAG_TIMER_DHCP_EN) = 1; }
//***************************************************************************** // // This function was the callback function registered with the USB host audio // class driver. The only two events that are handled at this point are the // USBH_AUDIO_EVENT_OPEN and USBH_AUDIO_EVENT_CLOSE which indicate that a new // audio device has been found or that an existing audio device has been // disconnected. // //***************************************************************************** static void AudioCallback(tUSBHostAudioInstance *psAudioInstance, uint32_t ui32Event, uint32_t ui32MsgParam, void *pvBuffer) { switch(ui32Event) { // // New USB audio device has been enabled. // case USBH_AUDIO_EVENT_OPEN: { // // Set the EVENT_OPEN flag and let the main routine handle it. // HWREGBITW(&g_sAudioState.ui32EventFlags, EVENT_OPEN) = 1; break; } // // USB audio device has been removed. // case USBH_AUDIO_EVENT_CLOSE: { // // Set the EVENT_CLOSE flag and let the main routine handle it. // HWREGBITW(&g_sAudioState.ui32EventFlags, EVENT_CLOSE) = 1; break; } default: { } } }
//***************************************************************************** // // This function delays for the specified number of milliseconds, aborting the // delay if the CAN update ACK is received. // //***************************************************************************** static unsigned long DelayAck(unsigned long ulNumMS) { // // Loop one time per millisecond while the CAN update ACK has not been // received. // for(; (ulNumMS != 0) && (g_ulCANUpdateAck == 0); ulNumMS--) { // // Clear the tick flag. // HWREGBITW(&g_ulFlags, FLAG_TICK) = 0; // // Wait until the tick flag is set or the the CAN update ACK has been // received. // while((HWREGBITW(&g_ulFlags, FLAG_TICK) == 0) && (g_ulCANUpdateAck == 0)) { } // // If the CAN update ACK was received, return and indication of that // fact. // if(g_ulCANUpdateAck == 1) { return(1); } } // // The delay completed before the CAN update ACK was received. // return(0); }
//***************************************************************************** // // Indicates that an enumeration response should be sent for this device. // //***************************************************************************** void UARTIFPStatus(void) { // // Set the Periodic Status flag. // HWREGBITW(&g_ulUARTFlags, UART_FLAG_PSTATUS) = 1; // // Generate a fake UART interrupt, during which the enumeration response // will be sent. // HWREG(NVIC_SW_TRIG) = INT_UART0 - 16; }
//***************************************************************************** // // Take as many bytes from the transmit buffer as we have space for and move // them into the USB UART's transmit FIFO. // //***************************************************************************** static void USBUARTPrimeTransmit(uint32_t ui32Base) { uint32_t ui32Read; uint8_t ui8Char; // // If we are currently sending a break condition, don't receive any // more data. We will resume transmission once the break is turned off. // if(HWREGBITW(&g_ui32Flags, FLAG_SENDING_BREAK)) { return; } // // If there is space in the UART FIFO, try to read some characters // from the receive buffer to fill it again. // while(UARTSpaceAvail(ui32Base)) { // // Get a character from the buffer. // ui32Read = USBBufferRead((tUSBBuffer *)&g_sRxBuffer, &ui8Char, 1); // // Did we get a character? // if(ui32Read) { // // Place the character in the UART transmit FIFO. // ROM_UARTCharPutNonBlocking(ui32Base, ui8Char); // // Update our count of bytes transmitted via the UART. // g_ui32UARTTxCount++; } else { // // We ran out of characters so exit the function. // return; } } }
//***************************************************************************** // // This function sets or clears a break condition on the redirected UART RX // line. A break is started when the function is called with \e bSend set to // \b true and persists until the function is called again with \e bSend set // to \b false. // //***************************************************************************** static void SendBreak(bool bSend) { // // Are we being asked to start or stop the break condition? // if(!bSend) { // // Remove the break condition on the line. // ROM_UARTBreakCtl(UART0_BASE, false); HWREGBITW(&g_ui32Flags, FLAG_SENDING_BREAK) = 0; } else { // // Start sending a break condition on the line. // ROM_UARTBreakCtl(UART0_BASE, true); HWREGBITW(&g_ui32Flags, FLAG_SENDING_BREAK) = 1; } }
//***************************************************************************** // // Indicates that an enumeration response should be sent for this device. // //***************************************************************************** void UARTIFEnumerate(void) { // // Set the enumeration response flag. // HWREGBITW(&g_ulUARTFlags, UART_FLAG_ENUM) = 1; // // Generate a fake UART interrupt, during which the enumeration response // will be sent. // HWREG(NVIC_SW_TRIG) = INT_UART0 - 16; }
//***************************************************************************** // // The interrupt handler for the timer interrupt. // //***************************************************************************** void Timer0IntHandler(void) { // // Clear the timer interrupt. // ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT); // // Toggle the flag for the timer. // HWREGBITW(&g_ulFlags, 0) = 1; GPIOPinWrite(STP1_BASE, STP1_PLS, STP1_PLS); SysCtlDelay(SysCtlClockGet() / 500000); GPIOPinWrite(STP1_BASE, STP1_PLS, 0x00); }
//***************************************************************************** // // The interrupt handler for the second timer interrupt. (temperature) // //***************************************************************************** void Timer1IntHandler(void) { // // Clear the timer interrupt. // ROM_TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT); // // Clear ADC interrupt // ROM_ADCIntClear(ADC0_BASE, 3); //Increment Timer A Count TimerBCount++; /*// // Use the flags to Toggle the LED for this timer // GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, g_ui32Flags);*/ // // Toggle the flag for the temperature timer. // HWREGBITW(&g_ui32InterruptFlags, 0) = 1; // // Trigger ADC Conversion // ROM_ADCProcessorTrigger(ADC0_BASE, 3); // //Wait for ADC conversion to complete // while(!ROM_ADCIntStatus(ADC0_BASE, 3, false)) { //Wait for ADC to finish sampling } ROM_ADCSequenceDataGet(ADC0_BASE, 3, adc_value); //Get data from Sequencer 3 // // Update the interrupt status. // //ROM_IntMasterDisable(); //UARTprintf("ADC Value = %d\n", adc_value[0]); //Print out the first (and only) value //ROM_IntMasterEnable(); }
//***************************************************************************** // // Determines if a given point collides with one of the spiders. The spider // specified is ignored when doing collision detection in order to prevent a // false collision with itself (when checking to see if it is safe to move the // spider). // //***************************************************************************** static int32_t SpiderCollide(int32_t i32Spider, int32_t i32X, int32_t i32Y) { int32_t i32Idx, i32DX, i32DY; // // Loop through all the spiders. // for(i32Idx = 0; i32Idx < MAX_SPIDERS; i32Idx++) { // // Skip this spider if it is not alive or is the spider that should be // ignored. // if((HWREGBITW(&g_ui32SpiderAlive, i32Idx) == 0) || (i32Idx == i32Spider)) { continue; } // // Compute the horizontal and vertical difference between this spider's // position and the point in question. // i32DX = ((g_pi32SpiderX[i32Idx] > i32X) ? (g_pi32SpiderX[i32Idx] - i32X) : (i32X - g_pi32SpiderX[i32Idx])); i32DY = ((g_pi32SpiderY[i32Idx] > i32Y) ? (g_pi32SpiderY[i32Idx] - i32Y) : (i32Y - g_pi32SpiderY[i32Idx])); // // Return this spider index if the point in question collides with it. // if((i32DX < SPIDER_WIDTH) && (i32DY < SPIDER_HEIGHT)) { return(i32Idx); } } // // No collision was detected. // return(-1); }
//***************************************************************************** // // Handler for the "LinkListen" button. // //***************************************************************************** void OnListenButtonPress(tWidget *pWidget) { // // Tell the user we're switching into "LinkFrom" mode. // UpdateStatus(true, "Running as listener (LinkListen)"); // // Set the mode we will be running in. // g_ulMode = MODE_LISTENER; // // Tell the main loop to go ahead and start communication. // HWREGBITW(&g_ulCommandFlags, COMMAND_MODE_SET) = 1; }
//***************************************************************************** // // Enable the Speex encoder/decoder and allow the quality setting to be set // by a single decimal argument. // //***************************************************************************** int Cmd_speex(int argc, char *argv[]) { unsigned long ulTemp; // // Clear the pass through flag. // HWREGBITW(&g_ulFlags, FLAG_BYPASS) = 0; // // Check for an argument that is specifying a quality setting. // if(argc == 2) { // // Convert the value to a numeric value. // ulTemp = ustrtoul(argv[1], 0, 10); // // Rail the quality setting at 4. // if(ulTemp <= 4) { g_iQuality = (int)ulTemp; // // Set the quality setting. // SpeexEncodeQualitySet(g_iQuality); UARTprintf("Speex Encoder Quality set to %d\n", g_iQuality); } else { UARTprintf("Encoder Quality not changed, value must be (1-4).\n"); } } return(0); }
//***************************************************************************** // // Determines if a given point collides with one of the spiders. The spider // specified is ignored when doing collision detection in order to prevent a // false collision with itself (when checking to see if it is safe to move the // spider). // //***************************************************************************** static long SpiderCollide(long lSpider, long lX, long lY) { long lIdx, lDX, lDY; // // Loop through all the spiders. // for(lIdx = 0; lIdx < MAX_SPIDERS; lIdx++) { // // Skip this spider if it is not alive or is the spider that should be // ignored. // if((HWREGBITW(&g_ulSpiderAlive, lIdx) == 0) || (lIdx == lSpider)) { continue; } // // Compute the horizontal and vertical difference between this spider's // position and the point in question. // lDX = ((g_plSpiderX[lIdx] > lX) ? (g_plSpiderX[lIdx] - lX) : (lX - g_plSpiderX[lIdx])); lDY = ((g_plSpiderY[lIdx] > lY) ? (g_plSpiderY[lIdx] - lY) : (lY - g_plSpiderY[lIdx])); // // Return this spider index if the point in question collides with it. // if((lDX < SPIDER_WIDTH) && (lDY < SPIDER_HEIGHT)) { return(lIdx); } } // // No collision was detected. // return(-1); }