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.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
mbed_shared_queues.cpp
00001 /* events 00002 * Copyright (c) 2017 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #include "events/mbed_shared_queues.h" 00018 00019 #ifdef MBED_CONF_RTOS_PRESENT 00020 #include "rtos/Thread.h" 00021 using rtos::Thread; 00022 #endif 00023 00024 using namespace events; 00025 00026 namespace mbed { 00027 00028 #ifdef MBED_CONF_RTOS_PRESENT 00029 /* Create an event queue, and start the thread that dispatches it. Static 00030 * variables mean this happens once the first time each template instantiation 00031 * is called. This is currently instantiated no more than twice. 00032 */ 00033 template 00034 <osPriority Priority, size_t QueueSize, size_t StackSize> 00035 EventQueue *do_shared_event_queue_with_thread(const char *name) 00036 { 00037 static uint64_t queue_buffer[QueueSize / sizeof(uint64_t)]; 00038 static EventQueue queue(sizeof queue_buffer, (unsigned char *) queue_buffer); 00039 00040 static uint64_t stack[StackSize / sizeof(uint64_t)]; 00041 static Thread thread(Priority, StackSize, (unsigned char *) stack, name); 00042 00043 Thread::State state = thread.get_state(); 00044 if (state == Thread::Inactive || state == Thread::Deleted) { 00045 osStatus status = thread.start(callback(&queue, &EventQueue::dispatch_forever)); 00046 MBED_ASSERT(status == osOK); 00047 if (status != osOK) { 00048 return NULL; 00049 } 00050 } 00051 00052 return &queue; 00053 } 00054 #endif 00055 00056 EventQueue *mbed_event_queue() 00057 { 00058 #if MBED_CONF_EVENTS_SHARED_DISPATCH_FROM_APPLICATION || !defined MBED_CONF_RTOS_PRESENT 00059 /* Only create the EventQueue, but no dispatching thread */ 00060 static unsigned char queue_buffer[MBED_CONF_EVENTS_SHARED_EVENTSIZE]; 00061 static EventQueue queue(sizeof queue_buffer, queue_buffer); 00062 00063 return &queue; 00064 #else 00065 return do_shared_event_queue_with_thread<osPriorityNormal, MBED_CONF_EVENTS_SHARED_EVENTSIZE, MBED_CONF_EVENTS_SHARED_STACKSIZE>("shared_event_queue"); 00066 #endif 00067 } 00068 00069 #ifdef MBED_CONF_RTOS_PRESENT 00070 EventQueue *mbed_highprio_event_queue() 00071 { 00072 return do_shared_event_queue_with_thread<osPriorityHigh, MBED_CONF_EVENTS_SHARED_HIGHPRIO_EVENTSIZE, MBED_CONF_EVENTS_SHARED_HIGHPRIO_STACKSIZE>("shared_highprio_event_queue"); 00073 } 00074 #endif 00075 00076 }
Generated on Tue Jul 12 2022 13:54:34 by
