From 224c3224c7d1bea2f52bb51aca505812a12b9255 Mon Sep 17 00:00:00 2001 From: chenchaoqun Date: Mon, 27 Jul 2020 14:11:35 +0800 Subject: [format] enumeration define two styles: define first or all. --- include/rtdef.h | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'include') diff --git a/include/rtdef.h b/include/rtdef.h index b391ff7685..747643bb82 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -372,20 +372,20 @@ typedef struct rt_object *rt_object_t; /**< Type for kernel obj */ enum rt_object_class_type { - RT_Object_Class_Null = 0, /**< The object is not used. */ - RT_Object_Class_Thread, /**< The object is a thread. */ - RT_Object_Class_Semaphore, /**< The object is a semaphore. */ - RT_Object_Class_Mutex, /**< The object is a mutex. */ - RT_Object_Class_Event, /**< The object is a event. */ - RT_Object_Class_MailBox, /**< The object is a mail box. */ - RT_Object_Class_MessageQueue, /**< The object is a message queue. */ - RT_Object_Class_MemHeap, /**< The object is a memory heap */ - RT_Object_Class_MemPool, /**< The object is a memory pool. */ - RT_Object_Class_Device, /**< The object is a device */ - RT_Object_Class_Timer, /**< The object is a timer. */ - RT_Object_Class_Module, /**< The object is a module. */ - RT_Object_Class_Unknown, /**< The object is unknown. */ - RT_Object_Class_Static = 0x80 /**< The object is a static object. */ + RT_Object_Class_Null = 0x00, /**< The object is not used. */ + RT_Object_Class_Thread = 0x01, /**< The object is a thread. */ + RT_Object_Class_Semaphore = 0x02, /**< The object is a semaphore. */ + RT_Object_Class_Mutex = 0x03, /**< The object is a mutex. */ + RT_Object_Class_Event = 0x04, /**< The object is a event. */ + RT_Object_Class_MailBox = 0x05, /**< The object is a mail box. */ + RT_Object_Class_MessageQueue = 0x06, /**< The object is a message queue. */ + RT_Object_Class_MemHeap = 0x07, /**< The object is a memory heap. */ + RT_Object_Class_MemPool = 0x08, /**< The object is a memory pool. */ + RT_Object_Class_Device = 0x09, /**< The object is a device. */ + RT_Object_Class_Timer = 0x0a, /**< The object is a timer. */ + RT_Object_Class_Module = 0x0b, /**< The object is a module. */ + RT_Object_Class_Unknown = 0x0c, /**< The object is unknown. */ + RT_Object_Class_Static = 0x80 /**< The object is a static object. */ }; /** -- cgit v1.3.1 From 5e92521e0d0e6f73cafe5fe8b5c2e7e0d852863e Mon Sep 17 00:00:00 2001 From: Meco <920369182@qq.com> Date: Mon, 10 Aug 2020 04:35:08 +0800 Subject: struct rt_device_ops 结构体增加宏定义 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/rtdef.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include') diff --git a/include/rtdef.h b/include/rtdef.h index 747643bb82..5543b80ab7 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -32,6 +32,7 @@ * 2019-01-27 Bernard change version number to v4.0.1 * 2019-05-17 Bernard change version number to v4.0.2 * 2019-12-20 Bernard change version number to v4.0.3 + * 2020-08-10 Meco Man add macro for struct rt_device_ops */ #ifndef __RT_DEF_H__ @@ -920,6 +921,8 @@ enum rt_device_class_type #define RT_DEVICE_CTRL_RTC_SET_ALARM 0x13 /**< set alarm */ typedef struct rt_device *rt_device_t; + +#ifdef RT_USING_DEVICE_OPS /** * operations set for device object */ @@ -933,6 +936,7 @@ struct rt_device_ops rt_size_t (*write) (rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size); rt_err_t (*control)(rt_device_t dev, int cmd, void *args); }; +#endif /** * WaitQueue structure -- cgit v1.3.1 From 74ab1551fd030e4950ae4f773cb19240c7a7a6d3 Mon Sep 17 00:00:00 2001 From: mysterywolf <920369182@qq.com> Date: Sat, 5 Sep 2020 16:14:21 +0800 Subject: add posix 2008 limit.h --- components/libc/getline/README.md | 2 +- components/libc/getline/posix_getline.c | 2 +- include/libc/libc_limits.h | 24 ++++++++++++++++++++++++ include/rtlibc.h | 1 + 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 include/libc/libc_limits.h (limited to 'include') diff --git a/components/libc/getline/README.md b/components/libc/getline/README.md index 8f52898c82..3ba5a96b3d 100644 --- a/components/libc/getline/README.md +++ b/components/libc/getline/README.md @@ -1,4 +1,4 @@ -# getline/getdelim for RT-Thread POSIX +# getline/getdelim for RT-Thread POSIX(IEEE Std 1003.1-2008) [![Build Status](https://travis-ci.org/ivanrad/getline.svg?branch=master)](https://travis-ci.org/ivanrad/getline) diff --git a/components/libc/getline/posix_getline.c b/components/libc/getline/posix_getline.c index d4a7d3fce6..9853d09439 100644 --- a/components/libc/getline/posix_getline.c +++ b/components/libc/getline/posix_getline.c @@ -12,7 +12,7 @@ #include #include #include -#include +#include ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream) { char *cur_pos, *new_lineptr; diff --git a/include/libc/libc_limits.h b/include/libc/libc_limits.h new file mode 100644 index 0000000000..c2129e5343 --- /dev/null +++ b/include/libc/libc_limits.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * File : libc_limits.h + * + * Change Logs: + * Date Author Notes + * 2020-09-05 Meco Manthe first version + */ + +#ifndef __LIBC_LIMITS_H__ +#define __LIBC_LIMITS_H__ + +#include + +#ifndef SSIZE_MAX +# define SSIZE_MAX LONG_MAX +#endif + +#endif diff --git a/include/rtlibc.h b/include/rtlibc.h index b3a548beb1..73d735250f 100644 --- a/include/rtlibc.h +++ b/include/rtlibc.h @@ -20,6 +20,7 @@ #include "libc/libc_dirent.h" #include "libc/libc_signal.h" #include "libc/libc_fdset.h" +#include "libc/libc_limits.h" #if defined(__CC_ARM) || defined(__CLANG_ARM) || defined(__IAR_SYSTEMS_ICC__) typedef signed long off_t; -- cgit v1.3.1 From 6fa049ee3dedb7fe1ca321ef5f367fdb4a498181 Mon Sep 17 00:00:00 2001 From: mysterywolf <920369182@qq.com> Date: Sat, 5 Sep 2020 16:21:00 +0800 Subject: add libc_stdio.h --- include/libc/libc_limits.h | 4 ++-- include/libc/libc_stdio.h | 20 ++++++++++++++++++++ include/rtlibc.h | 1 + 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 include/libc/libc_stdio.h (limited to 'include') diff --git a/include/libc/libc_limits.h b/include/libc/libc_limits.h index c2129e5343..c2aa429229 100644 --- a/include/libc/libc_limits.h +++ b/include/libc/libc_limits.h @@ -12,8 +12,8 @@ * 2020-09-05 Meco Manthe first version */ -#ifndef __LIBC_LIMITS_H__ -#define __LIBC_LIMITS_H__ +#ifndef LIBC_LIMITS_H__ +#define LIBC_LIMITS_H__ #include diff --git a/include/libc/libc_stdio.h b/include/libc/libc_stdio.h new file mode 100644 index 0000000000..19d5fd4cc5 --- /dev/null +++ b/include/libc/libc_stdio.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * File : libc_stdio.h + * + * Change Logs: + * Date Author Notes + * 2020-09-05 Meco Manthe first version + */ + +#ifndef LIBC_STDIO_H__ +#define LIBC_STDIO_H__ + +#include + +#endif diff --git a/include/rtlibc.h b/include/rtlibc.h index 73d735250f..fb8c782095 100644 --- a/include/rtlibc.h +++ b/include/rtlibc.h @@ -21,6 +21,7 @@ #include "libc/libc_signal.h" #include "libc/libc_fdset.h" #include "libc/libc_limits.h" +#include "libc/libc_stdio.h" #if defined(__CC_ARM) || defined(__CLANG_ARM) || defined(__IAR_SYSTEMS_ICC__) typedef signed long off_t; -- cgit v1.3.1 From d5d8b345f4d9caacfd4dabce0d8ce374f7e7b81e Mon Sep 17 00:00:00 2001 From: mysterywolf <920369182@qq.com> Date: Sat, 5 Sep 2020 16:59:53 +0800 Subject: 修改libc_signal.h 该文件中不能用rt_数据类型,否则会引起编译器递归编译 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/getline/posix_getline.h | 1 + include/libc/libc_signal.h | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/components/libc/getline/posix_getline.h b/components/libc/getline/posix_getline.h index 1b3e43da1e..3de84cdfe6 100644 --- a/components/libc/getline/posix_getline.h +++ b/components/libc/getline/posix_getline.h @@ -14,6 +14,7 @@ #define POSIX_GETLINE_H #include +#include ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream); ssize_t getline(char **lineptr, size_t *n, FILE *stream); diff --git a/include/libc/libc_signal.h b/include/libc/libc_signal.h index 898fe13f43..539685de3e 100644 --- a/include/libc/libc_signal.h +++ b/include/libc/libc_signal.h @@ -15,6 +15,7 @@ extern "C" { #endif +#include #ifdef HAVE_CCONFIG_H #include #endif @@ -46,8 +47,8 @@ struct sigevent #ifndef HAVE_SIGINFO struct siginfo { - rt_uint16_t si_signo; - rt_uint16_t si_code; + uint16_t si_signo; + uint16_t si_code; union sigval si_value; }; -- cgit v1.3.1 From cf00e7f0a1c5d76fd990f37e72f165391ff2d595 Mon Sep 17 00:00:00 2001 From: mysterywolf <920369182@qq.com> Date: Sat, 5 Sep 2020 18:10:30 +0800 Subject: 增加 RT_USING_POSIX MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/libc/libc_limits.h | 4 ++++ include/libc/libc_stdio.h | 4 ++++ 2 files changed, 8 insertions(+) (limited to 'include') diff --git a/include/libc/libc_limits.h b/include/libc/libc_limits.h index c2aa429229..32f7df1b1a 100644 --- a/include/libc/libc_limits.h +++ b/include/libc/libc_limits.h @@ -17,8 +17,12 @@ #include +#ifdef RT_USING_POSIX + #ifndef SSIZE_MAX # define SSIZE_MAX LONG_MAX #endif #endif + +#endif diff --git a/include/libc/libc_stdio.h b/include/libc/libc_stdio.h index 19d5fd4cc5..6201b85ea4 100644 --- a/include/libc/libc_stdio.h +++ b/include/libc/libc_stdio.h @@ -15,6 +15,10 @@ #ifndef LIBC_STDIO_H__ #define LIBC_STDIO_H__ +#ifdef RT_USING_POSIX + #include #endif + +#endif -- cgit v1.3.1 From 443978eb784e68c33b469e04f4105e87fdf2fa55 Mon Sep 17 00:00:00 2001 From: mysterywolf <920369182@qq.com> Date: Sat, 5 Sep 2020 19:47:34 +0800 Subject: 增加RT_USING_POSIX_GETLINE用于单独控制是否启用getline函数,并修改Kconfig增加对应选项 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/Kconfig | 8 ++++++-- components/libc/getline/SConscript | 2 +- include/libc/libc_stdio.h | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/components/libc/Kconfig b/components/libc/Kconfig index 26e156522b..65c8d44225 100644 --- a/components/libc/Kconfig +++ b/components/libc/Kconfig @@ -22,11 +22,15 @@ if RT_USING_LIBC && RT_USING_DFS if RT_USING_POSIX config RT_USING_POSIX_MMAP - bool "Enable mmap() api" + bool "Enable mmap() API" default n config RT_USING_POSIX_TERMIOS - bool "Enable termios feature" + bool "Enable termios APIs" + default n + + config RT_USING_POSIX_GETLINE + bool "Enable getline()/getdelim() APIs" default n config RT_USING_POSIX_AIO diff --git a/components/libc/getline/SConscript b/components/libc/getline/SConscript index 7bede9f31b..fa4c8618c1 100644 --- a/components/libc/getline/SConscript +++ b/components/libc/getline/SConscript @@ -7,7 +7,7 @@ src = Glob('*.c') + Glob('*.cpp') CPPPATH = [cwd] group = DefineGroup('libc', src, - depend = ['RT_USING_LIBC', 'RT_USING_POSIX'], + depend = ['RT_USING_LIBC', 'RT_USING_POSIX','RT_USING_POSIX_GETLINE'], CPPPATH = CPPPATH) Return('group') diff --git a/include/libc/libc_stdio.h b/include/libc/libc_stdio.h index 6201b85ea4..4a09f5c3d7 100644 --- a/include/libc/libc_stdio.h +++ b/include/libc/libc_stdio.h @@ -15,7 +15,7 @@ #ifndef LIBC_STDIO_H__ #define LIBC_STDIO_H__ -#ifdef RT_USING_POSIX +#ifdef RT_USING_POSIX_GETLINE #include -- cgit v1.3.1 From 0d7d1fbbf78d5b6f75b28781d3c8c326da6b713b Mon Sep 17 00:00:00 2001 From: mysterywolf <920369182@qq.com> Date: Sat, 5 Sep 2020 22:05:16 +0800 Subject: 修改include/libc头文件版权信息格式 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/libc/libc_fcntl.h | 4 ---- include/libc/libc_fdset.h | 4 ---- include/libc/libc_ioctl.h | 4 ---- include/libc/libc_limits.h | 4 ---- include/libc/libc_stdio.h | 4 ---- 5 files changed, 20 deletions(-) (limited to 'include') diff --git a/include/libc/libc_fcntl.h b/include/libc/libc_fcntl.h index 1b7c69b1f4..385ac7cd9f 100644 --- a/include/libc/libc_fcntl.h +++ b/include/libc/libc_fcntl.h @@ -2,10 +2,6 @@ * Copyright (c) 2006-2018, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 - */ - -/* - * File : libc_fcntl.h * * Change Logs: * Date Author Notes diff --git a/include/libc/libc_fdset.h b/include/libc/libc_fdset.h index ecd965cd22..b4d2e2189a 100644 --- a/include/libc/libc_fdset.h +++ b/include/libc/libc_fdset.h @@ -2,10 +2,6 @@ * Copyright (c) 2006-2018, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 - */ - -/* - * File : libc_errno.h * * Change Logs: * Date Author Notes diff --git a/include/libc/libc_ioctl.h b/include/libc/libc_ioctl.h index ef5a5257a8..42a21a2cea 100644 --- a/include/libc/libc_ioctl.h +++ b/include/libc/libc_ioctl.h @@ -2,10 +2,6 @@ * Copyright (c) 2006-2018, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 - */ - -/* - * File : libc_ioctl.h * * Change Logs: * Date Author Notes diff --git a/include/libc/libc_limits.h b/include/libc/libc_limits.h index 32f7df1b1a..2b49db97d9 100644 --- a/include/libc/libc_limits.h +++ b/include/libc/libc_limits.h @@ -2,10 +2,6 @@ * Copyright (c) 2006-2018, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 - */ - -/* - * File : libc_limits.h * * Change Logs: * Date Author Notes diff --git a/include/libc/libc_stdio.h b/include/libc/libc_stdio.h index 4a09f5c3d7..0550583630 100644 --- a/include/libc/libc_stdio.h +++ b/include/libc/libc_stdio.h @@ -2,10 +2,6 @@ * Copyright (c) 2006-2018, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 - */ - -/* - * File : libc_stdio.h * * Change Logs: * Date Author Notes -- cgit v1.3.1 From 0eadf69f81b2f77eed0cf7a35acdf50c03cc48a4 Mon Sep 17 00:00:00 2001 From: mysterywolf <920369182@qq.com> Date: Sun, 6 Sep 2020 12:31:42 +0800 Subject: 增加rtconfig.h头文件 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/libc/libc_limits.h | 1 + include/libc/libc_stdio.h | 2 ++ 2 files changed, 3 insertions(+) (limited to 'include') diff --git a/include/libc/libc_limits.h b/include/libc/libc_limits.h index 2b49db97d9..b8368160df 100644 --- a/include/libc/libc_limits.h +++ b/include/libc/libc_limits.h @@ -12,6 +12,7 @@ #define LIBC_LIMITS_H__ #include +#include #ifdef RT_USING_POSIX diff --git a/include/libc/libc_stdio.h b/include/libc/libc_stdio.h index 0550583630..85ba509852 100644 --- a/include/libc/libc_stdio.h +++ b/include/libc/libc_stdio.h @@ -11,6 +11,8 @@ #ifndef LIBC_STDIO_H__ #define LIBC_STDIO_H__ +#include + #ifdef RT_USING_POSIX_GETLINE #include -- cgit v1.3.1 From ff097f0467fb0041817846f2472343b7b9c098c4 Mon Sep 17 00:00:00 2001 From: mysterywolf <920369182@qq.com> Date: Tue, 8 Sep 2020 13:16:49 +0800 Subject: 增加 __GNUC__宏定义 和sconscript的平台识别以避免重复定义 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/common/SConscript | 3 ++- components/libc/compilers/minilibc/SConscript | 2 +- include/libc/libc_errno.h | 4 ++-- include/libc/libc_fcntl.h | 2 +- include/libc/libc_fdset.h | 2 +- include/libc/libc_stat.h | 2 +- 6 files changed, 8 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/components/libc/compilers/common/SConscript b/components/libc/compilers/common/SConscript index 718f05743c..a5f4a3fda6 100644 --- a/components/libc/compilers/common/SConscript +++ b/components/libc/compilers/common/SConscript @@ -16,6 +16,7 @@ else: if GetDepend('RT_USING_POSIX') == False: SrcRemove(src, ['unistd.c']) -group = DefineGroup('libc', src, depend = [''], CPPPATH = CPPPATH) +if not GetDepend('RT_USING_MINILIBC') and GetDepend('RT_USING_LIBC'): + group = DefineGroup('libc', src, depend = [''], CPPPATH = CPPPATH) Return('group') diff --git a/components/libc/compilers/minilibc/SConscript b/components/libc/compilers/minilibc/SConscript index 518d800571..dec657028f 100644 --- a/components/libc/compilers/minilibc/SConscript +++ b/components/libc/compilers/minilibc/SConscript @@ -8,7 +8,7 @@ group = [] CPPPATH = [cwd] CPPDEFINES = ['RT_USING_MINILIBC'] -if rtconfig.PLATFORM == 'gcc' and rtconfig.ARCH != 'sim' and not GetDepend('RT_USING_LIBC'): +if rtconfig.PLATFORM == 'gcc' and rtconfig.ARCH != 'sim' and not GetDepend('RT_USING_LIBC') and GetDepend('RT_USING_MINILIBC'): group = DefineGroup('libc', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES) diff --git a/include/libc/libc_errno.h b/include/libc/libc_errno.h index 0f3bc7635a..00c1f733d3 100644 --- a/include/libc/libc_errno.h +++ b/include/libc/libc_errno.h @@ -13,7 +13,7 @@ #include -#if defined(RT_USING_NEWLIB) || defined(_WIN32) +#if defined(RT_USING_NEWLIB) || defined(_WIN32) || defined( __GNUC__ ) /* use errno.h file in toolchains */ #include #endif @@ -45,7 +45,7 @@ defined in armcc/errno.h #define ERROR_BASE_NO 0 #endif -#if !defined(RT_USING_NEWLIB) && !defined(_WIN32) +#if !defined(RT_USING_NEWLIB) && !defined(_WIN32) && !defined(__GNUC__ ) #define EPERM (ERROR_BASE_NO + 1) #define ENOENT (ERROR_BASE_NO + 2) diff --git a/include/libc/libc_fcntl.h b/include/libc/libc_fcntl.h index 385ac7cd9f..39740b7d85 100644 --- a/include/libc/libc_fcntl.h +++ b/include/libc/libc_fcntl.h @@ -12,7 +12,7 @@ #ifndef LIBC_FCNTL_H__ #define LIBC_FCNTL_H__ -#if defined(RT_USING_NEWLIB) || defined(_WIN32) +#if defined(RT_USING_NEWLIB) || defined(_WIN32) || defined( __GNUC__ ) #include #ifndef O_NONBLOCK diff --git a/include/libc/libc_fdset.h b/include/libc/libc_fdset.h index b4d2e2189a..4a778b51c1 100644 --- a/include/libc/libc_fdset.h +++ b/include/libc/libc_fdset.h @@ -13,7 +13,7 @@ #include -#if defined(RT_USING_NEWLIB) || defined(_WIN32) +#if defined(RT_USING_NEWLIB) || defined(_WIN32) || defined( __GNUC__ ) #include #if defined(HAVE_SYS_SELECT_H) #include diff --git a/include/libc/libc_stat.h b/include/libc/libc_stat.h index 9079d1ef15..9388688572 100644 --- a/include/libc/libc_stat.h +++ b/include/libc/libc_stat.h @@ -9,7 +9,7 @@ #include -#if defined(RT_USING_NEWLIB) +#if defined(RT_USING_NEWLIB) || defined( __GNUC__ ) /* use header file of newlib */ #include -- cgit v1.3.1 From c7aa6f0619318a3730fc4f4689d2cd2e72efed52 Mon Sep 17 00:00:00 2001 From: mysterywolf <920369182@qq.com> Date: Fri, 2 Oct 2020 12:00:52 +0800 Subject: [fix bug] #3902 --- components/libc/compilers/common/readme.md | 11 ++++++++++- components/net/lwip-1.4.1/src/arch/include/arch/cc.h | 11 ++++++++--- components/net/lwip-2.0.2/src/arch/include/arch/cc.h | 11 ++++++++--- components/net/lwip-2.1.2/src/arch/include/arch/cc.h | 11 ++++++++--- include/libc/libc_errno.h | 4 ++-- include/libc/libc_fcntl.h | 2 +- include/libc/libc_fdset.h | 2 +- include/libc/libc_stat.h | 2 +- 8 files changed, 39 insertions(+), 15 deletions(-) (limited to 'include') diff --git a/components/libc/compilers/common/readme.md b/components/libc/compilers/common/readme.md index cb91d95f45..0cd56272ff 100644 --- a/components/libc/compilers/common/readme.md +++ b/components/libc/compilers/common/readme.md @@ -1 +1,10 @@ -This folder is "common" for armlibc newlibc and dlib. It's not "common" for minilibc. \ No newline at end of file +# Attention : + +1. This folder is "common" for armlibc newlibc and dlib. It's not "common" for minilibc. + +2. If you want to add new .c files, please do not forget to fix SConscript file too. eg: + +```python +if GetDepend('RT_USING_POSIX') == False: + SrcRemove(src, ['unistd.c']) +``` \ No newline at end of file diff --git a/components/net/lwip-1.4.1/src/arch/include/arch/cc.h b/components/net/lwip-1.4.1/src/arch/include/arch/cc.h index 604477dab8..80e9007459 100644 --- a/components/net/lwip-1.4.1/src/arch/include/arch/cc.h +++ b/components/net/lwip-1.4.1/src/arch/include/arch/cc.h @@ -66,7 +66,7 @@ typedef uintptr_t mem_ptr_t; #endif /* __CC_ARM/__IAR_SYSTEMS_ICC__ */ #endif -#if defined(RT_USING_LIBC) || defined(RT_USING_MINILIBC) || defined(RT_LIBC_USING_TIME) || defined ( __GNUC__) +#if defined(RT_USING_LIBC) || defined(RT_USING_MINILIBC) || defined(RT_LIBC_USING_TIME) || (defined( __GNUC__ ) && !defined(__ARMCC_VERSION)) #include #define LWIP_TIMEVAL_PRIVATE 0 #else @@ -78,10 +78,15 @@ typedef uintptr_t mem_ptr_t; #define PACK_STRUCT_STRUCT __attribute__ ((__packed__)) #define PACK_STRUCT_BEGIN #define PACK_STRUCT_END -#elif defined(__IAR_SYSTEMS_ICC__) /* IAR Compiler */ +#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) /*Arm Compiler 6*/ +#define PACK_STRUCT_FIELD(x) x +#define PACK_STRUCT_STRUCT __attribute__((packed)) #define PACK_STRUCT_BEGIN -#define PACK_STRUCT_STRUCT #define PACK_STRUCT_END +#elif defined(__IAR_SYSTEMS_ICC__) /* IAR Compiler */ +#define PACK_STRUCT_BEGIN #pragma pack(1) +#define PACK_STRUCT_STRUCT +#define PACK_STRUCT_END #pragma pack() #define PACK_STRUCT_FIELD(x) x #define PACK_STRUCT_USE_INCLUDES #elif defined(__GNUC__) /* GNU GCC Compiler */ diff --git a/components/net/lwip-2.0.2/src/arch/include/arch/cc.h b/components/net/lwip-2.0.2/src/arch/include/arch/cc.h index 00536a8419..8888995bcc 100644 --- a/components/net/lwip-2.0.2/src/arch/include/arch/cc.h +++ b/components/net/lwip-2.0.2/src/arch/include/arch/cc.h @@ -45,7 +45,7 @@ #define S32_F "ld" #define X32_F "lx" -#if defined(RT_USING_LIBC) || defined(RT_USING_MINILIBC) || defined(RT_LIBC_USING_TIME) || defined ( __GNUC__) +#if defined(RT_USING_LIBC) || defined(RT_USING_MINILIBC) || defined(RT_LIBC_USING_TIME) || (defined( __GNUC__ ) && !defined(__ARMCC_VERSION)) #include #define LWIP_TIMEVAL_PRIVATE 0 #else @@ -57,10 +57,15 @@ #define PACK_STRUCT_STRUCT __attribute__ ((__packed__)) #define PACK_STRUCT_BEGIN #define PACK_STRUCT_END -#elif defined(__IAR_SYSTEMS_ICC__) /* IAR Compiler */ +#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) /*Arm Compiler 6*/ +#define PACK_STRUCT_FIELD(x) x +#define PACK_STRUCT_STRUCT __attribute__((packed)) #define PACK_STRUCT_BEGIN -#define PACK_STRUCT_STRUCT #define PACK_STRUCT_END +#elif defined(__IAR_SYSTEMS_ICC__) /* IAR Compiler */ +#define PACK_STRUCT_BEGIN #pragma pack(1) +#define PACK_STRUCT_STRUCT +#define PACK_STRUCT_END #pragma pack() #define PACK_STRUCT_FIELD(x) x #define PACK_STRUCT_USE_INCLUDES #elif defined(__GNUC__) /* GNU GCC Compiler */ diff --git a/components/net/lwip-2.1.2/src/arch/include/arch/cc.h b/components/net/lwip-2.1.2/src/arch/include/arch/cc.h index 6905ecd442..61086b96d3 100644 --- a/components/net/lwip-2.1.2/src/arch/include/arch/cc.h +++ b/components/net/lwip-2.1.2/src/arch/include/arch/cc.h @@ -59,7 +59,7 @@ #endif /* __CC_ARM/__IAR_SYSTEMS_ICC__ */ #endif /* RT_USING_LIBC */ -#if defined(RT_USING_LIBC) || defined(RT_USING_MINILIBC) || defined(RT_LIBC_USING_TIME) || defined ( __GNUC__) +#if defined(RT_USING_LIBC) || defined(RT_USING_MINILIBC) || defined(RT_LIBC_USING_TIME) || (defined( __GNUC__ ) && !defined(__ARMCC_VERSION)) #include #define LWIP_TIMEVAL_PRIVATE 0 #else @@ -71,10 +71,15 @@ #define PACK_STRUCT_STRUCT __attribute__ ((__packed__)) #define PACK_STRUCT_BEGIN #define PACK_STRUCT_END -#elif defined(__IAR_SYSTEMS_ICC__) /* IAR Compiler */ +#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) /*Arm Compiler 6*/ +#define PACK_STRUCT_FIELD(x) x +#define PACK_STRUCT_STRUCT __attribute__((packed)) #define PACK_STRUCT_BEGIN -#define PACK_STRUCT_STRUCT #define PACK_STRUCT_END +#elif defined(__IAR_SYSTEMS_ICC__) /* IAR Compiler */ +#define PACK_STRUCT_BEGIN #pragma pack(1) +#define PACK_STRUCT_STRUCT +#define PACK_STRUCT_END #pragma pack() #define PACK_STRUCT_FIELD(x) x #define PACK_STRUCT_USE_INCLUDES #elif defined(__GNUC__) /* GNU GCC Compiler */ diff --git a/include/libc/libc_errno.h b/include/libc/libc_errno.h index 00c1f733d3..9143c841f2 100644 --- a/include/libc/libc_errno.h +++ b/include/libc/libc_errno.h @@ -13,7 +13,7 @@ #include -#if defined(RT_USING_NEWLIB) || defined(_WIN32) || defined( __GNUC__ ) +#if defined(RT_USING_NEWLIB) || defined(_WIN32) || (defined( __GNUC__ ) && !defined(__ARMCC_VERSION)) /* use errno.h file in toolchains */ #include #endif @@ -45,7 +45,7 @@ defined in armcc/errno.h #define ERROR_BASE_NO 0 #endif -#if !defined(RT_USING_NEWLIB) && !defined(_WIN32) && !defined(__GNUC__ ) +#if !defined(RT_USING_NEWLIB) && !defined(_WIN32) && !(defined( __GNUC__ ) && !defined(__ARMCC_VERSION)) #define EPERM (ERROR_BASE_NO + 1) #define ENOENT (ERROR_BASE_NO + 2) diff --git a/include/libc/libc_fcntl.h b/include/libc/libc_fcntl.h index 39740b7d85..d149d86964 100644 --- a/include/libc/libc_fcntl.h +++ b/include/libc/libc_fcntl.h @@ -12,7 +12,7 @@ #ifndef LIBC_FCNTL_H__ #define LIBC_FCNTL_H__ -#if defined(RT_USING_NEWLIB) || defined(_WIN32) || defined( __GNUC__ ) +#if defined(RT_USING_NEWLIB) || defined(_WIN32) || (defined( __GNUC__ ) && !defined(__ARMCC_VERSION)) #include #ifndef O_NONBLOCK diff --git a/include/libc/libc_fdset.h b/include/libc/libc_fdset.h index 4a778b51c1..9700c7e83e 100644 --- a/include/libc/libc_fdset.h +++ b/include/libc/libc_fdset.h @@ -13,7 +13,7 @@ #include -#if defined(RT_USING_NEWLIB) || defined(_WIN32) || defined( __GNUC__ ) +#if defined(RT_USING_NEWLIB) || defined(_WIN32) || (defined( __GNUC__ ) && !defined(__ARMCC_VERSION)) #include #if defined(HAVE_SYS_SELECT_H) #include diff --git a/include/libc/libc_stat.h b/include/libc/libc_stat.h index 9388688572..6497cfe12c 100644 --- a/include/libc/libc_stat.h +++ b/include/libc/libc_stat.h @@ -9,7 +9,7 @@ #include -#if defined(RT_USING_NEWLIB) || defined( __GNUC__ ) +#if defined(RT_USING_NEWLIB) || (defined( __GNUC__ ) && !defined(__ARMCC_VERSION)) /* use header file of newlib */ #include -- cgit v1.3.1 From 502378cf93bf780035316d594c80dd9b027efa17 Mon Sep 17 00:00:00 2001 From: WangQiang Date: Mon, 12 Oct 2020 18:15:01 +0800 Subject: 1. 抽象了PHY的设备模型,在components中增加了PHY设备的相关代码以及KCONFIG配置和SConscript脚本 2. 在IMXRT的Libraries中增加了peripherals目录,用于具体型号的设备驱动相关的代码的实现,不应与MCU的平台相关,实现PHY的设备对象中的相关接口。 3. 修改了BSP中的Sconstruct文件,增加了peripherals目录的构建 4. 修改了KEIL环境的SCT文件,用于实现以太网功能 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bsp/imxrt/imxrt1064-nxp-evk/SConstruct | 3 + bsp/imxrt/imxrt1064-nxp-evk/board/Kconfig | 35 +- bsp/imxrt/imxrt1064-nxp-evk/board/SConscript | 4 - bsp/imxrt/imxrt1064-nxp-evk/board/board.c | 26 ++ bsp/imxrt/imxrt1064-nxp-evk/board/board.h | 2 +- .../board/linker_scripts/link.sct | 4 +- .../board/ports/phyksz8081/fsl_phy.c | 315 ------------------ .../board/ports/phyksz8081/fsl_phy.h | 200 ----------- bsp/imxrt/libraries/drivers/SConscript | 3 + bsp/imxrt/libraries/drivers/drv_eth.c | 94 +++--- bsp/imxrt/libraries/drivers/drv_mdio.c | 160 +++++++++ bsp/imxrt/libraries/drivers/drv_mdio.h | 25 ++ bsp/imxrt/libraries/peripherals/SConscript | 16 + bsp/imxrt/libraries/peripherals/phyksz8081.c | 367 +++++++++++++++++++++ bsp/imxrt/tools/sdk_dist.py | 3 + components/drivers/Kconfig | 4 + components/drivers/include/drivers/phy.h | 79 +++++ components/drivers/include/drivers/phy_mdio.h | 35 ++ components/drivers/include/rtdevice.h | 5 + components/drivers/phy/SConscript | 8 + components/drivers/phy/phy.c | 78 +++++ components/finsh/cmd.c | 1 + include/rtdef.h | 1 + 23 files changed, 903 insertions(+), 565 deletions(-) delete mode 100644 bsp/imxrt/imxrt1064-nxp-evk/board/ports/phyksz8081/fsl_phy.c delete mode 100644 bsp/imxrt/imxrt1064-nxp-evk/board/ports/phyksz8081/fsl_phy.h create mode 100644 bsp/imxrt/libraries/drivers/drv_mdio.c create mode 100644 bsp/imxrt/libraries/drivers/drv_mdio.h create mode 100644 bsp/imxrt/libraries/peripherals/SConscript create mode 100644 bsp/imxrt/libraries/peripherals/phyksz8081.c create mode 100644 components/drivers/include/drivers/phy.h create mode 100644 components/drivers/include/drivers/phy_mdio.h create mode 100644 components/drivers/phy/SConscript create mode 100644 components/drivers/phy/phy.c (limited to 'include') diff --git a/bsp/imxrt/imxrt1064-nxp-evk/SConstruct b/bsp/imxrt/imxrt1064-nxp-evk/SConstruct index 01c823f118..92ab729ed1 100644 --- a/bsp/imxrt/imxrt1064-nxp-evk/SConstruct +++ b/bsp/imxrt/imxrt1064-nxp-evk/SConstruct @@ -66,5 +66,8 @@ objs.extend(SConscript(os.path.join(libraries_path_prefix, imxrt_library, 'SCons # include drivers objs.extend(SConscript(os.path.join(libraries_path_prefix, 'drivers', 'SConscript'))) +# include peripherals +objs.extend(SConscript(os.path.join(libraries_path_prefix, 'peripherals', 'SConscript'))) + # make a building DoBuilding(TARGET, objs) diff --git a/bsp/imxrt/imxrt1064-nxp-evk/board/Kconfig b/bsp/imxrt/imxrt1064-nxp-evk/board/Kconfig index 4c7caa2d53..5c660b91c7 100644 --- a/bsp/imxrt/imxrt1064-nxp-evk/board/Kconfig +++ b/bsp/imxrt/imxrt1064-nxp-evk/board/Kconfig @@ -44,20 +44,41 @@ menu "Onboard Peripheral Drivers" menuconfig BSP_USING_ETH bool "Enable Ethernet" - select PHY_USING_KSZ8081 select RT_USING_NETDEV default n if BSP_USING_ETH - config PHY_USING_KSZ8081 - bool "i.MX RT1064EVK uses ksz8081 phy" + config BSP_USING_PHY + select RT_USING_PHY + bool "Enable ethernet phy" default y - config FSL_FEATURE_PHYKSZ8081_USE_RMII50M_MODE - bool "Enable the PHY ksz8081 RMII50M mode" - depends on PHY_USING_KSZ8081 - default y + if BSP_USING_PHY + config PHY_DEVICE_ADDRESS + int "Specify address of phy device" + default 2 + + config PHY_USING_KSZ8081 + bool "i.MX RT1064EVK uses ksz8081 phy" + default y + + if PHY_USING_KSZ8081 + config PHY_RESET_PORT + int "indicate port of reset" + default 1 + + config PHY_RESET_PIN + int "indicate pin of reset" + default 9 + + config FSL_FEATURE_PHYKSZ8081_USE_RMII50M_MODE + bool "Enable the PHY ksz8081 RMII50M mode" + depends on PHY_USING_KSZ8081 + default y + endif + + endif endif endmenu diff --git a/bsp/imxrt/imxrt1064-nxp-evk/board/SConscript b/bsp/imxrt/imxrt1064-nxp-evk/board/SConscript index 6afc7c3ae4..050a6c10bc 100644 --- a/bsp/imxrt/imxrt1064-nxp-evk/board/SConscript +++ b/bsp/imxrt/imxrt1064-nxp-evk/board/SConscript @@ -15,10 +15,6 @@ CPPPATH = [cwd,cwd + '/MCUX_Config',cwd + '/ports'] CPPDEFINES = ['CPU_MIMXRT1064DVL6A', 'SKIP_SYSCLK_INIT', 'EVK_MCIMXRM', 'FSL_SDK_ENABLE_DRIVER_CACHE_CONTROL=1','XIP_EXTERNAL_FLASH=1', 'XIP_BOOT_HEADER_ENABLE=1', 'XIP_BOOT_HEADER_DCD_ENABLE=1'] -if GetDepend(['PHY_USING_KSZ8081']): - src += Glob('ports/phyksz8081/fsl_phy.c') - CPPPATH += [cwd + '/ports/phyksz8081'] - if rtconfig.CROSS_TOOL == 'keil': CPPDEFINES.append('__FPU_PRESENT=1') diff --git a/bsp/imxrt/imxrt1064-nxp-evk/board/board.c b/bsp/imxrt/imxrt1064-nxp-evk/board/board.c index 0ef8769e0e..603cd856c5 100644 --- a/bsp/imxrt/imxrt1064-nxp-evk/board/board.c +++ b/bsp/imxrt/imxrt1064-nxp-evk/board/board.c @@ -416,6 +416,7 @@ void imxrt_enet_pins_init(void) Hyst. Enable Field: Hysteresis Disabled */ } +#ifndef BSP_USING_PHY void imxrt_enet_phy_reset_by_gpio(void) { gpio_pin_config_t gpio_config = {kGPIO_DigitalOutput, 0, kGPIO_NoIntmode}; @@ -428,8 +429,29 @@ void imxrt_enet_phy_reset_by_gpio(void) rt_thread_delay(100); GPIO_WritePinOutput(GPIO1, 9, 1); } +#endif /* BSP_USING_PHY */ + #endif /* BSP_USING_ETH */ +#ifdef BSP_USING_PHY +void imxrt_phy_pins_init( void ) +{ + IOMUXC_SetPinMux( + IOMUXC_GPIO_AD_B0_09_GPIO1_IO09, /* GPIO_AD_B0_09 is configured as GPIO1_IO09 */ + 0U); /* Software Input On Field: Input Path is determined by functionality */ + IOMUXC_SetPinConfig( + IOMUXC_GPIO_AD_B0_09_GPIO1_IO09, /* GPIO_B0_00 PAD functional properties : */ + 0x10B0u); /* Slew Rate Field: Slow Slew Rate + Drive Strength Field: R0/6 + Speed Field: medium(100MHz) + Open Drain Enable Field: Open Drain Disabled + Pull / Keep Enable Field: Pull/Keeper Enabled + Pull / Keep Select Field: Keeper + Pull Up / Down Config. Field: 100K Ohm Pull Down + Hyst. Enable Field: Hysteresis Disabled */ +} +#endif /* BSP_USING_PHY */ + /** * This function will initial rt1050 board. */ @@ -450,6 +472,10 @@ void rt_hw_board_init() imxrt_enet_pins_init(); #endif +#ifdef BSP_USING_PHY + imxrt_phy_pins_init(); +#endif + #ifdef BSP_USING_DMA imxrt_dma_init(); #endif diff --git a/bsp/imxrt/imxrt1064-nxp-evk/board/board.h b/bsp/imxrt/imxrt1064-nxp-evk/board/board.h index 500cc62450..dd7b7d3e56 100644 --- a/bsp/imxrt/imxrt1064-nxp-evk/board/board.h +++ b/bsp/imxrt/imxrt1064-nxp-evk/board/board.h @@ -48,7 +48,7 @@ void rt_hw_board_init(void); #ifdef BSP_USING_ETH void imxrt_enet_pins_init(void); void imxrt_enet_phy_reset_by_gpio(void); -#define PHY_ADDRESS 0x02u + #endif #endif diff --git a/bsp/imxrt/imxrt1064-nxp-evk/board/linker_scripts/link.sct b/bsp/imxrt/imxrt1064-nxp-evk/board/linker_scripts/link.sct index 7b7bf4fbba..f36201c200 100644 --- a/bsp/imxrt/imxrt1064-nxp-evk/board/linker_scripts/link.sct +++ b/bsp/imxrt/imxrt1064-nxp-evk/board/linker_scripts/link.sct @@ -66,6 +66,8 @@ #define m_data3_start 0x00000000 ; ITCM 128KB #define m_data3_size 0x00020000 +#define m_ncache_start 0x81E00000 +#define m_ncache_size 0x00200000 /* Sizes */ #if (defined(__stack_size__)) @@ -124,7 +126,7 @@ LR_IROM1 m_text_start m_text_size RTT_HEAP +0 EMPTY RTT_HEAP_SIZE{} ; ncache RW data - RW_m_ncache m_data2_start m_data2_size + RW_m_ncache m_ncache_start m_ncache_size { * (NonCacheable.init) * (NonCacheable) diff --git a/bsp/imxrt/imxrt1064-nxp-evk/board/ports/phyksz8081/fsl_phy.c b/bsp/imxrt/imxrt1064-nxp-evk/board/ports/phyksz8081/fsl_phy.c deleted file mode 100644 index 4197514aa5..0000000000 --- a/bsp/imxrt/imxrt1064-nxp-evk/board/ports/phyksz8081/fsl_phy.c +++ /dev/null @@ -1,315 +0,0 @@ -/* - * Copyright (c) 2015, Freescale Semiconductor, Inc. - * Copyright 2016-2017 NXP - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include "fsl_phy.h" -#include -/******************************************************************************* - * Definitions - ******************************************************************************/ - -/*! @brief Defines the timeout macro. */ -#define PHY_TIMEOUT_COUNT 0x3FFFFFFU - -/******************************************************************************* - * Prototypes - ******************************************************************************/ - -/*! - * @brief Get the ENET instance from peripheral base address. - * - * @param base ENET peripheral base address. - * @return ENET instance. - */ -extern uint32_t ENET_GetInstance(ENET_Type *base); - -/******************************************************************************* - * Variables - ******************************************************************************/ - -#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) -/*! @brief Pointers to enet clocks for each instance. */ -extern clock_ip_name_t s_enetClock[FSL_FEATURE_SOC_ENET_COUNT]; -#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */ - -/******************************************************************************* - * Code - ******************************************************************************/ - -status_t PHY_Init(ENET_Type *base, uint32_t phyAddr, uint32_t srcClock_Hz) -{ - uint32_t bssReg; - uint32_t counter = PHY_TIMEOUT_COUNT; - uint32_t idReg = 0; - status_t result = kStatus_Success; - uint32_t instance = ENET_GetInstance(base); - uint32_t timeDelay; - uint32_t ctlReg = 0; - -#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) - /* Set SMI first. */ - CLOCK_EnableClock(s_enetClock[instance]); -#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */ - ENET_SetSMI(base, srcClock_Hz, false); - - /* Initialization after PHY stars to work. */ - while ((idReg != PHY_CONTROL_ID1) && (counter != 0)) - { - PHY_Read(base, phyAddr, PHY_ID1_REG, &idReg); - counter --; - } - - if (!counter) - { - return kStatus_Fail; - } - - /* Reset PHY. */ - counter = PHY_TIMEOUT_COUNT; - result = PHY_Write(base, phyAddr, PHY_BASICCONTROL_REG, PHY_BCTL_RESET_MASK); - if (result == kStatus_Success) - { - -#if defined(FSL_FEATURE_PHYKSZ8081_USE_RMII50M_MODE) - uint32_t data = 0; - result = PHY_Read(base, phyAddr, PHY_CONTROL2_REG, &data); - if ( result != kStatus_Success) - { - return result; - } - result = PHY_Write(base, phyAddr, PHY_CONTROL2_REG, (data | PHY_CTL2_REFCLK_SELECT_MASK)); - if (result != kStatus_Success) - { - return result; - } -#endif /* FSL_FEATURE_PHYKSZ8081_USE_RMII50M_MODE */ - - /* Set the negotiation. */ - result = PHY_Write(base, phyAddr, PHY_AUTONEG_ADVERTISE_REG, - (PHY_100BASETX_FULLDUPLEX_MASK | PHY_100BASETX_HALFDUPLEX_MASK | - PHY_10BASETX_FULLDUPLEX_MASK | PHY_10BASETX_HALFDUPLEX_MASK | 0x1U)); - if (result == kStatus_Success) - { - result = PHY_Write(base, phyAddr, PHY_BASICCONTROL_REG, - (PHY_BCTL_AUTONEG_MASK | PHY_BCTL_RESTART_AUTONEG_MASK)); - if (result == kStatus_Success) - { - /* Check auto negotiation complete. */ - while (counter --) - { - result = PHY_Read(base, phyAddr, PHY_BASICSTATUS_REG, &bssReg); - if ( result == kStatus_Success) - { - PHY_Read(base, phyAddr, PHY_CONTROL1_REG, &ctlReg); - if (((bssReg & PHY_BSTATUS_AUTONEGCOMP_MASK) != 0) && (ctlReg & PHY_LINK_READY_MASK)) - { - /* Wait a moment for Phy status stable. */ - for (timeDelay = 0; timeDelay < PHY_TIMEOUT_COUNT; timeDelay ++) - { - __ASM("nop"); - } - break; - } - } - - if (!counter) - { - return kStatus_PHY_AutoNegotiateFail; - } - } - } - } - } - - return result; -} - -status_t PHY_Write(ENET_Type *base, uint32_t phyAddr, uint32_t phyReg, uint32_t data) -{ - uint32_t counter; - - /* Clear the SMI interrupt event. */ - ENET_ClearInterruptStatus(base, ENET_EIR_MII_MASK); - - /* Starts a SMI write command. */ - ENET_StartSMIWrite(base, phyAddr, phyReg, kENET_MiiWriteValidFrame, data); - - /* Wait for SMI complete. */ - for (counter = PHY_TIMEOUT_COUNT; counter > 0; counter--) - { - if (ENET_GetInterruptStatus(base) & ENET_EIR_MII_MASK) - { - break; - } - } - - /* Check for timeout. */ - if (!counter) - { - return kStatus_PHY_SMIVisitTimeout; - } - - /* Clear MII interrupt event. */ - ENET_ClearInterruptStatus(base, ENET_EIR_MII_MASK); - - return kStatus_Success; -} - -status_t PHY_Read(ENET_Type *base, uint32_t phyAddr, uint32_t phyReg, uint32_t *dataPtr) -{ - assert(dataPtr); - - uint32_t counter; - - /* Clear the MII interrupt event. */ - ENET_ClearInterruptStatus(base, ENET_EIR_MII_MASK); - - /* Starts a SMI read command operation. */ - ENET_StartSMIRead(base, phyAddr, phyReg, kENET_MiiReadValidFrame); - - /* Wait for MII complete. */ - for (counter = PHY_TIMEOUT_COUNT; counter > 0; counter--) - { - if (ENET_GetInterruptStatus(base) & ENET_EIR_MII_MASK) - { - break; - } - } - - /* Check for timeout. */ - if (!counter) - { - return kStatus_PHY_SMIVisitTimeout; - } - - /* Get data from MII register. */ - *dataPtr = ENET_ReadSMIData(base); - - /* Clear MII interrupt event. */ - ENET_ClearInterruptStatus(base, ENET_EIR_MII_MASK); - - return kStatus_Success; -} - -status_t PHY_EnableLoopback(ENET_Type *base, uint32_t phyAddr, phy_loop_t mode, phy_speed_t speed, bool enable) -{ - status_t result; - uint32_t data = 0; - - /* Set the loop mode. */ - if (enable) - { - if (mode == kPHY_LocalLoop) - { - if (speed == kPHY_Speed100M) - { - data = PHY_BCTL_SPEED_100M_MASK | PHY_BCTL_DUPLEX_MASK | PHY_BCTL_LOOP_MASK; - } - else - { - data = PHY_BCTL_DUPLEX_MASK | PHY_BCTL_LOOP_MASK; - } - return PHY_Write(base, phyAddr, PHY_BASICCONTROL_REG, data); - } - else - { - /* First read the current status in control register. */ - result = PHY_Read(base, phyAddr, PHY_CONTROL2_REG, &data); - if (result == kStatus_Success) - { - return PHY_Write(base, phyAddr, PHY_CONTROL2_REG, (data | PHY_CTL2_REMOTELOOP_MASK)); - } - } - } - else - { - /* Disable the loop mode. */ - if (mode == kPHY_LocalLoop) - { - /* First read the current status in control register. */ - result = PHY_Read(base, phyAddr, PHY_BASICCONTROL_REG, &data); - if (result == kStatus_Success) - { - data &= ~PHY_BCTL_LOOP_MASK; - return PHY_Write(base, phyAddr, PHY_BASICCONTROL_REG, (data | PHY_BCTL_RESTART_AUTONEG_MASK)); - } - } - else - { - /* First read the current status in control one register. */ - result = PHY_Read(base, phyAddr, PHY_CONTROL2_REG, &data); - if (result == kStatus_Success) - { - return PHY_Write(base, phyAddr, PHY_CONTROL2_REG, (data & ~PHY_CTL2_REMOTELOOP_MASK)); - } - } - } - return result; -} - -status_t PHY_GetLinkStatus(ENET_Type *base, uint32_t phyAddr, bool *status) -{ - assert(status); - - status_t result = kStatus_Success; - uint32_t data; - - /* Read the basic status register. */ - result = PHY_Read(base, phyAddr, PHY_BASICSTATUS_REG, &data); - if (result == kStatus_Success) - { - if (!(PHY_BSTATUS_LINKSTATUS_MASK & data)) - { - /* link down. */ - *status = false; - } - else - { - /* link up. */ - *status = true; - } - } - return result; -} - -status_t PHY_GetLinkSpeedDuplex(ENET_Type *base, uint32_t phyAddr, phy_speed_t *speed, phy_duplex_t *duplex) -{ - assert(duplex); - - status_t result = kStatus_Success; - uint32_t data, ctlReg; - - /* Read the control two register. */ - result = PHY_Read(base, phyAddr, PHY_CONTROL1_REG, &ctlReg); - if (result == kStatus_Success) - { - data = ctlReg & PHY_CTL1_SPEEDUPLX_MASK; - if ((PHY_CTL1_10FULLDUPLEX_MASK == data) || (PHY_CTL1_100FULLDUPLEX_MASK == data)) - { - /* Full duplex. */ - *duplex = kPHY_FullDuplex; - } - else - { - /* Half duplex. */ - *duplex = kPHY_HalfDuplex; - } - - data = ctlReg & PHY_CTL1_SPEEDUPLX_MASK; - if ((PHY_CTL1_100HALFDUPLEX_MASK == data) || (PHY_CTL1_100FULLDUPLEX_MASK == data)) - { - /* 100M speed. */ - *speed = kPHY_Speed100M; - } - else - { /* 10M speed. */ - *speed = kPHY_Speed10M; - } - } - - return result; -} diff --git a/bsp/imxrt/imxrt1064-nxp-evk/board/ports/phyksz8081/fsl_phy.h b/bsp/imxrt/imxrt1064-nxp-evk/board/ports/phyksz8081/fsl_phy.h deleted file mode 100644 index a1eff6d723..0000000000 --- a/bsp/imxrt/imxrt1064-nxp-evk/board/ports/phyksz8081/fsl_phy.h +++ /dev/null @@ -1,200 +0,0 @@ -/* - * Copyright (c) 2015, Freescale Semiconductor, Inc. - * Copyright 2016-2017 NXP - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ -#ifndef _FSL_PHY_H_ -#define _FSL_PHY_H_ - -#include "fsl_enet.h" - -/*! - * @addtogroup phy_driver - * @{ - */ - -/******************************************************************************* - * Definitions - ******************************************************************************/ - -/*! @brief PHY driver version */ -#define FSL_PHY_DRIVER_VERSION (MAKE_VERSION(2, 0, 0)) /*!< Version 2.0.0. */ - -/*! @brief Defines the PHY registers. */ -#define PHY_BASICCONTROL_REG 0x00U /*!< The PHY basic control register. */ -#define PHY_BASICSTATUS_REG 0x01U /*!< The PHY basic status register. */ -#define PHY_ID1_REG 0x02U /*!< The PHY ID one register. */ -#define PHY_ID2_REG 0x03U /*!< The PHY ID two register. */ -#define PHY_AUTONEG_ADVERTISE_REG 0x04U /*!< The PHY auto-negotiate advertise register. */ -#define PHY_CONTROL1_REG 0x1EU /*!< The PHY control one register. */ -#define PHY_CONTROL2_REG 0x1FU /*!< The PHY control two register. */ - -#define PHY_CONTROL_ID1 0x22U /*!< The PHY ID1*/ - -/*! @brief Defines the mask flag in basic control register. */ -#define PHY_BCTL_DUPLEX_MASK 0x0100U /*!< The PHY duplex bit mask. */ -#define PHY_BCTL_RESTART_AUTONEG_MASK 0x0200U /*!< The PHY restart auto negotiation mask. */ -#define PHY_BCTL_AUTONEG_MASK 0x1000U /*!< The PHY auto negotiation bit mask. */ -#define PHY_BCTL_SPEED_MASK 0x2000U /*!< The PHY speed bit mask. */ -#define PHY_BCTL_LOOP_MASK 0x4000U /*!< The PHY loop bit mask. */ -#define PHY_BCTL_RESET_MASK 0x8000U /*!< The PHY reset bit mask. */ -#define PHY_BCTL_SPEED_100M_MASK 0x2000U /*!< The PHY 100M speed mask. */ - -/*!@brief Defines the mask flag of operation mode in control two register*/ -#define PHY_CTL2_REMOTELOOP_MASK 0x0004U /*!< The PHY remote loopback mask. */ -#define PHY_CTL2_REFCLK_SELECT_MASK 0x0080U /*!< The PHY RMII reference clock select. */ -#define PHY_CTL1_10HALFDUPLEX_MASK 0x0001U /*!< The PHY 10M half duplex mask. */ -#define PHY_CTL1_100HALFDUPLEX_MASK 0x0002U /*!< The PHY 100M half duplex mask. */ -#define PHY_CTL1_10FULLDUPLEX_MASK 0x0005U /*!< The PHY 10M full duplex mask. */ -#define PHY_CTL1_100FULLDUPLEX_MASK 0x0006U /*!< The PHY 100M full duplex mask. */ -#define PHY_CTL1_SPEEDUPLX_MASK 0x0007U /*!< The PHY speed and duplex mask. */ -#define PHY_CTL1_ENERGYDETECT_MASK 0x10U /*!< The PHY signal present on rx differential pair. */ -#define PHY_CTL1_LINKUP_MASK 0x100U /*!< The PHY link up. */ -#define PHY_LINK_READY_MASK (PHY_CTL1_ENERGYDETECT_MASK | PHY_CTL1_LINKUP_MASK) - -/*! @brief Defines the mask flag in basic status register. */ -#define PHY_BSTATUS_LINKSTATUS_MASK 0x0004U /*!< The PHY link status mask. */ -#define PHY_BSTATUS_AUTONEGABLE_MASK 0x0008U /*!< The PHY auto-negotiation ability mask. */ -#define PHY_BSTATUS_AUTONEGCOMP_MASK 0x0020U /*!< The PHY auto-negotiation complete mask. */ - -/*! @brief Defines the mask flag in PHY auto-negotiation advertise register. */ -#define PHY_100BaseT4_ABILITY_MASK 0x200U /*!< The PHY have the T4 ability. */ -#define PHY_100BASETX_FULLDUPLEX_MASK 0x100U /*!< The PHY has the 100M full duplex ability.*/ -#define PHY_100BASETX_HALFDUPLEX_MASK 0x080U /*!< The PHY has the 100M full duplex ability.*/ -#define PHY_10BASETX_FULLDUPLEX_MASK 0x040U /*!< The PHY has the 10M full duplex ability.*/ -#define PHY_10BASETX_HALFDUPLEX_MASK 0x020U /*!< The PHY has the 10M full duplex ability.*/ - -/*! @brief Defines the PHY status. */ -enum _phy_status -{ - kStatus_PHY_SMIVisitTimeout = MAKE_STATUS(kStatusGroup_PHY, 1), /*!< ENET PHY SMI visit timeout. */ - kStatus_PHY_AutoNegotiateFail = MAKE_STATUS(kStatusGroup_PHY, 2) /*!< ENET PHY AutoNegotiate Fail. */ -}; - -/*! @brief Defines the PHY link speed. This is align with the speed for ENET MAC. */ -typedef enum _phy_speed -{ - kPHY_Speed10M = 0U, /*!< ENET PHY 10M speed. */ - kPHY_Speed100M /*!< ENET PHY 100M speed. */ -} phy_speed_t; - -/*! @brief Defines the PHY link duplex. */ -typedef enum _phy_duplex -{ - kPHY_HalfDuplex = 0U, /*!< ENET PHY half duplex. */ - kPHY_FullDuplex /*!< ENET PHY full duplex. */ -} phy_duplex_t; - -/*! @brief Defines the PHY loopback mode. */ -typedef enum _phy_loop -{ - kPHY_LocalLoop = 0U, /*!< ENET PHY local loopback. */ - kPHY_RemoteLoop /*!< ENET PHY remote loopback. */ -} phy_loop_t; - -/******************************************************************************* - * API - ******************************************************************************/ - -#if defined(__cplusplus) -extern "C" { -#endif - -/*! - * @name PHY Driver - * @{ - */ - -/*! - * @brief Initializes PHY. - * - * This function initialize the SMI interface and initialize PHY. - * The SMI is the MII management interface between PHY and MAC, which should be - * firstly initialized before any other operation for PHY. The PHY initialize with auto-negotiation. - * - * @param base ENET peripheral base address. - * @param phyAddr The PHY address. - * @param srcClock_Hz The module clock frequency - system clock for MII management interface - SMI. - * @retval kStatus_Success PHY initialize success - * @retval kStatus_PHY_SMIVisitTimeout PHY SMI visit time out - * @retval kStatus_PHY_AutoNegotiateFail PHY auto negotiate fail - */ -status_t PHY_Init(ENET_Type *base, uint32_t phyAddr, uint32_t srcClock_Hz); - -/*! - * @brief PHY Write function. This function write data over the SMI to - * the specified PHY register. This function is called by all PHY interfaces. - * - * @param base ENET peripheral base address. - * @param phyAddr The PHY address. - * @param phyReg The PHY register. - * @param data The data written to the PHY register. - * @retval kStatus_Success PHY write success - * @retval kStatus_PHY_SMIVisitTimeout PHY SMI visit time out - */ -status_t PHY_Write(ENET_Type *base, uint32_t phyAddr, uint32_t phyReg, uint32_t data); - -/*! - * @brief PHY Read function. This interface read data over the SMI from the - * specified PHY register. This function is called by all PHY interfaces. - * - * @param base ENET peripheral base address. - * @param phyAddr The PHY address. - * @param phyReg The PHY register. - * @param dataPtr The address to store the data read from the PHY register. - * @retval kStatus_Success PHY read success - * @retval kStatus_PHY_SMIVisitTimeout PHY SMI visit time out - */ -status_t PHY_Read(ENET_Type *base, uint32_t phyAddr, uint32_t phyReg, uint32_t *dataPtr); - -/*! - * @brief Enables/disables PHY loopback. - * - * @param base ENET peripheral base address. - * @param phyAddr The PHY address. - * @param mode The loopback mode to be enabled, please see "phy_loop_t". - * the two loopback mode should not be both set. when one loopback mode is set - * the other one should be disabled. - * @param speed PHY speed for loopback mode. - * @param enable True to enable, false to disable. - * @retval kStatus_Success PHY loopback success - * @retval kStatus_PHY_SMIVisitTimeout PHY SMI visit time out - */ -status_t PHY_EnableLoopback(ENET_Type *base, uint32_t phyAddr, phy_loop_t mode, phy_speed_t speed, bool enable); - -/*! - * @brief Gets the PHY link status. - * - * @param base ENET peripheral base address. - * @param phyAddr The PHY address. - * @param status The link up or down status of the PHY. - * - true the link is up. - * - false the link is down. - * @retval kStatus_Success PHY get link status success - * @retval kStatus_PHY_SMIVisitTimeout PHY SMI visit time out - */ -status_t PHY_GetLinkStatus(ENET_Type *base, uint32_t phyAddr, bool *status); - -/*! - * @brief Gets the PHY link speed and duplex. - * - * @param base ENET peripheral base address. - * @param phyAddr The PHY address. - * @param speed The address of PHY link speed. - * @param duplex The link duplex of PHY. - * @retval kStatus_Success PHY get link speed and duplex success - * @retval kStatus_PHY_SMIVisitTimeout PHY SMI visit time out - */ -status_t PHY_GetLinkSpeedDuplex(ENET_Type *base, uint32_t phyAddr, phy_speed_t *speed, phy_duplex_t *duplex); - -/* @} */ - -#if defined(__cplusplus) -} -#endif - -/*! @}*/ - -#endif /* _FSL_PHY_H_ */ diff --git a/bsp/imxrt/libraries/drivers/SConscript b/bsp/imxrt/libraries/drivers/SConscript index c806dada25..c610fcd082 100644 --- a/bsp/imxrt/libraries/drivers/SConscript +++ b/bsp/imxrt/libraries/drivers/SConscript @@ -44,6 +44,9 @@ if GetDepend('BSP_USING_LCD'): if GetDepend('BSP_USING_ETH'): src += ['drv_eth.c'] + +if GetDepend('BSP_USING_PHY'): + src += ['drv_mdio.c'] if GetDepend('BSP_USING_USB_DEVICE'): src += ['drv_usbd.c'] diff --git a/bsp/imxrt/libraries/drivers/drv_eth.c b/bsp/imxrt/libraries/drivers/drv_eth.c index 4558312be8..665886f936 100644 --- a/bsp/imxrt/libraries/drivers/drv_eth.c +++ b/bsp/imxrt/libraries/drivers/drv_eth.c @@ -19,7 +19,6 @@ #include "fsl_enet.h" #include "fsl_gpio.h" -#include "fsl_phy.h" #include "fsl_cache.h" #include "fsl_iomuxc.h" #include "fsl_common.h" @@ -537,31 +536,52 @@ struct pbuf *rt_imxrt_eth_rx(rt_device_t dev) return NULL; } +#ifdef BSP_USING_PHY +static struct rt_phy_device *phy_dev = RT_NULL; static void phy_monitor_thread_entry(void *parameter) { - phy_speed_t speed; - phy_duplex_t duplex; - bool link = false; + rt_uint32_t speed; + rt_uint32_t duplex; + rt_bool_t link = RT_FALSE; - imxrt_enet_phy_reset_by_gpio(); - - PHY_Init(imxrt_eth_device.enet_base, PHY_ADDRESS, CLOCK_GetFreq(kCLOCK_AhbClk)); + phy_dev = (struct rt_phy_device *)rt_device_find("rtt-phy"); + if ((RT_NULL == phy_dev) || (RT_NULL == phy_dev->ops)) + { + // TODO print warning information + LOG_E("Can not find phy device called \"rtt-phy\""); + return ; + } + LOG_I("start to initialize phy device!"); + if (RT_NULL == phy_dev->ops->init) + { + LOG_E("phy driver error!"); + return ; + } + rt_phy_status status = phy_dev->ops->init(imxrt_eth_device.enet_base, PHY_DEVICE_ADDRESS, CLOCK_GetFreq(kCLOCK_AhbClk)); + if (PHY_STATUS_OK != status) + { + LOG_E("Phy device initialize unsuccessful!\n"); + return ; + } + else + { + LOG_I("Phy device initialize successful!\n"); + } while (1) { - bool new_link = false; - status_t status = PHY_GetLinkStatus(imxrt_eth_device.enet_base, PHY_ADDRESS, &new_link); + rt_bool_t new_link = RT_FALSE; + rt_phy_status status = phy_dev->ops->get_link_status(&new_link); - if ((status == kStatus_Success) && (link != new_link)) + if ((PHY_STATUS_OK == status) && (link != new_link)) { link = new_link; - if (link) // link up + if (link) // link up { - PHY_GetLinkSpeedDuplex(imxrt_eth_device.enet_base, - PHY_ADDRESS, &speed, &duplex); + phy_dev->ops->get_link_speed_duplex(&speed, &duplex); - if (kPHY_Speed10M == speed) + if (PHY_SPEED_10M == speed) { dbg_log(DBG_LOG, "10M\n"); } @@ -570,7 +590,7 @@ static void phy_monitor_thread_entry(void *parameter) dbg_log(DBG_LOG, "100M\n"); } - if (kPHY_HalfDuplex == duplex) + if (PHY_HALF_DUPLEX == duplex) { dbg_log(DBG_LOG, "half dumplex\n"); } @@ -579,8 +599,7 @@ static void phy_monitor_thread_entry(void *parameter) dbg_log(DBG_LOG, "full dumplex\n"); } - if ((imxrt_eth_device.speed != (enet_mii_speed_t)speed) - || (imxrt_eth_device.duplex != (enet_mii_duplex_t)duplex)) + if ((imxrt_eth_device.speed != (enet_mii_speed_t)speed) || (imxrt_eth_device.duplex != (enet_mii_duplex_t)duplex)) { imxrt_eth_device.speed = (enet_mii_speed_t)speed; imxrt_eth_device.duplex = (enet_mii_duplex_t)duplex; @@ -605,6 +624,7 @@ static void phy_monitor_thread_entry(void *parameter) rt_thread_delay(RT_TICK_PER_SECOND * 2); } } +#endif static int rt_hw_imxrt_eth_init(void) { @@ -657,6 +677,7 @@ static int rt_hw_imxrt_eth_init(void) /* start phy monitor */ { + #ifdef BSP_USING_PHY rt_thread_t tid; tid = rt_thread_create("phy", phy_monitor_thread_entry, @@ -666,6 +687,7 @@ static int rt_hw_imxrt_eth_init(void) 2); if (tid != RT_NULL) rt_thread_startup(tid); + #endif } return state; @@ -673,50 +695,47 @@ static int rt_hw_imxrt_eth_init(void) INIT_DEVICE_EXPORT(rt_hw_imxrt_eth_init); #endif -#ifdef RT_USING_FINSH +#if defined(RT_USING_FINSH) && defined(RT_USING_PHY) #include -void phy_read(uint32_t phyReg) +void phy_read(rt_uint32_t phy_reg) { - uint32_t data; - status_t status; + rt_uint32_t data; - status = PHY_Read(imxrt_eth_device.enet_base, PHY_ADDRESS, phyReg, &data); - if (kStatus_Success == status) + rt_phy_status status = phy_dev->ops->read(phy_reg, &data); + if (PHY_STATUS_OK == status) { - rt_kprintf("PHY_Read: %02X --> %08X", phyReg, data); + rt_kprintf("PHY_Read: %02X --> %08X", phy_reg, data); } else { - rt_kprintf("PHY_Read: %02X --> faild", phyReg); + rt_kprintf("PHY_Read: %02X --> faild", phy_reg); } } -void phy_write(uint32_t phyReg, uint32_t data) +void phy_write(rt_uint32_t phy_reg, rt_uint32_t data) { - status_t status; - - status = PHY_Write(imxrt_eth_device.enet_base, PHY_ADDRESS, phyReg, data); - if (kStatus_Success == status) + rt_phy_status status = phy_dev->ops->write(phy_reg, data); + if (PHY_STATUS_OK == status) { - rt_kprintf("PHY_Write: %02X --> %08X\n", phyReg, data); + rt_kprintf("PHY_Write: %02X --> %08X\n", phy_reg, data); } else { - rt_kprintf("PHY_Write: %02X --> faild\n", phyReg); + rt_kprintf("PHY_Write: %02X --> faild\n", phy_reg); } } void phy_dump(void) { - uint32_t data; - status_t status; + rt_uint32_t data; + rt_phy_status status; int i; for (i = 0; i < 32; i++) { - status = PHY_Read(imxrt_eth_device.enet_base, PHY_ADDRESS, i, &data); - if (kStatus_Success != status) + status = phy_dev->ops->read(i, &data); + if (PHY_STATUS_OK != status) { rt_kprintf("phy_dump: %02X --> faild", i); break; @@ -730,10 +749,11 @@ void phy_dump(void) { rt_kprintf("%02X --> %08X\n", i, data); } - } } +#endif +#if defined(RT_USING_FINSH) && defined(RT_USING_LWIP) void enet_reg_dump(void) { ENET_Type *enet_base = imxrt_eth_device.enet_base; diff --git a/bsp/imxrt/libraries/drivers/drv_mdio.c b/bsp/imxrt/libraries/drivers/drv_mdio.c new file mode 100644 index 0000000000..3e98d57f29 --- /dev/null +++ b/bsp/imxrt/libraries/drivers/drv_mdio.c @@ -0,0 +1,160 @@ + +/* + * Copyright (c) 2006-2020, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2020-09-29 WangQiang the first version + * + */ + +#include + +#ifdef BSP_USING_PHY + +#define LOG_TAG "drv.mdio" +#include + +#include +#include "drv_mdio.h" + + + +/*! @brief Defines the timeout macro. */ +#define PHY_TIMEOUT_COUNT 0x3FFFFFFU + +/*! + * @brief Get the ENET instance from peripheral base address. + * + * @param base ENET peripheral base address. + * @return ENET instance. + */ +extern uint32_t ENET_GetInstance(ENET_Type *base); + +#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) +/*! @brief Pointers to enet clocks for each instance. */ +extern clock_ip_name_t s_enetClock[FSL_FEATURE_SOC_ENET_COUNT]; +#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */ + +static rt_bool_t rt_hw_mdio_init(void *bus, rt_uint32_t src_clock_hz) +{ + struct rt_mdio_bus *bus_obj = (struct rt_mdio_bus *)bus; + uint32_t instance = ENET_GetInstance((ENET_Type *)(bus_obj->hw_obj)); +#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) + /* Set SMI first. */ + CLOCK_EnableClock(s_enetClock[instance]); +#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */ + ENET_SetSMI((ENET_Type *)(bus_obj->hw_obj), src_clock_hz, RT_FALSE); + + return RT_TRUE; +} + +static rt_size_t rt_hw_mdio_read(void *bus, rt_uint32_t addr, rt_uint32_t reg, void *data, rt_uint32_t size) +{ + RT_ASSERT(data); + struct rt_mdio_bus *bus_obj = (struct rt_mdio_bus *)bus; + + rt_uint32_t counter; + rt_uint32_t *data_ptr = (rt_uint32_t *)data; + + if (4 != size) + { + return 0; + } + + /* Clear the MII interrupt event. */ + ENET_ClearInterruptStatus((ENET_Type *)(bus_obj->hw_obj), ENET_EIR_MII_MASK); + + /* Starts a SMI read command operation. */ + ENET_StartSMIRead((ENET_Type *)(bus_obj->hw_obj), addr, reg, kENET_MiiReadValidFrame); + + /* Wait for MII complete. */ + for (counter = PHY_TIMEOUT_COUNT; counter > 0; counter--) + { + if (ENET_GetInterruptStatus((ENET_Type *)(bus_obj->hw_obj)) & ENET_EIR_MII_MASK) + { + break; + } + } + + /* Check for timeout. */ + if (!counter) + { + // return kStatus_PHY_SMIVisitTimeout; + return 0; + } + + /* Get data from MII register. */ + *data_ptr = ENET_ReadSMIData((ENET_Type *)(bus_obj->hw_obj)); + + /* Clear MII interrupt event. */ + ENET_ClearInterruptStatus((ENET_Type *)bus_obj->hw_obj, ENET_EIR_MII_MASK); + + return 4; +} + + +static rt_size_t rt_hw_mdio_write(void *bus, rt_uint32_t addr, rt_uint32_t reg, void *data, rt_uint32_t size) +{ + struct rt_mdio_bus *bus_obj = (struct rt_mdio_bus *)bus; + uint32_t counter; + rt_uint32_t *data_ptr = (rt_uint32_t *)data; + + if (4 != size) + { + return 0; + } + + /* Clear the SMI interrupt event. */ + ENET_ClearInterruptStatus((ENET_Type *)(bus_obj->hw_obj), ENET_EIR_MII_MASK); + + /* Starts a SMI write command. */ + ENET_StartSMIWrite((ENET_Type *)(bus_obj->hw_obj), addr, reg, kENET_MiiWriteValidFrame, *data_ptr); + + /* Wait for SMI complete. */ + for (counter = PHY_TIMEOUT_COUNT; counter > 0; counter--) + { + if (ENET_GetInterruptStatus((ENET_Type *)(bus_obj->hw_obj)) & ENET_EIR_MII_MASK) + { + break; + } + } + + /* Check for timeout. */ + if (!counter) + { + return 0; + } + + /* Clear MII interrupt event. */ + ENET_ClearInterruptStatus((ENET_Type *)(bus_obj->hw_obj), ENET_EIR_MII_MASK); + + return size; +} + +static struct rt_mdio_bus_ops imxrt_mdio_ops = +{ + .init = rt_hw_mdio_init, + .read = rt_hw_mdio_read, + .write = rt_hw_mdio_write, + .uninit = RT_NULL, +}; + +static rt_mdio_t mdio_bus; + +rt_mdio_t *rt_hw_mdio_register(void *hw_obj, char *name) +{ + mdio_bus.hw_obj = hw_obj; + mdio_bus.name = name; + mdio_bus.ops = &imxrt_mdio_ops; + return &mdio_bus; +} + +rt_mdio_t *rt_hw_mdio_get(void) +{ + return &mdio_bus; +} + +#endif diff --git a/bsp/imxrt/libraries/drivers/drv_mdio.h b/bsp/imxrt/libraries/drivers/drv_mdio.h new file mode 100644 index 0000000000..a1623cfc2c --- /dev/null +++ b/bsp/imxrt/libraries/drivers/drv_mdio.h @@ -0,0 +1,25 @@ + +/* + * Copyright (c) 2006-2020, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2020-09-29 WangQiang the first version + * + */ + +#ifndef DRV_MDIO_H__ +#define DRV_MDIO_H__ + +#include + +#include "fsl_enet.h" + + +rt_mdio_t *rt_hw_mdio_register(void *hw_obj, char *name); + +rt_mdio_t *rt_hw_mdio_get(void); + +#endif /*DRV_MDIO_H__*/ diff --git a/bsp/imxrt/libraries/peripherals/SConscript b/bsp/imxrt/libraries/peripherals/SConscript new file mode 100644 index 0000000000..13d040cf2b --- /dev/null +++ b/bsp/imxrt/libraries/peripherals/SConscript @@ -0,0 +1,16 @@ +from building import * + +src = [] +cwd = [] +CPPDEFINES = [] + +cwd = GetCurrentDir() + +if GetDepend('BSP_USING_PHY') and GetDepend('PHY_USING_KSZ8081'): + src += ['phyksz8081.c'] + +path = [cwd] + +group = DefineGroup('Peripherals', src, depend = [''], CPPPATH = path, CPPDEFINES=CPPDEFINES) + +Return('group') diff --git a/bsp/imxrt/libraries/peripherals/phyksz8081.c b/bsp/imxrt/libraries/peripherals/phyksz8081.c new file mode 100644 index 0000000000..88c041f4d1 --- /dev/null +++ b/bsp/imxrt/libraries/peripherals/phyksz8081.c @@ -0,0 +1,367 @@ +/* + * Copyright (c) 2015, Freescale Semiconductor, Inc. + * Copyright 2016-2017 NXP + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include + +#ifdef PHY_USING_KSZ8081 + +#include +#include "drv_gpio.h" +#include "drv_mdio.h" + + +/******************************************************************************* + * Definitions + ******************************************************************************/ + +/*! @brief Defines the PHY registers. */ +#define PHY_BASICCONTROL_REG 0x00U /*!< The PHY basic control register. */ +#define PHY_BASICSTATUS_REG 0x01U /*!< The PHY basic status register. */ +#define PHY_ID1_REG 0x02U /*!< The PHY ID one register. */ +#define PHY_ID2_REG 0x03U /*!< The PHY ID two register. */ +#define PHY_AUTONEG_ADVERTISE_REG 0x04U /*!< The PHY auto-negotiate advertise register. */ +#define PHY_CONTROL1_REG 0x1EU /*!< The PHY control one register. */ +#define PHY_CONTROL2_REG 0x1FU /*!< The PHY control two register. */ + +#define PHY_CONTROL_ID1 0x22U /*!< The PHY ID1*/ + +/*! @brief Defines the mask flag in basic control register. */ +#define PHY_BCTL_DUPLEX_MASK 0x0100U /*!< The PHY duplex bit mask. */ +#define PHY_BCTL_RESTART_AUTONEG_MASK 0x0200U /*!< The PHY restart auto negotiation mask. */ +#define PHY_BCTL_AUTONEG_MASK 0x1000U /*!< The PHY auto negotiation bit mask. */ +#define PHY_BCTL_SPEED_MASK 0x2000U /*!< The PHY speed bit mask. */ +#define PHY_BCTL_LOOP_MASK 0x4000U /*!< The PHY loop bit mask. */ +#define PHY_BCTL_RESET_MASK 0x8000U /*!< The PHY reset bit mask. */ +#define PHY_BCTL_SPEED_100M_MASK 0x2000U /*!< The PHY 100M speed mask. */ + +/*!@brief Defines the mask flag of operation mode in control two register*/ +#define PHY_CTL2_REMOTELOOP_MASK 0x0004U /*!< The PHY remote loopback mask. */ +#define PHY_CTL2_REFCLK_SELECT_MASK 0x0080U /*!< The PHY RMII reference clock select. */ +#define PHY_CTL1_10HALFDUPLEX_MASK 0x0001U /*!< The PHY 10M half duplex mask. */ +#define PHY_CTL1_100HALFDUPLEX_MASK 0x0002U /*!< The PHY 100M half duplex mask. */ +#define PHY_CTL1_10FULLDUPLEX_MASK 0x0005U /*!< The PHY 10M full duplex mask. */ +#define PHY_CTL1_100FULLDUPLEX_MASK 0x0006U /*!< The PHY 100M full duplex mask. */ +#define PHY_CTL1_SPEEDUPLX_MASK 0x0007U /*!< The PHY speed and duplex mask. */ +#define PHY_CTL1_ENERGYDETECT_MASK 0x10U /*!< The PHY signal present on rx differential pair. */ +#define PHY_CTL1_LINKUP_MASK 0x100U /*!< The PHY link up. */ +#define PHY_LINK_READY_MASK (PHY_CTL1_ENERGYDETECT_MASK | PHY_CTL1_LINKUP_MASK) + +/*! @brief Defines the mask flag in basic status register. */ +#define PHY_BSTATUS_LINKSTATUS_MASK 0x0004U /*!< The PHY link status mask. */ +#define PHY_BSTATUS_AUTONEGABLE_MASK 0x0008U /*!< The PHY auto-negotiation ability mask. */ +#define PHY_BSTATUS_AUTONEGCOMP_MASK 0x0020U /*!< The PHY auto-negotiation complete mask. */ + +/*! @brief Defines the mask flag in PHY auto-negotiation advertise register. */ +#define PHY_100BaseT4_ABILITY_MASK 0x200U /*!< The PHY have the T4 ability. */ +#define PHY_100BASETX_FULLDUPLEX_MASK 0x100U /*!< The PHY has the 100M full duplex ability.*/ +#define PHY_100BASETX_HALFDUPLEX_MASK 0x080U /*!< The PHY has the 100M full duplex ability.*/ +#define PHY_10BASETX_FULLDUPLEX_MASK 0x040U /*!< The PHY has the 10M full duplex ability.*/ +#define PHY_10BASETX_HALFDUPLEX_MASK 0x020U /*!< The PHY has the 10M full duplex ability.*/ + + + +/*! @brief Defines the timeout macro. */ +#define PHY_TIMEOUT_COUNT 0x3FFFFFFU + +/* defined the Reset pin, PORT and PIN config by menuconfig */ +#define RESET_PIN GET_PIN(PHY_RESET_PORT, PHY_RESET_PIN) + +/******************************************************************************* + * Prototypes + ******************************************************************************/ + + +/******************************************************************************* + * Variables + ******************************************************************************/ +static struct rt_phy_device phy_ksz8081; + +/******************************************************************************* + * Code + ******************************************************************************/ + + + +static inline rt_bool_t read_reg(rt_mdio_t *bus, rt_uint32_t addr, rt_uint32_t reg_id, rt_uint32_t *value) +{ + if (4 != bus->ops->read(bus, addr, reg_id, value, 4)) + { + return RT_FALSE; + } + return RT_TRUE; +} + +static inline rt_bool_t write_reg(rt_mdio_t *bus, rt_uint32_t addr, rt_uint32_t reg_id, rt_uint32_t value) +{ + if (4 != bus->ops->write(bus, addr, reg_id, &value, 4)) + { + return RT_FALSE; + } + return RT_TRUE; +} + +static rt_phy_status rt_phy_init(void *object, rt_uint32_t phy_addr, rt_uint32_t src_clock_hz) +{ + rt_bool_t ret; + rt_phy_status result; + rt_uint32_t counter = PHY_TIMEOUT_COUNT; + rt_uint32_t id_reg = 0; + rt_uint32_t time_delay; + rt_uint32_t bss_reg; + rt_uint32_t ctl_reg = 0; + + // reset phy device by gpio + rt_pin_mode(RESET_PIN, PIN_MODE_OUTPUT); + rt_pin_write(RESET_PIN, PIN_LOW); + rt_thread_mdelay(100); + rt_pin_write(RESET_PIN, PIN_HIGH); + + rt_mdio_t *mdio_bus = rt_hw_mdio_register(object, "phy_mdio"); + if (RT_NULL == mdio_bus) + { + return PHY_STATUS_FAIL; + } + phy_ksz8081.bus = mdio_bus; + phy_ksz8081.addr = phy_addr; + ret = mdio_bus->ops->init(mdio_bus, src_clock_hz); + if ( !ret ) + { + return PHY_STATUS_FAIL; + } + + /* Initialization after PHY stars to work. */ + while ((id_reg != PHY_CONTROL_ID1) && (counter != 0)) + { + phy_ksz8081.ops->read(PHY_ID1_REG, &id_reg); + counter--; + } + + if (!counter) + { + return PHY_STATUS_FAIL; + } + + /* Reset PHY. */ + counter = PHY_TIMEOUT_COUNT; + result = phy_ksz8081.ops->write(PHY_BASICCONTROL_REG, PHY_BCTL_RESET_MASK); + if (PHY_STATUS_OK == result) + { + #if defined(FSL_FEATURE_PHYKSZ8081_USE_RMII50M_MODE) + rt_uint32_t data = 0; + result = phy_ksz8081.ops->read(PHY_CONTROL2_REG, &data); + if (PHY_STATUS_FAIL == result) + { + return PHY_STATUS_FAIL; + } + result = phy_ksz8081.ops->write(PHY_CONTROL2_REG, (data | PHY_CTL2_REFCLK_SELECT_MASK)); + if (PHY_STATUS_FAIL == result) + { + return PHY_STATUS_FAIL; + } + #endif /* FSL_FEATURE_PHYKSZ8081_USE_RMII50M_MODE */ + + /* Set the negotiation. */ + result = phy_ksz8081.ops->write(PHY_AUTONEG_ADVERTISE_REG, + (PHY_100BASETX_FULLDUPLEX_MASK | PHY_100BASETX_HALFDUPLEX_MASK | + PHY_10BASETX_FULLDUPLEX_MASK | PHY_10BASETX_HALFDUPLEX_MASK | 0x1U)); + if (PHY_STATUS_OK == result) + { + result = phy_ksz8081.ops->write(PHY_BASICCONTROL_REG, (PHY_BCTL_AUTONEG_MASK | PHY_BCTL_RESTART_AUTONEG_MASK)); + if (PHY_STATUS_OK == result) + { + /* Check auto negotiation complete. */ + while (counter--) + { + result = phy_ksz8081.ops->read(PHY_BASICSTATUS_REG, &bss_reg); + if (PHY_STATUS_OK == result) + { + phy_ksz8081.ops->read(PHY_CONTROL1_REG, &ctl_reg); + if (((bss_reg & PHY_BSTATUS_AUTONEGCOMP_MASK) != 0) && (ctl_reg & PHY_LINK_READY_MASK)) + { + /* Wait a moment for Phy status stable. */ + for (time_delay = 0; time_delay < PHY_TIMEOUT_COUNT; time_delay++) + { + __ASM("nop"); + } + break; + } + } + + if (!counter) + { + return PHY_STATUS_FAIL; + } + } + } + } + } + + return PHY_STATUS_OK; +} + + +static rt_phy_status rt_phy_read(rt_uint32_t reg, rt_uint32_t *data) +{ + rt_mdio_t *mdio_bus = phy_ksz8081.bus; + rt_uint32_t device_id = phy_ksz8081.addr; + + if (read_reg(mdio_bus, device_id, reg, data)) + { + return PHY_STATUS_OK; + } + return PHY_STATUS_FAIL; +} + +static rt_phy_status rt_phy_write(rt_uint32_t reg, rt_uint32_t data) +{ + rt_mdio_t *mdio_bus = phy_ksz8081.bus; + rt_uint32_t device_id = phy_ksz8081.addr; + + if (write_reg(mdio_bus, device_id, reg, data)) + { + return PHY_STATUS_OK; + } + return PHY_STATUS_FAIL; +} + +static rt_phy_status rt_phy_loopback(rt_uint32_t mode, rt_uint32_t speed, rt_bool_t enable) +{ + rt_uint32_t data = 0; + rt_phy_status result; + + /* Set the loop mode. */ + if (enable) + { + if (PHY_LOCAL_LOOP == mode) + { + if (PHY_SPEED_100M == speed) + { + data = PHY_BCTL_SPEED_100M_MASK | PHY_BCTL_DUPLEX_MASK | PHY_BCTL_LOOP_MASK; + } + else + { + data = PHY_BCTL_DUPLEX_MASK | PHY_BCTL_LOOP_MASK; + } + return phy_ksz8081.ops->write(PHY_BASICCONTROL_REG, data); + } + else + { + /* First read the current status in control register. */ + result = phy_ksz8081.ops->read(PHY_CONTROL2_REG, &data); + if (PHY_STATUS_OK == result) + { + return phy_ksz8081.ops->write(PHY_CONTROL2_REG, (data | PHY_CTL2_REMOTELOOP_MASK)); + } + } + } + else + { + /* Disable the loop mode. */ + if (PHY_LOCAL_LOOP == mode) + { + /* First read the current status in control register. */ + result = phy_ksz8081.ops->read(PHY_BASICCONTROL_REG, &data); + if (PHY_STATUS_OK == result) + { + data &= ~PHY_BCTL_LOOP_MASK; + return phy_ksz8081.ops->write(PHY_BASICCONTROL_REG, (data | PHY_BCTL_RESTART_AUTONEG_MASK)); + } + } + else + { + /* First read the current status in control one register. */ + result = phy_ksz8081.ops->read(PHY_CONTROL2_REG, &data); + if (PHY_STATUS_OK == result) + { + return phy_ksz8081.ops->write(PHY_CONTROL2_REG, (data & ~PHY_CTL2_REMOTELOOP_MASK)); + } + } + } + return result; +} + +static rt_phy_status get_link_status(rt_bool_t *status) +{ + rt_phy_status result; + rt_uint32_t data; + + /* Read the basic status register. */ + result = phy_ksz8081.ops->read(PHY_BASICSTATUS_REG, &data); + if (PHY_STATUS_OK == result) + { + if (!(PHY_BSTATUS_LINKSTATUS_MASK & data)) + { + /* link down. */ + *status = RT_FALSE; + } + else + { + /* link up. */ + *status = RT_TRUE; + } + } + return result; +} +static rt_phy_status get_link_speed_duplex(rt_uint32_t *speed, rt_uint32_t *duplex) +{ + rt_phy_status result = PHY_STATUS_OK; + rt_uint32_t data, ctl_reg; + + /* Read the control two register. */ + result = phy_ksz8081.ops->read(PHY_CONTROL1_REG, &ctl_reg); + if (PHY_STATUS_OK == result) + { + data = ctl_reg & PHY_CTL1_SPEEDUPLX_MASK; + if ((PHY_CTL1_10FULLDUPLEX_MASK == data) || (PHY_CTL1_100FULLDUPLEX_MASK == data)) + { + /* Full duplex. */ + *duplex = PHY_FULL_DUPLEX; + } + else + { + /* Half duplex. */ + *duplex = PHY_HALF_DUPLEX; + } + + data = ctl_reg & PHY_CTL1_SPEEDUPLX_MASK; + if ((PHY_CTL1_100HALFDUPLEX_MASK == data) || (PHY_CTL1_100FULLDUPLEX_MASK == data)) + { + /* 100M speed. */ + *speed = PHY_SPEED_100M; + } + else + { /* 10M speed. */ + *speed = PHY_SPEED_10M; + } + } + + return result; +} + +static struct rt_phy_ops phy_ops = +{ + .init = rt_phy_init, + .read = rt_phy_read, + .write = rt_phy_write, + .loopback = rt_phy_loopback, + .get_link_status = get_link_status, + .get_link_speed_duplex = get_link_speed_duplex, +}; + +static int rt_phy_ksz8081_register( void ) +{ + phy_ksz8081.ops = &phy_ops; + rt_hw_phy_register(&phy_ksz8081, "rtt-phy"); + return 1; +} + +INIT_DEVICE_EXPORT(rt_phy_ksz8081_register); + + + +#endif /* PHY_USING_KSZ8081 */ diff --git a/bsp/imxrt/tools/sdk_dist.py b/bsp/imxrt/tools/sdk_dist.py index 89b7da4356..b663628504 100644 --- a/bsp/imxrt/tools/sdk_dist.py +++ b/bsp/imxrt/tools/sdk_dist.py @@ -21,3 +21,6 @@ def dist_do_building(BSP_ROOT, dist_dir=None): print("=> copy bsp drivers") bsp_copy_files(os.path.join(library_path, 'drivers'), os.path.join(library_dir, 'drivers')) shutil.copyfile(os.path.join(library_path, 'Kconfig'), os.path.join(library_dir, 'Kconfig')) + + print("=> copy bsp peripherals") + bsp_copy_files(os.path.join(library_path, 'peripherals'), os.path.join(library_dir, 'peripherals')) diff --git a/components/drivers/Kconfig b/components/drivers/Kconfig index 457b8751fe..db4455160e 100755 --- a/components/drivers/Kconfig +++ b/components/drivers/Kconfig @@ -103,6 +103,10 @@ if RT_USING_I2C endif endif +config RT_USING_PHY + bool "Using ethernet phy device drivers" + default n + config RT_USING_PIN bool "Using generic GPIO device drivers" default y diff --git a/components/drivers/include/drivers/phy.h b/components/drivers/include/drivers/phy.h new file mode 100644 index 0000000000..9a9eaeb5dd --- /dev/null +++ b/components/drivers/include/drivers/phy.h @@ -0,0 +1,79 @@ + + +#ifndef __PHY_H___ +#define __PHY_H___ + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +/* Defines the PHY link speed. This is align with the speed for MAC. */ +enum phy_speed +{ + PHY_SPEED_10M = 0U, /* PHY 10M speed. */ + PHY_SPEED_100M /* PHY 100M speed. */ +}; + +/* Defines the PHY link duplex. */ +enum phy_duplex +{ + PHY_HALF_DUPLEX = 0U, /* PHY half duplex. */ + PHY_FULL_DUPLEX /* PHY full duplex. */ +}; + +/*! @brief Defines the PHY loopback mode. */ +enum phy_loop +{ + PHY_LOCAL_LOOP = 0U, /* PHY local loopback. */ + PHY_REMOTE_LOOP /* PHY remote loopback. */ +}; + + +struct rt_phy_msg +{ + rt_uint32_t reg; + rt_uint32_t value; +}; + +typedef struct rt_phy_msg rt_phy_msg_t; + + +struct rt_phy_device +{ + struct rt_device parent; + struct rt_mdio_bus *bus; + rt_uint32_t addr; + struct rt_phy_ops *ops; +}; + +typedef struct rt_phy_device rt_phy_t; + + +enum { + PHY_STATUS_OK = 0, + PHY_STATUS_FAIL, + PHY_STATUS_TIMEOUT, +}; + +typedef rt_int32_t rt_phy_status; + +struct rt_phy_ops +{ + rt_phy_status (*init)(void *object, rt_uint32_t phy_addr, rt_uint32_t src_clock_hz); + rt_phy_status (*read)(rt_uint32_t reg, rt_uint32_t *data); + rt_phy_status (*write)(rt_uint32_t reg, rt_uint32_t data); + rt_phy_status (*loopback)(rt_uint32_t mode, rt_uint32_t speed, rt_bool_t enable); + rt_phy_status (*get_link_status)(rt_bool_t *status); + rt_phy_status (*get_link_speed_duplex)(rt_uint32_t *speed, rt_uint32_t *duplex); +}; + +rt_err_t rt_hw_phy_register(struct rt_phy_device *phy, const char *name); + +#ifdef __cplusplus +} +#endif + +#endif /* __PHY_H__*/ diff --git a/components/drivers/include/drivers/phy_mdio.h b/components/drivers/include/drivers/phy_mdio.h new file mode 100644 index 0000000000..a4a79f6e7a --- /dev/null +++ b/components/drivers/include/drivers/phy_mdio.h @@ -0,0 +1,35 @@ + + +#ifndef __MDIO_H___ +#define __MDIO_H___ + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + +struct rt_mdio_bus_ops +{ + rt_bool_t (*init)(void *bus, rt_uint32_t src_clock_hz); + rt_size_t (*read)(void *bus, rt_uint32_t addr, rt_uint32_t reg, void *data, rt_uint32_t size); + rt_size_t (*write)(void *bus, rt_uint32_t addr, rt_uint32_t reg, void *data, rt_uint32_t size); + rt_bool_t (*uninit)(void *bus); +}; + +struct rt_mdio_bus +{ + void *hw_obj; + char *name; + struct rt_mdio_bus_ops *ops; +}; + +typedef struct rt_mdio_bus rt_mdio_t; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/components/drivers/include/rtdevice.h b/components/drivers/include/rtdevice.h index f54290097c..f0fa2f5b4a 100644 --- a/components/drivers/include/rtdevice.h +++ b/components/drivers/include/rtdevice.h @@ -69,6 +69,11 @@ extern "C" { #endif /* RT_USING_I2C_BITOPS */ #endif /* RT_USING_I2C */ +#ifdef RT_USING_PHY +#include "drivers/phy.h" +#include "drivers/phy_mdio.h" +#endif /* RT_USING_PHY */ + #ifdef RT_USING_SDIO #include "drivers/mmcsd_core.h" #include "drivers/sd.h" diff --git a/components/drivers/phy/SConscript b/components/drivers/phy/SConscript new file mode 100644 index 0000000000..ec12ed24c2 --- /dev/null +++ b/components/drivers/phy/SConscript @@ -0,0 +1,8 @@ +from building import * + +cwd = GetCurrentDir() +src = Glob('*.c') +CPPPATH = [cwd + '/../include'] +group = DefineGroup('DeviceDrivers', src, depend = ['RT_USING_PHY'], CPPPATH = CPPPATH) + +Return('group') diff --git a/components/drivers/phy/phy.c b/components/drivers/phy/phy.c new file mode 100644 index 0000000000..3ed4a1a265 --- /dev/null +++ b/components/drivers/phy/phy.c @@ -0,0 +1,78 @@ + +/* + * Copyright (c) 2006-2020, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2020-09-27 wangqiang first version + */ + +#include +#include +#include + +#define DBG_TAG "PHY" +#define DBG_LVL DBG_INFO +#include + + +static rt_size_t phy_device_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t count) +{ + struct rt_phy_device *phy = (struct rt_phy_device *)dev->user_data; + struct rt_phy_msg *msg = (struct rt_phy_msg *)buffer; + return phy->bus->ops->read(phy->bus, phy->addr, msg->reg, &(msg->value), 4); +} +static rt_size_t phy_device_write(rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t count) +{ + struct rt_phy_device *phy = (struct rt_phy_device *)dev->user_data; + struct rt_phy_msg *msg = (struct rt_phy_msg *)buffer; + return phy->bus->ops->write(phy->bus, phy->addr, msg->reg, &(msg->value), 4); +} + + + +#ifdef RT_USING_DEVICE_OPS +const static struct rt_device_ops phy_ops = +{ + RT_NULL, + RT_NULL, + RT_NULL, + phy_device_read, + phy_device_write, + RT_NULL, +}; +#endif + +/* +* phy device register +*/ +rt_err_t rt_hw_phy_register(struct rt_phy_device *phy, const char *name) +{ + rt_err_t ret; + struct rt_device *device; + + device = &(phy->parent); + + device->type = RT_Device_Class_PHY; + device->rx_indicate = RT_NULL; + device->tx_complete = RT_NULL; + +#ifdef RT_USING_DEVICE_OPS + device->ops = phy_ops; +#else + device->init = NULL; + device->open = NULL; + device->close = NULL; + device->read = phy_device_read; + device->write = phy_device_write; + device->control = NULL; +#endif + device->user_data = phy; + + /* register a character device */ + ret = rt_device_register(device, name, RT_DEVICE_FLAG_RDWR); + + return ret; +} diff --git a/components/finsh/cmd.c b/components/finsh/cmd.c index d764ea4231..afbda59e90 100644 --- a/components/finsh/cmd.c +++ b/components/finsh/cmd.c @@ -821,6 +821,7 @@ static char *const device_type_str[] = "Miscellaneous Device", "Sensor Device", "Touch Device", + "Phy Device", "Unknown" }; diff --git a/include/rtdef.h b/include/rtdef.h index 5543b80ab7..100cd5c2d6 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -863,6 +863,7 @@ enum rt_device_class_type RT_Device_Class_Miscellaneous, /**< Miscellaneous device */ RT_Device_Class_Sensor, /**< Sensor device */ RT_Device_Class_Touch, /**< Touch device */ + RT_Device_Class_PHY, /**< PHY device */ RT_Device_Class_Unknown /**< unknown device */ }; -- cgit v1.3.1 From 98f0cfbf6e37a072ddf3aa2ae6a600c5dee964aa Mon Sep 17 00:00:00 2001 From: mysterywolf <920369182@qq.com> Date: Fri, 23 Oct 2020 01:04:06 +0800 Subject: define maximum value of ipc type --- include/rtdef.h | 8 ++++++++ src/ipc.c | 16 ++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/rtdef.h b/include/rtdef.h index 5543b80ab7..0690371c6d 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -33,6 +33,7 @@ * 2019-05-17 Bernard change version number to v4.0.2 * 2019-12-20 Bernard change version number to v4.0.3 * 2020-08-10 Meco Man add macro for struct rt_device_ops + * 2020-10-23 Meco Man define maximum value of ipc type */ #ifndef __RT_DEF_H__ @@ -102,6 +103,13 @@ typedef rt_base_t rt_off_t; /**< Type for offset */ #define RT_UINT32_MAX 0xffffffff /**< Maxium number of UINT32 */ #define RT_TICK_MAX RT_UINT32_MAX /**< Maxium number of tick */ +/* maximum value of ipc type */ +#define RT_SEM_VALUE_MAX RT_UINT16_MAX /**< Maxium number of semaphore .value */ +#define RT_MUTEX_VALUE_MAX RT_UINT16_MAX /**< Maxium number of mutex .value */ +#define RT_MUTEX_HOLD_MAX RT_UINT8_MAX /**< Maxium number of mutex .hold */ +#define RT_MB_ENTRY_MAX RT_UINT16_MAX /**< Maxium number of mailbox .entry */ +#define RT_MQ_ENTRY_MAX RT_UINT16_MAX /**< Maxium number of message queue .entry */ + #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) #define __CLANG_ARM #endif diff --git a/src/ipc.c b/src/ipc.c index 9cd2b8846d..454fcb5439 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -465,7 +465,7 @@ rt_err_t rt_sem_release(rt_sem_t sem) } else { - if(sem->value < 65535u) + if(sem->value < RT_SEM_VALUE_MAX) { sem->value ++; /* increase value */ } @@ -696,7 +696,7 @@ rt_err_t rt_mutex_take(rt_mutex_t mutex, rt_int32_t time) if (mutex->owner == thread) { - if(mutex->hold < 255u) + if(mutex->hold < RT_MUTEX_HOLD_MAX) { /* it's the same thread */ mutex->hold ++; @@ -723,7 +723,7 @@ __again: /* set mutex owner and original priority */ mutex->owner = thread; mutex->original_priority = thread->current_priority; - if(mutex->hold < 255u) + if(mutex->hold < RT_MUTEX_HOLD_MAX) { mutex->hold ++; } @@ -888,7 +888,7 @@ rt_err_t rt_mutex_release(rt_mutex_t mutex) /* set new owner and priority */ mutex->owner = thread; mutex->original_priority = thread->current_priority; - if(mutex->hold < 255u) + if(mutex->hold < RT_MUTEX_HOLD_MAX) { mutex->hold ++; } @@ -905,7 +905,7 @@ rt_err_t rt_mutex_release(rt_mutex_t mutex) } else { - if(mutex->value < 65535u) + if(mutex->value < RT_MUTEX_VALUE_MAX) { /* increase value */ mutex->value ++; @@ -1607,7 +1607,7 @@ rt_err_t rt_mb_send_wait(rt_mailbox_t mb, if (mb->in_offset >= mb->size) mb->in_offset = 0; - if(mb->entry < 65535u) + if(mb->entry < RT_MB_ENTRY_MAX) { /* increase message entry */ mb->entry ++; @@ -2179,7 +2179,7 @@ rt_err_t rt_mq_send_wait(rt_mq_t mq, if (mq->msg_queue_head == RT_NULL) mq->msg_queue_head = msg; - if(mq->entry < 65535u) + if(mq->entry < RT_MQ_ENTRY_MAX) { /* increase message entry */ mq->entry ++; @@ -2287,7 +2287,7 @@ rt_err_t rt_mq_urgent(rt_mq_t mq, const void *buffer, rt_size_t size) if (mq->msg_queue_tail == RT_NULL) mq->msg_queue_tail = msg; - if(mq->entry < 65535u) + if(mq->entry < RT_MQ_ENTRY_MAX) { /* increase message entry */ mq->entry ++; -- cgit v1.3.1 From a22decb71ba92fdd879914be50809c97f0defb07 Mon Sep 17 00:00:00 2001 From: guozhanxin Date: Mon, 23 Nov 2020 11:36:04 +0800 Subject: 【优化】在代码中移除 rt_system_object_init/rt_system_tick_init 的调用。 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bsp/CME_M7/applications/startup.c | 6 ------ bsp/avr32uc3b0/startup.c | 2 -- bsp/bf533/startup.c | 6 ------ bsp/efm32/startup.c | 6 ------ bsp/fh8620/platform/fh8620/iot_cam/startup.c | 6 ------ bsp/frdm-k64f/applications/startup.c | 6 ------ bsp/gkipc/armv6/rtos_lib.c | 5 ----- bsp/lm3s8962/applications/startup.c | 6 ------ bsp/lm3s9b9x/applications/startup.c | 6 ------ bsp/lm4f232/applications/startup.c | 6 ------ bsp/lpc2148/applications/startup.c | 6 ------ bsp/lpc2478/applications/startup.c | 6 ------ bsp/lpc5410x/applications/startup.c | 6 ------ bsp/lpc824/applications/startup.c | 6 ------ bsp/m16c62p/applications/startup.c | 8 +------- bsp/mb9bf500r/startup.c | 6 ------ bsp/microblaze/startup.c | 6 ------ bsp/mini4020/applications/startup.c | 6 ------ bsp/nios_ii/startup.c | 6 ------ bsp/nrf51822/applications/startup.c | 6 ------ bsp/nrf52832/applications/startup.c | 6 ------ bsp/nrf5x/libraries/templates/nrf52x/applications/startup.c | 6 ------ bsp/pic32ethernet/startup.c | 6 ------ bsp/rm48x50/application/startup.c | 6 ------ bsp/sam7x/applications/startup.c | 6 ------ bsp/samd21/applications/startup.c | 6 ------ bsp/sep6200/application/startup.c | 6 ------ bsp/simulator/applications/startup.c | 6 ------ bsp/stm32f20x/applications/startup.c | 6 ------ bsp/taihu/applications/startup.c | 3 --- bsp/tms320f28379d/applications/startup.c | 6 ------ bsp/upd70f3454/applications/startup.c | 8 +------- bsp/wh44b0/startup.c | 6 ------ bsp/x86/applications/startup.c | 6 ------ documentation/doxygen/systeminit.h | 6 ------ include/rtthread.h | 2 -- src/clock.c | 11 ----------- src/object.c | 12 ------------ 38 files changed, 2 insertions(+), 229 deletions(-) (limited to 'include') diff --git a/bsp/CME_M7/applications/startup.c b/bsp/CME_M7/applications/startup.c index edff582d1f..44f439690b 100644 --- a/bsp/CME_M7/applications/startup.c +++ b/bsp/CME_M7/applications/startup.c @@ -47,12 +47,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/avr32uc3b0/startup.c b/bsp/avr32uc3b0/startup.c index 6f1a3d3ada..0411b5d1ce 100644 --- a/bsp/avr32uc3b0/startup.c +++ b/bsp/avr32uc3b0/startup.c @@ -30,8 +30,6 @@ int main(void) #endif rt_hw_board_init(); - rt_system_tick_init(); - rt_system_object_init(); rt_system_timer_init(); #ifdef RT_USING_HEAP diff --git a/bsp/bf533/startup.c b/bsp/bf533/startup.c index 8f1b83912a..7d90dd2493 100644 --- a/bsp/bf533/startup.c +++ b/bsp/bf533/startup.c @@ -35,12 +35,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/efm32/startup.c b/bsp/efm32/startup.c index f997c6aadd..9a70f1278a 100644 --- a/bsp/efm32/startup.c +++ b/bsp/efm32/startup.c @@ -102,12 +102,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/fh8620/platform/fh8620/iot_cam/startup.c b/bsp/fh8620/platform/fh8620/iot_cam/startup.c index 52c4775da5..6f5cd6defa 100644 --- a/bsp/fh8620/platform/fh8620/iot_cam/startup.c +++ b/bsp/fh8620/platform/fh8620/iot_cam/startup.c @@ -93,12 +93,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* initialize tick */ - rt_system_tick_init(); - - /* initialize kernel object */ - rt_system_object_init(); - /* initialize timer system */ rt_system_timer_init(); diff --git a/bsp/frdm-k64f/applications/startup.c b/bsp/frdm-k64f/applications/startup.c index 3627cb993b..d16aefddb2 100644 --- a/bsp/frdm-k64f/applications/startup.c +++ b/bsp/frdm-k64f/applications/startup.c @@ -65,12 +65,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/gkipc/armv6/rtos_lib.c b/bsp/gkipc/armv6/rtos_lib.c index 7d7aec5c51..c4b4285fbe 100644 --- a/bsp/gkipc/armv6/rtos_lib.c +++ b/bsp/gkipc/armv6/rtos_lib.c @@ -1095,14 +1095,9 @@ U32 RTOS_InitKernel(U32 Heap_size) /* show version */ //rt_show_version(); - /* initialize tick */ - //rt_system_tick_init(); RTOS_HwTickInit(); //rt_kprintf("set tick\n"); - /* initialize kernel object */ - rt_system_object_init(); - /* initialize timer system */ rt_system_timer_init(); diff --git a/bsp/lm3s8962/applications/startup.c b/bsp/lm3s8962/applications/startup.c index d598ee8fc7..e78cfa7eca 100644 --- a/bsp/lm3s8962/applications/startup.c +++ b/bsp/lm3s8962/applications/startup.c @@ -77,12 +77,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/lm3s9b9x/applications/startup.c b/bsp/lm3s9b9x/applications/startup.c index 2e8ad05d7b..4d374824e7 100644 --- a/bsp/lm3s9b9x/applications/startup.c +++ b/bsp/lm3s9b9x/applications/startup.c @@ -77,12 +77,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/lm4f232/applications/startup.c b/bsp/lm4f232/applications/startup.c index e1f3b6efd1..8d9eb54611 100644 --- a/bsp/lm4f232/applications/startup.c +++ b/bsp/lm4f232/applications/startup.c @@ -77,12 +77,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/lpc2148/applications/startup.c b/bsp/lpc2148/applications/startup.c index 5b699a8613..cc16a5c12b 100644 --- a/bsp/lpc2148/applications/startup.c +++ b/bsp/lpc2148/applications/startup.c @@ -52,12 +52,6 @@ void rtthread_startup(void) /* init board */ rt_hw_board_init(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - rt_show_version(); /* init timer system */ diff --git a/bsp/lpc2478/applications/startup.c b/bsp/lpc2478/applications/startup.c index 270312f7ae..0b961e4f94 100644 --- a/bsp/lpc2478/applications/startup.c +++ b/bsp/lpc2478/applications/startup.c @@ -38,12 +38,6 @@ void rtthread_startup(void) /* init board */ rt_hw_board_init(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - rt_show_version(); /* init timer system */ diff --git a/bsp/lpc5410x/applications/startup.c b/bsp/lpc5410x/applications/startup.c index 6589dc6b46..6f4ab94e82 100644 --- a/bsp/lpc5410x/applications/startup.c +++ b/bsp/lpc5410x/applications/startup.c @@ -27,12 +27,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* initialize tick */ - rt_system_tick_init(); - - /* initialize kernel object */ - rt_system_object_init(); - /* initialize timer system */ rt_system_timer_init(); diff --git a/bsp/lpc824/applications/startup.c b/bsp/lpc824/applications/startup.c index 5e95382ba0..e165242f86 100644 --- a/bsp/lpc824/applications/startup.c +++ b/bsp/lpc824/applications/startup.c @@ -52,12 +52,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/m16c62p/applications/startup.c b/bsp/m16c62p/applications/startup.c index 95b9484c1f..1802ecadee 100644 --- a/bsp/m16c62p/applications/startup.c +++ b/bsp/m16c62p/applications/startup.c @@ -48,13 +48,7 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - + /* init timer system */ rt_system_timer_init(); diff --git a/bsp/mb9bf500r/startup.c b/bsp/mb9bf500r/startup.c index dc65496ba6..bc96eb5dca 100644 --- a/bsp/mb9bf500r/startup.c +++ b/bsp/mb9bf500r/startup.c @@ -44,12 +44,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/microblaze/startup.c b/bsp/microblaze/startup.c index b9dc03e588..c900973bb7 100755 --- a/bsp/microblaze/startup.c +++ b/bsp/microblaze/startup.c @@ -55,12 +55,6 @@ void rtthread_startup(void) rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/mini4020/applications/startup.c b/bsp/mini4020/applications/startup.c index 575bd6f306..ae84f8b461 100644 --- a/bsp/mini4020/applications/startup.c +++ b/bsp/mini4020/applications/startup.c @@ -49,12 +49,6 @@ void rtthread_startup() /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/nios_ii/startup.c b/bsp/nios_ii/startup.c index 8f2512630d..e2bbaaa996 100644 --- a/bsp/nios_ii/startup.c +++ b/bsp/nios_ii/startup.c @@ -45,12 +45,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/nrf51822/applications/startup.c b/bsp/nrf51822/applications/startup.c index 660105ee48..1e7729fc83 100644 --- a/bsp/nrf51822/applications/startup.c +++ b/bsp/nrf51822/applications/startup.c @@ -48,12 +48,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/nrf52832/applications/startup.c b/bsp/nrf52832/applications/startup.c index a48524814c..78a5ef7f65 100644 --- a/bsp/nrf52832/applications/startup.c +++ b/bsp/nrf52832/applications/startup.c @@ -48,12 +48,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/nrf5x/libraries/templates/nrf52x/applications/startup.c b/bsp/nrf5x/libraries/templates/nrf52x/applications/startup.c index a48524814c..78a5ef7f65 100644 --- a/bsp/nrf5x/libraries/templates/nrf52x/applications/startup.c +++ b/bsp/nrf5x/libraries/templates/nrf52x/applications/startup.c @@ -48,12 +48,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/pic32ethernet/startup.c b/bsp/pic32ethernet/startup.c index b841da98f3..e139dfefca 100644 --- a/bsp/pic32ethernet/startup.c +++ b/bsp/pic32ethernet/startup.c @@ -35,12 +35,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/rm48x50/application/startup.c b/bsp/rm48x50/application/startup.c index 31c2f92fa9..40b69e2c95 100644 --- a/bsp/rm48x50/application/startup.c +++ b/bsp/rm48x50/application/startup.c @@ -81,12 +81,6 @@ void rtthread_startup(void) /* init board */ rt_hw_board_init(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - rt_show_version(); /* init timer system */ diff --git a/bsp/sam7x/applications/startup.c b/bsp/sam7x/applications/startup.c index ddf194b1d1..d167d9ebcb 100644 --- a/bsp/sam7x/applications/startup.c +++ b/bsp/sam7x/applications/startup.c @@ -82,12 +82,6 @@ void rtthread_startup(void) rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/samd21/applications/startup.c b/bsp/samd21/applications/startup.c index aaa75d3f1c..ecbe617d2e 100644 --- a/bsp/samd21/applications/startup.c +++ b/bsp/samd21/applications/startup.c @@ -68,12 +68,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/sep6200/application/startup.c b/bsp/sep6200/application/startup.c index fc12985ce1..e714675699 100644 --- a/bsp/sep6200/application/startup.c +++ b/bsp/sep6200/application/startup.c @@ -63,12 +63,6 @@ void rtthread_startup() /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/simulator/applications/startup.c b/bsp/simulator/applications/startup.c index cc2144d64f..900d774844 100644 --- a/bsp/simulator/applications/startup.c +++ b/bsp/simulator/applications/startup.c @@ -47,12 +47,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/stm32f20x/applications/startup.c b/bsp/stm32f20x/applications/startup.c index 77f915cbbd..92be9bd2ce 100644 --- a/bsp/stm32f20x/applications/startup.c +++ b/bsp/stm32f20x/applications/startup.c @@ -61,12 +61,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/taihu/applications/startup.c b/bsp/taihu/applications/startup.c index f52a185495..9f7d9415b5 100644 --- a/bsp/taihu/applications/startup.c +++ b/bsp/taihu/applications/startup.c @@ -40,9 +40,6 @@ void rtthread_startup(void) rt_hw_board_init(); rt_show_version(); - /* init tick */ - rt_system_tick_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/tms320f28379d/applications/startup.c b/bsp/tms320f28379d/applications/startup.c index 301e63a00a..da5c31e237 100644 --- a/bsp/tms320f28379d/applications/startup.c +++ b/bsp/tms320f28379d/applications/startup.c @@ -50,12 +50,6 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/upd70f3454/applications/startup.c b/bsp/upd70f3454/applications/startup.c index d25ca73f28..409b3cc615 100644 --- a/bsp/upd70f3454/applications/startup.c +++ b/bsp/upd70f3454/applications/startup.c @@ -49,13 +49,7 @@ void rtthread_startup(void) /* show version */ rt_show_version(); - - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - + /* init timer system */ rt_system_timer_init(); diff --git a/bsp/wh44b0/startup.c b/bsp/wh44b0/startup.c index 4ea7a4f03d..5e62200a19 100644 --- a/bsp/wh44b0/startup.c +++ b/bsp/wh44b0/startup.c @@ -58,12 +58,6 @@ void rtthread_startup(void) rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/bsp/x86/applications/startup.c b/bsp/x86/applications/startup.c index 72a4eb0a96..475273267f 100644 --- a/bsp/x86/applications/startup.c +++ b/bsp/x86/applications/startup.c @@ -69,12 +69,6 @@ void rtthread_startup(void) rt_show_version(); - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - /* init timer system */ rt_system_timer_init(); diff --git a/documentation/doxygen/systeminit.h b/documentation/doxygen/systeminit.h index d62aca59bb..c45eda4079 100644 --- a/documentation/doxygen/systeminit.h +++ b/documentation/doxygen/systeminit.h @@ -21,12 +21,6 @@ * - show version * rt_show_version(); * - * - initialize system tick - * rt_system_tick_init(); - * - * - initialize kernel object [deprecated] - * rt_system_object_init(); - * * - initialize timer system * rt_system_timer_init(); * diff --git a/include/rtthread.h b/include/rtthread.h index a76601a3bf..27cfea19e0 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -38,7 +38,6 @@ extern "C" { /* * kernel object interface */ -void rt_system_object_init(void); struct rt_object_information * rt_object_get_information(enum rt_object_class_type type); int rt_object_get_length(enum rt_object_class_type type); @@ -74,7 +73,6 @@ void rt_object_put_sethook(void (*hook)(struct rt_object *object)); /* * clock & timer interface */ -void rt_system_tick_init(void); rt_tick_t rt_tick_get(void); void rt_tick_set(rt_tick_t tick); void rt_tick_increase(void); diff --git a/src/clock.c b/src/clock.c index a91cd829b6..9fd276cf6f 100644 --- a/src/clock.c +++ b/src/clock.c @@ -24,17 +24,6 @@ static rt_tick_t rt_tick = 0; #endif -/** - * This function will initialize system tick and set it to zero. - * @ingroup SystemInit - * - * @deprecated since 1.1.0, this function does not need to be invoked - * in the system initialization. - */ -void rt_system_tick_init(void) -{ -} - /** * @addtogroup Clock */ diff --git a/src/object.c b/src/object.c index 6866d805ca..fbd3879f67 100644 --- a/src/object.c +++ b/src/object.c @@ -191,18 +191,6 @@ void rt_object_put_sethook(void (*hook)(struct rt_object *object)) /**@}*/ #endif -/** - * @ingroup SystemInit - * - * This function will initialize system object management. - * - * @deprecated since 0.3.0, this function does not need to be invoked - * in the system initialization. - */ -void rt_system_object_init(void) -{ -} - /** * @addtogroup KernelObject */ -- cgit v1.3.1 From c2e15e003c60fd0aeb412dbc7c6deb1c1f55a0ef Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Tue, 29 Dec 2020 00:08:24 +0800 Subject: add function rt_hw_1ms_tick_get() --- bsp/stm32/libraries/HAL_Drivers/drv_common.c | 2 +- components/net/lwip-1.4.1/src/arch/sys_arch.c | 3 ++- components/net/lwip-2.0.2/src/arch/sys_arch.c | 3 ++- components/net/lwip-2.1.2/src/arch/sys_arch.c | 3 ++- include/rthw.h | 5 +++++ src/clock.c | 17 +++++++++++++++++ 6 files changed, 29 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_common.c b/bsp/stm32/libraries/HAL_Drivers/drv_common.c index f150d81fef..c6fb516b0e 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_common.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_common.c @@ -58,7 +58,7 @@ void SysTick_Handler(void) uint32_t HAL_GetTick(void) { - return rt_tick_get() * 1000 / RT_TICK_PER_SECOND; + return rt_hw_1ms_tick_get(); } void HAL_SuspendTick(void) diff --git a/components/net/lwip-1.4.1/src/arch/sys_arch.c b/components/net/lwip-1.4.1/src/arch/sys_arch.c index 2392dde2fa..0919c29e01 100644 --- a/components/net/lwip-1.4.1/src/arch/sys_arch.c +++ b/components/net/lwip-1.4.1/src/arch/sys_arch.c @@ -32,6 +32,7 @@ */ #include +#include #include "lwip/sys.h" #include "lwip/opt.h" @@ -617,7 +618,7 @@ u32_t sys_jiffies(void) u32_t sys_now(void) { - return rt_tick_get() * (1000 / RT_TICK_PER_SECOND); + return rt_hw_1ms_tick_get(); } #ifdef RT_LWIP_PPP diff --git a/components/net/lwip-2.0.2/src/arch/sys_arch.c b/components/net/lwip-2.0.2/src/arch/sys_arch.c index 40c79011ec..1404628a60 100644 --- a/components/net/lwip-2.0.2/src/arch/sys_arch.c +++ b/components/net/lwip-2.0.2/src/arch/sys_arch.c @@ -32,6 +32,7 @@ */ #include +#include #include "lwip/sys.h" #include "lwip/opt.h" @@ -627,7 +628,7 @@ u32_t sys_jiffies(void) u32_t sys_now(void) { - return rt_tick_get() * (1000 / RT_TICK_PER_SECOND); + return rt_hw_1ms_tick_get(); } diff --git a/components/net/lwip-2.1.2/src/arch/sys_arch.c b/components/net/lwip-2.1.2/src/arch/sys_arch.c index 0633501bb6..8905765440 100644 --- a/components/net/lwip-2.1.2/src/arch/sys_arch.c +++ b/components/net/lwip-2.1.2/src/arch/sys_arch.c @@ -33,6 +33,7 @@ */ #include +#include #include "lwip/sys.h" #include "lwip/opt.h" @@ -641,7 +642,7 @@ u32_t sys_jiffies(void) u32_t sys_now(void) { - return rt_tick_get() * (1000 / RT_TICK_PER_SECOND); + return rt_hw_1ms_tick_get(); } #if MEM_OVERFLOW_CHECK || MEMP_OVERFLOW_CHECK diff --git a/include/rthw.h b/include/rthw.h index 89877faf90..c3960350b8 100644 --- a/include/rthw.h +++ b/include/rthw.h @@ -134,6 +134,11 @@ void rt_hw_exception_install(rt_err_t (*exception_handle)(void *context)); */ void rt_hw_us_delay(rt_uint32_t us); +/* + * provides a tick value ALWAYS in millisecond + */ +rt_tick_t rt_hw_1ms_tick_get(void); + #ifdef RT_USING_SMP typedef union { unsigned long slock; diff --git a/src/clock.c b/src/clock.c index 9fd276cf6f..778126fb23 100644 --- a/src/clock.c +++ b/src/clock.c @@ -13,6 +13,7 @@ * 2010-07-13 Bernard fix rt_tick_from_millisecond issue found by kuronca * 2011-06-26 Bernard add rt_tick_set function. * 2018-11-22 Jesven add per cpu tick + * 2020-12-29 Meco Man add function rt_hw_1ms_tick_get() */ #include @@ -116,5 +117,21 @@ rt_tick_t rt_tick_from_millisecond(rt_int32_t ms) } RTM_EXPORT(rt_tick_from_millisecond); +/** + * This function provides a tick value ALWAYS in millisecond + * + * @return 1ms-based tick + */ +RT_WEAK rt_tick_t rt_hw_1ms_tick_get(void) +{ +#if 1000 % RT_TICK_PER_SECOND == 0 + return rt_tick_get() * (1000U / RT_TICK_PER_SECOND); +#else + #warning "rt-thread cannot provide a correct 1ms-based tick any longer,\ + please redefine this function in another file by using a high-precision hard-timer." + return 0; +#endif +} + /**@}*/ -- cgit v1.3.1 From 63cd26b0d1a876cb8d87c3d60d5591d89dfbf297 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Wed, 30 Dec 2020 16:32:20 +0800 Subject: update --- bsp/stm32/libraries/HAL_Drivers/drv_common.c | 2 +- components/net/lwip-1.4.1/src/arch/sys_arch.c | 2 +- components/net/lwip-2.0.2/src/arch/sys_arch.c | 2 +- components/net/lwip-2.1.2/src/arch/sys_arch.c | 2 +- include/rthw.h | 5 ----- include/rtthread.h | 1 + src/clock.c | 10 +++++----- 7 files changed, 10 insertions(+), 14 deletions(-) (limited to 'include') diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_common.c b/bsp/stm32/libraries/HAL_Drivers/drv_common.c index c6fb516b0e..d868d63dfc 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_common.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_common.c @@ -58,7 +58,7 @@ void SysTick_Handler(void) uint32_t HAL_GetTick(void) { - return rt_hw_1ms_tick_get(); + return rt_tick_get_millisecond(); } void HAL_SuspendTick(void) diff --git a/components/net/lwip-1.4.1/src/arch/sys_arch.c b/components/net/lwip-1.4.1/src/arch/sys_arch.c index 0919c29e01..2f6dbb4143 100644 --- a/components/net/lwip-1.4.1/src/arch/sys_arch.c +++ b/components/net/lwip-1.4.1/src/arch/sys_arch.c @@ -618,7 +618,7 @@ u32_t sys_jiffies(void) u32_t sys_now(void) { - return rt_hw_1ms_tick_get(); + return rt_tick_get_millisecond(); } #ifdef RT_LWIP_PPP diff --git a/components/net/lwip-2.0.2/src/arch/sys_arch.c b/components/net/lwip-2.0.2/src/arch/sys_arch.c index 1404628a60..fbf02cad0a 100644 --- a/components/net/lwip-2.0.2/src/arch/sys_arch.c +++ b/components/net/lwip-2.0.2/src/arch/sys_arch.c @@ -628,7 +628,7 @@ u32_t sys_jiffies(void) u32_t sys_now(void) { - return rt_hw_1ms_tick_get(); + return rt_tick_get_millisecond(); } diff --git a/components/net/lwip-2.1.2/src/arch/sys_arch.c b/components/net/lwip-2.1.2/src/arch/sys_arch.c index 8905765440..a0eeed1073 100644 --- a/components/net/lwip-2.1.2/src/arch/sys_arch.c +++ b/components/net/lwip-2.1.2/src/arch/sys_arch.c @@ -642,7 +642,7 @@ u32_t sys_jiffies(void) u32_t sys_now(void) { - return rt_hw_1ms_tick_get(); + return rt_tick_get_millisecond(); } #if MEM_OVERFLOW_CHECK || MEMP_OVERFLOW_CHECK diff --git a/include/rthw.h b/include/rthw.h index c3960350b8..89877faf90 100644 --- a/include/rthw.h +++ b/include/rthw.h @@ -134,11 +134,6 @@ void rt_hw_exception_install(rt_err_t (*exception_handle)(void *context)); */ void rt_hw_us_delay(rt_uint32_t us); -/* - * provides a tick value ALWAYS in millisecond - */ -rt_tick_t rt_hw_1ms_tick_get(void); - #ifdef RT_USING_SMP typedef union { unsigned long slock; diff --git a/include/rtthread.h b/include/rtthread.h index 27cfea19e0..1e0094e73b 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -77,6 +77,7 @@ rt_tick_t rt_tick_get(void); void rt_tick_set(rt_tick_t tick); void rt_tick_increase(void); rt_tick_t rt_tick_from_millisecond(rt_int32_t ms); +rt_tick_t rt_tick_get_millisecond(void); void rt_system_timer_init(void); void rt_system_timer_thread_init(void); diff --git a/src/clock.c b/src/clock.c index 778126fb23..24456fb23d 100644 --- a/src/clock.c +++ b/src/clock.c @@ -118,14 +118,14 @@ rt_tick_t rt_tick_from_millisecond(rt_int32_t ms) RTM_EXPORT(rt_tick_from_millisecond); /** - * This function provides a tick value ALWAYS in millisecond + * This function will provide the passed millisecond from boot. * - * @return 1ms-based tick + * @return passed millisecond from boot */ -RT_WEAK rt_tick_t rt_hw_1ms_tick_get(void) +RT_WEAK rt_tick_t rt_tick_get_millisecond(void) { -#if 1000 % RT_TICK_PER_SECOND == 0 - return rt_tick_get() * (1000U / RT_TICK_PER_SECOND); +#if 1000 % RT_TICK_PER_SECOND == 0u + return rt_tick_get() * (1000u / RT_TICK_PER_SECOND); #else #warning "rt-thread cannot provide a correct 1ms-based tick any longer,\ please redefine this function in another file by using a high-precision hard-timer." -- cgit v1.3.1 From 11fc8d27c1c955fbaedfb3efd14fb72122c1cdbf Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Fri, 1 Jan 2021 17:00:52 +0800 Subject: re-format libc_ioctl.h --- include/libc/libc_ioctl.h | 165 +++++++++++++++++++++++----------------------- 1 file changed, 82 insertions(+), 83 deletions(-) (limited to 'include') diff --git a/include/libc/libc_ioctl.h b/include/libc/libc_ioctl.h index 42a21a2cea..812a119507 100644 --- a/include/libc/libc_ioctl.h +++ b/include/libc/libc_ioctl.h @@ -28,99 +28,99 @@ * in send queue. */ #endif -#define TCGETS 0x5401 -#define TCSETS 0x5402 -#define TCSETSW 0x5403 -#define TCSETSF 0x5404 -#define TCGETA 0x5405 -#define TCSETA 0x5406 -#define TCSETAW 0x5407 -#define TCSETAF 0x5408 -#define TCSBRK 0x5409 -#define TCXONC 0x540A -#define TCFLSH 0x540B -#define TIOCEXCL 0x540C -#define TIOCNXCL 0x540D -#define TIOCSCTTY 0x540E -#define TIOCGPGRP 0x540F -#define TIOCSPGRP 0x5410 -#define TIOCOUTQ 0x5411 -#define TIOCSTI 0x5412 -#define TIOCGWINSZ 0x5413 -#define TIOCSWINSZ 0x5414 -#define TIOCMGET 0x5415 -#define TIOCMBIS 0x5416 -#define TIOCMBIC 0x5417 -#define TIOCMSET 0x5418 -#define TIOCGSOFTCAR 0x5419 -#define TIOCSSOFTCAR 0x541A -// #define FIONREAD 0x541B -#define TIOCINQ FIONREAD -#define TIOCLINUX 0x541C -#define TIOCCONS 0x541D -#define TIOCGSERIAL 0x541E -#define TIOCSSERIAL 0x541F -#define TIOCPKT 0x5420 -// #define FIONBIO 0x5421 -#define TIOCNOTTY 0x5422 -#define TIOCSETD 0x5423 -#define TIOCGETD 0x5424 -#define TCSBRKP 0x5425 -#define TIOCSBRK 0x5427 -#define TIOCCBRK 0x5428 -#define TIOCGSID 0x5429 -#define TIOCGRS485 0x542E -#define TIOCSRS485 0x542F -#define TIOCGPTN 0x80045430 -#define TIOCSPTLCK 0x40045431 -#define TIOCGDEV 0x80045432 -#define TCGETX 0x5432 -#define TCSETX 0x5433 -#define TCSETXF 0x5434 -#define TCSETXW 0x5435 -#define TIOCSIG 0x40045436 -#define TIOCVHANGUP 0x5437 -#define TIOCGPKT 0x80045438 -#define TIOCGPTLCK 0x80045439 -#define TIOCGEXCL 0x80045440 - -#define FIONCLEX 0x5450 -#define FIOCLEX 0x5451 +#define TCGETS 0x5401 +#define TCSETS 0x5402 +#define TCSETSW 0x5403 +#define TCSETSF 0x5404 +#define TCGETA 0x5405 +#define TCSETA 0x5406 +#define TCSETAW 0x5407 +#define TCSETAF 0x5408 +#define TCSBRK 0x5409 +#define TCXONC 0x540A +#define TCFLSH 0x540B +#define TIOCEXCL 0x540C +#define TIOCNXCL 0x540D +#define TIOCSCTTY 0x540E +#define TIOCGPGRP 0x540F +#define TIOCSPGRP 0x5410 +#define TIOCOUTQ 0x5411 +#define TIOCSTI 0x5412 +#define TIOCGWINSZ 0x5413 +#define TIOCSWINSZ 0x5414 +#define TIOCMGET 0x5415 +#define TIOCMBIS 0x5416 +#define TIOCMBIC 0x5417 +#define TIOCMSET 0x5418 +#define TIOCGSOFTCAR 0x5419 +#define TIOCSSOFTCAR 0x541A +// #define FIONREAD 0x541B +#define TIOCINQ FIONREAD +#define TIOCLINUX 0x541C +#define TIOCCONS 0x541D +#define TIOCGSERIAL 0x541E +#define TIOCSSERIAL 0x541F +#define TIOCPKT 0x5420 +// #define FIONBIO 0x5421 +#define TIOCNOTTY 0x5422 +#define TIOCSETD 0x5423 +#define TIOCGETD 0x5424 +#define TCSBRKP 0x5425 +#define TIOCSBRK 0x5427 +#define TIOCCBRK 0x5428 +#define TIOCGSID 0x5429 +#define TIOCGRS485 0x542E +#define TIOCSRS485 0x542F +#define TIOCGPTN 0x80045430 +#define TIOCSPTLCK 0x40045431 +#define TIOCGDEV 0x80045432 +#define TCGETX 0x5432 +#define TCSETX 0x5433 +#define TCSETXF 0x5434 +#define TCSETXW 0x5435 +#define TIOCSIG 0x40045436 +#define TIOCVHANGUP 0x5437 +#define TIOCGPKT 0x80045438 +#define TIOCGPTLCK 0x80045439 +#define TIOCGEXCL 0x80045440 + +#define FIONCLEX 0x5450 +#define FIOCLEX 0x5451 #ifndef _WIN32 -#define FIOASYNC 0x5452 +#define FIOASYNC 0x5452 #endif -#define TIOCSERCONFIG 0x5453 -#define TIOCSERGWILD 0x5454 -#define TIOCSERSWILD 0x5455 -#define TIOCGLCKTRMIOS 0x5456 -#define TIOCSLCKTRMIOS 0x5457 -#define TIOCSERGSTRUCT 0x5458 +#define TIOCSERCONFIG 0x5453 +#define TIOCSERGWILD 0x5454 +#define TIOCSERSWILD 0x5455 +#define TIOCGLCKTRMIOS 0x5456 +#define TIOCSLCKTRMIOS 0x5457 +#define TIOCSERGSTRUCT 0x5458 #define TIOCSERGETLSR 0x5459 #define TIOCSERGETMULTI 0x545A #define TIOCSERSETMULTI 0x545B -#define TIOCMIWAIT 0x545C -#define TIOCGICOUNT 0x545D -#define FIOQSIZE 0x5460 +#define TIOCMIWAIT 0x545C +#define TIOCGICOUNT 0x545D +#define FIOQSIZE 0x5460 -#define TIOCPKT_DATA 0 -#define TIOCPKT_FLUSHREAD 1 -#define TIOCPKT_FLUSHWRITE 2 -#define TIOCPKT_STOP 4 -#define TIOCPKT_START 8 -#define TIOCPKT_NOSTOP 16 -#define TIOCPKT_DOSTOP 32 -#define TIOCPKT_IOCTL 64 +#define TIOCPKT_DATA 0 +#define TIOCPKT_FLUSHREAD 1 +#define TIOCPKT_FLUSHWRITE 2 +#define TIOCPKT_STOP 4 +#define TIOCPKT_START 8 +#define TIOCPKT_NOSTOP 16 +#define TIOCPKT_DOSTOP 32 +#define TIOCPKT_IOCTL 64 #define TIOCSER_TEMT 0x01 struct winsize { - unsigned short ws_row; - unsigned short ws_col; - unsigned short ws_xpixel; - unsigned short ws_ypixel; + unsigned short ws_row; + unsigned short ws_col; + unsigned short ws_xpixel; + unsigned short ws_ypixel; }; #define TIOCM_LE 0x001 @@ -223,8 +223,7 @@ struct winsize { #define SIOCADDDLCI 0x8980 #define SIOCDELDLCI 0x8981 -#define SIOCDEVPRIVATE 0x89F0 -#define SIOCPROTOPRIVATE 0x89E0 +#define SIOCDEVPRIVATE 0x89F0 +#define SIOCPROTOPRIVATE 0x89E0 #endif - -- cgit v1.3.1 From b1cdc3a2cbce88d9cd015eeaa5cfed09e75a1858 Mon Sep 17 00:00:00 2001 From: tangweikang Date: Fri, 5 Feb 2021 18:27:41 +0800 Subject: [toolchain] Added support for the TASKING toolchain. --- include/libc/libc_ioctl.h | 2 +- include/rtdef.h | 12 ++++++++++++ src/components.c | 9 ++++++--- 3 files changed, 19 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/libc/libc_ioctl.h b/include/libc/libc_ioctl.h index 812a119507..516c56b1f4 100644 --- a/include/libc/libc_ioctl.h +++ b/include/libc/libc_ioctl.h @@ -16,7 +16,7 @@ #define _IOC_WRITE 1U #define _IOC_READ 2U -#ifndef _WIN32 +#if !defined (_WIN32) && !defined (__TASKING__) #define _IO(a,b) _IOC(_IOC_NONE,(a),(b),0) #define _IOW(a,b,c) _IOC(_IOC_WRITE,(a),(b),sizeof(c)) #define _IOR(a,b,c) _IOC(_IOC_READ,(a),(b),sizeof(c)) diff --git a/include/rtdef.h b/include/rtdef.h index e4ddbd37d3..1226b43020 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -192,6 +192,18 @@ typedef rt_base_t rt_off_t; /**< Type for offset */ #define RT_WEAK #define rt_inline static inline #define RTT_API +#elif defined (__TASKING__) + + #include + #define SECTION(x) + #define RT_UNUSED + #define RT_USED + #define PRAGMA(x) _Pragma(#x) + #define ALIGN(n) + #define RT_WEAK + #define rt_inline static inline + #define RTT_API + #else #error not supported tool chain #endif diff --git a/src/components.c b/src/components.c index e7824b65ef..8ea5654d0c 100644 --- a/src/components.c +++ b/src/components.c @@ -173,19 +173,22 @@ struct rt_thread main_thread; void main_thread_entry(void *parameter) { extern int main(void); - extern int $Super$$main(void); #ifdef RT_USING_COMPONENTS_INIT /* RT-Thread components initialization */ rt_components_init(); #endif + #ifdef RT_USING_SMP rt_hw_secondary_cpu_up(); #endif /* invoke system main function */ #if defined(__CC_ARM) || defined(__CLANG_ARM) - $Super$$main(); /* for ARMCC. */ -#elif defined(__ICCARM__) || defined(__GNUC__) + { + extern int $Super$$main(void); + $Super$$main(); /* for ARMCC. */ + } +#elif defined(__ICCARM__) || defined(__GNUC__) || defined(__TASKING__) main(); #endif } -- cgit v1.3.1 From f5ede64c8330b09450562b509a84c8e6e85d6c32 Mon Sep 17 00:00:00 2001 From: liruncong Date: Tue, 9 Feb 2021 23:25:16 +0800 Subject: [include]SECTION=>RT_SECTION(与catch2中SECTION冲突) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/rtdef.h | 18 +++++++++--------- include/rtm.h | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'include') diff --git a/include/rtdef.h b/include/rtdef.h index 1226b43020..0256601949 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -117,7 +117,7 @@ typedef rt_base_t rt_off_t; /**< Type for offset */ /* Compiler Related Definitions */ #if defined(__CC_ARM) || defined(__CLANG_ARM) /* ARM Compiler */ #include - #define SECTION(x) __attribute__((section(x))) + #define RT_SECTION(x) __attribute__((section(x))) #define RT_UNUSED __attribute__((unused)) #define RT_USED __attribute__((used)) #define ALIGN(n) __attribute__((aligned(n))) @@ -133,7 +133,7 @@ typedef rt_base_t rt_off_t; /**< Type for offset */ #elif defined (__IAR_SYSTEMS_ICC__) /* for IAR Compiler */ #include - #define SECTION(x) @ x + #define RT_SECTION(x) @ x #define RT_UNUSED #define RT_USED __root #define PRAGMA(x) _Pragma(#x) @@ -154,7 +154,7 @@ typedef rt_base_t rt_off_t; /**< Type for offset */ #define va_arg(v,l) __builtin_va_arg(v,l) #endif - #define SECTION(x) __attribute__((section(x))) + #define RT_SECTION(x) __attribute__((section(x))) #define RT_UNUSED __attribute__((unused)) #define RT_USED __attribute__((used)) #define ALIGN(n) __attribute__((aligned(n))) @@ -163,7 +163,7 @@ typedef rt_base_t rt_off_t; /**< Type for offset */ #define RTT_API #elif defined (__ADSPBLACKFIN__) /* for VisualDSP++ Compiler */ #include - #define SECTION(x) __attribute__((section(x))) + #define RT_SECTION(x) __attribute__((section(x))) #define RT_UNUSED __attribute__((unused)) #define RT_USED __attribute__((used)) #define ALIGN(n) __attribute__((aligned(n))) @@ -172,7 +172,7 @@ typedef rt_base_t rt_off_t; /**< Type for offset */ #define RTT_API #elif defined (_MSC_VER) #include - #define SECTION(x) + #define RT_SECTION(x) #define RT_UNUSED #define RT_USED #define ALIGN(n) __declspec(align(n)) @@ -184,7 +184,7 @@ typedef rt_base_t rt_off_t; /**< Type for offset */ /* The way that TI compiler set section is different from other(at least * GCC and MDK) compilers. See ARM Optimizing C/C++ Compiler 5.9.3 for more * details. */ - #define SECTION(x) + #define RT_SECTION(x) #define RT_UNUSED #define RT_USED #define PRAGMA(x) _Pragma(#x) @@ -195,7 +195,7 @@ typedef rt_base_t rt_off_t; /**< Type for offset */ #elif defined (__TASKING__) #include - #define SECTION(x) + #define RT_SECTION(x) #define RT_UNUSED #define RT_USED #define PRAGMA(x) _Pragma(#x) @@ -222,11 +222,11 @@ typedef int (*init_fn_t)(void); }; #define INIT_EXPORT(fn, level) \ const char __rti_##fn##_name[] = #fn; \ - RT_USED const struct rt_init_desc __rt_init_desc_##fn SECTION(".rti_fn." level) = \ + RT_USED const struct rt_init_desc __rt_init_desc_##fn RT_SECTION(".rti_fn." level) = \ { __rti_##fn##_name, fn}; #else #define INIT_EXPORT(fn, level) \ - RT_USED const init_fn_t __rt_init_##fn SECTION(".rti_fn." level) = fn + RT_USED const init_fn_t __rt_init_##fn RT_SECTION(".rti_fn." level) = fn #endif #endif #else diff --git a/include/rtm.h b/include/rtm.h index 7e07a2239c..9da3a6b8b2 100644 --- a/include/rtm.h +++ b/include/rtm.h @@ -28,8 +28,8 @@ __declspec(allocate("RTMSymTab$f"))const char __rtmsym_##symbol##_name[] = "__vs #else #define RTM_EXPORT(symbol) \ -const char __rtmsym_##symbol##_name[] SECTION(".rodata.name") = #symbol; \ -const struct rt_module_symtab __rtmsym_##symbol SECTION("RTMSymTab")= \ +const char __rtmsym_##symbol##_name[] RT_SECTION(".rodata.name") = #symbol; \ +const struct rt_module_symtab __rtmsym_##symbol RT_SECTION("RTMSymTab")= \ { \ (void *)&symbol, \ __rtmsym_##symbol##_name \ -- cgit v1.3.1