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