Describes predefine macros for mbed online compiler (armcc)

Committer:
MACRUM
Date:
Thu Mar 16 21:58:09 2017 +0900
Revision:
6:40e873bbc5f7
Add licence header info

Who changed what in which revision?

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