nkjnm

Dependencies:   MAX44000 nexpaq_mdk

Fork of LED_Demo by Maxim nexpaq

Committer:
nexpaq
Date:
Sat Sep 17 16:32:05 2016 +0000
Revision:
1:55a6170b404f
checking in for sharing

Who changed what in which revision?

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