|
TIVA lm4f120 DEMO qs-rgb 简单翻译
[复制链接]
由于英语很差(用谷歌 百度 翻译 +有道 各种翻译) 有的地方翻译和分析可能有错 请多多指教谢谢! - //*****************************************************************************
- //
- // qs-rgb.c - Quickstart for the EK-TM4C123GXL.
- //
- // Copyright (c) 2012-2013 Texas Instruments Incorporated. All rights reserved.
- // Software License Agreement
- //
- // Texas Instruments (TI) is supplying this software for use solely and
- // exclusively on TI's microcontroller products. The software is owned by
- // TI and/or its suppliers, and is protected under applicable copyright
- // laws. You may not combine this software with "viral" open-source
- // software in order to form a larger program.
- //
- // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
- // 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. TI SHALL NOT, UNDER ANY
- // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
- // DAMAGES, FOR ANY REASON WHATSOEVER.
- //
- // This is part of revision 1.1 of the EK-TM4C123GXL Firmware Package.
- //
- //*****************************************************************************
- #include //标准C库的头文件
- #include //布尔型的预定义宏 用到的true和false
- #include //数学函数库
- #include //
- #include "inc/hw_types.h"//
- #include "inc/hw_memmap.h"// 定义有全部片内外设在存储器里的基地址
- #include "inc/hw_hibernate.h"//
- #include "driverlib/fpu.h"//浮点单元函数库
- #include "driverlib/gpio.h"//GPIO函数库
- #include "driverlib/hibernate.h"//休眠模块驱动头文件
- #include "driverlib/interrupt.h"//
- #include "driverlib/pin_map.h"//
- #include "driverlib/rom.h"//rom头文件 来调用 ROM;
- #include "driverlib/sysctl.h"//系统设置
- #include "driverlib/systick.h"//
- #include "driverlib/uart.h"//UART函数头文件
- #include "utils/uartstdio.h"//
- #include "utils/cmdline.h"//
- #include "drivers/rgb.h"//rgb驱动头文件
- #include "drivers/buttons.h"//按键驱动头文件
- #include "rgb_commands.h"//
- #include "qs-rgb.h"//
- //*****************************************************************************
- //
- //! \addtogroup example_list
- //!
EK-TM4C123GXL Quickstart Application (qs-rgb)
- //!
- //! A demonstration of the Tiva C Series LaunchPad (EK-TM4C123GXL)
- //! capabilities.
- //!
- //! Press and/or hold the left button to traverse towards the red end of the
- //! ROYGBIV color spectrum. Press and/or hold the right button to traverse
- //! toward the violet end of the ROYGBIV color spectrum.
- //!
- //! If no input is received for 5 seconds, the application will start
- //! automatically changing the color displayed.
- //!
- //! Press and hold both left and right buttons for 3 seconds to enter
- //! hibernation. During hibernation, the last color displayed will blink
- //! for 0.5 seconds every 3 seconds.
- //!
- //! The system can also be controlled via a command line provided via the UART.
- //! Configure your host terminal emulator for 115200, 8-N-1 to access this
- //! feature.
- //!
- //! - Command 'help' generates a list of commands and helpful information.
- //! - Command 'hib' will place the device into hibernation mode.
- //! - Command 'rand' will initiate the pseudo-random color sequence.
- //! - Command 'intensity' followed by a number between 0 and 100 will set the
- //! brightness of the LED as a percentage of maximum brightness.
- //! - Command 'rgb' followed by a six character hex value will set the color.
- //! For example 'rgb FF0000' will produce a red color.
- //
- //*****************************************************************************
- //*****************************************************************************
- //
- // Entry counter to track how int32_t to stay in certain staging states before
- // making transition into hibernate.
- // 保存 休眠模式前计数器中的数
- //*****************************************************************************
- static volatile uint32_t ui32HibModeEntryCount;
- //*****************************************************************************
- //
- // Array of pre-defined colors for use when buttons cause manual color steps.
- // 数组用于按键 变换的颜色
- //*****************************************************************************
- static float fManualColors[7] = {0.0f, .214f, .428f, .642f, .856f, 1.07f,
- 1.284f};
- //*****************************************************************************
- //
- // Input buffer for the command line interpreter.
- // 用于命令行解释输入缓冲区
- //*****************************************************************************
- static char g_cInput[APP_INPUT_BUF_SIZE];
- //*****************************************************************************
- //
- // Application state structure. Gets stored to hibernate memory for
- // preservation across hibernate events.
- // 应用程序状态的结构体
- //*****************************************************************************
- volatile tAppState g_sAppState;
- //*****************************************************************************
- //
- // The error routine that is called if the driver library encounters an error.
- //
- //*****************************************************************************
- #ifdef DEBUG
- void
- __error__(char *pcFilename, uint32_t ui32Line)
- {
- }
- #endif
- //*****************************************************************************
- //
- // Handler to manage the button press events and state machine transitions
- // that result from those button events.
- //
- // This function is called by the SysTickIntHandler if a button event is
- // detected. Function will determine which button was pressed and tweak various
- // elements of the global state structure accordingly.
- // 按键处理
- //*****************************************************************************
- void
- AppButtonHandler(void)
- {
- static uint32_t ui32TickCounter;
- ui32TickCounter++;//记数自增()
- //
- // Switch statement to adjust the color wheel position based on buttons
- // 按键改变颜色
- switch(g_sAppState.ui32Buttons & ALL_BUTTONS)
- {
- case LEFT_BUTTON:
- //
- // Check if the button has been held int32_t enough to perform another
- // color wheel increment.
- // 判断按键时间满足执行自增
- if((ui32TickCounter % APP_BUTTON_POLL_DIVIDER) == 0)
- {
- //
- // Perform the increment and index wrap around.
- // 执行自增
- g_sAppState.ui32ManualIndex++; //手动按键颜色 从数组中选择的元素
- if(g_sAppState.ui32ManualIndex >= APP_NUM_MANUAL_COLORS)//判断是否是最后一个颜色 在七种颜色范围内
- {
- g_sAppState.ui32ManualIndex = 0; //第一个颜色
- }
- g_sAppState.fColorWheelPos = APP_PI *
- fManualColors[g_sAppState.ui32ManualIndex];
- }
- //
- // Reset some state counts and system mode so that we know the user
- // is present and actively engaging with the application.
- //
- ui32HibModeEntryCount = 0; // 模式记数清零
- g_sAppState.ui32ModeTimer = 0; // 模式时间清零
- g_sAppState.ui32Mode = APP_MODE_NORMAL;//正常模式
- break;
- case RIGHT_BUTTON:
- //
- // Check if the button has been held int32_t enough to perform another
- // color wheel decrement.
- // 判断按键时间满足执行自减
- if((ui32TickCounter % APP_BUTTON_POLL_DIVIDER) == 0)
- {
- //
- // Perform the decrement and index wrap around.
- //
- if(g_sAppState.ui32ManualIndex == 0)//判断是否是第一个颜色
- {
- //
- // set to one greater than the last color so that we decrement
- // back into range with next instruction.
- //
- g_sAppState.ui32ManualIndex = APP_NUM_MANUAL_COLORS;//变换为最后一个颜色
- }
- g_sAppState.ui32ManualIndex--;//执行自减
- g_sAppState.fColorWheelPos = APP_PI *
- fManualColors[g_sAppState.ui32ManualIndex];
- }
- //
- // Reset some state counts and system mode so that we know the user
- // is present and actively engaging with the application.
- //
- ui32HibModeEntryCount = 0; //模式记数清零
- g_sAppState.ui32ModeTimer = 0; //模式时间清零
- g_sAppState.ui32Mode = APP_MODE_NORMAL; //正常模式
- break;
- case ALL_BUTTONS:
- //
- // Both buttons for longer than debounce time will cause hibernation
- // 判断两个按键时间 是否达到 休眠模式 (约3s)
- if(ui32HibModeEntryCount < APP_HIB_BUTTON_DEBOUNCE)
- {
- ui32HibModeEntryCount++; //记数自增
- g_sAppState.ui32Mode = APP_MODE_NORMAL; //进入正常模式
- }
- else
- {
- g_sAppState.ui32Mode = APP_MODE_HIB; //进入休眠模式
- }
- g_sAppState.ui32ModeTimer = 0; //模式时间清零
- break;
- default:
- if(g_sAppState.ui32Mode == APP_MODE_HIB_FLASH)
- {
- //
- // Waking from hibernate RTC just do a quick flash then back to
- // hibernation.
- // RTC唤醒后 快速进入到休眠模式 休眠后led闪的哪半秒钟
- if(ui32HibModeEntryCount < APP_HIB_FLASH_DURATION)
- {
- ui32HibModeEntryCount++;
- }
- else
- {
- g_sAppState.ui32Mode = APP_MODE_HIB; //进入休眠模式
- }
- }
- else
- {
- //
- // Normal or remote mode and no user action will cause transition
- // to automatic scrolling mode.
- // 经过约一两秒时间没有其他操作 进入自动模式 不包括亮度的设定
- ui32HibModeEntryCount = 0;
- if(g_sAppState.ui32ModeTimer < APP_AUTO_MODE_TIMEOUT)//是否达到模式作用时间
- {
- g_sAppState.ui32ModeTimer++;
- }
- else
- {
- g_sAppState.ui32Mode = APP_MODE_AUTO;//进入自动模式
- }
- //
- // reset the tick counter when no buttons are pressed
- // this makes the first button reaction speed quicker
- //
- ui32TickCounter = APP_BUTTON_POLL_DIVIDER - 1;//减一 为了能加快下一次按键的反应时间
- }
- break;
- }
- }
- //*****************************************************************************
- //
- // Uses the fColorWheelPos variable to update the color mix shown on the RGB
- //
- // ui32ForceUpdate when set forces a color update even if a color change
- // has not been detected. Used primarily at startup to init the color after
- // a hibernate.
- //
- // This function is called by the SysTickIntHandler to update the colors on
- // the RGB LED whenever a button or timeout event has changed the color wheel
- // position. Color is determined by a series of sine functions and conditions
- //
- //*****************************************************************************
- void
- AppRainbow(uint32_t ui32ForceUpdate)
- {
- static float fPrevPos;//暂存颜色 比较
- float fCurPos; //存储混合颜色
- float fTemp;
- volatile uint32_t * pui32Colors;
- pui32Colors = g_sAppState.ui32Colors;//
- fCurPos = g_sAppState.fColorWheelPos;//当前混合颜色值
- if((fCurPos != fPrevPos) || ui32ForceUpdate)
- {
- //
- // Preserve the new color wheel position
- // 保存新的色盘的位置
- fPrevPos = fCurPos;
- //通过正弦函数 相位 负数二分之PI 0 二分之PI 分成 R G B 组合后形成混合色
- // Adjust the BLUE value based on the control state
- //
- fTemp = 65535.0f * sinf(fCurPos);//0相位 对应绿色
- if(fTemp < 0)
- {
- pui32Colors[GREEN] = 0;//存储到 peculiars数组中 为 rgb驱动提供参数
- }
- else
- {
- pui32Colors[GREEN] = (uint32_t) fTemp;//存储到 peculiars数组中 为 rgb驱动提供参数
- }
- //
- // Adjust the RED value based on the control state
- //
- fTemp = 65535.0f * sinf(fCurPos - APP_PI / 2.0f);//负二分之PI相位 对应 蓝色
- if(fTemp < 0)
- {
- pui32Colors[BLUE] = 0;//存储到 peculiars数组中 为 rgb驱动提供参数
- }
- else
- {
- pui32Colors[BLUE] = (uint32_t) fTemp;//存储到 peculiars数组中 为 rgb驱动提供参数
- }
- //
- // Adjust the GREEN value based on the control state
- //
- if(fCurPos < APP_PI)//保证 0到1.5PI 之间都有两种颜色亮
- {
- fTemp = 65535.0f * sinf(fCurPos + APP_PI * 0.5f);//小于PI 相位 二分之PI 对应 红色
- }
- else
- {
- fTemp = 65535.0f * sinf(fCurPos + APP_PI);//大于PI 相位 PI 对应红色
- }
- if(fTemp < 0)
- {
- pui32Colors[RED] = 0;//存储到 peculiars数组中 为 rgb驱动提供参数
- }
- else
- {
- pui32Colors[RED] = (uint32_t) fTemp;//存储到 peculiars数组中 为 rgb驱动提供参数
- }
- //
- // Update the actual LED state
- // 更新目前LED颜色
- RGBColorSet(pui32Colors);
- }
- }
- //*****************************************************************************
- //
- // Called by the NVIC as a result of SysTick Timer rollover interrupt flag
- //
- // Checks buttons and calls AppButtonHandler to manage button events.
- // Tracks time and auto mode color stepping. Calls AppRainbow to implement
- // RGB color changes.
- // SysTick中断处理函数
- //*****************************************************************************
- void
- SysTickIntHandler(void)
- {
- static float x;
- g_sAppState.ui32Buttons = ButtonsPoll(0,0);//获取按键状态
- AppButtonHandler(); //处理按键函数
- //
- // Auto increment the color wheel if in the AUTO mode. AUTO mode is when
- // device is active but user interaction has timed out.
- //
- if(g_sAppState.ui32Mode == APP_MODE_AUTO)//判断是否是自动模式
- {
- g_sAppState.fColorWheelPos += APP_AUTO_COLOR_STEP;//这个值决定七彩灯变换的细腻程度
- }
- //
- // Provide wrap around of the control variable from 0 to 1.5 times PI
- // 提供环绕的控制变量 控制g_sAppState.fColorWheelPos在 0到1.5π之间
- if(g_sAppState.fColorWheelPos > (APP_PI * 1.5f))
- {
- g_sAppState.fColorWheelPos = 0.0f;
- }
- if(x < 0.0f)//没发现在那 用到变量X
- {
- g_sAppState.fColorWheelPos = APP_PI * 1.5f;
- }
- //
- // Set the RGB Color based on current control variable value.
- //
- AppRainbow(0);//由于SysTick中断处理函数中 而且g_sAppState.fColorWheelPos的值还是变化的
- //出现了七彩灯变换效果
- }
- //*****************************************************************************
- //
- // Uses the fColorWheelPos variable to update the color mix shown on the RGB
- //
- // This function is called when system has decided it is time to enter
- // Hibernate. This will prepare the hibernate peripheral, save the system
- // state and then enter hibernate mode.
- // 休眠处理函数
- //*****************************************************************************
- void
- AppHibernateEnter(void)
- {
- //
- // Alert UART command line users that we are going to hibernate
- // 警报串口命令行用户, 将要休眠
- UARTprintf("Entering Hibernate...\n");
- //
- // Prepare Hibernation Module
- // 休眠模块
- HibernateGPIORetentionEnable(); //使能GPIO唤醒
- HibernateRTCSet(0); //设置时钟(RTC)计数器的初值
- HibernateRTCEnable(); //使能休眠模块的RTC
- HibernateRTCMatchSet(0, 5); //设置匹配寄存器0 的值为5
- HibernateWakeSet(HIBERNATE_WAKE_PIN | HIBERNATE_WAKE_RTC);//唤醒模式 引脚唤醒和RTC唤醒
- //
- // Store state information to battery backed memory
- // since sizeof returns number of bytes we convert to words and force
- // a rounding up to next whole word.
- // 将要存储到休眠模块中的存储器 存储的32位字的计数
- HibernateDataSet((uint32_t*)&g_sAppState, sizeof(tAppState)/4+1);//把数据存储在休眠模块的非易失性存储器中
- //
- // Disable the LED for 100 milliseconds to let user know we are
- // ready for hibernate and will hibernate on relase of buttons
- //禁用LED 100毫秒来让用户知道将要休眠,在释放按钮休眠
- RGBDisable(); //禁止 RGB
- SysCtlDelay(SysCtlClockGet()/3/10);//延时一段时间 延时长度=3*系统时钟速率*系统时钟周期
- RGBEnable(); //使能RGB
- //
- // Wait for wake button to be released prior to going into hibernate
- //等待唤醒按钮被释放之前进入休眠
- while(g_sAppState.ui32Buttons & RIGHT_BUTTON)
- {
- //
- //Delay for about 300 clock ticks to allow time for interrupts to
- //sense that button is released
- //延时约300个时钟
- SysCtlDelay(100);
- }
- //
- // Disable the LED for power savings and go to hibernate mode
- // 禁用LED节能和进入休眠模式
- RGBDisable(); //禁止RGB
- HibernateRequest(); //启动休眠模式
- }
- //*****************************************************************************
- //
- // Configure the UART and its pins. This must be called before UARTprintf().
- // 配置串口 必须在UARTprintf()函数之前
- //*****************************************************************************
- void
- ConfigureUART(void)
- {
- //
- // Enable the GPIO Peripheral used by the UART.
- // 使能GPIOA
- ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
- //
- // Enable UART0
- // 使能 UART0
- ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
- //
- // Configure GPIO Pins for UART mode.
- //GPIO引脚配置异步模式
- ROM_GPIOPinConfigure(GPIO_PA0_U0RX); //配置GPIO引脚的复用功能
- ROM_GPIOPinConfigure(GPIO_PA1_U0TX); //配置GPIO引脚的复用功能
- ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);//配置管脚供UART外设使用
- //
- // Use the internal 16MHz oscillator as the UART clock source.
- //使用内部16M晶振作为 UART 时钟源
- UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);//设置指定的UART波特率时钟源
- // UART0地址 内部精密时钟源 还可选 UART_CLOCK_SYSTEM 系统时钟源
- //
- // Initialize the UART for console I/O.
- //初始化 UART的I/O
- UARTStdioConfig(0, 115200, 16000000);//配置UART (UART0,波特率115200,晶振频率16M)
- }
- //*****************************************************************************
- //
- // Main function performs init and manages system.
- //
- // Called automatically after the system and compiler pre-init sequences.
- // Performs system init calls, restores state from hibernate if needed and
- // then manages the application context duties of the system.
- //
- //*****************************************************************************
- int
- main(void)
- {
- uint32_t ui32Status; //中断状态
- uint32_t ui32ResetCause; //复位原因
- int32_t i32CommandStatus; //命令状态
- //
- // 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_FPUEnable(); //使能浮点运算单元
- ROM_FPUStackingEnable(); //使能浮点堆寄存器
- //
- // Set the system clock to run at 40Mhz off PLL with external crystal as
- // reference. 经五分频为40M 固定二分频后到200M
- //系统时钟配置 系统5分频 使用pll(倍频到400M) 外置晶振频率 (驱动pll) 时钟源主时钟
- ROM_SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
- SYSCTL_OSC_MAIN);
- //
- // Enable the hibernate module
- // 使能外设 低功耗休眠模式
- SysCtlPeripheralEnable(SYSCTL_PERIPH_HIBERNATE);
- //
- // Enable and Initialize the UART.
- // 使能 初始化 UART
- ConfigureUART();
- //串口输出
- UARTprintf("Welcome to the Tiva C Series TM4C123G LaunchPad!\n");
- UARTprintf("Type 'help' for a list of commands\n");
- UARTprintf("> ");
- //
- // Determine why system reset occurred and respond accordingly.
- // 确定为什么系统复位发生并作出相应的反应
- ui32ResetCause = SysCtlResetCauseGet(); //获取一个复位原因 (LDO 软件。看门狗。 掉电 。上电。 外部)
- SysCtlResetCauseClear(ui32ResetCause); //清除复位原因 清除的也是 (LDO 软件。看门狗。 掉电 。上电。 外部) 让程序继续执行
- if(ui32ResetCause == SYSCTL_CAUSE_POR) //判断是否是上电复位
- {
- if(HibernateIsActive())//查看休眠模块是否已被激活 是返回true 否返回false 从而根据结果采取适当的操作
- { //如果冬眠模式已激活,那就无需再次使能休眠模块。。在上电复位时调用此函数可以帮助确定复位是否由于从冬眠中唤醒或者是一个冷启动而导致的
- //
- // Read the status bits to see what caused the wake.
- // 读取状态是什么引起的唤醒
- ui32Status = HibernateIntStatus(0); //获取休眠模块的当前中断情形 (获取原始的中断状态时为False,获取被屏蔽的中断状态时为True)
- HibernateIntClear(ui32Status); //清除冬眠模块中正在挂起的中断
- //
- // Wake was due to the push button.
- //
- if(ui32Status & HIBERNATE_INT_PIN_WAKE) //是否是从/WAKE管脚触发中断
- {
- UARTprintf("Hibernate Wake Pin Wake Event\n");
- UARTprintf("> ");
- //
- // Recover the application state variables from battery backed
- // hibernate memory. Set ui32Mode to normal.
- // 从休眠模块存储器中读出的数据将要保存的位置
- HibernateDataGet((uint32_t*) &g_sAppState,
- sizeof(tAppState) / 4 + 1);//从冬眠模块的非易失性存储器中读取一组数据
- g_sAppState.ui32Mode = APP_MODE_NORMAL; //正常模式
- }
- //
- // Wake was due to RTC match
- // RTC唤醒
- else if(ui32Status & HIBERNATE_INT_RTC_MATCH_0)//是否是 RTC匹配0中断
- {
- UARTprintf("Hibernate RTC Wake Event\n");
- UARTprintf("> ");
- //
- // Recover the application state variables from battery backed
- // hibernate memory. Set ui32Mode to briefly flash the RGB.
- // 从休眠模块存储器中读出的数据将要保存的位置 、读取的32位字的计数值
- HibernateDataGet((uint32_t*) &g_sAppState,
- sizeof(tAppState) / 4 + 1);//从冬眠模块的非易失性存储器中读取一组数据
- g_sAppState.ui32Mode = APP_MODE_HIB_FLASH; // 再次进入休眠模式
- }
- }
- else
- {
- //
- // Reset was do to a cold first time power up.
- //
- UARTprintf("Power on reset. Hibernate not active.\n");
- UARTprintf("> ");
- g_sAppState.ui32Mode = APP_MODE_NORMAL; //正常模式
- g_sAppState.fColorWheelPos = 0; //RGB混合颜色 (都不亮)
- g_sAppState.fIntensity = APP_INTENSITY_DEFAULT; //LED亮度默认值
- g_sAppState.ui32Buttons = 0; //按键状态清零
- }
- }
- else
- {
- //
- // External Pin reset or other reset event occured.
- // 外部引脚复位或者其他复位
- UARTprintf("External or other reset\n");
- UARTprintf("> ");
- //
- // Treat this as a cold power up reset without restore from hibernate.
- //
- g_sAppState.ui32Mode = APP_MODE_NORMAL; //正常模式
- g_sAppState.fColorWheelPos = APP_PI; //RGB的混合颜色
- g_sAppState.fIntensity = APP_INTENSITY_DEFAULT; //LED亮度默认值
- g_sAppState.ui32Buttons = 0; //按键状态清零
- //
- // colors get a default initialization later when we call AppRainbow.
- //
- }
- // 初始化休眠模块的时钟
- // Initialize clocking for the Hibernate module
- // 使能冬眠模块的操作
- HibernateEnableExpClk(SysCtlClockGet());//为系统时钟提供休眠模块的时钟速率
- //
- // Initialize the RGB LED. AppRainbow typically only called from interrupt
- // context. Safe to call here to force initial color update because
- // interrupts are not yet enabled.
- //
- RGBInit(0);//RGB初始化 ( 使能定时器 GPIO 访问硬件寄存器)
- RGBIntensitySet(g_sAppState.fIntensity);//LED亮度设置
- AppRainbow(1);
- RGBEnable(); //RGB使能 即配置GPIO 定时器
- //
- // Initialize the buttons
- //按键初始化
- ButtonsInit();
- //
- // Initialize the SysTick interrupt to process colors and buttons.
- // 初始化系统定时器中断处理的色彩和按钮
- SysTickPeriodSet(SysCtlClockGet() / APP_SYSTICKS_PER_SEC);//设置SysTick计数器的周期值 初值 系统时钟速率/32
- SysTickEnable(); //使能SysTick 计数器
- SysTickIntEnable();//使能 SysTick 中断。
- IntMasterEnable(); //使能处理器中断
- //
- // spin forever and wait for carriage returns or state changes.
- //
- while(1)
- {
- UARTprintf("\n>");
- //
- // Peek to see if a full command is ready for processing
- //查看是否完整的命令准备处理
- while(UARTPeek('\r') == -1)
- {
- //
- // millisecond delay. A SysCtlSleep() here would also be OK.
- // 毫秒延时。
- SysCtlDelay(SysCtlClockGet() / (1000 / 3));//延时长度=3*系统时钟速率*系统时钟周期
- //
- // Check for change of mode and enter hibernate if requested.
- // all other mode changes handled in interrupt context.
- //
- if(g_sAppState.ui32Mode == APP_MODE_HIB)//判断是否是休眠模式
- {
- AppHibernateEnter();//进入休眠函数
- }
- }
- //
- // a '\r' was detected get the line of text from the user.
- // 检测获得的字符
- UARTgets(g_cInput,sizeof(g_cInput));
- //
- // Pass the line from the user to the command processor.
- // It will be parsed and valid commands executed.
- // UART输入的命令进行处理
- i32CommandStatus = CmdLineProcess(g_cInput);
- //
- // Handle the case of bad command.
- //
- if(i32CommandStatus == CMDLINE_BAD_CMD)//判断是否是错误命令
- {
- UARTprintf("Bad command!\n");
- }
- //
- // Handle the case of too many arguments.
- // 处理参数太多的情况下
- else if(i32CommandStatus == CMDLINE_TOO_MANY_ARGS)//判断是否命令过多
- {
- UARTprintf("Too many arguments for command processor!\n");
- }
- }
- }
复制代码
|
|