]>
git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/libraries/tests/rtos/mbed/mail/main.cpp
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 Mail
<mail_t
, QUEUE_SIZE
> mail_box
;
29 void send_thread (void const *argument
) {
30 static uint32_t i
= 10;
32 i
++; // fake data update
33 mail_t
*mail
= mail_box
.alloc();
34 mail
->voltage
= CREATE_VOLTAGE(i
);
35 mail
->current
= CREATE_CURRENT(i
);
38 Thread::wait(QUEUE_PUT_DELAY
);
43 MBED_HOSTTEST_TIMEOUT(20);
44 MBED_HOSTTEST_SELECT(default_auto
);
45 MBED_HOSTTEST_DESCRIPTION(Mail messaging
);
46 MBED_HOSTTEST_START("RTOS_6");
48 Thread
thread(send_thread
, NULL
, osPriorityNormal
, STACK_SIZE
);
50 int result_counter
= 0;
53 osEvent evt
= mail_box
.get();
54 if (evt
.status
== osEventMail
) {
55 mail_t
*mail
= (mail_t
*)evt
.value
.p
;
56 const float expected_voltage
= CREATE_VOLTAGE(mail
->counter
);
57 const float expected_current
= CREATE_CURRENT(mail
->counter
);
58 // Check using macros if received values correspond to values sent via queue
59 bool expected_values
= (expected_voltage
== mail
->voltage
) &&
60 (expected_current
== mail
->current
);
61 result
= result
&& expected_values
;
62 const char *result_msg
= expected_values
? "OK" : "FAIL";
63 printf("%3d %.2fV %.2fA ... [%s]\r\n", mail
->counter
,
68 if (result
== false || ++result_counter
== QUEUE_SIZE
) {
73 MBED_HOSTTEST_RESULT(result
);