mirror of
https://github.com/Ai-Thinker-Open/Ai-Thinker-Open_RTL8710BX_ALIOS_SDK.git
synced 2026-07-12 05:05:39 +00:00
rel_1.6.0 init
This commit is contained in:
commit
27b3e2883d
19359 changed files with 8093121 additions and 0 deletions
356
Living_SDK/device/sal/include/internal/sal_arch_internal.h
Normal file
356
Living_SDK/device/sal/include/internal/sal_arch_internal.h
Normal file
|
|
@ -0,0 +1,356 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef _SAL_ARCH_INTERNAL_H_
|
||||
#define _SAL_ARCH_INTERNAL_H_
|
||||
|
||||
#include <aos/aos.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup sys_time
|
||||
* Returns the current time in milliseconds,
|
||||
* may be the same as sys_jiffies or at least based on it.
|
||||
*/
|
||||
uint32_t sys_now(void);
|
||||
|
||||
//#define EVENT_SIMPLE
|
||||
#define SAL_ARCH_TIMEOUT 0xffffffffUL
|
||||
|
||||
/** sys_mbox_tryfetch() returns SAL_MBOX_EMPTY if appropriate.
|
||||
* For now we use the same magic value, but we allow this to change in future.
|
||||
*/
|
||||
#define SAL_MBOX_EMPTY SAL_ARCH_TIMEOUT
|
||||
|
||||
#define SAL_SEM_NULL NULL
|
||||
|
||||
#define SAL_LIGHTWEIGHT_PROT 1
|
||||
|
||||
#define SAL_DEFAULT_INPUTMBOX_SIZE 8
|
||||
#define SAL_DEFAULT_OUTPUTMBOX_SIZE 8
|
||||
|
||||
typedef aos_sem_t sal_sem_t;
|
||||
|
||||
#define sal_sem_valid(sem) aos_sem_is_valid(sem)
|
||||
#define sal_sem_set_invalid(sem) do { if(sem != NULL) { (sem)->hdl = NULL; }}while(0)
|
||||
|
||||
typedef uint32_t sal_prot_t;
|
||||
|
||||
typedef aos_mutex_t sal_mutex_t;
|
||||
#define sal_mutex_valid(mutex) aos_mutex_is_valid(mutex)
|
||||
#define sal_mutex_set_invalid(mutex) do { if(mutex != NULL) { (mutex)->hdl = NULL; }}while(0)
|
||||
|
||||
typedef aos_queue_t sal_mbox_t;
|
||||
#define sal_mbox_valid(mbox) aos_queue_is_valid(mbox)
|
||||
#define sal_mbox_set_invalid(mbox) do { if(mbox != NULL) { (mbox)->hdl = NULL; }}while(0)
|
||||
|
||||
typedef void *sal_thread_t;
|
||||
/**
|
||||
* @ingroup sal_mutex
|
||||
* Create a new mutex.
|
||||
* Note that mutexes are expected to not be taken recursively by the lwIP code,
|
||||
* so both implementation types (recursive or non-recursive) should work.
|
||||
* @param mutex pointer to the mutex to create
|
||||
* @return ERR_OK if successful, another err_t otherwise
|
||||
*/
|
||||
err_t sal_mutex_new(sal_mutex_t *mutex);
|
||||
/**
|
||||
* @ingroup sal_mutex
|
||||
* Lock a mutex
|
||||
* @param mutex the mutex to lock
|
||||
*/
|
||||
void sal_mutex_lock(sal_mutex_t *mutex);
|
||||
/**
|
||||
* @ingroup sal_mutex
|
||||
* Unlock a mutex
|
||||
* @param mutex the mutex to unlock
|
||||
*/
|
||||
void sal_mutex_unlock(sal_mutex_t *mutex);
|
||||
/**
|
||||
* @ingroup sal_mutex
|
||||
* Delete a semaphore
|
||||
* @param mutex the mutex to delete
|
||||
*/
|
||||
void sal_mutex_free(sal_mutex_t *mutex);
|
||||
#ifndef sal_mutex_valid
|
||||
/**
|
||||
* @ingroup sal_mutex
|
||||
* Check if a mutex is valid/allocated: return 1 for valid, 0 for invalid
|
||||
*/
|
||||
int sal_mutex_valid(sal_mutex_t *mutex);
|
||||
#endif
|
||||
#ifndef sal_mutex_set_invalid
|
||||
/**
|
||||
* @ingroup sal_mutex
|
||||
* Set a mutex invalid so that sal_mutex_valid returns 0
|
||||
*/
|
||||
void sal_mutex_set_invalid(sal_mutex_t *mutex);
|
||||
#endif
|
||||
/* Semaphore functions: */
|
||||
|
||||
/**
|
||||
* @ingroup sal_sem
|
||||
* Create a new semaphore
|
||||
* @param sem pointer to the semaphore to create
|
||||
* @param count initial count of the semaphore
|
||||
* @return ERR_OK if successful, another err_t otherwise
|
||||
*/
|
||||
err_t sal_sem_new(sal_sem_t *sem, uint8_t count);
|
||||
/**
|
||||
* @ingroup sal_sem
|
||||
* Signals a semaphore
|
||||
* @param sem the semaphore to signal
|
||||
*/
|
||||
void sal_sem_signal(sal_sem_t *sem);
|
||||
/**
|
||||
* @ingroup sal_sem
|
||||
* Wait for a semaphore for the specified timeout
|
||||
* @param sem the semaphore to wait for
|
||||
* @param timeout timeout in milliseconds to wait (0 = wait forever)
|
||||
* @return time (in milliseconds) waited for the semaphore
|
||||
* or SAL_ARCH_TIMEOUT on timeout
|
||||
*/
|
||||
uint32_t sal_arch_sem_wait(sal_sem_t *sem, uint32_t timeout);
|
||||
/**
|
||||
* @ingroup sal_sem
|
||||
* Delete a semaphore
|
||||
* @param sem semaphore to delete
|
||||
*/
|
||||
void sal_sem_free(sal_sem_t *sem);
|
||||
/** Wait for a semaphore - forever/no timeout */
|
||||
#define sal_sem_wait(sem) sal_arch_sem_wait(sem, 0)
|
||||
#ifndef sal_sem_valid
|
||||
/**
|
||||
* @ingroup sal_sem
|
||||
* Check if a semaphore is valid/allocated: return 1 for valid, 0 for invalid
|
||||
*/
|
||||
int sal_sem_valid(sal_sem_t *sem);
|
||||
#endif
|
||||
#ifndef sal_sem_set_invalid
|
||||
/**
|
||||
* @ingroup sal_sem
|
||||
* Set a semaphore invalid so that sal_sem_valid returns 0
|
||||
*/
|
||||
void sal_sem_set_invalid(sal_sem_t *sem);
|
||||
#endif
|
||||
#ifndef sal_sem_valid_val
|
||||
/**
|
||||
* Same as sal_sem_valid() but taking a value, not a pointer
|
||||
*/
|
||||
#define sal_sem_valid_val(sem) sal_sem_valid(&(sem))
|
||||
#endif
|
||||
#ifndef sal_sem_set_invalid_val
|
||||
/**
|
||||
* Same as sal_sem_set_invalid() but taking a value, not a pointer
|
||||
*/
|
||||
#define sal_sem_set_invalid_val(sem) sal_sem_set_invalid(&(sem))
|
||||
#endif
|
||||
|
||||
/* sal_mutex_arch_init() must be called before anything else. */
|
||||
void sal_mutex_arch_init(void);
|
||||
|
||||
void sal_mutex_arch_free(void);
|
||||
|
||||
/* Mailbox functions. */
|
||||
|
||||
/**
|
||||
* @ingroup sys_mbox
|
||||
* Create a new mbox of specified size
|
||||
* @param mbox pointer to the mbox to create
|
||||
* @param size (minimum) number of messages in this mbox
|
||||
* @return ERR_OK if successful, another err_t otherwise
|
||||
*/
|
||||
err_t sal_mbox_new(sal_mbox_t *mbox, int size);
|
||||
/**
|
||||
* @ingroup sys_mbox
|
||||
* Post a message to an mbox - may not fail
|
||||
* -> blocks if full, only used from tasks not from ISR
|
||||
* @param mbox mbox to posts the message
|
||||
* @param msg message to post (ATTENTION: can be NULL)
|
||||
*/
|
||||
void sal_mbox_post(sal_mbox_t *mbox, void *msg);
|
||||
/**
|
||||
* @ingroup sys_mbox
|
||||
* Try to post a message to an mbox - may fail if full or ISR
|
||||
* @param mbox mbox to posts the message
|
||||
* @param msg message to post (ATTENTION: can be NULL)
|
||||
*/
|
||||
err_t sal_mbox_trypost(sal_mbox_t *mbox, void *msg);
|
||||
/**
|
||||
* @ingroup sys_mbox
|
||||
* Wait for a new message to arrive in the mbox
|
||||
* @param mbox mbox to get a message from
|
||||
* @param msg pointer where the message is stored
|
||||
* @param timeout maximum time (in milliseconds) to wait for a message (0 = wait forever)
|
||||
* @return time (in milliseconds) waited for a message, may be 0 if not waited
|
||||
or SYS_ARCH_TIMEOUT on timeout
|
||||
* The returned time has to be accurate to prevent timer jitter!
|
||||
*/
|
||||
u32_t sal_arch_mbox_fetch(sal_mbox_t *mbox, void **msg, u32_t timeout);
|
||||
/* Allow port to override with a macro, e.g. special timeout for sys_arch_mbox_fetch() */
|
||||
#ifndef sal_arch_mbox_tryfetch
|
||||
/**
|
||||
* @ingroup sys_mbox
|
||||
* Wait for a new message to arrive in the mbox
|
||||
* @param mbox mbox to get a message from
|
||||
* @param msg pointer where the message is stored
|
||||
* @return 0 (milliseconds) if a message has been received
|
||||
* or SAL_MBOX_EMPTY if the mailbox is empty
|
||||
*/
|
||||
u32_t sal_arch_mbox_tryfetch(sal_mbox_t *mbox, void **msg);
|
||||
#endif
|
||||
/**
|
||||
* For now, we map straight to sys_arch implementation.
|
||||
*/
|
||||
#define sal_mbox_tryfetch(mbox, msg) sal_arch_mbox_tryfetch(mbox, msg)
|
||||
/**
|
||||
* @ingroup sys_mbox
|
||||
* Delete an mbox
|
||||
* @param mbox mbox to delete
|
||||
*/
|
||||
void sal_mbox_free(sal_mbox_t *mbox);
|
||||
|
||||
#define sal_mbox_fetch(mbox, msg) sal_arch_mbox_fetch(mbox, msg, 0)
|
||||
#ifndef sal_mbox_valid
|
||||
/**
|
||||
* @ingroup sys_mbox
|
||||
* Check if an mbox is valid/allocated: return 1 for valid, 0 for invalid
|
||||
*/
|
||||
int sal_mbox_valid(sal_mbox_t *mbox);
|
||||
#endif
|
||||
#ifndef sal_mbox_set_invalid
|
||||
/**
|
||||
* @ingroup sys_mbox
|
||||
* Set an mbox invalid so that sys_mbox_valid returns 0
|
||||
*/
|
||||
void sal_mbox_set_invalid(sal_mbox_t *mbox);
|
||||
#endif
|
||||
#ifndef sal_mbox_valid_val
|
||||
/**
|
||||
* Same as sys_mbox_valid() but taking a value, not a pointer
|
||||
*/
|
||||
#define sal_mbox_valid_val(mbox) sal_mbox_valid(&(mbox))
|
||||
#endif
|
||||
#ifndef sal_mbox_set_invalid_val
|
||||
/**
|
||||
* Same as sys_mbox_set_invalid() but taking a value, not a pointer
|
||||
*/
|
||||
#define sal_mbox_set_invalid_val(mbox) sal_mbox_set_invalid(&(mbox))
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @ingroup sal_time
|
||||
* Returns the current time in milliseconds,
|
||||
* may be the same as sal_jiffies or at least based on it.
|
||||
*/
|
||||
uint32_t sal_now(void);
|
||||
|
||||
/* Critical Region Protection */
|
||||
/* These functions must be implemented in the sal_arch.c file.
|
||||
In some implementations they can provide a more light-weight protection
|
||||
mechanism than using semaphores. Otherwise semaphores can be used for
|
||||
implementation */
|
||||
#ifndef SAL_ARCH_PROTECT
|
||||
/** SAL_LIGHTWEIGHT_PROT
|
||||
* define SAL_LIGHTWEIGHT_PROT in lwipopts.h if you want inter-task protection
|
||||
* for certain critical regions during buffer allocation, deallocation and memory
|
||||
* allocation and deallocation.
|
||||
*/
|
||||
#if SAL_LIGHTWEIGHT_PROT
|
||||
|
||||
/**
|
||||
* @ingroup sal_prot
|
||||
* SAL_ARCH_DECL_PROTECT
|
||||
* declare a protection variable. This macro will default to defining a variable of
|
||||
* type sal_prot_t. If a particular port needs a different implementation, then
|
||||
* this macro may be defined in sal_arch.h.
|
||||
*/
|
||||
#define SAL_ARCH_DECL_PROTECT(lev) sal_prot_t lev
|
||||
/**
|
||||
* @ingroup sal_prot
|
||||
* SAL_ARCH_PROTECT
|
||||
* Perform a "fast" protect. This could be implemented by
|
||||
* disabling interrupts for an embedded system or by using a semaphore or
|
||||
* mutex. The implementation should allow calling SAL_ARCH_PROTECT when
|
||||
* already protected. The old protection level is returned in the variable
|
||||
* "lev". This macro will default to calling the sal_arch_protect() function
|
||||
* which should be implemented in sal_arch.c. If a particular port needs a
|
||||
* different implementation, then this macro may be defined in sal_arch.h
|
||||
*/
|
||||
#define SAL_ARCH_PROTECT(lev) lev = sal_arch_protect()
|
||||
/**
|
||||
* @ingroup sal_prot
|
||||
* SAL_ARCH_UNPROTECT
|
||||
* Perform a "fast" set of the protection level to "lev". This could be
|
||||
* implemented by setting the interrupt level to "lev" within the MACRO or by
|
||||
* using a semaphore or mutex. This macro will default to calling the
|
||||
* sal_arch_unprotect() function which should be implemented in
|
||||
* sal_arch.c. If a particular port needs a different implementation, then
|
||||
* this macro may be defined in sal_arch.h
|
||||
*/
|
||||
#define SAL_ARCH_UNPROTECT(lev) sal_arch_unprotect(lev)
|
||||
sal_prot_t sal_arch_protect(void);
|
||||
void sal_arch_unprotect(sal_prot_t pval);
|
||||
|
||||
#else
|
||||
|
||||
#define SAL_ARCH_DECL_PROTECT(lev)
|
||||
#define SAL_ARCH_PROTECT(lev)
|
||||
#define SAL_ARCH_UNPROTECT(lev)
|
||||
|
||||
#endif /* SAL_LIGHTWEIGHT_PROT */
|
||||
|
||||
#endif /* SAL_ARCH_PROTECT */
|
||||
|
||||
/*
|
||||
* Macros to set/get and increase/decrease variables in a thread-safe way.
|
||||
* Use these for accessing variable that are used from more than one thread.
|
||||
*/
|
||||
|
||||
#ifndef SAL_ARCH_INC
|
||||
#define SAL_ARCH_INC(var, val) do { \
|
||||
SAL_ARCH_DECL_PROTECT(old_level); \
|
||||
SAL_ARCH_PROTECT(old_level); \
|
||||
var += val; \
|
||||
SAL_ARCH_UNPROTECT(old_level); \
|
||||
} while(0)
|
||||
#endif /* SAL_ARCH_INC */
|
||||
|
||||
#ifndef SAL_ARCH_DEC
|
||||
#define SAL_ARCH_DEC(var, val) do { \
|
||||
SAL_ARCH_DECL_PROTECT(old_level); \
|
||||
SAL_ARCH_PROTECT(old_level); \
|
||||
var -= val; \
|
||||
SAL_ARCH_UNPROTECT(old_level); \
|
||||
} while(0)
|
||||
#endif /* SAL_ARCH_DEC */
|
||||
|
||||
#ifndef SAL_ARCH_GET
|
||||
#define SAL_ARCH_GET(var, ret) do { \
|
||||
SAL_ARCH_DECL_PROTECT(old_level); \
|
||||
SAL_ARCH_PROTECT(old_level); \
|
||||
ret = var; \
|
||||
SAL_ARCH_UNPROTECT(old_level); \
|
||||
} while(0)
|
||||
#endif /* SAL_ARCH_GET */
|
||||
|
||||
#ifndef SAL_ARCH_SET
|
||||
#define SAL_ARCH_SET(var, val) do { \
|
||||
SAL_ARCH_DECL_PROTECT(old_level); \
|
||||
SAL_ARCH_PROTECT(old_level); \
|
||||
var = val; \
|
||||
SAL_ARCH_UNPROTECT(old_level); \
|
||||
} while(0)
|
||||
#endif /* SAL_ARCH_SET */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_SAL_ARCH_H_*/
|
||||
200
Living_SDK/device/sal/include/internal/sal_pcb.h
Normal file
200
Living_SDK/device/sal/include/internal/sal_pcb.h
Normal file
|
|
@ -0,0 +1,200 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef _SAL_PCB_H_
|
||||
#define _SAL_PCB_H_
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if SAL_NETIF_HWADDRHINT
|
||||
#define IP_PCB_ADDRHINT ;u8_t addr_hint
|
||||
#else
|
||||
#define IP_PCB_ADDRHINT
|
||||
#endif
|
||||
|
||||
/** Main packet buffer struct */
|
||||
struct pbuf {
|
||||
/** next pbuf in singly linked pbuf chain */
|
||||
struct pbuf *next;
|
||||
|
||||
/** pointer to the actual data in the buffer */
|
||||
void *payload;
|
||||
|
||||
/**
|
||||
* total length of this buffer and all next buffers in chain
|
||||
* belonging to the same packet.
|
||||
*
|
||||
* For non-queue packet chains this is the invariant:
|
||||
* p->tot_len == p->len + (p->next? p->next->tot_len: 0)
|
||||
*/
|
||||
u16_t tot_len;
|
||||
|
||||
/** length of this buffer */
|
||||
u16_t len;
|
||||
|
||||
/** pbuf_type as u8_t instead of enum to save space */
|
||||
u8_t /*pbuf_type*/ type;
|
||||
|
||||
/** misc flags */
|
||||
u8_t flags;
|
||||
|
||||
#if SAL_XR_EXT_MBUF_SUPPORT
|
||||
/** new flags for mbuf */
|
||||
u8_t mb_flags;
|
||||
|
||||
/** decrease its size to u8_t */
|
||||
u8_t ref;
|
||||
#else /* SAL_XR_EXT_MBUF_SUPPORT */
|
||||
/**
|
||||
* the reference count always equals the number of pointers
|
||||
* that refer to this pbuf. This can be pointers from an application,
|
||||
* the stack itself, or pbuf->next pointers from a chain.
|
||||
*/
|
||||
u16_t ref;
|
||||
#endif
|
||||
};
|
||||
/** This is the common part of all PCB types. It needs to be at the
|
||||
beginning of a PCB type definition. It is located here so that
|
||||
changes to this common part are made in one location instead of
|
||||
having to change all PCB structs. */
|
||||
#define IP_PCB \
|
||||
/* ip addresses in network byte order */ \
|
||||
ip_addr_t local_ip; \
|
||||
ip_addr_t remote_ip; \
|
||||
/* Socket options */ \
|
||||
u8_t so_options; \
|
||||
/* Type Of Service */ \
|
||||
u8_t tos; \
|
||||
/* Time To Live */ \
|
||||
u8_t ttl \
|
||||
/* link layer address resolution hint */ \
|
||||
IP_PCB_ADDRHINT
|
||||
|
||||
struct ip_pcb {
|
||||
/* Common members of all PCB types */
|
||||
IP_PCB;
|
||||
};
|
||||
|
||||
struct tcp_pcb;
|
||||
typedef void (*tcp_recv_fn)(void *arg, struct tcp_pcb *pcb, struct pbuf *p,
|
||||
const ip_addr_t *addr, u16_t port);
|
||||
/**
|
||||
* members common to struct tcp_pcb and struct tcp_listen_pcb
|
||||
*/
|
||||
#define TCP_PCB_COMMON(type) \
|
||||
type *next; /* for the linked list */ \
|
||||
void *callback_arg; \
|
||||
u8_t prio; \
|
||||
/* ports are in host byte order */ \
|
||||
u16_t local_port
|
||||
|
||||
/** the TCP protocol control block */
|
||||
struct tcp_pcb {
|
||||
/** common PCB members */
|
||||
IP_PCB;
|
||||
/** protocol specific PCB members */
|
||||
TCP_PCB_COMMON(struct tcp_pcb);
|
||||
|
||||
/* ports are in host byte order */
|
||||
u16_t remote_port;
|
||||
/** receive callback function */
|
||||
tcp_recv_fn recv;
|
||||
/* user-supplied argument for the recv callback */
|
||||
void *recv_arg;
|
||||
};
|
||||
|
||||
struct udp_pcb;
|
||||
|
||||
/** Function prototype for udp pcb receive callback functions
|
||||
* addr and port are in same byte order as in the pcb
|
||||
* The callback is responsible for freeing the pbuf
|
||||
* if it's not used any more.
|
||||
*
|
||||
* ATTENTION: Be aware that 'addr' might point into the pbuf 'p' so freeing this pbuf
|
||||
* can make 'addr' invalid, too.
|
||||
*
|
||||
* @param arg user supplied argument (udp_pcb.recv_arg)
|
||||
* @param pcb the udp_pcb which received data
|
||||
* @param p the packet buffer that was received
|
||||
* @param addr the remote IP address from which the packet was received
|
||||
* @param port the remote port from which the packet was received
|
||||
*/
|
||||
typedef void (*udp_recv_fn)(void *arg, struct udp_pcb *pcb, struct pbuf *p,
|
||||
const ip_addr_t *addr, u16_t port);
|
||||
|
||||
/** the UDP protocol control block */
|
||||
struct udp_pcb {
|
||||
/** Common members of all PCB types */
|
||||
IP_PCB;
|
||||
|
||||
/* Protocol specific PCB members */
|
||||
|
||||
struct udp_pcb *next;
|
||||
|
||||
u8_t flags;
|
||||
/** ports are in host byte order */
|
||||
u16_t local_port, remote_port;
|
||||
|
||||
#if SAL_MULTICAST_TX_OPTIONS
|
||||
/** outgoing network interface for multicast packets */
|
||||
ip_addr_t multicast_ip;
|
||||
/** TTL for outgoing multicast packets */
|
||||
u8_t mcast_ttl;
|
||||
#endif /* SAL_MULTICAST_TX_OPTIONS */
|
||||
|
||||
#if SAL_UDPLITE
|
||||
/** used for UDP_LITE only */
|
||||
u16_t chksum_len_rx, chksum_len_tx;
|
||||
#endif /* SAL_UDPLITE */
|
||||
|
||||
/** receive callback function */
|
||||
udp_recv_fn recv;
|
||||
/** user-supplied argument for the recv callback */
|
||||
void *recv_arg;
|
||||
};
|
||||
|
||||
struct raw_pcb;
|
||||
|
||||
/** Function prototype for raw pcb receive callback functions.
|
||||
* @param arg user supplied argument (raw_pcb.recv_arg)
|
||||
* @param pcb the raw_pcb which received data
|
||||
* @param p the packet buffer that was received
|
||||
* @param addr the remote IP address from which the packet was received
|
||||
* @return 1 if the packet was 'eaten' (aka. deleted),
|
||||
* 0 if the packet lives on
|
||||
* If returning 1, the callback is responsible for freeing the pbuf
|
||||
* if it's not used any more.
|
||||
*/
|
||||
typedef u8_t (*raw_recv_fn)(void *arg, struct raw_pcb *pcb, struct pbuf *p,
|
||||
const ip_addr_t *addr);
|
||||
|
||||
/** the RAW protocol control block */
|
||||
struct raw_pcb {
|
||||
/* Common members of all PCB types */
|
||||
IP_PCB;
|
||||
|
||||
struct raw_pcb *next;
|
||||
|
||||
u8_t protocol;
|
||||
|
||||
/** receive callback function */
|
||||
raw_recv_fn recv;
|
||||
/* user-supplied argument for the recv callback */
|
||||
void *recv_arg;
|
||||
#if SAL_IPV6
|
||||
/* fields for handling checksum computations as per RFC3542. */
|
||||
u16_t chksum_offset;
|
||||
u8_t chksum_reqd;
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __AOS_EVENTFD_H__ */
|
||||
|
||||
270
Living_SDK/device/sal/include/internal/sal_sockets_internal.h
Normal file
270
Living_SDK/device/sal/include/internal/sal_sockets_internal.h
Normal file
|
|
@ -0,0 +1,270 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef _SAL_SOCKETS_INTERNAL_H_
|
||||
#define _SAL_SOCKETS_INTERNAL_H_
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <stdlib.h>
|
||||
#include <aos/aos.h>
|
||||
#include "vfs_conf.h"
|
||||
#include "sal_arch.h"
|
||||
#include "sal_def.h"
|
||||
#include "sal_ipaddr.h"
|
||||
#include "sal_err.h"
|
||||
#include "sal_pcb.h"
|
||||
#include "sal_arch_internal.h"
|
||||
#include "sal.h"
|
||||
#include "sal_sockets.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define MEMP_NUM_NETCONN 5//(MAX_SOCKETS_TCP + MAX_LISTENING_SOCKETS_TCP + MAX_SOCKETS_UDP)
|
||||
|
||||
#define SAL_TAG "sal"
|
||||
|
||||
#ifdef SAL_USE_DEBUG
|
||||
#define SAL_DEBUG(format, ...) LOGD(SAL_TAG, format, ##__VA_ARGS__)
|
||||
#else
|
||||
#define SAL_DEBUG(format, ...)
|
||||
#endif
|
||||
|
||||
#define SAL_ERROR(format, ...) LOGE(SAL_TAG, format, ##__VA_ARGS__)
|
||||
#define SAL_ASSERT(msg, assertion) do { if (!(assertion)) { \
|
||||
LOGE(SAL_TAG, msg);} \
|
||||
} while (0)
|
||||
|
||||
/** IPv4 only: set the IP address given as an u32_t */
|
||||
#define ip4_addr_set_u32(dest_ipaddr, src_u32) ((dest_ipaddr)->addr = (src_u32))
|
||||
/** IPv4 only: get the IP address as an u32_t */
|
||||
#define ip4_addr_get_u32(src_ipaddr) ((src_ipaddr)->addr)
|
||||
|
||||
/* Helpers to process several netconn_types by the same code */
|
||||
#define NETCONNTYPE_GROUP(t) ((t)&0xF0)
|
||||
#define NETCONNTYPE_DATAGRAM(t) ((t)&0xE0)
|
||||
|
||||
#if SAL_NETCONN_SEM_PER_THREAD
|
||||
#define SELECT_SEM_T sal_sem_t*
|
||||
#define SELECT_SEM_PTR(sem) (sem)
|
||||
#else /* SAL_NETCONN_SEM_PER_THREAD */
|
||||
#define SELECT_SEM_T sal_sem_t
|
||||
#define SELECT_SEM_PTR(sem) (&(sem))
|
||||
#endif /* SAL_NETCONN_SEM_PER_THREAD */
|
||||
|
||||
/* Flags for struct netconn.flags (u8_t) */
|
||||
/** Should this netconn avoid blocking? */
|
||||
#define NETCONN_FLAG_NON_BLOCKING 0x02
|
||||
/** Was the last connect action a non-blocking one? */
|
||||
#define NETCONN_FLAG_IN_NONBLOCKING_CONNECT 0x04
|
||||
|
||||
/** Set the blocking status of netconn calls (@todo: write/send is missing) */
|
||||
#define netconn_set_nonblocking(conn, val) do { if(val) { \
|
||||
(conn)->flags |= NETCONN_FLAG_NON_BLOCKING; \
|
||||
} else { \
|
||||
(conn)->flags &= ~ NETCONN_FLAG_NON_BLOCKING; }} while(0)
|
||||
/** Get the blocking status of netconn calls (@todo: write/send is missing) */
|
||||
#define netconn_is_nonblocking(conn) (((conn)->flags & NETCONN_FLAG_NON_BLOCKING) != 0)
|
||||
|
||||
|
||||
// #if defined(AOS_CONFIG_VFS_DEV_NODES)
|
||||
// #define SAL_SOCKET_OFFSET AOS_CONFIG_VFS_DEV_NODES
|
||||
// #endif
|
||||
|
||||
#define NETDB_ELEM_SIZE (sizeof(struct addrinfo) + sizeof(struct sockaddr_storage) + DNS_MAX_NAME_LENGTH + 1)
|
||||
|
||||
typedef struct sal_netbuf{
|
||||
void *payload;
|
||||
u16_t len;
|
||||
ip_addr_t addr;
|
||||
u16_t port;
|
||||
}sal_netbuf_t;
|
||||
|
||||
typedef struct sal_outputbuf{
|
||||
void *payload;
|
||||
u16_t len;
|
||||
u16_t remote_port;
|
||||
char remote_ip[16];
|
||||
}sal_outputbuf_t;
|
||||
|
||||
/** Description for a task waiting in select */
|
||||
struct sal_select_cb {
|
||||
/** Pointer to the next waiting task */
|
||||
struct sal_select_cb *next;
|
||||
/** Pointer to the previous waiting task */
|
||||
struct sal_select_cb *prev;
|
||||
/** readset passed to select */
|
||||
fd_set *readset;
|
||||
/** writeset passed to select */
|
||||
fd_set *writeset;
|
||||
/** unimplemented: exceptset passed to select */
|
||||
fd_set *exceptset;
|
||||
/** don't signal the same semaphore twice: set to 1 when signalled */
|
||||
int sem_signalled;
|
||||
/** semaphore to wake up a task waiting for select */
|
||||
SELECT_SEM_T sem;
|
||||
};
|
||||
|
||||
/** Current state of the netconn. Non-TCP netconns are always
|
||||
* in state NETCONN_NONE! */
|
||||
enum netconn_state {
|
||||
NETCONN_NONE,
|
||||
NETCONN_WRITE,
|
||||
NETCONN_LISTEN,
|
||||
NETCONN_CONNECT,
|
||||
NETCONN_CLOSE
|
||||
};
|
||||
|
||||
/* Flags for struct netconn.flags (u8_t) */
|
||||
/** Should this netconn avoid blocking? */
|
||||
#define NETCONN_FLAG_NON_BLOCKING 0x02
|
||||
/** Was the last connect action a non-blocking one? */
|
||||
#define NETCONN_FLAG_IN_NONBLOCKING_CONNECT 0x04
|
||||
/** If a nonblocking write has been rejected before, poll_tcp needs to
|
||||
check if the netconn is writable again */
|
||||
#define NETCONN_FLAG_CHECK_WRITESPACE 0x10
|
||||
/** If this flag is set then only IPv6 communication is allowed on the
|
||||
netconn. As per RFC#3493 this features defaults to OFF allowing
|
||||
dual-stack usage by default. */
|
||||
#define NETCONN_FLAG_IPV6_V6ONLY 0x20
|
||||
|
||||
/** @ingroup netconn_common
|
||||
* Protocol family and type of the netconn
|
||||
*/
|
||||
enum netconn_type {
|
||||
NETCONN_INVALID = 0,
|
||||
/** TCP IPv4 */
|
||||
NETCONN_TCP = 0x10,
|
||||
#if SAL_IPV6
|
||||
/** TCP IPv6 */
|
||||
NETCONN_TCP_IPV6 = NETCONN_TCP | NETCONN_TYPE_IPV6 /* 0x18 */,
|
||||
#endif /* SAL_IPV6 */
|
||||
/** UDP IPv4 */
|
||||
NETCONN_UDP = 0x20,
|
||||
/** UDP IPv4 lite */
|
||||
NETCONN_UDPLITE = 0x21,
|
||||
/** UDP IPv4 no checksum */
|
||||
NETCONN_UDPNOCHKSUM = 0x22,
|
||||
|
||||
#if SAL_IPV6
|
||||
/** UDP IPv6 (dual-stack by default, unless you call @ref netconn_set_ipv6only) */
|
||||
NETCONN_UDP_IPV6 = NETCONN_UDP | NETCONN_TYPE_IPV6 /* 0x28 */,
|
||||
/** UDP IPv6 lite (dual-stack by default, unless you call @ref netconn_set_ipv6only) */
|
||||
NETCONN_UDPLITE_IPV6 = NETCONN_UDPLITE | NETCONN_TYPE_IPV6 /* 0x29 */,
|
||||
/** UDP IPv6 no checksum (dual-stack by default, unless you call @ref netconn_set_ipv6only) */
|
||||
NETCONN_UDPNOCHKSUM_IPV6 = NETCONN_UDPNOCHKSUM | NETCONN_TYPE_IPV6 /* 0x2a */,
|
||||
#endif /* SAL_IPV6 */
|
||||
|
||||
/** Raw connection IPv4 */
|
||||
NETCONN_RAW = 0x40
|
||||
#if SAL_IPV6
|
||||
/** Raw connection IPv6 (dual-stack by default, unless you call @ref netconn_set_ipv6only) */
|
||||
, NETCONN_RAW_IPV6 = NETCONN_RAW | NETCONN_TYPE_IPV6 /* 0x48 */
|
||||
#endif /* SAL_IPV6 */
|
||||
};
|
||||
|
||||
struct sal_netconn;
|
||||
/** A callback prototype to inform about events for a netconn */
|
||||
typedef void (* netconn_callback)(struct sal_netconn *conn, enum netconn_evt, u16_t len);
|
||||
|
||||
/** A netconn descriptor */
|
||||
typedef struct sal_netconn {
|
||||
int socket;
|
||||
/** type of the netconn (TCP, UDP or RAW) */
|
||||
enum netconn_type type;
|
||||
/** current state of the netconn */
|
||||
enum netconn_state state;
|
||||
|
||||
/** the SAL internal protocol control block */
|
||||
union {
|
||||
struct ip_pcb *ip;
|
||||
struct tcp_pcb *tcp;
|
||||
struct udp_pcb *udp;
|
||||
struct raw_pcb *raw;
|
||||
} pcb;
|
||||
/** the last error this netconn had */
|
||||
err_t last_err;
|
||||
|
||||
/** mbox where received packets are stored until they are fetched
|
||||
by the neconn application thread. */
|
||||
sal_mbox_t recvmbox;
|
||||
|
||||
sal_mbox_t sendmbox;
|
||||
|
||||
/** flags holding more netconn-internal state, see NETCONN_FLAG_* defines */
|
||||
u8_t flags;
|
||||
/** timeout to wait for sending data (which means enqueueing data for sending
|
||||
in internal buffers) in milliseconds */
|
||||
s32_t send_timeout;
|
||||
/** timeout in milliseconds to wait for new data to be received
|
||||
(or connections to arrive for listening netconns) */
|
||||
int recv_timeout;
|
||||
#if SAL_RCVBUF
|
||||
/** maximum amount of bytes queued in recvmbox
|
||||
not used for TCP: adjust TCP_WND instead! */
|
||||
int recv_bufsize;
|
||||
/** number of bytes currently in recvmbox to be received,
|
||||
tested against recv_bufsize to limit bytes on recvmbox
|
||||
for UDP and RAW, used for FIONREAD */
|
||||
int recv_avail;
|
||||
#endif /* SAL_RCVBUF */
|
||||
/** A callback function that is informed about events for this netconn */
|
||||
netconn_callback callback;
|
||||
} sal_netconn_t;
|
||||
|
||||
/** Set the blocking status of netconn calls (@todo: write/send is missing) */
|
||||
#define netconn_set_nonblocking(conn, val) do { if(val) { \
|
||||
(conn)->flags |= NETCONN_FLAG_NON_BLOCKING; \
|
||||
} else { \
|
||||
(conn)->flags &= ~ NETCONN_FLAG_NON_BLOCKING; }} while(0)
|
||||
/** Get the blocking status of netconn calls (@todo: write/send is missing) */
|
||||
#define netconn_is_nonblocking(conn) (((conn)->flags & NETCONN_FLAG_NON_BLOCKING) != 0)
|
||||
|
||||
#define SAL_SO_SNDRCVTIMEO_GET_MS(optval) ((((const struct timeval *)(optval))->tv_sec * 1000U) + (((const struct timeval *)(optval))->tv_usec / 1000U))
|
||||
|
||||
#define SAL_SOCKET_MAX_PAYLOAD_SIZE 1512
|
||||
#define SAL_SOCKET_IP4_ANY_ADDR "0.0.0.0"
|
||||
#define SAL_SOCKET_IP4_ADDR_LEN 16
|
||||
|
||||
void sal_deal_event(int s, enum netconn_evt evt);
|
||||
|
||||
#define API_EVENT_SIMPLE(s,e) sal_deal_event(s,e)
|
||||
|
||||
#define EAI_NONAME 200
|
||||
#define EAI_SERVICE 201
|
||||
#define EAI_FAIL 202
|
||||
#define EAI_MEMORY 203
|
||||
#define EAI_FAMILY 204
|
||||
|
||||
#define HOST_NOT_FOUND 210
|
||||
#define NO_DATA 211
|
||||
#define NO_RECOVERY 212
|
||||
#define TRY_AGAIN 213
|
||||
|
||||
/* input flags for struct addrinfo */
|
||||
#define AI_PASSIVE 0x01
|
||||
#define AI_CANONNAME 0x02
|
||||
#define AI_NUMERICHOST 0x04
|
||||
#define AI_NUMERICSERV 0x08
|
||||
#define AI_V4MAPPED 0x10
|
||||
#define AI_ALL 0x20
|
||||
#define AI_ADDRCONFIG 0x40
|
||||
|
||||
struct sockaddr_storage {
|
||||
u8_t s2_len;
|
||||
sa_family_t ss_family;
|
||||
char s2_data1[2];
|
||||
u32_t s2_data2[3];
|
||||
#if LWIP_IPV6
|
||||
u32_t s2_data3[3];
|
||||
#endif /* LWIP_IPV6 */
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __AOS_EVENTFD_H__ */
|
||||
Loading…
Add table
Add a link
Reference in a new issue