temp

Dependencies:   mbed SDFileSystem MS5607 ADXL345_I2C FATFileSystem

Committer:
IKobayashi
Date:
Mon Mar 16 23:37:42 2020 +0900
Revision:
0:c88c3b616c00
copy

Who changed what in which revision?

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