Rtos API example

Committer:
marcozecchini
Date:
Sat Feb 23 12:13:36 2019 +0000
Revision:
0:9fca2b23d0ba
final commit

Who changed what in which revision?

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