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