停止和启动任务
Stopping and Starting an task
所以。这是一个抽象的问题。
在学习 FreeRTOS 时,我遇到了一些问题。
作为背景,我尝试使一个函数的 LED 灯闪烁,它闪烁是在 for(;;) 内部还是外部,这与任务是 运行ning 仅在 for(;;) 循环之后 initialization/first 运行 通过它。
尽量说清楚:
Task functions should never return so are typically implemented as a continuous loop.
任务定义为:
void vATaskFunction( void *pvParameters )
{
for( ;; )
{
-- Task application code here. --
}
/* Tasks must not attempt to return from their implementing
function or otherwise exit. In newer FreeRTOS port
attempting to do so will result in an configASSERT() being
called if it is defined. If it is necessary for a task to
exit then have the task call vTaskDelete( NULL ) to ensure
its exit is clean. */
vTaskDelete( NULL );
}
知道了,我的问题是:
- 如果任务是死循环,调度器如何挂起它(切换到另一个任务)?
- 局部变量中的当前值会怎样?
- 当切换回我们的任务时,任务是直接跳转到 for(;;) 循环内,还是像往常一样正常地通过函数?
任务有自己的堆栈,因此保留了局部变量值。
RTOSes 的工作方式与 "normal" OS-es 完全不同。
如果只有一个具有最高优先级的任务(以及许多其他具有较低优先级的任务),它必须将控制权交还给系统。它发生在任务进入暂停或阻塞状态时。否则它将永远不会被抢占。 (当然会触发中断)
举个例子:如果你开始任务A和B任务的优先级A[=如果任务 A 不会通过进入挂起或阻塞状态(例如通过等待通知、信号量、互斥量或其他东西)任务 A 将有 100% 的执行时间而任务 B 0% (零)
如果有多个任务具有相同的最高优先级,则会发生循环抢占。在嵌入式 RTOS 开发中无论如何都是非常罕见的情况。
所以。这是一个抽象的问题。
在学习 FreeRTOS 时,我遇到了一些问题。
作为背景,我尝试使一个函数的 LED 灯闪烁,它闪烁是在 for(;;) 内部还是外部,这与任务是 运行ning 仅在 for(;;) 循环之后 initialization/first 运行 通过它。
尽量说清楚:
Task functions should never return so are typically implemented as a continuous loop.
任务定义为:
void vATaskFunction( void *pvParameters )
{
for( ;; )
{
-- Task application code here. --
}
/* Tasks must not attempt to return from their implementing
function or otherwise exit. In newer FreeRTOS port
attempting to do so will result in an configASSERT() being
called if it is defined. If it is necessary for a task to
exit then have the task call vTaskDelete( NULL ) to ensure
its exit is clean. */
vTaskDelete( NULL );
}
知道了,我的问题是:
- 如果任务是死循环,调度器如何挂起它(切换到另一个任务)?
- 局部变量中的当前值会怎样?
- 当切换回我们的任务时,任务是直接跳转到 for(;;) 循环内,还是像往常一样正常地通过函数?
任务有自己的堆栈,因此保留了局部变量值。
RTOSes 的工作方式与 "normal" OS-es 完全不同。
如果只有一个具有最高优先级的任务(以及许多其他具有较低优先级的任务),它必须将控制权交还给系统。它发生在任务进入暂停或阻塞状态时。否则它将永远不会被抢占。 (当然会触发中断)
举个例子:如果你开始任务A和B任务的优先级A[=如果任务 A 不会通过进入挂起或阻塞状态(例如通过等待通知、信号量、互斥量或其他东西)任务 A 将有 100% 的执行时间而任务 B 0% (零)
如果有多个任务具有相同的最高优先级,则会发生循环抢占。在嵌入式 RTOS 开发中无论如何都是非常罕见的情况。