ChibiOS/HAL  6.1.0
hal_mac_lld.h
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.h
19  * @brief PLATFORM MAC subsystem low level driver header.
20  *
21  * @addtogroup MAC
22  * @{
23  */
24 
25 #ifndef HAL_MAC_LLD_H
26 #define HAL_MAC_LLD_H
27 
28 #if (HAL_USE_MAC == TRUE) || defined(__DOXYGEN__)
29 
30 /*===========================================================================*/
31 /* Driver constants. */
32 /*===========================================================================*/
33 
34 /**
35  * @brief This implementation supports the zero-copy mode API.
36  */
37 #define MAC_SUPPORTS_ZERO_COPY TRUE
38 
39 /*===========================================================================*/
40 /* Driver pre-compile time settings. */
41 /*===========================================================================*/
42 
43 /**
44  * @name PLATFORM configuration options
45  * @{
46  */
47 /**
48  * @brief MAC driver enable switch.
49  * @details If set to @p TRUE the support for MAC1 is included.
50  * @note The default is @p FALSE.
51  */
52 #if !defined(PLATFORM_MAC_USE_MAC1) || defined(__DOXYGEN__)
53 #define PLATFORM_MAC_USE_MAC1 FALSE
54 #endif
55 /** @} */
56 
57 /*===========================================================================*/
58 /* Derived constants and error checks. */
59 /*===========================================================================*/
60 
61 /*===========================================================================*/
62 /* Driver data structures and types. */
63 /*===========================================================================*/
64 
65 /**
66  * @brief Driver configuration structure.
67  */
68 typedef struct {
69  /**
70  * @brief MAC address.
71  */
72  uint8_t *mac_address;
73  /* End of the mandatory fields.*/
74 } MACConfig;
75 
76 /**
77  * @brief Structure representing a MAC driver.
78  */
79 struct MACDriver {
80  /**
81  * @brief Driver state.
82  */
84  /**
85  * @brief Current configuration data.
86  */
87  const MACConfig *config;
88  /**
89  * @brief Transmit semaphore.
90  */
92  /**
93  * @brief Receive semaphore.
94  */
96 #if (MAC_USE_EVENTS == TRUE) || defined(__DOXYGEN__)
97  /**
98  * @brief Receive event.
99  */
101 #endif
102  /* End of the mandatory fields.*/
103 };
104 
105 /**
106  * @brief Structure representing a transmit descriptor.
107  */
108 typedef struct {
109  /**
110  * @brief Current write offset.
111  */
112  size_t offset;
113  /**
114  * @brief Available space size.
115  */
116  size_t size;
117  /* End of the mandatory fields.*/
119 
120 /**
121  * @brief Structure representing a receive descriptor.
122  */
123 typedef struct {
124  /**
125  * @brief Current read offset.
126  */
127  size_t offset;
128  /**
129  * @brief Available data size.
130  */
131  size_t size;
132  /* End of the mandatory fields.*/
134 
135 /*===========================================================================*/
136 /* Driver macros. */
137 /*===========================================================================*/
138 
139 /*===========================================================================*/
140 /* External declarations. */
141 /*===========================================================================*/
142 
143 #if (PLATFORM_MAC_USE_MAC1 == TRUE) && !defined(__DOXYGEN__)
144 extern MACDriver ETHD1;
145 #endif
146 
147 #ifdef __cplusplus
148 extern "C" {
149 #endif
150  void mac_lld_init(void);
151  void mac_lld_start(MACDriver *macp);
152  void mac_lld_stop(MACDriver *macp);
154  MACTransmitDescriptor *tdp);
157  MACReceiveDescriptor *rdp);
161  uint8_t *buf,
162  size_t size);
164  uint8_t *buf,
165  size_t size);
166 #if MAC_USE_ZERO_COPY == TRUE
168  size_t size,
169  size_t *sizep);
171  size_t *sizep);
172 #endif
173 #ifdef __cplusplus
174 }
175 #endif
176 
177 #endif /* HAL_USE_MAC == TRUE */
178 
179 #endif /* HAL_MAC_LLD_H */
180 
181 /** @} */
size_t size
Available space size.
Definition: hal_mac_lld.h:116
threads_queue_t tdqueue
Transmit semaphore.
Definition: hal_mac_lld.h:91
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
Events source object.
Definition: osal.h:212
size_t offset
Current write offset.
Definition: hal_mac_lld.h:112
size_t mac_lld_write_transmit_descriptor(MACTransmitDescriptor *tdp, uint8_t *buf, size_t size)
Writes to a transmit descriptor's stream.
Definition: hal_mac_lld.c:221
void mac_lld_init(void)
Low level MAC initialization.
Definition: hal_mac_lld.c:69
size_t offset
Current read offset.
Definition: hal_mac_lld.h:127
size_t size
Available data size.
Definition: hal_mac_lld.h:131
size_t mac_lld_read_receive_descriptor(MACReceiveDescriptor *rdp, uint8_t *buf, size_t size)
Reads from a receive descriptor's stream.
Definition: hal_mac_lld.c:244
event_source_t rdevent
Receive event.
Definition: hal_mac_lld.h:100
void mac_lld_release_receive_descriptor(MACReceiveDescriptor *rdp)
Releases a receive descriptor.
Definition: hal_mac_lld.c:184
macstate_t
Driver state machine possible states.
Definition: hal_mac.h:67
int32_t msg_t
Type of a message.
Definition: osal.h:160
Type of a thread queue.
Definition: osal.h:232
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
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
const MACConfig * config
Current configuration data.
Definition: hal_mac_lld.h:87
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
threads_queue_t rdqueue
Receive semaphore.
Definition: hal_mac_lld.h:95
uint8_t * mac_address
MAC address.
Definition: hal_mac_lld.h:72
Driver configuration structure.
Definition: hal_mac_lld.h:68
Structure representing a receive descriptor.
Definition: hal_mac_lld.h:123
MACDriver ETHD1
MAC1 driver identifier.
Definition: hal_mac_lld.c:45