注:在这种情况下,术语" ISR“实际上并不是指ISR向量。司机们有很多窍门。其中之一是处理无线电传送芯片产生的中断。SX1276_LoRaRadio驱动程序有一个线程来检查实际的中断源。这是因为所有这些事情都是在一个rtos上工作(mbed,基于RTX5),并且rtos不允许直接访问MCU中断向量。因此,一旦触发单片机的PIN_X,线程就会读取用于实际中断源的无线电芯片寄存器。
我正在为ARM单片机开发。在我的板上有一个无线电传送芯片(sx1276)。无线电芯片驱动程序需要指向我自己的ISR成员函数的指针。因此,我必须将ISR成员函数的指针传递给同一个类的另一个成员对象(一个保存指针的结构)。详细解释如下。
带有设备寄存器(SX1276_LoRaRadio.cpp).的低级无线电驱动程序
中的其他两个。
收音机有一些中断引脚,在发生某些事件时被触发。但由于制造商是如何设计驱动程序的,我只能使用其中之一。这一点在一开始就解释过了。这些事件是结构的成员:
// This is in LoRaRadio.h
typedef struct radio_events {
/**
* Callback when Transmission is done.
*/
mbed::Callback<void()> tx_done;
<other mbed::Callback type members>
} radio_events_t;我的ProtoTelecom.hpp看起来是这样的:
class ProtoTelecom: public manageCommands {
public:
explicit ProtoTelecom(LoRaRadio *Radio, tcm_Manager *tcm);
static void OnTxDone(void);
void nonstaticTxDone(void);
<other corresponding ISR member functions>
private:
static radio_events_t RadioEvents;
<other private stuff here>
};然后在ProtoTelecom.cpp中,我将相应的静态成员函数的指针分配给RadioEvents成员:
radio_events_t ProtoTelecom::RadioEvents = {
.tx_done = ProtoTelecom::OnTxDone,
<other pointer assignments>
};
ProtoTelecom::ProtoTelecom(LoRaRadio *Radio, c_TC_Manager *tcm) : manageCommands()
{
<other stuff goes here>
Radio->init_radio(&RadioEvents);
}我的问题是我必须有多个ProtoRadio实例。但是,无线电isr函数必须是静态的,因为在c++中不允许在类本身内传递成员函数指针。这只会阻止我初始化另一个hw,因为它们都执行相同的isr函数。那么,如何将非静态成员函数的指针传递给类本身内的另一个非静态成员对象呢?就像这样:
ProtoTelecom::ProtoTelecom(LoRaRadio *Radio, c_TC_Manager *tcm) : manageCommands()
{
<other stuff goes here>
RadioEvents.tx_done = nonstaticTxDone;
Radio->init_radio(&RadioEvents);
}我找到了this线程,但情况与我的略有不同,我无法使它适应我的情况。我问题的主题是标题,但我知道我想要取得的成果有点奇怪,需要一些技巧。因此,如果有其他方法来实现我的最终目标,那对我来说也是可以的。谢谢。
发布于 2022-07-27 14:40:11
正如@Wutz在他的第三条评论中所指出的,正确的方式是使用mbed::Callback。下面是我的新构造函数:
ProtoTelecom::ProtoTelecom(LoRaRadio *Radio, c_TC_Manager *tcm) : manageCommands()
{
this->Radio = Radio;
this->tcm = tcm;
//Inizialize the radio
newRadioEvents.tx_done = mbed::Callback<void()>(this, &ProtoTelecom::nonstaticOnTxDone);
newRadioEvents.tx_timeout = mbed::Callback<void()>(this, &ProtoTelecom::nonstaticOnTxTimeout);
newRadioEvents.rx_done = mbed::Callback<void(const uint8_t *, uint16_t , int16_t , int8_t)>(this, &ProtoTelecom::nonstaticOnRxDone);
newRadioEvents.rx_timeout = mbed::Callback<void()>(this, &ProtoTelecom::nonstaticOnRxTimeout);
newRadioEvents.rx_error = mbed::Callback<void()>(this, &ProtoTelecom::nonstaticOnRxError);
Radio->init_radio( &newRadioEvents );
switchModem(radio_mode);
setState(RADIO_RECEIVE);
}newRadioEvents是radio_events_t的一个非静态实例。
https://stackoverflow.com/questions/72992732
复制相似问题