Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-os by
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 #define SIGNAL_SET_VALUE 0x01 00010 const int SIGNALS_TO_EMIT = 100; 00011 const int SIGNAL_HANDLE_DELEY = 25; 00012 00013 /* 00014 * The stack size is defined in cmsis_os.h mainly dependent on the underlying toolchain and 00015 * the C standard library. For GCC, ARM_STD and IAR it is defined with a size of 2048 bytes 00016 * and for ARM_MICRO 512. Because of reduce RAM size some targets need a reduced stacksize. 00017 */ 00018 #if (defined(TARGET_EFM32HG_STK3400)) && !defined(TOOLCHAIN_ARM_MICRO) 00019 #define STACK_SIZE 512 00020 #elif (defined(TARGET_EFM32LG_STK3600) || defined(TARGET_EFM32WG_STK3800) || defined(TARGET_EFM32PG_STK3401)) && !defined(TOOLCHAIN_ARM_MICRO) 00021 #define STACK_SIZE 768 00022 #elif (defined(TARGET_EFM32GG_STK3700)) && !defined(TOOLCHAIN_ARM_MICRO) 00023 #define STACK_SIZE 1536 00024 #elif defined(TARGET_MCU_NRF51822) || defined(TARGET_MCU_NRF52832) 00025 #define STACK_SIZE 768 00026 #elif defined(TARGET_XDOT_L151CC) 00027 #define STACK_SIZE 1024 00028 #else 00029 #define STACK_SIZE DEFAULT_STACK_SIZE 00030 #endif 00031 00032 DigitalOut led(LED1); 00033 int signal_counter = 0; 00034 00035 void led_thread(void const *argument) { 00036 while (true) { 00037 // Signal flags that are reported as event are automatically cleared. 00038 Thread::signal_wait(SIGNAL_SET_VALUE); 00039 led = !led; 00040 signal_counter++; 00041 } 00042 } 00043 00044 int main (void) { 00045 GREENTEA_SETUP(20, "default_auto"); 00046 00047 Thread thread(led_thread, NULL, osPriorityNormal, STACK_SIZE); 00048 bool result = false; 00049 00050 printf("Handling %d signals...\r\n", SIGNALS_TO_EMIT); 00051 00052 while (true) { 00053 Thread::wait(2 * SIGNAL_HANDLE_DELEY); 00054 thread.signal_set(SIGNAL_SET_VALUE); 00055 if (signal_counter == SIGNALS_TO_EMIT) { 00056 printf("Handled %d signals\r\n", signal_counter); 00057 result = true; 00058 break; 00059 } 00060 } 00061 GREENTEA_TESTSUITE_RESULT(result); 00062 return 0; 00063 }
Generated on Tue Jul 12 2022 13:15:58 by
