Marco Zecchini
/
Example_RTOS
Rtos API example
mbed-os/features/netsocket/emac_stack_mem.h@0:9fca2b23d0ba, 2019-02-23 (annotated)
- Committer:
- marcozecchini
- Date:
- Sat Feb 23 12:13:36 2019 +0000
- Revision:
- 0:9fca2b23d0ba
final commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
marcozecchini | 0:9fca2b23d0ba | 1 | /* mbed Microcontroller Library |
marcozecchini | 0:9fca2b23d0ba | 2 | * Copyright (c) 2016 ARM Limited |
marcozecchini | 0:9fca2b23d0ba | 3 | * |
marcozecchini | 0:9fca2b23d0ba | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
marcozecchini | 0:9fca2b23d0ba | 5 | * you may not use this file except in compliance with the License. |
marcozecchini | 0:9fca2b23d0ba | 6 | * You may obtain a copy of the License at |
marcozecchini | 0:9fca2b23d0ba | 7 | * |
marcozecchini | 0:9fca2b23d0ba | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
marcozecchini | 0:9fca2b23d0ba | 9 | * |
marcozecchini | 0:9fca2b23d0ba | 10 | * Unless required by applicable law or agreed to in writing, software |
marcozecchini | 0:9fca2b23d0ba | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
marcozecchini | 0:9fca2b23d0ba | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
marcozecchini | 0:9fca2b23d0ba | 13 | * See the License for the specific language governing permissions and |
marcozecchini | 0:9fca2b23d0ba | 14 | * limitations under the License. |
marcozecchini | 0:9fca2b23d0ba | 15 | */ |
marcozecchini | 0:9fca2b23d0ba | 16 | #ifndef MBED_EMAC_STACK_MEM_H |
marcozecchini | 0:9fca2b23d0ba | 17 | #define MBED_EMAC_STACK_MEM_H |
marcozecchini | 0:9fca2b23d0ba | 18 | |
marcozecchini | 0:9fca2b23d0ba | 19 | #if DEVICE_EMAC |
marcozecchini | 0:9fca2b23d0ba | 20 | |
marcozecchini | 0:9fca2b23d0ba | 21 | #include <stdint.h> |
marcozecchini | 0:9fca2b23d0ba | 22 | |
marcozecchini | 0:9fca2b23d0ba | 23 | /** |
marcozecchini | 0:9fca2b23d0ba | 24 | * Stack memory module |
marcozecchini | 0:9fca2b23d0ba | 25 | * |
marcozecchini | 0:9fca2b23d0ba | 26 | * This interface provides abstraction for memory modules used in different IP stacks (often to accommodate zero copy). |
marcozecchini | 0:9fca2b23d0ba | 27 | * Emac interface may be required to accept output packets and provide received data using this stack specific API. |
marcozecchini | 0:9fca2b23d0ba | 28 | * This header should be implemented for each IP stack, so that we keep emacs module independent. |
marcozecchini | 0:9fca2b23d0ba | 29 | */ |
marcozecchini | 0:9fca2b23d0ba | 30 | typedef void emac_stack_mem_t; |
marcozecchini | 0:9fca2b23d0ba | 31 | typedef void emac_stack_mem_chain_t; |
marcozecchini | 0:9fca2b23d0ba | 32 | typedef void emac_stack_t; |
marcozecchini | 0:9fca2b23d0ba | 33 | |
marcozecchini | 0:9fca2b23d0ba | 34 | /** |
marcozecchini | 0:9fca2b23d0ba | 35 | * Allocates stack memory |
marcozecchini | 0:9fca2b23d0ba | 36 | * |
marcozecchini | 0:9fca2b23d0ba | 37 | * @param stack Emac stack context |
marcozecchini | 0:9fca2b23d0ba | 38 | * @param size Size of memory to allocate |
marcozecchini | 0:9fca2b23d0ba | 39 | * @param align Memory alignment requirements |
marcozecchini | 0:9fca2b23d0ba | 40 | * @return Allocated memory struct, or NULL in case of error |
marcozecchini | 0:9fca2b23d0ba | 41 | */ |
marcozecchini | 0:9fca2b23d0ba | 42 | emac_stack_mem_t *emac_stack_mem_alloc(emac_stack_t* stack, uint32_t size, uint32_t align); |
marcozecchini | 0:9fca2b23d0ba | 43 | |
marcozecchini | 0:9fca2b23d0ba | 44 | /** |
marcozecchini | 0:9fca2b23d0ba | 45 | * Free memory allocated using @a stack_mem_alloc |
marcozecchini | 0:9fca2b23d0ba | 46 | * |
marcozecchini | 0:9fca2b23d0ba | 47 | * @param stack Emac stack context |
marcozecchini | 0:9fca2b23d0ba | 48 | * @param mem Memory to be freed |
marcozecchini | 0:9fca2b23d0ba | 49 | */ |
marcozecchini | 0:9fca2b23d0ba | 50 | void emac_stack_mem_free(emac_stack_t* stack, emac_stack_mem_t *mem); |
marcozecchini | 0:9fca2b23d0ba | 51 | |
marcozecchini | 0:9fca2b23d0ba | 52 | /** |
marcozecchini | 0:9fca2b23d0ba | 53 | * Copy memory |
marcozecchini | 0:9fca2b23d0ba | 54 | * |
marcozecchini | 0:9fca2b23d0ba | 55 | * @param stack Emac stack context |
marcozecchini | 0:9fca2b23d0ba | 56 | * @param to Memory to copy to |
marcozecchini | 0:9fca2b23d0ba | 57 | * @param from Memory to copy from |
marcozecchini | 0:9fca2b23d0ba | 58 | */ |
marcozecchini | 0:9fca2b23d0ba | 59 | void emac_stack_mem_copy(emac_stack_t* stack, emac_stack_mem_t *to, emac_stack_mem_t *from); |
marcozecchini | 0:9fca2b23d0ba | 60 | |
marcozecchini | 0:9fca2b23d0ba | 61 | /** |
marcozecchini | 0:9fca2b23d0ba | 62 | * Return pointer to the payload |
marcozecchini | 0:9fca2b23d0ba | 63 | * |
marcozecchini | 0:9fca2b23d0ba | 64 | * @param stack Emac stack context |
marcozecchini | 0:9fca2b23d0ba | 65 | * @param mem Memory structure |
marcozecchini | 0:9fca2b23d0ba | 66 | * @return Pointer to the payload |
marcozecchini | 0:9fca2b23d0ba | 67 | */ |
marcozecchini | 0:9fca2b23d0ba | 68 | void *emac_stack_mem_ptr(emac_stack_t* stack, emac_stack_mem_t *mem); |
marcozecchini | 0:9fca2b23d0ba | 69 | |
marcozecchini | 0:9fca2b23d0ba | 70 | /** |
marcozecchini | 0:9fca2b23d0ba | 71 | * Return actual payload size |
marcozecchini | 0:9fca2b23d0ba | 72 | * |
marcozecchini | 0:9fca2b23d0ba | 73 | * @param stack Emac stack context |
marcozecchini | 0:9fca2b23d0ba | 74 | * @param mem Memory structure |
marcozecchini | 0:9fca2b23d0ba | 75 | * @return Size in bytes |
marcozecchini | 0:9fca2b23d0ba | 76 | */ |
marcozecchini | 0:9fca2b23d0ba | 77 | uint32_t emac_stack_mem_len(emac_stack_t* stack, emac_stack_mem_t *mem); |
marcozecchini | 0:9fca2b23d0ba | 78 | |
marcozecchini | 0:9fca2b23d0ba | 79 | /** |
marcozecchini | 0:9fca2b23d0ba | 80 | * Sets the actual payload size (the allocated payload size will not change) |
marcozecchini | 0:9fca2b23d0ba | 81 | * |
marcozecchini | 0:9fca2b23d0ba | 82 | * @param stack Emac stack context |
marcozecchini | 0:9fca2b23d0ba | 83 | * @param mem Memory structure |
marcozecchini | 0:9fca2b23d0ba | 84 | * @param len Actual payload size |
marcozecchini | 0:9fca2b23d0ba | 85 | */ |
marcozecchini | 0:9fca2b23d0ba | 86 | void emac_stack_mem_set_len(emac_stack_t* stack, emac_stack_mem_t *mem, uint32_t len); |
marcozecchini | 0:9fca2b23d0ba | 87 | |
marcozecchini | 0:9fca2b23d0ba | 88 | /** |
marcozecchini | 0:9fca2b23d0ba | 89 | * Returns first memory structure from the list and move the head to point to the next node |
marcozecchini | 0:9fca2b23d0ba | 90 | * |
marcozecchini | 0:9fca2b23d0ba | 91 | * @param stack Emac stack context |
marcozecchini | 0:9fca2b23d0ba | 92 | * @param chain Pointer to the list |
marcozecchini | 0:9fca2b23d0ba | 93 | * @return First memory structure from the list |
marcozecchini | 0:9fca2b23d0ba | 94 | */ |
marcozecchini | 0:9fca2b23d0ba | 95 | emac_stack_mem_t *emac_stack_mem_chain_dequeue(emac_stack_t* stack, emac_stack_mem_chain_t **chain); |
marcozecchini | 0:9fca2b23d0ba | 96 | |
marcozecchini | 0:9fca2b23d0ba | 97 | /** |
marcozecchini | 0:9fca2b23d0ba | 98 | * Return total length of the memory chain |
marcozecchini | 0:9fca2b23d0ba | 99 | * |
marcozecchini | 0:9fca2b23d0ba | 100 | * @param stack Emac stack context |
marcozecchini | 0:9fca2b23d0ba | 101 | * @param chain Memory chain |
marcozecchini | 0:9fca2b23d0ba | 102 | * @return Chain length |
marcozecchini | 0:9fca2b23d0ba | 103 | */ |
marcozecchini | 0:9fca2b23d0ba | 104 | uint32_t emac_stack_mem_chain_len(emac_stack_t* stack, emac_stack_mem_chain_t *chain); |
marcozecchini | 0:9fca2b23d0ba | 105 | |
marcozecchini | 0:9fca2b23d0ba | 106 | /** |
marcozecchini | 0:9fca2b23d0ba | 107 | * Increases the reference counter for the memory |
marcozecchini | 0:9fca2b23d0ba | 108 | * |
marcozecchini | 0:9fca2b23d0ba | 109 | * @param stack Emac stack context |
marcozecchini | 0:9fca2b23d0ba | 110 | * @param mem Memory structure |
marcozecchini | 0:9fca2b23d0ba | 111 | */ |
marcozecchini | 0:9fca2b23d0ba | 112 | void emac_stack_mem_ref(emac_stack_t* stack, emac_stack_mem_t *mem); |
marcozecchini | 0:9fca2b23d0ba | 113 | |
marcozecchini | 0:9fca2b23d0ba | 114 | #endif /* DEVICE_EMAC */ |
marcozecchini | 0:9fca2b23d0ba | 115 | |
marcozecchini | 0:9fca2b23d0ba | 116 | #endif /* EMAC_MBED_STACK_MEM_h */ |