From ff811a93ff0a834ae3080c435ee216e5b92cd759 Mon Sep 17 00:00:00 2001 From: aozima Date: Tue, 6 Feb 2018 18:19:17 +0800 Subject: [PATCH 1/4] [examples] remove unused old code. --- examples/network/mqttclient.c | 560 ---------------------------------- 1 file changed, 560 deletions(-) delete mode 100644 examples/network/mqttclient.c diff --git a/examples/network/mqttclient.c b/examples/network/mqttclient.c deleted file mode 100644 index 17b049dd93..0000000000 --- a/examples/network/mqttclient.c +++ /dev/null @@ -1,560 +0,0 @@ - -#define OS_RTTHREAD 1 - -#if (OS_RTTHREAD == 0) -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define DEBUG printf -#define SLEEP(x) sleep(x) -#else -#include -#include -#include -#include -#include - -#define DEBUG rt_kprintf -#define SLEEP(x) rt_thread_delay((x)*RT_TICK_PER_SECOND) -#endif - -#include -#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_FUNCTION_EXPORT(mqtt_client_init, MQTT Pub/Sub Test); -#endif From e20fb2f5b2130093191f818d307bb9cc30b0bc28 Mon Sep 17 00:00:00 2001 From: aozima Date: Tue, 6 Feb 2018 18:59:24 +0800 Subject: [PATCH 2/4] [examples] update: 1. cleanup for posix dfs_net. 2. fixed recv buf overwrite. 3. format code. --- examples/network/chargen.c | 49 ++++--- examples/network/tcpclient.c | 16 +-- examples/network/tcpsendpacket.c | 17 +-- examples/network/tcpserver.c | 223 ++++++++++++++++--------------- examples/network/udpclient.c | 60 ++++----- examples/network/udpserver.c | 127 +++++++++--------- 6 files changed, 254 insertions(+), 238 deletions(-) diff --git a/examples/network/chargen.c b/examples/network/chargen.c index f6a2879cbd..7db47da76f 100644 --- a/examples/network/chargen.c +++ b/examples/network/chargen.c @@ -1,7 +1,14 @@ #include -#include -#include -#include +#include + +#ifdef RT_USING_DFS_NET +#include // only dfs_net +#include +#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 void chargen() { - chargen_init(); + chargen_init(); } FINSH_FUNCTION_EXPORT(chargen, start chargen server); #endif diff --git a/examples/network/tcpclient.c b/examples/network/tcpclient.c index a8a9d2959c..20d14baebb 100644 --- a/examples/network/tcpclient.c +++ b/examples/network/tcpclient.c @@ -1,15 +1,12 @@ #include -//#include /* 为了解析主机名,需要包含netdb.h头文件 */ -//#include /* 使用BSD socket,需要包含sockets.h头文件 */ - -#include /* 使用BSD socket,需要包含sockets.h头文件 */ +#include /* 使用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) { /* 接收失败,关闭这个连接 */ diff --git a/examples/network/tcpsendpacket.c b/examples/network/tcpsendpacket.c index e7c514806e..75134c19a2 100644 --- a/examples/network/tcpsendpacket.c +++ b/examples/network/tcpsendpacket.c @@ -1,8 +1,9 @@ #include -#include /* Ϊ˽Ҫnetdb.hͷļ */ -#include /* ʹBSD socketҪsockets.hͷļ */ -void tcp_senddata(const char* url, int port, int length) +#include /* Ϊ˽Ҫnetdb.hͷļ */ +#include /* ʹ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); diff --git a/examples/network/tcpserver.c b/examples/network/tcpserver.c index f07d2cd0e2..97292449a0 100644 --- a/examples/network/tcpserver.c +++ b/examples/network/tcpserver.c @@ -1,140 +1,147 @@ #include -//#include /* 使用BSD Socket接口必须包含sockets.h这个头文件 */ -#include /* 使用BSD socket,需要包含sockets.h头文件 */ +#include /* 使用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 diff --git a/examples/network/udpclient.c b/examples/network/udpclient.c index c19a25fa6c..5060c9a087 100644 --- a/examples/network/udpclient.c +++ b/examples/network/udpclient.c @@ -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_DGRAM,UDP类型 */ - if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) - { - rt_kprintf("Socket error\n"); - return; - } + /* 创建一个socket,类型是SOCK_DGRAM,UDP类型 */ + 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 diff --git a/examples/network/udpserver.c b/examples/network/udpserver.c index 3b5abd976b..a684e9cd0c 100644 --- a/examples/network/udpserver.c +++ b/examples/network/udpserver.c @@ -1,85 +1,84 @@ #include -//#include /* 使用BSD socket,需要包含sockets.h头文件 */ -#include /* 使用BSD socket,需要包含sockets.h头文件 */ + +#include /* 使用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_DGRAM,UDP类型 */ - if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) - { - rt_kprintf("Socket error\n"); + /* 创建一个socket,类型是SOCK_DGRAM,UDP类型 */ + 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 From 19433e0cf5a311ff27e341834675cc218bf34655 Mon Sep 17 00:00:00 2001 From: aozima Date: Tue, 6 Feb 2018 20:07:28 +0800 Subject: [PATCH 3/4] update SConscript: support scons 3. --- bsp/apollo2/rtconfig.py | 6 +++--- bsp/avr32uc3b0/rtconfig.py | 12 ++++++------ bsp/beaglebone/rtconfig.py | 6 +++--- bsp/efm32/rtconfig.py | 12 ++++++------ bsp/frdm-k64f/rtconfig.py | 6 +++--- bsp/gd32450z-eval/SConstruct | 4 ++-- bsp/gd32450z-eval/rtconfig.py | 6 +++--- bsp/lm3s8962/rtconfig.py | 6 +++--- bsp/lm3s9b9x/rtconfig.py | 6 +++--- bsp/lm4f232/rtconfig.py | 6 +++--- bsp/lpc178x/rtconfig.py | 6 +++--- bsp/lpc2148/rtconfig.py | 6 +++--- bsp/lpc2478/rtconfig.py | 6 +++--- bsp/lpc408x/rtconfig.py | 6 +++--- bsp/lpc43xx/M0/SConstruct | 4 ++-- bsp/lpc43xx/M4/SConstruct | 6 +++--- bsp/lpc5410x/rtconfig.py | 6 +++--- bsp/lpc824/rtconfig.py | 6 +++--- bsp/ls1bdev/rtconfig.py | 6 +++--- bsp/ls1cdev/rtconfig.py | 6 +++--- bsp/m16c62p/rtconfig.py | 6 +++--- bsp/mb9bf568r/rtconfig.py | 6 +++--- bsp/mini2440/rtconfig.py | 6 +++--- bsp/mini4020/rtconfig.py | 14 +++++++------- bsp/nrf51822/rtconfig.py | 6 +++--- bsp/nrf52832/rtconfig.py | 6 +++--- bsp/nv32f100x/rtconfig.py | 12 ++++++------ bsp/realview-a8/SConstruct | 2 +- bsp/rm48x50/rtconfig.py | 6 +++--- bsp/sam7x/rtconfig.py | 6 +++--- bsp/samd21/rtconfig.py | 6 +++--- bsp/sep6200/rtconfig.py | 6 +++--- bsp/simulator/SConstruct | 2 +- bsp/simulator/rtconfig.py | 2 +- bsp/stm32f0x/rtconfig.py | 6 +++--- bsp/stm32f40x/SConstruct | 4 ++-- bsp/stm32f40x/rtconfig.py | 6 +++--- bsp/stm32f411-nucleo/SConstruct | 4 ++-- bsp/stm32f429-apollo/SConstruct | 4 ++-- bsp/stm32f429-armfly/SConstruct | 4 ++-- bsp/stm32f429-armfly/rtconfig.py | 6 +++--- bsp/stm32f429-disco/SConstruct | 4 ++-- bsp/stm32f429-disco/rtconfig.py | 6 +++--- bsp/stm32f4xx-HAL/SConstruct | 4 ++-- bsp/stm32f7-disco/SConstruct | 4 ++-- bsp/stm32h743-nucleo/SConstruct | 4 ++-- bsp/stm32l072/rtconfig.py | 12 ++++++------ bsp/stm32l475-iot-disco/SConstruct | 4 ++-- bsp/stm32l475-iot-disco/rtconfig.py | 6 +++--- bsp/stm32l476-nucleo/SConstruct | 4 ++-- bsp/stm32l476-nucleo/rtconfig.py | 6 +++--- bsp/tm4c129x/rtconfig.py | 6 +++--- bsp/upd70f3454/rtconfig.py | 12 ++++++------ bsp/x1000/rtconfig.py | 2 +- bsp/x86/rtconfig.py | 12 ++++++------ bsp/zynq7000/rtconfig.py | 6 +++--- components/dfs/filesystems/romfs/mkromfs.py | 4 ++-- 57 files changed, 172 insertions(+), 172 deletions(-) diff --git a/bsp/apollo2/rtconfig.py b/bsp/apollo2/rtconfig.py index 579c93b17b..354e5f6389 100644 --- a/bsp/apollo2/rtconfig.py +++ b/bsp/apollo2/rtconfig.py @@ -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'): diff --git a/bsp/avr32uc3b0/rtconfig.py b/bsp/avr32uc3b0/rtconfig.py index b6004940d9..a9400c6051 100644 --- a/bsp/avr32uc3b0/rtconfig.py +++ b/bsp/avr32uc3b0/rtconfig.py @@ -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'): diff --git a/bsp/beaglebone/rtconfig.py b/bsp/beaglebone/rtconfig.py index a5561f54d3..6cd0b71505 100644 --- a/bsp/beaglebone/rtconfig.py +++ b/bsp/beaglebone/rtconfig.py @@ -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'): diff --git a/bsp/efm32/rtconfig.py b/bsp/efm32/rtconfig.py index b412851de4..b1bd8330bb 100644 --- a/bsp/efm32/rtconfig.py +++ b/bsp/efm32/rtconfig.py @@ -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'): diff --git a/bsp/frdm-k64f/rtconfig.py b/bsp/frdm-k64f/rtconfig.py index baaf4905fa..009b4b71fb 100644 --- a/bsp/frdm-k64f/rtconfig.py +++ b/bsp/frdm-k64f/rtconfig.py @@ -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'): diff --git a/bsp/gd32450z-eval/SConstruct b/bsp/gd32450z-eval/SConstruct index 42ae8c9646..27ac9b0241 100644 --- a/bsp/gd32450z-eval/SConstruct +++ b/bsp/gd32450z-eval/SConstruct @@ -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 diff --git a/bsp/gd32450z-eval/rtconfig.py b/bsp/gd32450z-eval/rtconfig.py index 70ffabba2f..af754e3c75 100644 --- a/bsp/gd32450z-eval/rtconfig.py +++ b/bsp/gd32450z-eval/rtconfig.py @@ -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' diff --git a/bsp/lm3s8962/rtconfig.py b/bsp/lm3s8962/rtconfig.py index 0a0c98a71d..829120bd3a 100644 --- a/bsp/lm3s8962/rtconfig.py +++ b/bsp/lm3s8962/rtconfig.py @@ -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'): diff --git a/bsp/lm3s9b9x/rtconfig.py b/bsp/lm3s9b9x/rtconfig.py index f806ec1e19..d9c51ac722 100644 --- a/bsp/lm3s9b9x/rtconfig.py +++ b/bsp/lm3s9b9x/rtconfig.py @@ -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'): diff --git a/bsp/lm4f232/rtconfig.py b/bsp/lm4f232/rtconfig.py index cfe518891b..5e6075ead5 100644 --- a/bsp/lm4f232/rtconfig.py +++ b/bsp/lm4f232/rtconfig.py @@ -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'): diff --git a/bsp/lpc178x/rtconfig.py b/bsp/lpc178x/rtconfig.py index a0b4243081..a5302bb36f 100644 --- a/bsp/lpc178x/rtconfig.py +++ b/bsp/lpc178x/rtconfig.py @@ -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'): diff --git a/bsp/lpc2148/rtconfig.py b/bsp/lpc2148/rtconfig.py index 2c44325803..57f7ee46da 100644 --- a/bsp/lpc2148/rtconfig.py +++ b/bsp/lpc2148/rtconfig.py @@ -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'): diff --git a/bsp/lpc2478/rtconfig.py b/bsp/lpc2478/rtconfig.py index 5e99582469..7464fa0dc4 100644 --- a/bsp/lpc2478/rtconfig.py +++ b/bsp/lpc2478/rtconfig.py @@ -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'): diff --git a/bsp/lpc408x/rtconfig.py b/bsp/lpc408x/rtconfig.py index a2a6fac53f..ba797aab63 100644 --- a/bsp/lpc408x/rtconfig.py +++ b/bsp/lpc408x/rtconfig.py @@ -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'): diff --git a/bsp/lpc43xx/M0/SConstruct b/bsp/lpc43xx/M0/SConstruct index c7967d02f6..c0d1d2fdc0 100644 --- a/bsp/lpc43xx/M0/SConstruct +++ b/bsp/lpc43xx/M0/SConstruct @@ -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 diff --git a/bsp/lpc43xx/M4/SConstruct b/bsp/lpc43xx/M4/SConstruct index 7b02b732d4..a6390025a3 100644 --- a/bsp/lpc43xx/M4/SConstruct +++ b/bsp/lpc43xx/M4/SConstruct @@ -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 diff --git a/bsp/lpc5410x/rtconfig.py b/bsp/lpc5410x/rtconfig.py index 555a1b4962..3c0e37fe07 100644 --- a/bsp/lpc5410x/rtconfig.py +++ b/bsp/lpc5410x/rtconfig.py @@ -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'): diff --git a/bsp/lpc824/rtconfig.py b/bsp/lpc824/rtconfig.py index 7fb0a2e110..906729dfb9 100644 --- a/bsp/lpc824/rtconfig.py +++ b/bsp/lpc824/rtconfig.py @@ -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' diff --git a/bsp/ls1bdev/rtconfig.py b/bsp/ls1bdev/rtconfig.py index 70077e64ce..4dcbf0bd75 100644 --- a/bsp/ls1bdev/rtconfig.py +++ b/bsp/ls1bdev/rtconfig.py @@ -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'): diff --git a/bsp/ls1cdev/rtconfig.py b/bsp/ls1cdev/rtconfig.py index c08dfc6852..4bf85c0993 100644 --- a/bsp/ls1cdev/rtconfig.py +++ b/bsp/ls1cdev/rtconfig.py @@ -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'): diff --git a/bsp/m16c62p/rtconfig.py b/bsp/m16c62p/rtconfig.py index 494f52ff76..5fb198af6c 100644 --- a/bsp/m16c62p/rtconfig.py +++ b/bsp/m16c62p/rtconfig.py @@ -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'): diff --git a/bsp/mb9bf568r/rtconfig.py b/bsp/mb9bf568r/rtconfig.py index 82cf6acf38..abee5014b2 100644 --- a/bsp/mb9bf568r/rtconfig.py +++ b/bsp/mb9bf568r/rtconfig.py @@ -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'): diff --git a/bsp/mini2440/rtconfig.py b/bsp/mini2440/rtconfig.py index bdd11aafef..969cd7fa82 100644 --- a/bsp/mini2440/rtconfig.py +++ b/bsp/mini2440/rtconfig.py @@ -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'): diff --git a/bsp/mini4020/rtconfig.py b/bsp/mini4020/rtconfig.py index 9d7b859db8..be8e4535c7 100644 --- a/bsp/mini4020/rtconfig.py +++ b/bsp/mini4020/rtconfig.py @@ -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'): diff --git a/bsp/nrf51822/rtconfig.py b/bsp/nrf51822/rtconfig.py index 3e9c68fed8..654730708e 100644 --- a/bsp/nrf51822/rtconfig.py +++ b/bsp/nrf51822/rtconfig.py @@ -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'): diff --git a/bsp/nrf52832/rtconfig.py b/bsp/nrf52832/rtconfig.py index 5e40e7201e..1775b4ab4b 100644 --- a/bsp/nrf52832/rtconfig.py +++ b/bsp/nrf52832/rtconfig.py @@ -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'): diff --git a/bsp/nv32f100x/rtconfig.py b/bsp/nv32f100x/rtconfig.py index 6927eee3ab..bf568e19b7 100644 --- a/bsp/nv32f100x/rtconfig.py +++ b/bsp/nv32f100x/rtconfig.py @@ -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'): diff --git a/bsp/realview-a8/SConstruct b/bsp/realview-a8/SConstruct index 6d57bc4025..67ae413023 100644 --- a/bsp/realview-a8/SConstruct +++ b/bsp/realview-a8/SConstruct @@ -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) diff --git a/bsp/rm48x50/rtconfig.py b/bsp/rm48x50/rtconfig.py index b5e3664dbd..e0899cf38e 100644 --- a/bsp/rm48x50/rtconfig.py +++ b/bsp/rm48x50/rtconfig.py @@ -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'): diff --git a/bsp/sam7x/rtconfig.py b/bsp/sam7x/rtconfig.py index 565120bfed..761c1b9b6f 100644 --- a/bsp/sam7x/rtconfig.py +++ b/bsp/sam7x/rtconfig.py @@ -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'): diff --git a/bsp/samd21/rtconfig.py b/bsp/samd21/rtconfig.py index edd1d7358d..9b4743a20c 100644 --- a/bsp/samd21/rtconfig.py +++ b/bsp/samd21/rtconfig.py @@ -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'): diff --git a/bsp/sep6200/rtconfig.py b/bsp/sep6200/rtconfig.py index 58b05417ad..53384875c9 100644 --- a/bsp/sep6200/rtconfig.py +++ b/bsp/sep6200/rtconfig.py @@ -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'): diff --git a/bsp/simulator/SConstruct b/bsp/simulator/SConstruct index 4283082d04..d433039bba 100755 --- a/bsp/simulator/SConstruct +++ b/bsp/simulator/SConstruct @@ -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 diff --git a/bsp/simulator/rtconfig.py b/bsp/simulator/rtconfig.py index c62b24ea93..915cc3f686 100755 --- a/bsp/simulator/rtconfig.py +++ b/bsp/simulator/rtconfig.py @@ -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'): diff --git a/bsp/stm32f0x/rtconfig.py b/bsp/stm32f0x/rtconfig.py index 790e6215ed..659b664723 100644 --- a/bsp/stm32f0x/rtconfig.py +++ b/bsp/stm32f0x/rtconfig.py @@ -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'): diff --git a/bsp/stm32f40x/SConstruct b/bsp/stm32f40x/SConstruct index 99c2876aab..ea1e8bf447 100644 --- a/bsp/stm32f40x/SConstruct +++ b/bsp/stm32f40x/SConstruct @@ -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 diff --git a/bsp/stm32f40x/rtconfig.py b/bsp/stm32f40x/rtconfig.py index 3438597ee6..1df6020628 100644 --- a/bsp/stm32f40x/rtconfig.py +++ b/bsp/stm32f40x/rtconfig.py @@ -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'): diff --git a/bsp/stm32f411-nucleo/SConstruct b/bsp/stm32f411-nucleo/SConstruct index b4d12cc06b..4921ba69bc 100644 --- a/bsp/stm32f411-nucleo/SConstruct +++ b/bsp/stm32f411-nucleo/SConstruct @@ -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 diff --git a/bsp/stm32f429-apollo/SConstruct b/bsp/stm32f429-apollo/SConstruct index ac3196e370..ea6c96c0a8 100644 --- a/bsp/stm32f429-apollo/SConstruct +++ b/bsp/stm32f429-apollo/SConstruct @@ -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 diff --git a/bsp/stm32f429-armfly/SConstruct b/bsp/stm32f429-armfly/SConstruct index ac3196e370..ea6c96c0a8 100644 --- a/bsp/stm32f429-armfly/SConstruct +++ b/bsp/stm32f429-armfly/SConstruct @@ -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 diff --git a/bsp/stm32f429-armfly/rtconfig.py b/bsp/stm32f429-armfly/rtconfig.py index 50b58434d9..ece5a363fb 100644 --- a/bsp/stm32f429-armfly/rtconfig.py +++ b/bsp/stm32f429-armfly/rtconfig.py @@ -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'): diff --git a/bsp/stm32f429-disco/SConstruct b/bsp/stm32f429-disco/SConstruct index ac3196e370..ea6c96c0a8 100644 --- a/bsp/stm32f429-disco/SConstruct +++ b/bsp/stm32f429-disco/SConstruct @@ -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 diff --git a/bsp/stm32f429-disco/rtconfig.py b/bsp/stm32f429-disco/rtconfig.py index 312b46052c..40d5f3c805 100644 --- a/bsp/stm32f429-disco/rtconfig.py +++ b/bsp/stm32f429-disco/rtconfig.py @@ -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'): diff --git a/bsp/stm32f4xx-HAL/SConstruct b/bsp/stm32f4xx-HAL/SConstruct index 99c2876aab..ea1e8bf447 100644 --- a/bsp/stm32f4xx-HAL/SConstruct +++ b/bsp/stm32f4xx-HAL/SConstruct @@ -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 diff --git a/bsp/stm32f7-disco/SConstruct b/bsp/stm32f7-disco/SConstruct index af8f4a90b2..edbf0c62b8 100644 --- a/bsp/stm32f7-disco/SConstruct +++ b/bsp/stm32f7-disco/SConstruct @@ -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 diff --git a/bsp/stm32h743-nucleo/SConstruct b/bsp/stm32h743-nucleo/SConstruct index 1e2018c543..dae244260a 100644 --- a/bsp/stm32h743-nucleo/SConstruct +++ b/bsp/stm32h743-nucleo/SConstruct @@ -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 diff --git a/bsp/stm32l072/rtconfig.py b/bsp/stm32l072/rtconfig.py index a8f00d12da..8796a79b60 100644 --- a/bsp/stm32l072/rtconfig.py +++ b/bsp/stm32l072/rtconfig.py @@ -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'): diff --git a/bsp/stm32l475-iot-disco/SConstruct b/bsp/stm32l475-iot-disco/SConstruct index ac3196e370..ea6c96c0a8 100644 --- a/bsp/stm32l475-iot-disco/SConstruct +++ b/bsp/stm32l475-iot-disco/SConstruct @@ -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 diff --git a/bsp/stm32l475-iot-disco/rtconfig.py b/bsp/stm32l475-iot-disco/rtconfig.py index 50b58434d9..ece5a363fb 100644 --- a/bsp/stm32l475-iot-disco/rtconfig.py +++ b/bsp/stm32l475-iot-disco/rtconfig.py @@ -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'): diff --git a/bsp/stm32l476-nucleo/SConstruct b/bsp/stm32l476-nucleo/SConstruct index 1a32356531..063261ea93 100644 --- a/bsp/stm32l476-nucleo/SConstruct +++ b/bsp/stm32l476-nucleo/SConstruct @@ -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 diff --git a/bsp/stm32l476-nucleo/rtconfig.py b/bsp/stm32l476-nucleo/rtconfig.py index 3b863008b2..43fad6104b 100644 --- a/bsp/stm32l476-nucleo/rtconfig.py +++ b/bsp/stm32l476-nucleo/rtconfig.py @@ -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'): diff --git a/bsp/tm4c129x/rtconfig.py b/bsp/tm4c129x/rtconfig.py index d92c9f1101..9b8b95a402 100644 --- a/bsp/tm4c129x/rtconfig.py +++ b/bsp/tm4c129x/rtconfig.py @@ -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'): diff --git a/bsp/upd70f3454/rtconfig.py b/bsp/upd70f3454/rtconfig.py index ad1565251d..e25c81cfc7 100644 --- a/bsp/upd70f3454/rtconfig.py +++ b/bsp/upd70f3454/rtconfig.py @@ -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'): diff --git a/bsp/x1000/rtconfig.py b/bsp/x1000/rtconfig.py index 331639b2e7..b935d7bc4e 100644 --- a/bsp/x1000/rtconfig.py +++ b/bsp/x1000/rtconfig.py @@ -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'): diff --git a/bsp/x86/rtconfig.py b/bsp/x86/rtconfig.py index c602315d06..b833f4de49 100644 --- a/bsp/x86/rtconfig.py +++ b/bsp/x86/rtconfig.py @@ -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'): diff --git a/bsp/zynq7000/rtconfig.py b/bsp/zynq7000/rtconfig.py index 45889fb7a5..33e6442073 100644 --- a/bsp/zynq7000/rtconfig.py +++ b/bsp/zynq7000/rtconfig.py @@ -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'): diff --git a/components/dfs/filesystems/romfs/mkromfs.py b/components/dfs/filesystems/romfs/mkromfs.py index 9917cf85b9..f3c12876d2 100644 --- a/components/dfs/filesystems/romfs/mkromfs.py +++ b/components/dfs/filesystems/romfs/mkromfs.py @@ -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) From cd74a4be476965b882bb9fac89cf5d2f13ed7c3e Mon Sep 17 00:00:00 2001 From: aozima Date: Tue, 6 Feb 2018 20:26:49 +0800 Subject: [PATCH 4/4] [drivers] move tf/sd card driver to spi/spi/spi_msd.c, and update Kconfig script. --- bsp/stm32f107/drivers/SConscript | 1 - bsp/stm32f107/drivers/platform.c | 8 ++++---- components/drivers/Kconfig | 5 +++++ components/drivers/spi/SConscript | 5 ++++- .../drivers/msd.c => components/drivers/spi/spi_msd.c | 4 ++-- .../drivers/msd.h => components/drivers/spi/spi_msd.h | 6 +++--- 6 files changed, 18 insertions(+), 11 deletions(-) rename bsp/stm32f107/drivers/msd.c => components/drivers/spi/spi_msd.c (99%) rename bsp/stm32f107/drivers/msd.h => components/drivers/spi/spi_msd.h (98%) diff --git a/bsp/stm32f107/drivers/SConscript b/bsp/stm32f107/drivers/SConscript index 0bdb61e301..43d7f2c19c 100644 --- a/bsp/stm32f107/drivers/SConscript +++ b/bsp/stm32f107/drivers/SConscript @@ -18,7 +18,6 @@ if GetDepend('RT_USING_LWIP'): if GetDepend('RT_USING_SPI'): src += ['rt_stm32f10x_spi.c'] - src += ['msd.c'] CPPPATH = [cwd] diff --git a/bsp/stm32f107/drivers/platform.c b/bsp/stm32f107/drivers/platform.c index a429e232a9..830b9a4c55 100644 --- a/bsp/stm32f107/drivers/platform.c +++ b/bsp/stm32f107/drivers/platform.c @@ -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 diff --git a/components/drivers/Kconfig b/components/drivers/Kconfig index dcd23715b0..9f4147f9fd 100755 --- a/components/drivers/Kconfig +++ b/components/drivers/Kconfig @@ -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 diff --git a/components/drivers/spi/SConscript b/components/drivers/spi/SConscript index 01cc608c2b..ee423c33db 100644 --- a/components/drivers/spi/SConscript +++ b/components/drivers/spi/SConscript @@ -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'] diff --git a/bsp/stm32f107/drivers/msd.c b/components/drivers/spi/spi_msd.c similarity index 99% rename from bsp/stm32f107/drivers/msd.c rename to components/drivers/spi/spi_msd.c index dc04804039..cd278df0c2 100644 --- a/bsp/stm32f107/drivers/msd.c +++ b/components/drivers/spi/spi_msd.c @@ -18,7 +18,7 @@ */ #include -#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 diff --git a/bsp/stm32f107/drivers/msd.h b/components/drivers/spi/spi_msd.h similarity index 98% rename from bsp/stm32f107/drivers/msd.h rename to components/drivers/spi/spi_msd.h index e004944332..98722711d3 100644 --- a/bsp/stm32f107/drivers/msd.h +++ b/components/drivers/spi/spi_msd.h @@ -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 #include @@ -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