Erste version der Software für der Prototyp

Committer:
borlanic
Date:
Fri Mar 30 14:07:05 2018 +0000
Revision:
4:75df35ef4fb6
Parent:
0:380207fcb5c1
commentar

Who changed what in which revision?

UserRevisionLine numberNew contents of line
borlanic 0:380207fcb5c1 1 /* mbed Microcontroller Library
borlanic 0:380207fcb5c1 2 * Copyright (c) 2006-2012 ARM Limited
borlanic 0:380207fcb5c1 3 *
borlanic 0:380207fcb5c1 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
borlanic 0:380207fcb5c1 5 * of this software and associated documentation files (the "Software"), to deal
borlanic 0:380207fcb5c1 6 * in the Software without restriction, including without limitation the rights
borlanic 0:380207fcb5c1 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
borlanic 0:380207fcb5c1 8 * copies of the Software, and to permit persons to whom the Software is
borlanic 0:380207fcb5c1 9 * furnished to do so, subject to the following conditions:
borlanic 0:380207fcb5c1 10 *
borlanic 0:380207fcb5c1 11 * The above copyright notice and this permission notice shall be included in
borlanic 0:380207fcb5c1 12 * all copies or substantial portions of the Software.
borlanic 0:380207fcb5c1 13 *
borlanic 0:380207fcb5c1 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
borlanic 0:380207fcb5c1 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
borlanic 0:380207fcb5c1 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
borlanic 0:380207fcb5c1 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
borlanic 0:380207fcb5c1 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
borlanic 0:380207fcb5c1 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
borlanic 0:380207fcb5c1 20 * SOFTWARE.
borlanic 0:380207fcb5c1 21 */
borlanic 0:380207fcb5c1 22 #ifndef SEMAPHORE_H
borlanic 0:380207fcb5c1 23 #define SEMAPHORE_H
borlanic 0:380207fcb5c1 24
borlanic 0:380207fcb5c1 25 #include <stdint.h>
borlanic 0:380207fcb5c1 26 #include "cmsis_os2.h"
borlanic 0:380207fcb5c1 27 #include "mbed_rtos1_types.h"
borlanic 0:380207fcb5c1 28 #include "mbed_rtos_storage.h"
borlanic 0:380207fcb5c1 29 #include "platform/NonCopyable.h"
borlanic 0:380207fcb5c1 30
borlanic 0:380207fcb5c1 31 namespace rtos {
borlanic 0:380207fcb5c1 32 /** \addtogroup rtos */
borlanic 0:380207fcb5c1 33 /** @{*/
borlanic 0:380207fcb5c1 34 /**
borlanic 0:380207fcb5c1 35 * \defgroup rtos_Semaphore Semaphore class
borlanic 0:380207fcb5c1 36 * @{
borlanic 0:380207fcb5c1 37 */
borlanic 0:380207fcb5c1 38
borlanic 0:380207fcb5c1 39 /** The Semaphore class is used to manage and protect access to a set of shared resources.
borlanic 0:380207fcb5c1 40 *
borlanic 0:380207fcb5c1 41 * @note
borlanic 0:380207fcb5c1 42 * Memory considerations: The semaphore control structures will be created on current thread's stack, both for the mbed OS
borlanic 0:380207fcb5c1 43 * and underlying RTOS objects (static or dynamic RTOS memory pools are not being used).
borlanic 0:380207fcb5c1 44 */
borlanic 0:380207fcb5c1 45 class Semaphore : private mbed::NonCopyable<Semaphore> {
borlanic 0:380207fcb5c1 46 public:
borlanic 0:380207fcb5c1 47 /** Create and Initialize a Semaphore object used for managing resources.
borlanic 0:380207fcb5c1 48 @param count number of available resources; maximum index value is (count-1). (default: 0).
borlanic 0:380207fcb5c1 49
borlanic 0:380207fcb5c1 50 @note You cannot call this function from ISR context.
borlanic 0:380207fcb5c1 51 */
borlanic 0:380207fcb5c1 52 Semaphore(int32_t count=0);
borlanic 0:380207fcb5c1 53
borlanic 0:380207fcb5c1 54 /** Create and Initialize a Semaphore object used for managing resources.
borlanic 0:380207fcb5c1 55 @param count number of available resources
borlanic 0:380207fcb5c1 56 @param max_count maximum number of available resources
borlanic 0:380207fcb5c1 57
borlanic 0:380207fcb5c1 58 @note You cannot call this function from ISR context.
borlanic 0:380207fcb5c1 59 */
borlanic 0:380207fcb5c1 60 Semaphore(int32_t count, uint16_t max_count);
borlanic 0:380207fcb5c1 61
borlanic 0:380207fcb5c1 62 /** Wait until a Semaphore resource becomes available.
borlanic 0:380207fcb5c1 63 @param millisec timeout value or 0 in case of no time-out. (default: osWaitForever).
borlanic 0:380207fcb5c1 64 @return number of available tokens, before taking one; or -1 in case of incorrect parameters
borlanic 0:380207fcb5c1 65
borlanic 0:380207fcb5c1 66 @note You may call this function from ISR context if the millisec parameter is set to 0.
borlanic 0:380207fcb5c1 67 */
borlanic 0:380207fcb5c1 68 int32_t wait(uint32_t millisec=osWaitForever);
borlanic 0:380207fcb5c1 69
borlanic 0:380207fcb5c1 70 /** Wait until a Semaphore resource becomes available.
borlanic 0:380207fcb5c1 71 @param millisec absolute timeout time, referenced to Kernel::get_ms_count()
borlanic 0:380207fcb5c1 72 @return number of available tokens, before taking one; or -1 in case of incorrect parameters
borlanic 0:380207fcb5c1 73 @note the underlying RTOS may have a limit to the maximum wait time
borlanic 0:380207fcb5c1 74 due to internal 32-bit computations, but this is guaranteed to work if the
borlanic 0:380207fcb5c1 75 wait is <= 0x7fffffff milliseconds (~24 days). If the limit is exceeded,
borlanic 0:380207fcb5c1 76 the acquire attempt will time out earlier than specified.
borlanic 0:380207fcb5c1 77
borlanic 0:380207fcb5c1 78 @note You cannot call this function from ISR context.
borlanic 0:380207fcb5c1 79 */
borlanic 0:380207fcb5c1 80 int32_t wait_until(uint64_t millisec);
borlanic 0:380207fcb5c1 81
borlanic 0:380207fcb5c1 82 /** Release a Semaphore resource that was obtain with Semaphore::wait.
borlanic 0:380207fcb5c1 83 @return status code that indicates the execution status of the function:
borlanic 0:380207fcb5c1 84 @a osOK the token has been correctly released.
borlanic 0:380207fcb5c1 85 @a osErrorResource the maximum token count has been reached.
borlanic 0:380207fcb5c1 86 @a osErrorParameter internal error.
borlanic 0:380207fcb5c1 87
borlanic 0:380207fcb5c1 88 @note You may call this function from ISR context.
borlanic 0:380207fcb5c1 89 */
borlanic 0:380207fcb5c1 90 osStatus release(void);
borlanic 0:380207fcb5c1 91
borlanic 0:380207fcb5c1 92 /** Semaphore destructor
borlanic 0:380207fcb5c1 93 *
borlanic 0:380207fcb5c1 94 * @note You cannot call this function from ISR context.
borlanic 0:380207fcb5c1 95 */
borlanic 0:380207fcb5c1 96 ~Semaphore();
borlanic 0:380207fcb5c1 97
borlanic 0:380207fcb5c1 98 private:
borlanic 0:380207fcb5c1 99 void constructor(int32_t count, uint16_t max_count);
borlanic 0:380207fcb5c1 100
borlanic 0:380207fcb5c1 101 osSemaphoreId_t _id;
borlanic 0:380207fcb5c1 102 mbed_rtos_storage_semaphore_t _obj_mem;
borlanic 0:380207fcb5c1 103 };
borlanic 0:380207fcb5c1 104 /** @}*/
borlanic 0:380207fcb5c1 105 /** @}*/
borlanic 0:380207fcb5c1 106 }
borlanic 0:380207fcb5c1 107 #endif
borlanic 0:380207fcb5c1 108
borlanic 0:380207fcb5c1 109