Hi,
I have a project which reads sensor data (let's call it Thread A) and passes on to another thread (let's call it Thread B) through message queue. The size of the queue is 10 sensor data, and each thread is running periodically at 1 second.
When deep sleep configuration is enabled, I can see the data is passed on successfully to another thread (as verified through serial printout on Thread B).
However when deep sleep is disabled (when I need to use JTAG debugging), the data is not passed on to another thread, and the program just stuck there. It could be both the threads are not running. But when I use JTAG debugging to step through the program, everything is working fine.
- Are there any clues on how the deep sleep configuration will affect the message queue?
- Also, does the QAPI qurt_pipe_send() perform deep copy of the data to be transferred, which in this case I can modify the data after the QAPI is called? Or do I have to keep the data untouched until it has been read by another thread?
Thank you in advance!
Hi Foong,
Could you confirm if qurt_pipe_send() is not called in ISR context?
Please let me know which RTOS option is used, ThreadX or FreeRTOS.
Thanks
BR,
Jayden
Hi Jaydenk
Both the qurt_pipe_send() (called in Thread A) and qurt_pipe_receive() (called in Thread B) are called in thread context. The default RTOS is used, which is ThreadX.
Thank you for your help!
Best regards,
Foong
HI Foong,
I simply modified HelloWorld demo to create two threads.
Thread B could receive message through pipe regardless of sleep configuration.
Could you try to compare how you're using the API with following example?
static void A_Thread(void *Param)
{
while(true)
{
qurt_pipe_send(pipe_hello, message_tx);
Sleep(1000); //sleep for 1 sec
}
}
static void B_Thread(void *Param)
{
while(true)
{
qurt_pipe_receive(pipe_hello, message_rx);
}
}
///////////////////////////////////////////////////////////////////////////
#define DEFAULT_QUEUE_DEPTH 32
qurt_pipe_t pipe_hello;
char message_tx [10] = "Message!";
char message_rx [10];
///////////////////////////////////////////////////////////////////////////
// Initialize
qurt_pipe_attr_t qurt_pipe_attr;
memset(&qurt_pipe_attr, 0, sizeof(qurt_pipe_attr));
qurt_pipe_attr_init(&qurt_pipe_attr);
qurt_pipe_attr_set_element_size(&qurt_pipe_attr, sizeof(message_tx));
qurt_pipe_attr_set_elements(&qurt_pipe_attr, DEFAULT_QUEUE_DEPTH);
Result = qurt_pipe_create(&pipe_hello, &qurt_pipe_attr);
if(Result != QURT_EOK)
{
print error
return;
}
Thanks
BR,
Jayden
Hi Jayden,
I compared your code to mine. I found out that I have a printf() call executed after qurt_pipe_send(), which causes the system to have this behavior.
Removing the printf() call has solved the problem. Thank you for your help.
Another question I would like to ask:
Does the QAPI qurt_pipe_send() perform deep copy of the data to be transferred, which in this case I can modify the data after the qurt_pipe_send() API is called? Or do I have to keep the data untouched until it has been read by another thread?
Hi Foong,
Yes, If two threads print logs into UART. We need to make sure previous UART TX was done.
Following example just shows how to avoid that situation by mutex lock/unlock.
void PAL_Console_Write(uint32_t Length, const char *Buffer)
{
+ if(qurt_mutex_lock_timed(&UartMutex, QURT_TIME_WAIT_FOREVER) == QURT_EOK)
{
if((Length != 0) && (Buffer != NULL) && (PAL_Context.Uart_Enabled))
{
PAL_Context.BytesToTx = Length;
/* Transmit the data. */
if(qapi_UART_Transmit(PAL_Context.Console_UART, (char *)Buffer, Length, NULL) == QAPI_OK)
{
/* Wait for the packet to be sent. */
qurt_signal_wait(&(PAL_Context.Event), PAL_EVENT_MASK_TRANSMIT, QURT_SIGNAL_ATTR_WAIT_ANY | QURT_SIGNAL_ATTR_CLEAR_MASK);
}
}
}
else
{
PAL_CONSOLE_WRITE_STRING_LITERAL("Failed - qurt_mutex_lock_timed");
}
+ qurt_mutex_unlock(&UartMutex);
}
Thanks
BR,
Jayden
Hi Foong,
Regarding qurt_pipe_send() will do deep copy into pipe queue.
Thanks
BR,
Jayden
Hi Foong,
Regarding qurt_pipe_send() will do deep copy into pipe queue.
Thanks
BR,
Jayden
Hi Jayden,
Thank you for your help.
Best regards,
Foong