修复mico-sdk错误

This commit is contained in:
nhkefus
2025-03-11 15:54:45 +08:00
parent 3422912129
commit 2ccb892a1c
2152 changed files with 664341 additions and 702636 deletions

View File

@@ -1,95 +1,99 @@
/*
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __CC_H__
#define __CC_H__
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <inttypes.h>
#include "../../../mico/cpu.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef uint8_t u8_t;
typedef int8_t s8_t;
typedef uint16_t u16_t;
typedef int16_t s16_t;
typedef uint32_t u32_t;
typedef int32_t s32_t;
typedef ptrdiff_t mem_ptr_t;
typedef int sys_prot_t;
#define U16_F PRIu16
#define S16_F PRId16
#define X16_F PRIx16
#define U32_F PRIu32
#define S32_F PRId32
#define X32_F PRIx32
#define SZT_F "lu"
#if defined __GNUC__
#define LWIP_TIMEVAL_PRIVATE 0
#endif
#ifdef __GNUC__
#define PACK_STRUCT_BEGIN
#define PACK_STRUCT_STRUCT __attribute__ ((__packed__))
#define PACK_STRUCT_END
#define PACK_STRUCT_FIELD(x) x
#elif defined( __IAR_SYSTEMS_ICC__ )
#define PACK_STRUCT_BEGIN __packed
#define PACK_STRUCT_STRUCT
#define PACK_STRUCT_END
#define PACK_STRUCT_FIELD(x) x
#endif
/* Select how LwIP debug will print */
#define LWIP_PLATFORM_DIAG(x) {printf x;}
#ifdef MICO_LWIP_DEBUG
#define LWIP_PLATFORM_ASSERT(x) MICO_ASSERTION_FAIL_ACTION()
#else
#define LWIP_PLATFORM_ASSERT(x)
#endif /* ifdef MICO_LWIP_DEBUG */
#ifdef __cplusplus
} /*extern "C" */
#endif
#endif /* __CC_H__ */
/*
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __CC_H__
#define __CC_H__
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <inttypes.h>
#include "../../../mico/cpu.h"
#ifdef __cplusplus
extern "C" {
#endif
#define LWIP_NO_STDINT_H 1
typedef uint8_t u8_t;
typedef int8_t s8_t;
typedef uint16_t u16_t;
typedef int16_t s16_t;
typedef uint32_t u32_t;
typedef int32_t s32_t;
typedef ptrdiff_t mem_ptr_t;
typedef int sys_prot_t;
#define U16_F PRIu16
#define S16_F PRId16
#define X16_F PRIx16
#define U32_F PRIu32
#define S32_F PRId32
#define X32_F PRIx32
#define SZT_F "lu"
#if defined __GNUC__
#define LWIP_TIMEVAL_PRIVATE 0
#endif
#ifdef __GNUC__
#define PACK_STRUCT_BEGIN
#define PACK_STRUCT_STRUCT __attribute__ ((__packed__))
#define PACK_STRUCT_END
#define PACK_STRUCT_FIELD(x) x
#elif defined( __IAR_SYSTEMS_ICC__ )
#define PACK_STRUCT_BEGIN __packed
#define PACK_STRUCT_STRUCT
#define PACK_STRUCT_END
#define PACK_STRUCT_FIELD(x) x
#endif
/* Select how LwIP debug will print */
#define LWIP_PLATFORM_DIAG(x) {printf x;}
#define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS
#ifdef MICO_LWIP_DEBUG
#define LWIP_PLATFORM_ASSERT(x) MICO_ASSERTION_FAIL_ACTION()
#else
#define LWIP_PLATFORM_ASSERT(x)
#endif /* ifdef MICO_LWIP_DEBUG */
#ifdef __cplusplus
} /*extern "C" */
#endif
#endif /* __CC_H__ */

View File

@@ -1,267 +1,267 @@
/**
******************************************************************************
* @file mico_socket.c
* @author William Xu
* @version V1.0.0
* @date 05-Aug-2018
* @brief This file provide the MiCO Socket abstract layer convert functions.
******************************************************************************
*
* UNPUBLISHED PROPRIETARY SOURCE CODE
* Copyright (c) 2016 MXCHIP Inc.
*
* The contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of MXCHIP Corporation.
******************************************************************************
*/
#include <string.h>
#include <stdlib.h>
#include "common.h"
#include "lwip/sockets.h"
#include "lwip/netdb.h"
/******************************************************
* Macros
******************************************************/
#ifdef inet_addr
#undef inet_addr
#endif
#ifdef inet_ntoa
#undef inet_ntoa
#endif
/******************************************************
* Constants
******************************************************/
/******************************************************
* Enumerations
******************************************************/
/******************************************************
* Type Definitions
******************************************************/
/******************************************************
* Structures
******************************************************/
struct pollfd {
int fd; /**< fd related to */
short events; /**< which POLL... events to respond to */
short revents; /**< which POLL... events occurred */
};
#define POLLIN 0x0001
#define POLLPRI 0x0002
#define POLLOUT 0x0004
#define POLLERR 0x0008
#define POLLHUP 0x0010
#define POLLNVAL 0x0020
/******************************************************
* Function Declarations
******************************************************/
/******************************************************
* Variables Definitions
******************************************************/
/******************************************************
* Function Definitions
******************************************************/
int socket(int domain, int type, int protocol)
{
return lwip_socket( domain, type, protocol );
}
int setsockopt (int socket, int level, int optname, void *optval, socklen_t optlen)
{
return lwip_setsockopt( socket, level, optname, optval, optlen );
}
int getsockopt (int socket, int level, int optname, void *optval, socklen_t *optlen_ptr)
{
return lwip_getsockopt( socket, level, optname, optval, optlen_ptr );
}
int bind (int socket, struct sockaddr *addr, socklen_t length)
{
return lwip_bind ( socket, addr, length);
}
int connect (int socket, struct sockaddr *addr, socklen_t length)
{
return lwip_connect( socket, addr, length );
}
int listen (int socket, int n)
{
return lwip_listen( socket, n );
}
int accept (int socket, struct sockaddr *addr, socklen_t *length_ptr)
{
return lwip_accept( socket, addr, length_ptr );
}
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
{
nfds = 64;
if ((timeout->tv_sec == 0) && (timeout->tv_usec < 1000)) // timeout must bigger than 1ms.
timeout->tv_usec = 1000;
return lwip_select( nfds, readfds, writefds, exceptfds, timeout );
}
int poll(struct pollfd *fds, int nfds, int timeout)
{
int maxfd=0;
int i, n;
fd_set rfds, wfds, efds;
struct timeval t;
int ret = 0, got;
//printf("poll nfds=%d, timeout = %d\r\n", nfds, timeout);
FD_ZERO(&rfds);
FD_ZERO(&wfds);
FD_ZERO(&efds);
for(i=0; i<nfds; i++) {
if (fds[i].fd > maxfd)
maxfd = fds[i].fd;
if (fds[i].events & (POLLIN|POLLPRI))
FD_SET(fds[i].fd, &rfds);
if (fds[i].events & (POLLOUT))
FD_SET(fds[i].fd, &wfds);
if (fds[i].events & (POLLERR|POLLHUP|POLLNVAL))
FD_SET(fds[i].fd, &efds);
fds[i].revents = 0;
//printf("<%d> fd=%d, evetns = %x\r\n", i, fds[i].fd, fds[i].events);
}
if (timeout < 0) {
n = lwip_select(maxfd+1, &rfds, &wfds, &efds, NULL);
} else {
t.tv_sec = timeout / 1000;
t.tv_usec = (timeout % 1000) * 1000;
n = lwip_select(maxfd+1, &rfds, &wfds, &efds, &t);
}
if (n <= 0)
return n;
for(i=0; i<nfds; i++) {
got=0;
if (FD_ISSET(fds[i].fd, &rfds)) {
fds[i].revents = fds[i].events & (POLLIN|POLLPRI);
got = 1;
}
if (FD_ISSET(fds[i].fd, &wfds)) {
fds[i].revents = fds[i].events & POLLOUT;
got = 1;
}
if (FD_ISSET(fds[i].fd, &efds)) {
fds[i].revents = fds[i].events & (POLLERR|POLLHUP|POLLNVAL);
got = 1;
}
if (got == 1) {
//printf("fd=%d, revetns = %x\r\n", fds[i].fd, fds[i].revents);
ret++;
}
}
return ret;
}
int send (int socket, const void *buffer, size_t size, int flags)
{
return lwip_send( socket, buffer, size, flags );
}
int sendto (int socket, const void *buffer, size_t size, int flags, const struct sockaddr *addr, socklen_t length)
{
return lwip_sendto( socket, buffer, size, flags, addr, length);
}
int recv (int socket, void *buffer, size_t size, int flags)
{
return lwip_recv( socket, buffer, size, flags );
}
int recvfrom (int socket, void *buffer, size_t size, int flags, struct sockaddr *addr, socklen_t *length_ptr)
{
return lwip_recvfrom( socket, buffer, size, flags, addr, length_ptr );
}
ssize_t read (int filedes, void *buffer, size_t size)
{
return recv(filedes, buffer, size, 0);
}
ssize_t write (int filedes, const void *buffer, size_t size)
{
return send(filedes, buffer, size, 0);
}
int close (int filedes)
{
return lwip_close( filedes );
}
/*
int shutdown(int s, int how)
{
return lwip_shutdown(s, how);
}
*/
struct hostent * gethostbyname (const char *name)
{
return lwip_gethostbyname( name );
}
int getaddrinfo(const char *nodename,
const char *servname,
const struct addrinfo *hints,
struct addrinfo **res)
{
printf("%s, nodename %s, servname %s\r\n", __FUNCTION__, nodename, servname);
return lwip_getaddrinfo(nodename,servname,hints,res);
}
void freeaddrinfo(struct addrinfo *ai)
{
lwip_freeaddrinfo(ai);
}
int getpeername (int s, struct sockaddr *name, socklen_t *namelen)
{
return lwip_getpeername (s, name, namelen);
}
int getsockname (int s, struct sockaddr *name, socklen_t *namelen)
{
return lwip_getsockname (s, name, namelen);
}
uint32_t inet_addr (const char *name)
{
return ipaddr_addr( name );
}
char *inet_ntoa (struct in_addr addr)
{
#if LwIP_VERSION_MAJOR == 1 && LwIP_VERSION_MINOR < 5
return ipaddr_ntoa( (ip_addr_t*) &(addr) );
#elif LwIP_VERSION_MAJOR == 1 && LwIP_VERSION_MINOR >= 5
return ipaddr_ntoa( (ip_addr_t*) &(addr) );
#elif LwIP_VERSION_MAJOR == 2
return ipaddr_ntoa( (ip_addr_t*) &(addr) );
#else
#error LwIP version not supported
#endif
}
/**
******************************************************************************
* @file mico_socket.c
* @author William Xu
* @version V1.0.0
* @date 05-Aug-2018
* @brief This file provide the MiCO Socket abstract layer convert functions.
******************************************************************************
*
* UNPUBLISHED PROPRIETARY SOURCE CODE
* Copyright (c) 2016 MXCHIP Inc.
*
* The contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of MXCHIP Corporation.
******************************************************************************
*/
#include <string.h>
#include <stdlib.h>
#include "common.h"
#include "lwip/sockets.h"
#include "lwip/netdb.h"
/******************************************************
* Macros
******************************************************/
#ifdef inet_addr
#undef inet_addr
#endif
#ifdef inet_ntoa
#undef inet_ntoa
#endif
/******************************************************
* Constants
******************************************************/
/******************************************************
* Enumerations
******************************************************/
/******************************************************
* Type Definitions
******************************************************/
/******************************************************
* Structures
******************************************************/
struct pollfd {
int fd; /**< fd related to */
short events; /**< which POLL... events to respond to */
short revents; /**< which POLL... events occurred */
};
#define POLLIN 0x0001
#define POLLPRI 0x0002
#define POLLOUT 0x0004
#define POLLERR 0x0008
#define POLLHUP 0x0010
#define POLLNVAL 0x0020
/******************************************************
* Function Declarations
******************************************************/
/******************************************************
* Variables Definitions
******************************************************/
/******************************************************
* Function Definitions
******************************************************/
int socket(int domain, int type, int protocol)
{
return lwip_socket( domain, type, protocol );
}
int setsockopt (int socket, int level, int optname, void *optval, socklen_t optlen)
{
return lwip_setsockopt( socket, level, optname, optval, optlen );
}
int getsockopt (int socket, int level, int optname, void *optval, socklen_t *optlen_ptr)
{
return lwip_getsockopt( socket, level, optname, optval, optlen_ptr );
}
int bind (int socket, struct sockaddr *addr, socklen_t length)
{
return lwip_bind ( socket, addr, length);
}
int connect (int socket, struct sockaddr *addr, socklen_t length)
{
return lwip_connect( socket, addr, length );
}
int listen (int socket, int n)
{
return lwip_listen( socket, n );
}
int accept (int socket, struct sockaddr *addr, socklen_t *length_ptr)
{
return lwip_accept( socket, addr, length_ptr );
}
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
{
nfds = 64;
if ((timeout->tv_sec == 0) && (timeout->tv_usec < 1000)) // timeout must bigger than 1ms.
timeout->tv_usec = 1000;
return lwip_select( nfds, readfds, writefds, exceptfds, timeout );
}
int poll(struct pollfd *fds, int nfds, int timeout)
{
int maxfd=0;
int i, n;
fd_set rfds, wfds, efds;
struct timeval t;
int ret = 0, got;
//printf("poll nfds=%d, timeout = %d\r\n", nfds, timeout);
FD_ZERO(&rfds);
FD_ZERO(&wfds);
FD_ZERO(&efds);
for(i=0; i<nfds; i++) {
if (fds[i].fd > maxfd)
maxfd = fds[i].fd;
if (fds[i].events & (POLLIN|POLLPRI))
FD_SET(fds[i].fd, &rfds);
if (fds[i].events & (POLLOUT))
FD_SET(fds[i].fd, &wfds);
if (fds[i].events & (POLLERR|POLLHUP|POLLNVAL))
FD_SET(fds[i].fd, &efds);
fds[i].revents = 0;
//printf("<%d> fd=%d, evetns = %x\r\n", i, fds[i].fd, fds[i].events);
}
if (timeout < 0) {
n = lwip_select(maxfd+1, &rfds, &wfds, &efds, NULL);
} else {
t.tv_sec = timeout / 1000;
t.tv_usec = (timeout % 1000) * 1000;
n = lwip_select(maxfd+1, &rfds, &wfds, &efds, &t);
}
if (n <= 0)
return n;
for(i=0; i<nfds; i++) {
got=0;
if (FD_ISSET(fds[i].fd, &rfds)) {
fds[i].revents = fds[i].events & (POLLIN|POLLPRI);
got = 1;
}
if (FD_ISSET(fds[i].fd, &wfds)) {
fds[i].revents = fds[i].events & POLLOUT;
got = 1;
}
if (FD_ISSET(fds[i].fd, &efds)) {
fds[i].revents = fds[i].events & (POLLERR|POLLHUP|POLLNVAL);
got = 1;
}
if (got == 1) {
//printf("fd=%d, revetns = %x\r\n", fds[i].fd, fds[i].revents);
ret++;
}
}
return ret;
}
int send (int socket, const void *buffer, size_t size, int flags)
{
return lwip_send( socket, buffer, size, flags );
}
int sendto (int socket, const void *buffer, size_t size, int flags, const struct sockaddr *addr, socklen_t length)
{
return lwip_sendto( socket, buffer, size, flags, addr, length);
}
int recv (int socket, void *buffer, size_t size, int flags)
{
return lwip_recv( socket, buffer, size, flags );
}
int recvfrom (int socket, void *buffer, size_t size, int flags, struct sockaddr *addr, socklen_t *length_ptr)
{
return lwip_recvfrom( socket, buffer, size, flags, addr, length_ptr );
}
ssize_t read (int filedes, void *buffer, size_t size)
{
return recv(filedes, buffer, size, 0);
}
ssize_t write (int filedes, const void *buffer, size_t size)
{
return send(filedes, buffer, size, 0);
}
int close (int filedes)
{
return lwip_close( filedes );
}
/*
int shutdown(int s, int how)
{
return lwip_shutdown(s, how);
}
*/
struct hostent * gethostbyname (const char *name)
{
return lwip_gethostbyname( name );
}
int getaddrinfo(const char *nodename,
const char *servname,
const struct addrinfo *hints,
struct addrinfo **res)
{
printf("%s, nodename %s, servname %s\r\n", __FUNCTION__, nodename, servname);
return lwip_getaddrinfo(nodename,servname,hints,res);
}
void freeaddrinfo(struct addrinfo *ai)
{
lwip_freeaddrinfo(ai);
}
int getpeername (int s, struct sockaddr *name, socklen_t *namelen)
{
return lwip_getpeername (s, name, namelen);
}
int getsockname (int s, struct sockaddr *name, socklen_t *namelen)
{
return lwip_getsockname (s, name, namelen);
}
uint32_t inet_addr (const char *name)
{
return ipaddr_addr( name );
}
char *inet_ntoa (struct in_addr addr)
{
#if LwIP_VERSION_MAJOR == 1 && LwIP_VERSION_MINOR < 5
return ipaddr_ntoa( (ip_addr_t*) &(addr) );
#elif LwIP_VERSION_MAJOR == 1 && LwIP_VERSION_MINOR >= 5
return ipaddr_ntoa( (ip_addr_t*) &(addr) );
#elif LwIP_VERSION_MAJOR == 2
return ipaddr_ntoa( (ip_addr_t*) &(addr) );
#else
#error LwIP version not supported
#endif
}