lol

Dependencies:   MMA8451Q

Fork of Application by Mateusz Kowalik

Committer:
danix
Date:
Sun Jan 21 22:28:30 2018 +0000
Revision:
12:3a30cdffa27c
Parent:
10:41552d038a69
Working acelerometer and mouse

Who changed what in which revision?

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