Backup 1

Committer:
borlanic
Date:
Tue Apr 24 11:45:18 2018 +0000
Revision:
0:02dd72d1d465
BaBoRo_test2 - backup 1

Who changed what in which revision?

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