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_broadcast.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 "emac_tests.h" 00026 #include "emac_util.h" 00027 #include "emac_ctp.h" 00028 00029 using namespace utest::v1; 00030 00031 void test_emac_broadcast_cb(int opt) 00032 { 00033 static bool send_request = true; 00034 static int no_response_cnt = 0; 00035 static int retries = 0; 00036 static int test_step = 0; 00037 static int msg_len = 100; 00038 static int wait = 0; 00039 00040 if (wait) { 00041 --wait; 00042 return; 00043 } 00044 00045 #if MBED_CONF_APP_ECHO_SERVER 00046 static bool echo_server_started = false; 00047 if (!echo_server_started) { 00048 #if MBED_CONF_APP_ECHO_SERVER_TRACE == 0 00049 SET_TRACE_LEVEL(TRACE_NONE); 00050 #endif 00051 printf("echo server started successfully\r\n\r\n"); 00052 echo_server_started = true; 00053 } else { 00054 // Sends broadcast every 60 seconds 00055 CTP_MSG_SEND(msg_len, eth_mac_broadcast_addr, emac_if_get_own_addr(), emac_if_get_own_addr(), 0); 00056 wait = 60; 00057 } 00058 return; 00059 #endif 00060 00061 // Timeout 00062 if (opt == TIMEOUT && send_request) { 00063 CTP_MSG_SEND(msg_len, eth_mac_broadcast_addr, emac_if_get_own_addr(), emac_if_get_own_addr(), 0); 00064 send_request = false; 00065 no_response_cnt = 0; 00066 } else if (opt == TIMEOUT) { 00067 if (++no_response_cnt > 3) { 00068 if (++retries > 6) { 00069 printf("too many retries\r\n\r\n"); 00070 END_TEST_LOOP; 00071 } else { 00072 printf("retry count %i\r\n\r\n", retries); 00073 send_request = true; 00074 } 00075 } 00076 } 00077 00078 // Echo response received 00079 if (opt == INPUT) { 00080 ++test_step; 00081 if (test_step == 3) { 00082 msg_len = 60; 00083 wait = 3; 00084 } else if (test_step == 6) { 00085 END_TEST_LOOP; 00086 } 00087 retries = 0; 00088 send_request = true; 00089 } 00090 } 00091 00092 void test_emac_broadcast(void) 00093 { 00094 RESET_ALL_ERROR_FLAGS; 00095 SET_TRACE_LEVEL(TRACE_SEND | TRACE_ETH_FRAMES | TRACE_SUCCESS | TRACE_FAILURE); 00096 00097 START_TEST_LOOP(test_emac_broadcast_cb, 1 * SECOND_TO_MS); 00098 00099 PRINT_ERROR_FLAGS; 00100 TEST_ASSERT_FALSE(ERROR_FLAGS); 00101 RESET_OUTGOING_MSG_DATA; 00102 } 00103 00104 #endif
Generated on Tue Jul 12 2022 12:43:52 by
1.7.2