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_membuf.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 "lwip/opt.h" /* ETH_PAD_SIZE */ 00026 00027 #include "mbed.h" 00028 00029 #include "EMAC.h" 00030 #include "EMACMemoryManager.h" 00031 #include "emac_TestMemoryManager.h" 00032 00033 #include "emac_initialize.h" 00034 #include "emac_membuf.h" 00035 #include "emac_util.h" 00036 00037 int emac_if_memory_buffer_read(void *buf, unsigned char *eth_frame) 00038 { 00039 int eth_frame_index = 0; 00040 int invalid_data_index = 0; 00041 00042 for (emac_mem_buf_t *mem_buf = buf; mem_buf != NULL; mem_buf = emac_m_mngr_get()->get_next(mem_buf)) { 00043 unsigned char *buf_payload = (unsigned char *) emac_m_mngr_get()->get_ptr(mem_buf); 00044 int buf_payload_len = emac_m_mngr_get()->get_len(mem_buf); 00045 00046 for (int index = 0; index < buf_payload_len; index++) { 00047 if (eth_frame_index < ETH_FRAME_HEADER_LEN) { 00048 eth_frame[eth_frame_index] = buf_payload[index]; 00049 } else { 00050 if (buf_payload[index] != (uint8_t) eth_frame_index) { 00051 invalid_data_index = eth_frame_index; 00052 break; 00053 } 00054 } 00055 eth_frame_index++; 00056 } 00057 } 00058 00059 return invalid_data_index; 00060 } 00061 00062 void emac_if_memory_buffer_write(void *buf, unsigned char *eth_frame, bool write_data) 00063 { 00064 int eth_frame_index = 0; 00065 00066 for (emac_mem_buf_t *mem_buf = buf; mem_buf != NULL; mem_buf = emac_m_mngr_get()->get_next(mem_buf)) { 00067 unsigned char *buf_payload = (unsigned char *) emac_m_mngr_get()->get_ptr(mem_buf); 00068 int buf_payload_len = emac_m_mngr_get()->get_len(mem_buf); 00069 00070 for (int index = 0; index < buf_payload_len; index++) { 00071 if (eth_frame_index < ETH_FRAME_HEADER_LEN) { 00072 buf_payload[index] = eth_frame[eth_frame_index]; 00073 } else if (write_data) { 00074 buf_payload[index] = (char) eth_frame_index; 00075 } else { 00076 break; 00077 } 00078 eth_frame_index++; 00079 } 00080 } 00081 } 00082 00083 #endif
Generated on Tue Jul 12 2022 12:43:52 by
1.7.2