本帖最后由 baiyongbin2009 于 2015-2-12 14:38 编辑
特别说明:完整STemWin的1-60期教程和配套实例下载地址:链接
第29章 STemWin多任务(uCOS-III)
本期教程主要是在开发板实现上期教程中所说的三种系统。这里大家重点学习一下官方推荐的设计框架即可,如果有不懂的函数会在后面跟大家讲。 29. 1 单任务系统(超级循环) 29. 2 多任务系统:一个任务调用emWin 29. 3 多任务系统:多个任务调用emWin 29. 4 总结 29.1 单任务系统(超级循环)工程代码的结构如下: 关于移植的知识已经在前面的第二章详细讲解了,这里重点介绍时间框架和接口函数。 29.1.1 内核接口 内核接口文件GUI_X.C内容如下: - ----------------------------------------------------------------------
- File : GUI_X.C
- Purpose : Config / System dependent externals for GUI
- ---------------------------END-OF-HEADER------------------------------
- */
-
- #include "GUI.h"
- #include "stm32f4xx.h"
-
-
-
- /*********************************************************************
- *
- * Timing:
- * GUI_X_GetTime()
- * GUI_X_Delay(int)
-
- Some timing dependent routines require a GetTime
- and delay function. Default time unit (tick), normally is
- 1 ms.
- */
- extern __IO int32_t g_iRunTime;(1)
- int GUI_X_GetTime(void)(2)
- {
-
- return g_iRunTime;
- }
-
- void GUI_X_Delay(int ms)(3)
- {
- int tEnd = g_iRunTime + ms;
- while ((tEnd - g_iRunTime) > 0);
- }
-
- /*********************************************************************
- *
- * GUI_X_Init()
- *
- * Note:
- * GUI_X_Init() is called from GUI_Init is a possibility to init
- * some hardware which needs to be up and running before the GUI.
- * If not required, leave this routine blank.
- */
-
- void GUI_X_Init(void) {}
-
-
- /*********************************************************************
- *
- * GUI_X_ExecIdle
- *
- * Note:
- * Called if WM is in idle state
- */
-
- void GUI_X_ExecIdle(void) {}
-
- /*********************************************************************
- *
- * Logging: OS dependent
-
- Note:
- Logging is used in higher debug levels only. The typical target
- build does not use logging and does therefor not require any of
- the logging routines below. For a release build without logging
- the routines below may be eliminated to save some space.
- (If the linker is not function aware and eliminates unreferenced
- functions automatically)
-
- */
-
- void GUI_X_Log (const char *s) { GUI_USE_PARA(s); }
- void GUI_X_Warn (const char *s) { GUI_USE_PARA(s); }
- void GUI_X_ErrorOut(const char *s) { GUI_USE_PARA(s); }
复制代码1. 时间基准全局变量,这个变量在bsp_timer.c文件里面进行了定义,由嘀嗒定时器中断进行调用,每1ms调用一次。 -
- /*
- 全局运行时间,单位1ms
- 最长可以表示 24.85天,如果你的产品连续运行时间超过这个数,则必须考虑溢出问题
- */
- __IO int32_t g_iRunTime = 0;
- /*
- *********************************************************************************************************
- * 函 数 名: SysTick_ISR
- * 功能说明: SysTick中断服务程序,每隔1ms进入1次
- * 形 参: 无
- * 返 回 值: 无
- *********************************************************************************************************
- */
- void SysTick_ISR(void)
- {
- static uint8_t s_count = 0;
- uint8_t i;
-
- /* 每隔1ms进来1次 (仅用于 bsp_DelayMS) */
- if (s_uiDelayCount > 0)
- {
- if (--s_uiDelayCount == 0)
- {
- s_ucTimeOutFlag = 1;
- }
- }
-
- /* 每隔1ms,对软件定时器的计数器进行减一操作 */
- for (i = 0; i < TMR_COUNT; i++)
- {
- bsp_SoftTimerDec(&s_tTmr[i]);
- }
-
- /* 全局运行时间每1ms增1 */
- g_iRunTime++;
- if (g_iRunTime == 0x7FFFFFFF) /* 这个变量是 int32_t 类型,最大数为 0x7FFFFFFF */
- {
- g_iRunTime = 0;
- }
-
- bsp_RunPer1ms(); /* 每隔1ms调用一次此函数,此函数在 bsp.c */
-
- if (++s_count >= 10)
- {
- s_count = 0;
-
- bsp_RunPer10ms(); /* 每隔10ms调用一次此函数,此函数在 bsp.c */
- }
- }
复制代码2. 供STemWin调用的接口函数,用于获取系统时钟基准。 3. 供STemWin调用的接口函数,用于延迟时间设置。 4. 主要设置上面两个函数即可,其余函数根据需要进行配置。 29.1.2 触摸接口 触摸部分由嘀嗒定时器中周期性的调用: - /*
- *********************************************************************************************************
- * 函 数 名: bsp_RunPer10ms
- * 功能说明: 该函数每隔10ms被调用1次。在bsp_timer.c的定时中断调用。主要用于硬件事件检测
- * 形 参:无
- * 返 回 值: 无
- *********************************************************************************************************
- */
- extern __IO uint8_t s_ucRA8875BusyNow;
- void bsp_RunPer10ms(void)
- {
- /* RA8875 触摸*/
- if (g_ChipID == IC_8875)
- {
- /* 资源共享标志 */
- if(s_ucRA8875BusyNow == 0)
- {
- GUI_TOUCH_Exec();
- }
- }
- /* XPT2046 */
- else
- {
- GUI_TOUCH_Exec();
- }
- }
复制代码 29.1.3 主程序在文件main.c - /*
- *********************************************************************************************************
- * 函 数 名: main
- * 功能说明: c程序入口
- * 形 参:无
- * 返 回 值: 错误代码(无需处理)
- *********************************************************************************************************
- */
- int main(void)
- {
- bsp_Init(); /* 为了是main函数看起来更简洁些,我们将硬件初始化的代码封装到这个函数 */
-
- MainTask();
- }
复制代码在文件MainTask.c - /*
- *********************************************************************************************************
- * 函 数 名: main
- * 功能说明: c程序入口
- * 形 参:无
- * 返 回 值: 错误代码(无需处理)
- *********************************************************************************************************
- */
- void MainTask(void)
- {
- int xPos;
- int yPos;
- int xSize;
- int i;
-
- i = 0;
- /* 初始化 */
- GUI_Init();
- /* 获取要显示的X,Y坐标 */
- xPos = LCD_GetXSize() / 2;
- yPos = LCD_GetYSize() / 3;
- /* 设置文本显示模式 */
- GUI_SetTextMode(GUI_TM_REV);
- /* 设置显示字体 */
- GUI_SetFont(GUI_FONT_20F_ASCII);
- GUI_DispStringHCenterAt("Hello world!", xPos, yPos);
- /* 设置显示数字字体 */
- GUI_SetFont(GUI_FONT_D24X32);
- /* 获取显示0000,在字体GUI_FONT_D24X32下的显示情况 */
- xSize = GUI_GetStringDistX("0000");
- /* 设置显示位置 */
- xPos -= xSize / 2;
- yPos += 24 + 10;
- while (1)
- {
- GUI_DispDecAt( i++, xPos, yPos, 4);
- if (i > 9999)
- {
- i = 0;
- }
- }
- }
复制代码功能比较简单,实现效果如下:
|