You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The mailbox message.info in the receiver thread was set to RX_MAILBOX_INFO. According to the zephyr document, the maiblox message.info in the sender thread should be updated to RX_MAILBOX_INFO after k_mbox_put() returned. But in the following test, it was not updated. Below are the test codes.
while (1) {
/* prepare to receive message */
recv_msg.info = RX_MAILBOX_INFO;
recv_msg.size = RX_BUFF_SIZE;
recv_msg.rx_source_thread = K_ANY;
printk("consumer thread waiting mailbox...\n" );
/* get message, but not its data */
k_mbox_get(&my_mailbox, &recv_msg, NULL, K_FOREVER);
/* get message data for only certain types of messages */
if ( TX_MAILBOX_INFO == recv_msg.info ) {
/* retrieve message data and delete the message */
k_mbox_data_get(&recv_msg, buffer);
/* process data in "buffer" */
printk( "mailbox with msg buffer rxed\n" );
} else {
/* ignore message data and delete the message */
k_mbox_data_get(&recv_msg, NULL);
printk("mailbox message.info not updated by mailbox\n" );
}
}
}
static void producer_thread(void)
{
char buffer[TX_BUFF_SIZE];
int buffer_bytes_used;
struct k_mbox_msg send_msg;
while (1) {
buffer_bytes_used = TX_BUFF_SIZE;
memset( buffer, 0x88, buffer_bytes_used );
/* prepare to send message */
send_msg.info = RX_MAILBOX_INFO;
send_msg.size = buffer_bytes_used;
send_msg.tx_data = buffer;
send_msg.tx_block.data = NULL;
send_msg.tx_target_thread = K_ANY;
printk( "Put msg in mailbox...\n" );
/* send message and wait until a consumer receives it */
k_mbox_put(&my_mailbox, &send_msg, K_FOREVER);
/* info, size, and tx_target_thread fields have been updated */
/* verify that message data was fully received */
if (send_msg.size < buffer_bytes_used) {
printk("some message data dropped during transfer!\n");
printk("receiver only received %d bytes\n", send_msg.size);
}
if ( RX_MAILBOX_INFO != send_msg.info) {
printk(".info not updated by mailbox!\n");
}
if ( producer_thread_id != send_msg.rx_source_thread ) {
printk(".rx_source_thread not updated by mailbox!\n");
}
if ( consumer_thread_id != send_msg.tx_target_thread ) {
printk(".tx_target_thread not updated by mailbox!\n");
}
k_msleep( 5000 );
}
}
The text was updated successfully, but these errors were encountered:
The mailbox message.info in the receiver thread was set to RX_MAILBOX_INFO. According to the zephyr document, the maiblox message.info in the sender thread should be updated to RX_MAILBOX_INFO after k_mbox_put() returned. But in the following test, it was not updated. Below are the test codes.
#include <zephyr.h>
#include <device.h>
#include <drivers/gpio.h>
#include <sys/printk.h>
#include <sys/__assert.h>
#include <string.h>
/* size of stack area used by each thread */
#define STACKSIZE 1024
/* scheduling priority used by each thread */
#define PRIORITY 7
#define TX_BUFF_SIZE ( 20 )
#define TX_MAILBOX_INFO ( 0x12345678 )
#define RX_BUFF_SIZE ( 20 )
#define RX_MAILBOX_INFO ( 0x87654321 )
K_MBOX_DEFINE(my_mailbox);
static void consumer_thread( void);
static void producer_thread( void);
K_THREAD_DEFINE(producer_thread_id, STACKSIZE, producer_thread, NULL, NULL, NULL,
PRIORITY, 0, 0);
K_THREAD_DEFINE(consumer_thread_id, STACKSIZE, consumer_thread, NULL, NULL, NULL,
PRIORITY, 0, 0);
static void consumer_thread( void)
{
struct k_mbox_msg recv_msg;
char buffer[RX_BUFF_SIZE];
printk( "consumer_thread started\n" );
}
static void producer_thread(void)
{
char buffer[TX_BUFF_SIZE];
int buffer_bytes_used;
}
The text was updated successfully, but these errors were encountered: