本帖最后由 shipeng1989 于 2024-7-12 17:33 编辑
最近在使用FreeRTOS的任务消息功能替代事件组,遇到一个毫无头绪的问题:当在中断函数中置位任务消息osSignalSet(TaskHandle,1);时会导致osEvent ReadEvent = osSignalWait(2,100);退出等待状态。仿真调试此时的ReadEvent.value.v=1,但是osSignalWait(2,100);却并没有阻塞100毫秒,不知是何原因?请大神们指教!
以下我附上我的源码:
#define CPL_U3TX_SIG 0x00000001u
#define ACK_U3TX_SIG 0x00000002u
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);
}
}
}
}
以下为中断中发送任务消息: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 */
}
当DMA传输完成后置位“CPL_U3TX_SIG”任务消息,此时任务中ReadEvent = osSignalWait(ACK_U3TX_SIG,100);也退出等待了,我的本意是要收到ACK_U3TX_SIG消息才退出阻塞
|