FreeRTOS:osDelay与HAL_delay [英] FreeRTOS: osDelay vs HAL_delay

查看:1308
本文介绍了FreeRTOS:osDelay与HAL_delay的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 STM32CubeMx 创建 FreeRTOS 应用程序项目时,可以使用两种方法引入延迟,即 osDelay HAL_Delay

While creating FreeRTOS application project with STM32CubeMx, there are two ways you can use to introduce delay, namely osDelay and HAL_Delay.

它们之间有什么区别,应该优先选择哪个?

What's the difference among them and which one should be preferred?

osDelay 代码:

/*********************** Generic Wait Functions *******************************/
/**
* @brief   Wait for Timeout (Time Delay)
* @param   millisec      time delay value
* @retval  status code that indicates the execution status of the function.
*/
osStatus osDelay (uint32_t millisec)
{
#if INCLUDE_vTaskDelay
  TickType_t ticks = millisec / portTICK_PERIOD_MS;

  vTaskDelay(ticks ? ticks : 1);          /* Minimum delay = 1 tick */

  return osOK;
#else
  (void) millisec;

  return osErrorResource;
#endif
}

HAL_Delay 代码:

/**
* @brief This function provides accurate delay (in milliseconds) based 
*        on variable incremented.
* @note In the default implementation , SysTick timer is the source of time base.
*       It is used to generate interrupts at regular time intervals where uwTick
*       is incremented.
* @note ThiS function is declared as __weak to be overwritten in case of other
*       implementations in user file.
* @param Delay: specifies the delay time length, in milliseconds.
* @retval None
*/
__weak void HAL_Delay(__IO uint32_t Delay)
{
  uint32_t tickstart = 0;
  tickstart = HAL_GetTick();
  while((HAL_GetTick() - tickstart) < Delay)
  {
  }
}


推荐答案

HAL_Delay 不是一个 FreeRTOS 函数和 _osDelay 是围绕 FreeRTOS 函数构建的函数。 (acc @Clifford :)它们都是完全不同的功能,不同的开发人员出于不同的目的。

HAL_Delay is NOT a FreeRTOS functions and _osDelay is a function built around FreeRTOS function. (acc @Clifford: ) They both are entirely different function by different developers for different purposes.

osDelay CMSIS库的一部分,并在内部使用 vTaskDelay()引入延迟,区别在于 osDelay 的输入参数是延迟时间(以毫秒为单位),而输入_vTaskDelay()的参数是要延迟的刻度数。 (根据 @Bence Kaulics :)使用此功能,操作系统将收到有关延迟的通知,并且操作系统将在特定时间段内将任务状态更改为已阻止

osDelay is part of CMSIS Library and uses vTaskDelay() internally to introduce delay with the difference that input argument of osDelay is delay time in milliseconds while the input argument of _vTaskDelay() is number of Ticks to be delayed. (acc. @Bence Kaulics:) Using this function, OS will be notified about the delay and OS will change the status of task to blocked for that particular time period.

HAL_Delay 是我们处理器的硬件抽象层的一部分。它基本上使用轮询来引入延迟。 (根据 @Bence Kaulics :)使用此功能,不会通知操作系统延迟。另外,如果您不使用OS,则 HAL_Delay 是默认设置,并且仅阻止HAL库提供的使用延迟。 (根据 @Clifford :)这是 HAL库的一部分,可以在没有FreeRTOS的情况下使用(或在FreeRTOS未运行时使用)

HAL_Delay is part of the hardware abstraction layer for our processor. It basically uses polling to introduce delay. (acc. @Bence Kaulics:) Using this function, OS won't be notified about the delay. Also if you do not use OS, then HAL_Delay is the default and only blocking delay to use provided by the HAL library. (acc. @Clifford: ) This is part of HAL Library and can be used without FreeRTOS (or when FreeRTOS is not running)

要使用FreeRTOS功能引入延迟,可以使用 vTaskDelay()或<调度程序启动后,a href = http://www.freertos.org/vtaskdelayuntil.html rel = noreferrer> vTaskDelayUntil()。

To introduce Delay using FreeRTOS functions, you can use vTaskDelay() or vTaskDelayUntil() after the scheduler has started.

(根据 @Clifford :)

如果您希望确定应用程序的确定性,则始终喜欢FreeRTOS API函数。

CubeMX 是来自多个来源的零件的集合。

(acc. @Clifford: )
Always Favour FreeRTOS API functino if you want your applicatino to be deterministic.
CubeMX is a collection of parts from multiple sources.

这篇关于FreeRTOS:osDelay与HAL_delay的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆