硬汉嵌入式论坛

 找回密码
 立即注册
查看: 1864|回复: 2
收起左侧

[FreeRTOS] 请教下,使用 v2 封装层貌似速度比较慢 ?

[复制链接]

609

主题

3047

回帖

4894

积分

至尊会员

积分
4894
发表于 2019-7-26 07:09:05 | 显示全部楼层 |阅读模式


emwin gui_x_os 配置

FreeRTOS V1 封装层:

#include "cmsis_os.h"
#include "FreeRTOS.h"
#include "task.h"

static osMutexId osMutex= NULL;
static osSemaphoreId osSemaphore= NULL;

int GUI_X_GetTime(void)
{
  return ((int) osKernelSysTick());
}

void GUI_X_Delay(int ms)
{
  osDelay( ms );
}


void GUI_X_Init(void) {
}


void GUI_X_ExecIdle(void) {}


/* Init OS */
void GUI_X_InitOS(void)
{
  /* Create Mutex lock */
  osMutexDef(MUTEX);
  osMutex = osMutexCreate(osMutex(MUTEX));

  /* Create Semaphore lock */
  osSemaphoreDef(SEM);
  osSemaphore= osSemaphoreCreate(osSemaphore(SEM), 1);  
}

void GUI_X_Unlock(void)
{
  osMutexRelease(osMutex);
}

void GUI_X_Lock(void)
{
        if((osMutex == NULL) || (osSemaphore == NULL))
  {
    GUI_X_InitOS();
  }
       
  osMutexWait(osMutex , osWaitForever) ;
}

/* Get Task handle */
U32 GUI_X_GetTaskId(void)
{
  return ((U32) osThreadGetId());
}


void GUI_X_WaitEvent (void)
{
  osSemaphoreWait(osSemaphore , osWaitForever) ;
}


void GUI_X_SignalEvent (void)
{
  osMutexRelease(osSemaphore);
}


void GUI_X_Log (const char *s) { }
void GUI_X_Warn (const char *s) { }
void GUI_X_ErrorOut(const char *s) { }



/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

FreeRTOS V2 封装层:

#include "cmsis_os.h"
#include "FreeRTOS.h"
#include "task.h"

static osMutexId osMutex= NULL;
static osSemaphoreId osSemaphore= NULL;

int GUI_X_GetTime(void)
{
  return ((int) osKernelSysTick());
}

void GUI_X_Delay(int ms)
{
  osDelay( ms );
}


void GUI_X_Init(void) {
}


void GUI_X_ExecIdle(void) {}

/* Init OS */
void GUI_X_InitOS(void)
{
  /* Create Mutex lock */
  osMutexDef(MUTEX);
  osMutex = osMutexNew(osMutex(MUTEX));
       
  /* Create Semaphore lock */
//        osSemaphoreDef(SEM);
//        osSemaphore = osSemaphoreNew (1, 0, osSemaphore(SEM));
       
        osSemaphore = osSemaphoreNew (1, 0, NULL);
}

void GUI_X_Unlock(void)
{
  osMutexRelease(osMutex);
}

void GUI_X_Lock(void)
{
        if((osMutex == NULL) || (osSemaphore == NULL))
  {
    GUI_X_InitOS();
  }
       
       
//  osMutexWait(osMutex , osWaitForever) ;
        osMutexAcquire(osMutex , osWaitForever) ;
}

/* Get Task handle */
U32 GUI_X_GetTaskId(void)
{
  return ((U32) osThreadGetId());
}


void GUI_X_WaitEvent (void)
{
//  osSemaphoreWait(osSemaphore , osWaitForever) ;
        osSemaphoreAcquire(osSemaphore , osWaitForever) ;
}


void GUI_X_SignalEvent (void)
{
  osMutexRelease(osSemaphore);
}


void GUI_X_Log (const char *s) { }
void GUI_X_Warn (const char *s) { }
void GUI_X_ErrorOut(const char *s) { }


大神帮忙看看是哪里没有搞对吗 ?

v2 封装层的 响应速度没有 v1 快 ????


回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106660
QQ
发表于 2019-7-26 10:31:30 | 显示全部楼层
  1. /*********************************************************************
  2. *                    SEGGER Microcontroller GmbH                     *
  3. *        Solutions for real time microcontroller applications        *
  4. **********************************************************************
  5. *                                                                    *
  6. *        (c) 1996 - 2019  SEGGER Microcontroller GmbH                *
  7. *                                                                    *
  8. *        Internet: www.segger.com    Support:  support@segger.com    *
  9. *                                                                    *
  10. **********************************************************************

  11. ** emWin V5.50 - Graphical user interface for embedded applications **
  12. All  Intellectual Property rights  in the Software belongs to  SEGGER.
  13. emWin is protected by  international copyright laws.  Knowledge of the
  14. source code may not be used to write a similar product.  This file may
  15. only be used in accordance with the following terms:

  16. The software has been licensed to  ARM LIMITED whose registered office
  17. is situated at  110 Fulbourn Road,  Cambridge CB1 9NJ,  England solely
  18. for  the  purposes  of  creating  libraries  for  ARM7, ARM9, Cortex-M
  19. series,  and   Cortex-R4   processor-based  devices,  sublicensed  and
  20. distributed as part of the  MDK-ARM  Professional  under the terms and
  21. conditions  of  the   End  User  License  supplied  with  the  MDK-ARM
  22. Professional.
  23. Full source code is available at: www.segger.com

  24. We appreciate your understanding and fairness.
  25. ----------------------------------------------------------------------
  26. Licensing information
  27. Licensor:                 SEGGER Software GmbH
  28. Licensed to:              ARM Ltd, 110 Fulbourn Road, CB1 9NJ Cambridge, UK
  29. Licensed SEGGER software: emWin
  30. License number:           GUI-00181
  31. License model:            LES-SLA-20007, Agreement, effective since October 1st 2011
  32. Licensed product:         MDK-ARM Professional
  33. Licensed platform:        ARM7/9, Cortex-M/R4
  34. Licensed number of seats: -
  35. ----------------------------------------------------------------------
  36. File        : GUI_X_RTE.c
  37. Purpose     : Config / System dependent externals for GUI
  38. ---------------------------END-OF-HEADER------------------------------
  39. */

  40. #include "RTE_Components.h"
  41. #ifdef RTE_CMSIS_RTOS2
  42. #include "cmsis_os2.h"
  43. #else
  44. #include "cmsis_os.h"
  45. #endif

  46. #include "GUI.h"

  47. /*********************************************************************
  48. *
  49. *       Global data
  50. */

  51. #ifndef RTE_CMSIS_RTOS2
  52. static volatile GUI_TIMER_TIME OS_TimeMS;
  53. #endif

  54. /*********************************************************************
  55. *
  56. *       GUI Tick (executed each ms)
  57. */

  58. #ifndef RTE_CMSIS_RTOS2
  59. static void GUI_Tick (void const *argument) {
  60.   (void)argument;
  61.   OS_TimeMS++;
  62. }
  63. #endif

  64. /*********************************************************************
  65. *
  66. *      Timing:
  67. *                 GUI_X_GetTime()
  68. *                 GUI_X_Delay(int)

  69.   Some timing dependent routines require a GetTime
  70.   and delay function. Default time unit (tick), normally is
  71.   1 ms.
  72. */


  73. GUI_TIMER_TIME GUI_X_GetTime(void) {
  74. #ifdef RTE_CMSIS_RTOS2
  75.   return ((GUI_TIMER_TIME)(osKernelGetTickCount()));
  76. #else
  77.   return OS_TimeMS;
  78. #endif
  79. }

  80. void GUI_X_Delay(int ms) {
  81.   osDelay((uint32_t)ms);
  82. }

  83. /*********************************************************************
  84. *
  85. *       GUI_X_Init()
  86. *
  87. * Note:
  88. *     GUI_X_Init() is called from GUI_Init is a possibility to init
  89. *     some hardware which needs to be up and running before the GUI.
  90. *     If not required, leave this routine blank.
  91. */

  92. #ifndef RTE_CMSIS_RTOS2
  93. osTimerDef(GUI_Timer, GUI_Tick);
  94. static osTimerId GUI_TimerId;
  95. #endif

  96. #ifdef RTE_Graphics_Touchscreen
  97. extern void GUI_TOUCH_Initialize(void);
  98. extern void GUI_TOUCH_Exec(void);
  99. #ifdef RTE_CMSIS_RTOS2
  100. static osTimerId_t GUI_TOUCH_TimerId;
  101. static void GUI_TOUCH_Tick(void *argument)       { (void)argument; GUI_TOUCH_Exec(); }
  102. #else
  103. static osTimerId   GUI_TOUCH_TimerId;
  104. static void GUI_TOUCH_Tick(void const *argument) { (void)argument; GUI_TOUCH_Exec(); }
  105. osTimerDef (GUI_TOUCH_Timer, GUI_TOUCH_Tick);
  106. #endif
  107. #endif

  108. #ifdef RTE_Graphics_Joystick
  109. extern void GUI_JOYSTICK_Initialize(void);
  110. extern void GUI_JOYSTICK_Exec(void);
  111. #ifdef RTE_CMSIS_RTOS2
  112. static osTimerId_t GUI_JOYSTICK_TimerId;
  113. static void GUI_JOYSTICK_Tick(void *argument)       { (void)argument; GUI_JOYSTICK_Exec(); }
  114. #else
  115. static osTimerId   GUI_JOYSTICK_TimerId;
  116. static void GUI_JOYSTICK_Tick(void const *argument) { (void)argument; GUI_JOYSTICK_Exec(); }
  117. osTimerDef (GUI_JOYSTICK_Timer, GUI_JOYSTICK_Tick);
  118. #endif
  119. #endif

  120. void GUI_X_Init(void) {

  121. #ifndef RTE_CMSIS_RTOS2
  122.   GUI_TimerId = osTimerCreate(osTimer(GUI_Timer), osTimerPeriodic, NULL);
  123.   osTimerStart(GUI_TimerId, 1);
  124. #endif

  125. #ifdef RTE_Graphics_Touchscreen
  126.   GUI_TOUCH_Initialize();
  127. #ifdef RTE_CMSIS_RTOS2
  128.   GUI_TOUCH_TimerId = osTimerNew(&GUI_TOUCH_Tick, osTimerPeriodic, NULL, NULL);
  129. #else
  130.   GUI_TOUCH_TimerId = osTimerCreate(osTimer(GUI_TOUCH_Timer), osTimerPeriodic, NULL);
  131. #endif
  132.   osTimerStart(GUI_TOUCH_TimerId, 20U);
  133. #endif

  134. #ifdef RTE_Graphics_Joystick
  135.   GUI_JOYSTICK_Initialize();
  136. #ifdef RTE_CMSIS_RTOS2
  137.   GUI_JOYSTICK_TimerId = osTimerNew(&GUI_JOYSTICK_Tick, osTimerPeriodic, NULL, NULL);
  138. #else
  139.   GUI_JOYSTICK_TimerId = osTimerCreate(osTimer(GUI_JOYSTICK_Timer), osTimerPeriodic, NULL);
  140. #endif
  141.   osTimerStart(GUI_JOYSTICK_TimerId, 50U);
  142. #endif

  143. }

  144. /*********************************************************************
  145. *
  146. *       GUI_X_ExecIdle
  147. *
  148. * Note:
  149. *  Called if WM is in idle state
  150. */

  151. void GUI_X_ExecIdle(void) {
  152.   osDelay(1U);
  153. }

  154. /*********************************************************************
  155. *
  156. *      Logging: OS dependent

  157. Note:
  158.   Logging is used in higher debug levels only. The typical target
  159.   build does not use logging and does therefor not require any of
  160.   the logging routines below. For a release build without logging
  161.   the routines below may be eliminated to save some space.
  162.   (If the linker is not function aware and eliminates unreferenced
  163.   functions automatically)

  164. */

  165. void GUI_X_Log     (const char *s) { GUI_USE_PARA(s); }
  166. void GUI_X_Warn    (const char *s) { GUI_USE_PARA(s); }
  167. void GUI_X_ErrorOut(const char *s) { GUI_USE_PARA(s); }

  168. /*********************************************************************
  169. *
  170. *      Multitasking:
  171. *
  172. *                 GUI_X_InitOS()
  173. *                 GUI_X_GetTaskId()
  174. *                 GUI_X_Lock()
  175. *                 GUI_X_Unlock()
  176. *
  177. * Note:
  178. *   The following routines are required only if emWin is used in a
  179. *   true multi task environment, which means you have more than one
  180. *   thread using the emWin API.
  181. *   In this case the
  182. *                       #define GUI_OS 1
  183. *  needs to be in GUIConf.h
  184. */

  185. #ifdef RTE_CMSIS_RTOS2
  186. static osMutexId_t      GUI_MutexId;
  187. static osEventFlagsId_t GUI_EventId;
  188. #else
  189. osMutexDef(GUI_Mutex);
  190. static osMutexId        GUI_MutexId;
  191. #endif

  192. void GUI_X_InitOS(void) {
  193. #ifdef RTE_CMSIS_RTOS2
  194.   GUI_MutexId = osMutexNew(NULL);
  195.   GUI_EventId = osEventFlagsNew(NULL);
  196. #else
  197.   GUI_MutexId = osMutexCreate(osMutex(GUI_Mutex));
  198. #endif
  199. }

  200. void GUI_X_Unlock(void) {
  201.   osMutexRelease(GUI_MutexId);
  202. }

  203. void GUI_X_Lock(void) {
  204. #ifdef RTE_CMSIS_RTOS2
  205.   osMutexAcquire(GUI_MutexId, osWaitForever);
  206. #else
  207.   osMutexWait   (GUI_MutexId, osWaitForever);
  208. #endif
  209. }

  210. U32  GUI_X_GetTaskId(void) {
  211.   return ((U32)(osThreadGetId()));
  212. }

  213. /*********************************************************************
  214. *
  215. *      Event driving (optional with multitasking)
  216. *
  217. *                 GUI_X_WaitEvent()
  218. *                 GUI_X_WaitEventTimed()
  219. *                 GUI_X_SignalEvent()
  220. */

  221. #ifndef RTE_CMSIS_RTOS2
  222. static osThreadId GUI_ThreadId = NULL;
  223. #endif

  224. void GUI_X_WaitEvent(void) {
  225. #ifdef RTE_CMSIS_RTOS2
  226.   osEventFlagsWait(GUI_EventId, 0x00000001U, osFlagsWaitAny, osWaitForever);
  227. #else
  228.   GUI_ThreadId = osThreadGetId();
  229.   osSignalWait(0x00000001, osWaitForever);
  230. #endif
  231. }

  232. void GUI_X_WaitEventTimed(int Period) {
  233. #ifdef RTE_CMSIS_RTOS2
  234.   osEventFlagsWait(GUI_EventId, 0x00000001U, osFlagsWaitAny, (uint32_t)Period);
  235. #else
  236.   GUI_ThreadId = osThreadGetId();
  237.   osSignalWait(0x00000001, (uint32_t)Period);
  238. #endif
  239. }

  240. void GUI_X_SignalEvent(void) {
  241. #ifdef RTE_CMSIS_RTOS2
  242.   osEventFlagsSet (GUI_EventId, 0x00000001U);
  243. #else
  244.   if (GUI_ThreadId) {
  245.     osSignalSet(GUI_ThreadId, 0x00000001);
  246.   }
  247. #endif
  248. }

  249. /*************************** End of file ****************************/
复制代码


回复

使用道具 举报

609

主题

3047

回帖

4894

积分

至尊会员

积分
4894
 楼主| 发表于 2019-7-27 09:37:15 | 显示全部楼层
本帖最后由 hpdell 于 2019-7-27 10:08 编辑

是我吧问题想的太简单了啊,原来需要这么的搞, 多谢多谢大神了啊
另外这个 emwin v5.5  的在哪里可以下载啊 ??
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-4-28 18:36 , Processed in 0.201521 second(s), 26 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表