Gleb Klochkov / Mbed OS Climatcontroll_Main

Dependencies:   esp8266-driver

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers emac_membuf.cpp Source File

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 "emac_api.h"
00028 #include "emac_stack_mem.h"
00029 
00030 #include "emac_membuf.h"
00031 #include "emac_util.h"
00032 
00033 int emac_if_memory_buffer_read(emac_stack_mem_chain_t *mem_chain_p, unsigned char *eth_frame)
00034 {
00035     int eth_frame_index = 0;
00036     int invalid_data_index = 0;
00037     int index = ETH_PAD_SIZE;
00038 
00039     for (emac_stack_mem_t *mem_p = emac_stack_mem_chain_dequeue(0, &mem_chain_p); mem_p != NULL; mem_p = emac_stack_mem_chain_dequeue(0, &mem_chain_p)) {
00040         unsigned char *buf_payload = (unsigned char *) emac_stack_mem_ptr(0, mem_p);
00041         int buf_payload_len = emac_stack_mem_len(0, mem_p);
00042 
00043         for (; index < buf_payload_len; index++) {
00044             if (eth_frame_index < ETH_FRAME_HEADER_LEN) {
00045                 eth_frame[eth_frame_index] = buf_payload[index];
00046             } else {
00047                 if (buf_payload[index] != (uint8_t) eth_frame_index) {
00048                     invalid_data_index = eth_frame_index;
00049                     break;
00050                 }
00051             }
00052             eth_frame_index++;
00053         }
00054         index = 0;
00055     }
00056 
00057     return invalid_data_index;
00058 }
00059 
00060 void emac_if_memory_buffer_write(emac_stack_mem_chain_t *mem_chain_p, unsigned char *eth_frame, bool write_data)
00061 {
00062     int eth_frame_index = 0;
00063     int index = ETH_PAD_SIZE;
00064 
00065     for (emac_stack_mem_t *mem_p = emac_stack_mem_chain_dequeue(0, &mem_chain_p); mem_p != NULL; mem_p = emac_stack_mem_chain_dequeue(0, &mem_chain_p)) {
00066         unsigned char *buf_payload = (unsigned char *) emac_stack_mem_ptr(0, mem_p);
00067         int buf_payload_len = emac_stack_mem_len(0, mem_p);
00068 
00069         for (; index < buf_payload_len; index++) {
00070             if (eth_frame_index < ETH_FRAME_HEADER_LEN) {
00071                 buf_payload[index] = eth_frame[eth_frame_index];
00072             } else if (write_data) {
00073                 buf_payload[index] = (char) eth_frame_index;
00074             } else {
00075                 break;
00076             }
00077             eth_frame_index++;
00078         }
00079         index = 0;
00080     }
00081 }
00082 
00083 #endif