Compare commits
	
		
			2 Commits
		
	
	
		
			303ef23a48
			...
			a35c234093
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| a35c234093 | |||
| d1f2e141d8 | 
							
								
								
									
										1
									
								
								app/common.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								app/common.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1 @@ | ||||
| #define NEW_LINE "\r\n" | ||||
							
								
								
									
										68
									
								
								app/main.c
									
									
									
									
									
								
							
							
						
						
									
										68
									
								
								app/main.c
									
									
									
									
									
								
							| @ -19,13 +19,15 @@ | ||||
| #include "lwip/netif.h" | ||||
| #include "FreeRTOS.h" | ||||
| #include "FreeRTOSConfig.h" | ||||
| #include "common.h" | ||||
| 
 | ||||
| tls_os_task_t nano_shell_task_handle = NULL; | ||||
| tls_os_task_t nano_shell_server_task_handle = NULL; | ||||
| extern s16 uart0_rx_callback(u16 len, void *user_data); | ||||
| extern s16 uart1_rx_callback(u16 len, void *user_data); | ||||
| extern int shell_printf(const char *format, ...); | ||||
| 
 | ||||
| #define NANO_SHELL_TASK_STK_SIZE 1024 | ||||
| #define NANO_SHELL_TASK_STK_SIZE 640 | ||||
| #define NANO_SHELL_SERVER_TASK_STK_SIZE 640 | ||||
| #define STATUS_LED WM_IO_PB_18 | ||||
| #define PWM_STATUS_LED WM_IO_PB_25 | ||||
| @ -45,47 +47,47 @@ void tls_netif_status_event_cb(u8 status) | ||||
| 	switch(status) | ||||
|   	{ | ||||
| 		case NETIF_WIFI_JOIN_SUCCESS: | ||||
| 			shell_printf("Evt : NETIF_WIFI_JOIN_SUCCESS\n"); | ||||
| 			shell_printf("Evt : NETIF_WIFI_JOIN_SUCCESS"NEW_LINE); | ||||
| 	  		break; | ||||
| 		case NETIF_WIFI_JOIN_FAILED: | ||||
| 			shell_printf("Evt : NETIF_WIFI_JOIN_FAILED\n"); | ||||
| 			shell_printf("Evt : NETIF_WIFI_JOIN_FAILED"NEW_LINE); | ||||
| 	  		break; | ||||
| 		case NETIF_WIFI_DISCONNECTED: | ||||
| 			shell_printf("Evt : NETIF_WIFI_DISCONNECTED\n"); | ||||
| 			shell_printf("Evt : NETIF_WIFI_DISCONNECTED"NEW_LINE); | ||||
| 			pulse_rate = PULSE_SLOW; | ||||
| 			break; | ||||
| 		case NETIF_IP_NET_UP: | ||||
| 			shell_printf("Evt : NETIF_IP_NET_UP\nip addr : %v\nnetmask : %v\ngateway : %v\n", netif->ip_addr.addr, | ||||
| 			shell_printf("Evt : NETIF_IP_NET_UP"NEW_LINE"ip addr : %v"NEW_LINE"netmask : %v"NEW_LINE"gateway : %v"NEW_LINE, netif->ip_addr.addr, | ||||
| 			netif->netmask.addr, | ||||
| 			netif->gw.addr); | ||||
| 			pulse_rate = PULSE_FAST; | ||||
| 			break; | ||||
| 		case NETIF_WIFI_SOFTAP_SUCCESS: | ||||
| 			shell_printf("Evt : NETIF_WIFI_SOFTAP_SUCCESS\n"); | ||||
| 			shell_printf("Evt : NETIF_WIFI_SOFTAP_SUCCESS"NEW_LINE); | ||||
| 			break; | ||||
| 		case NETIF_WIFI_SOFTAP_FAILED: | ||||
| 			shell_printf("Evt : NETIF_WIFI_SOFTAP_FAILED\n"); | ||||
| 			shell_printf("Evt : NETIF_WIFI_SOFTAP_FAILED"NEW_LINE); | ||||
| 			break; | ||||
| 		case NETIF_WIFI_SOFTAP_CLOSED: | ||||
| 			shell_printf("Evt : NETIF_WIFI_SOFTAP_CLOSED\n"); | ||||
| 			shell_printf("Evt : NETIF_WIFI_SOFTAP_CLOSED"NEW_LINE); | ||||
| 			break; | ||||
| 		case NETIF_IP_NET2_UP: | ||||
| 			shell_printf("Evt : NETIF_IP_NET2_UP\nip addr : %v\nnetmask : %v\ngateway : %v\n", netif->next->ip_addr.addr, | ||||
| 			shell_printf("Evt : NETIF_IP_NET2_UP"NEW_LINE"ip addr : %v"NEW_LINE"netmask : %v"NEW_LINE"gateway : %v"NEW_LINE, netif->next->ip_addr.addr, | ||||
| 			netif->next->netmask.addr, | ||||
| 			netif->next->gw.addr); | ||||
| 			break; | ||||
| 		case NETIF_IPV6_NET_UP: | ||||
| 			shell_printf("Evt : NETIF_IPV6_NET_UP\n"); | ||||
| 			shell_printf("Evt : NETIF_IPV6_NET_UP"NEW_LINE); | ||||
| 			break; | ||||
| 		default: | ||||
| 			shell_printf("Evt : UNKNOWN\n"); | ||||
| 			shell_printf("Evt : UNKNOWN"NEW_LINE); | ||||
| 			break; | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| void touchsensor_cb(u32 status) | ||||
| { | ||||
| 	shell_printf("Touch detected : status(%u)\n", status); | ||||
| 	shell_printf("Touch detected : status(%u)"NEW_LINE, status); | ||||
| } | ||||
| 
 | ||||
| void tls_gpio_irq_cb(void *arg) | ||||
| @ -123,6 +125,21 @@ void user_main(void *param) | ||||
| 	tls_uart_rx_callback_register(TLS_UART_1, &(uart1_rx_callback), NULL); | ||||
| 
 | ||||
| 	nano_shell_server_task_stack = tls_mem_alloc(sizeof(u32) * NANO_SHELL_SERVER_TASK_STK_SIZE); | ||||
| 	if(nano_shell_server_task_stack != NULL) | ||||
| 	{ | ||||
| 		tls_os_status_t status = tls_os_task_create( | ||||
| 													&nano_shell_server_task_handle, | ||||
| 													"shll_srv", | ||||
| 													&(nano_shell_server_task), | ||||
| 													NULL, | ||||
| 													(void*) nano_shell_server_task_stack, | ||||
| 													NANO_SHELL_SERVER_TASK_STK_SIZE * sizeof(u32_t), | ||||
| 													62, | ||||
| 													0 | ||||
| 												); | ||||
| 		if(status != TLS_OS_SUCCESS) | ||||
| 			shell_printf("Failed to create nano shell server task."NEW_LINE); | ||||
| 	} | ||||
| 	 | ||||
| 	nano_shell_task_stack = tls_mem_alloc(sizeof(u32) * NANO_SHELL_TASK_STK_SIZE); | ||||
| 	if(nano_shell_task_stack != NULL) | ||||
| @ -139,23 +156,9 @@ void user_main(void *param) | ||||
| 		); | ||||
| 	} | ||||
| 
 | ||||
| 	shell_printf("Registering netif callback.\n"); | ||||
| 	shell_printf("Registering netif callback."NEW_LINE); | ||||
| 	tls_netif_add_status_event(&(tls_netif_status_event_cb)); | ||||
| 
 | ||||
| 	//Socket test
 | ||||
| 	/*
 | ||||
| 	char buffer[100] = "", *found = NULL; | ||||
| 	struct sockaddr_in server = { | ||||
| 									.sin_family = AF_INET, | ||||
| 									.sin_addr.s_addr = INADDR_ANY, | ||||
| 									.sin_port = htons(80) | ||||
| 								}; | ||||
| 	struct sockaddr_in client; | ||||
| 	socklen_t socklent = sizeof(client); | ||||
| 	int listening_socket = socket(AF_INET, SOCK_STREAM, 0), client_socket; | ||||
| 	bind(listening_socket, (struct sockaddr *)&server, sizeof(server)); | ||||
| 	listen(listening_socket, 1);*/ | ||||
| 
 | ||||
| 	for(;;) | ||||
| 	{ | ||||
| 		tls_pwm_duty_set(3, pwm_led_duty_cycle); | ||||
| @ -173,17 +176,6 @@ void user_main(void *param) | ||||
| 		pwm_led_duty_cycle+=fading_direction; | ||||
| 
 | ||||
| 		tls_os_time_delay(pdMS_TO_TICKS(pulse_rate)); | ||||
| 		/*client_socket = accept(listening_socket, (struct sockaddr *)&client, &socklent);
 | ||||
| 		shell_printf("Client got accepted\n"); | ||||
| 		while(recv(client_socket, buffer, 99, 0) > 0) | ||||
| 		{ | ||||
| 			if((found = strchr(buffer, '\r')) != NULL) | ||||
| 				*found = '\0'; | ||||
| 			if(buffer[0]) | ||||
| 				shell_printf("Recv data : #%s#\n", buffer); | ||||
| 			memset(buffer, 0, sizeof buffer); | ||||
| 		} | ||||
| 		close(client_socket);*/ | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -6,6 +6,7 @@ | ||||
| #include "FreeRTOS.h" | ||||
| #include "task.h" | ||||
| #include "lwip/netif.h" | ||||
| #include "common.h" | ||||
| 
 | ||||
| extern int shell_printf(const char *format, ...); | ||||
| extern int wm_printf(const char *fmt,...); | ||||
| @ -20,7 +21,7 @@ void tls_wifi_client_event_cb(u8 *mac, enum tls_wifi_client_event_type event) | ||||
| { | ||||
|   struct tls_sta_info_t *mac_addr = (struct tls_sta_info_t *)mac; | ||||
| 
 | ||||
|   shell_printf("Client event(%d), MAC : %M\n", event, mac_addr); | ||||
|   shell_printf("Client event(%d), MAC : %M"NEW_LINE, event, mac_addr); | ||||
| } | ||||
| 
 | ||||
| void wifi_scan_result_cb(void) | ||||
| @ -29,14 +30,14 @@ void wifi_scan_result_cb(void) | ||||
|   u8 *buf = tls_mem_alloc(buffer_size); | ||||
|   if(buf == NULL) | ||||
|   { | ||||
|     shell_printf("Failed to allocate result buffer\n"); | ||||
|     shell_printf("Failed to allocate result buffer"NEW_LINE); | ||||
|     return; | ||||
|   } | ||||
|   struct tls_scan_bss_t *scan_result = (struct tls_scan_bss_t *)buf; | ||||
|   struct tls_bss_info_t *station_list = scan_result->bss; | ||||
| 
 | ||||
|   tls_wifi_get_scan_rslt(buf, buffer_size); | ||||
|   shell_printf("Found %u nearby station(s) - info size(%u/%u)\n", | ||||
|   shell_printf("Found %u nearby station(s) - info size(%u/%u)"NEW_LINE, | ||||
|   scan_result->count, | ||||
|   scan_result->length, | ||||
|   buffer_size); | ||||
| @ -44,7 +45,7 @@ void wifi_scan_result_cb(void) | ||||
|   for(u8 i = 0; i < scan_result->count; i++) | ||||
|   { | ||||
|     station_list[i].ssid[station_list[i].ssid_len] = '\0'; | ||||
|     shell_printf("station %u :\nSSID : %s\nBSSID : %02X:%02X:%02X:%02X:%02X:%02X\nRSSI : %d dB\nChannel : %u\nMax DR : %u Mbps\nMode %u\nAuth :%u\nWPS supported : %u\n\n", | ||||
|     shell_printf("station %u :"NEW_LINE"SSID : %s"NEW_LINE"BSSID : %02X:%02X:%02X:%02X:%02X:%02X"NEW_LINE"RSSI : %d dB"NEW_LINE"Channel : %u"NEW_LINE"Max DR : %u Mbps"NEW_LINE"Mode %u"NEW_LINE"Auth :%u"NEW_LINE"WPS supported : %u"NEW_LINE NEW_LINE, | ||||
|     i, | ||||
|     (char *)station_list[i].ssid, | ||||
|     station_list[i].bssid[0], station_list[i].bssid[1], station_list[i].bssid[2], station_list[i].bssid[3], station_list[i].bssid[4], station_list[i].bssid[5], | ||||
| @ -61,14 +62,14 @@ void wifi_scan_result_cb(void) | ||||
| 
 | ||||
| void tls_wifi_data_ext_recv_cb(u8* data, u32 data_len, struct tls_wifi_ext_t *ext) | ||||
| { | ||||
|   shell_printf("recv packet :\nrssi : %d\nrate : %u\n", (s8)ext->rssi, ext->rx_rate); | ||||
|   shell_printf("recv packet :"NEW_LINE"rssi : %d\nrate : %u"NEW_LINE, (s8)ext->rssi, ext->rx_rate); | ||||
|   for(u32 i = 0; i < data_len; i++) | ||||
|   { | ||||
|     shell_printf("%02X", data[i]); | ||||
|     if(i % 30 == 0) | ||||
|       shell_printf("\n"); | ||||
|       shell_printf(NEW_LINE); | ||||
|   } | ||||
|   shell_printf("\n"); | ||||
|   shell_printf(NEW_LINE); | ||||
| } | ||||
| 
 | ||||
| void tls_rtc_irq_cb(void *arg) | ||||
| @ -76,7 +77,7 @@ void tls_rtc_irq_cb(void *arg) | ||||
|   struct tm rtc_time; | ||||
|   tls_get_rtc(&rtc_time); | ||||
| 
 | ||||
|   shell_printf("rtc isr called\ntime is :\n%d:%d:%d %d/%d/%d\n", | ||||
|   shell_printf("rtc isr called"NEW_LINE"time is :"NEW_LINE"%d:%d:%d %d/%d/%d"NEW_LINE, | ||||
|   rtc_time.tm_hour, | ||||
|   rtc_time.tm_min, | ||||
|   rtc_time.tm_sec, | ||||
| @ -101,22 +102,22 @@ int _system(const shell_cmd_t *pcmd, int argc, char *const argv[]) | ||||
| #if configUSE_TRACE_FACILITY | ||||
|       vTaskList(buf); | ||||
| #endif | ||||
|       shell_printf("\n%s\nbuf_len : %d\n", buf, strlen(buf)); | ||||
|       shell_printf(NEW_LINE"%s"NEW_LINE"buf_len : %d"NEW_LINE, buf, strlen(buf)); | ||||
|       tls_mem_free(buf); | ||||
|       buf = NULL; | ||||
|     } | ||||
|     else if(strcmp(argv[1], "ram_usage") == 0) | ||||
|     { | ||||
|       shell_printf("Free OS heap : %u/%u byte(s)\ntls heap size : %u\n", xPortGetFreeHeapSize(), configTOTAL_HEAP_SIZE, tls_mem_get_avail_heapsize()); | ||||
|       shell_printf("Free OS heap : %u/%u byte(s)"NEW_LINE"tls heap size : %u"NEW_LINE, xPortGetFreeHeapSize(), configTOTAL_HEAP_SIZE, tls_mem_get_avail_heapsize()); | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|       shell_printf("Unknown %s action\n", argv[0]); | ||||
|       shell_printf("Unknown %s action"NEW_LINE, argv[0]); | ||||
|     } | ||||
|   } | ||||
|   else | ||||
|   { | ||||
|     shell_printf("List of system actions :\nlist_task\nram_usage\n"); | ||||
|     shell_printf("List of system actions :"NEW_LINE"list_task"NEW_LINE"ram_usage"NEW_LINE); | ||||
|   } | ||||
|   return 0; | ||||
| } | ||||
| @ -133,7 +134,7 @@ int _soft_ap(const shell_cmd_t *pcmd, int argc, char *const argv[]) | ||||
|   { | ||||
|     if(strcmp(argv[1], "state") == 0) | ||||
|     { | ||||
|       shell_printf("SOFT AP state : %u\n", tls_wifi_softap_get_state()); | ||||
|       shell_printf("SOFT AP state : %u"NEW_LINE, tls_wifi_softap_get_state()); | ||||
|     } | ||||
|     else if(strcmp(argv[1], "create") == 0) | ||||
|     { | ||||
| @ -143,7 +144,7 @@ int _soft_ap(const shell_cmd_t *pcmd, int argc, char *const argv[]) | ||||
|       tls_wifi_set_oneshot_flag(0); | ||||
|       tls_wifi_softap_destroy(); | ||||
| 
 | ||||
|       shell_printf("Registering client event callback\n"); | ||||
|       shell_printf("Registering client event callback"NEW_LINE); | ||||
|       tls_wifi_softap_client_event_register(&(tls_wifi_client_event_cb)); | ||||
| 
 | ||||
|       strncpy((char *)ap_info.ssid, argv[2], 32); | ||||
| @ -167,23 +168,23 @@ int _soft_ap(const shell_cmd_t *pcmd, int argc, char *const argv[]) | ||||
|       ip_info.dnsname[0] = '\0'; | ||||
|        | ||||
|       int result = tls_wifi_softap_create(&ap_info, &ip_info); | ||||
|       shell_printf("Create AP with SSID : %s, key(%d) : %s -> %d\n", ap_info.ssid, ap_info.keyinfo.key_len, ap_info.keyinfo.key, result); | ||||
|       shell_printf("Create AP with SSID : %s, key(%d) : %s -> %d"NEW_LINE, ap_info.ssid, ap_info.keyinfo.key_len, ap_info.keyinfo.key, result); | ||||
|     } | ||||
|     else if(strcmp(argv[1], "destroy") == 0) | ||||
|     { | ||||
|       tls_wifi_softap_client_event_register(NULL); | ||||
|       tls_wifi_set_oneshot_flag(0); | ||||
|       tls_wifi_softap_destroy(); | ||||
|       shell_printf("Stopping SOFT AP\n"); | ||||
|       shell_printf("Stopping SOFT AP"NEW_LINE); | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|       shell_printf("Unknown %s action\n", argv[0]); | ||||
|       shell_printf("Unknown %s action"NEW_LINE, argv[0]); | ||||
|     } | ||||
|   } | ||||
|   else | ||||
|   { | ||||
|     shell_printf("List of soft_ap actions :\nstate\ncreate <SSID> <PWD>\ndestroy\n"); | ||||
|     shell_printf("List of soft_ap actions :"NEW_LINE"state"NEW_LINE"create <SSID> <PWD>"NEW_LINE"destroy"NEW_LINE); | ||||
|   } | ||||
|   return 0; | ||||
| } | ||||
| @ -198,43 +199,43 @@ int _station(const shell_cmd_t *pcmd, int argc, char *const argv[]) | ||||
| 
 | ||||
|       if(tls_wifi_scan() == WM_SUCCESS) | ||||
|       { | ||||
|         shell_printf("Scanning nearby stations...\n"); | ||||
|         shell_printf("Scanning nearby stations..."NEW_LINE); | ||||
|       } | ||||
|       else | ||||
|       { | ||||
|         shell_printf("Failed to start wifi scan\n"); | ||||
|         shell_printf("Failed to start wifi scan"NEW_LINE); | ||||
|       } | ||||
|     } | ||||
|     else if(strcmp(argv[1], "state") == 0) | ||||
|     { | ||||
|       shell_printf("Station state : %u\n", tls_wifi_get_state()); | ||||
|       shell_printf("Station state : %u"NEW_LINE, tls_wifi_get_state()); | ||||
|     } | ||||
|     else if(strcmp(argv[1], "connect") == 0) | ||||
|     { | ||||
|       shell_printf("Connecting to %s with pwd : %s\n", argv[2], argv[3]); | ||||
|       shell_printf("Connecting to %s with pwd : %s"NEW_LINE, argv[2], argv[3]); | ||||
|       if(tls_wifi_connect((u8 *)argv[2], strlen(argv[2]), (u8 *)argv[3], strlen(argv[3])) == WM_SUCCESS) | ||||
|       { | ||||
|         shell_printf("Connected\n"); | ||||
|         shell_printf("Connecting..."NEW_LINE); | ||||
|       } | ||||
|       else | ||||
|       { | ||||
|         shell_printf("Failed to connect !\n"); | ||||
|         shell_printf("Failed to connect !"NEW_LINE); | ||||
|       } | ||||
|     } | ||||
|     else if(strcmp(argv[1], "disconnect") == 0) | ||||
|     { | ||||
|       shell_printf("Disconnecting from current station\n"); | ||||
|       shell_printf("Disconnecting from current station"NEW_LINE); | ||||
|       tls_wifi_set_oneshot_flag(0); | ||||
|       tls_wifi_disconnect(); | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|       shell_printf("Unknown %s action\n", argv[0]); | ||||
|       shell_printf("Unknown %s action"NEW_LINE, argv[0]); | ||||
|     } | ||||
|   } | ||||
|   else | ||||
|   { | ||||
|     shell_printf("List of station actions :\nscan\nstate\nconnect <SSID> <PWD>\ndisconnect\n"); | ||||
|     shell_printf("List of station actions :"NEW_LINE"scan"NEW_LINE"state"NEW_LINE"connect <SSID> <PWD>"NEW_LINE"disconnect"NEW_LINE); | ||||
|   } | ||||
|   return 0; | ||||
| } | ||||
| @ -243,7 +244,7 @@ int _cpu_temp(const shell_cmd_t *pcmd, int argc, char *const argv[]) | ||||
| { | ||||
|   int temperature = adc_temp(); | ||||
| 
 | ||||
|   shell_printf("CPU temp is %d.%03d\n", temperature/1000, temperature%1000); | ||||
|   shell_printf("CPU temp is %d.%03d"NEW_LINE, temperature/1000, temperature%1000); | ||||
|   return 0; | ||||
| } | ||||
| 
 | ||||
| @ -255,26 +256,26 @@ int _wifi(const shell_cmd_t *pcmd, int argc, char *const argv[]) | ||||
|     { | ||||
|       tls_wifi_softap_destroy(); | ||||
|       tls_wifi_disconnect(); | ||||
|       shell_printf("set one shot flg : %d\n",tls_wifi_set_oneshot_flag(0)); | ||||
|       shell_printf("Stopping WIFI interface\n"); | ||||
|       shell_printf("set one shot flg : %d"NEW_LINE,tls_wifi_set_oneshot_flag(0)); | ||||
|       shell_printf("Stopping WIFI interface"NEW_LINE); | ||||
|     } | ||||
|     else if(strcmp(argv[1], "error") == 0) | ||||
|     { | ||||
|       shell_printf("Error : %s\n", tls_wifi_get_errinfo(tls_wifi_get_errno())); | ||||
|       shell_printf("Error : %s"NEW_LINE, tls_wifi_get_errinfo(tls_wifi_get_errno())); | ||||
|     } | ||||
|     else if(strcmp(argv[1], "promiscuous_on") == 0) | ||||
|     { | ||||
|       shell_printf("WiFi promiscuous on\n"); | ||||
|       shell_printf("WiFi promiscuous on"NEW_LINE); | ||||
|       tls_wifi_data_ext_recv_cb_register(&(tls_wifi_data_ext_recv_cb)); | ||||
|     } | ||||
|     else if(strcmp(argv[1], "promiscuous_off") == 0) | ||||
|     { | ||||
|       shell_printf("WiFi promiscuous off\n"); | ||||
|       shell_printf("WiFi promiscuous off"NEW_LINE); | ||||
|       tls_wifi_data_ext_recv_cb_register(NULL); | ||||
|     } | ||||
|     else if(strcmp(argv[1], "mode") == 0) | ||||
|     { | ||||
|       shell_printf("Mode is : %d\n", tls_wifi_get_oneshot_flag()); | ||||
|       shell_printf("Mode is : %d"NEW_LINE, tls_wifi_get_oneshot_flag()); | ||||
|     } | ||||
|     else if(strcmp(argv[1], "get_ip") == 0) | ||||
|     { | ||||
| @ -282,30 +283,30 @@ int _wifi(const shell_cmd_t *pcmd, int argc, char *const argv[]) | ||||
| 
 | ||||
|       if(netif) | ||||
|       { | ||||
|         shell_printf("netif 1\nip addr : %v\nnetmask : %v\ngateway : %v\n", netif->ip_addr.addr, | ||||
|         shell_printf("netif 1"NEW_LINE"ip addr : %v"NEW_LINE"netmask : %v"NEW_LINE"gateway : %v"NEW_LINE, netif->ip_addr.addr, | ||||
| 			  netif->netmask.addr, | ||||
| 			  netif->gw.addr); | ||||
| 
 | ||||
|         if(netif->next) | ||||
|         { | ||||
|           shell_printf("netif 2\nip addr : %v\nnetmask : %v\ngateway : %v\n", netif->next->ip_addr.addr, | ||||
|           shell_printf("netif 2"NEW_LINE"ip addr : %v"NEW_LINE"netmask : %v"NEW_LINE"gateway : %v"NEW_LINE, netif->next->ip_addr.addr, | ||||
| 			    netif->next->netmask.addr, | ||||
| 			    netif->next->gw.addr); | ||||
|         } | ||||
|       } | ||||
|       else | ||||
|       { | ||||
|         shell_printf("No netif yet, connect to sta or create soft_ap !\n"); | ||||
|         shell_printf("No netif yet, connect to sta or create soft_ap !"NEW_LINE); | ||||
|       } | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|       shell_printf("Unknown %s action\n", argv[0]); | ||||
|       shell_printf("Unknown %s action"NEW_LINE, argv[0]); | ||||
|     } | ||||
|   } | ||||
|   else | ||||
|   { | ||||
|     shell_printf("List of wifi actions :\noff\nerror\npromiscuous_on\npromiscuous_off\nmode\nget_ip\n"); | ||||
|     shell_printf("List of wifi actions :"NEW_LINE"off"NEW_LINE"error"NEW_LINE"promiscuous_on"NEW_LINE"promiscuous_off"NEW_LINE"mode"NEW_LINE"get_ip"NEW_LINE); | ||||
|   } | ||||
|   return 0; | ||||
| } | ||||
| @ -316,7 +317,7 @@ int _wifi_sleep(const shell_cmd_t *pcmd, int argc, char *const argv[]) | ||||
|   { | ||||
|     if(strcmp(argv[1], "query") == 0) | ||||
|     { | ||||
|       shell_printf("power saving : 0x%X, psm chip sleep : 0x%X\n", | ||||
|       shell_printf("power saving : 0x%X, psm chip sleep : 0x%X"NEW_LINE, | ||||
|       tls_wifi_get_psflag(), | ||||
|       tls_wifi_get_psm_chipsleep_flag()); | ||||
|     } | ||||
| @ -326,13 +327,13 @@ int _wifi_sleep(const shell_cmd_t *pcmd, int argc, char *const argv[]) | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|       shell_printf("Unknown %s action\n", argv[0]); | ||||
|       shell_printf("Unknown %s action"NEW_LINE, argv[0]); | ||||
|     } | ||||
|      | ||||
|   } | ||||
|   else | ||||
|   { | ||||
|     shell_printf("List of wifi_sleep actions :\nquery\nset\n"); | ||||
|     shell_printf("List of wifi_sleep actions :"NEW_LINE"query"NEW_LINE"set"NEW_LINE); | ||||
|   } | ||||
|   return 0; | ||||
| } | ||||
| @ -344,29 +345,29 @@ int _pmu(const shell_cmd_t *pcmd, int argc, char *const argv[]) | ||||
|     if(strcmp(argv[1], "sleep") == 0) | ||||
|     { | ||||
|       u32 duration = strtoul(argv[2], NULL, 10); | ||||
|       shell_printf("Going to sleep mode for %u s\n", duration); | ||||
|       shell_printf("Going to sleep mode for %u s"NEW_LINE, duration); | ||||
|       tls_pmu_timer0_start(duration); | ||||
|       tls_pmu_sleep_start(); | ||||
|       shell_printf("Waking up out of sleep mode\n"); | ||||
|       shell_printf("Waking up out of sleep mode"NEW_LINE); | ||||
|       tls_pmu_timer0_stop(); | ||||
|     } | ||||
|     else if(strcmp(argv[1], "standby") == 0) | ||||
|     { | ||||
|       u32 duration = strtoul(argv[2], NULL, 10); | ||||
|       shell_printf("Going to standby mode for %u s\n", duration); | ||||
|       shell_printf("Going to standby mode for %u s"NEW_LINE, duration); | ||||
|       tls_pmu_timer0_start(duration); | ||||
|       tls_pmu_standby_start(); | ||||
|       shell_printf("Waking up out of standby mode\n"); | ||||
|       shell_printf("Waking up out of standby mode"NEW_LINE); | ||||
|       tls_pmu_timer0_stop(); | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|       shell_printf("Unknown %s action\n", argv[0]); | ||||
|       shell_printf("Unknown %s action"NEW_LINE, argv[0]); | ||||
|     } | ||||
|   } | ||||
|   else | ||||
|   { | ||||
|     shell_printf("List of pmu actions :\nsleep <duration(s)>\nstandby <duration(s)>\n"); | ||||
|     shell_printf("List of pmu actions :"NEW_LINE"sleep <duration(s)>"NEW_LINE"standby <duration(s)>"NEW_LINE); | ||||
|   } | ||||
|   return 0; | ||||
| } | ||||
| @ -380,7 +381,7 @@ int _rtc(const shell_cmd_t *pcmd, int argc, char *const argv[]) | ||||
|       struct tm rtc_time; | ||||
|       tls_get_rtc(&rtc_time); | ||||
| 
 | ||||
|       shell_printf("rtc time is :\n%d:%d:%d %d/%d/%d\n", | ||||
|       shell_printf("rtc time is :"NEW_LINE"%d:%d:%d %d/%d/%d"NEW_LINE, | ||||
|       rtc_time.tm_hour, | ||||
|       rtc_time.tm_min, | ||||
|       rtc_time.tm_sec, | ||||
| @ -399,7 +400,7 @@ int _rtc(const shell_cmd_t *pcmd, int argc, char *const argv[]) | ||||
|       rtc_time.tm_mon  = strtoul(argv[6], NULL, 10); | ||||
|       rtc_time.tm_year  = strtoul(argv[7], NULL, 10); | ||||
| 
 | ||||
|       shell_printf("Setting rtc to :\n%d:%d:%d %d/%d/%d\nisr callback registered !\n", | ||||
|       shell_printf("Setting rtc to :"NEW_LINE"%d:%d:%d %d/%d/%d"NEW_LINE"isr callback registered !"NEW_LINE, | ||||
|       rtc_time.tm_hour, | ||||
|       rtc_time.tm_min, | ||||
|       rtc_time.tm_sec, | ||||
| @ -421,7 +422,7 @@ int _rtc(const shell_cmd_t *pcmd, int argc, char *const argv[]) | ||||
|       rtc_time.tm_mon  = strtoul(argv[6], NULL, 10); | ||||
|       rtc_time.tm_year  = strtoul(argv[7], NULL, 10); | ||||
| 
 | ||||
|       shell_printf("Setting rtc alarm to :\n%d:%d:%d %d/%d/%d\n", | ||||
|       shell_printf("Setting rtc alarm to :"NEW_LINE"%d:%d:%d %d/%d/%d"NEW_LINE, | ||||
|       rtc_time.tm_hour, | ||||
|       rtc_time.tm_min, | ||||
|       rtc_time.tm_sec, | ||||
| @ -433,12 +434,12 @@ int _rtc(const shell_cmd_t *pcmd, int argc, char *const argv[]) | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|       shell_printf("Unknown %s action\n", argv[0]); | ||||
|       shell_printf("Unknown %s action"NEW_LINE, argv[0]); | ||||
|     } | ||||
|   } | ||||
|   else | ||||
|   { | ||||
|     shell_printf("List of rtc actions :\nget\nset <h> <m> <s> <d> <m> <y>\nalarm <h> <m> <s> <d> <m> <y>\n"); | ||||
|     shell_printf("List of rtc actions :"NEW_LINE"get"NEW_LINE"set <h> <m> <s> <d> <m> <y>"NEW_LINE"alarm <h> <m> <s> <d> <m> <y>"NEW_LINE); | ||||
|   } | ||||
|   return 0;  | ||||
| } | ||||
| @ -449,30 +450,30 @@ int _bluetooth(const shell_cmd_t *pcmd, int argc, char *const argv[]) | ||||
|   { | ||||
|     if(strcmp(argv[1], "enable") == 0) | ||||
|     { | ||||
|       //shell_printf("Enabling bluetooth : %d\n", demo_bt_enable());
 | ||||
|       shell_printf("Enabling bluetooth test\n"); | ||||
|       //shell_printf("Enabling bluetooth : %d"NEW_LINE, demo_bt_enable());
 | ||||
|       shell_printf("Enabling bluetooth test"NEW_LINE); | ||||
|     } | ||||
|     else if(strcmp(argv[1], "disable") == 0) | ||||
|     { | ||||
|       //shell_printf("Disabling bluetooth : %d\n", demo_bt_destroy());
 | ||||
|       shell_printf("Disabling bluetooth test\n"); | ||||
|       //shell_printf("Disabling bluetooth : %d"NEW_LINE, demo_bt_destroy());
 | ||||
|       shell_printf("Disabling bluetooth test"NEW_LINE); | ||||
|     } | ||||
|     else if(strcmp(argv[1], "start_demo") == 0) | ||||
|     { | ||||
|       shell_printf("Starting demo : %d\nUse a BLE app to find the device\n", demo_ble_server_on()); | ||||
|       shell_printf("Starting demo : %d"NEW_LINE"Use a BLE app to find the device"NEW_LINE, demo_ble_server_on()); | ||||
|     } | ||||
|     else if(strcmp(argv[1], "stop_demo") == 0) | ||||
|     { | ||||
|       shell_printf("Stopping demo : %d\n", demo_ble_server_off()); | ||||
|       shell_printf("Stopping demo : %d"NEW_LINE, demo_ble_server_off()); | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|       shell_printf("Unknown %s action\n", argv[0]); | ||||
|       shell_printf("Unknown %s action"NEW_LINE, argv[0]); | ||||
|     } | ||||
|   } | ||||
|   else | ||||
|   { | ||||
|     shell_printf("List of bluetooth actions :\nenable\ndisable\nstart_demo\nstop_demo\n"); | ||||
|     shell_printf("List of bluetooth actions :"NEW_LINE"enable"NEW_LINE"disable"NEW_LINE"start_demo"NEW_LINE"stop_demo"NEW_LINE); | ||||
|   } | ||||
|   return 0;  | ||||
| } | ||||
| @ -480,40 +481,40 @@ int _bluetooth(const shell_cmd_t *pcmd, int argc, char *const argv[]) | ||||
| NANO_SHELL_ADD_CMD(system, | ||||
|                    _system, | ||||
|                    "Query system information", | ||||
|                    "  Use this command to get system information\r\n"); | ||||
|                    "  Use this command to get system information"NEW_LINE); | ||||
| NANO_SHELL_ADD_CMD(reset, | ||||
|                    _reset, | ||||
|                    "Reset the system", | ||||
|                    "  Use this command reset the system\r\n"); | ||||
|                    "  Use this command reset the system"NEW_LINE); | ||||
| NANO_SHELL_ADD_CMD(soft_ap, | ||||
|                    _soft_ap, | ||||
|                    "Command to control SOFT AP", | ||||
|                    "  Use this command to control the SOFT AP subsystem\r\n"); | ||||
|                    "  Use this command to control the SOFT AP subsystem"NEW_LINE); | ||||
| NANO_SHELL_ADD_CMD(station, | ||||
|                    _station, | ||||
|                    "Command to control STATION mode", | ||||
|                    "  Use this command to connect to a WiFi access point\r\n"); | ||||
|                    "  Use this command to connect to a WiFi access point"NEW_LINE); | ||||
| NANO_SHELL_ADD_CMD(wifi, | ||||
|                    _wifi, | ||||
|                    "Command to control WIFI interface", | ||||
|                    "  Use this command to control the WIFI interface\r\n"); | ||||
|                    "  Use this command to control the WIFI interface"NEW_LINE); | ||||
| NANO_SHELL_ADD_CMD(cpu_temp, | ||||
|                    _cpu_temp, | ||||
|                    "Command to read the CPU temperature", | ||||
|                    "  Use this command to read the CPU temperature\r\n"); | ||||
|                    "  Use this command to read the CPU temperature"NEW_LINE); | ||||
| NANO_SHELL_ADD_CMD(wifi_sleep, | ||||
|                    _wifi_sleep, | ||||
|                    "Command to control WiFi sleep", | ||||
|                    "  Use this command to control WiFi sleep feature\r\n"); | ||||
|                    "  Use this command to control WiFi sleep feature"NEW_LINE); | ||||
| NANO_SHELL_ADD_CMD(pmu, | ||||
|                    _pmu, | ||||
|                    "Command to control the power management unit", | ||||
|                    "  Use this command to control power management unit feature\r\n"); | ||||
|                    "  Use this command to control power management unit feature"NEW_LINE); | ||||
| NANO_SHELL_ADD_CMD(rtc, | ||||
|                    _rtc, | ||||
|                    "Command to query and set up the rtc", | ||||
|                   "  Use this command to interact with the rtc module\n"); | ||||
|                   "  Use this command to interact with the rtc module"NEW_LINE); | ||||
| NANO_SHELL_ADD_CMD(bluetooth, | ||||
|                    _bluetooth, | ||||
|                    "Command to control bluetooth functionality", | ||||
|                   "  Use this command to interact use bluetooth\n"); | ||||
|                   "  Use this command to interact use bluetooth"NEW_LINE); | ||||
|  | ||||
| @ -64,6 +64,8 @@ int shell_getc(char *ch) | ||||
|     return 1; | ||||
| } | ||||
| 
 | ||||
| bool got_linefeed = false; | ||||
| 
 | ||||
| void low_level_write_char(char ch) | ||||
| { | ||||
|     (void)sendchar((int)ch); | ||||
|  | ||||
| @ -1,6 +1,119 @@ | ||||
| #include "string.h" | ||||
| #include "lwip/netif.h" | ||||
| #include "wm_include.h" | ||||
| #include "FreeRTOS.h" | ||||
| #include "FreeRTOSConfig.h" | ||||
| #include "nano_shell_server_task.h" | ||||
| #include "common.h" | ||||
| 
 | ||||
| extern int shell_printf(const char *format, ...); | ||||
| extern void network_rx_callback(u16 len, char *data); | ||||
| 
 | ||||
| int nano_shell_srv_sock = 0, client_sock = 0; | ||||
| const char greeting_buffer[] = "\r\n" | ||||
|              " _   _                     ____  _          _ _\r\n" | ||||
|              "| \\ | | __ _ _ __   ___   / ___|| |__   ___| | |\r\n" | ||||
|              "|  \\| |/ _` | '_ \\ / _ \\  \\___ \\| '_ \\ / _ \\ | |\r\n" | ||||
|              "| |\\  | (_| | | | | (_) |  ___) | | | |  __/ | |\r\n" | ||||
|              "|_| \\_|\\__,_|_| |_|\\___/  |____/|_| |_|\\___|_|_|\r\n" | ||||
|              "\r\n" | ||||
|              "Welcome to Nano-Shell remote access\r\n" | ||||
|              "\r\n" | ||||
|              " * Source:    https://github.com/lebinlv/nano-shell\r\n" | ||||
|              " * Copyright: (c) Liber 2020\r\n" | ||||
|              "\r\n"; | ||||
| 
 | ||||
| void network_write(char c) | ||||
| { | ||||
|     if(client_sock > 0) | ||||
|     { | ||||
|         if(send(client_sock, &c, 1, 0) < 0) | ||||
|         { | ||||
|             shell_printf("Failed to send data to client - errno(%d)."NEW_LINE, errno); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void nano_shell_server_task(void* param) | ||||
| { | ||||
|     (void)param; | ||||
| 
 | ||||
|     bool setup_error = false; | ||||
|     char recv_buffer[256] = ""; | ||||
|     //We setup the listening socket :
 | ||||
|     struct sockaddr_in nano_shell_srv_addr = { .sin_family = AF_INET, .sin_addr.s_addr = INADDR_ANY, .sin_port = htons(NANO_SHELL_SERVER_PORT)}, client_addr; | ||||
|     socklen_t sockaddr_in_len = sizeof(struct sockaddr_in); | ||||
| 
 | ||||
|     if((nano_shell_srv_sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) | ||||
|     { | ||||
|         shell_printf("Failed to create nano_shell listening socket."NEW_LINE); | ||||
|         setup_error = true; | ||||
|     } | ||||
| 
 | ||||
|     if(bind(nano_shell_srv_sock, (struct sockaddr *) &nano_shell_srv_addr, sockaddr_in_len) < 0) | ||||
|     { | ||||
|         shell_printf("Failed to bind nano_shell listening socket to addr."NEW_LINE); | ||||
|         setup_error = true; | ||||
|     } | ||||
| 
 | ||||
|     //We only wait for one connection at a time because the nano_shell is not multi user anyway
 | ||||
|     if(listen(nano_shell_srv_sock, 0) < 0) | ||||
|     { | ||||
|         shell_printf("Failed to mark nano_shell_sock as a listening socket."NEW_LINE); | ||||
|         setup_error = true; | ||||
|     } | ||||
| 
 | ||||
|     if(setup_error) | ||||
|     { | ||||
|         for(;;) | ||||
|             tls_os_time_delay(portMAX_DELAY); | ||||
|     } | ||||
|      | ||||
|     for(;;) | ||||
|     { | ||||
|         if((client_sock = accept(nano_shell_srv_sock, (struct sockaddr *)&client_addr, &sockaddr_in_len)) < 0) | ||||
|         { | ||||
|             shell_printf("Failed to accept incoming connection."NEW_LINE); | ||||
|         } | ||||
| 
 | ||||
|         if(send(client_sock, greeting_buffer, sizeof greeting_buffer, 0) < 0) | ||||
|         { | ||||
|             shell_printf("Failed to send greetings to client - errno(%d)."NEW_LINE, errno); | ||||
| 
 | ||||
|         } | ||||
| 
 | ||||
|         for(;client_sock > 0;) | ||||
|         { | ||||
|             int result = recv(client_sock, recv_buffer, 255, 0); | ||||
|             if(result < 0) | ||||
|             { | ||||
|                 shell_printf("Failed to receive data from client - errno(%d)."NEW_LINE"Closing connection."NEW_LINE, errno); | ||||
|                 if(close(client_sock) < 0) | ||||
|                 { | ||||
|                     shell_printf("Failed to close socket - errno(%d)."NEW_LINE, errno); | ||||
|                 } | ||||
|                 client_sock = 0; | ||||
|             } | ||||
|             else if(result == 0) | ||||
|             { | ||||
|                 shell_printf("Client disconnected."NEW_LINE); | ||||
|                 if(close(client_sock) < 0) | ||||
|                 { | ||||
|                     shell_printf("Failed to close socket - errno(%d)."NEW_LINE, errno); | ||||
|                 } | ||||
|                 client_sock = 0; | ||||
|             } | ||||
|             else //We pass the received data to the nano shell process
 | ||||
|             { | ||||
|                 //Need to remove the \n at the end
 | ||||
|                 char *pos = strchr(recv_buffer, '\r'); | ||||
|                 if(pos) | ||||
|                 { | ||||
|                     *pos = '\n'; | ||||
|                     result = pos + 1 - recv_buffer; | ||||
|                 } | ||||
|                 network_rx_callback(result, recv_buffer); | ||||
|             } | ||||
|         }   | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,3 @@ | ||||
| #define NANO_SHELL_SERVER_PORT 21  | ||||
| 
 | ||||
| void nano_shell_server_task(void* param); | ||||
| @ -835,6 +835,33 @@ typedef QueueHandle_t SemaphoreHandle_t; | ||||
|  */ | ||||
| #define xSemaphoreGetMutexHolder( xSemaphore ) xQueueGetMutexHolder( ( xSemaphore ) ) | ||||
| 
 | ||||
| /**
 | ||||
|  * semphr.h | ||||
|  * @code{c} | ||||
|  * UBaseType_t uxSemaphoreGetCount( SemaphoreHandle_t xSemaphore ); | ||||
|  * @endcode | ||||
|  * | ||||
|  * If the semaphore is a counting semaphore then uxSemaphoreGetCount() returns | ||||
|  * its current count value.  If the semaphore is a binary semaphore then | ||||
|  * uxSemaphoreGetCount() returns 1 if the semaphore is available, and 0 if the | ||||
|  * semaphore is not available. | ||||
|  * | ||||
|  */ | ||||
| #define uxSemaphoreGetCount( xSemaphore ) uxQueueMessagesWaiting( ( QueueHandle_t ) ( xSemaphore ) ) | ||||
| 
 | ||||
| /**
 | ||||
|  * semphr.h | ||||
|  * @code{c} | ||||
|  * UBaseType_t uxSemaphoreGetCountFromISR( SemaphoreHandle_t xSemaphore ); | ||||
|  * @endcode | ||||
|  * | ||||
|  * If the semaphore is a counting semaphore then uxSemaphoreGetCountFromISR() returns | ||||
|  * its current count value.  If the semaphore is a binary semaphore then | ||||
|  * uxSemaphoreGetCountFromISR() returns 1 if the semaphore is available, and 0 if the | ||||
|  * semaphore is not available. | ||||
|  * | ||||
|  */ | ||||
| #define uxSemaphoreGetCountFromISR( xSemaphore ) uxQueueMessagesWaitingFromISR( ( QueueHandle_t ) ( xSemaphore ) ) | ||||
| #endif /* SEMAPHORE_H */ | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
| @ -515,7 +515,7 @@ tls_os_status_t tls_os_task_resume_from_isr(tls_os_task_t task) | ||||
| 
 | ||||
| u16 tls_os_sem_get_count(tls_os_sem_t *sem) | ||||
| { | ||||
|     return (u16)xSemaphoreGetCount((xQUEUE *)sem); | ||||
|     return (u16)uxSemaphoreGetCount((xQUEUE *)sem); | ||||
| } | ||||
| 
 | ||||
| /*
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user