diff --git a/bsp/stm32f10x/drivers/gpio.c b/bsp/stm32f10x/drivers/gpio.c index 747b55b4dc..6e46835417 100644 --- a/bsp/stm32f10x/drivers/gpio.c +++ b/bsp/stm32f10x/drivers/gpio.c @@ -35,6 +35,7 @@ struct pin_index static const struct pin_index pins[] = { #if (STM32F10X_PIN_NUMBERS == 64) + __STM32_PIN_DEFAULT, __STM32_PIN_DEFAULT, __STM32_PIN(2, APB2, C, 13), __STM32_PIN(3, APB2, C, 14), diff --git a/bsp/stm32f20x/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F2xx/system_stm32f2xx.c b/bsp/stm32f20x/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F2xx/system_stm32f2xx.c index da0e189c88..63938af735 100644 --- a/bsp/stm32f20x/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F2xx/system_stm32f2xx.c +++ b/bsp/stm32f20x/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F2xx/system_stm32f2xx.c @@ -142,7 +142,7 @@ /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N */ -#define PLL_M 25 +#define PLL_M (HSE_VALUE / 1000000) #define PLL_N 240 /* SYSCLK = PLL_VCO / PLL_P */ diff --git a/bsp/stm32f40x/Libraries/CMSIS/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c b/bsp/stm32f40x/Libraries/CMSIS/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c index 98e8e04dbe..18fa12b803 100644 --- a/bsp/stm32f40x/Libraries/CMSIS/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c +++ b/bsp/stm32f40x/Libraries/CMSIS/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c @@ -146,7 +146,7 @@ /************************* PLL Parameters *************************************/ /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N */ -#define PLL_M 25 +#define PLL_M (HSE_VALUE / 1000000) #define PLL_N 336 /* SYSCLK = PLL_VCO / PLL_P */ diff --git a/components/dfs/filesystems/lwip/SConscript b/components/dfs/filesystems/lwip/SConscript new file mode 100644 index 0000000000..7bc160af84 --- /dev/null +++ b/components/dfs/filesystems/lwip/SConscript @@ -0,0 +1,11 @@ +# RT-Thread building script for component + +from building import * + +cwd = GetCurrentDir() +src = Glob('*.c') +CPPPATH = [cwd] + +group = DefineGroup('Filesystem', src, depend = ['RT_USING_DFS', 'RT_USING_DFS_LWIP'], CPPPATH = CPPPATH) + +Return('group') diff --git a/components/dfs/filesystems/lwip/arpa/inet.h b/components/dfs/filesystems/lwip/arpa/inet.h new file mode 100644 index 0000000000..395f3489ba --- /dev/null +++ b/components/dfs/filesystems/lwip/arpa/inet.h @@ -0,0 +1,30 @@ +/* + * File : inet.h + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2015, RT-Thread Development Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Change Logs: + * Date Author Notes + * 2015-02-17 Bernard First version + */ + +#ifndef INET_H__ +#define INET_H__ + +#include + +#endif diff --git a/components/dfs/filesystems/lwip/dfs_lwip.c b/components/dfs/filesystems/lwip/dfs_lwip.c new file mode 100644 index 0000000000..4c3bb300d6 --- /dev/null +++ b/components/dfs/filesystems/lwip/dfs_lwip.c @@ -0,0 +1,125 @@ +/* + * File : dfs_lwip.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2015, RT-Thread Development Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Change Logs: + * Date Author Notes + * 2015-02-17 Bernard First version + */ + +#include +#include +#include + +#include "dfs_lwip.h" + +int dfs_lwip_getsocket(int fd) +{ + struct dfs_fd *_dfs_fd; + + _dfs_fd = fd_get(fd); + if (_dfs_fd == RT_NULL) return -1; + + return 0; +} + +int dfs_lwip_ioctl(struct dfs_fd* file, int cmd, void* args) +{ + return -DFS_STATUS_EIO; +} + +int dfs_lwip_read(struct dfs_fd* file, void *buf, rt_size_t count) +{ + int sock; + + sock = (int)file->data; + count = lwip_read(sock, buf, count); + + return count; +} + +int dfs_lwip_write(struct dfs_fd *file, const void *buf, rt_size_t count) +{ + int sock; + + sock = (int)file->data; + count = lwip_write(sock, buf, count); + + return count; +} + +int dfs_lwip_close(struct dfs_fd* file) +{ + int sock; + int result; + + sock = (int)file->data; + result = lwip_close(sock); + + if (result == 0) return DFS_STATUS_OK; + + return -result; +} + +static const struct dfs_filesystem_operation _lwip_fs_ops = +{ + "lwip", + DFS_FS_FLAG_DEFAULT, + RT_NULL, /* mount */ + RT_NULL, /* unmont */ + RT_NULL, /* mkfs */ + RT_NULL, /* statfs */ + + RT_NULL, /* open */ + dfs_lwip_close, + dfs_lwip_ioctl, + dfs_lwip_read, + dfs_lwip_write, + RT_NULL, + RT_NULL, /* lseek */ + RT_NULL, /* getdents */ + RT_NULL, /* unlink */ + RT_NULL, /* stat */ + RT_NULL, /* rename */ +}; + +static struct dfs_filesystem _lwip_fs = +{ + 0, /* dev_id */ + RT_NULL, /* path */ + &_lwip_fs_ops, + RT_NULL /* data */ +}; + +struct dfs_filesystem* dfs_lwip_get_fs(void) +{ + return &_lwip_fs; +} + +/* +NOTE: Beause we don't need to mount lwIP file system, the filesystem_ops is not +registered to the system. + +int dfs_lwip_system_init(void) +{ + dfs_register(&_lwip_fs_ops); + + return 0; +} +INIT_FS_EXPORT(dfs_lwip_system_init); +*/ diff --git a/components/dfs/filesystems/lwip/dfs_lwip.h b/components/dfs/filesystems/lwip/dfs_lwip.h new file mode 100644 index 0000000000..c72c38a7d6 --- /dev/null +++ b/components/dfs/filesystems/lwip/dfs_lwip.h @@ -0,0 +1,41 @@ +/* + * File : dfs_lwip.h + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2015, RT-Thread Development Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Change Logs: + * Date Author Notes + * 2015-02-17 Bernard First version + */ + +#ifndef DFS_LWIP_H__ +#define DFS_LWIP_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +struct dfs_filesystem* dfs_lwip_get_fs(void); +int dfs_lwip_getsocket(int fd); + +int dfs_lwip_system_init(void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/components/dfs/filesystems/lwip/lwip_sockets.c b/components/dfs/filesystems/lwip/lwip_sockets.c new file mode 100644 index 0000000000..399bc7ed3c --- /dev/null +++ b/components/dfs/filesystems/lwip/lwip_sockets.c @@ -0,0 +1,164 @@ +/* + * File : lwip_sockets.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2015, RT-Thread Development Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Change Logs: + * Date Author Notes + * 2015-02-17 Bernard First version + */ + +#include +#include +#include +#include + +#include "dfs_lwip.h" + +int accept(int s, struct sockaddr *addr, socklen_t *addrlen) +{ + int sock = dfs_lwip_getsocket(s); + + return lwip_accept(sock, addr, addrlen); +} + +int bind(int s, const struct sockaddr *name, socklen_t namelen) +{ + int sock = dfs_lwip_getsocket(s); + + return lwip_bind(sock, name, namelen); +} + +int shutdown(int s, int how) +{ + int sock = dfs_lwip_getsocket(s); + + return lwip_shutdown(s, how); +} + +int getpeername (int s, struct sockaddr *name, socklen_t *namelen) +{ + int sock = dfs_lwip_getsocket(s); + + return lwip_getpeername(sock, name, namelen); +} + +int getsockname (int s, struct sockaddr *name, socklen_t *namelen) +{ + int sock = dfs_lwip_getsocket(s); + + return lwip_getsockname(sock, name, namelen); +} + +int getsockopt (int s, int level, int optname, void *optval, socklen_t *optlen) +{ + int sock = dfs_lwip_getsocket(s); + + return lwip_getsockopt(sock, level, optname, optval, optlen); +} + +int setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen) +{ + int sock = dfs_lwip_getsocket(s); + + return lwip_setsockopt(sock, level, optname, optval, optlen); +} + +int connect(int s, const struct sockaddr *name, socklen_t namelen) +{ + int sock = dfs_lwip_getsocket(s); + + return lwip_connect(sock, name, namelen); +} + +int listen(int s, int backlog) +{ + int sock = dfs_lwip_getsocket(s); + + return lwip_listen(sock, backlog); +} + +int recv(int s, void *mem, size_t len, int flags) +{ + int sock = dfs_lwip_getsocket(s); + + return lwip_recv(sock, mem, len, flags); +} + +int recvfrom(int s, void *mem, size_t len, int flags, + struct sockaddr *from, socklen_t *fromlen) +{ + int sock = dfs_lwip_getsocket(s); + + return lwip_recvfrom(sock, mem, len, flags, from, fromlen); +} + +int send(int s, const void *dataptr, size_t size, int flags) +{ + int sock = dfs_lwip_getsocket(s); + + return lwip_send(sock, dataptr, size, flags); +} + +int sendto(int s, const void *dataptr, size_t size, int flags, + const struct sockaddr *to, socklen_t tolen) +{ + int sock = dfs_lwip_getsocket(s); + + return lwip_sendto(sock, dataptr, size, flags, to, tolen); +} + +int socket(int domain, int type, int protocol) +{ + /* create a BSD socket */ + int fd; + int sock; + struct dfs_fd *d; + + /* allocate a fd */ + fd = fd_new(); + if (fd < 0) + { + rt_set_errno(-DFS_STATUS_ENOMEM); + + return -1; + } + d = fd_get(fd); + + /* create socket in lwip and then put it to the dfs_fd */ + sock = lwip_socket(domain, type, protocol); + if (sock > 0) + { + /* this is a socket fd */ + d->type = FT_SOCKET; + d->path = RT_NULL; + + d->fs = dfs_lwip_get_fs(); + + d->flags = DFS_O_RDWR; /* set flags as read and write */ + d->size = 0; + d->pos = 0; + + /* set socket to the data of dfs_fd */ + d->data = (void*) sock; + } + + /* release the ref-count of fd */ + fd_put(d); + + return fd; +} diff --git a/components/dfs/filesystems/lwip/netdb.c b/components/dfs/filesystems/lwip/netdb.c new file mode 100644 index 0000000000..6871474251 --- /dev/null +++ b/components/dfs/filesystems/lwip/netdb.c @@ -0,0 +1,50 @@ +/* + * File : netdb.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2015, RT-Thread Development Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Change Logs: + * Date Author Notes + * 2015-02-17 Bernard First version + */ + +#include "netdb.h" +#include + +struct hostent *gethostbyname(const char *name) +{ + return lwip_gethostbyname(name); +} + +int gethostbyname_r(const char *name, struct hostent *ret, char *buf, + size_t buflen, struct hostent **result, int *h_errnop) +{ + return lwip_gethostbyname_r(name, ret, buf, buflen, result, h_errnop); +} + +void freeaddrinfo(struct addrinfo *ai) +{ + lwip_freeaddrinfo(ai); +} + +int getaddrinfo(const char *nodename, + const char *servname, + const struct addrinfo *hints, + struct addrinfo **res) +{ + return lwip_getaddrinfo(nodename, servname, hints, res); +} diff --git a/components/dfs/filesystems/lwip/netdb.h b/components/dfs/filesystems/lwip/netdb.h new file mode 100644 index 0000000000..bf509c371a --- /dev/null +++ b/components/dfs/filesystems/lwip/netdb.h @@ -0,0 +1,48 @@ +/* + * File : netdb.h + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2015, RT-Thread Development Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Change Logs: + * Date Author Notes + * 2015-02-17 Bernard First version + */ + +#ifndef NETDB_H__ +#define NETDB_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +struct hostent *gethostbyname(const char *name); + +int gethostbyname_r(const char *name, struct hostent *ret, char *buf, + size_t buflen, struct hostent **result, int *h_errnop); +void freeaddrinfo(struct addrinfo *ai); +int getaddrinfo(const char *nodename, + const char *servname, + const struct addrinfo *hints, + struct addrinfo **res); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/components/dfs/filesystems/lwip/netinet/in.h b/components/dfs/filesystems/lwip/netinet/in.h new file mode 100644 index 0000000000..93469bc8e3 --- /dev/null +++ b/components/dfs/filesystems/lwip/netinet/in.h @@ -0,0 +1,30 @@ +/* + * File : in.h + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2015, RT-Thread Development Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Change Logs: + * Date Author Notes + * 2015-02-17 Bernard First version + */ + +#ifndef IN_H__ +#define IN_H__ + +#include + +#endif diff --git a/components/dfs/filesystems/lwip/sys/socket.h b/components/dfs/filesystems/lwip/sys/socket.h new file mode 100644 index 0000000000..23d4bf32c5 --- /dev/null +++ b/components/dfs/filesystems/lwip/sys/socket.h @@ -0,0 +1,53 @@ +/* + * File : netdb.h + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2015, RT-Thread Development Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Change Logs: + * Date Author Notes + * 2015-02-17 Bernard First version + */ + +#ifndef SOCKET_H__ +#define SOCKET_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +int accept(int s, struct sockaddr *addr, socklen_t *addrlen); +int bind(int s, const struct sockaddr *name, socklen_t namelen); +int shutdown(int s, int how); +int getpeername (int s, struct sockaddr *name, socklen_t *namelen); +int getsockname (int s, struct sockaddr *name, socklen_t *namelen); +int getsockopt (int s, int level, int optname, void *optval, socklen_t *optlen); +int setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen); +int connect(int s, const struct sockaddr *name, socklen_t namelen); +int listen(int s, int backlog); +int recv(int s, void *mem, size_t len, int flags); +int recvfrom(int s, void *mem, size_t len, int flags, + struct sockaddr *from, socklen_t *fromlen); +int send(int s, const void *dataptr, size_t size, int flags); +int sendto(int s, const void *dataptr, size_t size, int flags, + const struct sockaddr *to, socklen_t tolen); +int socket(int domain, int type, int protocol); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/components/net/lwip-1.4.1/src/lwipopts.h b/components/net/lwip-1.4.1/src/lwipopts.h index cb7def8ae6..84f068db7a 100644 --- a/components/net/lwip-1.4.1/src/lwipopts.h +++ b/components/net/lwip-1.4.1/src/lwipopts.h @@ -353,4 +353,8 @@ #define LWIP_RAND rand #endif +#ifdef RT_USING_DFS_LWIP +#define LWIP_COMPAT_SOCKETS 0 +#endif + #endif /* __LWIPOPTS_H__ */