HI,
rfwakeonradioTx例程中,因为功能需要 我使用定时器来定时关闭接收状态,定时回调产生关闭接收的事件,,事件中 我调用RF_cancelCmd,程序如下:
if(cmdHdl >= 0)
{
status= RF_cancelCmd(rfHandle, cmdHdl, 0);
if(status == RF_StatSuccess)
{
if(cmdHdl >= 0)
{
RF_EventMask result = RF_pendCmd(rfHandle, cmdHdl, (RF_EventLastCmdDone |
RF_EventCmdAborted | RF_EventCmdCancelled | RF_EventCmdStopped));
if (result & RF_EventLastCmdDone)
{
asm("nop");
}
}
}
}
,本来应该每调用成功,会进入 回调,但是 我发现 多次调用之后,就会进不了回调了,status 返回RF_StatCmdEnded,这是为什么?
谢谢!
Alvin Chen:
RF_StatCmdEnded: Cmd is found in the pool but was already ended.RF_cancelCmd没有成功,返回这个说明已经结束了。
ruimao cong:
回复 Alvin Chen:
但是后来 进入RX状态再用这个命令取消RX状态的时候,就取消不了了。
Alvin Chen:
回复 ruimao cong:
As given my the RF_Stat enum, 0x04 means RF_StatCmdEnded (Cmd is found in the pool but was already ended). The fact still stands that if you intend to share drivers (in general) across multiple threads, you should implement the appropriate features needed in order to make your usage "thread safe" when needed. Exactly how you do this varies depending on your usage of said driver.
While you could possibly "make due" with simply calling cancelCmd(), relying on the RF driver to figure it out for you, I would still recommend you also keep track of this yourself in your application. In other words, one thread should know if the other threads RF command is still valid or not (for example, if/when you receive a "CMD done" flag, set the handle to NULL and perform NULL checks in your application).
这个是老外的解释你自己理解一下。
ruimao cong:
回复 Alvin Chen:
他这个是说多线程导致的,但是我这个跑的是单线程的,而且调用cancel的函数,只会在接收超时时调用。