Made feature-emac changes to emac greentea tests default code

Removed flagging of the new/old code.
pull/6847/head
Mika Leppänen 2018-03-02 14:43:35 +02:00 committed by Kevin Bracey
parent 7aebda7a0f
commit c1c69be10b
12 changed files with 7 additions and 270 deletions

View File

@ -15,7 +15,7 @@
* limitations under the License.
*/
#if MBED_CONF_APP_TEST_EMAC
#if MBED_CONF_APP_TEST_WIFI || MBED_CONF_APP_TEST_ETHERNET
#include <stdio.h>
#include <stdarg.h>

View File

@ -15,7 +15,8 @@
* limitations under the License.
*/
#if MBED_CONF_APP_TEST_EMAC
#if MBED_CONF_APP_TEST_WIFI || MBED_CONF_APP_TEST_ETHERNET
#ifndef EMAC_TEST_MEMORY_MANAGER_H
#define EMAC_TEST_MEMORY_MANAGER_H

View File

@ -15,7 +15,7 @@
* limitations under the License.
*/
#if MBED_CONF_APP_TEST_EMAC
#if MBED_CONF_APP_TEST_WIFI || MBED_CONF_APP_TEST_ETHERNET
#include "unity.h"

View File

@ -15,7 +15,7 @@
* limitations under the License.
*/
#if MBED_CONF_APP_TEST_EMAC
#if MBED_CONF_APP_TEST_WIFI || MBED_CONF_APP_TEST_ETHERNET
#ifndef EMAC_TEST_NETWORK_STACK_H
#define EMAC_TEST_NETWORK_STACK_H

View File

@ -23,20 +23,10 @@
#include "mbed.h"
#if MBED_CONF_APP_TEST_EMAC
#include "EMAC.h"
#include "EMACMemoryManager.h"
#include "emac_TestMemoryManager.h"
#else
#include "lwip/opt.h" /* ETH_PAD_SIZE */
#include "emac_stack_mem.h"
#include "emac_api.h"
#endif
#include "emac_tests.h"
#include "emac_ctp.h"
@ -126,7 +116,6 @@ void emac_if_ctp_msg_build(int eth_frame_len, const unsigned char *dest_addr, co
return;
}
#if MBED_CONF_APP_TEST_EMAC
int alloc_opt = 0;
int align = 0;
if (options & CTP_OPT_NON_ALIGNED) {
@ -141,9 +130,6 @@ void emac_if_ctp_msg_build(int eth_frame_len, const unsigned char *dest_addr, co
// Default allocation is from pool
buf = emac_m_mngr_get()->alloc_pool(eth_frame_len, align, alloc_opt);
}
#else
emac_stack_mem_chain_t *buf = emac_stack_mem_alloc(0, eth_frame_len + ETH_PAD_SIZE, 0);
#endif
if (!buf) {
SET_ERROR_FLAGS(NO_FREE_MEM_BUF);
@ -161,14 +147,9 @@ void emac_if_ctp_msg_build(int eth_frame_len, const unsigned char *dest_addr, co
emac_if_memory_buffer_write(buf, eth_output_frame_data, true);
#if MBED_CONF_APP_TEST_EMAC
emac_if_check_memory(true);
emac_if_get()->link_out(buf);
emac_if_check_memory(false);
#else
emac_if_get()->ops.link_out(emac_if_get(), buf);
emac_stack_mem_free(0, buf);
#endif
}
#endif

View File

@ -20,12 +20,7 @@
unsigned char *emac_if_get_hw_addr(void);
bool emac_if_init(void);
#if MBED_CONF_APP_TEST_EMAC
EMAC *emac_if_get(void);
EmacTestMemoryManager *emac_m_mngr_get(void);
#else
emac_interface_t *emac_if_get(void);
#endif
#endif /* EMAC_INITIALIZE_H */

View File

@ -26,25 +26,14 @@
#include "mbed.h"
#if MBED_CONF_APP_TEST_EMAC
#include "EMAC.h"
#include "EMACMemoryManager.h"
#include "emac_TestMemoryManager.h"
#else
#include "emac_api.h"
#include "emac_stack_mem.h"
#endif
#include "emac_initialize.h"
#include "emac_membuf.h"
#include "emac_util.h"
#if MBED_CONF_APP_TEST_EMAC
int emac_if_memory_buffer_read(void *buf, unsigned char *eth_frame)
{
int eth_frame_index = 0;
@ -91,58 +80,4 @@ void emac_if_memory_buffer_write(void *buf, unsigned char *eth_frame, bool write
}
}
#else
int emac_if_memory_buffer_read(void *buf, unsigned char *eth_frame)
{
int eth_frame_index = 0;
int invalid_data_index = 0;
int index = ETH_PAD_SIZE;
for (emac_stack_mem_t *mem_p = emac_stack_mem_chain_dequeue(0, &buf); mem_p != NULL; mem_p = emac_stack_mem_chain_dequeue(0, &buf)) {
unsigned char *buf_payload = (unsigned char *) emac_stack_mem_ptr(0, mem_p);
int buf_payload_len = emac_stack_mem_len(0, mem_p);
for (; index < buf_payload_len; index++) {
if (eth_frame_index < ETH_FRAME_HEADER_LEN) {
eth_frame[eth_frame_index] = buf_payload[index];
} else {
if (buf_payload[index] != (uint8_t) eth_frame_index) {
invalid_data_index = eth_frame_index;
break;
}
}
eth_frame_index++;
}
index = 0;
}
return invalid_data_index;
}
void emac_if_memory_buffer_write(void *buf, unsigned char *eth_frame, bool write_data)
{
int eth_frame_index = 0;
int index = ETH_PAD_SIZE;
for (emac_stack_mem_t *mem_p = emac_stack_mem_chain_dequeue(0, &buf); mem_p != NULL; mem_p = emac_stack_mem_chain_dequeue(0, &buf)) {
unsigned char *buf_payload = (unsigned char *) emac_stack_mem_ptr(0, mem_p);
int buf_payload_len = emac_stack_mem_len(0, mem_p);
for (; index < buf_payload_len; index++) {
if (eth_frame_index < ETH_FRAME_HEADER_LEN) {
buf_payload[index] = eth_frame[eth_frame_index];
} else if (write_data) {
buf_payload[index] = (char) eth_frame_index;
} else {
break;
}
eth_frame_index++;
}
index = 0;
}
}
#endif
#endif

View File

@ -24,30 +24,20 @@
#if MBED_CONF_APP_TEST_WIFI || MBED_CONF_APP_TEST_ETHERNET
#if MBED_CONF_APP_TEST_EMAC
#include "EthernetInterface.h"
#include "EMAC.h"
#include "EMACMemoryManager.h"
#include "emac_TestMemoryManager.h"
#include "emac_TestNetworkStack.h"
#else
#include "inttypes.h"
#if MBED_CONF_APP_TEST_WIFI
#ifdef TARGET_UBLOX_EVK_ODIN_W2
#include "wifi_emac_api.h"
#include "OdinWiFiInterface.h"
#endif
#ifdef TARGET_REALTEK_RTL8195AM
#include "rtw_emac.h"
#include "RTWInterface.h"
#endif
#endif
#include "emac_api.h"
#endif
@ -59,17 +49,10 @@ using namespace utest::v1;
static unsigned char eth_mac_addr[ETH_MAC_ADDR_LEN];
#if !MBED_CONF_APP_TEST_EMAC
static char emac_if_link_state_change_cb_data[] = "link_state_change_cb_data";
static char emac_if_link_input_cb_data[] = "link_input_cb_data";
#endif
void test_emac_initialize()
{
worker_loop_init();
#if MBED_CONF_APP_TEST_EMAC
#if MBED_CONF_APP_TEST_ETHERNET
static EthernetInterface *network_interface = new EthernetInterface;
@ -112,46 +95,6 @@ void test_emac_initialize()
network_interface->connect();
worker_loop_link_up_wait();
#else
#if MBED_CONF_APP_TEST_WIFI
static WiFiInterface *wifi;
#ifdef TARGET_UBLOX_EVK_ODIN_W2
wifi = new OdinWiFiInterface;
#endif
#ifdef TARGET_REALTEK_RTL8195AM
wifi = new RTWInterface;
#endif
#if MBED_CONF_APP_WIFI_SCAN
WiFiAccessPoint ap[30];
int size = wifi->scan(ap, 30);
for (int i=0; i<size; i++) {
const char *ssid = ap[i].get_ssid();
nsapi_security_t security = ap[i].get_security();
int8_t rssi = ap[i].get_rssi();
char ch = ap[i].get_channel();
printf("BS %i\r\n", i);
printf("ssid %s\r\n", ssid);
printf("security %i\r\n", security);
printf("rssi %i\r\n", rssi);
printf("ch %i\r\n\r\n", ch);
}
#endif
wifi->set_credentials(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD, MBED_CONF_APP_WIFI_SECURITY);
wifi->connect();
const char *ip_addr = wifi->get_ip_address();
printf("connected IP %s\r\n\r\n", ip_addr);
TEST_ASSERT(emac_if_init());
#endif
#endif
}
unsigned char *emac_if_get_hw_addr(void)
@ -159,7 +102,6 @@ unsigned char *emac_if_get_hw_addr(void)
return &eth_mac_addr[0];
}
#if MBED_CONF_APP_TEST_EMAC
EMAC *emac_if_get(void)
{
return &EMAC::get_default_instance();
@ -170,26 +112,8 @@ EmacTestMemoryManager *emac_m_mngr_get(void)
return &EmacTestMemoryManager::get_instance();
}
#else
emac_interface_t *emac_if_get(void)
{
#if MBED_CONF_APP_TEST_WIFI
#ifdef TARGET_UBLOX_EVK_ODIN_W2
return wifi_emac_get_interface();
#endif
#ifdef TARGET_REALTEK_RTL8195AM
return wlan_emac_init_interface();
#endif
#else
return 0;
#endif
}
#endif
bool emac_if_init(void)
{
#if MBED_CONF_APP_TEST_EMAC
static EMAC *emac = &EMAC::get_default_instance();
static EmacTestMemoryManager *memory_manager = &EmacTestMemoryManager::get_instance();
emac->set_memory_manager(*memory_manager);
@ -221,34 +145,6 @@ bool emac_if_init(void)
printf("emac if name %s\r\n\r\n", hw_name);
return true;
#else
emac_interface_t *emac_if = emac_if_get();
emac_if->ops.set_link_input_cb(emac_if, emac_if_link_input_cb, emac_if_link_input_cb_data);
emac_if->ops.set_link_state_cb(emac_if, emac_if_link_state_change_cb, emac_if_link_state_change_cb_data);
int hwaddr_len = emac_if->ops.get_hwaddr_size(emac_if);
printf("emac hwaddr length %i\r\n\r\n", hwaddr_len);
if (hwaddr_len == 6) {
emac_if->ops.get_hwaddr(emac_if, eth_mac_addr);
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]);
}
int mtu_size = emac_if->ops.get_mtu_size(emac_if);
printf("emac mtu %i\r\n\r\n", mtu_size);
emac_if_set_mtu_size(mtu_size);
char hw_name[11];
emac_if->ops.get_ifname(emac_if, hw_name, 10);
printf("emac if name %s\r\n\r\n", hw_name);
if (!emac_if->ops.power_up(emac_if)) {
return false;
}
return true;
#endif
}
#endif

View File

@ -24,23 +24,10 @@
#include "mbed.h"
#if MBED_CONF_APP_TEST_EMAC
#include "EMAC.h"
#include "EMACMemoryManager.h"
#include "emac_TestMemoryManager.h"
#else
extern "C" { // netif input
#include "tcpip.h"
}
#include "emac_api.h"
#include "emac_stack_mem.h"
#endif
#include "emac_tests.h"
#include "emac_initialize.h"
#include "emac_util.h"
@ -49,7 +36,6 @@ extern "C" { // netif input
using namespace utest::v1;
typedef struct {
int length;
int receipt_number;
@ -368,16 +354,12 @@ void emac_if_trace_to_ascii_hex_dump(const char *prefix, int len, unsigned char
void emac_if_set_all_multicast(bool all)
{
#if MBED_CONF_APP_TEST_EMAC
emac_if_get()->set_all_multicast(all);
#endif
}
void emac_if_add_multicast_group(uint8_t *address)
{
#if MBED_CONF_APP_TEST_EMAC
emac_if_get()->add_multicast_group(address);
#endif
}
void emac_if_set_output_memory(bool memory)
@ -403,21 +385,15 @@ void emac_if_check_memory(bool output)
void emac_if_set_memory(bool memory)
{
#if MBED_CONF_APP_TEST_EMAC
static bool memory_value = true;
if (memory_value != memory ) {
memory_value = memory;
EmacTestMemoryManager *mem_mngr = emac_m_mngr_get();
mem_mngr->set_memory_available(memory);
}
#endif
}
#if MBED_CONF_APP_TEST_EMAC
void emac_if_link_state_change_cb(bool up)
#else
void emac_if_link_state_change_cb(void *data, bool up)
#endif
{
if (up) {
worker_loop_event.post(LINK_UP);
@ -426,22 +402,14 @@ void emac_if_link_state_change_cb(void *data, bool up)
}
}
#if MBED_CONF_APP_TEST_EMAC
void emac_if_link_input_cb(void *buf)
#else
void emac_if_link_input_cb(void *data, void *buf)
#endif
{
link_input_event.post(buf);
}
static void link_input_event_cb(void *buf)
{
#if MBED_CONF_APP_TEST_EMAC
int length = emac_m_mngr_get()->get_total_len(buf);
#else
int length = emac_stack_mem_len(0, buf);
#endif
if (length >= ETH_FRAME_HEADER_LEN) {
// Ethernet input frame
@ -472,53 +440,24 @@ static void link_input_event_cb(void *buf)
// Echoes only if configured as echo server
} else if (function == CTP_FORWARD) {
emac_if_memory_buffer_write(buf, eth_output_frame_data, false);
#if MBED_CONF_APP_TEST_EMAC
emac_if_get()->link_out(buf);
buf = 0;
#else
emac_if_get()->ops.link_out(emac_if_get(), buf);
#endif
#endif
}
emac_if_add_echo_server_addr(&eth_input_frame_data[6]);
#if !MBED_CONF_APP_TEST_EMAC
emac_stack_mem_free(0, buf);
#endif
if (trace_level & TRACE_ETH_FRAMES) {
printf("INP> LEN %i\r\n\r\n", length);
const char trace_type[] = "INP>";
emac_if_trace_to_ascii_hex_dump(trace_type, ETH_FRAME_HEADER_LEN, eth_input_frame_data);
}
#if !MBED_CONF_APP_TEST_EMAC
return;
#endif
}
}
#if MBED_CONF_APP_TEST_EMAC
if (buf) {
emac_m_mngr_get()->free(buf);
}
#else
// Forward other than CTP frames to lwip
struct netif *netif;
/* loop through netif's */
netif = netif_list;
if (netif != NULL) {
struct pbuf *p = (struct pbuf *)buf;
/* pass all packets to ethernet_input, which decides what packets it supports */
if (netif->input(p, netif) != ERR_OK) {
emac_stack_mem_free(0, buf);
}
} else {
emac_stack_mem_free(0, buf);
}
#endif
}
static unsigned char thread_stack[2048];

View File

@ -108,13 +108,8 @@ unsigned char *emac_if_get_own_addr(void);
int emac_if_get_mtu_size();
void emac_if_set_mtu_size(int mtu_size);
#if MBED_CONF_APP_TEST_EMAC
extern void emac_if_link_input_cb(void *buf);
extern void emac_if_link_state_change_cb(bool up);
#else
extern void emac_if_link_input_cb(void *data, void *buf);
extern void emac_if_link_state_change_cb(void *data, bool up);
#endif
void emac_if_set_all_multicast(bool all);
void emac_if_add_multicast_group(uint8_t *address);

View File

@ -15,8 +15,7 @@
* limitations under the License.
*/
#if !defined(MBED_CONF_APP_TEST_EMAC) || \
!defined(MBED_CONF_APP_TEST_WIFI) || \
#if !defined(MBED_CONF_APP_TEST_WIFI) || \
!defined(MBED_CONF_APP_TEST_ETHERNET) || \
!defined(MBED_CONF_APP_ECHO_SERVER) || \
!defined(MBED_CONF_APP_WIFI_SCAN) || \

View File

@ -1,9 +1,5 @@
{
"config": {
"test-emac": {
"help": "Test feature-emac version of the emac",
"value": 1
},
"test-ethernet": {
"help": "Enable ethernet testing",
"value": 1