diff --git a/.ignore_format.yml b/.ignore_format.yml index 4a0e8bbec7..5af47eedd4 100644 --- a/.ignore_format.yml +++ b/.ignore_format.yml @@ -1,4 +1,4 @@ -# files format check exclude path, please follow the instructions below to modify; +# files format check exclude path, please follow the instructions below to modify; # If you need to exclude an entire folder, add the folder path in dir_path; # If you need to exclude a file, add the path to the file in file_path. @@ -6,4 +6,7 @@ file_path: - bsp/allwinner_tina/libcpu/cpu.c dir_path: -- tools \ No newline at end of file +- tools +- components/net/lwip-1.4.1 +- components/net/lwip-2.0.2 +- components/net/lwip-2.1.2 \ No newline at end of file diff --git a/components/drivers/sdio/mmc.c b/components/drivers/sdio/mmc.c index 5aba3dba7a..d8f3a9e0a5 100644 --- a/components/drivers/sdio/mmc.c +++ b/components/drivers/sdio/mmc.c @@ -300,7 +300,7 @@ static int mmc_select_bus_width(struct rt_mmcsd_card *card, rt_uint8_t *ext_csd) MMCSD_BUS_WIDTH_1 }; struct rt_mmcsd_host *host = card->host; - unsigned idx, bus_width = 0; + unsigned idx, trys, bus_width = 0; int err = 0; if (GET_BITS(card->resp_cid, 122, 4) < 4) @@ -335,10 +335,13 @@ static int mmc_select_bus_width(struct rt_mmcsd_card *card, rt_uint8_t *ext_csd) if (err) continue; - bus_width = bus_widths[idx]; - mmcsd_set_bus_width(host, bus_width); - mmcsd_delay_ms(20); //delay 10ms - err = mmc_compare_ext_csds(card, ext_csd, bus_width); + for(trys = 0; trys < 5; trys++){ + mmcsd_set_bus_width(host, bus_width); + mmcsd_delay_ms(10); + err = mmc_compare_ext_csds(card, ext_csd, bus_width); + if(!err) + break; + } if (!err) { err = bus_width; break; diff --git a/components/net/lwip-1.4.1/src/include/netif/ethernetif.h b/components/net/lwip-1.4.1/src/include/netif/ethernetif.h index 1c969e6e25..650ad32eff 100644 --- a/components/net/lwip-1.4.1/src/include/netif/ethernetif.h +++ b/components/net/lwip-1.4.1/src/include/netif/ethernetif.h @@ -27,6 +27,7 @@ struct eth_device rt_uint16_t flags; rt_uint8_t link_changed; rt_uint8_t link_status; + rt_uint8_t rx_notice; /* eth device interface */ struct pbuf* (*eth_rx)(rt_device_t dev); diff --git a/components/net/lwip-1.4.1/src/netif/ethernetif.c b/components/net/lwip-1.4.1/src/netif/ethernetif.c index f2570f9e2b..4565f5e528 100644 --- a/components/net/lwip-1.4.1/src/netif/ethernetif.c +++ b/components/net/lwip-1.4.1/src/netif/ethernetif.c @@ -156,16 +156,16 @@ static int lwip_netdev_set_dns_server(struct netdev *netif, uint8_t dns_num, ip_ static int lwip_netdev_set_dhcp(struct netdev *netif, rt_bool_t is_enabled) { netdev_low_level_set_dhcp_status(netif, is_enabled); - + if(RT_TRUE == is_enabled) { dhcp_start((struct netif *)netif->user_data); } else { - dhcp_stop((struct netif *)netif->user_data); + dhcp_stop((struct netif *)netif->user_data); } - + return ERR_OK; } #endif /* RT_LWIP_DHCP */ @@ -469,6 +469,8 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_ dev->flags = flags; /* link changed status of device */ dev->link_changed = 0x00; + /* avoid send the same mail to mailbox */ + dev->rx_notice = 0x00; dev->parent.type = RT_Device_Class_NetIf; /* register to RT-Thread device manager */ rt_device_register(&(dev->parent), name, RT_DEVICE_FLAG_RDWR); @@ -550,10 +552,18 @@ rt_err_t eth_device_init(struct eth_device * dev, const char *name) rt_err_t eth_device_ready(struct eth_device* dev) { if (dev->netif) + { + if(dev->rx_notice == RT_FALSE) + { + dev->rx_notice = RT_TRUE; + return rt_mb_send(ð_rx_thread_mb, (rt_uint32_t)dev); + } + else + return RT_EOK; /* post message to Ethernet thread */ - return rt_mb_send(ð_rx_thread_mb, (rt_uint32_t)dev); + } else - return ERR_OK; /* netif is not initialized yet, just return. */ + return -RT_ERROR; /* netif is not initialized yet, just return. */ } rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up) @@ -628,6 +638,7 @@ static void eth_rx_thread_entry(void* parameter) { if (rt_mb_recv(ð_rx_thread_mb, (rt_ubase_t*)&device, RT_WAITING_FOREVER) == RT_EOK) { + rt_base_t level; struct pbuf *p; /* check link status */ @@ -647,8 +658,13 @@ static void eth_rx_thread_entry(void* parameter) netifapi_netif_set_link_down(device->netif); } + level = rt_hw_interrupt_disable(); + /* 'rx_notice' will be modify in the interrupt or here */ + device->rx_notice = RT_FALSE; + rt_hw_interrupt_enable(level); + /* receive all of buffer */ - while (1) + while(1) { if(device->eth_rx == RT_NULL) break; diff --git a/components/net/lwip-2.0.2/src/include/netif/ethernetif.h b/components/net/lwip-2.0.2/src/include/netif/ethernetif.h index 244bafdd1b..1459e3241d 100644 --- a/components/net/lwip-2.0.2/src/include/netif/ethernetif.h +++ b/components/net/lwip-2.0.2/src/include/netif/ethernetif.h @@ -27,6 +27,7 @@ struct eth_device rt_uint16_t flags; rt_uint8_t link_changed; rt_uint8_t link_status; + rt_uint8_t rx_notice; /* eth device interface */ struct pbuf* (*eth_rx)(rt_device_t dev); diff --git a/components/net/lwip-2.0.2/src/netif/ethernetif.c b/components/net/lwip-2.0.2/src/netif/ethernetif.c index b93acb1fcf..1c0f3ca9b2 100644 --- a/components/net/lwip-2.0.2/src/netif/ethernetif.c +++ b/components/net/lwip-2.0.2/src/netif/ethernetif.c @@ -173,7 +173,7 @@ static int lwip_netdev_set_dhcp(struct netdev *netif, rt_bool_t is_enabled) } else { - dhcp_stop((struct netif *)netif->user_data); + dhcp_stop((struct netif *)netif->user_data); } return ERR_OK; } @@ -511,6 +511,8 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_ dev->flags = flags; /* link changed status of device */ dev->link_changed = 0x00; + /* avoid send the same mail to mailbox */ + dev->rx_notice = 0x00; dev->parent.type = RT_Device_Class_NetIf; /* register to RT-Thread device manager */ rt_device_register(&(dev->parent), name, RT_DEVICE_FLAG_RDWR); @@ -599,10 +601,18 @@ void eth_device_deinit(struct eth_device *dev) rt_err_t eth_device_ready(struct eth_device* dev) { if (dev->netif) + { + if(dev->rx_notice == RT_FALSE) + { + dev->rx_notice = RT_TRUE; + return rt_mb_send(ð_rx_thread_mb, (rt_uint32_t)dev); + } + else + return RT_EOK; /* post message to Ethernet thread */ - return rt_mb_send(ð_rx_thread_mb, (rt_ubase_t)dev); + } else - return ERR_OK; /* netif is not initialized yet, just return. */ + return -RT_ERROR; /* netif is not initialized yet, just return. */ } rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up) @@ -677,6 +687,7 @@ static void eth_rx_thread_entry(void* parameter) { if (rt_mb_recv(ð_rx_thread_mb, (rt_ubase_t *)&device, RT_WAITING_FOREVER) == RT_EOK) { + rt_base_t level; struct pbuf *p; /* check link status */ @@ -696,8 +707,13 @@ static void eth_rx_thread_entry(void* parameter) netifapi_netif_set_link_down(device->netif); } + level = rt_hw_interrupt_disable(); + /* 'rx_notice' will be modify in the interrupt or here */ + device->rx_notice = RT_FALSE; + rt_hw_interrupt_enable(level); + /* receive all of buffer */ - while (1) + while(1) { if(device->eth_rx == RT_NULL) break; diff --git a/components/net/lwip-2.1.2/src/include/netif/ethernetif.h b/components/net/lwip-2.1.2/src/include/netif/ethernetif.h index 244bafdd1b..1459e3241d 100644 --- a/components/net/lwip-2.1.2/src/include/netif/ethernetif.h +++ b/components/net/lwip-2.1.2/src/include/netif/ethernetif.h @@ -27,6 +27,7 @@ struct eth_device rt_uint16_t flags; rt_uint8_t link_changed; rt_uint8_t link_status; + rt_uint8_t rx_notice; /* eth device interface */ struct pbuf* (*eth_rx)(rt_device_t dev); diff --git a/components/net/lwip-2.1.2/src/netif/ethernetif.c b/components/net/lwip-2.1.2/src/netif/ethernetif.c index 52bd0fb7b6..81dd792f29 100644 --- a/components/net/lwip-2.1.2/src/netif/ethernetif.c +++ b/components/net/lwip-2.1.2/src/netif/ethernetif.c @@ -514,6 +514,8 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_ dev->flags = flags; /* link changed status of device */ dev->link_changed = 0x00; + /* avoid send the same mail to mailbox */ + dev->rx_notice = 0x00; dev->parent.type = RT_Device_Class_NetIf; /* register to RT-Thread device manager */ rt_device_register(&(dev->parent), name, RT_DEVICE_FLAG_RDWR); @@ -601,10 +603,18 @@ void eth_device_deinit(struct eth_device *dev) rt_err_t eth_device_ready(struct eth_device* dev) { if (dev->netif) + { + if(dev->rx_notice == RT_FALSE) + { + dev->rx_notice = RT_TRUE; + return rt_mb_send(ð_rx_thread_mb, (rt_uint32_t)dev); + } + else + return RT_EOK; /* post message to Ethernet thread */ - return rt_mb_send(ð_rx_thread_mb, (rt_uint32_t)dev); + } else - return ERR_OK; /* netif is not initialized yet, just return. */ + return -RT_ERROR; /* netif is not initialized yet, just return. */ } rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up) @@ -679,6 +689,7 @@ static void eth_rx_thread_entry(void* parameter) { if (rt_mb_recv(ð_rx_thread_mb, (rt_ubase_t *)&device, RT_WAITING_FOREVER) == RT_EOK) { + rt_base_t level; struct pbuf *p; /* check link status */ @@ -698,6 +709,11 @@ static void eth_rx_thread_entry(void* parameter) netifapi_netif_set_link_down(device->netif); } + level = rt_hw_interrupt_disable(); + /* 'rx_notice' will be modify in the interrupt or here */ + device->rx_notice = RT_FALSE; + rt_hw_interrupt_enable(level); + /* receive all of buffer */ while (1) { diff --git a/components/utilities/ymodem/ry_sy.c b/components/utilities/ymodem/ry_sy.c index a87f6949db..caad51d6cd 100644 --- a/components/utilities/ymodem/ry_sy.c +++ b/components/utilities/ymodem/ry_sy.c @@ -6,6 +6,7 @@ * Change Logs: * Date Author Notes * 2019-12-09 Steven Liu the first version + * 2021-04-14 Meco Man Check the file path's legitimacy of 'sy' command */ #include @@ -219,6 +220,12 @@ static rt_err_t sy(uint8_t argc, char **argv) const char *file_path; rt_device_t dev; + if (argc < 2) + { + rt_kprintf("invalid file path.\n"); + return -RT_ERROR; + } + if (argc > 2) dev = rt_device_find(argv[2]); else diff --git a/tools/cmake.py b/tools/cmake.py index 5e17643a14..645bdbb229 100644 --- a/tools/cmake.py +++ b/tools/cmake.py @@ -15,8 +15,9 @@ def GenerateCFiles(env,project): """ info = utils.ProjectInfo(env) - + CC = os.path.join(rtconfig.EXEC_PATH, rtconfig.CC) + CXX = os.path.join(rtconfig.EXEC_PATH, rtconfig.CXX) AS = os.path.join(rtconfig.EXEC_PATH, rtconfig.AS) AR = os.path.join(rtconfig.EXEC_PATH, rtconfig.AR) LINK = os.path.join(rtconfig.EXEC_PATH, rtconfig.LINK) @@ -28,20 +29,24 @@ def GenerateCFiles(env,project): if cm_file: cm_file.write("CMAKE_MINIMUM_REQUIRED(VERSION 3.10)\n\n") - cm_file.write("PROJECT(rtthread C ASM)\n") cm_file.write("SET(CMAKE_SYSTEM_NAME Generic)\n") cm_file.write("#SET(CMAKE_VERBOSE_MAKEFILE ON)\n\n") cm_file.write("SET(CMAKE_C_COMPILER \""+ CC + "\")\n") + cm_file.write("SET(CMAKE_CXX_COMPILER \""+ CXX + "\")\n") cm_file.write("SET(CMAKE_ASM_COMPILER \""+ AS + "\")\n") cm_file.write("SET(CMAKE_OBJCOPY \""+ OBJCOPY + "\")\n") cm_file.write("SET(CMAKE_SIZE \""+ SIZE + "\")\n\n") cm_file.write("SET(CMAKE_C_FLAGS \""+ rtconfig.CFLAGS + "\")\n") + cm_file.write("SET(CMAKE_CXX_FLAGS \""+ rtconfig.CXXFLAGS + "\")\n") cm_file.write("SET(CMAKE_ASM_FLAGS \""+ rtconfig.AFLAGS + "\")\n") cm_file.write("SET(CMAKE_EXE_LINKER_FLAGS \""+ re.sub('-T(\s*)', '-T ${CMAKE_SOURCE_DIR}/',rtconfig.LFLAGS) + "\")\n\n") - + + cm_file.write("SET(CMAKE_CXX_STANDARD 14)\n") + cm_file.write("PROJECT(rtthread C CXX ASM)\n") + cm_file.write("INCLUDE_DIRECTORIES(\n") for i in info['CPPPATH']: cm_file.write( "\t" +i + "\n") @@ -58,6 +63,20 @@ def GenerateCFiles(env,project): for f in group['src']: cm_file.write( "\t"+os.path.normpath(f.rfile().abspath)+"\n" ) cm_file.write(")\n\n") + + cm_file.write("LINK_DIRECTORIES(\n") + for group in project: + if 'LIBPATH' in group.keys(): + for f in group['LIBPATH']: + cm_file.write( "\t"+ f + "\n" ) + cm_file.write(")\n\n") + + cm_file.write("LINK_LIBRARIES(\n") + for group in project: + if 'LIBS' in group.keys(): + for f in group['LIBS']: + cm_file.write( "\t"+ "{}\n".format(f)) + cm_file.write(")\n\n") cm_file.write("ADD_EXECUTABLE(${CMAKE_PROJECT_NAME}.elf ${PROJECT_SOURCES})\n") cm_file.write("ADD_CUSTOM_COMMAND(TARGET ${CMAKE_PROJECT_NAME}.elf POST_BUILD \nCOMMAND ${CMAKE_OBJCOPY} -O binary ${CMAKE_PROJECT_NAME}.elf ${CMAKE_PROJECT_NAME}.bin COMMAND ${CMAKE_SIZE} ${CMAKE_PROJECT_NAME}.elf)")