如何实现ISR和main()同步?

发布于 2024-12-22 02:14:24 字数 633 浏览 4 评论 0原文

我是ARM微控制器编程的初学者,有以下问题需要解决。

  1. 程序中有两个ISR:ISR_TimerISR_Buffer。 ISR_Timer 每 5 分钟执行一次。每次应填充外部设备缓冲区时都会执行 ISR_Buffer(一秒内多次)。外部设备缓冲区很小。
  2. ISR_Buffer 从外部 SRAM 获取数据来填充缓冲区。 SRAM中有两个大的缓冲区。第一个当前使用,第二个用于重新计算。然后它们被交换。
  3. ISR_Timer 设置标志,指​​示 ma​​in() 重新计算外部 SRAM 中的第二个缓冲区。之后 ISR_Buffer 使用该缓冲区。第一个用于下次重新计算。重新计算大约需要1分钟。

问题是 main() 和 ISR_Buffer 都访问外部 SRAM,并且这些访问不是原子的。 main() 函数在缓冲区重新计算期间将数据写入 SRAM。 ISR_Buffers 读取数据以填充小设备缓冲区。如何解决这个问题?

IDE:IAR。 芯片:AT91SAM7。

I'm a beginner in ARM microcontroller programming and have the following problem to be solved.

  1. There are two ISRs in the program: ISR_Timer and ISR_Buffer. ISR_Timer is executed each 5 minutes. ISR_Buffer is executed each time external device buffer should be filled (several times in a second). External device buffer is a small one.
  2. ISR_Buffer takes data to fill buffer from external SRAM. There are two big buffers in SRAM. First is currently used, second is used for recalculation. Then they are swapped.
  3. ISR_Timer sets the flag that indicates the main() to recalculate the second buffer in external SRAM. After that ISR_Buffer uses that buffer. The first one is used for next recalculation. Recalculation takes about 1 minute.

The problem is that both main() and ISR_Buffer access external SRAM and those accesses are not atomic. main() function writes data to SRAM during buffer recalculation. ISR_Buffers reads data to fill small device buffer. How to solve this issue?

IDE: IAR. Chip: AT91SAM7.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倦话 2024-12-29 02:14:24

如果我理解正确,您可以使用循环缓冲区。如果实施得当,它将保证原子写入和读取。

或者,您可以在缓冲区操作期间屏蔽 main() 中的中断,以确保 ISR 无法访问数据。但这些操作必须很快,否则您的外部设备将出现缓冲区下溢。

If I understand right, you can use cyclic buffer. Being implemented right, it will guarantee atomic write and read.

Or, you can mask interrupts in main() during buffer manipulation to ensure that ISR has no access to data. But those manipulations must be fast, else your external device will get buffer underflow.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文