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