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

@ -11,17 +11,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 == '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

@ -29,6 +29,9 @@ 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>
#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 */
@ -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,6 +132,7 @@ static void chargen_thread(void *arg)
if (do_read(p_charcb) < 0)
break;
}
if (FD_ISSET(p_charcb->socket, &writeset))
{
char line[80];
@ -135,6 +144,7 @@ static void chargen_thread(void *arg)
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;
}

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,9 +1,6 @@
#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
@ -75,6 +72,7 @@ void tcpclient(const char* url, int port)
{
/* 打印recv函数返回值为0的警告信息 */
rt_kprintf("\nReceived warning,recv function return 0.\r\n");
continue;
}

View File

@ -1,6 +1,7 @@
#include <rtthread.h>
#include <lwip/netdb.h> /* 为了解析主机名需要包含netdb.h头文件 */
#include <lwip/sockets.h> /* 使用BSD socket需要包含sockets.h头文件 */
#include <netdb.h> /* 为了解析主机名需要包含netdb.h头文件 */
#include <sys/socket.h> /* 使用BSD socket需要包含socket.h头文件 */
void tcp_senddata(const char *url, int port, int length)
{
@ -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);
@ -45,7 +46,7 @@ void tcp_senddata(const char* url, int port, int length)
if (result < 0) //数据发送错误处理
{
rt_kprintf("TCP thread send error: %d\n", result);
lwip_close(sock);
closesocket(sock);
/* 关闭连接,重新创建连接 */
rt_thread_delay(10);

View File

@ -1,20 +1,21 @@
#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;
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); /* 分配接收用的数据缓冲 */
recv_data = rt_malloc(BUFSZ + 1); /* 分配接收用的数据缓冲 */
if (recv_data == RT_NULL)
{
rt_kprintf("No memory\n");
@ -36,7 +37,7 @@ void tcpserv(void* parameter)
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));
rt_memset(&(server_addr.sin_zero), 0, sizeof(server_addr.sin_zero));
/* 绑定socket到服务端地址 */
if (bind(sock, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) == -1)
@ -67,6 +68,11 @@ void tcpserv(void* parameter)
/* 接受一个客户端连接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",
@ -91,7 +97,7 @@ void tcpserv(void* parameter)
}
/* 从connected socket中接收数据接收buffer是1024大小但并不一定能够收到1024大小的数据 */
bytes_received = recv(connected,recv_data, 1024, 0);
bytes_received = recv(connected, recv_data, BUFSZ, 0);
if (bytes_received < 0)
{
/* 接收失败关闭这个connected socket */
@ -102,7 +108,8 @@ void tcpserv(void* parameter)
{
/* 打印recv函数返回值为0的警告信息 */
rt_kprintf("\nReceived warning,recv function return 0.\r\n");
continue;
closesocket(connected);
break;
}
/* 有接收到数据,把末端清零 */

View File

@ -1,17 +1,16 @@
#include <rtthread.h>
//#include <lwip/sockets.h> /* 使用BSD socket需要包含sockets.h头文件 */
#include <sys/socket.h> /* 使用BSD socket需要包含sockets.h头文件 */
#include "netdb.h"
#include <sys/socket.h> /* 使用BSD socket需要包含socket.h头文件 */
#include "netdb.h"
#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;
socklen_t addr_len;
struct sockaddr_in server_addr, client_addr;
/* 分配接收用的数据缓冲 */