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.
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(void const *argument) { 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(queue_thread, NULL, osPriorityNormal, STACK_SIZE); 00054 Ticker ticker; 00055 ticker.attach(queue_isr, 1.0); 00056 int isr_puts_counter = 0; 00057 bool result = true; 00058 00059 while (true) { 00060 osEvent evt = queue.get(); 00061 if (evt.status != osEventMessage) { 00062 printf("QUEUE_GET: Status(0x%02X) ... [FAIL]\r\n", evt.status); 00063 result = false; 00064 break; 00065 } else { 00066 printf("QUEUE_GET: Value(%u) ... [OK]\r\n", evt.value.v); 00067 if (evt.value.v == QUEUE_PUT_ISR_VALUE) { 00068 isr_puts_counter++; 00069 } 00070 if (isr_puts_counter >= QUEUE_SIZE) { 00071 break; 00072 } 00073 } 00074 } 00075 00076 GREENTEA_TESTSUITE_RESULT(result); 00077 return 0; 00078 }
Generated on Tue Jul 12 2022 17:34:48 by
1.7.2