Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 #include "greentea-client/test_env.h" 00003 #include "rtos.h" 00004 00005 #if defined(MBED_RTOS_SINGLE_THREAD) 00006 #error [NOT_SUPPORTED] test not supported 00007 #endif 00008 00009 typedef struct { 00010 float voltage; /* AD result of measured voltage */ 00011 float current; /* AD result of measured current */ 00012 uint32_t counter; /* A counter value */ 00013 } message_t; 00014 00015 #define CREATE_VOLTAGE(COUNTER) (COUNTER * 0.1) * 33 00016 #define CREATE_CURRENT(COUNTER) (COUNTER * 0.1) * 11 00017 #define QUEUE_SIZE 16 00018 #define QUEUE_PUT_DELAY 100 00019 00020 /* 00021 * The stack size is defined in cmsis_os.h mainly dependent on the underlying toolchain and 00022 * the C standard library. For GCC, ARM_STD and IAR it is defined with a size of 2048 bytes 00023 * and for ARM_MICRO 512. Because of reduce RAM size some targets need a reduced stacksize. 00024 */ 00025 #if (defined(TARGET_EFM32HG_STK3400)) && !defined(TOOLCHAIN_ARM_MICRO) 00026 #define STACK_SIZE 512 00027 #elif (defined(TARGET_EFM32LG_STK3600) || defined(TARGET_EFM32WG_STK3800) || defined(TARGET_EFM32PG_STK3401)) && !defined(TOOLCHAIN_ARM_MICRO) 00028 #define STACK_SIZE 768 00029 #elif (defined(TARGET_EFM32GG_STK3700)) && !defined(TOOLCHAIN_ARM_MICRO) 00030 #define STACK_SIZE 1536 00031 #elif defined(TARGET_MCU_NRF51822) || defined(TARGET_MCU_NRF52832) 00032 #define STACK_SIZE 768 00033 #elif defined(TARGET_XDOT_L151CC) 00034 #define STACK_SIZE 1024 00035 #else 00036 #define STACK_SIZE DEFAULT_STACK_SIZE 00037 #endif 00038 00039 MemoryPool<message_t, QUEUE_SIZE> mpool; 00040 Queue<message_t, QUEUE_SIZE> queue; 00041 00042 /* Send Thread */ 00043 void send_thread (void const *argument) { 00044 static uint32_t i = 10; 00045 while (true) { 00046 i++; // Fake data update 00047 message_t *message = mpool.alloc(); 00048 message->voltage = CREATE_VOLTAGE(i); 00049 message->current = CREATE_CURRENT(i); 00050 message->counter = i; 00051 queue.put(message); 00052 Thread::wait(QUEUE_PUT_DELAY); 00053 } 00054 } 00055 00056 int main (void) { 00057 GREENTEA_SETUP(20, "default_auto"); 00058 00059 Thread thread(send_thread, NULL, osPriorityNormal, STACK_SIZE); 00060 bool result = true; 00061 int result_counter = 0; 00062 00063 while (true) { 00064 osEvent evt = queue.get(); 00065 if (evt.status == osEventMessage) { 00066 message_t *message = (message_t*)evt.value.p; 00067 const float expected_voltage = CREATE_VOLTAGE(message->counter); 00068 const float expected_current = CREATE_CURRENT(message->counter); 00069 // Check using macros if received values correspond to values sent via queue 00070 bool expected_values = (expected_voltage == message->voltage) && 00071 (expected_current == message->current); 00072 result = result && expected_values; 00073 const char *result_msg = expected_values ? "OK" : "FAIL"; 00074 printf("%3d %.2fV %.2fA ... [%s]\r\n", message->counter, 00075 message->voltage, 00076 message->current, 00077 result_msg); 00078 mpool.free(message); 00079 if (result == false || ++result_counter == QUEUE_SIZE) { 00080 break; 00081 } 00082 } 00083 } 00084 GREENTEA_TESTSUITE_RESULT(result); 00085 return 0; 00086 }
Generated on Tue Jul 12 2022 17:34:48 by
1.7.2