Preliminary main mbed library for nexpaq development

Committer:
nexpaq
Date:
Fri Nov 04 20:54:50 2016 +0000
Revision:
1:d96dbedaebdb
Parent:
0:6c56fb4bc5f0
Removed extra directories for other platforms

Who changed what in which revision?

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