两个任务之间的同步 [英] synchronization between two tasks

查看:226
本文介绍了两个任务之间的同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这实际上是嵌入式系统中固件的设计问题
我有两个独立执行的ISR(优先级相同)。
当h / w生成数据时,这些ISR被触发。
我想要一个机制,必须在task1和task2之间进行同步。任务2必须知道在task1中计算出的某些值,然后在计算任务2中的某些值时必须将其考虑在内。
我没有使用操作系统原语,即系统没有任何操作系统。
任务1在ISR2和上下文中的ISR1和task2的上下文中执行。
我们使用的处理器是STMicroelectronics 32控制器

This is actually a design question for firmware in an embedded system I have two ISRs (of same priority) executed independently . These ISRs are triggered when the h/w generates data. I want a mechanism which must be put in place to synchronise between task1 and task2. task 2 must know about the certain values calculated in task1 which must then be taken into account while computing certain values in task2. I don't have OS primitives to use ie the system does not have any Operating system. Task1 is executed within the context of ISR1 and task2 within the context of ISR2. The processor which we use is a STMicroelectronics 32 controller

编辑:附加信息
处理器连接到某些IP,它们在触发中断时准备好数据。这些IP作为输入流媒体帧数据上的累加器类型。

additional info The processor is connected to certain IPs which trigger interrupts when they are ready with data. These IPs act as type of Accumulators on input streaming frame data.

推荐答案

我不会在中断上下文中进行大量处理读取数据并设置一个标志。

I wouldn't do heavy processing in interrupt context, just read the data and set a flag.

然后可以在主循环中的简单调度程序中检查标志,以便根据需要执行任务。所以任务不能互相干扰,看不到其他任务的输出不一致。

The flags can then be checked in a simple scheduler in the main loop to execute the tasks as necessary. So tasks can't interrupt each other and can't see inconsistent output of the other task.

任务还可以设置这样一个标志来激活另一个任务。例如。 Task1可以激活Task2,因为Task2需要Task1的值。

A task could also set such a flag to activate another task. E.g. Task1 could activate Task2 because Task2 needs values from Task1.

对于在ISR中读取的数据,您需要一些缓冲区。取决于可能是环形缓冲区或双缓冲区的传入数据的时间。

For the data that is read in the ISR you need some buffer. Depending on the timing of your incoming data that might be a ring buffer or a double buffer.

这篇关于两个任务之间的同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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