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.
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 <inttypes.h> 00019 #include "mbed.h" 00020 #include "mbed_stats.h" 00021 #include "greentea-client/test_env.h" 00022 #include "unity.h" 00023 #include "utest.h" 00024 00025 #if MBED_CONF_APP_TEST_WIFI || MBED_CONF_APP_TEST_ETHERNET 00026 00027 #include "EthernetInterface.h" 00028 #include "EMAC.h" 00029 #include "EMACMemoryManager.h" 00030 #include "emac_TestMemoryManager.h" 00031 #include "emac_TestNetworkStack.h" 00032 00033 #if MBED_CONF_APP_TEST_WIFI 00034 00035 #if defined(TARGET_UBLOX_EVK_ODIN_W2) || defined(TARGET_MTB_UBLOX_ODIN_W2) 00036 #include "OdinWiFiInterface.h" 00037 #endif 00038 #ifdef TARGET_REALTEK_RTL8195AM 00039 #include "RTWInterface.h" 00040 #endif 00041 #if defined(TARGET_MTB_ADV_WISE_1530) || \ 00042 defined(TARGET_MTB_USI_WM_BN_BM_22) || \ 00043 defined(TARGET_MTB_MXCHIP_EMW3166) 00044 #include "WicedInterface.h" 00045 #endif 00046 00047 #endif 00048 00049 #include "emac_initialize.h" 00050 #include "emac_tests.h" 00051 #include "emac_util.h" 00052 00053 using namespace utest::v1; 00054 00055 static unsigned char eth_mac_addr[ETH_MAC_ADDR_LEN]; 00056 EMAC *emac_handle = NULL; 00057 00058 void test_emac_initialize() 00059 { 00060 worker_loop_init(); 00061 00062 #if MBED_CONF_APP_TEST_ETHERNET 00063 00064 static EthernetInterface *network_interface = new EthernetInterface; 00065 00066 #elif MBED_CONF_APP_TEST_WIFI 00067 00068 // Add wifi classes here 00069 #if defined(TARGET_UBLOX_EVK_ODIN_W2) || defined(TARGET_MTB_UBLOX_ODIN_W2) 00070 static WiFiInterface *network_interface = new OdinWiFiInterface; 00071 #elif defined(TARGET_REALTEK_RTL8195AM) 00072 static WiFiInterface *network_interface = new RTWInterface; 00073 #elif defined(TARGET_MTB_ADV_WISE_1530) || \ 00074 defined(TARGET_MTB_USI_WM_BN_BM_22) || \ 00075 defined(TARGET_MTB_MXCHIP_EMW3166) 00076 static WiFiInterface *network_interface = new WicedInterface; 00077 #else 00078 static WiFiInterface *network_interface = new WiFiInterface; 00079 #endif 00080 00081 #if MBED_CONF_APP_WIFI_SCAN 00082 WiFiAccessPoint ap[30]; 00083 00084 int size = network_interface->scan(ap, 30); 00085 00086 for (int i=0; i<size; i++) { 00087 const char *ssid = ap[i].get_ssid(); 00088 nsapi_security_t security = ap[i].get_security(); 00089 int8_t rssi = ap[i].get_rssi(); 00090 char ch = ap[i].get_channel(); 00091 00092 printf("BS %i\r\n", i); 00093 printf("ssid %s\r\n", ssid); 00094 printf("security %i\r\n", security); 00095 printf("rssi %i\r\n", rssi); 00096 printf("ch %i\r\n\r\n", ch); 00097 } 00098 #endif 00099 00100 network_interface->set_credentials(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD, MBED_CONF_APP_WIFI_SECURITY); 00101 00102 #endif 00103 00104 // Power up the interface and emac driver 00105 network_interface->connect(); 00106 00107 worker_loop_link_up_wait(); 00108 } 00109 00110 unsigned char *emac_if_get_hw_addr(void) 00111 { 00112 return ð_mac_addr[0]; 00113 } 00114 00115 EMAC *emac_if_get(void) 00116 { 00117 return emac_handle; 00118 } 00119 00120 EmacTestMemoryManager *emac_m_mngr_get(void) 00121 { 00122 return &EmacTestMemoryManager::get_instance(); 00123 } 00124 00125 bool emac_if_init(EMAC *emac) 00126 { 00127 emac_handle = emac; 00128 00129 emac->set_link_input_cb(emac_if_link_input_cb); 00130 emac->set_link_state_cb(emac_if_link_state_change_cb); 00131 00132 if (!emac->power_up()) { 00133 TEST_ASSERT_MESSAGE(0, "emac power up failed!"); 00134 } 00135 00136 int hwaddr_len = emac->get_hwaddr_size(); 00137 printf("emac hwaddr length %i\r\n\r\n", hwaddr_len); 00138 00139 TEST_ASSERT_MESSAGE(hwaddr_len == 6, "invalid emac hwaddr length!"); 00140 00141 // If driver updates this, write it back, otherwise write default from mbed_mac_address 00142 mbed_mac_address(reinterpret_cast<char *>(ð_mac_addr[0])); 00143 emac->get_hwaddr(eth_mac_addr); 00144 emac->set_hwaddr(eth_mac_addr); 00145 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]); 00146 00147 int mtu_size = emac->get_mtu_size(); 00148 printf("emac mtu %i\r\n\r\n", mtu_size); 00149 emac_if_set_mtu_size(mtu_size); 00150 00151 char hw_name[11]; 00152 emac->get_ifname(hw_name, 10); 00153 printf("emac if name %s\r\n\r\n", hw_name); 00154 00155 return true; 00156 } 00157 00158 #endif
Generated on Tue Jul 12 2022 12:43:52 by
