6 float voltage; /* AD result of measured voltage */
7 float current; /* AD result of measured current */
8 uint32_t counter; /* A counter value */
11 #define CREATE_VOLTAGE(COUNTER) (COUNTER * 0.1) * 33
12 #define CREATE_CURRENT(COUNTER) (COUNTER * 0.1) * 11
14 #define QUEUE_PUT_DELAY 100
17 * The stack size is defined in cmsis_os.h mainly dependent on the underlying toolchain and
18 * the C standard library. For GCC, ARM_STD and IAR it is defined with a size of 2048 bytes
19 * and for ARM_MICRO 512. Because of reduce RAM size some targets need a reduced stacksize.
21 #if defined(TARGET_STM32L053R8) || defined(TARGET_STM32L053C8)
22 #define STACK_SIZE DEFAULT_STACK_SIZE/4
24 #define STACK_SIZE DEFAULT_STACK_SIZE
27 MemoryPool<message_t, QUEUE_SIZE> mpool;
28 Queue<message_t, QUEUE_SIZE> queue;
31 void send_thread (void const *argument) {
32 static uint32_t i = 10;
34 i++; // Fake data update
35 message_t *message = mpool.alloc();
36 message->voltage = CREATE_VOLTAGE(i);
37 message->current = CREATE_CURRENT(i);
40 Thread::wait(QUEUE_PUT_DELAY);
45 MBED_HOSTTEST_TIMEOUT(20);
46 MBED_HOSTTEST_SELECT(default_auto);
47 MBED_HOSTTEST_DESCRIPTION(Queue messaging);
48 MBED_HOSTTEST_START("RTOS_5");
50 Thread thread(send_thread, NULL, osPriorityNormal, STACK_SIZE);
52 int result_counter = 0;
55 osEvent evt = queue.get();
56 if (evt.status == osEventMessage) {
57 message_t *message = (message_t*)evt.value.p;
58 const float expected_voltage = CREATE_VOLTAGE(message->counter);
59 const float expected_current = CREATE_CURRENT(message->counter);
60 // Check using macros if received values correspond to values sent via queue
61 bool expected_values = (expected_voltage == message->voltage) &&
62 (expected_current == message->current);
63 result = result && expected_values;
64 const char *result_msg = expected_values ? "OK" : "FAIL";
65 printf("%3d %.2fV %.2fA ... [%s]\r\n", message->counter,
70 if (result == false || ++result_counter == QUEUE_SIZE) {
75 MBED_HOSTTEST_RESULT(result);