001

Committer:
ganlikun
Date:
Sun Jun 12 14:02:44 2022 +0000
Revision:
0:13413ea9a877
00

Who changed what in which revision?

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