mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
51 lines
1.0 KiB
C
51 lines
1.0 KiB
C
/*
|
|
* Copyright (C) 2020 Inria
|
|
*
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
* directory for more details.
|
|
*/
|
|
|
|
/**
|
|
* @ingroup pkg_mynewt_core
|
|
* @{
|
|
*
|
|
* @file
|
|
* @brief Decawave Porting Layer semaphore RIOT wrapper
|
|
*
|
|
* @author Francisco Molina <francois-xavier.molina@inria.fr>
|
|
* @}
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <errno.h>
|
|
|
|
#include "irq.h"
|
|
#include "os/os_sem.h"
|
|
|
|
os_error_t os_sem_init(struct os_sem *sem, uint16_t tokens)
|
|
{
|
|
sema_create(&sem->sema, tokens);
|
|
return OS_OK;
|
|
}
|
|
|
|
os_error_t os_sem_release(struct os_sem *sem)
|
|
{
|
|
int ret = sema_post(&sem->sema);
|
|
|
|
return (ret) ? OS_ERROR : OS_OK;
|
|
}
|
|
|
|
os_error_t os_sem_pend(struct os_sem *sem, os_time_t timeout)
|
|
{
|
|
int ret;
|
|
|
|
if (timeout == OS_TIMEOUT_NEVER) {
|
|
ret = sema_wait(&sem->sema);
|
|
}
|
|
else {
|
|
ret = sema_wait_timed_ztimer(&sem->sema, ZTIMER_MSEC, timeout);
|
|
}
|
|
return ret == 0 ? OS_OK : ret == -ETIMEDOUT ? OS_TIMEOUT: OS_ERROR;
|
|
}
|