ChibiOS/HAL  6.1.0
hal_mac_lld.c
Go to the documentation of this file.
1 /*
2  ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 
17 /**
18  * @file hal_mac_lld.c
19  * @brief PLATFORM MAC subsystem low level driver source.
20  *
21  * @addtogroup MAC
22  * @{
23  */
24 
25 #include <string.h>
26 
27 #include "hal.h"
28 
29 #if (HAL_USE_MAC == TRUE) || defined(__DOXYGEN__)
30 
31 #include "hal_mii.h"
32 
33 /*===========================================================================*/
34 /* Driver local definitions. */
35 /*===========================================================================*/
36 
37 /*===========================================================================*/
38 /* Driver exported variables. */
39 /*===========================================================================*/
40 
41 /**
42  * @brief MAC1 driver identifier.
43  */
44 #if (PLATFORM_MAC_USE_MAC1 == TRUE) || defined(__DOXYGEN__)
46 #endif
47 
48 /*===========================================================================*/
49 /* Driver local variables and types. */
50 /*===========================================================================*/
51 
52 /*===========================================================================*/
53 /* Driver local functions. */
54 /*===========================================================================*/
55 
56 /*===========================================================================*/
57 /* Driver interrupt handlers. */
58 /*===========================================================================*/
59 
60 /*===========================================================================*/
61 /* Driver exported functions. */
62 /*===========================================================================*/
63 
64 /**
65  * @brief Low level MAC initialization.
66  *
67  * @notapi
68  */
69 void mac_lld_init(void) {
70 
71 #if PLATFORM_MAC_USE_MAC1 == TRUE
72  /* Driver initialization.*/
73  macObjectInit(&MACD1);
74 #endif
75 }
76 
77 /**
78  * @brief Configures and activates the MAC peripheral.
79  *
80  * @param[in] macp pointer to the @p MACDriver object
81  *
82  * @notapi
83  */
84 void mac_lld_start(MACDriver *macp) {
85 
86  if (macp->state == MAC_STOP) {
87  /* Enables the peripheral.*/
88 #if PLATFORM_MAC_USE_MAC1 == TRUE
89  if (&MACD1 == macp) {
90 
91  }
92 #endif
93  }
94  /* Configures the peripheral.*/
95 
96 }
97 
98 /**
99  * @brief Deactivates the MAC peripheral.
100  *
101  * @param[in] macp pointer to the @p MACDriver object
102  *
103  * @notapi
104  */
105 void mac_lld_stop(MACDriver *macp) {
106 
107  if (macp->state != MAC_STOP) {
108  /* Resets the peripheral.*/
109 
110  /* Disables the peripheral.*/
111 #if PLATFORM_MAC_USE_MAC1 == TRUE
112  if (&MACD1 == macp) {
113 
114  }
115 #endif
116  }
117 }
118 
119 /**
120  * @brief Returns a transmission descriptor.
121  * @details One of the available transmission descriptors is locked and
122  * returned.
123  *
124  * @param[in] macp pointer to the @p MACDriver object
125  * @param[out] tdp pointer to a @p MACTransmitDescriptor structure
126  * @return The operation status.
127  * @retval MSG_OK the descriptor has been obtained.
128  * @retval MSG_TIMEOUT descriptor not available.
129  *
130  * @notapi
131  */
133  MACTransmitDescriptor *tdp) {
134 
135  (void)macp;
136  (void)tdp;
137 
138  return MSG_OK;
139 }
140 
141 /**
142  * @brief Releases a transmit descriptor and starts the transmission of the
143  * enqueued data as a single frame.
144  *
145  * @param[in] tdp the pointer to the @p MACTransmitDescriptor structure
146  *
147  * @notapi
148  */
150 
151  (void)tdp;
152 
153 }
154 
155 /**
156  * @brief Returns a receive descriptor.
157  *
158  * @param[in] macp pointer to the @p MACDriver object
159  * @param[out] rdp pointer to a @p MACReceiveDescriptor structure
160  * @return The operation status.
161  * @retval MSG_OK the descriptor has been obtained.
162  * @retval MSG_TIMEOUT descriptor not available.
163  *
164  * @notapi
165  */
167  MACReceiveDescriptor *rdp) {
168 
169  (void)macp;
170  (void)rdp;
171 
172  return MSG_OK;
173 }
174 
175 /**
176  * @brief Releases a receive descriptor.
177  * @details The descriptor and its buffer are made available for more incoming
178  * frames.
179  *
180  * @param[in] rdp the pointer to the @p MACReceiveDescriptor structure
181  *
182  * @notapi
183  */
185 
186  (void)rdp;
187 
188 }
189 
190 /**
191  * @brief Updates and returns the link status.
192  *
193  * @param[in] macp pointer to the @p MACDriver object
194  * @return The link status.
195  * @retval true if the link is active.
196  * @retval false if the link is down.
197  *
198  * @notapi
199  */
201 
202  (void)macp;
203 
204  return false;
205 }
206 
207 /**
208  * @brief Writes to a transmit descriptor's stream.
209  *
210  * @param[in] tdp pointer to a @p MACTransmitDescriptor structure
211  * @param[in] buf pointer to the buffer containing the data to be
212  * written
213  * @param[in] size number of bytes to be written
214  * @return The number of bytes written into the descriptor's
215  * stream, this value can be less than the amount
216  * specified in the parameter @p size if the maximum
217  * frame size is reached.
218  *
219  * @notapi
220  */
222  uint8_t *buf,
223  size_t size) {
224 
225  (void)tdp;
226  (void)buf;
227 
228  return size;
229 }
230 
231 /**
232  * @brief Reads from a receive descriptor's stream.
233  *
234  * @param[in] rdp pointer to a @p MACReceiveDescriptor structure
235  * @param[in] buf pointer to the buffer that will receive the read data
236  * @param[in] size number of bytes to be read
237  * @return The number of bytes read from the descriptor's
238  * stream, this value can be less than the amount
239  * specified in the parameter @p size if there are
240  * no more bytes to read.
241  *
242  * @notapi
243  */
245  uint8_t *buf,
246  size_t size) {
247 
248  (void)rdp;
249  (void)buf;
250 
251  return size;
252 }
253 
254 #if (MAC_USE_ZERO_COPY == TRUE) || defined(__DOXYGEN__)
255 /**
256  * @brief Returns a pointer to the next transmit buffer in the descriptor
257  * chain.
258  * @note The API guarantees that enough buffers can be requested to fill
259  * a whole frame.
260  *
261  * @param[in] tdp pointer to a @p MACTransmitDescriptor structure
262  * @param[in] size size of the requested buffer. Specify the frame size
263  * on the first call then scale the value down subtracting
264  * the amount of data already copied into the previous
265  * buffers.
266  * @param[out] sizep pointer to variable receiving the buffer size, it is
267  * zero when the last buffer has already been returned.
268  * Note that a returned size lower than the amount
269  * requested means that more buffers must be requested
270  * in order to fill the frame data entirely.
271  * @return Pointer to the returned buffer.
272  * @retval NULL if the buffer chain has been entirely scanned.
273  *
274  * @notapi
275  */
277  size_t size,
278  size_t *sizep) {
279 
280  (void)tdp;
281  (void)size;
282  (void)sizep;
283 
284  return NULL;
285 }
286 
287 /**
288  * @brief Returns a pointer to the next receive buffer in the descriptor
289  * chain.
290  * @note The API guarantees that the descriptor chain contains a whole
291  * frame.
292  *
293  * @param[in] rdp pointer to a @p MACReceiveDescriptor structure
294  * @param[out] sizep pointer to variable receiving the buffer size, it is
295  * zero when the last buffer has already been returned.
296  * @return Pointer to the returned buffer.
297  * @retval NULL if the buffer chain has been entirely scanned.
298  *
299  * @notapi
300  */
302  size_t *sizep) {
303 
304  (void)rdp;
305  (void)sizep;
306 
307  return NULL;
308 }
309 #endif /* MAC_USE_ZERO_COPY == TRUE */
310 
311 #endif /* HAL_USE_MAC == TRUE */
312 
313 /** @} */
uint8_t * mac_lld_get_next_transmit_buffer(MACTransmitDescriptor *tdp, size_t size, size_t *sizep)
Returns a pointer to the next transmit buffer in the descriptor chain.
Definition: hal_mac_lld.c:276
size_t mac_lld_write_transmit_descriptor(MACTransmitDescriptor *tdp, uint8_t *buf, size_t size)
Writes to a transmit descriptor&#39;s stream.
Definition: hal_mac_lld.c:221
void mac_lld_init(void)
Low level MAC initialization.
Definition: hal_mac_lld.c:69
HAL subsystem header.
size_t mac_lld_read_receive_descriptor(MACReceiveDescriptor *rdp, uint8_t *buf, size_t size)
Reads from a receive descriptor&#39;s stream.
Definition: hal_mac_lld.c:244
void mac_lld_release_receive_descriptor(MACReceiveDescriptor *rdp)
Releases a receive descriptor.
Definition: hal_mac_lld.c:184
int32_t msg_t
Type of a message.
Definition: osal.h:160
macstate_t state
Driver state.
Definition: hal_mac_lld.h:83
const uint8_t * mac_lld_get_next_receive_buffer(MACReceiveDescriptor *rdp, size_t *sizep)
Returns a pointer to the next receive buffer in the descriptor chain.
Definition: hal_mac_lld.c:301
bool mac_lld_poll_link_status(MACDriver *macp)
Updates and returns the link status.
Definition: hal_mac_lld.c:200
Structure representing a MAC driver.
Definition: hal_mac_lld.h:79
MII macros and structures.
void macObjectInit(MACDriver *macp)
Initialize the standard part of a MACDriver structure.
Definition: hal_mac.c:76
msg_t mac_lld_get_receive_descriptor(MACDriver *macp, MACReceiveDescriptor *rdp)
Returns a receive descriptor.
Definition: hal_mac_lld.c:166
Structure representing a transmit descriptor.
Definition: hal_mac_lld.h:108
msg_t mac_lld_get_transmit_descriptor(MACDriver *macp, MACTransmitDescriptor *tdp)
Returns a transmission descriptor.
Definition: hal_mac_lld.c:132
void mac_lld_release_transmit_descriptor(MACTransmitDescriptor *tdp)
Releases a transmit descriptor and starts the transmission of the enqueued data as a single frame...
Definition: hal_mac_lld.c:149
void mac_lld_start(MACDriver *macp)
Configures and activates the MAC peripheral.
Definition: hal_mac_lld.c:84
void mac_lld_stop(MACDriver *macp)
Deactivates the MAC peripheral.
Definition: hal_mac_lld.c:105
Structure representing a receive descriptor.
Definition: hal_mac_lld.h:123
MACDriver ETHD1
MAC1 driver identifier.
Definition: hal_mac_lld.c:45