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 #include "rtos/Semaphore.h"
rahul_dahiya 0:fb8047b156bb 23 #include "platform/mbed_assert.h"
rahul_dahiya 0:fb8047b156bb 24
rahul_dahiya 0:fb8047b156bb 25 #include <string.h>
rahul_dahiya 0:fb8047b156bb 26
rahul_dahiya 0:fb8047b156bb 27 namespace rtos {
rahul_dahiya 0:fb8047b156bb 28
rahul_dahiya 0:fb8047b156bb 29 Semaphore::Semaphore(int32_t count) {
rahul_dahiya 0:fb8047b156bb 30 constructor(count, 0xffff);
rahul_dahiya 0:fb8047b156bb 31 }
rahul_dahiya 0:fb8047b156bb 32
rahul_dahiya 0:fb8047b156bb 33 Semaphore::Semaphore(int32_t count, uint16_t max_count) {
rahul_dahiya 0:fb8047b156bb 34 constructor(count, max_count);
rahul_dahiya 0:fb8047b156bb 35 }
rahul_dahiya 0:fb8047b156bb 36
rahul_dahiya 0:fb8047b156bb 37 void Semaphore::constructor(int32_t count, uint16_t max_count) {
rahul_dahiya 0:fb8047b156bb 38 memset(&_obj_mem, 0, sizeof(_obj_mem));
rahul_dahiya 0:fb8047b156bb 39 osSemaphoreAttr_t attr = { 0 };
rahul_dahiya 0:fb8047b156bb 40 attr.cb_mem = &_obj_mem;
rahul_dahiya 0:fb8047b156bb 41 attr.cb_size = sizeof(_obj_mem);
rahul_dahiya 0:fb8047b156bb 42 _id = osSemaphoreNew(max_count, count, &attr);
rahul_dahiya 0:fb8047b156bb 43 MBED_ASSERT(_id != NULL);
rahul_dahiya 0:fb8047b156bb 44 }
rahul_dahiya 0:fb8047b156bb 45
rahul_dahiya 0:fb8047b156bb 46 int32_t Semaphore::wait(uint32_t millisec) {
rahul_dahiya 0:fb8047b156bb 47 osStatus_t stat = osSemaphoreAcquire(_id, millisec);
rahul_dahiya 0:fb8047b156bb 48 switch (stat) {
rahul_dahiya 0:fb8047b156bb 49 case osOK:
rahul_dahiya 0:fb8047b156bb 50 return osSemaphoreGetCount(_id) + 1;
rahul_dahiya 0:fb8047b156bb 51 case osErrorTimeout:
rahul_dahiya 0:fb8047b156bb 52 case osErrorResource:
rahul_dahiya 0:fb8047b156bb 53 return 0;
rahul_dahiya 0:fb8047b156bb 54 case osErrorParameter:
rahul_dahiya 0:fb8047b156bb 55 default:
rahul_dahiya 0:fb8047b156bb 56 return -1;
rahul_dahiya 0:fb8047b156bb 57 }
rahul_dahiya 0:fb8047b156bb 58 }
rahul_dahiya 0:fb8047b156bb 59
rahul_dahiya 0:fb8047b156bb 60 osStatus Semaphore::release(void) {
rahul_dahiya 0:fb8047b156bb 61 return osSemaphoreRelease(_id);
rahul_dahiya 0:fb8047b156bb 62 }
rahul_dahiya 0:fb8047b156bb 63
rahul_dahiya 0:fb8047b156bb 64 Semaphore::~Semaphore() {
rahul_dahiya 0:fb8047b156bb 65 osSemaphoreDelete(_id);
rahul_dahiya 0:fb8047b156bb 66 }
rahul_dahiya 0:fb8047b156bb 67
rahul_dahiya 0:fb8047b156bb 68 }