关于FreeRTOS的任务消息替代事件组问题
<div><table style="overflow-wrap:break-word; word-break:break-all; empty-cells:show; border-collapse:collapse; table-layout:fixed">
<tbody style="overflow-wrap:break-word; word-break:break-all">
<tr>
<td id="postmessage_14145388">最近在使用FreeRTOS的任务消息功能替代事件组,遇到一个毫无头绪的问题:当在中断函数中置位任务消息osSignalSet(TaskHandle,1);时会导致osEvent ReadEvent = osSignalWait(2,100);退出等待状态。仿真调试此时的ReadEvent.value.v=1,但是osSignalWait(2,100);却并没有阻塞100毫秒,不知是何原因?请大神们指教!<br style="overflow-wrap:break-word; word-break:break-all" />
<br style="overflow-wrap:break-word; word-break:break-all" />
以下我附上我的源码:<br style="overflow-wrap:break-word; word-break:break-all" />
<strong style="overflow-wrap:break-word; word-break:break-all">#define</strong> <strong style="overflow-wrap:break-word; word-break:break-all">CPL_U3TX_SIG</strong> 0x00000001u<br style="overflow-wrap:break-word; word-break:break-all" />
<strong style="overflow-wrap:break-word; word-break:break-all">#define</strong> <strong style="overflow-wrap:break-word; word-break:break-all">ACK_U3TX_SIG</strong> 0x00000002u<br style="overflow-wrap:break-word; word-break:break-all" />
<br style="overflow-wrap:break-word; word-break:break-all" />
<br style="overflow-wrap:break-word; word-break:break-all" />
<br style="overflow-wrap:break-word; word-break:break-all" />
<div>
<div><a onclick="copycode($('code_n8s'));" style="overflow-wrap:break-word; word-break:break-all; color:white; cursor:pointer">复制</a></div>
<pre id="code_n8s">
<code>
void StartTaskAndroidTx(void const * argument)
{
MyDataStruct_t *tx_buffer;
osSignalSet(AndroidTxHandle,CPL_U3TX_SIG);//osSemaphoreRelease(myBinarySemU3TxHandle);
/* Infinite loop */
for(;;)
{
if (pdPASS==xQueueReceive(U3TxQueueHandle, (uint8_t*)&tx_buffer, osWaitForever))
{
if (NULL!=tx_buffer) {
uint8_t data_len=tx_buffer->length;
if (0!=data_len) {
osEvent ReadEvent;
osSignalWait(CPL_U3TX_SIG,100);
osSignalWait(ACK_U3TX_SIG,0);
memcpy(DMA_USART3_TxBuf,tx_buffer->DatArea,data_len);
vPortFree((uint8_t*)tx_buffer);
for (int i = 0; i < 10; ++i) {
LCD_RS485_DE=LCD_RS485_RE=1;
LL_DMA_DisableStream(DMA1,LL_DMA_STREAM_3);
LL_DMA_SetDataLength(DMA1,LL_DMA_STREAM_3,data_len);
LL_DMA_EnableStream(DMA1,LL_DMA_STREAM_3);
ReadEvent = osSignalWait(ACK_U3TX_SIG,100);
if (ReadEvent.value.v & ACK_U3TX_SIG)break;
}
}
else vPortFree((uint8_t*)tx_buffer);
}
}
}
}
</code></pre>
</div>
以下为中断中发送任务消息:
<div>
<div ><a onclick="copycode($('code_CkT'));" style="overflow-wrap:break-word; word-break:break-all; color:white; cursor:pointer">复制</a></div>
<pre id="code_CkT">
<code>void DMA1_Stream3_IRQHandler(void)
{
/* USER CODE BEGIN DMA1_Stream3_IRQn 0 */
if (LL_DMA_IsEnabledIT_TC(DMA1,LL_DMA_STREAM_3)!=RESET && LL_DMA_IsActiveFlag_TC3(DMA1) != RESET)
{
LL_DMA_ClearFlag_TC3(DMA1);
LL_DMA_DisableStream(DMA1,LL_DMA_STREAM_3);
osSignalSet(AndroidTxHandle,CPL_U3TX_SIG);
}
/* USER CODE END DMA1_Stream3_IRQn 0 */
/* USER CODE BEGIN DMA1_Stream3_IRQn 1 */
/* USER CODE END DMA1_Stream3_IRQn 1 */
}
</code></pre>
</div>
<br style="overflow-wrap:break-word; word-break:break-all" />
当DMA传输完成后置位“CPL_U3TX_SIG”任务消息,此时任务中ReadEvent = osSignalWait(ACK_U3TX_SIG,100);也退出等待了,我的本意是要收到ACK_U3TX_SIG消息才退出阻塞<br style="overflow-wrap:break-word; word-break:break-all" />
<br style="overflow-wrap:break-word; word-break:break-all" />
</td>
</tr>
</tbody>
</table>
</div>
<div style="border-bottom:1px dashed #c8cfd4 !important; border-top:1px dashed #cdcdcd">
<div>
<p ><a href="javascript:;" id="mgc_post_14145388" onmouseover="showMenu(this.id)" style="overflow-wrap:break-word; word-break:break-all; color:#333333; background:url("https://bbs.21ic.com/static/image/common/arrwd.gif") 100% 50% no-repeat; cursor:pointer; white-space:nowrap">使用特权</a></p>
<em style="overflow-wrap:break-word; word-break:break-all; color:#666666;Microsoft Yahei", Simsun; white-space:normal; background-color:#f2f9fd"><a href="javascript:;" id="morebtn14145388" initialized="true" onclick="delayShow(this, function(){showMenu({'ctrlid':'morebtn14145388','duration':2});});return false;" onmouseover="delayShow(this, function(){showMenu({'ctrlid':'morebtn14145388','duration':2});});" style="overflow-wrap:break-word; word-break:break-all; color:#333333; background:url("https://bbs.21ic.com/static/image/common/icon_morebtns.png") 0px -24px no-repeat; overflow:hidden" title="更多操作">更多操作</a></em></div>
</div>
<p>当DMA传输完成后置位“CPL_U3TX_SIG”任务消息,此时任务中ReadEvent = osSignalWait(ACK_U3TX_SIG,100);退出等待,</p>
<p>和收到ACK_U3TX_SIG消息退出阻塞</p>
<p>两者有什么不同呢<br />
</p>
Jacktang 发表于 2024-7-13 09:19
当DMA传输完成后置位“CPL_U3TX_SIG”任务消息,此时任务中ReadEvent = osSignalWait(ACK_U3TX_S ...
<p>“CPL_U3TX_SIG”消息位用来指示DMA传输完成,"ACK_U3TX_SIG"消息位我在串口接收处理中置位,用来指示串口数据收到从机应答不需要再重发此数据了。因为我做了一个串口数据重发机制,只有收到目标设备应答才会退出重发,否则会重发10次数据。</p>
<p>看看它下面的定时器是什么情况</p>
freebsder 发表于 2024-7-16 15:24
看看它下面的定时器是什么情况
<p>不知是哪个下面的定时器?</p>
<p>系统定时器</p>
页:
[1]