inport from local

Dependents:   Hobbyking_Cheetah_0511

Committer:
NYX
Date:
Mon Mar 16 06:35:48 2020 +0000
Revision:
0:85b3fd62ea1a
reinport to mbed;

Who changed what in which revision?

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