diff --git a/APP_Framework/Applications/connection_app/socket_demo/lwip_tcp_socket_demo.c b/APP_Framework/Applications/connection_app/socket_demo/lwip_tcp_socket_demo.c index 08452c8ee..384698ef3 100755 --- a/APP_Framework/Applications/connection_app/socket_demo/lwip_tcp_socket_demo.c +++ b/APP_Framework/Applications/connection_app/socket_demo/lwip_tcp_socket_demo.c @@ -72,7 +72,7 @@ static void tcp_recv_demo(void *arg) tcp_addr.sin_family = AF_INET; tcp_addr.sin_addr.s_addr = INADDR_ANY; - tcp_addr.sin_port = htons(LOCAL_PORT_SERVER); + tcp_addr.sin_port = htons(LWIP_LOCAL_PORT); memset(&(tcp_addr.sin_zero), 0, sizeof(tcp_addr.sin_zero)); if (bind(fd, (struct sockaddr *)&tcp_addr, sizeof(struct sockaddr)) == -1) @@ -82,7 +82,7 @@ static void tcp_recv_demo(void *arg) } lw_print("tcp bind sucess, start to receive.\n"); - lw_print("\n\nLocal Port:%d\n\n", LOCAL_PORT_SERVER); + lw_print("\n\nLocal Port:%d\n\n", LWIP_LOCAL_PORT); while(1) { @@ -124,7 +124,7 @@ SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | static void tcp_send_demo(void *arg) { - int cnt = TEST_LWIP_TIMES; + int cnt = LWIP_DEMO_TIMES; lw_print("tcp_send_demo start.\n"); int fd = -1; char send_msg[128]; @@ -139,7 +139,7 @@ static void tcp_send_demo(void *arg) struct sockaddr_in tcp_sock; tcp_sock.sin_family = AF_INET; - tcp_sock.sin_port = htons(TARGET_PORT_CLIENT); + tcp_sock.sin_port = htons(LWIP_TARGET_PORT); tcp_sock.sin_addr.s_addr = PP_HTONL(LWIP_MAKEU32(tcp_socket_ip[0],tcp_socket_ip[1],tcp_socket_ip[2],tcp_socket_ip[3])); memset(&(tcp_sock.sin_zero), 0, sizeof(tcp_sock.sin_zero)); diff --git a/APP_Framework/Applications/connection_app/socket_demo/lwip_udp_socket_demo.c b/APP_Framework/Applications/connection_app/socket_demo/lwip_udp_socket_demo.c index 3f71783a3..b04311f5f 100755 --- a/APP_Framework/Applications/connection_app/socket_demo/lwip_udp_socket_demo.c +++ b/APP_Framework/Applications/connection_app/socket_demo/lwip_udp_socket_demo.c @@ -78,7 +78,7 @@ static void udp_recv_demo(void *arg) udp_addr.sin_family = AF_INET; udp_addr.sin_addr.s_addr = INADDR_ANY; - udp_addr.sin_port = htons(LOCAL_PORT_SERVER); + udp_addr.sin_port = htons(LWIP_LOCAL_PORT); memset(&(udp_addr.sin_zero), 0, sizeof(udp_addr.sin_zero)); if (bind(socket_fd, (struct sockaddr *)&udp_addr, sizeof(struct sockaddr)) == -1) @@ -88,7 +88,7 @@ static void udp_recv_demo(void *arg) } lw_print("UDP bind sucess, start to receive.\n"); - lw_print("\n\nLocal Port:%d\n\n", LOCAL_PORT_SERVER); + lw_print("\n\nLocal Port:%d\n\n", LWIP_LOCAL_PORT); while(1) { @@ -135,7 +135,7 @@ SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | static void udp_send_demo(void *arg) { - int cnt = TEST_LWIP_TIMES; + int cnt = LWIP_DEMO_TIMES; char send_str[128]; lw_print("udp_send_demo start.\n"); @@ -152,7 +152,7 @@ static void udp_send_demo(void *arg) struct sockaddr_in udp_sock; udp_sock.sin_family = AF_INET; - udp_sock.sin_port = htons(TARGET_PORT_CLIENT); + udp_sock.sin_port = htons(LWIP_TARGET_PORT); udp_sock.sin_addr.s_addr = PP_HTONL(LWIP_MAKEU32(udp_target[0],udp_target[1],udp_target[2],udp_target[3])); memset(&(udp_sock.sin_zero), 0, sizeof(udp_sock.sin_zero)); diff --git a/APP_Framework/Applications/control_app/opcua_demo/opcua_demo.c b/APP_Framework/Applications/control_app/opcua_demo/opcua_demo.c index 342375357..9e948c81f 100755 --- a/APP_Framework/Applications/control_app/opcua_demo/opcua_demo.c +++ b/APP_Framework/Applications/control_app/opcua_demo/opcua_demo.c @@ -30,6 +30,7 @@ ******************************************************************************/ #define TCP_LOCAL_PORT 4840 +#define UA_URL_SIZE 100 /******************************************************************************* * Prototypes @@ -39,24 +40,19 @@ * Variables ******************************************************************************/ -const char *test_uri = "opc.tcp://192.168.250.5:4840"; -const char *test_cb_str = "tcp client connected\r\n"; - -char test_ua_gw[] = {192, 168, 250, 5}; - -static pthread_t eth_input_id = 0; -static pthread_t ua_demo_id; +char test_ua_ip[] = {192, 168, 250, 5}; /******************************************************************************* * Code ******************************************************************************/ -void *test_ua_get_server_info(void *param); - static void test_ua_connect(void *arg) { struct netif net; UA_StatusCode retval; + char ua_uri[UA_URL_SIZE]; + + memset(ua_uri, 0, sizeof(ua_uri)); UA_Client *client = UA_Client_new(); @@ -69,7 +65,10 @@ static void test_ua_connect(void *arg) UA_ClientConfig *config = UA_Client_getConfig(client); UA_ClientConfig_setDefault(config); - retval = UA_Client_connect(client, test_uri); + snprintf(ua_uri, UA_URL_SIZE, "opc.tcp://%d.%d.%d.%d:4840", + test_ua_ip[0], test_ua_ip[1], test_ua_ip[2], test_ua_ip[3]); + + retval = UA_Client_connect(client, ua_uri); if (retval != UA_STATUSCODE_GOOD) { ua_print("ua: [%s] ret %x\n", __func__, retval); @@ -83,7 +82,7 @@ static void test_ua_connect(void *arg) void test_ua_connect_thr(void *arg) { ETH_BSP_Config(); - lwip_config_tcp(lwip_ipaddr, lwip_netmask, test_ua_gw); + lwip_config_tcp(lwip_ipaddr, lwip_netmask, test_ua_ip); test_ua_connect(NULL); } @@ -98,7 +97,7 @@ void test_sh_ua_connect(void) SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0), UaConnect, test_sh_ua_connect, Test Opc UA connection); -void *test_ua_get_server_info(void *param) +void test_ua_browser_objects(void *param) { UA_Client *client = UA_Client_new(); @@ -107,7 +106,7 @@ void *test_ua_get_server_info(void *param) if (client == NULL) { ua_print("ua: [%s] tcp client null\n", __func__); - return NULL; + return; } UA_ClientConfig *config = UA_Client_getConfig(client); @@ -117,7 +116,7 @@ void *test_ua_get_server_info(void *param) if(retval != UA_STATUSCODE_GOOD) { ua_print("ua: [%s] connect failed %#x\n", __func__, retval); UA_Client_delete(client); - return NULL; + return; } ua_print("ua: [%s] connect ok!\n", __func__); @@ -128,37 +127,85 @@ void *test_ua_get_server_info(void *param) ua_pr_info("--- get server info ---\n", __func__); ua_browser_objects(client); - /* Same thing, this time using the node iterator... */ - ua_browser_nodes(client); + /* Clean up */ + UA_Client_disconnect(client); + UA_Client_delete(client); /* Disconnects the client internally */ +} + +void *test_sh_ua_brower_objects(int argc, char *argv[]) +{ + if(argc == 2) + { + if(isdigit(argv[1][0])) + { + if(sscanf(argv[1], "%d.%d.%d.%d", &test_ua_ip[0], &test_ua_ip[1], &test_ua_ip[2], &test_ua_ip[3]) == EOF) + { + lw_pr_info("input wrong ip\n"); + return NULL; + } + } + } + + ETH_BSP_Config(); + lwip_config_tcp(lwip_ipaddr, lwip_netmask, test_ua_ip); + sys_thread_new("ua object", test_ua_browser_objects, NULL, 4096, 15); + return NULL; +} + +SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3), + UaObj, test_sh_ua_brower_objects, UaObj [IP]); + +void test_ua_get_info(void *param) +{ + UA_Client *client = UA_Client_new(); + + ua_pr_info("ua: [%s] start ...\n", __func__); + + if (client == NULL) + { + ua_print("ua: [%s] tcp client null\n", __func__); + return; + } + + UA_ClientConfig *config = UA_Client_getConfig(client); + UA_ClientConfig_setDefault(config); + + UA_StatusCode retval = UA_Client_connect(client, OPC_SERVER); + if(retval != UA_STATUSCODE_GOOD) { + ua_print("ua: [%s] connect failed %#x\n", __func__, retval); + UA_Client_delete(client); + return; + } + + ua_print("ua: [%s] connect ok!\n", __func__); + ua_pr_info("--- get server info ---\n", __func__); + ua_get_server_info(client); /* Clean up */ UA_Client_disconnect(client); UA_Client_delete(client); /* Disconnects the client internally */ } -void *test_ua_get_server_info_thr(void *arg) +void *test_sh_ua_get_info(int argc, char *argv[]) { - ETH_BSP_Config(); - lwip_config_tcp(lwip_ipaddr, lwip_netmask, test_ua_gw); - test_ua_get_server_info(NULL); -} - -void *test_sh_ua_get_server_info(void *param) -{ - int result = 0; - pthread_attr_t attr; - - attr.schedparam.sched_priority = 15; - attr.stacksize = 4096; - - result = pthread_create(&ua_demo_id, &attr, test_ua_get_server_info_thr, NULL); - if (0 == result) { - lw_print("test_ua_get_server_info %d successfully!\n", __func__, ua_demo_id); - } else { - lw_print("test_ua_get_server_info failed! error code is %d\n", __func__, result); + if(argc == 2) + { + if(isdigit(argv[1][0])) + { + if(sscanf(argv[1], "%d.%d.%d.%d", &test_ua_ip[0], &test_ua_ip[1], &test_ua_ip[2], &test_ua_ip[3]) == EOF) + { + lw_pr_info("input wrong ip\n"); + return NULL; + } + } } + + ETH_BSP_Config(); + lwip_config_tcp(lwip_ipaddr, lwip_netmask, test_ua_ip); + sys_thread_new("ua object", test_ua_browser_objects, NULL, 4096, 15); + return NULL; } -SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0), - UaGetInfo, test_sh_ua_get_server_info, Get information from OpcUA server); +SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3), + UaInfo, test_sh_ua_get_info, UaInfo [IP]); diff --git a/APP_Framework/Framework/control/plc/interoperability/opcua/ua_client.c b/APP_Framework/Framework/control/plc/interoperability/opcua/ua_client.c index a4083ea8e..eb8e439ea 100755 --- a/APP_Framework/Framework/control/plc/interoperability/opcua/ua_client.c +++ b/APP_Framework/Framework/control/plc/interoperability/opcua/ua_client.c @@ -66,24 +66,34 @@ void ua_browser_objects(UA_Client *client) { /* Browse some objects */ ua_pr_info("Browsing nodes in objects folder:\n"); + UA_BrowseRequest bReq; UA_BrowseRequest_init(&bReq); + bReq.requestedMaxReferencesPerNode = 0; bReq.nodesToBrowse = UA_BrowseDescription_new(); bReq.nodesToBrowseSize = 1; bReq.nodesToBrowse[0].nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER); /* browse objects folder */ bReq.nodesToBrowse[0].resultMask = UA_BROWSERESULTMASK_ALL; /* return everything */ + UA_BrowseResponse bResp = UA_Client_Service_browse(client, bReq); + ua_pr_info("%-9s %-16s %-16s %-16s\n", "NAMESPACE", "NODEID", "BROWSE NAME", "DISPLAY NAME"); - for(size_t i = 0; i < bResp.resultsSize; ++i) { - for(size_t j = 0; j < bResp.results[i].referencesSize; ++j) { + + for(size_t i = 0; i < bResp.resultsSize; ++i) + { + for(size_t j = 0; j < bResp.results[i].referencesSize; ++j) + { UA_ReferenceDescription *ref = &(bResp.results[i].references[j]); - if(ref->nodeId.nodeId.identifierType == UA_NODEIDTYPE_NUMERIC) { + if(ref->nodeId.nodeId.identifierType == UA_NODEIDTYPE_NUMERIC) + { ua_pr_info("%-9d %-16d %-16.*s %-16.*s\n", ref->nodeId.nodeId.namespaceIndex, ref->nodeId.nodeId.identifier.numeric, (int)ref->browseName.name.length, ref->browseName.name.data, (int)ref->displayName.text.length, ref->displayName.text.data); - } else if(ref->nodeId.nodeId.identifierType == UA_NODEIDTYPE_STRING) { + } + else if(ref->nodeId.nodeId.identifierType == UA_NODEIDTYPE_STRING) + { ua_pr_info("%-9d %-16.*s %-16.*s %-16.*s\n", ref->nodeId.nodeId.namespaceIndex, (int)ref->nodeId.nodeId.identifier.string.length, ref->nodeId.nodeId.identifier.string.data, @@ -164,7 +174,8 @@ void ua_read_attr(UA_Client *client) wReq.nodesToWrite[0].value.value.data = &value; UA_WriteResponse wResp = UA_Client_Service_write(client, wReq); if(wResp.responseHeader.serviceResult == UA_STATUSCODE_GOOD) - ua_print("the new value is: %i\n", value); + ua_print("the new value is: %i\n", value); + UA_WriteRequest_clear(&wReq); UA_WriteResponse_clear(&wResp); @@ -188,11 +199,14 @@ void ua_call_remote(UA_Client *client) UA_Variant *output; UA_StatusCode retval = UA_Client_call(client, UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER), UA_NODEID_NUMERIC(1, 62541), 1, &input, &outputSize, &output); - if(retval == UA_STATUSCODE_GOOD) { + if(retval == UA_STATUSCODE_GOOD) + { ua_print("Method call was successful, and %lu returned values available.\n", (unsigned long)outputSize); UA_Array_delete(output, outputSize, &UA_TYPES[UA_TYPES_VARIANT]); - } else { + } + else + { ua_print("Method call was unsuccessful, and %x returned values available.\n", retval); } UA_Variant_clear(&input); @@ -270,23 +284,6 @@ void ua_add_nodes(UA_Client *client) int ua_get_server_info(UA_Client *client) { - UA_StatusCode retval; - - /* Listing endpoints */ -// retval = ua_get_points(client); -// if(retval != UA_STATUSCODE_GOOD) { -// UA_Client_delete(client); -// return EXIT_FAILURE; -// } -// -// /* Connect to a server */ -// /* anonymous connect would be: retval = UA_Client_connect(client, "opc.tcp://localhost:4840"); */ -// retval = UA_Client_connect(client, OPC_SERVER); -// if(retval != UA_STATUSCODE_GOOD) { -// UA_Client_delete(client); -// return EXIT_FAILURE; -// } - ua_browser_objects(client); /* Same thing, this time using the node iterator... */ diff --git a/Ubiquitous/XiUOS/board/ok1052-c/third_party_driver/ethernet/enet_ethernetif.c b/Ubiquitous/XiUOS/board/ok1052-c/third_party_driver/ethernet/enet_ethernetif.c index 39d9f45be..40a9e3251 100755 --- a/Ubiquitous/XiUOS/board/ok1052-c/third_party_driver/ethernet/enet_ethernetif.c +++ b/Ubiquitous/XiUOS/board/ok1052-c/third_party_driver/ethernet/enet_ethernetif.c @@ -216,7 +216,7 @@ void ethernetif_input(struct netif *netif) /* pass all packets to ethernet_input, which decides what packets it supports */ if ((ret = netif->input(p, netif)) != ERR_OK) { -// LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n")); + LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n")); lw_print("lw: [%s] ret %d p %p\n", __func__, ret, p); pbuf_free(p); p = NULL; diff --git a/Ubiquitous/XiUOS/board/ok1052-c/third_party_driver/ethernet/enet_ethernetif_kinetis.c b/Ubiquitous/XiUOS/board/ok1052-c/third_party_driver/ethernet/enet_ethernetif_kinetis.c index 68c63777c..aafb460a2 100755 --- a/Ubiquitous/XiUOS/board/ok1052-c/third_party_driver/ethernet/enet_ethernetif_kinetis.c +++ b/Ubiquitous/XiUOS/board/ok1052-c/third_party_driver/ethernet/enet_ethernetif_kinetis.c @@ -118,6 +118,8 @@ typedef struct EventGroupDef_t struct EventGroupDef_t; typedef struct EventGroupDef_t * EventGroupHandle_t; +#else +int lwip_sempahore; #endif #endif @@ -130,8 +132,6 @@ typedef struct EventGroupDef_t * EventGroupHandle_t; #include "sys_arch.h" - - /******************************************************************************* * Definitions ******************************************************************************/ @@ -166,6 +166,13 @@ struct ethernetif * Code ******************************************************************************/ #if USE_RTOS && defined(FSL_RTOS_FREE_RTOS) + +int32 lwip_obtain_semaphore(struct netif *netif) +{ + struct ethernetif *ethernetif = netif->state; + return (KSemaphoreObtain(ethernetif->enetSemaphore, WAITING_FOREVER) == EOK); +} + #if FSL_FEATURE_ENET_QUEUE > 1 static void ethernet_callback(ENET_Type *base, enet_handle_t *handle, uint32_t ringId, enet_event_t event, void *param) #else @@ -176,21 +183,18 @@ static void ethernet_callback(ENET_Type *base, enet_handle_t *handle, enet_event struct ethernetif *ethernetif = netif->state; BaseType_t xResult; - - lw_print("lw: [%s] input event %#x \n", __func__, event); - switch (event) { case kENET_RxEvent: ethernetif_input(netif); break; case kENET_TxEvent: - { - portBASE_TYPE taskToWake = pdFALSE; - #ifdef FSL_RTOS_XIUOS #else + { + portBASE_TYPE taskToWake = pdFALSE; + #ifdef __CA7_REV if (SystemGetIRQNestingLevel()) #else @@ -207,14 +211,15 @@ static void ethernet_callback(ENET_Type *base, enet_handle_t *handle, enet_event { xEventGroupSetBits(ethernetif->enetTransmitAccessEvent, ethernetif->txFlag); } -#endif } +#endif break; default: break; } - KSemaphoreAbandon(ethernetif->enetSemaphore); +// KSemaphoreAbandon(ethernetif->enetSemaphore); + KSemaphoreAbandon(lwip_sempahore); } #endif @@ -315,7 +320,7 @@ err_t ethernetif_mld_mac_filter(struct netif *netif, const ip6_addr_t *group, // // for( ;; ) // { -// if (KSemaphoreObtain( s_xSemaphore, WAITING_FOREVER)==EOK) +// if (KSemaphoreObtain( lwip_sempahore, WAITING_FOREVER)==EOK) // { // p = low_level_input( s_pxNetIf ); // @@ -392,6 +397,7 @@ void ethernetif_enet_init(struct netif *netif, struct ethernetif *ethernetif, { ethernetif->enetSemaphore = KSemaphoreCreate(0); } +// lwip_sempahore = KSemaphoreCreate(0); #else ethernetif->enetTransmitAccessEvent = xEventGroupCreate(); #endif @@ -458,7 +464,7 @@ static err_t enet_send_frame(struct ethernetif *ethernetif, unsigned char *data, { status_t result; - lw_print("lw: [%s] len %d\n", __func__, length); + lw_print("lw: [%s] len %d\n", __func__, length); do { @@ -467,7 +473,8 @@ static err_t enet_send_frame(struct ethernetif *ethernetif, unsigned char *data, if (result == kStatus_ENET_TxFrameBusy) { #ifdef FSL_RTOS_XIUOS -// KSemaphoreObtain(ethernetif->enetSemaphore, portMAX_DELAY); + KSemaphoreObtain(ethernetif->enetSemaphore, portMAX_DELAY); +// KSemaphoreObtain(lwip_sempahore, portMAX_DELAY); #else xEventGroupWaitBits(ethernetif->enetTransmitAccessEvent, ethernetif->txFlag, pdTRUE, (BaseType_t) false, portMAX_DELAY); @@ -582,11 +589,10 @@ struct pbuf *ethernetif_linkinput(struct netif *netif) if (status == kStatus_ENET_RxFrameError) { #if 0 && defined(FSL_FEATURE_SOC_ENET_COUNT) && (FSL_FEATURE_SOC_ENET_COUNT > 0) /* Error statisctics */ - enet_data_error_stats_t eErrStatic; - /* Get the error information of the received g_frame. */ - ENET_GetRxErrBeforeReadFrame(ðernetif->handle, &eErrStatic); + enet_data_error_stats_t eErrStatic; + /* Get the error information of the received g_frame. */ + ENET_GetRxErrBeforeReadFrame(ðernetif->handle, &eErrStatic); #endif - /* Update the receive buffer. */ ENET_ReadFrame(ethernetif->base, ðernetif->handle, NULL, 0U); diff --git a/Ubiquitous/XiUOS/board/ok1052-c/third_party_driver/ethernet/enet_ethernetif_lpc.c b/Ubiquitous/XiUOS/board/ok1052-c/third_party_driver/ethernet/enet_ethernetif_lpc.c index 3afc0da46..d851dc709 100755 --- a/Ubiquitous/XiUOS/board/ok1052-c/third_party_driver/ethernet/enet_ethernetif_lpc.c +++ b/Ubiquitous/XiUOS/board/ok1052-c/third_party_driver/ethernet/enet_ethernetif_lpc.c @@ -801,30 +801,30 @@ err_t ethernetif_linkoutput(struct netif *netif, struct pbuf *p) } } - if (copy) + if (copy) { /* Pbuf needs to be copied. */ p_copy = pbuf_alloc(PBUF_RAW, (uint16_t) p->tot_len, PBUF_POOL); - if (p_copy == NULL) + if (p_copy == NULL) { - return ERR_MEM; - } + return ERR_MEM; + } - dst = (uint8_t *) p_copy->payload; - for (q = p; q != NULL; q = q->next) + dst = (uint8_t *) p_copy->payload; + for (q = p; q != NULL; q = q->next) { LWIP_ASSERT("Copied bytes would exceed p->tot_len", (q->len + dst - (uint8_t *) p_copy->payload) <= p->tot_len); memcpy(dst, (uint8_t *)q->payload, q->len); - dst += q->len; - } + dst += q->len; + } LWIP_ASSERT("Copied bytes != p->tot_len", (dst - (uint8_t *) p_copy->payload) == p->tot_len); - p_copy->len = p_copy->tot_len = p->tot_len; + p_copy->len = p_copy->tot_len = p->tot_len; - p = p_copy; - } + p = p_copy; + } else { /* diff --git a/Ubiquitous/XiUOS/board/ok1052-c/third_party_driver/ethernet/fsl_enet.c b/Ubiquitous/XiUOS/board/ok1052-c/third_party_driver/ethernet/fsl_enet.c index 4da401faf..a5f14720d 100755 --- a/Ubiquitous/XiUOS/board/ok1052-c/third_party_driver/ethernet/fsl_enet.c +++ b/Ubiquitous/XiUOS/board/ok1052-c/third_party_driver/ethernet/fsl_enet.c @@ -1490,6 +1490,9 @@ static void ENET_UpdateReadBuffers(ENET_Type *base, enet_handle_t *handle, uint3 assert(handle); assert(ringId < FSL_FEATURE_ENET_QUEUE); + +// lw_print("lw: [%s] base %p handle %p ring %d\n", __func__, base, handle, ringId); + /* Clears status. */ handle->rxBdCurrent[ringId]->control &= ENET_BUFFDESCRIPTOR_RX_WRAP_MASK; /* Sets the receive buffer descriptor with the empty flag. */ diff --git a/Ubiquitous/XiUOS/board/ok1052-c/third_party_driver/include/enet_ethernetif.h b/Ubiquitous/XiUOS/board/ok1052-c/third_party_driver/include/enet_ethernetif.h index b7009bc3d..cc7016b3b 100755 --- a/Ubiquitous/XiUOS/board/ok1052-c/third_party_driver/include/enet_ethernetif.h +++ b/Ubiquitous/XiUOS/board/ok1052-c/third_party_driver/include/enet_ethernetif.h @@ -195,6 +195,8 @@ void ethernetif_input( struct netif *netif); void ETH_BSP_Config(void); +int32 lwip_obtain_semaphore(struct netif *netif); + #if defined(__cplusplus) } #endif /* __cplusplus */ diff --git a/Ubiquitous/XiUOS/resources/ethernet/LwIP/arch/sys_arch.c b/Ubiquitous/XiUOS/resources/ethernet/LwIP/arch/sys_arch.c index 1b2720ef6..df323a9e5 100644 --- a/Ubiquitous/XiUOS/resources/ethernet/LwIP/arch/sys_arch.c +++ b/Ubiquitous/XiUOS/resources/ethernet/LwIP/arch/sys_arch.c @@ -85,11 +85,9 @@ char lwip_ipaddr[] = {192, 168, 250, 253}; char lwip_netmask[] = {255, 255, 255, 0}; char lwip_gwaddr[] = {192, 168, 250, 252}; -int errno; int is_lwip_test = 0; //for lwip input thread x_ticks_t lwip_sys_now; - static int lwip_init_flag = 0; struct sys_timeouts { @@ -386,7 +384,7 @@ ip4_addr_t ipaddr; ip4_addr_t netmask; ip4_addr_t gw; -void TcpIpInit(void) +void lwip_tcp_init(void) { tcpip_init(NULL, NULL); @@ -397,14 +395,9 @@ void TcpIpInit(void) ip_addr_set_zero_ip4(&netmask); ip_addr_set_zero_ip4(&gw); #else - #ifdef SET_AS_SERVER - IP4_ADDR(&ipaddr,IP_ADDR0_SERVER,IP_ADDR1_SERVER,IP_ADDR2_SERVER,IP_ADDR3_SERVER); - #else - IP4_ADDR(&ipaddr,IP_ADDR0_ClIENT,IP_ADDR1_ClIENT,IP_ADDR2_ClIENT,IP_ADDR3_ClIENT); - #endif - - IP4_ADDR(&netmask,NETMASK_ADDR0,NETMASK_ADDR1,NETMASK_ADDR2,NETMASK_ADDR3); - IP4_ADDR(&gw,GW_ADDR0,GW_ADDR1,GW_ADDR2,GW_ADDR3); + IP4_ADDR(&ipaddr, lwip_ipaddr[0], lwip_ipaddr[1], lwip_ipaddr[2], lwip_ipaddr[3]); + IP4_ADDR(&netmask, lwip_netmask[0], lwip_netmask[1], lwip_netmask[2], lwip_netmask[3]); + IP4_ADDR(&gw, lwip_gwaddr[0], lwip_gwaddr[1], lwip_gwaddr[2], lwip_gwaddr[3]); #endif /* USE_DHCP */ /* USER CODE END 0 */ /* Initilialize the LwIP stack without RTOS */ @@ -417,13 +410,13 @@ void TcpIpInit(void) if (netif_is_link_up(&gnetif)) { /* When the netif is fully configured this function must be called */ - KPrintf("TcpIpInit : netif_set_up\n"); + KPrintf("%s : netif_set_up\n", __func__); netif_set_up(&gnetif); } else { /* When the netif link is down this function must be called */ - KPrintf("TcpIpInit : netif_set_down\n"); + KPrintf("%s : netif_set_down\n", __func__); netif_set_down(&gnetif); } @@ -459,10 +452,14 @@ void lwip_input_thread(void *param) while (1) { - /* Poll the driver, get any outstanding frames */ - ethernetif_input(net); - sys_check_timeouts(); /* Handle all system timeouts for all core protocols */ -// DelayKTask(1); +#ifdef FSL_RTOS_XIUOS + if (lwip_obtain_semaphore(net) == EOK) +#endif + { + /* Poll the driver, get any outstanding frames */ + ethernetif_input(net); + sys_check_timeouts(); /* Handle all system timeouts for all core protocols */ + } } } @@ -502,6 +499,7 @@ void lwip_config_net(char *ip, char *mask, char *gw) IP4_ADDR(&net_netmask, mask[0], mask[1], mask[2], mask[3]); IP4_ADDR(&net_gw, gw[0], gw[1], gw[2], gw[3]); + // update ip addr netif_set_down(&gnetif); netif_set_gw(&gnetif, &net_gw); netif_set_netmask(&gnetif, &net_netmask); diff --git a/Ubiquitous/XiUOS/resources/ethernet/LwIP/arch/sys_arch.h b/Ubiquitous/XiUOS/resources/ethernet/LwIP/arch/sys_arch.h index 781e64fe9..b2d059386 100644 --- a/Ubiquitous/XiUOS/resources/ethernet/LwIP/arch/sys_arch.h +++ b/Ubiquitous/XiUOS/resources/ethernet/LwIP/arch/sys_arch.h @@ -60,42 +60,18 @@ #include -/* USER CODE BEGIN 0 */ -// #define SET_AS_SERVER 1 /* define this terminal is udp server or not*/ +/* LWIP task parameter */ +#define LWIP_LOCAL_PORT 4840 +#define LWIP_TARGET_PORT LWIP_LOCAL_PORT -#define LOCAL_PORT_SERVER 4840 -#define TARGET_PORT_CLIENT LOCAL_PORT_SERVER - -#define TEST_LWIP_TIMES 3 - -/*Static IP ADDRESS: IP_ADDR0.IP_ADDR1.IP_ADDR2.IP_ADDR3 */ -#define IP_ADDR0_SERVER 192 -#define IP_ADDR1_SERVER 168 -#define IP_ADDR2_SERVER 250 -#define IP_ADDR3_SERVER 252 - -#define IP_ADDR0_ClIENT 192 -#define IP_ADDR1_ClIENT 168 -#define IP_ADDR2_ClIENT 250 -#define IP_ADDR3_ClIENT 253 - -/*NETMASK*/ -#define NETMASK_ADDR0 255 -#define NETMASK_ADDR1 255 -#define NETMASK_ADDR2 255 -#define NETMASK_ADDR3 0 - -/*Gateway Address*/ -#define GW_ADDR0 192 -#define GW_ADDR1 168 -#define GW_ADDR2 250 -#define GW_ADDR3 5 +#define LWIP_DEMO_TIMES 3 +#define LWIP_TASK_STACK_SIZE 4096 +#define LWIP_TASK_PRIO 15 /* MAC address configuration. */ -#define configMAC_ADDR { 0x02, 0x12, 0x13, 0x10, 0x15, 0x11} +#define configMAC_ADDR {0x02, 0x12, 0x13, 0x10, 0x15, 0x11} /* USER CODE END 0 */ - #define SYS_MBOX_NULL -1 #define SYS_SEM_NULL 0 #define SYS_MRTEX_NULL SYS_SEM_NULL @@ -104,18 +80,21 @@ typedef int32 sys_sem_t; typedef int32 sys_mutex_t; typedef int32 sys_mbox_t; typedef int32 sys_thread_t; - typedef x_base sys_prot_t; #define MS_PER_SYSTICK_F407 1000/TICK_PER_SECOND +//debug rtos with IRQ +//#define FSL_RTOS_XIUOS + extern char lwip_ipaddr[]; extern char lwip_netmask[]; extern char lwip_gwaddr[]; extern int is_lwip_test; +extern int lwip_sempahore; extern struct netif gnetif; -void TcpIpInit(void); +void lwip_tcp_init(void); void lwip_config_net(char *ip, char *mask, char *gw); void lwip_config_tcp(char *ip, char *mask, char *gw); diff --git a/Ubiquitous/XiUOS/resources/ethernet/cmd_lwip/lwip_demo.h b/Ubiquitous/XiUOS/resources/ethernet/cmd_lwip/lwip_demo.h index c2cf2ebbb..99e273aa1 100755 --- a/Ubiquitous/XiUOS/resources/ethernet/cmd_lwip/lwip_demo.h +++ b/Ubiquitous/XiUOS/resources/ethernet/cmd_lwip/lwip_demo.h @@ -1,6 +1,7 @@ #ifndef __LWIP_DEMO_H__ #define __LWIP_DEMO_H__ -void *eth_input_thread(void *param); +#define LWIP_TEST_STACK_SIZE 4096 +#define LWIP_TEST_TASK_PRIO 20 #endif /* __LWIP_DEMO_H__ */ diff --git a/Ubiquitous/XiUOS/resources/ethernet/cmd_lwip/lwip_tcp_demo.c b/Ubiquitous/XiUOS/resources/ethernet/cmd_lwip/lwip_tcp_demo.c index 647199d97..94adbf3d2 100755 --- a/Ubiquitous/XiUOS/resources/ethernet/cmd_lwip/lwip_tcp_demo.c +++ b/Ubiquitous/XiUOS/resources/ethernet/cmd_lwip/lwip_tcp_demo.c @@ -29,6 +29,8 @@ * Definitions ******************************************************************************/ +#define MSG_SIZE 128 + /******************************************************************************* * Prototypes ******************************************************************************/ @@ -37,10 +39,9 @@ * Variables ******************************************************************************/ -char tcp_target[] = {192, 168, 250, 252}; -#define MSG_SIZE 128 // this is for test in shell, in fact, shell restrict the length of input string, which is less then 128 char tcp_send_msg[MSG_SIZE] = {0}; +char tcp_target[] = {192, 168, 250, 252}; /******************************************************************************* * Code @@ -60,7 +61,7 @@ static void lwip_tcp_send_thread(void *arg) struct sockaddr_in tcp_sock; tcp_sock.sin_family = AF_INET; - tcp_sock.sin_port = htons(TARGET_PORT_CLIENT); + tcp_sock.sin_port = htons(LWIP_TARGET_PORT); tcp_sock.sin_addr.s_addr = PP_HTONL(LWIP_MAKEU32(tcp_target[0], tcp_target[1], tcp_target[2], tcp_target[3])); memset(&(tcp_sock.sin_zero), 0, sizeof(tcp_sock.sin_zero)); @@ -104,7 +105,7 @@ void lwip_tcp_send_run(int argc, char *argv[]) ETH_BSP_Config(); lwip_config_tcp(lwip_ipaddr, lwip_netmask, lwip_gwaddr); - sys_thread_new("tcp send", lwip_tcp_send_thread, NULL, 4096, 25); + sys_thread_new("tcp send", lwip_tcp_send_thread, NULL, LWIP_TASK_STACK_SIZE, LWIP_TASK_PRIO); } SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3), diff --git a/Ubiquitous/XiUOS/resources/ethernet/cmd_lwip/lwip_udp_demo.c b/Ubiquitous/XiUOS/resources/ethernet/cmd_lwip/lwip_udp_demo.c index 37c16b0e2..5dd19c5c3 100755 --- a/Ubiquitous/XiUOS/resources/ethernet/cmd_lwip/lwip_udp_demo.c +++ b/Ubiquitous/XiUOS/resources/ethernet/cmd_lwip/lwip_udp_demo.c @@ -53,7 +53,7 @@ char udp_send_msg[] = "\n\nThis one is UDP pkg. Congratulations on you.\n\n"; static void lwip_udp_send(void *arg) { - int cnt = TEST_LWIP_TIMES; + int cnt = LWIP_DEMO_TIMES; lw_print("udp_send_demo start.\n"); @@ -67,7 +67,7 @@ static void lwip_udp_send(void *arg) struct sockaddr_in udp_sock; udp_sock.sin_family = AF_INET; - udp_sock.sin_port = htons(TARGET_PORT_CLIENT); + udp_sock.sin_port = htons(LWIP_TARGET_PORT); udp_sock.sin_addr.s_addr = PP_HTONL(LWIP_MAKEU32(udp_target[0],udp_target[1],udp_target[2],udp_target[3])); memset(&(udp_sock.sin_zero), 0, sizeof(udp_sock.sin_zero)); @@ -170,7 +170,7 @@ void udpecho_raw_init(void) return; } - err = udp_bind(udpecho_raw_pcb, IP_ANY_TYPE, LOCAL_PORT_SERVER); + err = udp_bind(udpecho_raw_pcb, IP_ANY_TYPE, LWIP_LOCAL_PORT); if (err == ERR_OK) { udp_recv(udpecho_raw_pcb, udpecho_raw_recv, NULL); diff --git a/Ubiquitous/XiUOS/resources/ethernet/cmd_lwip/ping.c b/Ubiquitous/XiUOS/resources/ethernet/cmd_lwip/ping.c index 925f174ba..3312d8da6 100755 --- a/Ubiquitous/XiUOS/resources/ethernet/cmd_lwip/ping.c +++ b/Ubiquitous/XiUOS/resources/ethernet/cmd_lwip/ping.c @@ -248,7 +248,7 @@ ping_thread(void *arg) { int s; int ret; - int cnt = TEST_LWIP_TIMES; + int cnt = LWIP_DEMO_TIMES; #if LWIP_SO_SNDRCVTIMEO_NONSTANDARD int timeout = PING_RCV_TIMEO; @@ -367,7 +367,7 @@ ping_send(struct raw_pcb *raw, const ip_addr_t *addr) static void ping_timeout(void *arg) { - static int cnt = TEST_LWIP_TIMES; + static int cnt = LWIP_DEMO_TIMES; struct raw_pcb *pcb = (struct raw_pcb*)arg; LWIP_ASSERT("ping_timeout: no pcb given!", pcb != NULL); @@ -380,7 +380,7 @@ ping_timeout(void *arg) } else { - cnt = TEST_LWIP_TIMES; + cnt = LWIP_DEMO_TIMES; } } @@ -483,7 +483,7 @@ int get_url_ip(char* url) #else int timeout = PING_RCV_TIMEO * 1000UL / TICK_PER_SECOND; #endif - int cnt = TEST_LWIP_TIMES; + int cnt = LWIP_DEMO_TIMES; int s, ttl, recv_len; ip_addr_t target_addr; diff --git a/Ubiquitous/XiUOS/resources/ethernet/cmd_lwip/tcpecho_raw.c b/Ubiquitous/XiUOS/resources/ethernet/cmd_lwip/tcpecho_raw.c index 887e8bcd8..026207891 100755 --- a/Ubiquitous/XiUOS/resources/ethernet/cmd_lwip/tcpecho_raw.c +++ b/Ubiquitous/XiUOS/resources/ethernet/cmd_lwip/tcpecho_raw.c @@ -49,7 +49,10 @@ #if LWIP_TCP && LWIP_CALLBACK_API -#define MAX_TESTED_TCP_SEND_SIZE (56000) +#define MAX_TCP_RECV_SIZE (56000) +#define MAX_TCP_SHOW_SIZE 80 +#define TCP_ACK_MSG_SIZE 20 +#define TCP_EOF_CH '\n' static struct tcp_pcb *tcpecho_raw_pcb; @@ -109,70 +112,73 @@ tcpecho_raw_error(void *arg, err_t err) tcpecho_raw_free(es); } -#define SHELL_TCP_LENGTH 80 -char* recved_msg; -int recved_msg_length; +static void +tcpecho_raw_ack_size(struct tcp_pcb *tpcb, int ack_len) +{ + struct pbuf *ack_buf = NULL; + + // ack message + ack_buf = pbuf_alloc(PBUF_TRANSPORT, TCP_ACK_MSG_SIZE, PBUF_RAM); + snprintf(ack_buf->payload, TCP_ACK_MSG_SIZE, "%d\n\0", ack_len); + ack_buf->len = strlen(ack_buf->payload); + ack_buf->tot_len = strlen(ack_buf->payload); + ack_buf->next = NULL; + + tcp_write(tpcb, ack_buf->payload, ack_buf->len, 1); + pbuf_free(ack_buf); +} + // compute received message length until '\n' -static void record_msg(struct tcp_pcb *tpcb, struct tcpecho_raw_state* es){ - struct pbuf* ptr = es->p; - int plen = ptr->len; - if(es==NULL||ptr==NULL||plen==0){ - if(recved_msg){ - free(recved_msg); - recved_msg = NULL; - } - recved_msg_length = 0; +static void +tcpecho_raw_ack(struct tcp_pcb *tpcb, struct tcpecho_raw_state* es){ + struct pbuf *ptr = es->p; + char *recv_buf = ptr->payload; + int recv_len = ptr->len; + static char *g_buf = NULL; //global received buffer + static int g_buf_size = 0; + + lw_print("lw: [%s] recv %d tot %d next %p ref %d tye %d id %d %s\n", __func__, ptr->len, ptr->tot_len, + ptr->next, ptr->ref, ptr->type_internal, + ptr->if_idx, ptr->payload); + + if(g_buf == NULL) + { + g_buf = (char *)malloc(MAX_TCP_RECV_SIZE); + memset(g_buf, 0, MAX_TCP_RECV_SIZE); + memcpy(g_buf, recv_buf, recv_len); } - int new_size = plen+1; - char* temp = recved_msg; - if(temp!=NULL){ - new_size += strlen(temp); - } - recved_msg = malloc(new_size); - memset(recved_msg, 0, new_size); - if(temp!=NULL){ - memcpy(recved_msg,temp,strlen(temp)); - } - memcpy(recved_msg+new_size-plen-1, ptr->payload, plen); - free(temp); - recved_msg_length += plen; - if(recved_msg_length>=SHELL_TCP_LENGTH){ - if(recved_msg){ - free(recved_msg); - recved_msg = NULL; + else + { + if(g_buf_size + recv_len <= MAX_TCP_RECV_SIZE) + { + memcpy(g_buf + g_buf_size, recv_buf, recv_len); } } - if(((char*)ptr->payload)[plen-1]=='\n'){ - if(recved_msg_length>MAX_TESTED_TCP_SEND_SIZE){ - KPrintf("Recved_msg_length is larger than %d, which may lead to unexpected exceptions.\n",MAX_TESTED_TCP_SEND_SIZE); - } - if(recved_msg_lengthpayload,"%d\n\0",recved_msg_length); - reply_pbuf->len = strlen(reply_pbuf->payload); - reply_pbuf->tot_len = strlen(reply_pbuf->payload); - reply_pbuf->next = NULL; - - tcp_write(tpcb, reply_pbuf->payload, reply_pbuf->len, 1); - - pbuf_free(reply_pbuf); - free(recved_msg); - recved_msg = NULL; - recved_msg_length = 0; + + tcpecho_raw_ack_size(tpcb, g_buf_size); + + free(g_buf); + g_buf = NULL; + g_buf_size = 0; } + es->p = ptr->next; if(es->p != NULL) { /* new reference! */ pbuf_ref(es->p); } pbuf_free(ptr); - tcp_recved(tpcb, plen); -} + tcp_recved(tpcb, recv_len); +} static err_t tcpecho_raw_poll(void *arg, struct tcp_pcb *tpcb) @@ -184,7 +190,7 @@ tcpecho_raw_poll(void *arg, struct tcp_pcb *tpcb) if (es != NULL) { if (es->p != NULL) { /* there is a remaining pbuf (chain) */ - record_msg(tpcb, es); + tcpecho_raw_ack(tpcb, es); } else { /* no remaining pbuf (chain) */ if(es->state == ES_CLOSING) { @@ -233,7 +239,7 @@ tcpecho_raw_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err) tcpecho_raw_close(tpcb, es); } else { /* we're not done yet */ - record_msg(tpcb, es); + tcpecho_raw_ack(tpcb, es); } ret_err = ERR_OK; } else if(err != ERR_OK) { @@ -248,13 +254,13 @@ tcpecho_raw_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err) es->state = ES_RECEIVED; /* store reference to incoming pbuf (chain) */ es->p = p; - record_msg(tpcb, es); + tcpecho_raw_ack(tpcb, es); ret_err = ERR_OK; } else if (es->state == ES_RECEIVED) { /* read some more data */ if(es->p == NULL) { es->p = p; - record_msg(tpcb, es); + tcpecho_raw_ack(tpcb, es); } else { struct pbuf *ptr; @@ -277,8 +283,6 @@ tcpecho_raw_accept(void *arg, struct tcp_pcb *newpcb, err_t err) { err_t ret_err; struct tcpecho_raw_state *es; - recved_msg = NULL; - recved_msg_length = 0; LWIP_UNUSED_ARG(arg); if ((err != ERR_OK) || (newpcb == NULL)) {