⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ui.c

📁 luminary芯片直流无刷电机控制程序
💻 C
字号:
//*****************************************************************************//// ui.c - Simple serial port user interface.//// Copyright (c) 2005,2006 Luminary Micro, Inc.  All rights reserved.//// Software License Agreement//// Luminary Micro, Inc. (LMI) is supplying this software for use solely and// exclusively on LMI's microcontroller products.//// The software is owned by LMI and/or its suppliers, and is protected under// applicable copyright laws.  All rights are reserved.  Any use in violation// of the foregoing restrictions may subject the user to criminal sanctions// under applicable laws, as well as to civil liability for the breach of the// terms and conditions of this license.//// THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED// OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.// LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR// CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.//// This is part of revision 196 of an01238.////*****************************************************************************#include "../../hw_ints.h"#include "../../hw_memmap.h"#include "../../hw_types.h"#include "../../src/gpio.h"#include "../../src/interrupt.h"#include "../../src/sysctl.h"#include "../../src/uart.h"#include "ui.h"//*****************************************************************************//// The description of the user interface being used.////*****************************************************************************static const tUIDescription *g_pUIInfo;//*****************************************************************************//// The command that is currently being parsed.  When non-zero, the argument// for this command is being read from the user.////*****************************************************************************static const tUICommandList *g_pCmd;//*****************************************************************************//// The current value read from the user for the command described by g_pCmd.////*****************************************************************************static unsigned long g_ulValue;//*****************************************************************************//// The number of characters read and displayed in g_ulValue; determines the// number of times the backspace character is processed.////*****************************************************************************static unsigned long g_ulCount;//*****************************************************************************////! Handles reception of characters from the UART.//!//! This function is called, during the UART interrupt, whenever characters are//! read from the UART by the UART driver.  They will be processed according to//! the currently defined user interface, possibly calling one of the handlers.//! The handlers are therefore called during the UART interrupt as well.//!//! \return None.////*****************************************************************************voidUIRxCallback(void){    const tUICommandList *pList;    unsigned long ulIdx;    char cChar;    //    // Loop while there are more characters in the UART buffer.    //    while(UARTCharsAvail(UART0_BASE))    {        //        // Read the next character.        //        cChar = UARTCharGet(UART0_BASE);        //        // See if the value for a command is being processed.        //        if(g_pCmd)        {            //            // See if the backspace key was pressed and there are characters to            // be deleted.            //            if((cChar == '\b') && g_ulCount)            {                //                // Rub out the previous character.                //                UARTCharPut(UART0_BASE, '\b');                UARTCharPut(UART0_BASE, ' ');                UARTCharPut(UART0_BASE, '\b');                //                // Remove the previous digit from the value.                //                g_ulValue /= 10;                //                // Decrement the number of digits that have been displayed.                //                g_ulCount--;                //                // Read the next character.                //                continue;            }            //            // See if the carriage return or escape key was pressed.            //            if((cChar == '\r') || (cChar == '\n') || (cChar == 0x1b))            {                //                // Call the command handler with the value read from the user                // if carriage return was pressed and there was at least one                // valid character entered.                //                if(((cChar == '\r') || (cChar == '\n')) && (g_ulCount != 0))                {                    (g_pCmd->pfnHandler)(g_ulValue);                }                //                // Indicate that we are done handling this command.                //                g_pCmd = 0;                //                // Reflect the carriage return back to the user.                //                UARTCharPut(UART0_BASE, '\n');                //                // Re-display the main display.                //                UIUpdate();                //                // Read the next character.                //                continue;            }            //            // Ignore this character if it is not a digit, or if 9 digits have            // already been entered.            //            if((cChar < '0') || (cChar > '9') || (g_ulCount == 9))            {                continue;            }            //            // Add this digit to the running total.            //            g_ulValue *= 10;            g_ulValue += cChar - '0';            //            // Increment the count of digits that have been displayed.            //            g_ulCount++;            //            // Reflect this character back to the user.            //            UARTCharPut(UART0_BASE, cChar);        }        else        {            //            // Try to find a command that matches this character.            //            pList = g_pUIInfo->psCommands;            for(ulIdx = 0; ulIdx < g_pUIInfo->ulCommandCount; ulIdx++)            {                if(pList[ulIdx].cCmd == cChar)                {                    break;                }            }            //            // Ignore this character if it does not match any of the commands.            //            if(ulIdx == g_pUIInfo->ulCommandCount)            {                continue;            }            //            // Determine how to handle this command.            //            if(pList[ulIdx].cType == 0)            {                //                // This is a simple command, so call the handler right now.                //                (pList[ulIdx].pfnHandler)(0);            }            else if(pList[ulIdx].cType == 1)            {                //                // This command takes an integer argument, so save the command                // structure pointer.                //                g_pCmd = &(pList[ulIdx]);                //                // Display the command name to the user.                //                UARTCharPut(UART0_BASE, '\r');                UARTCharPut(UART0_BASE, '\n');                for(ulIdx = 0; g_pCmd->pcName[ulIdx]; ulIdx++)                {                    UARTCharPut(UART0_BASE, g_pCmd->pcName[ulIdx]);                }                //                // Initialize the value and digit count to zero.                //                g_ulValue = 0;                g_ulCount = 0;            }        }    }}//*****************************************************************************////! Initialize the user interface.//!//! \param pUIInfo is a pointer to the structure that describes the requried//! user interface.//!//! This function will initialize the user interface.//!//! \return Returns 0 on success, or -1 if an error occurred with the UART//! driver.////*****************************************************************************longUIInitialize(const tUIDescription *pUIInfo){    //    // Enable the UART.    //    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);    //    // Make the appropriate GPIO pins be UART signals instead of GPIO.    //    GPIODirModeSet(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1, GPIO_DIR_MODE_HW);    //    // Save the user interface description, and set the command parser so that    // it is not reading a command value.    //    g_pUIInfo = pUIInfo;    g_pCmd = 0;    //    // Configure the UART for 115,200, 8-N-1 operation.    //    UARTConfigSet(UART0_BASE, 115200,                  (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |                   UART_CONFIG_PAR_NONE));    //    // Enable the interrupt handler to process all characters received on the    // UART.    //    UARTIntEnable(UART0_BASE, UART_INT_RT | UART_INT_RX);    IntEnable(INT_UART0);    //    // Success.    //    return(0);}//*****************************************************************************////! Displays a string to the user.//!//! \param pcString is the string to be displayed.//!//! This function sends a string to the serial port, providing information to//! the user.  No checking is done to ensure that no characters are lost by//! the UART driver; the display string should either be short enough to fit//! into the FIFOs or the FIFOs needs to be expanded.//!//! \return None.////*****************************************************************************voidUIDisplay(char *pcString){    //    // Loop through the string, displaying the characters in it one by one.    //    while(*pcString)    {        UARTCharPut(UART0_BASE, *pcString++);    }}//*****************************************************************************////! Updates the main user interface display.//!//! This function will re-display the main user interface display, if it is//! currently being displayed (i.e. if a command argument is not being read//! from the user).  This is used whenever the display needs to be changed.  No//! checking is done to ensure that no characters are lost by the UART driver;//! the display string should either be short enough to fit into the FIFOs or//! the FIFOs needs to be expanded.//!//! \return None.////*****************************************************************************voidUIUpdate(void){    unsigned long ulIdx;    //    // Do nothing if a command argument is currently being read.    //    if(g_pCmd)    {        return;    }    //    // Re-display the main user interface display.    //    for(ulIdx = 0; g_pUIInfo->pcDisplay[ulIdx]; ulIdx++)    {        UARTCharPut(UART0_BASE, g_pUIInfo->pcDisplay[ulIdx]);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -