int main (void) { Thread thread(send_thread); bool result = true; int result_counter = 0; while (true) { osEvent evt = queue.get(); if (evt.status == osEventMessage) { message_t *message = (message_t*)evt.value.p; const float expected_voltage = CREATE_VOLTAGE(message->counter); const float expected_current = CREATE_CURRENT(message->counter); // Check using macros if received values correspond to values sent via queue bool expected_values = (expected_voltage == message->voltage) && (expected_current == message->current); result = result && expected_values; const char *result_msg = expected_values ? "OK" : "FAIL"; printf("%3d %.2fV %.2fA ... [%s]\r\n", message->counter, message->voltage, message->current, result_msg); mpool.free(message); if (result == false || ++result_counter == QUEUE_SIZE) { break; } } } notify_completion(result); return 0; }
int main (void) { GREENTEA_SETUP(20, "default_auto"); Thread thread(send_thread, NULL, osPriorityNormal, STACK_SIZE); bool result = true; int result_counter = 0; while (true) { osEvent evt = queue.get(); if (evt.status == osEventMessage) { message_t *message = (message_t*)evt.value.p; const float expected_voltage = CREATE_VOLTAGE(message->counter); const float expected_current = CREATE_CURRENT(message->counter); // Check using macros if received values correspond to values sent via queue bool expected_values = (expected_voltage == message->voltage) && (expected_current == message->current); result = result && expected_values; const char *result_msg = expected_values ? "OK" : "FAIL"; printf("%3d %.2fV %.2fA ... [%s]\r\n", message->counter, message->voltage, message->current, result_msg); mpool.free(message); if (result == false || ++result_counter == QUEUE_SIZE) { break; } } } GREENTEA_TESTSUITE_RESULT(result); return 0; }
int main (void) { MBED_HOSTTEST_TIMEOUT(20); MBED_HOSTTEST_SELECT(default_auto); MBED_HOSTTEST_DESCRIPTION(Mail messaging); MBED_HOSTTEST_START("RTOS_6"); Thread thread(send_thread, NULL, osPriorityNormal, STACK_SIZE); bool result = true; int result_counter = 0; while (true) { osEvent evt = mail_box.get(); if (evt.status == osEventMail) { mail_t *mail = (mail_t*)evt.value.p; const float expected_voltage = CREATE_VOLTAGE(mail->counter); const float expected_current = CREATE_CURRENT(mail->counter); // Check using macros if received values correspond to values sent via queue bool expected_values = (expected_voltage == mail->voltage) && (expected_current == mail->current); result = result && expected_values; const char *result_msg = expected_values ? "OK" : "FAIL"; printf("%3d %.2fV %.2fA ... [%s]\r\n", mail->counter, mail->voltage, mail->current, result_msg); mail_box.free(mail); if (result == false || ++result_counter == QUEUE_SIZE) { break; } } } MBED_HOSTTEST_RESULT(result); return 0; }
/* Send Thread */ void send_thread (void const *argument) { static uint32_t i = 10; while (true) { i++; // Fake data update message_t *message = mpool.alloc(); message->voltage = CREATE_VOLTAGE(i); message->current = CREATE_CURRENT(i); message->counter = i; queue.put(message); Thread::wait(QUEUE_PUT_DELAY); } }
void send_thread (void const *argument) { static uint32_t i = 10; while (true) { i++; // fake data update mail_t *mail = mail_box.alloc(); mail->voltage = CREATE_VOLTAGE(i); mail->current = CREATE_CURRENT(i); mail->counter = i; mail_box.put(mail); Thread::wait(QUEUE_PUT_DELAY); } }