WORKS

Dependencies:   MAX44000 PWM_Tone_Library nexpaq_mdk

Fork of LED_Demo by Maxim nexpaq

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "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 SIGNALS_TO_EMIT     100
00010 #define SIGNAL_HANDLE_DELEY 25
00011 #define SIGNAL_SET_VALUE    0x01
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_STM32L053R8) || defined(TARGET_STM32L053C8)
00019     #define STACK_SIZE DEFAULT_STACK_SIZE/4
00020 #elif (defined(TARGET_STM32F030R8)) && defined(TOOLCHAIN_IAR)
00021     #define STACK_SIZE DEFAULT_STACK_SIZE/2
00022 #elif (defined(TARGET_EFM32HG_STK3400)) && !defined(TOOLCHAIN_ARM_MICRO)
00023     #define STACK_SIZE 512
00024 #elif (defined(TARGET_EFM32LG_STK3600) || defined(TARGET_EFM32WG_STK3800) || defined(TARGET_EFM32PG_STK3401)) && !defined(TOOLCHAIN_ARM_MICRO)
00025     #define STACK_SIZE 768
00026 #elif (defined(TARGET_EFM32GG_STK3700)) && !defined(TOOLCHAIN_ARM_MICRO)
00027     #define STACK_SIZE 1536
00028 #elif defined(TARGET_MCU_NRF51822)
00029     #define STACK_SIZE 768
00030 #else
00031     #define STACK_SIZE DEFAULT_STACK_SIZE
00032 #endif
00033 
00034 DigitalOut led(LED1);
00035 volatile int signal_counter = 0;
00036 
00037 void led_thread(void const *argument) {
00038     while (true) {
00039         // Signal flags that are reported as event are automatically cleared.
00040         Thread::signal_wait(SIGNAL_SET_VALUE);
00041         led = !led;
00042         signal_counter++;
00043     }
00044 }
00045 
00046 int main (void) {
00047     MBED_HOSTTEST_TIMEOUT(20);
00048     MBED_HOSTTEST_SELECT(default_auto);
00049     MBED_HOSTTEST_DESCRIPTION(Signals messaging);
00050     MBED_HOSTTEST_START("RTOS_4");
00051 
00052     Thread thread(led_thread, NULL, osPriorityNormal, STACK_SIZE);
00053     bool result = true;
00054 
00055     while (true) {
00056         Thread::wait(2 * SIGNAL_HANDLE_DELEY);
00057         thread.signal_set(SIGNAL_SET_VALUE);
00058         if (signal_counter == SIGNALS_TO_EMIT) {
00059             printf("Handled %d signals\r\n", signal_counter);
00060             break;
00061         }
00062     }
00063     MBED_HOSTTEST_RESULT(result);
00064     return 0;
00065 }