Development mbed library for MAX32630FTHR
Dependents: blinky_max32630fthr
TESTS/mbedmicro-rtos-mbed/isr/main.cpp@3:1198227e6421, 2016-12-16 (annotated)
- Committer:
- switches
- Date:
- Fri Dec 16 16:27:57 2016 +0000
- Revision:
- 3:1198227e6421
- Parent:
- 0:5c4d7b2438d3
Changed ADC scale for MAX32625 platforms to 1.2V full scale to match MAX32630 platforms
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
switches | 0:5c4d7b2438d3 | 1 | #include "mbed.h" |
switches | 0:5c4d7b2438d3 | 2 | #include "greentea-client/test_env.h" |
switches | 0:5c4d7b2438d3 | 3 | #include "rtos.h" |
switches | 0:5c4d7b2438d3 | 4 | |
switches | 0:5c4d7b2438d3 | 5 | #if defined(MBED_RTOS_SINGLE_THREAD) |
switches | 0:5c4d7b2438d3 | 6 | #error [NOT_SUPPORTED] test not supported |
switches | 0:5c4d7b2438d3 | 7 | #endif |
switches | 0:5c4d7b2438d3 | 8 | |
switches | 0:5c4d7b2438d3 | 9 | #define QUEUE_SIZE 5 |
switches | 0:5c4d7b2438d3 | 10 | #define THREAD_DELAY 250 |
switches | 0:5c4d7b2438d3 | 11 | #define QUEUE_PUT_ISR_VALUE 128 |
switches | 0:5c4d7b2438d3 | 12 | #define QUEUE_PUT_THREAD_VALUE 127 |
switches | 0:5c4d7b2438d3 | 13 | |
switches | 0:5c4d7b2438d3 | 14 | /* |
switches | 0:5c4d7b2438d3 | 15 | * The stack size is defined in cmsis_os.h mainly dependent on the underlying toolchain and |
switches | 0:5c4d7b2438d3 | 16 | * the C standard library. For GCC, ARM_STD and IAR it is defined with a size of 2048 bytes |
switches | 0:5c4d7b2438d3 | 17 | * and for ARM_MICRO 512. Because of reduce RAM size some targets need a reduced stacksize. |
switches | 0:5c4d7b2438d3 | 18 | */ |
switches | 0:5c4d7b2438d3 | 19 | #if (defined(TARGET_EFM32HG_STK3400)) && !defined(TOOLCHAIN_ARM_MICRO) |
switches | 0:5c4d7b2438d3 | 20 | #define STACK_SIZE 512 |
switches | 0:5c4d7b2438d3 | 21 | #elif (defined(TARGET_EFM32LG_STK3600) || defined(TARGET_EFM32WG_STK3800) || defined(TARGET_EFM32PG_STK3401)) && !defined(TOOLCHAIN_ARM_MICRO) |
switches | 0:5c4d7b2438d3 | 22 | #define STACK_SIZE 768 |
switches | 0:5c4d7b2438d3 | 23 | #elif (defined(TARGET_EFM32GG_STK3700)) && !defined(TOOLCHAIN_ARM_MICRO) |
switches | 0:5c4d7b2438d3 | 24 | #define STACK_SIZE 1536 |
switches | 0:5c4d7b2438d3 | 25 | #elif defined(TARGET_MCU_NRF51822) || defined(TARGET_MCU_NRF52832) |
switches | 0:5c4d7b2438d3 | 26 | #define STACK_SIZE 768 |
switches | 0:5c4d7b2438d3 | 27 | #elif defined(TARGET_XDOT_L151CC) |
switches | 0:5c4d7b2438d3 | 28 | #define STACK_SIZE 1024 |
switches | 0:5c4d7b2438d3 | 29 | #else |
switches | 0:5c4d7b2438d3 | 30 | #define STACK_SIZE DEFAULT_STACK_SIZE |
switches | 0:5c4d7b2438d3 | 31 | #endif |
switches | 0:5c4d7b2438d3 | 32 | |
switches | 0:5c4d7b2438d3 | 33 | Queue<uint32_t, QUEUE_SIZE> queue; |
switches | 0:5c4d7b2438d3 | 34 | |
switches | 0:5c4d7b2438d3 | 35 | DigitalOut myled(LED1); |
switches | 0:5c4d7b2438d3 | 36 | |
switches | 0:5c4d7b2438d3 | 37 | void queue_isr() { |
switches | 0:5c4d7b2438d3 | 38 | |
switches | 0:5c4d7b2438d3 | 39 | queue.put((uint32_t*)QUEUE_PUT_ISR_VALUE); |
switches | 0:5c4d7b2438d3 | 40 | myled = !myled; |
switches | 0:5c4d7b2438d3 | 41 | } |
switches | 0:5c4d7b2438d3 | 42 | |
switches | 0:5c4d7b2438d3 | 43 | void queue_thread(void const *argument) { |
switches | 0:5c4d7b2438d3 | 44 | while (true) { |
switches | 0:5c4d7b2438d3 | 45 | queue.put((uint32_t*)QUEUE_PUT_THREAD_VALUE); |
switches | 0:5c4d7b2438d3 | 46 | Thread::wait(THREAD_DELAY); |
switches | 0:5c4d7b2438d3 | 47 | } |
switches | 0:5c4d7b2438d3 | 48 | } |
switches | 0:5c4d7b2438d3 | 49 | |
switches | 0:5c4d7b2438d3 | 50 | int main (void) { |
switches | 0:5c4d7b2438d3 | 51 | GREENTEA_SETUP(20, "default_auto"); |
switches | 0:5c4d7b2438d3 | 52 | |
switches | 0:5c4d7b2438d3 | 53 | Thread thread(queue_thread, NULL, osPriorityNormal, STACK_SIZE); |
switches | 0:5c4d7b2438d3 | 54 | Ticker ticker; |
switches | 0:5c4d7b2438d3 | 55 | ticker.attach(queue_isr, 1.0); |
switches | 0:5c4d7b2438d3 | 56 | int isr_puts_counter = 0; |
switches | 0:5c4d7b2438d3 | 57 | bool result = true; |
switches | 0:5c4d7b2438d3 | 58 | |
switches | 0:5c4d7b2438d3 | 59 | while (true) { |
switches | 0:5c4d7b2438d3 | 60 | osEvent evt = queue.get(); |
switches | 0:5c4d7b2438d3 | 61 | if (evt.status != osEventMessage) { |
switches | 0:5c4d7b2438d3 | 62 | printf("QUEUE_GET: Status(0x%02X) ... [FAIL]\r\n", evt.status); |
switches | 0:5c4d7b2438d3 | 63 | result = false; |
switches | 0:5c4d7b2438d3 | 64 | break; |
switches | 0:5c4d7b2438d3 | 65 | } else { |
switches | 0:5c4d7b2438d3 | 66 | printf("QUEUE_GET: Value(%u) ... [OK]\r\n", evt.value.v); |
switches | 0:5c4d7b2438d3 | 67 | if (evt.value.v == QUEUE_PUT_ISR_VALUE) { |
switches | 0:5c4d7b2438d3 | 68 | isr_puts_counter++; |
switches | 0:5c4d7b2438d3 | 69 | } |
switches | 0:5c4d7b2438d3 | 70 | if (isr_puts_counter >= QUEUE_SIZE) { |
switches | 0:5c4d7b2438d3 | 71 | break; |
switches | 0:5c4d7b2438d3 | 72 | } |
switches | 0:5c4d7b2438d3 | 73 | } |
switches | 0:5c4d7b2438d3 | 74 | } |
switches | 0:5c4d7b2438d3 | 75 | |
switches | 0:5c4d7b2438d3 | 76 | GREENTEA_TESTSUITE_RESULT(result); |
switches | 0:5c4d7b2438d3 | 77 | return 0; |
switches | 0:5c4d7b2438d3 | 78 | } |