Development mbed library for MAX32630FTHR
Dependents: blinky_max32630fthr
TESTS/mbedmicro-rtos-mbed/mail/main.cpp@3:1198227e6421, 2016-12-16 (annotated)
- Committer:
- switches
- Date:
- Fri Dec 16 16:27:57 2016 +0000
- Revision:
- 3:1198227e6421
- Parent:
- 0:5c4d7b2438d3
Changed ADC scale for MAX32625 platforms to 1.2V full scale to match MAX32630 platforms
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
switches | 0:5c4d7b2438d3 | 1 | #include "mbed.h" |
switches | 0:5c4d7b2438d3 | 2 | #include "greentea-client/test_env.h" |
switches | 0:5c4d7b2438d3 | 3 | #include "rtos.h" |
switches | 0:5c4d7b2438d3 | 4 | |
switches | 0:5c4d7b2438d3 | 5 | #if defined(MBED_RTOS_SINGLE_THREAD) |
switches | 0:5c4d7b2438d3 | 6 | #error [NOT_SUPPORTED] test not supported |
switches | 0:5c4d7b2438d3 | 7 | #endif |
switches | 0:5c4d7b2438d3 | 8 | |
switches | 0:5c4d7b2438d3 | 9 | typedef struct { |
switches | 0:5c4d7b2438d3 | 10 | float voltage; /* AD result of measured voltage */ |
switches | 0:5c4d7b2438d3 | 11 | float current; /* AD result of measured current */ |
switches | 0:5c4d7b2438d3 | 12 | uint32_t counter; /* A counter value */ |
switches | 0:5c4d7b2438d3 | 13 | } mail_t; |
switches | 0:5c4d7b2438d3 | 14 | |
switches | 0:5c4d7b2438d3 | 15 | #define CREATE_VOLTAGE(COUNTER) (COUNTER * 0.1) * 33 |
switches | 0:5c4d7b2438d3 | 16 | #define CREATE_CURRENT(COUNTER) (COUNTER * 0.1) * 11 |
switches | 0:5c4d7b2438d3 | 17 | #define QUEUE_SIZE 16 |
switches | 0:5c4d7b2438d3 | 18 | #define QUEUE_PUT_DELAY 100 |
switches | 0:5c4d7b2438d3 | 19 | |
switches | 0:5c4d7b2438d3 | 20 | /* |
switches | 0:5c4d7b2438d3 | 21 | * The stack size is defined in cmsis_os.h mainly dependent on the underlying toolchain and |
switches | 0:5c4d7b2438d3 | 22 | * the C standard library. For GCC, ARM_STD and IAR it is defined with a size of 2048 bytes |
switches | 0:5c4d7b2438d3 | 23 | * and for ARM_MICRO 512. Because of reduce RAM size some targets need a reduced stacksize. |
switches | 0:5c4d7b2438d3 | 24 | */ |
switches | 0:5c4d7b2438d3 | 25 | #if (defined(TARGET_EFM32HG_STK3400)) && !defined(TOOLCHAIN_ARM_MICRO) |
switches | 0:5c4d7b2438d3 | 26 | #define STACK_SIZE 512 |
switches | 0:5c4d7b2438d3 | 27 | #elif (defined(TARGET_EFM32LG_STK3600) || defined(TARGET_EFM32WG_STK3800) || defined(TARGET_EFM32PG_STK3401)) && !defined(TOOLCHAIN_ARM_MICRO) |
switches | 0:5c4d7b2438d3 | 28 | #define STACK_SIZE 768 |
switches | 0:5c4d7b2438d3 | 29 | #elif (defined(TARGET_EFM32GG_STK3700)) && !defined(TOOLCHAIN_ARM_MICRO) |
switches | 0:5c4d7b2438d3 | 30 | #define STACK_SIZE 1536 |
switches | 0:5c4d7b2438d3 | 31 | #elif defined(TARGET_MCU_NRF51822) || defined(TARGET_MCU_NRF52832) |
switches | 0:5c4d7b2438d3 | 32 | #define STACK_SIZE 768 |
switches | 0:5c4d7b2438d3 | 33 | #elif defined(TARGET_XDOT_L151CC) |
switches | 0:5c4d7b2438d3 | 34 | #define STACK_SIZE 1024 |
switches | 0:5c4d7b2438d3 | 35 | #else |
switches | 0:5c4d7b2438d3 | 36 | #define STACK_SIZE DEFAULT_STACK_SIZE |
switches | 0:5c4d7b2438d3 | 37 | #endif |
switches | 0:5c4d7b2438d3 | 38 | |
switches | 0:5c4d7b2438d3 | 39 | Mail<mail_t, QUEUE_SIZE> mail_box; |
switches | 0:5c4d7b2438d3 | 40 | |
switches | 0:5c4d7b2438d3 | 41 | void send_thread (void const *argument) { |
switches | 0:5c4d7b2438d3 | 42 | static uint32_t i = 10; |
switches | 0:5c4d7b2438d3 | 43 | while (true) { |
switches | 0:5c4d7b2438d3 | 44 | i++; // fake data update |
switches | 0:5c4d7b2438d3 | 45 | mail_t *mail = mail_box.alloc(); |
switches | 0:5c4d7b2438d3 | 46 | mail->voltage = CREATE_VOLTAGE(i); |
switches | 0:5c4d7b2438d3 | 47 | mail->current = CREATE_CURRENT(i); |
switches | 0:5c4d7b2438d3 | 48 | mail->counter = i; |
switches | 0:5c4d7b2438d3 | 49 | mail_box.put(mail); |
switches | 0:5c4d7b2438d3 | 50 | Thread::wait(QUEUE_PUT_DELAY); |
switches | 0:5c4d7b2438d3 | 51 | } |
switches | 0:5c4d7b2438d3 | 52 | } |
switches | 0:5c4d7b2438d3 | 53 | |
switches | 0:5c4d7b2438d3 | 54 | int main (void) { |
switches | 0:5c4d7b2438d3 | 55 | GREENTEA_SETUP(20, "default_auto"); |
switches | 0:5c4d7b2438d3 | 56 | |
switches | 0:5c4d7b2438d3 | 57 | Thread thread(send_thread, NULL, osPriorityNormal, STACK_SIZE); |
switches | 0:5c4d7b2438d3 | 58 | bool result = true; |
switches | 0:5c4d7b2438d3 | 59 | int result_counter = 0; |
switches | 0:5c4d7b2438d3 | 60 | |
switches | 0:5c4d7b2438d3 | 61 | while (true) { |
switches | 0:5c4d7b2438d3 | 62 | osEvent evt = mail_box.get(); |
switches | 0:5c4d7b2438d3 | 63 | if (evt.status == osEventMail) { |
switches | 0:5c4d7b2438d3 | 64 | mail_t *mail = (mail_t*)evt.value.p; |
switches | 0:5c4d7b2438d3 | 65 | const float expected_voltage = CREATE_VOLTAGE(mail->counter); |
switches | 0:5c4d7b2438d3 | 66 | const float expected_current = CREATE_CURRENT(mail->counter); |
switches | 0:5c4d7b2438d3 | 67 | // Check using macros if received values correspond to values sent via queue |
switches | 0:5c4d7b2438d3 | 68 | bool expected_values = (expected_voltage == mail->voltage) && |
switches | 0:5c4d7b2438d3 | 69 | (expected_current == mail->current); |
switches | 0:5c4d7b2438d3 | 70 | result = result && expected_values; |
switches | 0:5c4d7b2438d3 | 71 | const char *result_msg = expected_values ? "OK" : "FAIL"; |
switches | 0:5c4d7b2438d3 | 72 | printf("%3d %.2fV %.2fA ... [%s]\r\n", mail->counter, |
switches | 0:5c4d7b2438d3 | 73 | mail->voltage, |
switches | 0:5c4d7b2438d3 | 74 | mail->current, |
switches | 0:5c4d7b2438d3 | 75 | result_msg); |
switches | 0:5c4d7b2438d3 | 76 | mail_box.free(mail); |
switches | 0:5c4d7b2438d3 | 77 | if (result == false || ++result_counter == QUEUE_SIZE) { |
switches | 0:5c4d7b2438d3 | 78 | break; |
switches | 0:5c4d7b2438d3 | 79 | } |
switches | 0:5c4d7b2438d3 | 80 | } |
switches | 0:5c4d7b2438d3 | 81 | } |
switches | 0:5c4d7b2438d3 | 82 | GREENTEA_TESTSUITE_RESULT(result); |
switches | 0:5c4d7b2438d3 | 83 | return 0; |
switches | 0:5c4d7b2438d3 | 84 | } |