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