Dependents:   sensomed

Committer:
switches
Date:
Tue Nov 08 18:27:11 2016 +0000
Revision:
0:0e018d759a2a
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
switches 0:0e018d759a2a 1 #include "mbed.h"
switches 0:0e018d759a2a 2 #include "greentea-client/test_env.h"
switches 0:0e018d759a2a 3 #include "rtos.h"
switches 0:0e018d759a2a 4
switches 0:0e018d759a2a 5 #if defined(MBED_RTOS_SINGLE_THREAD)
switches 0:0e018d759a2a 6 #error [NOT_SUPPORTED] test not supported
switches 0:0e018d759a2a 7 #endif
switches 0:0e018d759a2a 8
switches 0:0e018d759a2a 9 #define SIGNAL_SET_VALUE 0x01
switches 0:0e018d759a2a 10 const int SIGNALS_TO_EMIT = 100;
switches 0:0e018d759a2a 11 const int SIGNAL_HANDLE_DELEY = 25;
switches 0:0e018d759a2a 12
switches 0:0e018d759a2a 13 /*
switches 0:0e018d759a2a 14 * The stack size is defined in cmsis_os.h mainly dependent on the underlying toolchain and
switches 0:0e018d759a2a 15 * the C standard library. For GCC, ARM_STD and IAR it is defined with a size of 2048 bytes
switches 0:0e018d759a2a 16 * and for ARM_MICRO 512. Because of reduce RAM size some targets need a reduced stacksize.
switches 0:0e018d759a2a 17 */
switches 0:0e018d759a2a 18 #if (defined(TARGET_EFM32HG_STK3400)) && !defined(TOOLCHAIN_ARM_MICRO)
switches 0:0e018d759a2a 19 #define STACK_SIZE 512
switches 0:0e018d759a2a 20 #elif (defined(TARGET_EFM32LG_STK3600) || defined(TARGET_EFM32WG_STK3800) || defined(TARGET_EFM32PG_STK3401)) && !defined(TOOLCHAIN_ARM_MICRO)
switches 0:0e018d759a2a 21 #define STACK_SIZE 768
switches 0:0e018d759a2a 22 #elif (defined(TARGET_EFM32GG_STK3700)) && !defined(TOOLCHAIN_ARM_MICRO)
switches 0:0e018d759a2a 23 #define STACK_SIZE 1536
switches 0:0e018d759a2a 24 #elif defined(TARGET_MCU_NRF51822) || defined(TARGET_MCU_NRF52832)
switches 0:0e018d759a2a 25 #define STACK_SIZE 768
switches 0:0e018d759a2a 26 #elif defined(TARGET_XDOT_L151CC)
switches 0:0e018d759a2a 27 #define STACK_SIZE 1024
switches 0:0e018d759a2a 28 #else
switches 0:0e018d759a2a 29 #define STACK_SIZE DEFAULT_STACK_SIZE
switches 0:0e018d759a2a 30 #endif
switches 0:0e018d759a2a 31
switches 0:0e018d759a2a 32 DigitalOut led(LED1);
switches 0:0e018d759a2a 33 int signal_counter = 0;
switches 0:0e018d759a2a 34
switches 0:0e018d759a2a 35 void led_thread(void const *argument) {
switches 0:0e018d759a2a 36 while (true) {
switches 0:0e018d759a2a 37 // Signal flags that are reported as event are automatically cleared.
switches 0:0e018d759a2a 38 Thread::signal_wait(SIGNAL_SET_VALUE);
switches 0:0e018d759a2a 39 led = !led;
switches 0:0e018d759a2a 40 signal_counter++;
switches 0:0e018d759a2a 41 }
switches 0:0e018d759a2a 42 }
switches 0:0e018d759a2a 43
switches 0:0e018d759a2a 44 int main (void) {
switches 0:0e018d759a2a 45 GREENTEA_SETUP(20, "default_auto");
switches 0:0e018d759a2a 46
switches 0:0e018d759a2a 47 Thread thread(led_thread, NULL, osPriorityNormal, STACK_SIZE);
switches 0:0e018d759a2a 48 bool result = false;
switches 0:0e018d759a2a 49
switches 0:0e018d759a2a 50 printf("Handling %d signals...\r\n", SIGNALS_TO_EMIT);
switches 0:0e018d759a2a 51
switches 0:0e018d759a2a 52 while (true) {
switches 0:0e018d759a2a 53 Thread::wait(2 * SIGNAL_HANDLE_DELEY);
switches 0:0e018d759a2a 54 thread.signal_set(SIGNAL_SET_VALUE);
switches 0:0e018d759a2a 55 if (signal_counter == SIGNALS_TO_EMIT) {
switches 0:0e018d759a2a 56 printf("Handled %d signals\r\n", signal_counter);
switches 0:0e018d759a2a 57 result = true;
switches 0:0e018d759a2a 58 break;
switches 0:0e018d759a2a 59 }
switches 0:0e018d759a2a 60 }
switches 0:0e018d759a2a 61 GREENTEA_TESTSUITE_RESULT(result);
switches 0:0e018d759a2a 62 return 0;
switches 0:0e018d759a2a 63 }