- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我想使用 C++
作为我的微 Controller (MSP432) 项目的主要编程语言。
我写了一些不涉及中断服务例程(ISR)的简单脚本。他们都工作得很好。代码如下所示:
/* MSP and DriverLib includes */
/* no <<extern "C">> needed due to the header files implement it. */
#include <ti/devices/msp432p4xx/driverlib/driverlib.h>
int main()
{
/* Some C++ code here that worked fine. */
}
现在我想升级我的代码以获得简单的 ISR,例如 UART 通信(串行 PC 接口(interface))。所以我这样做了:
/* MSP and DriverLib includes */
/* no <<extern "C">> needed due to the header files implement it. */
#include <ti/devices/msp432p4xx/driverlib/driverlib.h>
int main()
{
/* Some C++ code here that worked fine. */
}
void EUSCIA0_IRQHandler(void)
{
/* Some C++ code here that worked fine. */
}
此代码的问题在于未触发 ISR。而是调用 DriverLib 中的默认 ISR。我想知道并开始尝试挖掘自己。
在某些时候,我不小心将extern "C"
放在源代码的C++ 部分中定义的ISR 周围。它奏效了:
/* MSP and DriverLib includes */
/* no <<extern "C">> needed due to the header files implement it. */
#include <ti/devices/msp432p4xx/driverlib/driverlib.h>
int main()
{
/* Some C++ code here that worked fine. */
}
extern "C"
{
void EUSCIA0_IRQHandler(void)
{
/* Only C code here works fine. */
}
}
我假设因为“我”(DriverLib) 在源代码的 C(不是 C++)部分注册了 ISR vector 和 extern
ISR 签名,所以我的 C++ ISR 有点超出范围对于 ISR 签名..
1) 我说得对吗?
但是有一个问题。因为我移动我的 C++ ISR 到 C context 我不能使用 C++ 代码,例如ISR 中不再有类等。
2) 如何在不触及 DriverLib 的 ISR 初始化(例如 startup_msp432p401r_ccs.c
)的情况下,将 C++ 保留在源代码的 C++ 部分的 ISR 中?
C++03
C89
最佳答案
如果驱动库是静态的(即.a
),你可以这样做:
extern "C" void EUSCIA0_IRQHandler(void)
{
// whatever ...
}
这应该用您的函数替换标准函数 [您可以使用 nm
等检查]。而且,当驱动程序库注册 ISR 函数时,它应该捕获你的而不是它内部的
我相信您现在可以从此函数调用 c++
代码。
如果没有,您可能需要:
void cplus_plus_handler(void)
{
// whatever ...
}
extern "C" void EUSCIA0_IRQHandler(void)
{
cplus_plus_handler();
}
这可能按原样工作。但是,cplus_plus_handler
可能需要位于单独的 .cpp
文件中 [C 处理程序位于 .c
中]。
如果库是动态的(即 .so
、.dll
),您可能需要调用注册函数来附加您的 ISR 函数。
关于c++ - 如何使用 MSP432 DriverLib 的 C 代码编写 C++ ISR?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45219247/
我有一段用于 PIC 设备的 C 代码,它按照预定义的模式驱动 4 个独立的继电器,每个继电器通过计数次数和发生频率来单独设置。这种模式会无限延续,但发现标准delay_ms 上的计时不够准确。我希望
我对这种宏尝试有疑问: #define ISR(x) #pragma isr=x 无法编译,因为它试图用不存在的参数替换 #pragma。有什么办法可以实现我想要做的事情吗?我想将 ISR(VEC1)
我现在使用的是嵌入式产品,即 PIC32 Microchip CPU。 我熟悉几个实时内核:AVIX , FreeRTOS , TNKernel ,并且在所有这些函数中,几乎所有函数都有 2 个版本:
我正在调试 arm-family cpu (Cortex M3) 上的固件。 调试器显示 CPU 寄存器,包括一个称为“xPSR”的寄存器,其中包含一个称为“ISR”的子字段。 CPU寄存器中的模式是
我有以下设置经纪人:3 - 全部启动并运行 min.insync.replicas=3。 我创建了一个topic,配置如下 bin\windows\kafka-topics --zookeeper 1
我有以下设置经纪人:3 - 全部启动并运行 min.insync.replicas=3。 我创建了一个topic,配置如下 bin\windows\kafka-topics --zookeeper 1
我有一个带有3个kafka节点和3个zk节点的kakfa集群。 生产者在AWS机器上尝试将数据推送到我的Intranet服务器上运行的kafka集群上。 使用以下命令从控制台创建主题(JOB_AWS_
在mspgcc中声明中断处理程序的首选方法是什么? 最佳答案 请澄清一下,因为这是Google的早期结果。 __attribute__((__interrupt__(TIMER0_A0_VECTOR)
在 ISR 内设置断点是否合法/可能?或者这是特定于硬件的? 最佳答案 是的,这是完全合法的,但是由于其他 ISR 没有及时触发,例如 USB,可能会出现一些小问题。 关于embedded - ISR
我正在使用 Hi-Tech-PICC v9.65PL1 进行 C 语言编程,对 PIC16F876 进行编程。 对于中断,我使用以下结构: void interrupt isr() { if
被零除错误未调用 ISR0。 我的内核主要从 boot.s 调用 void kernel_main() { gdt_install(); idt_install(); isrs_
我用8051的硬件中断0编写了一个简单的led闪烁代码。当按钮被按下时,它进入中断服务程序(ISR)。执行后它应该返回到主函数中,但它没有出现。这是我的c代码。任何积极的答复将不胜感激。 sbit L
在特定的 ISR 之后是否有任何(脏)方法来触发上下文切换到特定的进程? 在正常情况下,在 ISR 之后,被中断的进程会继续运行,我必须等待调度程序选择那个特定的进程。我想在 ISR 之后立即切换到具
我有一个非常简单的程序让我很头疼。 一些背景:我正在 atmelstudio 6 中对 arduino Uno“Atmega328P”进行编程。我在 debugwire 模式下使用 JTAGICE m
有没有一种方法可以从定时器 ISR 中操纵堆栈?所以我可以通过强制退出长时间运行的函数来丢弃堆栈的最高帧吗? (我知道在这种情况下会丢失堆分配的内存) 目标可能是 ARM CPU。 最好的问候 最佳答
我正在研究操作系统,我遇到了 ISR 和中断处理程序这两个术语。他们是同一个机制的两个词吗?如果不是,有什么区别? 最佳答案 中断处理程序和 ISR 没有区别。 Wiki说: In computer
是否可以使用类方法作为中断服务程序? 我有一个 ISR 编写并使用一个函数在 C 中工作: static void interrupt far ISR(...) {} 我尝试在 C++ 中创建
我正在尝试实现该功能 unsigned int (*poll) (struct file *filp, poll_table *wait); 在我的驱动程序中。我已经使用 将设备的文件描述符添加到等待
使用 RTOS(前 FreeRTOS)时,我们为每个线程提供单独的堆栈空间。那么ISR(中断服务程序)呢,它们在内存中是否有单独的堆栈?或者这是可配置的? 如果他们没有一个堆栈来存储 ISR 中声明的
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 6 年前。 Improve
我是一名优秀的程序员,十分优秀!