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: mbed-TFT-example-NCS36510 mbed-Accelerometer-example-NCS36510 mbed-Accelerometer-example-NCS36510
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 QUEUE_SIZE 5 00010 #define THREAD_DELAY 250 00011 #define QUEUE_PUT_ISR_VALUE 128 00012 #define QUEUE_PUT_THREAD_VALUE 127 00013 00014 /* 00015 * The stack size is defined in cmsis_os.h mainly dependent on the underlying toolchain and 00016 * the C standard library. For GCC, ARM_STD and IAR it is defined with a size of 2048 bytes 00017 * and for ARM_MICRO 512. Because of reduce RAM size some targets need a reduced stacksize. 00018 */ 00019 #if (defined(TARGET_EFM32HG_STK3400)) && !defined(TOOLCHAIN_ARM_MICRO) 00020 #define STACK_SIZE 512 00021 #elif (defined(TARGET_EFM32LG_STK3600) || defined(TARGET_EFM32WG_STK3800) || defined(TARGET_EFM32PG_STK3401)) && !defined(TOOLCHAIN_ARM_MICRO) 00022 #define STACK_SIZE 768 00023 #elif (defined(TARGET_EFM32GG_STK3700)) && !defined(TOOLCHAIN_ARM_MICRO) 00024 #define STACK_SIZE 1536 00025 #elif defined(TARGET_MCU_NRF51822) || defined(TARGET_MCU_NRF52832) 00026 #define STACK_SIZE 768 00027 #elif defined(TARGET_XDOT_L151CC) 00028 #define STACK_SIZE 1024 00029 #else 00030 #define STACK_SIZE DEFAULT_STACK_SIZE 00031 #endif 00032 00033 Queue<uint32_t, QUEUE_SIZE> queue; 00034 00035 DigitalOut myled(LED1); 00036 00037 void queue_isr() { 00038 00039 queue.put((uint32_t*)QUEUE_PUT_ISR_VALUE); 00040 myled = !myled; 00041 } 00042 00043 void queue_thread() { 00044 while (true) { 00045 queue.put((uint32_t*)QUEUE_PUT_THREAD_VALUE); 00046 Thread::wait(THREAD_DELAY); 00047 } 00048 } 00049 00050 int main (void) { 00051 GREENTEA_SETUP(20, "default_auto"); 00052 00053 Thread thread(osPriorityNormal, STACK_SIZE); 00054 thread.start(queue_thread); 00055 Ticker ticker; 00056 ticker.attach(queue_isr, 1.0); 00057 int isr_puts_counter = 0; 00058 bool result = true; 00059 00060 while (true) { 00061 osEvent evt = queue.get(); 00062 if (evt.status != osEventMessage) { 00063 printf("QUEUE_GET: Status(0x%02X) ... [FAIL]\r\n", evt.status); 00064 result = false; 00065 break; 00066 } else { 00067 printf("QUEUE_GET: Value(%u) ... [OK]\r\n", evt.value.v); 00068 if (evt.value.v == QUEUE_PUT_ISR_VALUE) { 00069 isr_puts_counter++; 00070 } 00071 if (isr_puts_counter >= QUEUE_SIZE) { 00072 break; 00073 } 00074 } 00075 } 00076 00077 GREENTEA_TESTSUITE_RESULT(result); 00078 return 0; 00079 }
Generated on Tue Jul 12 2022 11:02:46 by
