dhgdh
Dependencies: MAX44000 PWM_Tone_Library nexpaq_mdk
Fork of LED_Demo by
mbd_os/TESTS/mbedmicro-rtos-mbed/isr/main.cpp@1:55a6170b404f, 2016-09-17 (annotated)
- Committer:
- nexpaq
- Date:
- Sat Sep 17 16:32:05 2016 +0000
- Revision:
- 1:55a6170b404f
checking in for sharing
Who changed what in which revision?
User | Revision | Line number | New 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 QUEUE_SIZE 5 |
nexpaq | 1:55a6170b404f | 10 | #define THREAD_DELAY 250 |
nexpaq | 1:55a6170b404f | 11 | #define QUEUE_PUT_ISR_VALUE 128 |
nexpaq | 1:55a6170b404f | 12 | #define QUEUE_PUT_THREAD_VALUE 127 |
nexpaq | 1:55a6170b404f | 13 | |
nexpaq | 1:55a6170b404f | 14 | /* |
nexpaq | 1:55a6170b404f | 15 | * The stack size is defined in cmsis_os.h mainly dependent on the underlying toolchain and |
nexpaq | 1:55a6170b404f | 16 | * the C standard library. For GCC, ARM_STD and IAR it is defined with a size of 2048 bytes |
nexpaq | 1:55a6170b404f | 17 | * and for ARM_MICRO 512. Because of reduce RAM size some targets need a reduced stacksize. |
nexpaq | 1:55a6170b404f | 18 | */ |
nexpaq | 1:55a6170b404f | 19 | #if defined(TARGET_STM32L053R8) || defined(TARGET_STM32L053C8) |
nexpaq | 1:55a6170b404f | 20 | #define STACK_SIZE DEFAULT_STACK_SIZE/4 |
nexpaq | 1:55a6170b404f | 21 | #elif (defined(TARGET_STM32F030R8)) && defined(TOOLCHAIN_IAR) |
nexpaq | 1:55a6170b404f | 22 | #define STACK_SIZE DEFAULT_STACK_SIZE/2 |
nexpaq | 1:55a6170b404f | 23 | #elif (defined(TARGET_EFM32HG_STK3400)) && !defined(TOOLCHAIN_ARM_MICRO) |
nexpaq | 1:55a6170b404f | 24 | #define STACK_SIZE 512 |
nexpaq | 1:55a6170b404f | 25 | #elif (defined(TARGET_EFM32LG_STK3600) || defined(TARGET_EFM32WG_STK3800) || defined(TARGET_EFM32PG_STK3401)) && !defined(TOOLCHAIN_ARM_MICRO) |
nexpaq | 1:55a6170b404f | 26 | #define STACK_SIZE 768 |
nexpaq | 1:55a6170b404f | 27 | #elif (defined(TARGET_EFM32GG_STK3700)) && !defined(TOOLCHAIN_ARM_MICRO) |
nexpaq | 1:55a6170b404f | 28 | #define STACK_SIZE 1536 |
nexpaq | 1:55a6170b404f | 29 | #elif defined(TARGET_MCU_NRF51822) || defined(TARGET_MCU_NRF52832) |
nexpaq | 1:55a6170b404f | 30 | #define STACK_SIZE 768 |
nexpaq | 1:55a6170b404f | 31 | #else |
nexpaq | 1:55a6170b404f | 32 | #define STACK_SIZE DEFAULT_STACK_SIZE |
nexpaq | 1:55a6170b404f | 33 | #endif |
nexpaq | 1:55a6170b404f | 34 | |
nexpaq | 1:55a6170b404f | 35 | Queue<uint32_t, QUEUE_SIZE> queue; |
nexpaq | 1:55a6170b404f | 36 | |
nexpaq | 1:55a6170b404f | 37 | DigitalOut myled(LED1); |
nexpaq | 1:55a6170b404f | 38 | |
nexpaq | 1:55a6170b404f | 39 | void queue_isr() { |
nexpaq | 1:55a6170b404f | 40 | |
nexpaq | 1:55a6170b404f | 41 | queue.put((uint32_t*)QUEUE_PUT_ISR_VALUE); |
nexpaq | 1:55a6170b404f | 42 | myled = !myled; |
nexpaq | 1:55a6170b404f | 43 | } |
nexpaq | 1:55a6170b404f | 44 | |
nexpaq | 1:55a6170b404f | 45 | void queue_thread(void const *argument) { |
nexpaq | 1:55a6170b404f | 46 | while (true) { |
nexpaq | 1:55a6170b404f | 47 | queue.put((uint32_t*)QUEUE_PUT_THREAD_VALUE); |
nexpaq | 1:55a6170b404f | 48 | Thread::wait(THREAD_DELAY); |
nexpaq | 1:55a6170b404f | 49 | } |
nexpaq | 1:55a6170b404f | 50 | } |
nexpaq | 1:55a6170b404f | 51 | |
nexpaq | 1:55a6170b404f | 52 | int main (void) { |
nexpaq | 1:55a6170b404f | 53 | GREENTEA_SETUP(20, "default_auto"); |
nexpaq | 1:55a6170b404f | 54 | |
nexpaq | 1:55a6170b404f | 55 | Thread thread(queue_thread, NULL, osPriorityNormal, STACK_SIZE); |
nexpaq | 1:55a6170b404f | 56 | Ticker ticker; |
nexpaq | 1:55a6170b404f | 57 | ticker.attach(queue_isr, 1.0); |
nexpaq | 1:55a6170b404f | 58 | int isr_puts_counter = 0; |
nexpaq | 1:55a6170b404f | 59 | bool result = true; |
nexpaq | 1:55a6170b404f | 60 | |
nexpaq | 1:55a6170b404f | 61 | while (true) { |
nexpaq | 1:55a6170b404f | 62 | osEvent evt = queue.get(); |
nexpaq | 1:55a6170b404f | 63 | if (evt.status != osEventMessage) { |
nexpaq | 1:55a6170b404f | 64 | printf("QUEUE_GET: Status(0x%02X) ... [FAIL]\r\n", evt.status); |
nexpaq | 1:55a6170b404f | 65 | result = false; |
nexpaq | 1:55a6170b404f | 66 | break; |
nexpaq | 1:55a6170b404f | 67 | } else { |
nexpaq | 1:55a6170b404f | 68 | printf("QUEUE_GET: Value(%u) ... [OK]\r\n", evt.value.v); |
nexpaq | 1:55a6170b404f | 69 | if (evt.value.v == QUEUE_PUT_ISR_VALUE) { |
nexpaq | 1:55a6170b404f | 70 | isr_puts_counter++; |
nexpaq | 1:55a6170b404f | 71 | } |
nexpaq | 1:55a6170b404f | 72 | if (isr_puts_counter >= QUEUE_SIZE) { |
nexpaq | 1:55a6170b404f | 73 | break; |
nexpaq | 1:55a6170b404f | 74 | } |
nexpaq | 1:55a6170b404f | 75 | } |
nexpaq | 1:55a6170b404f | 76 | } |
nexpaq | 1:55a6170b404f | 77 | |
nexpaq | 1:55a6170b404f | 78 | GREENTEA_TESTSUITE_RESULT(result); |
nexpaq | 1:55a6170b404f | 79 | return 0; |
nexpaq | 1:55a6170b404f | 80 | } |