ST / ST_Events-old

Dependents:   HelloWorld_CCA01M1 HelloWorld_CCA02M1 CI-data-logger-server HelloWorld_CCA02M1 ... more

This is a fork of the events subdirectory of https://github.com/ARMmbed/mbed-os.

Note, you must import this library with import name: events!!!

Committer:
Bartek Szatkowski
Date:
Mon May 15 09:55:45 2017 -0500
Revision:
9824:23b5875f4221
Parent:
18:dba7bd0f39f3
Child:
9828:b778d3912beb
Update codebase for CMSIS5/RTX5

Update all of mbed-os to use RTX5.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jimmy Brisson 5:705843a08e16 1
Jimmy Brisson 5:705843a08e16 2 /** \addtogroup events */
Jimmy Brisson 5:705843a08e16 3 /** @{*/
Bogdan Marinescu 0:a792d4bf36c2 4 /*
Bogdan Marinescu 0:a792d4bf36c2 5 * System specific implementation
Bogdan Marinescu 0:a792d4bf36c2 6 *
Bogdan Marinescu 0:a792d4bf36c2 7 * Copyright (c) 2016 Christopher Haster
Bogdan Marinescu 0:a792d4bf36c2 8 *
Bogdan Marinescu 0:a792d4bf36c2 9 * Licensed under the Apache License, Version 2.0 (the "License");
Bogdan Marinescu 0:a792d4bf36c2 10 * you may not use this file except in compliance with the License.
Bogdan Marinescu 0:a792d4bf36c2 11 * You may obtain a copy of the License at
Bogdan Marinescu 0:a792d4bf36c2 12 *
Bogdan Marinescu 0:a792d4bf36c2 13 * http://www.apache.org/licenses/LICENSE-2.0
Bogdan Marinescu 0:a792d4bf36c2 14 *
Bogdan Marinescu 0:a792d4bf36c2 15 * Unless required by applicable law or agreed to in writing, software
Bogdan Marinescu 0:a792d4bf36c2 16 * distributed under the License is distributed on an "AS IS" BASIS,
Bogdan Marinescu 0:a792d4bf36c2 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Bogdan Marinescu 0:a792d4bf36c2 18 * See the License for the specific language governing permissions and
Bogdan Marinescu 0:a792d4bf36c2 19 * limitations under the License.
Bogdan Marinescu 0:a792d4bf36c2 20 */
Bogdan Marinescu 0:a792d4bf36c2 21 #ifndef EQUEUE_PLATFORM_H
Bogdan Marinescu 0:a792d4bf36c2 22 #define EQUEUE_PLATFORM_H
Bogdan Marinescu 0:a792d4bf36c2 23
Bogdan Marinescu 0:a792d4bf36c2 24 #ifdef __cplusplus
Bogdan Marinescu 0:a792d4bf36c2 25 extern "C" {
Bogdan Marinescu 0:a792d4bf36c2 26 #endif
Bogdan Marinescu 0:a792d4bf36c2 27
Bogdan Marinescu 0:a792d4bf36c2 28 #include <stdbool.h>
Bogdan Marinescu 0:a792d4bf36c2 29
Bogdan Marinescu 0:a792d4bf36c2 30 // Currently supported platforms
Bogdan Marinescu 0:a792d4bf36c2 31 //
Bogdan Marinescu 0:a792d4bf36c2 32 // Uncomment to select a supported platform or reimplement this file
Bogdan Marinescu 0:a792d4bf36c2 33 // for a specific target.
Bogdan Marinescu 0:a792d4bf36c2 34 //#define EQUEUE_PLATFORM_POSIX
Bogdan Marinescu 0:a792d4bf36c2 35 //#define EQUEUE_PLATFORM_MBED
Bogdan Marinescu 0:a792d4bf36c2 36
Bogdan Marinescu 0:a792d4bf36c2 37 // Try to infer a platform if none was manually selected
Bogdan Marinescu 0:a792d4bf36c2 38 #if !defined(EQUEUE_PLATFORM_POSIX) \
Bogdan Marinescu 0:a792d4bf36c2 39 && !defined(EQUEUE_PLATFORM_MBED)
Bogdan Marinescu 0:a792d4bf36c2 40 #if defined(__unix__)
Bogdan Marinescu 0:a792d4bf36c2 41 #define EQUEUE_PLATFORM_POSIX
Bogdan Marinescu 0:a792d4bf36c2 42 #elif defined(__MBED__)
Bogdan Marinescu 0:a792d4bf36c2 43 #define EQUEUE_PLATFORM_MBED
Bogdan Marinescu 0:a792d4bf36c2 44 #else
Bogdan Marinescu 0:a792d4bf36c2 45 #warning "Unknown platform! Please update equeue_platform.h"
Bogdan Marinescu 0:a792d4bf36c2 46 #endif
Bogdan Marinescu 0:a792d4bf36c2 47 #endif
Bogdan Marinescu 0:a792d4bf36c2 48
Bogdan Marinescu 0:a792d4bf36c2 49 // Platform includes
Bogdan Marinescu 0:a792d4bf36c2 50 #if defined(EQUEUE_PLATFORM_POSIX)
Bogdan Marinescu 0:a792d4bf36c2 51 #include <pthread.h>
Bogdan Marinescu 0:a792d4bf36c2 52 #endif
Bogdan Marinescu 0:a792d4bf36c2 53
Bogdan Marinescu 0:a792d4bf36c2 54
Bogdan Marinescu 0:a792d4bf36c2 55 // Platform millisecond counter
Bogdan Marinescu 0:a792d4bf36c2 56 //
Bogdan Marinescu 0:a792d4bf36c2 57 // Return a tick that represents the number of milliseconds that have passed
Bogdan Marinescu 0:a792d4bf36c2 58 // since an arbitrary point in time. The granularity does not need to be at
Bogdan Marinescu 0:a792d4bf36c2 59 // the millisecond level, however the accuracy of the equeue library is
Bogdan Marinescu 0:a792d4bf36c2 60 // limited by the accuracy of this tick.
Bogdan Marinescu 0:a792d4bf36c2 61 //
Bogdan Marinescu 0:a792d4bf36c2 62 // Must intentionally overflow to 0 after 2^32-1
Bogdan Marinescu 0:a792d4bf36c2 63 unsigned equeue_tick(void);
Bogdan Marinescu 0:a792d4bf36c2 64
Bogdan Marinescu 0:a792d4bf36c2 65
Bogdan Marinescu 0:a792d4bf36c2 66 // Platform mutex type
Bogdan Marinescu 0:a792d4bf36c2 67 //
Bogdan Marinescu 0:a792d4bf36c2 68 // The equeue library requires at minimum a non-recursive mutex that is
Bogdan Marinescu 0:a792d4bf36c2 69 // safe in interrupt contexts. The mutex section is help for a bounded
Bogdan Marinescu 0:a792d4bf36c2 70 // amount of time, so simply disabling interrupts is acceptable
Bogdan Marinescu 0:a792d4bf36c2 71 //
Bogdan Marinescu 0:a792d4bf36c2 72 // If irq safety is not required, a regular blocking mutex can be used.
Bogdan Marinescu 0:a792d4bf36c2 73 #if defined(EQUEUE_PLATFORM_POSIX)
Bogdan Marinescu 0:a792d4bf36c2 74 typedef pthread_mutex_t equeue_mutex_t;
Bogdan Marinescu 0:a792d4bf36c2 75 #elif defined(EQUEUE_PLATFORM_WINDOWS)
Bogdan Marinescu 0:a792d4bf36c2 76 typedef CRITICAL_SECTION equeue_mutex_t;
Bogdan Marinescu 0:a792d4bf36c2 77 #elif defined(EQUEUE_PLATFORM_MBED)
Bogdan Marinescu 0:a792d4bf36c2 78 typedef unsigned equeue_mutex_t;
Bogdan Marinescu 0:a792d4bf36c2 79 #elif defined(EQUEUE_PLATFORM_FREERTOS)
Bogdan Marinescu 0:a792d4bf36c2 80 typedef UBaseType_t equeue_mutex_t;
Bogdan Marinescu 0:a792d4bf36c2 81 #endif
Bogdan Marinescu 0:a792d4bf36c2 82
Bogdan Marinescu 0:a792d4bf36c2 83 // Platform mutex operations
Bogdan Marinescu 0:a792d4bf36c2 84 //
Bogdan Marinescu 0:a792d4bf36c2 85 // The equeue_mutex_create and equeue_mutex_destroy manage the lifetime
Bogdan Marinescu 0:a792d4bf36c2 86 // of the mutex. On error, equeue_mutex_create should return a negative
Bogdan Marinescu 0:a792d4bf36c2 87 // error code.
Bogdan Marinescu 0:a792d4bf36c2 88 //
Bogdan Marinescu 0:a792d4bf36c2 89 // The equeue_mutex_lock and equeue_mutex_unlock lock and unlock the
Bogdan Marinescu 0:a792d4bf36c2 90 // underlying mutex.
Bogdan Marinescu 0:a792d4bf36c2 91 int equeue_mutex_create(equeue_mutex_t *mutex);
Bogdan Marinescu 0:a792d4bf36c2 92 void equeue_mutex_destroy(equeue_mutex_t *mutex);
Bogdan Marinescu 0:a792d4bf36c2 93 void equeue_mutex_lock(equeue_mutex_t *mutex);
Bogdan Marinescu 0:a792d4bf36c2 94 void equeue_mutex_unlock(equeue_mutex_t *mutex);
Bogdan Marinescu 0:a792d4bf36c2 95
Bogdan Marinescu 0:a792d4bf36c2 96
Bogdan Marinescu 0:a792d4bf36c2 97 // Platform semaphore type
Bogdan Marinescu 0:a792d4bf36c2 98 //
Bogdan Marinescu 0:a792d4bf36c2 99 // The equeue library requires a binary semaphore type that can be safely
Bogdan Marinescu 0:a792d4bf36c2 100 // signaled from interrupt contexts and from inside a equeue_mutex section.
Bogdan Marinescu 0:a792d4bf36c2 101 //
Bogdan Marinescu 0:a792d4bf36c2 102 // The equeue_signal_wait is relied upon by the equeue library to sleep the
Bogdan Marinescu 0:a792d4bf36c2 103 // processor between events. Spurious wakeups have no negative-effects.
Bogdan Marinescu 0:a792d4bf36c2 104 //
Bogdan Marinescu 0:a792d4bf36c2 105 // A counting semaphore will also work, however may cause the event queue
Bogdan Marinescu 0:a792d4bf36c2 106 // dispatch loop to run unnecessarily. For that matter, equeue_signal_wait
Bogdan Marinescu 0:a792d4bf36c2 107 // may even be implemented as a single return statement.
Bogdan Marinescu 0:a792d4bf36c2 108 #if defined(EQUEUE_PLATFORM_POSIX)
Bogdan Marinescu 0:a792d4bf36c2 109 typedef struct equeue_sema {
Bogdan Marinescu 0:a792d4bf36c2 110 pthread_mutex_t mutex;
Bogdan Marinescu 0:a792d4bf36c2 111 pthread_cond_t cond;
Bogdan Marinescu 0:a792d4bf36c2 112 bool signal;
Bogdan Marinescu 0:a792d4bf36c2 113 } equeue_sema_t;
Bogdan Marinescu 0:a792d4bf36c2 114 #elif defined(EQUEUE_PLATFORM_MBED) && defined(MBED_CONF_RTOS_PRESENT)
Bartek Szatkowski 9824:23b5875f4221 115 typedef unsigned equeue_sema_t[9];
Bogdan Marinescu 0:a792d4bf36c2 116 #elif defined(EQUEUE_PLATFORM_MBED)
Bogdan Marinescu 0:a792d4bf36c2 117 typedef volatile int equeue_sema_t;
Bogdan Marinescu 0:a792d4bf36c2 118 #endif
Bogdan Marinescu 0:a792d4bf36c2 119
Bogdan Marinescu 0:a792d4bf36c2 120 // Platform semaphore operations
Bogdan Marinescu 0:a792d4bf36c2 121 //
Bogdan Marinescu 0:a792d4bf36c2 122 // The equeue_sema_create and equeue_sema_destroy manage the lifetime
Bogdan Marinescu 0:a792d4bf36c2 123 // of the semaphore. On error, equeue_sema_create should return a negative
Bogdan Marinescu 0:a792d4bf36c2 124 // error code.
Bogdan Marinescu 0:a792d4bf36c2 125 //
Bogdan Marinescu 0:a792d4bf36c2 126 // The equeue_sema_signal marks a semaphore as signalled such that the next
Bogdan Marinescu 0:a792d4bf36c2 127 // equeue_sema_wait will return true.
Bogdan Marinescu 0:a792d4bf36c2 128 //
Bogdan Marinescu 0:a792d4bf36c2 129 // The equeue_sema_wait waits for a semaphore to be signalled or returns
Bogdan Marinescu 0:a792d4bf36c2 130 // immediately if equeue_sema_signal had been called since the last
Bogdan Marinescu 0:a792d4bf36c2 131 // equeue_sema_wait. The equeue_sema_wait returns true if it detected that
Christopher Haster 18:dba7bd0f39f3 132 // equeue_sema_signal had been called. If ms is negative, equeue_sema_wait
Christopher Haster 18:dba7bd0f39f3 133 // will wait for a signal indefinitely.
Bogdan Marinescu 0:a792d4bf36c2 134 int equeue_sema_create(equeue_sema_t *sema);
Bogdan Marinescu 0:a792d4bf36c2 135 void equeue_sema_destroy(equeue_sema_t *sema);
Bogdan Marinescu 0:a792d4bf36c2 136 void equeue_sema_signal(equeue_sema_t *sema);
Bogdan Marinescu 0:a792d4bf36c2 137 bool equeue_sema_wait(equeue_sema_t *sema, int ms);
Bogdan Marinescu 0:a792d4bf36c2 138
Bogdan Marinescu 0:a792d4bf36c2 139
Bogdan Marinescu 0:a792d4bf36c2 140 #ifdef __cplusplus
Bogdan Marinescu 0:a792d4bf36c2 141 }
Bogdan Marinescu 0:a792d4bf36c2 142 #endif
Bogdan Marinescu 0:a792d4bf36c2 143
Bogdan Marinescu 0:a792d4bf36c2 144 #endif
Jimmy Brisson 5:705843a08e16 145
Jimmy Brisson 5:705843a08e16 146 /** @}*/