Committer:
borlanic
Date:
Fri Mar 30 14:07:05 2018 +0000
Revision:
4:75df35ef4fb6
Parent:
0:380207fcb5c1
commentar

Who changed what in which revision?

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