Forums - Message Queue not working when sleep is disabled

9 posts / 0 new
Last post
Message Queue not working when sleep is disabled
Foong
Join Date: 30 Aug 18
Posts: 15
Posted: Tue, 2018-11-27 18:15
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.
 
  1. Are there any clues on how the deep sleep configuration will affect the message queue?
  2. 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!

  • Up0
  • Down0
jaydenk
Join Date: 21 Jun 18
Posts: 64
Posted: Wed, 2018-11-28 15:53

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

  • Up0
  • Down0
Foong
Join Date: 30 Aug 18
Posts: 15
Posted: Wed, 2018-11-28 22:37

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

  • Up0
  • Down0
jaydenk
Join Date: 21 Jun 18
Posts: 64
Posted: Thu, 2018-11-29 14:28

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

  • Up0
  • Down0
Foong
Join Date: 30 Aug 18
Posts: 15
Posted: Wed, 2018-12-05 00:31

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?

  • Up0
  • Down0
jaydenk
Join Date: 21 Jun 18
Posts: 64
Posted: Wed, 2018-12-05 15:32

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

  • Up0
  • Down0
jaydenk
Join Date: 21 Jun 18
Posts: 64
Posted: Wed, 2018-12-05 15:56

Hi Foong,

Regarding qurt_pipe_send() will do deep copy into pipe queue.

Thanks
BR,
Jayden

  • Up0
  • Down0
jaydenk
Join Date: 21 Jun 18
Posts: 64
Posted: Wed, 2018-12-05 15:56

Hi Foong,

Regarding qurt_pipe_send() will do deep copy into pipe queue.

Thanks
BR,
Jayden

  • Up0
  • Down0
Foong
Join Date: 30 Aug 18
Posts: 15
Posted: Thu, 2018-12-06 01:00

Hi Jayden,

Thank you for your help.

 

Best regards,
Foong

  • Up0
  • Down0
or Register

Opinions expressed in the content posted here are the personal opinions of the original authors, and do not necessarily reflect those of Qualcomm Incorporated or its subsidiaries (“Qualcomm”). The content is provided for informational purposes only and is not meant to be an endorsement or representation by Qualcomm or any other party. This site may also provide links or references to non-Qualcomm sites and resources. Qualcomm makes no representations, warranties, or other commitments whatsoever about any non-Qualcomm sites or third-party resources that may be referenced, accessible from, or linked to this site.