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