Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of OmniWheels by
emac_test_initialize.cpp
00001 /* 00002 * Copyright (c) 2017, ARM Limited, All Rights Reserved 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); you may 00006 * not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00013 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 #include "mbed.h" 00019 #include "greentea-client/test_env.h" 00020 #include "unity.h" 00021 #include "utest.h" 00022 00023 #if MBED_CONF_APP_TEST_WIFI || MBED_CONF_APP_TEST_ETHERNET 00024 00025 #include "inttypes.h" 00026 00027 #if MBED_CONF_APP_TEST_WIFI 00028 #ifdef TARGET_UBLOX_EVK_ODIN_W2 00029 #include "wifi_emac_api.h" 00030 #include "OdinWiFiInterface.h" 00031 #endif 00032 #ifdef TARGET_REALTEK_RTL8195AM 00033 #include "rtw_emac.h" 00034 #include "RTWInterface.h" 00035 #endif 00036 #endif 00037 00038 #include "emac_api.h" 00039 #include "emac_tests.h" 00040 #include "emac_util.h" 00041 00042 using namespace utest::v1; 00043 00044 static unsigned char eth_mac_addr[ETH_MAC_ADDR_LEN]; 00045 00046 static char emac_if_link_state_change_cb_data[] = "link_state_change_cb_data"; 00047 static char emac_if_link_input_cb_data[] = "link_input_cb_data"; 00048 00049 static bool emac_if_init(void); 00050 00051 void test_emac_initialize() 00052 { 00053 #if MBED_CONF_APP_TEST_WIFI 00054 static WiFiInterface *wifi; 00055 00056 #ifdef TARGET_UBLOX_EVK_ODIN_W2 00057 wifi = new OdinWiFiInterface; 00058 #endif 00059 #ifdef TARGET_REALTEK_RTL8195AM 00060 wifi = new RTWInterface; 00061 #endif 00062 00063 #if MBED_CONF_APP_WIFI_SCAN 00064 WiFiAccessPoint ap[30]; 00065 00066 int size = wifi->scan(ap, 30); 00067 00068 for (int i=0; i<size; i++) { 00069 const char *ssid = ap[i].get_ssid(); 00070 nsapi_security_t security = ap[i].get_security(); 00071 int8_t rssi = ap[i].get_rssi(); 00072 char ch = ap[i].get_channel(); 00073 00074 printf("BS %i\r\n", i); 00075 printf("ssid %s\r\n", ssid); 00076 printf("security %i\r\n", security); 00077 printf("rssi %i\r\n", rssi); 00078 printf("ch %i\r\n\r\n", ch); 00079 } 00080 #endif 00081 00082 wifi->set_credentials(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD, MBED_CONF_APP_WIFI_SECURITY); 00083 wifi->connect(); 00084 00085 const char *ip_addr = wifi->get_ip_address(); 00086 printf("connected IP %s\r\n\r\n", ip_addr); 00087 #endif 00088 00089 TEST_ASSERT(emac_if_init()); 00090 } 00091 00092 unsigned char *emac_if_get_hw_addr(void) 00093 { 00094 return ð_mac_addr[0]; 00095 } 00096 00097 emac_interface_t *emac_if_get(void) 00098 { 00099 #if MBED_CONF_APP_TEST_WIFI 00100 #ifdef TARGET_UBLOX_EVK_ODIN_W2 00101 return wifi_emac_get_interface(); 00102 #endif 00103 #ifdef TARGET_REALTEK_RTL8195AM 00104 return wlan_emac_init_interface(); 00105 #endif 00106 #else 00107 return 0; 00108 #endif 00109 } 00110 00111 static bool emac_if_init(void) 00112 { 00113 emac_interface_t *emac_if = emac_if_get(); 00114 00115 emac_if->ops.set_link_input_cb(emac_if, emac_if_link_input_cb, emac_if_link_input_cb_data); 00116 emac_if->ops.set_link_state_cb(emac_if, emac_if_link_state_change_cb, emac_if_link_state_change_cb_data); 00117 00118 int hwaddr_len = emac_if->ops.get_hwaddr_size(emac_if); 00119 printf("emac hwaddr length %i\r\n\r\n", hwaddr_len); 00120 00121 if (hwaddr_len == 6) { 00122 emac_if->ops.get_hwaddr(emac_if, eth_mac_addr); 00123 printf("emac hwaddr %x:%x:%x:%x:%x:%x\r\n\r\n", eth_mac_addr[0],eth_mac_addr[1],eth_mac_addr[2],eth_mac_addr[3],eth_mac_addr[4],eth_mac_addr[5]); 00124 } 00125 00126 int mtu = emac_if->ops.get_mtu_size(emac_if); 00127 printf("emac mtu %i\r\n\r\n", mtu); 00128 00129 char hw_name[11]; 00130 emac_if->ops.get_ifname(emac_if, hw_name, 10); 00131 printf("emac if name %s\r\n\r\n", hw_name); 00132 00133 if (!emac_if->ops.power_up(emac_if)) { 00134 return false; 00135 } 00136 00137 return true; 00138 } 00139 00140 #endif
Generated on Fri Jul 22 2022 04:53:47 by
1.7.2
