Merge pull request #1212 from aozima/pulls

整理network示例和tf卡SPI驱动代码
This commit is contained in:
Bernard Xiong 2018-02-07 17:15:21 +08:00 committed by GitHub
commit 64a20c0f15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
70 changed files with 444 additions and 981 deletions

View File

@ -18,9 +18,9 @@ elif CROSS_TOOL == 'keil':
PLATFORM = 'armcc'
EXEC_PATH = 'C:/Keil_v5'
elif CROSS_TOOL == 'iar':
print '================ERROR============================'
print 'Not support iar yet!'
print '================================================='
print('================ERROR============================')
print('Not support iar yet!')
print('=================================================')
exit(0)
if os.getenv('RTT_EXEC_PATH'):

View File

@ -15,14 +15,14 @@ if CROSS_TOOL == 'gcc':
PLATFORM = 'gcc'
EXEC_PATH = 'C:/Program Files/Atmel/AVR Tools/AVR Toolchain/bin'
elif CROSS_TOOL == 'keil':
print '================ERROR============================'
print 'Not support keil yet!'
print '================================================='
print('================ERROR============================')
print('Not support keil yet!')
print('=================================================')
exit(0)
elif CROSS_TOOL == 'iar':
print '================ERROR============================'
print 'Not support iar yet!'
print '================================================='
print('================ERROR============================')
print('Not support iar yet!')
print('=================================================')
exit(0)
if os.getenv('RTT_EXEC_PATH'):

View File

@ -15,9 +15,9 @@ elif CROSS_TOOL == 'keil':
PLATFORM = 'armcc'
EXEC_PATH = 'C:/Keil'
elif CROSS_TOOL == 'iar':
print '================ERROR============================'
print 'Not support IAR yet!'
print '================================================='
print('================ERROR============================')
print('Not support IAR yet!')
print('=================================================')
exit(0)
if os.getenv('RTT_EXEC_PATH'):

View File

@ -13,14 +13,14 @@ if CROSS_TOOL == 'gcc':
EXEC_PATH = 'C:\Program Files (x86)\CodeSourcery\Sourcery G++ Lite\bin'
#EXEC_PATH = 'C:\Program Files (x86)\yagarto\bin'
elif CROSS_TOOL == 'keil':
print '================ERROR============================'
print 'Not support keil yet!'
print '================================================='
print('================ERROR============================')
print('Not support keil yet!')
print('=================================================')
exit(0)
elif CROSS_TOOL == 'iar':
print '================ERROR============================'
print 'Not support iar yet!'
print '================================================='
print('================ERROR============================')
print('Not support iar yet!')
print('=================================================')
exit(0)
if os.getenv('RTT_EXEC_PATH'):

View File

@ -17,9 +17,9 @@ elif CROSS_TOOL == 'keil':
PLATFORM = 'armcc'
EXEC_PATH = r'C:/Keil'
elif CROSS_TOOL == 'iar':
print '================ERROR============================'
print 'Not support iar yet!'
print '================================================='
print('================ERROR============================')
print('Not support iar yet!')
print('=================================================')
exit(0)
if os.getenv('RTT_EXEC_PATH'):

View File

@ -11,8 +11,8 @@ sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
try:
from building import *
except:
print 'Cannot found RT-Thread root directory, please check RTT_ROOT'
print RTT_ROOT
print('Cannot found RT-Thread root directory, please check RTT_ROOT')
print(RTT_ROOT)
exit(-1)
TARGET = 'rtthread-gd32f4xx.' + rtconfig.TARGET_EXT

View File

@ -13,9 +13,9 @@ if os.getenv('RTT_ROOT'):
# cross_tool provides the cross compiler
# EXEC_PATH is the compiler execute path, for example, CodeSourcery, Keil MDK, IAR
if CROSS_TOOL == 'gcc':
print '================ERROR============================'
print 'Not support gcc yet!'
print '================================================='
print('================ERROR============================')
print('Not support gcc yet!')
print('=================================================')
PLATFORM = 'gcc'
elif CROSS_TOOL == 'keil':
PLATFORM = 'armcc'

View File

@ -18,9 +18,9 @@ elif CROSS_TOOL == 'keil':
PLATFORM = 'armcc'
EXEC_PATH = 'C:/Keil'
elif CROSS_TOOL == 'iar':
print '================ERROR============================'
print 'Not support iar yet!'
print '================================================='
print('================ERROR============================')
print('Not support iar yet!')
print('=================================================')
exit(0)
if os.getenv('RTT_EXEC_PATH'):

View File

@ -18,9 +18,9 @@ elif CROSS_TOOL == 'keil':
PLATFORM = 'armcc'
EXEC_PATH = 'C:/Keil'
elif CROSS_TOOL == 'iar':
print '================ERROR============================'
print 'Not support iar yet!'
print '================================================='
print('================ERROR============================')
print('Not support iar yet!')
print('=================================================')
exit(0)
if os.getenv('RTT_EXEC_PATH'):

View File

@ -20,9 +20,9 @@ elif CROSS_TOOL == 'keil':
PLATFORM = 'armcc'
EXEC_PATH = r'C:/Keil'
elif CROSS_TOOL == 'iar':
print '================ERROR============================'
print 'Not support iar yet!'
print '================================================='
print('================ERROR============================')
print('Not support iar yet!')
print('=================================================')
exit(0)
if os.getenv('RTT_EXEC_PATH'):

View File

@ -15,9 +15,9 @@ elif CROSS_TOOL == 'keil':
PLATFORM = 'armcc'
EXEC_PATH = 'C:/Keil'
elif CROSS_TOOL == 'iar':
print '================ERROR============================'
print 'Not support iar yet!'
print '================================================='
print('================ERROR============================')
print('Not support iar yet!')
print('=================================================')
exit(0)
if os.getenv('RTT_EXEC_PATH'):

View File

@ -15,9 +15,9 @@ elif CROSS_TOOL == 'keil':
PLATFORM = 'armcc'
EXEC_PATH = 'C:\Keil'
elif CROSS_TOOL == 'iar':
print '================ERROR============================'
print 'Not support iar yet!'
print '================================================='
print('================ERROR============================')
print('Not support iar yet!')
print('=================================================')
exit(0)
if os.getenv('RTT_EXEC_PATH'):

View File

@ -15,9 +15,9 @@ elif CROSS_TOOL == 'keil':
PLATFORM = 'armcc'
EXEC_PATH = 'C:/Keil'
elif CROSS_TOOL == 'iar':
print '================ERROR============================'
print 'Not support iar yet!'
print '================================================='
print('================ERROR============================')
print('Not support iar yet!')
print('=================================================')
exit(0)
if os.getenv('RTT_EXEC_PATH'):

View File

@ -16,9 +16,9 @@ elif CROSS_TOOL == 'keil':
PLATFORM = 'armcc'
EXEC_PATH = 'D:/Keil'
elif CROSS_TOOL == 'iar':
print '================ERROR============================'
print 'Not support iar yet!'
print '================================================='
print('================ERROR============================')
print('Not support iar yet!')
print('=================================================')
exit(0)
if os.getenv('RTT_EXEC_PATH'):

View File

@ -29,7 +29,7 @@ if rtconfig.CROSS_TOOL == 'gcc':
import glob
# Remove the .o for M0 left on the drivers dir.
for i in glob.glob(GetCurrentDir() + '/../drivers/*.o'):
print 'RM %s' % i
print('RM %s' % i)
os.unlink(i)
if sys.platform.startswith('linux'):
@ -40,7 +40,7 @@ if rtconfig.CROSS_TOOL == 'gcc':
else:
# Assume Windows.
ocwd = os.getcwdu()
print 'TODO: remove the object files in ../Libraries'
print('TODO: remove the object files in ../Libraries')
os.chdir(ocwd)
# do building

View File

@ -26,14 +26,14 @@ Export('rtconfig')
objs = PrepareBuilding(env, RTT_ROOT, has_libcpu=False)
if rtconfig.CROSS_TOOL == 'gcc':
print 'build M0 code first'
print('build M0 code first')
if sys.platform.startswith('linux'):
import glob
ocwd = os.getcwdu()
os.chdir('../M0')
res = os.system('scons')
if res:
print 'build M0 exit with code %d\n' % res
print('build M0 exit with code %d\n' % res)
sys.exit(res)
os.chdir(ocwd)
res = os.system('cd ../Libraries/; find -name \*.o -exec rm {} \;')
@ -47,7 +47,7 @@ if rtconfig.CROSS_TOOL == 'gcc':
# Remove the .o for M0 left on the drivers dir.
for i in glob.glob(GetCurrentDir() + '/../drivers/*.o'):
print 'RM %s' % i
print('RM %s' % i)
os.unlink(i)
# do building

View File

@ -16,9 +16,9 @@ elif CROSS_TOOL == 'keil':
PLATFORM = 'armcc'
EXEC_PATH = 'D:/Keil_v5'
elif CROSS_TOOL == 'iar':
print '================ERROR============================'
print 'Not support iar yet!'
print '================================================='
print('================ERROR============================')
print('Not support iar yet!')
print('=================================================')
exit(0)
if os.getenv('RTT_EXEC_PATH'):

View File

@ -11,9 +11,9 @@ if os.getenv('RTT_CC'):
# cross_tool provides the cross compiler
# EXEC_PATH is the compiler execute path, for example, CodeSourcery, Keil MDK, IAR
if CROSS_TOOL == 'gcc':
print '================ERROR============================'
print 'Not support gcc yet!'
print '================================================='
print('================ERROR============================')
print('Not support gcc yet!')
print('=================================================')
elif CROSS_TOOL == 'keil':
PLATFORM = 'armcc'
EXEC_PATH = 'C:/keil_v5'

View File

@ -14,9 +14,9 @@ if CROSS_TOOL == 'gcc':
PLATFORM = 'gcc'
EXEC_PATH = r'C:\Program Files\CodeSourcery\Sourcery G++ Lite For MIPS ELF\bin'
else:
print '================ERROR============================'
print 'Not support %s yet!' % CROSS_TOOL
print '================================================='
print('================ERROR============================')
print('Not support %s yet!' % CROSS_TOOL)
print('=================================================')
exit(0)
if os.getenv('RTT_EXEC_PATH'):

View File

@ -15,9 +15,9 @@ if CROSS_TOOL == 'gcc':
# EXEC_PATH = "/opt/mips-2015.05/bin"
EXEC_PATH = r'D:\mgc\embedded\codebench\bin'
else:
print '================ERROR==========================='
print 'Not support %s yet!' % CROSS_TOOL
print '================================================='
print('================ERROR===========================')
print('Not support %s yet!' % CROSS_TOOL)
print('=================================================')
exit(0)
if os.getenv('RTT_EXEC_PATH'):

View File

@ -17,9 +17,9 @@ elif CROSS_TOOL == 'iar':
IAR_PATH = 'C:/Program Files/IAR Systems/Embedded Workbench Evaluation 6.0'
# EXEC_PATH = 'C:/Program Files/IAR Systems/Embedded Workbench Evaluation 6.0'
elif CROSS_TOOL == 'keil':
print '================ERROR============================'
print 'Not support keil yet!'
print '================================================='
print('================ERROR============================')
print('Not support keil yet!')
print('=================================================')
exit(0)
if os.getenv('RTT_EXEC_PATH'):

View File

@ -16,9 +16,9 @@ elif CROSS_TOOL == 'keil':
PLATFORM = 'armcc'
EXEC_PATH = 'C:/Keil_MDK_471'
elif CROSS_TOOL == 'iar':
print '================ERROR============================'
print 'Not support iar yet!'
print '================================================='
print('================ERROR============================')
print('Not support iar yet!')
print('=================================================')
exit(0)
if os.getenv('RTT_EXEC_PATH'):

View File

@ -21,9 +21,9 @@ elif CROSS_TOOL == 'keil':
PLATFORM = 'armcc'
EXEC_PATH = 'C:/Keil'
elif CROSS_TOOL == 'iar':
print '================ERROR============================'
print 'Not support iar yet!'
print '================================================='
print('================ERROR============================')
print('Not support iar yet!')
print('=================================================')
exit(0)
if os.getenv('RTT_EXEC_PATH'):

View File

@ -10,18 +10,18 @@ CROSS_TOOL = 'keil'
if os.getenv('RTT_CC'):
CROSS_TOOL = os.getenv('RTT_CC')
if CROSS_TOOL == 'gcc':
print '================ERROR============================'
print 'Not support gcc yet!'
print '================================================='
if CROSS_TOOL == 'gcc':
print('================ERROR============================')
print('Not support gcc yet!')
print('=================================================')
exit(0)
elif CROSS_TOOL == 'keil':
PLATFORM = 'armcc'
EXEC_PATH = 'c:/Keil'
elif CROSS_TOOL == 'iar':
print '================ERROR============================'
print 'Not support iar yet!'
print '================================================='
print('================ERROR============================')
print('Not support iar yet!')
print('=================================================')
exit(0)
if os.getenv('RTT_EXEC_PATH'):

View File

@ -17,9 +17,9 @@ elif CROSS_TOOL == 'keil':
PLATFORM = 'armcc'
EXEC_PATH = 'C:/Keil_v5'
elif CROSS_TOOL == 'iar':
print '================ERROR============================'
print 'Not support iar yet!'
print '================================================='
print('================ERROR============================')
print('Not support iar yet!')
print('=================================================')
exit(0)
if os.getenv('RTT_EXEC_PATH'):

View File

@ -18,9 +18,9 @@ elif CROSS_TOOL == 'keil':
PLATFORM = 'armcc'
EXEC_PATH = 'C:/Keil_v5'
elif CROSS_TOOL == 'iar':
print '================ERROR============================'
print 'Not support iar yet!'
print '================================================='
print('================ERROR============================')
print('Not support iar yet!')
print('=================================================')
exit(0)
if os.getenv('RTT_EXEC_PATH'):

View File

@ -14,14 +14,14 @@ if CROSS_TOOL == 'gcc':
PLATFORM = 'gcc'
EXEC_PATH = 'G:/iot/camera_studio-win32-20160903/camera_studio/tools/arm-2014.05/bin'
elif CROSS_TOOL == 'keil':
print '================ERROR============================'
print 'Not support iar yet!'
print '================================================='
print('================ERROR============================')
print('Not support iar yet!')
print('=================================================')
exit(0)
elif CROSS_TOOL == 'iar':
print '================ERROR============================'
print 'Not support iar yet!'
print '================================================='
print('================ERROR============================')
print('Not support iar yet!')
print('=================================================')
exit(0)
if os.getenv('RTT_EXEC_PATH'):

View File

@ -29,7 +29,7 @@ if GetDepend('RT_USING_VMM'):
if os.system('{cppcmd} -P -C -E -I. -D__ASSEMBLY__ {ldfile}.S -o {ldfile}'.format(
cppcmd = os.path.join(rtconfig.EXEC_PATH, 'arm-none-eabi-gcc'),
ldfile = rtconfig.LINK_SCRIPT)) != 0:
print 'failed to generate linker script %s' % rtconfig.LINK_SCRIPT
print('failed to generate linker script %s' % rtconfig.LINK_SCRIPT)
sys.exit(255)
# if the linker script changed, relink the target
Depends(TARGET, rtconfig.LINK_SCRIPT)

View File

@ -15,9 +15,9 @@ elif CROSS_TOOL == 'keil':
PLATFORM = 'armcc'
EXEC_PATH = 'C:/Keil'
elif CROSS_TOOL == 'iar':
print '================ERROR============================'
print 'Not support IAR yet!'
print '================================================='
print('================ERROR============================')
print('Not support IAR yet!')
print('=================================================')
exit(0)
if os.getenv('RTT_EXEC_PATH'):

View File

@ -16,9 +16,9 @@ elif CROSS_TOOL == 'keil':
PLATFORM = 'armcc'
EXEC_PATH = 'C:/Keil'
elif CROSS_TOOL == 'iar':
print '================ERROR============================'
print 'Not support iar yet!'
print '================================================='
print('================ERROR============================')
print('Not support iar yet!')
print('=================================================')
exit(0)
if os.getenv('RTT_EXEC_PATH'):

View File

@ -22,9 +22,9 @@ elif CROSS_TOOL == 'keil':
PLATFORM = 'armcc'
EXEC_PATH = 'C:/Keil'
elif CROSS_TOOL == 'iar':
print '================ERROR============================'
print 'Not support iar yet!'
print '================================================='
print('================ERROR============================')
print('Not support iar yet!')
print('=================================================')
exit(0)
if os.getenv('RTT_EXEC_PATH'):

View File

@ -14,9 +14,9 @@ if CROSS_TOOL == 'gcc':
PLATFORM = 'gcc'
EXEC_PATH = '/usr/unicore/gnu-toolchain-unicore/uc4-1.0-beta-hard-RHELAS5/bin/'
else :
print '================ERROR============================'
print 'Not support yet!'
print '================================================='
print('================ERROR============================')
print('Not support yet!')
print('=================================================')
exit(0)
if os.getenv('RTT_EXEC_PATH'):

View File

@ -80,7 +80,7 @@ objs = PrepareBuilding(env, RTT_ROOT, has_libcpu=False)
def ObjRemove(objs, remove):
for item in objs:
# print type(item), os.path.basename(str(item))
# print(type(item), os.path.basename(str(item)) )
if os.path.basename(str(item)) in remove:
objs.remove(item)
return

View File

@ -27,7 +27,7 @@ elif CROSS_TOOL == 'msvc':
PLATFORM = 'cl'
EXEC_PATH = ''
else:
print "bad CROSS TOOL!"
print("bad CROSS TOOL!")
exit(1)
if os.getenv('RTT_EXEC_PATH'):

View File

@ -17,9 +17,9 @@ elif CROSS_TOOL == 'keil':
PLATFORM = 'armcc'
EXEC_PATH = 'C:/Keil'
elif CROSS_TOOL == 'iar':
print '================ERROR============================'
print 'Not support iar yet!'
print '================================================='
print('================ERROR============================')
print('Not support iar yet!')
print('=================================================')
exit(0)
if os.getenv('RTT_EXEC_PATH'):

View File

@ -18,7 +18,6 @@ if GetDepend('RT_USING_LWIP'):
if GetDepend('RT_USING_SPI'):
src += ['rt_stm32f10x_spi.c']
src += ['msd.c']
CPPPATH = [cwd]

View File

@ -8,8 +8,8 @@
#ifdef RT_USING_SPI
#include "rt_stm32f10x_spi.h"
#if defined(RT_USING_DFS) && defined(RT_USING_DFS_ELMFAT)
#include "msd.h"
#if defined(RT_USING_DFS) && defined(RT_USING_SPI_MSD)
#include "spi_msd.h"
#endif /* RT_USING_DFS */
/*
@ -70,7 +70,7 @@ void rt_platform_init(void)
#ifdef RT_USING_SPI
rt_hw_spi_init();
#if defined(RT_USING_DFS) && defined(RT_USING_DFS_ELMFAT)
#if defined(RT_USING_DFS) && defined(RT_USING_SPI_MSD)
/* init sdcard driver */
{
extern void rt_hw_msd_init(void);
@ -90,7 +90,7 @@ void rt_platform_init(void)
msd_init("sd0", "spi10");
}
#endif /* RT_USING_DFS && RT_USING_DFS_ELMFAT */
#endif /* RT_USING_DFS && RT_USING_SPI_MSD */
#endif // RT_USING_SPI

View File

@ -11,8 +11,8 @@ sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
try:
from building import *
except:
print 'Cannot found RT-Thread root directory, please check RTT_ROOT'
print RTT_ROOT
print('Cannot found RT-Thread root directory, please check RTT_ROOT')
print(RTT_ROOT)
exit(-1)
TARGET = 'rtthread-stm32f4xx.' + rtconfig.TARGET_EXT

View File

@ -17,9 +17,9 @@ elif CROSS_TOOL == 'keil':
PLATFORM = 'armcc'
EXEC_PATH = r'C:/Keil'
elif CROSS_TOOL == 'iar':
print '================ERROR============================'
print 'Not support iar yet!'
print '================================================='
print('================ERROR============================')
print('Not support iar yet!')
print('=================================================')
exit(0)
if os.getenv('RTT_EXEC_PATH'):

View File

@ -11,8 +11,8 @@ sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
try:
from building import *
except:
print 'Cannot found RT-Thread root directory, please check RTT_ROOT'
print RTT_ROOT
print('Cannot found RT-Thread root directory, please check RTT_ROOT')
print(RTT_ROOT)
exit(-1)
TARGET = 'rtthread-stm32f411.' + rtconfig.TARGET_EXT

View File

@ -11,8 +11,8 @@ sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
try:
from building import *
except:
print 'Cannot found RT-Thread root directory, please check RTT_ROOT'
print RTT_ROOT
print('Cannot found RT-Thread root directory, please check RTT_ROOT')
print(RTT_ROOT)
exit(-1)
TARGET = 'rtthread-stm32f42x.' + rtconfig.TARGET_EXT

View File

@ -11,8 +11,8 @@ sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
try:
from building import *
except:
print 'Cannot found RT-Thread root directory, please check RTT_ROOT'
print RTT_ROOT
print('Cannot found RT-Thread root directory, please check RTT_ROOT')
print(RTT_ROOT)
exit(-1)
TARGET = 'rtthread-stm32f42x.' + rtconfig.TARGET_EXT

View File

@ -19,9 +19,9 @@ elif CROSS_TOOL == 'keil':
PLATFORM = 'armcc'
EXEC_PATH = r'C:/Keil_v5'
elif CROSS_TOOL == 'iar':
print '================ERROR============================'
print 'Not support iar yet!'
print '================================================='
print('================ERROR============================')
print('Not support iar yet!')
print('=================================================')
exit(0)
if os.getenv('RTT_EXEC_PATH'):

View File

@ -11,8 +11,8 @@ sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
try:
from building import *
except:
print 'Cannot found RT-Thread root directory, please check RTT_ROOT'
print RTT_ROOT
print('Cannot found RT-Thread root directory, please check RTT_ROOT')
print(RTT_ROOT)
exit(-1)
TARGET = 'rtthread-stm32f42x.' + rtconfig.TARGET_EXT

View File

@ -17,9 +17,9 @@ elif CROSS_TOOL == 'keil':
PLATFORM = 'armcc'
EXEC_PATH = r'C:/Keil'
elif CROSS_TOOL == 'iar':
print '================ERROR============================'
print 'Not support iar yet!'
print '================================================='
print('================ERROR============================')
print('Not support iar yet!')
print('=================================================')
exit(0)
if os.getenv('RTT_EXEC_PATH'):

View File

@ -11,8 +11,8 @@ sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
try:
from building import *
except:
print 'Cannot found RT-Thread root directory, please check RTT_ROOT'
print RTT_ROOT
print('Cannot found RT-Thread root directory, please check RTT_ROOT')
print(RTT_ROOT)
exit(-1)
TARGET = 'rtthread-stm32f4xx.' + rtconfig.TARGET_EXT

View File

@ -11,8 +11,8 @@ sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
try:
from building import *
except:
print 'Cannot found RT-Thread root directory, please check RTT_ROOT'
print RTT_ROOT
print('Cannot found RT-Thread root directory, please check RTT_ROOT')
print(RTT_ROOT)
exit(-1)
TARGET = 'rtthread-stm32f7xx.' + rtconfig.TARGET_EXT

View File

@ -11,8 +11,8 @@ sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
try:
from building import *
except:
print 'Cannot found RT-Thread root directory, please check RTT_ROOT'
print RTT_ROOT
print('Cannot found RT-Thread root directory, please check RTT_ROOT')
print(RTT_ROOT)
exit(-1)
TARGET = 'rtthread-stm32h7xx.' + rtconfig.TARGET_EXT

View File

@ -14,14 +14,14 @@ if CROSS_TOOL == 'gcc':
PLATFORM = 'gcc'
EXEC_PATH = 'G:/iot/camera_studio-win32-20160903/camera_studio/tools/arm-2014.05/bin'
elif CROSS_TOOL == 'keil':
print '================ERROR============================'
print 'Not support iar yet!'
print '================================================='
print('================ERROR============================')
print('Not support iar yet!')
print('=================================================')
exit(0)
elif CROSS_TOOL == 'iar':
print '================ERROR============================'
print 'Not support iar yet!'
print '================================================='
print('================ERROR============================')
print('Not support iar yet!')
print('=================================================')
exit(0)
if os.getenv('RTT_EXEC_PATH'):

View File

@ -11,8 +11,8 @@ sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
try:
from building import *
except:
print 'Cannot found RT-Thread root directory, please check RTT_ROOT'
print RTT_ROOT
print('Cannot found RT-Thread root directory, please check RTT_ROOT')
print(RTT_ROOT)
exit(-1)
TARGET = 'rtthread-stm32f42x.' + rtconfig.TARGET_EXT

View File

@ -19,9 +19,9 @@ elif CROSS_TOOL == 'keil':
PLATFORM = 'armcc'
EXEC_PATH = r'C:/Keil_v5'
elif CROSS_TOOL == 'iar':
print '================ERROR============================'
print 'Not support iar yet!'
print '================================================='
print('================ERROR============================')
print('Not support iar yet!')
print('=================================================')
exit(0)
if os.getenv('RTT_EXEC_PATH'):

View File

@ -11,8 +11,8 @@ sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
try:
from building import *
except:
print 'Cannot found RT-Thread root directory, please check RTT_ROOT'
print RTT_ROOT
print('Cannot found RT-Thread root directory, please check RTT_ROOT')
print(RTT_ROOT)
exit(-1)
TARGET = 'rtthread-stm32l476.' + rtconfig.TARGET_EXT

View File

@ -19,9 +19,9 @@ elif CROSS_TOOL == 'keil':
PLATFORM = 'armcc'
EXEC_PATH = r'C:/Keil_v5'
elif CROSS_TOOL == 'iar':
print '================ERROR============================'
print 'Not support iar yet!'
print '================================================='
print('================ERROR============================')
print('Not support iar yet!')
print('=================================================')
exit(0)
if os.getenv('RTT_EXEC_PATH'):

View File

@ -21,9 +21,9 @@ elif CROSS_TOOL == 'keil':
PLATFORM = 'armcc'
EXEC_PATH = r'D:\Keil_v5'
elif CROSS_TOOL == 'iar':
print '================ERROR============================'
print 'Not support iar yet!'
print '================================================='
print('================ERROR============================')
print('Not support iar yet!')
print('=================================================')
exit(0)
if os.getenv('RTT_EXEC_PATH'):

View File

@ -10,17 +10,17 @@ if os.getenv('RTT_CC'):
CROSS_TOOL = os.getenv('RTT_CC')
if CROSS_TOOL == 'gcc':
print '================ERROR============================'
print 'Not support gcc yet!'
print '================================================='
print('================ERROR============================')
print('Not support gcc yet!')
print('=================================================')
exit(0)
elif CROSS_TOOL == 'iar':
PLATFORM = 'iar'
IAR_PATH = 'C:/Program Files/IAR Systems/Embedded Workbench 6.0 Evaluation_0'
elif CROSS_TOOL == 'keil':
print '================ERROR============================'
print 'Not support keil yet!'
print '================================================='
print('================ERROR============================')
print('Not support keil yet!')
print('=================================================')
exit(0)
if os.getenv('RTT_EXEC_PATH'):

View File

@ -12,7 +12,7 @@ if CROSS_TOOL == 'gcc':
PLATFORM = 'gcc'
EXEC_PATH = r'E:\work\env\tools\gnu_gcc\mips_gcc\mips-2016.05\bin'
else:
print 'Please make sure your toolchains is GNU GCC!'
print('Please make sure your toolchains is GNU GCC!')
exit(0)
if os.getenv('RTT_EXEC_PATH'):

View File

@ -15,14 +15,14 @@ if CROSS_TOOL == 'gcc':
PLATFORM = 'gcc'
EXEC_PATH = 'E:/Program Files/CodeSourcery/Sourcery_CodeBench_Lite_for_IA32_ELF/bin'
elif CROSS_TOOL == 'keil':
print '================ERROR============================'
print 'Not support keil yet!'
print '================================================='
print('================ERROR============================')
print('Not support keil yet!')
print('=================================================')
exit(0)
elif CROSS_TOOL == 'iar':
print '================ERROR============================'
print 'Not support iar yet!'
print '================================================='
print('================ERROR============================')
print('Not support iar yet!')
print('=================================================')
exit(0)
if os.getenv('RTT_EXEC_PATH'):

View File

@ -15,9 +15,9 @@ elif CROSS_TOOL == 'keil':
PLATFORM = 'armcc'
EXEC_PATH = 'C:/Keil'
elif CROSS_TOOL == 'iar':
print '================ERROR============================'
print 'Not support IAR yet!'
print '================================================='
print('================ERROR============================')
print('Not support IAR yet!')
print('=================================================')
exit(0)
if os.getenv('RTT_EXEC_PATH'):

View File

@ -50,7 +50,7 @@ class File(object):
return bytes(self._data)
def dump(self, indent=0):
print '%s%s' % (' ' * indent, self._name)
print('%s%s' % (' ' * indent, self._name))
class Folder(object):
bin_fmt = struct.Struct('IIII')
@ -108,7 +108,7 @@ class Folder(object):
c.sort()
def dump(self, indent=0):
print '%s%s' % (' ' * indent, self._name)
print('%s%s' % (' ' * indent, self._name))
for c in self._children:
c.dump(indent + 1)

View File

@ -87,6 +87,11 @@ config RT_USING_SPI
default n
if RT_USING_SPI
config RT_USING_SPI_MSD
bool "Using SD/TF card driver with spi"
select RT_USING_DFS
default n
config RT_USING_SFUD
bool "Using Serial Flash Universal Driver"
default n

View File

@ -28,7 +28,10 @@ if GetDepend('RT_USING_SST25VFXX'):
if GetDepend('RT_USING_GD'):
src_device += ['spi_flash_gd.c']
if GetDepend('RT_USING_SPI_MSD'):
src_device += ['spi_msd.c']
if GetDepend('RT_USING_SFUD'):
src_device += ['spi_flash_sfud.c', 'sfud/src/sfud.c']
CPPPATH += [cwd + '/sfud/inc']

View File

@ -18,7 +18,7 @@
*/
#include <string.h>
#include "msd.h"
#include "spi_msd.h"
//#define MSD_TRACE
@ -30,7 +30,7 @@
#define DUMMY 0xFF
#define CARD_NCR_MAX 8
#define CARD_NCR_MAX 9
#define CARD_NRC 1
#define CARD_NCR 1

View File

@ -13,8 +13,8 @@
* 2009-04-17 Bernard first version.
*/
#ifndef MSD_H_INCLUDED
#define MSD_H_INCLUDED
#ifndef SPI_MSD_H_INCLUDED
#define SPI_MSD_H_INCLUDED
#include <stdint.h>
#include <drivers/spi.h>
@ -129,4 +129,4 @@ struct msd_device
extern rt_err_t msd_init(const char * sd_device_name, const char * spi_device_name);
#endif // MSD_H_INCLUDED
#endif // SPI_MSD_H_INCLUDED

View File

@ -1,7 +1,14 @@
#include <rtthread.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <dfs_posix.h>
#include <sys/socket.h>
#ifdef RT_USING_DFS_NET
#include <sys/select.h> // only dfs_net
#include <dfs_posix.h>
#else
#define read lwip_read
#define write lwip_write
#endif /* RT_USING_DFS_NET */
#include "netdb.h"
#define MAX_SERV 32 /* Maximum number of chargen services. Don't need too many */
@ -52,16 +59,16 @@ static void chargen_thread(void *arg)
if (bind(listenfd, (struct sockaddr *) &chargen_saddr, sizeof(chargen_saddr)) == -1)
LWIP_ASSERT("chargen_thread(): Socket bind failed.", 0);
/* Put socket into listening mode */
if (listen(listenfd, MAX_SERV) == -1)
LWIP_ASSERT("chargen_thread(): Listen failed.", 0);
/* Wait forever for network input: This could be connections or data */
for (;;)
{
maxfdp1 = listenfd+1;
maxfdp1 = listenfd + 1;
/* Determine what sockets need to be in readset */
FD_ZERO(&readset);
@ -78,7 +85,7 @@ static void chargen_thread(void *arg)
/* Wait for data or a new connection */
i = select(maxfdp1, &readset, &writeset, 0, 0);
if (i == 0) continue;
if (i == 0) continue;
/* At least one descriptor is ready */
if (FD_ISSET(listenfd, &readset))
@ -89,8 +96,8 @@ static void chargen_thread(void *arg)
if (p_charcb)
{
p_charcb->socket = accept(listenfd,
(struct sockaddr *) &p_charcb->cliaddr,
&p_charcb->clilen);
(struct sockaddr *) &p_charcb->cliaddr,
&p_charcb->clilen);
if (p_charcb->socket < 0)
rt_free(p_charcb);
else
@ -101,8 +108,8 @@ static void chargen_thread(void *arg)
p_charcb->nextchar = 0x21;
}
}
else
{
else
{
/* No memory to accept connection. Just accept and then close */
int sock;
struct sockaddr cliaddr;
@ -113,6 +120,7 @@ static void chargen_thread(void *arg)
closesocket(sock);
}
}
/* Go through list of connected clients and process data */
for (p_charcb = charcb_list; p_charcb; p_charcb = p_charcb->next)
{
@ -124,17 +132,19 @@ static void chargen_thread(void *arg)
if (do_read(p_charcb) < 0)
break;
}
if (FD_ISSET(p_charcb->socket, &writeset))
{
char line[80];
char setchar = p_charcb->nextchar;
for( i = 0; i < 59; i++)
for (i = 0; i < 59; i++)
{
line[i] = setchar;
if (++setchar == 0x7f)
setchar = 0x21;
}
line[i] = 0;
strcat(line, "\n\r");
if (write(p_charcb->socket, line, strlen(line)) < 0)
@ -142,6 +152,7 @@ static void chargen_thread(void *arg)
close_chargen(p_charcb);
break;
}
if (++p_charcb->nextchar == 0x7f)
p_charcb->nextchar = 0x21;
}
@ -202,19 +213,19 @@ static int do_read(struct charcb *p_charcb)
void chargen_init(void)
{
rt_thread_t chargen;
rt_thread_t chargen;
chargen = rt_thread_create(CHARGEN_THREAD_NAME,
chargen_thread, RT_NULL,
CHARGEN_THREAD_STACKSIZE,
CHARGEN_PRIORITY, 5);
if (chargen != RT_NULL) rt_thread_startup(chargen);
chargen = rt_thread_create(CHARGEN_THREAD_NAME,
chargen_thread, RT_NULL,
CHARGEN_THREAD_STACKSIZE,
CHARGEN_PRIORITY, 5);
if (chargen != RT_NULL) rt_thread_startup(chargen);
}
#ifdef RT_USING_FINSH
#include <finsh.h>
void chargen()
{
chargen_init();
chargen_init();
}
FINSH_FUNCTION_EXPORT(chargen, start chargen server);
#endif

View File

@ -1,560 +0,0 @@
#define OS_RTTHREAD 1
#if (OS_RTTHREAD == 0)
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/select.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <pthread.h>
#include <signal.h>
#include <stdlib.h>
#define DEBUG printf
#define SLEEP(x) sleep(x)
#else
#include <rtthread.h>
#include <lwip/netdb.h>
#include <lwip/sockets.h>
#include <arch/sys_arch.h>
#include <lwip/sys.h>
#define DEBUG rt_kprintf
#define SLEEP(x) rt_thread_delay((x)*RT_TICK_PER_SECOND)
#endif
#include <string.h>
#include "MQTTPacket.h"
#define HOSTNAME "m2m.eclipse.org"
#define HOSTPORT 1883
#define USERNAME "testuser"
#define PASSWORD "testpassword"
#define TOPIC "test"
#define KEEPALIVE_INTERVAL 20
typedef struct
{
int qos;
unsigned char retained;
unsigned char dup;
unsigned short id;
int payloadlen;
unsigned char *payload;
}mqtt_msg_t;
typedef struct
{
int sockfd;
unsigned char *wbuf; //
int wbuflen;
unsigned char *rbuf;
int rbuflen;
int (*getfn)(unsigned char*, int);
}mqtt_client_t;
static mqtt_client_t _cpub;
static mqtt_client_t _csub;
static void *mqtt_ping_thread(void *param)
{
int *sockfd = (int*)param;
unsigned char buf[2];
int len;
DEBUG("ping start\n");
while (*sockfd >= 0)
{
SLEEP(KEEPALIVE_INTERVAL-1);
len = MQTTSerialize_pingreq(buf, sizeof(buf));
send(*sockfd, buf, len, 0);
}
DEBUG("ping exit\n");
return 0;
}
void mqtt_ping_start(int *sockfd)
{
#if (OS_RTTHREAD == 0)
pthread_t tid;
pthread_create(&tid, NULL, mqtt_ping_thread, (void*)sockfd);
#else
sys_thread_new("ping",
mqtt_ping_thread,
(void*)sockfd,
512,
20);
#endif
}
static int sub_read(unsigned char *buf, int len)
{
int bytes = 0;
struct timeval interval;
int rc;
interval.tv_sec = 3;
interval.tv_usec = 0;
rc = setsockopt(_csub.sockfd, SOL_SOCKET, SO_RCVTIMEO, (char *)&interval, sizeof(struct timeval));
while (bytes < len)
{
rc = recv(_csub.sockfd, &buf[bytes], (size_t)(len - bytes), 0);
if (rc == -1)
{
if (errno != ENOTCONN && errno != ECONNRESET)
{
bytes = -1;
break;
}
}
else
bytes += rc;
}
return bytes;
}
static int pub_read(unsigned char *buf, int len)
{
int bytes = 0;
struct timeval interval;
int rc;
interval.tv_sec = 3;
interval.tv_usec = 0;
rc = setsockopt(_cpub.sockfd, SOL_SOCKET, SO_RCVTIMEO, (char *)&interval, sizeof(struct timeval));
while (bytes < len)
{
rc = recv(_cpub.sockfd, &buf[bytes], (size_t)(len - bytes), 0);
if (rc == -1)
{
if (errno != ENOTCONN && errno != ECONNRESET)
{
bytes = -1;
break;
}
}
else
bytes += rc;
}
return bytes;
}
int mqtt_write(int sockfd, unsigned char *buf, int len)
{
int rc;
struct timeval tv;
tv.tv_sec = 2;
tv.tv_usec = 0;
setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, (char *)&tv, sizeof(struct timeval));
rc = send(sockfd, buf, len, 0);
if (rc == len)
rc = 0;
return rc;
}
int mqtt_subscribe(mqtt_client_t *c, char* topicstr, int qos)
{
MQTTString topic = MQTTString_initializer;
int msgid = 1;
int len;
int rc = -1;
topic.cstring = topicstr;
len = MQTTSerialize_subscribe(c->wbuf, c->wbuflen, 0, msgid, 1, &topic, &qos);
if (len <= 0)
goto exit;
rc = mqtt_write(c->sockfd, c->wbuf, len);
if (rc < 0)
goto exit;
if (MQTTPacket_read(c->rbuf, c->rbuflen, c->getfn) == SUBACK)
{
unsigned short submsgid;
int subcount;
int granted_qos;
rc = MQTTDeserialize_suback(&submsgid, 1, &subcount, &granted_qos, c->rbuf, c->rbuflen);
if (granted_qos != 0)
{
DEBUG("granted qos != 0, %d\n", granted_qos);
rc = -1;
}
else
{
rc = 0;
}
}
else
{
rc = -1;
}
exit:
return rc;
}
int mqtt_publish(mqtt_client_t *c, char* topicstr, mqtt_msg_t *msg)
{
int rc = -1;
MQTTString topic = MQTTString_initializer;
int len;
int pktype;
topic.cstring = topicstr;
len = MQTTSerialize_publish(c->wbuf, c->wbuflen,
msg->dup, msg->qos, msg->retained, msg->id,
topic, msg->payload, msg->payloadlen);
if (len <= 0)
goto exit;
if ((rc = mqtt_write(c->sockfd, c->wbuf, len)) <= 0)
goto exit;
pktype = MQTTPacket_read(c->rbuf, c->rbuflen, c->getfn);
if (msg->qos == 1)
{
if (pktype == PUBACK)
{
unsigned short mypacketid;
unsigned char dup, type;
if (MQTTDeserialize_ack(&type, &dup, &mypacketid, c->rbuf, c->rbuflen) != 1)
rc = -1;
}
else
rc = -1;
}
else if (msg->qos == 2)
{
if (pktype == PUBCOMP)
{
unsigned short mypacketid;
unsigned char dup, type;
if (MQTTDeserialize_ack(&type, &dup, &mypacketid, c->rbuf, c->rbuflen) != 1)
rc = -1;
}
else
rc = -1;
}
exit:
return rc;
}
int mqtt_netconnect(char *addr, int port)
{
struct hostent *host = 0;
struct sockaddr_in sockaddr;
int sock;
host = gethostbyname(addr);
if (host == 0)
return -1;
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1)
{
return -1;
}
sockaddr.sin_family = AF_INET;
sockaddr.sin_port = htons(port);
sockaddr.sin_addr = *((struct in_addr *)host->h_addr);
memset(&(sockaddr.sin_zero), 0, sizeof(sockaddr.sin_zero));
if (connect(sock, (struct sockaddr *)&sockaddr, sizeof(struct sockaddr)) == -1)
{
#if (OS_RTTHREAD == 0)
close(sock);
#else
closesocket(sock);
#endif
return -2;
}
return sock;
}
void mqtt_netdisconnect(int *sockfd)
{
#if (OS_RTTHREAD == 0)
close(*sockfd);
#else
closesocket(*sockfd);
#endif
*sockfd = -1;
}
int mqtt_connect(mqtt_client_t *c, MQTTPacket_connectData *data)
{
int rc = -1;
int len;
len = MQTTSerialize_connect(c->wbuf, c->wbuflen, data);
if (len <= 0)
goto exit;
rc = mqtt_write(c->sockfd, c->wbuf, len);
if (rc < 0)
goto exit;
rc = MQTTPacket_read(c->rbuf, c->rbuflen, c->getfn);
if (rc < 0)
goto exit;
if (rc == CONNACK)
{
unsigned char sessionPresent, connack_rc;
if (MQTTDeserialize_connack(&sessionPresent, &connack_rc, c->rbuf, c->rbuflen) == 1)
{
rc = connack_rc;
}
else
{
rc = -1;
}
}
else
rc = -1;
exit:
return rc;
}
int mqtt_disconnect(mqtt_client_t *c)
{
int rc = -1;
int len;
len = MQTTSerialize_disconnect(c->wbuf, c->wbuflen);
if (len > 0)
{
rc = mqtt_write(c->sockfd, c->wbuf, len);
}
return rc;
}
static void *mqtt_pub_thread(void *param)
{
MQTTPacket_connectData condata = MQTTPacket_connectData_initializer;
int rc;
unsigned char rbuf[64];
unsigned char wbuf[64];
DEBUG("pub thread start\n");
/* */
_cpub.rbuf = rbuf;
_cpub.rbuflen = sizeof(rbuf);
_cpub.wbuf = wbuf;
_cpub.wbuflen = sizeof(wbuf);
_cpub.getfn = pub_read;
if ((_cpub.sockfd = mqtt_netconnect(HOSTNAME, HOSTPORT)) < 0)
{
DEBUG("pub netconnet fail\n");
return 0;
}
DEBUG("pub connect to: %s %d\n", HOSTNAME, HOSTPORT);
condata.clientID.cstring = "mqttpub";
condata.keepAliveInterval = KEEPALIVE_INTERVAL;
condata.cleansession = 1;
condata.username.cstring = USERNAME;
condata.password.cstring = PASSWORD;
rc = mqtt_connect(&_cpub, &condata);
if (rc < 0)
goto exit;
DEBUG("pub connect ok\n");
mqtt_ping_start(&_cpub.sockfd);
while (rc == 0)
{
mqtt_msg_t msg;
SLEEP(5);
msg.dup = 0;
msg.id = 0;
msg.qos = 0;
msg.retained = 0;
msg.payload = (unsigned char*)"RT-Thread";
msg.payloadlen = strlen((const char*)msg.payload);
rc = mqtt_publish(&_cpub, TOPIC, &msg);
}
exit:
mqtt_netdisconnect(&_cpub.sockfd);
DEBUG("pub thread exit\n");
return 0;
}
void msgprocess(MQTTString *topic, mqtt_msg_t *msg)
{
msg->payload[msg->payloadlen] = 0;
DEBUG("recv: size = %d, msg = %s\n", msg->payloadlen, msg->payload);
}
static void *mqtt_sub_thread(void *param)
{
MQTTPacket_connectData condata = MQTTPacket_connectData_initializer;
int pktype, rc, len;
int failcnt = 0;
unsigned char wbuf[64];
unsigned char rbuf[64];
DEBUG("sub thread start\n");
_csub.wbuf = wbuf;
_csub.wbuflen = sizeof(wbuf);
_csub.rbuf = rbuf;
_csub.rbuflen = sizeof(rbuf);
_csub.getfn = sub_read;
if ((_csub.sockfd = mqtt_netconnect(HOSTNAME, HOSTPORT)) < 0)
{
DEBUG("sub netconnect fail\n");
return 0;
}
DEBUG("sub connect to: %s %d\n", HOSTNAME, HOSTPORT);
condata.clientID.cstring = "mqttsub";
condata.keepAliveInterval = KEEPALIVE_INTERVAL;
condata.cleansession = 1;
condata.username.cstring = USERNAME;
condata.password.cstring = PASSWORD;
rc = mqtt_connect(&_csub, &condata);
if (rc < 0)
goto exit;
DEBUG("sub connect ok\n");
rc = mqtt_subscribe(&_csub, TOPIC, 0);
if (rc < 0)
goto exit;
DEBUG("sub topic: %s\n", TOPIC);
mqtt_ping_start(&_csub.sockfd);
while (1)
{
pktype = MQTTPacket_read(_csub.rbuf, _csub.rbuflen, sub_read);
switch (pktype)
{
case CONNACK:
case PUBACK:
case SUBACK:
break;
case PUBLISH:
{
MQTTString topic;
mqtt_msg_t msg;
if (MQTTDeserialize_publish(&msg.dup, &msg.qos, &msg.retained, &msg.id, &topic,
&msg.payload, &msg.payloadlen, _csub.rbuf, _csub.rbuflen) != 1)
goto exit;
msgprocess(&topic, &msg);
if (msg.qos != 0)
{
if (msg.qos == 1)
len = MQTTSerialize_ack(_csub.wbuf, _csub.wbuflen, PUBACK, 0, msg.id);
else if (msg.qos == 2)
len = MQTTSerialize_ack(_csub.wbuf, _csub.wbuflen, PUBREC, 0, msg.id);
if (len <= 0)
rc = -1;
else
rc = mqtt_write(_csub.sockfd, _csub.wbuf, len);
if (rc == -1)
goto exit;
}
}
break;
case PUBCOMP:
break;
case PINGRESP:
failcnt = 0;
break;
case -1:
if (++failcnt > KEEPALIVE_INTERVAL)
{
/* */
goto exit;
}
break;
}
}
/* */
mqtt_disconnect(&_csub);
exit:
mqtt_netdisconnect(&_csub.sockfd);
DEBUG("sub thread exit\n");
return 0;
}
void mqtt_client_init(void)
{
#if (OS_RTTHREAD == 0)
pthread_t tid;
pthread_create(&tid, NULL, mqtt_sub_thread, NULL);
pthread_create(&tid, NULL, mqtt_pub_thread, NULL);
#else
sys_thread_new("sub",
mqtt_sub_thread,
NULL,
1024,
20);
sys_thread_new("pub",
mqtt_pub_thread,
NULL,
1024,
20);
#endif
}
#ifdef RT_USING_FINSH
#include <finsh.h>
FINSH_FUNCTION_EXPORT(mqtt_client_init, MQTT Pub/Sub Test);
#endif

View File

@ -1,15 +1,12 @@
#include <rtthread.h>
//#include <lwip/netdb.h> /* 为了解析主机名需要包含netdb.h头文件 */
//#include <lwip/sockets.h> /* 使用BSD socket需要包含sockets.h头文件 */
#include <sys/socket.h> /* 使用BSD socket需要包含sockets.h头文件 */
#include <sys/socket.h> /* 使用BSD socket需要包含socket.h头文件 */
#include "netdb.h"
#define BUFSZ 1024
static const char send_data[] = "This is TCP Client from RT-Thread."; /* 发送用到的数据 */
void tcpclient(const char* url, int port)
void tcpclient(const char *url, int port)
{
int ret;
char *recv_data;
@ -57,7 +54,7 @@ void tcpclient(const char* url, int port)
return;
}
while(1)
while (1)
{
/* 从sock连接中接收最大BUFSZ - 1字节数据 */
bytes_received = recv(sock, recv_data, BUFSZ - 1, 0);
@ -75,13 +72,14 @@ void tcpclient(const char* url, int port)
{
/* 打印recv函数返回值为0的警告信息 */
rt_kprintf("\nReceived warning,recv function return 0.\r\n");
continue;
}
/* 有接收到数据,把末端清零 */
recv_data[bytes_received] = '\0';
if (strcmp(recv_data , "q") == 0 || strcmp(recv_data , "Q") == 0)
if (strcmp(recv_data, "q") == 0 || strcmp(recv_data, "Q") == 0)
{
/* 如果是首字母是q或Q关闭这个连接 */
closesocket(sock);
@ -94,11 +92,11 @@ void tcpclient(const char* url, int port)
else
{
/* 在控制终端显示收到的数据 */
rt_kprintf("\nReceived data = %s " , recv_data);
rt_kprintf("\nReceived data = %s ", recv_data);
}
/* 发送数据到sock连接 */
ret = send(sock,send_data,strlen(send_data), 0);
ret = send(sock, send_data, strlen(send_data), 0);
if (ret < 0)
{
/* 接收失败,关闭这个连接 */

View File

@ -1,8 +1,9 @@
#include <rtthread.h>
#include <lwip/netdb.h> /* 为了解析主机名需要包含netdb.h头文件 */
#include <lwip/sockets.h> /* 使用BSD socket需要包含sockets.h头文件 */
void tcp_senddata(const char* url, int port, int length)
#include <netdb.h> /* 为了解析主机名需要包含netdb.h头文件 */
#include <sys/socket.h> /* 使用BSD socket需要包含socket.h头文件 */
void tcp_senddata(const char *url, int port, int length)
{
struct hostent *host;
int sock, err, result, timeout, index;
@ -27,7 +28,7 @@ void tcp_senddata(const char* url, int port, int length)
timeout = 100;
/* 设置发送超时时间100ms */
lwip_setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout));
setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout));
/* 初始化预连接的服务端地址 */
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(port);
@ -38,20 +39,20 @@ void tcp_senddata(const char* url, int port, int length)
err = connect(sock, (struct sockaddr *)&server_addr, sizeof(struct sockaddr));
rt_kprintf("TCP thread connect error code: %d\n", err);
while(1)
while (1)
{
/* 发送数据到sock连接 */
result = send(sock, buffer_ptr, length, MSG_DONTWAIT);
if(result < 0) //数据发送错误处理
if (result < 0) //数据发送错误处理
{
rt_kprintf("TCP thread send error: %d\n", result);
lwip_close(sock);
closesocket(sock);
/* 关闭连接,重新创建连接 */
rt_thread_delay(10);
if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1)
rt_kprintf("TCP Socket error:%d\n",sock);
rt_kprintf("TCP Socket error:%d\n", sock);
err = connect(sock, (struct sockaddr *)&server_addr, sizeof(struct sockaddr));
rt_kprintf("TCP thread connect error code: %d\n", err);

View File

@ -1,140 +1,147 @@
#include <rtthread.h>
//#include <lwip/sockets.h> /* 使用BSD Socket接口必须包含sockets.h这个头文件 */
#include <sys/socket.h> /* 使用BSD socket需要包含sockets.h头文件 */
#include <sys/socket.h> /* 使用BSD socket需要包含socket.h头文件 */
#include "netdb.h"
#define BUFSZ (1024)
static const char send_data[] = "This is TCP Server from RT-Thread."; /* 发送用到的数据 */
void tcpserv(void* parameter)
static void tcpserv(void *parameter)
{
char *recv_data; /* 用于接收的指针,后面会做一次动态分配以请求可用内存 */
rt_uint32_t sin_size;
int sock, connected, bytes_received;
struct sockaddr_in server_addr, client_addr;
rt_bool_t stop = RT_FALSE; /* 停止标志 */
int ret;
char *recv_data; /* 用于接收的指针,后面会做一次动态分配以请求可用内存 */
socklen_t sin_size;
int sock, connected, bytes_received;
struct sockaddr_in server_addr, client_addr;
rt_bool_t stop = RT_FALSE; /* 停止标志 */
int ret;
recv_data = rt_malloc(1024); /* 分配接收用的数据缓冲 */
if (recv_data == RT_NULL)
{
rt_kprintf("No memory\n");
return;
}
recv_data = rt_malloc(BUFSZ + 1); /* 分配接收用的数据缓冲 */
if (recv_data == RT_NULL)
{
rt_kprintf("No memory\n");
return;
}
/* 一个socket在使用前需要预先创建出来指定SOCK_STREAM为TCP的socket */
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1)
{
/* 创建失败的错误处理 */
rt_kprintf("Socket error\n");
/* 一个socket在使用前需要预先创建出来指定SOCK_STREAM为TCP的socket */
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1)
{
/* 创建失败的错误处理 */
rt_kprintf("Socket error\n");
/* 释放已分配的接收缓冲 */
rt_free(recv_data);
return;
}
/* 释放已分配的接收缓冲 */
rt_free(recv_data);
return;
}
/* 初始化服务端地址 */
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(5000); /* 服务端工作的端口 */
server_addr.sin_addr.s_addr = INADDR_ANY;
rt_memset(&(server_addr.sin_zero),8, sizeof(server_addr.sin_zero));
/* 初始化服务端地址 */
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(5000); /* 服务端工作的端口 */
server_addr.sin_addr.s_addr = INADDR_ANY;
rt_memset(&(server_addr.sin_zero), 0, sizeof(server_addr.sin_zero));
/* 绑定socket到服务端地址 */
if (bind(sock, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) == -1)
{
/* 绑定失败 */
rt_kprintf("Unable to bind\n");
/* 绑定socket到服务端地址 */
if (bind(sock, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) == -1)
{
/* 绑定失败 */
rt_kprintf("Unable to bind\n");
/* 释放已分配的接收缓冲 */
rt_free(recv_data);
return;
}
/* 释放已分配的接收缓冲 */
rt_free(recv_data);
return;
}
/* 在socket上进行监听 */
if (listen(sock, 5) == -1)
{
rt_kprintf("Listen error\n");
/* 在socket上进行监听 */
if (listen(sock, 5) == -1)
{
rt_kprintf("Listen error\n");
/* release recv buffer */
rt_free(recv_data);
return;
}
/* release recv buffer */
rt_free(recv_data);
return;
}
rt_kprintf("\nTCPServer Waiting for client on port 5000...\n");
while(stop != RT_TRUE)
{
sin_size = sizeof(struct sockaddr_in);
rt_kprintf("\nTCPServer Waiting for client on port 5000...\n");
while (stop != RT_TRUE)
{
sin_size = sizeof(struct sockaddr_in);
/* 接受一个客户端连接socket的请求这个函数调用是阻塞式的 */
connected = accept(sock, (struct sockaddr *)&client_addr, &sin_size);
/* 返回的是连接成功的socket */
/* 接受一个客户端连接socket的请求这个函数调用是阻塞式的 */
connected = accept(sock, (struct sockaddr *)&client_addr, &sin_size);
/* 返回的是连接成功的socket */
if (connected < 0)
{
rt_kprintf("accept connection failed! errno = %d\n", errno);
continue;
}
/* 接受返回的client_addr指向了客户端的地址信息 */
rt_kprintf("I got a connection from (%s , %d)\n",
inet_ntoa(client_addr.sin_addr),ntohs(client_addr.sin_port));
/* 接受返回的client_addr指向了客户端的地址信息 */
rt_kprintf("I got a connection from (%s , %d)\n",
inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));
/* 客户端连接的处理 */
while (1)
{
/* 发送数据到connected socket */
ret = send(connected, send_data, strlen(send_data), 0);
if (ret < 0)
{
/* 客户端连接的处理 */
while (1)
{
/* 发送数据到connected socket */
ret = send(connected, send_data, strlen(send_data), 0);
if (ret < 0)
{
/* 发送失败,关闭这个连接 */
closesocket(connected);
rt_kprintf("\nsend error,close the socket.\r\n");
break;
}
else if (ret == 0)
{
}
else if (ret == 0)
{
/* 打印send函数返回值为0的警告信息 */
rt_kprintf("\n Send warning,send function return 0.\r\n");
}
}
/* 从connected socket中接收数据接收buffer是1024大小但并不一定能够收到1024大小的数据 */
bytes_received = recv(connected,recv_data, 1024, 0);
if (bytes_received < 0)
{
/* 接收失败关闭这个connected socket */
closesocket(connected);
break;
}
else if (bytes_received == 0)
{
/* 打印recv函数返回值为0的警告信息 */
rt_kprintf("\nReceived warning,recv function return 0.\r\n");
continue;
}
/* 从connected socket中接收数据接收buffer是1024大小但并不一定能够收到1024大小的数据 */
bytes_received = recv(connected, recv_data, BUFSZ, 0);
if (bytes_received < 0)
{
/* 接收失败关闭这个connected socket */
closesocket(connected);
break;
}
else if (bytes_received == 0)
{
/* 打印recv函数返回值为0的警告信息 */
rt_kprintf("\nReceived warning,recv function return 0.\r\n");
closesocket(connected);
break;
}
/* 有接收到数据,把末端清零 */
recv_data[bytes_received] = '\0';
if (strcmp(recv_data , "q") == 0 || strcmp(recv_data , "Q") == 0)
{
/* 如果是首字母是q或Q关闭这个连接 */
closesocket(connected);
break;
}
else if (strcmp(recv_data, "exit") == 0)
{
/* 如果接收的是exit则关闭整个服务端 */
closesocket(connected);
stop = RT_TRUE;
break;
}
else
{
/* 在控制终端显示收到的数据 */
rt_kprintf("RECEIVED DATA = %s \n" , recv_data);
}
}
}
/* 有接收到数据,把末端清零 */
recv_data[bytes_received] = '\0';
if (strcmp(recv_data, "q") == 0 || strcmp(recv_data, "Q") == 0)
{
/* 如果是首字母是q或Q关闭这个连接 */
closesocket(connected);
break;
}
else if (strcmp(recv_data, "exit") == 0)
{
/* 如果接收的是exit则关闭整个服务端 */
closesocket(connected);
stop = RT_TRUE;
break;
}
else
{
/* 在控制终端显示收到的数据 */
rt_kprintf("RECEIVED DATA = %s \n", recv_data);
}
}
}
/* 退出服务 */
closesocket(sock);
/* 退出服务 */
closesocket(sock);
/* 释放接收缓冲 */
rt_free(recv_data);
/* 释放接收缓冲 */
rt_free(recv_data);
return ;
return ;
}
#ifdef RT_USING_FINSH

View File

@ -5,44 +5,44 @@
#include "netdb.h"
const char send_data[] = "This is UDP Client from RT-Thread.\n"; /* 发送用到的数据 */
void udpclient(const char* url, int port, int count)
void udpclient(const char *url, int port, int count)
{
int sock;
struct hostent *host;
struct sockaddr_in server_addr;
int sock;
struct hostent *host;
struct sockaddr_in server_addr;
/* 通过函数入口参数url获得host地址如果是域名会做域名解析 */
host= (struct hostent *) gethostbyname(url);
/* 通过函数入口参数url获得host地址如果是域名会做域名解析 */
host = (struct hostent *) gethostbyname(url);
/* 创建一个socket类型是SOCK_DGRAMUDP类型 */
if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
{
rt_kprintf("Socket error\n");
return;
}
/* 创建一个socket类型是SOCK_DGRAMUDP类型 */
if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
{
rt_kprintf("Socket error\n");
return;
}
/* 初始化预连接的服务端地址 */
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(port);
server_addr.sin_addr = *((struct in_addr *)host->h_addr);
rt_memset(&(server_addr.sin_zero), 0, sizeof(server_addr.sin_zero));
/* 初始化预连接的服务端地址 */
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(port);
server_addr.sin_addr = *((struct in_addr *)host->h_addr);
rt_memset(&(server_addr.sin_zero), 0, sizeof(server_addr.sin_zero));
/* 总计发送count次数据 */
while (count)
{
/* 发送数据到服务远端 */
sendto(sock, send_data, strlen(send_data), 0,
(struct sockaddr *)&server_addr, sizeof(struct sockaddr));
/* 总计发送count次数据 */
while (count)
{
/* 发送数据到服务远端 */
sendto(sock, send_data, strlen(send_data), 0,
(struct sockaddr *)&server_addr, sizeof(struct sockaddr));
/* 线程休眠一段时间 */
rt_thread_delay(50);
/* 线程休眠一段时间 */
rt_thread_delay(50);
/* 计数值减一 */
count --;
}
/* 计数值减一 */
count --;
}
/* 关闭这个socket */
closesocket(sock);
/* 关闭这个socket */
closesocket(sock);
}
#ifdef RT_USING_FINSH

View File

@ -1,85 +1,84 @@
#include <rtthread.h>
//#include <lwip/sockets.h> /* 使用BSD socket需要包含sockets.h头文件 */
#include <sys/socket.h> /* 使用BSD socket需要包含sockets.h头文件 */
#include <sys/socket.h> /* 使用BSD socket需要包含socket.h头文件 */
#include "netdb.h"
#define BUFSZ 1024
#define BUFSZ 1024
void udpserv(void* paramemter)
static void udpserv(void *paramemter)
{
int sock;
int bytes_read;
char *recv_data;
rt_uint32_t addr_len;
struct sockaddr_in server_addr, client_addr;
int sock;
int bytes_read;
char *recv_data;
socklen_t addr_len;
struct sockaddr_in server_addr, client_addr;
/* 分配接收用的数据缓冲 */
recv_data = rt_malloc(BUFSZ);
if (recv_data == RT_NULL)
{
/* 分配内存失败,返回 */
rt_kprintf("No memory\n");
return;
}
/* 分配接收用的数据缓冲 */
recv_data = rt_malloc(BUFSZ);
if (recv_data == RT_NULL)
{
/* 分配内存失败,返回 */
rt_kprintf("No memory\n");
return;
}
/* 创建一个socket类型是SOCK_DGRAMUDP类型 */
if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
{
rt_kprintf("Socket error\n");
/* 创建一个socket类型是SOCK_DGRAMUDP类型 */
if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
{
rt_kprintf("Socket error\n");
/* 释放接收用的数据缓冲 */
rt_free(recv_data);
return;
}
/* 释放接收用的数据缓冲 */
rt_free(recv_data);
return;
}
/* 初始化服务端地址 */
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(5000);
server_addr.sin_addr.s_addr = INADDR_ANY;
rt_memset(&(server_addr.sin_zero),0, sizeof(server_addr.sin_zero));
/* 初始化服务端地址 */
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(5000);
server_addr.sin_addr.s_addr = INADDR_ANY;
rt_memset(&(server_addr.sin_zero), 0, sizeof(server_addr.sin_zero));
/* 绑定socket到服务端地址 */
if (bind(sock,(struct sockaddr *)&server_addr,
sizeof(struct sockaddr)) == -1)
{
/* 绑定地址失败 */
rt_kprintf("Bind error\n");
/* 绑定socket到服务端地址 */
if (bind(sock, (struct sockaddr *)&server_addr,
sizeof(struct sockaddr)) == -1)
{
/* 绑定地址失败 */
rt_kprintf("Bind error\n");
/* 释放接收用的数据缓冲 */
rt_free(recv_data);
return;
}
/* 释放接收用的数据缓冲 */
rt_free(recv_data);
return;
}
addr_len = sizeof(struct sockaddr);
rt_kprintf("UDPServer Waiting for client on port 5000...\n");
addr_len = sizeof(struct sockaddr);
rt_kprintf("UDPServer Waiting for client on port 5000...\n");
while (1)
{
/* 从sock中收取最大BUFSZ - 1字节数据 */
bytes_read = recvfrom(sock, recv_data, BUFSZ - 1, 0,
(struct sockaddr *)&client_addr, &addr_len);
/* UDP不同于TCP它基本不会出现收取的数据失败的情况除非设置了超时等待 */
while (1)
{
/* 从sock中收取最大BUFSZ - 1字节数据 */
bytes_read = recvfrom(sock, recv_data, BUFSZ - 1, 0,
(struct sockaddr *)&client_addr, &addr_len);
/* UDP不同于TCP它基本不会出现收取的数据失败的情况除非设置了超时等待 */
recv_data[bytes_read] = '\0'; /* 把末端清零 */
recv_data[bytes_read] = '\0'; /* 把末端清零 */
/* 输出接收的数据 */
rt_kprintf("\n(%s , %d) said : ",inet_ntoa(client_addr.sin_addr),
ntohs(client_addr.sin_port));
rt_kprintf("%s", recv_data);
/* 输出接收的数据 */
rt_kprintf("\n(%s , %d) said : ", inet_ntoa(client_addr.sin_addr),
ntohs(client_addr.sin_port));
rt_kprintf("%s", recv_data);
/* 如果接收数据是exit退出 */
if (strcmp(recv_data, "exit") == 0)
{
closesocket(sock);
/* 如果接收数据是exit退出 */
if (strcmp(recv_data, "exit") == 0)
{
closesocket(sock);
/* 释放接收用的数据缓冲 */
rt_free(recv_data);
break;
}
}
/* 释放接收用的数据缓冲 */
rt_free(recv_data);
break;
}
}
return;
return;
}
#ifdef RT_USING_FINSH