mbed-os
Fork of mbed-os by
TESTS/mbedmicro-rtos-mbed/basic/main.cpp@0:f269e3021894, 2016-10-23 (annotated)
- Committer:
- elessair
- Date:
- Sun Oct 23 15:10:02 2016 +0000
- Revision:
- 0:f269e3021894
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
elessair | 0:f269e3021894 | 1 | #include "mbed.h" |
elessair | 0:f269e3021894 | 2 | #include "greentea-client/test_env.h" |
elessair | 0:f269e3021894 | 3 | #include "rtos.h" |
elessair | 0:f269e3021894 | 4 | |
elessair | 0:f269e3021894 | 5 | #if defined(MBED_RTOS_SINGLE_THREAD) |
elessair | 0:f269e3021894 | 6 | #error [NOT_SUPPORTED] test not supported |
elessair | 0:f269e3021894 | 7 | #endif |
elessair | 0:f269e3021894 | 8 | |
elessair | 0:f269e3021894 | 9 | /* |
elessair | 0:f269e3021894 | 10 | * The stack size is defined in cmsis_os.h mainly dependent on the underlying toolchain and |
elessair | 0:f269e3021894 | 11 | * the C standard library. For GCC, ARM_STD and IAR it is defined with a size of 2048 bytes |
elessair | 0:f269e3021894 | 12 | * and for ARM_MICRO 512. Because of reduce RAM size some targets need a reduced stacksize. |
elessair | 0:f269e3021894 | 13 | */ |
elessair | 0:f269e3021894 | 14 | #if defined(TARGET_STM32F070RB) && defined(TOOLCHAIN_GCC) |
elessair | 0:f269e3021894 | 15 | #define STACK_SIZE DEFAULT_STACK_SIZE/2 |
elessair | 0:f269e3021894 | 16 | #elif (defined(TARGET_EFM32HG_STK3400)) && !defined(TOOLCHAIN_ARM_MICRO) |
elessair | 0:f269e3021894 | 17 | #define STACK_SIZE 512 |
elessair | 0:f269e3021894 | 18 | #elif (defined(TARGET_EFM32LG_STK3600) || defined(TARGET_EFM32WG_STK3800) || defined(TARGET_EFM32PG_STK3401)) && !defined(TOOLCHAIN_ARM_MICRO) |
elessair | 0:f269e3021894 | 19 | #define STACK_SIZE 768 |
elessair | 0:f269e3021894 | 20 | #elif (defined(TARGET_EFM32GG_STK3700)) && !defined(TOOLCHAIN_ARM_MICRO) |
elessair | 0:f269e3021894 | 21 | #define STACK_SIZE 1536 |
elessair | 0:f269e3021894 | 22 | #elif defined(TARGET_MCU_NRF51822) || defined(TARGET_MCU_NRF52832) |
elessair | 0:f269e3021894 | 23 | #define STACK_SIZE 768 |
elessair | 0:f269e3021894 | 24 | #elif defined(TARGET_XDOT_L151CC) |
elessair | 0:f269e3021894 | 25 | #define STACK_SIZE 1024 |
elessair | 0:f269e3021894 | 26 | #else |
elessair | 0:f269e3021894 | 27 | #define STACK_SIZE DEFAULT_STACK_SIZE |
elessair | 0:f269e3021894 | 28 | #endif |
elessair | 0:f269e3021894 | 29 | |
elessair | 0:f269e3021894 | 30 | #define SIGNAL_PRINT_TICK 0x01 |
elessair | 0:f269e3021894 | 31 | |
elessair | 0:f269e3021894 | 32 | DigitalOut led1(LED1); |
elessair | 0:f269e3021894 | 33 | |
elessair | 0:f269e3021894 | 34 | const int total_ticks = 10; |
elessair | 0:f269e3021894 | 35 | |
elessair | 0:f269e3021894 | 36 | void print_tick_thread() { |
elessair | 0:f269e3021894 | 37 | for (int i = 0; i <= total_ticks; i++) { |
elessair | 0:f269e3021894 | 38 | Thread::signal_wait(SIGNAL_PRINT_TICK); |
elessair | 0:f269e3021894 | 39 | greentea_send_kv("tick", i); |
elessair | 0:f269e3021894 | 40 | led1 = !led1; |
elessair | 0:f269e3021894 | 41 | } |
elessair | 0:f269e3021894 | 42 | } |
elessair | 0:f269e3021894 | 43 | |
elessair | 0:f269e3021894 | 44 | int main() { |
elessair | 0:f269e3021894 | 45 | GREENTEA_SETUP(total_ticks + 5, "timing_drift_auto"); |
elessair | 0:f269e3021894 | 46 | |
elessair | 0:f269e3021894 | 47 | Thread tick_thread(osPriorityNormal, STACK_SIZE); |
elessair | 0:f269e3021894 | 48 | tick_thread.start(print_tick_thread); |
elessair | 0:f269e3021894 | 49 | |
elessair | 0:f269e3021894 | 50 | for (int i = 0; i <= total_ticks; i++) { |
elessair | 0:f269e3021894 | 51 | Thread::wait(1000); |
elessair | 0:f269e3021894 | 52 | tick_thread.signal_set(SIGNAL_PRINT_TICK); |
elessair | 0:f269e3021894 | 53 | } |
elessair | 0:f269e3021894 | 54 | |
elessair | 0:f269e3021894 | 55 | tick_thread.join(); |
elessair | 0:f269e3021894 | 56 | GREENTEA_TESTSUITE_RESULT(1); |
elessair | 0:f269e3021894 | 57 | } |