this hurts
Dependencies: FFT
mbed/hal/emac_api.h@0:d6c9b09b4042, 2020-12-02 (annotated)
- Committer:
- annieluo2
- Date:
- Wed Dec 02 18:02:03 2020 +0000
- Revision:
- 0:d6c9b09b4042
boo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
annieluo2 | 0:d6c9b09b4042 | 1 | /* mbed Microcontroller Library |
annieluo2 | 0:d6c9b09b4042 | 2 | * Copyright (c) 2016 ARM Limited |
annieluo2 | 0:d6c9b09b4042 | 3 | * |
annieluo2 | 0:d6c9b09b4042 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
annieluo2 | 0:d6c9b09b4042 | 5 | * you may not use this file except in compliance with the License. |
annieluo2 | 0:d6c9b09b4042 | 6 | * You may obtain a copy of the License at |
annieluo2 | 0:d6c9b09b4042 | 7 | * |
annieluo2 | 0:d6c9b09b4042 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
annieluo2 | 0:d6c9b09b4042 | 9 | * |
annieluo2 | 0:d6c9b09b4042 | 10 | * Unless required by applicable law or agreed to in writing, software |
annieluo2 | 0:d6c9b09b4042 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
annieluo2 | 0:d6c9b09b4042 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
annieluo2 | 0:d6c9b09b4042 | 13 | * See the License for the specific language governing permissions and |
annieluo2 | 0:d6c9b09b4042 | 14 | * limitations under the License. |
annieluo2 | 0:d6c9b09b4042 | 15 | */ |
annieluo2 | 0:d6c9b09b4042 | 16 | |
annieluo2 | 0:d6c9b09b4042 | 17 | #ifndef MBED_EMAC_API_H |
annieluo2 | 0:d6c9b09b4042 | 18 | #define MBED_EMAC_API_H |
annieluo2 | 0:d6c9b09b4042 | 19 | |
annieluo2 | 0:d6c9b09b4042 | 20 | #if DEVICE_EMAC |
annieluo2 | 0:d6c9b09b4042 | 21 | |
annieluo2 | 0:d6c9b09b4042 | 22 | #include <stdbool.h> |
annieluo2 | 0:d6c9b09b4042 | 23 | #include "emac_stack_mem.h" |
annieluo2 | 0:d6c9b09b4042 | 24 | |
annieluo2 | 0:d6c9b09b4042 | 25 | typedef struct emac_interface emac_interface_t; |
annieluo2 | 0:d6c9b09b4042 | 26 | |
annieluo2 | 0:d6c9b09b4042 | 27 | /** |
annieluo2 | 0:d6c9b09b4042 | 28 | * EmacInterface |
annieluo2 | 0:d6c9b09b4042 | 29 | * |
annieluo2 | 0:d6c9b09b4042 | 30 | * This interface should be used to abstract low level access to networking hardware |
annieluo2 | 0:d6c9b09b4042 | 31 | */ |
annieluo2 | 0:d6c9b09b4042 | 32 | |
annieluo2 | 0:d6c9b09b4042 | 33 | /** |
annieluo2 | 0:d6c9b09b4042 | 34 | * Callback to be register with Emac interface and to be called fore received packets |
annieluo2 | 0:d6c9b09b4042 | 35 | * |
annieluo2 | 0:d6c9b09b4042 | 36 | * @param data Arbitrary user data (IP stack) |
annieluo2 | 0:d6c9b09b4042 | 37 | * @param buf Received data |
annieluo2 | 0:d6c9b09b4042 | 38 | */ |
annieluo2 | 0:d6c9b09b4042 | 39 | typedef void (*emac_link_input_fn)(void *data, emac_stack_mem_chain_t *buf); |
annieluo2 | 0:d6c9b09b4042 | 40 | |
annieluo2 | 0:d6c9b09b4042 | 41 | /** |
annieluo2 | 0:d6c9b09b4042 | 42 | * Callback to be register with Emac interface and to be called for link status changes |
annieluo2 | 0:d6c9b09b4042 | 43 | * |
annieluo2 | 0:d6c9b09b4042 | 44 | * @param data Arbitrary user data (IP stack) |
annieluo2 | 0:d6c9b09b4042 | 45 | * @param up Link status |
annieluo2 | 0:d6c9b09b4042 | 46 | */ |
annieluo2 | 0:d6c9b09b4042 | 47 | typedef void (*emac_link_state_change_fn)(void *data, bool up); |
annieluo2 | 0:d6c9b09b4042 | 48 | |
annieluo2 | 0:d6c9b09b4042 | 49 | /** |
annieluo2 | 0:d6c9b09b4042 | 50 | * Return maximum transmission unit |
annieluo2 | 0:d6c9b09b4042 | 51 | * |
annieluo2 | 0:d6c9b09b4042 | 52 | * @param emac Emac interface |
annieluo2 | 0:d6c9b09b4042 | 53 | * @return MTU in bytes |
annieluo2 | 0:d6c9b09b4042 | 54 | */ |
annieluo2 | 0:d6c9b09b4042 | 55 | typedef uint32_t (*emac_get_mtu_size_fn)(emac_interface_t *emac); |
annieluo2 | 0:d6c9b09b4042 | 56 | |
annieluo2 | 0:d6c9b09b4042 | 57 | /** |
annieluo2 | 0:d6c9b09b4042 | 58 | * Return interface name |
annieluo2 | 0:d6c9b09b4042 | 59 | * |
annieluo2 | 0:d6c9b09b4042 | 60 | * @param emac Emac interface |
annieluo2 | 0:d6c9b09b4042 | 61 | * @param name Pointer to where the name should be written |
annieluo2 | 0:d6c9b09b4042 | 62 | * @param size Maximum number of character to copy |
annieluo2 | 0:d6c9b09b4042 | 63 | */ |
annieluo2 | 0:d6c9b09b4042 | 64 | typedef void (*emac_get_ifname_fn)(emac_interface_t *emac, char *name, uint8_t size); |
annieluo2 | 0:d6c9b09b4042 | 65 | |
annieluo2 | 0:d6c9b09b4042 | 66 | /** |
annieluo2 | 0:d6c9b09b4042 | 67 | * Returns size of the underlying interface HW address size |
annieluo2 | 0:d6c9b09b4042 | 68 | * |
annieluo2 | 0:d6c9b09b4042 | 69 | * @param emac Emac interface |
annieluo2 | 0:d6c9b09b4042 | 70 | * @return HW address size in bytes |
annieluo2 | 0:d6c9b09b4042 | 71 | */ |
annieluo2 | 0:d6c9b09b4042 | 72 | typedef uint8_t (*emac_get_hwaddr_size_fn)(emac_interface_t *emac); |
annieluo2 | 0:d6c9b09b4042 | 73 | |
annieluo2 | 0:d6c9b09b4042 | 74 | /** |
annieluo2 | 0:d6c9b09b4042 | 75 | * Return interface hw address |
annieluo2 | 0:d6c9b09b4042 | 76 | * |
annieluo2 | 0:d6c9b09b4042 | 77 | * Copies HW address to provided memory, @param addr has to be of correct size see @a get_hwaddr_size |
annieluo2 | 0:d6c9b09b4042 | 78 | * |
annieluo2 | 0:d6c9b09b4042 | 79 | * @param emac Emac interface |
annieluo2 | 0:d6c9b09b4042 | 80 | * @param addr HW address for underlying interface |
annieluo2 | 0:d6c9b09b4042 | 81 | */ |
annieluo2 | 0:d6c9b09b4042 | 82 | typedef void (*emac_get_hwaddr_fn)(emac_interface_t *emac, uint8_t *addr); |
annieluo2 | 0:d6c9b09b4042 | 83 | |
annieluo2 | 0:d6c9b09b4042 | 84 | /** |
annieluo2 | 0:d6c9b09b4042 | 85 | * Set HW address for interface |
annieluo2 | 0:d6c9b09b4042 | 86 | * |
annieluo2 | 0:d6c9b09b4042 | 87 | * Provided address has to be of correct size, see @a get_hwaddr_size |
annieluo2 | 0:d6c9b09b4042 | 88 | * |
annieluo2 | 0:d6c9b09b4042 | 89 | * @param emac Emac interface |
annieluo2 | 0:d6c9b09b4042 | 90 | * @param addr Address to be set |
annieluo2 | 0:d6c9b09b4042 | 91 | */ |
annieluo2 | 0:d6c9b09b4042 | 92 | typedef void (*emac_set_hwaddr_fn)(emac_interface_t *emac, uint8_t *addr); |
annieluo2 | 0:d6c9b09b4042 | 93 | |
annieluo2 | 0:d6c9b09b4042 | 94 | /** |
annieluo2 | 0:d6c9b09b4042 | 95 | * Sends the packet over the link |
annieluo2 | 0:d6c9b09b4042 | 96 | * |
annieluo2 | 0:d6c9b09b4042 | 97 | * That can not be called from an interrupt context. |
annieluo2 | 0:d6c9b09b4042 | 98 | * |
annieluo2 | 0:d6c9b09b4042 | 99 | * @param emac Emac interface |
annieluo2 | 0:d6c9b09b4042 | 100 | * @param buf Packet to be send |
annieluo2 | 0:d6c9b09b4042 | 101 | * @return True if the packet was send successfully, False otherwise |
annieluo2 | 0:d6c9b09b4042 | 102 | */ |
annieluo2 | 0:d6c9b09b4042 | 103 | typedef bool (*emac_link_out_fn)(emac_interface_t *emac, emac_stack_mem_t *buf); |
annieluo2 | 0:d6c9b09b4042 | 104 | |
annieluo2 | 0:d6c9b09b4042 | 105 | /** |
annieluo2 | 0:d6c9b09b4042 | 106 | * Initializes the HW |
annieluo2 | 0:d6c9b09b4042 | 107 | * |
annieluo2 | 0:d6c9b09b4042 | 108 | * @return True on success, False in case of an error. |
annieluo2 | 0:d6c9b09b4042 | 109 | */ |
annieluo2 | 0:d6c9b09b4042 | 110 | typedef bool (*emac_power_up_fn)(emac_interface_t *emac); |
annieluo2 | 0:d6c9b09b4042 | 111 | |
annieluo2 | 0:d6c9b09b4042 | 112 | /** |
annieluo2 | 0:d6c9b09b4042 | 113 | * Deinitializes the HW |
annieluo2 | 0:d6c9b09b4042 | 114 | * |
annieluo2 | 0:d6c9b09b4042 | 115 | * @param emac Emac interface |
annieluo2 | 0:d6c9b09b4042 | 116 | */ |
annieluo2 | 0:d6c9b09b4042 | 117 | typedef void (*emac_power_down_fn)(emac_interface_t *emac); |
annieluo2 | 0:d6c9b09b4042 | 118 | |
annieluo2 | 0:d6c9b09b4042 | 119 | /** |
annieluo2 | 0:d6c9b09b4042 | 120 | * Sets a callback that needs to be called for packets received for that interface |
annieluo2 | 0:d6c9b09b4042 | 121 | * |
annieluo2 | 0:d6c9b09b4042 | 122 | * @param emac Emac interface |
annieluo2 | 0:d6c9b09b4042 | 123 | * @param input_cb Function to be register as a callback |
annieluo2 | 0:d6c9b09b4042 | 124 | * @param data Arbitrary user data to be passed to the callback |
annieluo2 | 0:d6c9b09b4042 | 125 | */ |
annieluo2 | 0:d6c9b09b4042 | 126 | typedef void (*emac_set_link_input_cb_fn)(emac_interface_t *emac, emac_link_input_fn input_cb, void *data); |
annieluo2 | 0:d6c9b09b4042 | 127 | |
annieluo2 | 0:d6c9b09b4042 | 128 | /** |
annieluo2 | 0:d6c9b09b4042 | 129 | * Sets a callback that needs to be called on link status changes for given interface |
annieluo2 | 0:d6c9b09b4042 | 130 | * |
annieluo2 | 0:d6c9b09b4042 | 131 | * @param emac Emac interface |
annieluo2 | 0:d6c9b09b4042 | 132 | * @param state_cb Function to be register as a callback |
annieluo2 | 0:d6c9b09b4042 | 133 | * @param data Arbitrary user data to be passed to the callback |
annieluo2 | 0:d6c9b09b4042 | 134 | */ |
annieluo2 | 0:d6c9b09b4042 | 135 | typedef void (*emac_set_link_state_cb_fn)(emac_interface_t *emac, emac_link_state_change_fn state_cb, void *data); |
annieluo2 | 0:d6c9b09b4042 | 136 | |
annieluo2 | 0:d6c9b09b4042 | 137 | typedef struct emac_interface_ops { |
annieluo2 | 0:d6c9b09b4042 | 138 | emac_get_mtu_size_fn get_mtu_size; |
annieluo2 | 0:d6c9b09b4042 | 139 | emac_get_ifname_fn get_ifname; |
annieluo2 | 0:d6c9b09b4042 | 140 | emac_get_hwaddr_size_fn get_hwaddr_size; |
annieluo2 | 0:d6c9b09b4042 | 141 | emac_get_hwaddr_fn get_hwaddr; |
annieluo2 | 0:d6c9b09b4042 | 142 | emac_set_hwaddr_fn set_hwaddr; |
annieluo2 | 0:d6c9b09b4042 | 143 | emac_link_out_fn link_out; |
annieluo2 | 0:d6c9b09b4042 | 144 | emac_power_up_fn power_up; |
annieluo2 | 0:d6c9b09b4042 | 145 | emac_power_down_fn power_down; |
annieluo2 | 0:d6c9b09b4042 | 146 | emac_set_link_input_cb_fn set_link_input_cb; |
annieluo2 | 0:d6c9b09b4042 | 147 | emac_set_link_state_cb_fn set_link_state_cb; |
annieluo2 | 0:d6c9b09b4042 | 148 | } emac_interface_ops_t; |
annieluo2 | 0:d6c9b09b4042 | 149 | |
annieluo2 | 0:d6c9b09b4042 | 150 | typedef struct emac_interface { |
annieluo2 | 0:d6c9b09b4042 | 151 | const emac_interface_ops_t ops; |
annieluo2 | 0:d6c9b09b4042 | 152 | void *hw; |
annieluo2 | 0:d6c9b09b4042 | 153 | } emac_interface_t; |
annieluo2 | 0:d6c9b09b4042 | 154 | |
annieluo2 | 0:d6c9b09b4042 | 155 | #else |
annieluo2 | 0:d6c9b09b4042 | 156 | |
annieluo2 | 0:d6c9b09b4042 | 157 | typedef void *emac_interface_t; |
annieluo2 | 0:d6c9b09b4042 | 158 | |
annieluo2 | 0:d6c9b09b4042 | 159 | #endif /* DEVICE_EMAC */ |
annieluo2 | 0:d6c9b09b4042 | 160 | #endif /* MBED_EMAC_API_H */ |