通知上层有关收到消息的首选方法

发布于 2024-08-03 08:39:51 字数 164 浏览 4 评论 0原文

我正在为嵌入式 C 项目编写 RS485 驱动程序。

驱动程序正在侦听传入的消息,并应在收到完整消息并准备好读取时通知上层应用程序。

执行此操作的首选方法是什么?

通过使用中断?触发 SW 中断并从 ISR 中读取消息?

让应用程序定期轮询驱动程序?

I'm writing a RS485 driver for an embedded C project.

The driver is listening for incoming messages and should notify the upper layer application when a complete message is received and ready to be read.

What is the preferred way to do this?

By using interrupts? Trigger a SW interrupt and read the message from within the ISR?

Let the application poll the driver periodically?

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

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

发布评论

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

评论(1

被你宠の有点坏 2024-08-10 08:39:51

我通常在 ISR 中做尽可能少的工作来保护接收到的数据或清理传输的数据。这通常意味着将数据从硬件缓冲区读取到循环缓冲区中。

在接收时,对于多线程操作系统,接收中断会清空硬件、清除中断并向线程发出信号以服务接收到的数据。

对于轮询环境,接收中断会清空硬件,清除中断,并设置一个标志来通知轮询循环它有东西要处理。

由于中断可能随时发生,因此必须使用互斥机制来保护 ISR 和轮询循环或处理线程之间共享的数据结构。
通常,这意味着在调整指针或计数时暂时禁用中断。

如果接收到的数据已打包,您可以在 ISR 中寻找数据包边界
仅当完整数据包到达时才通知处理程序。

I generally do as little work as possible in the ISR to secure the received data or clean up the transmitted data. This will usually mean reading data out of the hardware buffers and into a circular buffer.

On receive, for a multi-threaded os, a receive interrupt empties the hardware, clears the interrupt and signals a thread to service the received data.

For a polling environment, a receive interrupt empties the harwdware, clears the interrupt, and sets a flag to notify the polling loop that it has something to process.

Since interrupts can occur any time the data structures shared between the ISR and the polling loop or processing thread must be protected using a mutual exclusion mechanism.
Often this will mean disabling interrupts briefly while you adjust a pointer or count.

If the received data is packetized you can hunt for packet boundaries in the ISR
and notify the handler only when a full packet has arrived.

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