1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/pkg/lwip/include/arch/sys_arch.h

142 lines
3.3 KiB
C
Raw Normal View History

2015-11-15 20:58:39 +01:00
/*
* Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
*
* 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.
*/
/**
2019-10-09 12:45:32 +02:00
* @defgroup pkg_lwip_sys Porting layer
2018-06-01 13:18:00 +02:00
* @ingroup pkg_lwip
2019-10-09 12:45:32 +02:00
* @brief System abstraction layer
2015-11-15 20:58:39 +01:00
* @{
*
* @file
2019-10-09 12:45:32 +02:00
* @brief OS abstraction layer
* @see https://www.nongnu.org/lwip/2_1_x/group__sys__os.html
2015-11-15 20:58:39 +01:00
*
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
*/
#ifndef ARCH_SYS_ARCH_H
#define ARCH_SYS_ARCH_H
2015-11-15 20:58:39 +01:00
#include <stdbool.h>
#include <stdint.h>
#include "cib.h"
2020-11-20 13:56:48 +01:00
#include "sched.h"
2016-09-02 14:56:19 +02:00
#include "mbox.h"
2015-11-15 20:58:39 +01:00
#include "mutex.h"
#include "random.h"
#include "sema.h"
#ifdef __cplusplus
extern "C" {
#endif
2019-10-09 12:45:32 +02:00
/**
* @brief System configuration
*/
/* prefer mutexes rather than binary semaphores */
2015-11-15 20:58:39 +01:00
#define LWIP_COMPAT_MUTEX (0)
2019-10-09 12:45:32 +02:00
/** @} */
2015-11-15 20:58:39 +01:00
2019-10-09 12:45:32 +02:00
/**
* @name Critical sections protection definitions
* @see https://www.nongnu.org/lwip/2_1_x/group__sys__prot.html
* @{
*/
#define SYS_ARCH_PROTECT(x) mutex_lock(&x)
#define SYS_ARCH_UNPROTECT(x) mutex_unlock(&x)
#define SYS_ARCH_DECL_PROTECT(x) mutex_t x = MUTEX_INIT
/** @} */
2015-11-15 20:58:39 +01:00
2019-10-09 12:45:32 +02:00
/**
* @name Semaphores definitions
* @see https://www.nongnu.org/lwip/2_1_x/group__sys__sem.html
*/
typedef sema_t sys_sem_t; /**< Platform specific semaphore type */
2015-11-15 20:58:39 +01:00
2019-10-09 12:45:32 +02:00
static inline bool sys_sem_valid(sys_sem_t *sem)
2015-11-15 20:58:39 +01:00
{
2019-10-09 12:45:32 +02:00
return sem != NULL;
2015-11-15 20:58:39 +01:00
}
2019-10-09 12:45:32 +02:00
#define sys_sem_valid(sem) (sys_sem_valid(sem))
#define sys_sem_set_invalid(sem)
/** @} */
/**
* @name Mutexes definitions
* @see https://www.nongnu.org/lwip/2_1_x/group__sys__mutex.html
*/
typedef mutex_t sys_mutex_t; /**< Platform specific mutex type */
static inline bool sys_mutex_valid(sys_mutex_t *mutex)
2015-11-15 20:58:39 +01:00
{
2019-10-09 12:45:32 +02:00
return mutex != NULL;
2015-11-15 20:58:39 +01:00
}
2019-10-09 12:45:32 +02:00
#define sys_mutex_valid(mutex) (sys_mutex_valid(mutex))
#define sys_mutex_set_invalid(mutex)
/** @} */
/**
* @name Mailboxes OS abstraction layer definitions
* @see https://www.nongnu.org/lwip/2_1_x/group__sys__mbox.html
* @{
*/
#define SYS_MBOX_SIZE (8)
/**
* @brief Platform specific mailbox type
*/
typedef struct {
mbox_t mbox; /**< RIOT mbox */
msg_t msgs[SYS_MBOX_SIZE]; /**< queue for the mbox */
} sys_mbox_t;
2015-11-15 20:58:39 +01:00
static inline bool sys_mbox_valid(sys_mbox_t *mbox)
{
2016-09-02 14:56:19 +02:00
return (mbox != NULL) && (mbox->mbox.cib.mask != 0);
2015-11-15 20:58:39 +01:00
}
static inline void sys_mbox_set_invalid(sys_mbox_t *mbox)
{
if (mbox != NULL) {
2016-09-02 14:56:19 +02:00
mbox->mbox.cib.mask = 0;
2015-11-15 20:58:39 +01:00
}
}
#define sys_mbox_valid(mbox) (sys_mbox_valid(mbox))
#define sys_mbox_set_invalid(mbox) (sys_mbox_set_invalid(mbox))
2019-10-09 12:45:32 +02:00
/** @} */
typedef kernel_pid_t sys_thread_t; /**< Platform specific thread type */
2015-11-15 20:58:39 +01:00
/**
* @name Functions for locking/unlocking core to assure thread safety.
* @{
*/
void sys_lock_tcpip_core(void);
#define LOCK_TCPIP_CORE() sys_lock_tcpip_core()
void sys_unlock_tcpip_core(void);
#define UNLOCK_TCPIP_CORE() sys_unlock_tcpip_core()
/** @} */
2015-11-15 20:58:39 +01:00
#ifdef MODULE_RANDOM
2019-10-09 12:45:32 +02:00
/**
* @brief Use `random_uint32()` to generate random numbers, if available
*/
2015-11-15 20:58:39 +01:00
#define LWIP_RAND() (random_uint32())
#endif
#ifdef __cplusplus
}
#endif
#endif /* ARCH_SYS_ARCH_H */
2015-11-15 20:58:39 +01:00
/** @} */