mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-16 10:03:50 +01:00
On 8-bit and 16-bit platforms `uint32_t` is wider than `void *`, as
pointers are (typically) only 16 bit in size. This causes output like:
Message queue of thread 2
size: 8 (avail: 8)
* 0: sender: 2, type: 0x0000, content: 2701197312 (0)
* 1: sender: 2, type: 0x0001, content: 2701197313 (0x1)
As seen here, the leading two bytes of `msg.content.value` contain
"random" bits, as those bytes are not explicitly initialized.
This fixes the issue by explicitly initializing the whole `msg_t` via
an initializer list.
72 lines
1.4 KiB
C
72 lines
1.4 KiB
C
/*
|
|
* Copyright (C) 2021 Freie Universität Berlin
|
|
* Copyright (C) 2024 TU Dresden
|
|
*
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
* directory for more details.
|
|
*/
|
|
|
|
/**
|
|
* @ingroup tests
|
|
* @{
|
|
*
|
|
* @file
|
|
* @brief testing msg_queue_print
|
|
*
|
|
*
|
|
* @author Julian Holzwarth <julian.holzwarth@fu-berlin.de>
|
|
* @author Mikolai Gütschow <mikolai.guetschow@tu-dresden.de>
|
|
*
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <inttypes.h>
|
|
|
|
#include "msg.h"
|
|
|
|
#define QUEUE_SIZE 8
|
|
|
|
msg_t msg_queue[QUEUE_SIZE];
|
|
|
|
int main(void)
|
|
{
|
|
msg_t msg;
|
|
|
|
msg_queue_print();
|
|
msg_init_queue(msg_queue, QUEUE_SIZE);
|
|
msg_queue_print();
|
|
|
|
/* fill message queue */
|
|
for (uintptr_t i = 0; i < QUEUE_SIZE; i++) {
|
|
msg = (msg_t) {
|
|
.type = i,
|
|
.content.ptr = (void *)i,
|
|
};
|
|
msg_send_to_self(&msg);
|
|
}
|
|
|
|
msg_queue_print();
|
|
|
|
/* drain half of message queue */
|
|
for (uintptr_t i = 0; i < QUEUE_SIZE/2; i++) {
|
|
msg_receive(&msg);
|
|
}
|
|
|
|
msg_queue_print();
|
|
|
|
/* fill up message queue again */
|
|
for (uintptr_t i = QUEUE_SIZE; i < QUEUE_SIZE + QUEUE_SIZE/2; i++) {
|
|
msg = (msg_t) {
|
|
.type = i,
|
|
.content.ptr = (void *)i,
|
|
};
|
|
msg_send_to_self(&msg);
|
|
}
|
|
|
|
msg_queue_print();
|
|
|
|
puts("DONE");
|
|
return 0;
|
|
}
|