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