takashi kadono / Mbed OS Nucleo_446

Dependencies:   ssd1331

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers emac_test_initialize.cpp Source File

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 #include "NetworkInterface.h"
00026 #include "EMAC.h"
00027 #include "EMACMemoryManager.h"
00028 #include "emac_TestMemoryManager.h"
00029 #include "emac_TestNetworkStack.h"
00030 #include "emac_initialize.h"
00031 #include "emac_tests.h"
00032 #include "emac_util.h"
00033 
00034 using namespace utest::v1;
00035 
00036 static unsigned char eth_mac_addr[ETH_MAC_ADDR_LEN];
00037 EMAC *emac_handle = NULL;
00038 
00039 void test_emac_initialize()
00040 {
00041     worker_loop_init();
00042 
00043     static NetworkInterface *network_interface = NetworkInterface::get_default_instance();
00044 
00045 #define WIFI 2
00046 #if MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE == WIFI
00047 #if MBED_CONF_APP_WIFI_SCAN
00048     WiFiAccessPoint ap[30];
00049 
00050     int size = network_interface->wifiInterface()->scan(ap, 30);
00051 
00052     for (int i = 0; i < size; i++) {
00053         const char *ssid = ap[i].get_ssid();
00054         nsapi_security_t security = ap[i].get_security();
00055         int8_t rssi = ap[i].get_rssi();
00056         char ch = ap[i].get_channel();
00057 
00058         printf("BS %i\r\n", i);
00059         printf("ssid %s\r\n", ssid);
00060         printf("security %i\r\n", security);
00061         printf("rssi %i\r\n", rssi);
00062         printf("ch %i\r\n\r\n", ch);
00063     }
00064 #endif
00065 #endif
00066 
00067     // Power up the interface and emac driver
00068     TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK , network_interface->connect());
00069 
00070     worker_loop_link_up_wait();
00071 }
00072 
00073 unsigned char *emac_if_get_hw_addr(void)
00074 {
00075     return &eth_mac_addr[0];
00076 }
00077 
00078 EMAC *emac_if_get(void)
00079 {
00080     return emac_handle;
00081 }
00082 
00083 EmacTestMemoryManager *emac_m_mngr_get(void)
00084 {
00085     return &EmacTestMemoryManager::get_instance();
00086 }
00087 
00088 bool emac_if_init(EMAC *emac)
00089 {
00090     emac_handle = emac;
00091 
00092     emac->set_link_input_cb(emac_if_link_input_cb);
00093     emac->set_link_state_cb(emac_if_link_state_change_cb);
00094 
00095     if (!emac->power_up()) {
00096         TEST_ASSERT_MESSAGE(0, "emac power up failed!");
00097     }
00098 
00099     int hwaddr_len = emac->get_hwaddr_size();
00100     printf("emac hwaddr length %i\r\n\r\n", hwaddr_len);
00101 
00102     TEST_ASSERT_MESSAGE(hwaddr_len == 6, "invalid emac hwaddr length!");
00103 
00104     // If driver updates this, write it back, otherwise write default from mbed_mac_address
00105     mbed_mac_address(reinterpret_cast<char *>(&eth_mac_addr[0]));
00106     emac->get_hwaddr(eth_mac_addr);
00107     emac->set_hwaddr(eth_mac_addr);
00108     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]);
00109 
00110     int mtu_size = emac->get_mtu_size();
00111     printf("emac mtu %i\r\n\r\n", mtu_size);
00112     emac_if_set_mtu_size(mtu_size);
00113 
00114     char hw_name[11];
00115     emac->get_ifname(hw_name, 10);
00116     printf("emac if name %s\r\n\r\n", hw_name);
00117 
00118     return true;
00119 }