mbed-os for GR-LYCHEE
Dependents: mbed-os-example-blinky-gr-lychee GR-Boads_Camera_sample GR-Boards_Audio_Recoder GR-Boads_Camera_DisplayApp ... more
features/FEATURE_LWIP/lwip-interface/emac_stack_lwip.cpp@0:f782d9c66c49, 2018-02-02 (annotated)
- Committer:
- dkato
- Date:
- Fri Feb 02 05:42:23 2018 +0000
- Revision:
- 0:f782d9c66c49
mbed-os for GR-LYCHEE
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dkato | 0:f782d9c66c49 | 1 | /* mbed Microcontroller Library |
dkato | 0:f782d9c66c49 | 2 | * Copyright (c) 2016 ARM Limited |
dkato | 0:f782d9c66c49 | 3 | * |
dkato | 0:f782d9c66c49 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
dkato | 0:f782d9c66c49 | 5 | * you may not use this file except in compliance with the License. |
dkato | 0:f782d9c66c49 | 6 | * You may obtain a copy of the License at |
dkato | 0:f782d9c66c49 | 7 | * |
dkato | 0:f782d9c66c49 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
dkato | 0:f782d9c66c49 | 9 | * |
dkato | 0:f782d9c66c49 | 10 | * Unless required by applicable law or agreed to in writing, software |
dkato | 0:f782d9c66c49 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
dkato | 0:f782d9c66c49 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
dkato | 0:f782d9c66c49 | 13 | * See the License for the specific language governing permissions and |
dkato | 0:f782d9c66c49 | 14 | * limitations under the License. |
dkato | 0:f782d9c66c49 | 15 | */ |
dkato | 0:f782d9c66c49 | 16 | |
dkato | 0:f782d9c66c49 | 17 | #if DEVICE_EMAC |
dkato | 0:f782d9c66c49 | 18 | |
dkato | 0:f782d9c66c49 | 19 | #include "emac_stack_mem.h" |
dkato | 0:f782d9c66c49 | 20 | #include "pbuf.h" |
dkato | 0:f782d9c66c49 | 21 | |
dkato | 0:f782d9c66c49 | 22 | emac_stack_mem_t *emac_stack_mem_alloc(emac_stack_t* stack, uint32_t size, uint32_t align) |
dkato | 0:f782d9c66c49 | 23 | { |
dkato | 0:f782d9c66c49 | 24 | |
dkato | 0:f782d9c66c49 | 25 | struct pbuf *pbuf = pbuf_alloc(PBUF_RAW, size + align, PBUF_RAM); |
dkato | 0:f782d9c66c49 | 26 | if (pbuf == NULL) { |
dkato | 0:f782d9c66c49 | 27 | return NULL; |
dkato | 0:f782d9c66c49 | 28 | } |
dkato | 0:f782d9c66c49 | 29 | |
dkato | 0:f782d9c66c49 | 30 | if (align) { |
dkato | 0:f782d9c66c49 | 31 | uint32_t remainder = (uint32_t)pbuf->payload % align; |
dkato | 0:f782d9c66c49 | 32 | uint32_t offset = align - remainder; |
dkato | 0:f782d9c66c49 | 33 | if (offset >= align) { |
dkato | 0:f782d9c66c49 | 34 | offset = align; |
dkato | 0:f782d9c66c49 | 35 | } |
dkato | 0:f782d9c66c49 | 36 | |
dkato | 0:f782d9c66c49 | 37 | pbuf->payload = (void*)((char*)pbuf->payload + offset); |
dkato | 0:f782d9c66c49 | 38 | pbuf->tot_len -= offset; |
dkato | 0:f782d9c66c49 | 39 | pbuf->len -= offset; |
dkato | 0:f782d9c66c49 | 40 | } |
dkato | 0:f782d9c66c49 | 41 | |
dkato | 0:f782d9c66c49 | 42 | return (emac_stack_mem_t*)pbuf; |
dkato | 0:f782d9c66c49 | 43 | } |
dkato | 0:f782d9c66c49 | 44 | |
dkato | 0:f782d9c66c49 | 45 | void emac_stack_mem_free(emac_stack_t* stack, emac_stack_mem_t *mem) |
dkato | 0:f782d9c66c49 | 46 | { |
dkato | 0:f782d9c66c49 | 47 | pbuf_free((struct pbuf*)mem); |
dkato | 0:f782d9c66c49 | 48 | } |
dkato | 0:f782d9c66c49 | 49 | |
dkato | 0:f782d9c66c49 | 50 | void emac_stack_mem_copy(emac_stack_t* stack, emac_stack_mem_t *to, emac_stack_mem_t *from) |
dkato | 0:f782d9c66c49 | 51 | { |
dkato | 0:f782d9c66c49 | 52 | pbuf_copy((struct pbuf*)to, (struct pbuf*)from); |
dkato | 0:f782d9c66c49 | 53 | } |
dkato | 0:f782d9c66c49 | 54 | |
dkato | 0:f782d9c66c49 | 55 | void *emac_stack_mem_ptr(emac_stack_t* stack, emac_stack_mem_t *mem) |
dkato | 0:f782d9c66c49 | 56 | { |
dkato | 0:f782d9c66c49 | 57 | return ((struct pbuf*)mem)->payload; |
dkato | 0:f782d9c66c49 | 58 | } |
dkato | 0:f782d9c66c49 | 59 | |
dkato | 0:f782d9c66c49 | 60 | uint32_t emac_stack_mem_len(emac_stack_t* stack, emac_stack_mem_t *mem) |
dkato | 0:f782d9c66c49 | 61 | { |
dkato | 0:f782d9c66c49 | 62 | return ((struct pbuf*)mem)->len; |
dkato | 0:f782d9c66c49 | 63 | } |
dkato | 0:f782d9c66c49 | 64 | |
dkato | 0:f782d9c66c49 | 65 | void emac_stack_mem_set_len(emac_stack_t* stack, emac_stack_mem_t *mem, uint32_t len) |
dkato | 0:f782d9c66c49 | 66 | { |
dkato | 0:f782d9c66c49 | 67 | struct pbuf *pbuf = (struct pbuf*)mem; |
dkato | 0:f782d9c66c49 | 68 | |
dkato | 0:f782d9c66c49 | 69 | pbuf->len = len; |
dkato | 0:f782d9c66c49 | 70 | } |
dkato | 0:f782d9c66c49 | 71 | |
dkato | 0:f782d9c66c49 | 72 | emac_stack_mem_t *emac_stack_mem_chain_dequeue(emac_stack_t* stack, emac_stack_mem_chain_t **chain) |
dkato | 0:f782d9c66c49 | 73 | { |
dkato | 0:f782d9c66c49 | 74 | struct pbuf **list = (struct pbuf**)chain; |
dkato | 0:f782d9c66c49 | 75 | struct pbuf *head = *list; |
dkato | 0:f782d9c66c49 | 76 | *list = (*list)->next; |
dkato | 0:f782d9c66c49 | 77 | |
dkato | 0:f782d9c66c49 | 78 | return (emac_stack_mem_t *)head; |
dkato | 0:f782d9c66c49 | 79 | } |
dkato | 0:f782d9c66c49 | 80 | |
dkato | 0:f782d9c66c49 | 81 | uint32_t emac_stack_mem_chain_len(emac_stack_t* stack, emac_stack_mem_chain_t *chain) |
dkato | 0:f782d9c66c49 | 82 | { |
dkato | 0:f782d9c66c49 | 83 | return ((struct pbuf*)chain)->tot_len; |
dkato | 0:f782d9c66c49 | 84 | } |
dkato | 0:f782d9c66c49 | 85 | |
dkato | 0:f782d9c66c49 | 86 | void emac_stack_mem_ref(emac_stack_t* stack, emac_stack_mem_t *mem) |
dkato | 0:f782d9c66c49 | 87 | { |
dkato | 0:f782d9c66c49 | 88 | pbuf_ref((struct pbuf*)mem); |
dkato | 0:f782d9c66c49 | 89 | } |
dkato | 0:f782d9c66c49 | 90 | |
dkato | 0:f782d9c66c49 | 91 | #endif /* DEVICE_EMAC */ |