BBR 1 Ebene

Committer:
borlanic
Date:
Mon May 14 11:29:06 2018 +0000
Revision:
0:fbdae7e6d805
BBR

Who changed what in which revision?

UserRevisionLine numberNew contents of line
borlanic 0:fbdae7e6d805 1 /* events
borlanic 0:fbdae7e6d805 2 * Copyright (c) 2017 ARM Limited
borlanic 0:fbdae7e6d805 3 *
borlanic 0:fbdae7e6d805 4 * Licensed under the Apache License, Version 2.0 (the "License");
borlanic 0:fbdae7e6d805 5 * you may not use this file except in compliance with the License.
borlanic 0:fbdae7e6d805 6 * You may obtain a copy of the License at
borlanic 0:fbdae7e6d805 7 *
borlanic 0:fbdae7e6d805 8 * http://www.apache.org/licenses/LICENSE-2.0
borlanic 0:fbdae7e6d805 9 *
borlanic 0:fbdae7e6d805 10 * Unless required by applicable law or agreed to in writing, software
borlanic 0:fbdae7e6d805 11 * distributed under the License is distributed on an "AS IS" BASIS,
borlanic 0:fbdae7e6d805 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
borlanic 0:fbdae7e6d805 13 * See the License for the specific language governing permissions and
borlanic 0:fbdae7e6d805 14 * limitations under the License.
borlanic 0:fbdae7e6d805 15 */
borlanic 0:fbdae7e6d805 16
borlanic 0:fbdae7e6d805 17 #include "events/mbed_shared_queues.h"
borlanic 0:fbdae7e6d805 18 #include "mbed.h"
borlanic 0:fbdae7e6d805 19
borlanic 0:fbdae7e6d805 20 using namespace events;
borlanic 0:fbdae7e6d805 21
borlanic 0:fbdae7e6d805 22 namespace mbed {
borlanic 0:fbdae7e6d805 23
borlanic 0:fbdae7e6d805 24 #ifdef MBED_CONF_RTOS_PRESENT
borlanic 0:fbdae7e6d805 25 /* Create an event queue, and start the thread that dispatches it. Static
borlanic 0:fbdae7e6d805 26 * variables mean this happens once the first time each template instantiation
borlanic 0:fbdae7e6d805 27 * is called. This is currently instantiated no more than twice.
borlanic 0:fbdae7e6d805 28 */
borlanic 0:fbdae7e6d805 29 template
borlanic 0:fbdae7e6d805 30 <osPriority Priority, size_t QueueSize, size_t StackSize>
borlanic 0:fbdae7e6d805 31 EventQueue *do_shared_event_queue_with_thread()
borlanic 0:fbdae7e6d805 32 {
borlanic 0:fbdae7e6d805 33 static uint64_t queue_buffer[QueueSize / sizeof(uint64_t)];
borlanic 0:fbdae7e6d805 34 static EventQueue queue(sizeof queue_buffer, (unsigned char *) queue_buffer);
borlanic 0:fbdae7e6d805 35
borlanic 0:fbdae7e6d805 36 static uint64_t stack[StackSize / sizeof(uint64_t)];
borlanic 0:fbdae7e6d805 37 static Thread thread(Priority, StackSize, (unsigned char *) stack);
borlanic 0:fbdae7e6d805 38
borlanic 0:fbdae7e6d805 39 Thread::State state = thread.get_state();
borlanic 0:fbdae7e6d805 40 if (state == Thread::Inactive || state == Thread::Deleted) {
borlanic 0:fbdae7e6d805 41 osStatus status = thread.start(callback(&queue, &EventQueue::dispatch_forever));
borlanic 0:fbdae7e6d805 42 MBED_ASSERT(status == osOK);
borlanic 0:fbdae7e6d805 43 if (status != osOK) {
borlanic 0:fbdae7e6d805 44 return NULL;
borlanic 0:fbdae7e6d805 45 }
borlanic 0:fbdae7e6d805 46 }
borlanic 0:fbdae7e6d805 47
borlanic 0:fbdae7e6d805 48 return &queue;
borlanic 0:fbdae7e6d805 49 }
borlanic 0:fbdae7e6d805 50 #endif
borlanic 0:fbdae7e6d805 51
borlanic 0:fbdae7e6d805 52 EventQueue *mbed_event_queue()
borlanic 0:fbdae7e6d805 53 {
borlanic 0:fbdae7e6d805 54 #if MBED_CONF_EVENTS_SHARED_DISPATCH_FROM_APPLICATION || !defined MBED_CONF_RTOS_PRESENT
borlanic 0:fbdae7e6d805 55 /* Only create the EventQueue, but no dispatching thread */
borlanic 0:fbdae7e6d805 56 static unsigned char queue_buffer[MBED_CONF_EVENTS_SHARED_EVENTSIZE];
borlanic 0:fbdae7e6d805 57 static EventQueue queue(sizeof queue_buffer, queue_buffer);
borlanic 0:fbdae7e6d805 58
borlanic 0:fbdae7e6d805 59 return &queue;
borlanic 0:fbdae7e6d805 60 #else
borlanic 0:fbdae7e6d805 61 return do_shared_event_queue_with_thread<osPriorityNormal, MBED_CONF_EVENTS_SHARED_EVENTSIZE, MBED_CONF_EVENTS_SHARED_STACKSIZE>();
borlanic 0:fbdae7e6d805 62 #endif
borlanic 0:fbdae7e6d805 63 }
borlanic 0:fbdae7e6d805 64
borlanic 0:fbdae7e6d805 65 #ifdef MBED_CONF_RTOS_PRESENT
borlanic 0:fbdae7e6d805 66 EventQueue *mbed_highprio_event_queue()
borlanic 0:fbdae7e6d805 67 {
borlanic 0:fbdae7e6d805 68 return do_shared_event_queue_with_thread<osPriorityHigh, MBED_CONF_EVENTS_SHARED_HIGHPRIO_EVENTSIZE, MBED_CONF_EVENTS_SHARED_HIGHPRIO_STACKSIZE>();
borlanic 0:fbdae7e6d805 69 }
borlanic 0:fbdae7e6d805 70 #endif
borlanic 0:fbdae7e6d805 71
borlanic 0:fbdae7e6d805 72 }