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