Lee Kai Xuan / mbed-os

Fork of mbed-os by erkin yucel

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

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 /*
00010  * The stack size is defined in cmsis_os.h mainly dependent on the underlying toolchain and
00011  * the C standard library. For GCC, ARM_STD and IAR it is defined with a size of 2048 bytes
00012  * and for ARM_MICRO 512. Because of reduce RAM size some targets need a reduced stacksize.
00013  */
00014 #if defined(TARGET_STM32F070RB) && defined(TOOLCHAIN_GCC)
00015 #define STACK_SIZE DEFAULT_STACK_SIZE/2
00016 #elif (defined(TARGET_EFM32HG_STK3400)) && !defined(TOOLCHAIN_ARM_MICRO)
00017 #define STACK_SIZE 512
00018 #elif (defined(TARGET_EFM32LG_STK3600) || defined(TARGET_EFM32WG_STK3800) || defined(TARGET_EFM32PG_STK3401)) && !defined(TOOLCHAIN_ARM_MICRO)
00019 #define STACK_SIZE 768
00020 #elif (defined(TARGET_EFM32GG_STK3700)) && !defined(TOOLCHAIN_ARM_MICRO)
00021 #define STACK_SIZE 1536
00022 #elif defined(TARGET_MCU_NRF51822) || defined(TARGET_MCU_NRF52832)
00023 #define STACK_SIZE 768
00024 #elif defined(TARGET_XDOT_L151CC)
00025 #define STACK_SIZE 1024
00026 #else
00027 #define STACK_SIZE DEFAULT_STACK_SIZE
00028 #endif
00029 
00030 #define SIGNAL_PRINT_TICK 0x01
00031 
00032 DigitalOut led1(LED1);
00033 
00034 const int total_ticks = 10;
00035 
00036 void print_tick_thread() {
00037     for (int i = 0; i <= total_ticks; i++) {
00038       Thread::signal_wait(SIGNAL_PRINT_TICK);
00039       greentea_send_kv("tick", i);
00040       led1 = !led1;
00041     }
00042 }
00043 
00044 int main() {
00045     GREENTEA_SETUP(total_ticks + 5, "timing_drift_auto");
00046     
00047     Thread tick_thread(osPriorityNormal, STACK_SIZE);
00048     tick_thread.start(print_tick_thread);
00049     
00050     for (int i = 0; i <= total_ticks; i++) {
00051         Thread::wait(1000);
00052         tick_thread.signal_set(SIGNAL_PRINT_TICK);
00053     }
00054     
00055     tick_thread.join();
00056     GREENTEA_TESTSUITE_RESULT(1);
00057 }