Rahul Dahiya / Mbed OS STM32F7 Ethernet
Committer:
rahul_dahiya
Date:
Wed Jan 15 15:57:15 2020 +0530
Revision:
0:fb8047b156bb
STM32F7 LWIP

Who changed what in which revision?

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