Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The mailbox message.info in the receiver thread is not updated. #30022

Closed
jasonedn opened this issue Nov 14, 2020 · 1 comment
Closed

The mailbox message.info in the receiver thread is not updated. #30022

jasonedn opened this issue Nov 14, 2020 · 1 comment

Comments

@jasonedn
Copy link

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" );

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 );
}

}

@jasonedn
Copy link
Author

I found send_msg.info was not set to the expected TX_MAILBOX_INFO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant