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