ChibiOS/HAL
6.1.0
|
Generic MAC Driver. More...
Generic MAC Driver.
This module implements a generic MAC (Media Access Control) driver for Ethernet controllers.
HAL_USE_MAC
option must be enabled in halconf.h
. Macros | |
#define | MAC_SUPPORTS_ZERO_COPY TRUE |
This implementation supports the zero-copy mode API. More... | |
MAC configuration options | |
#define | MAC_USE_ZERO_COPY FALSE |
Enables an event sources for incoming packets. More... | |
#define | MAC_USE_EVENTS TRUE |
Enables an event sources for incoming packets. More... | |
Macro Functions | |
#define | macGetReceiveEventSource(macp) (&(macp)->rdevent) |
Enables the zero-copy API. More... | |
#define | macWriteTransmitDescriptor(tdp, buf, size) mac_lld_write_transmit_descriptor(tdp, buf, size) |
Writes to a transmit descriptor's stream. More... | |
#define | macReadReceiveDescriptor(rdp, buf, size) mac_lld_read_receive_descriptor(rdp, buf, size) |
Reads from a receive descriptor's stream. More... | |
#define | macGetNextTransmitBuffer(tdp, size, sizep) mac_lld_get_next_transmit_buffer(tdp, size, sizep) |
Returns a pointer to the next transmit buffer in the descriptor chain. More... | |
#define | macGetNextReceiveBuffer(rdp, sizep) mac_lld_get_next_receive_buffer(rdp, sizep) |
Returns a pointer to the next receive buffer in the descriptor chain. More... | |
PLATFORM configuration options | |
#define | PLATFORM_MAC_USE_MAC1 FALSE |
MAC driver enable switch. More... | |
Typedefs | |
typedef struct MACDriver | MACDriver |
Type of a structure representing a MAC driver. More... | |
Data Structures | |
struct | MACConfig |
Driver configuration structure. More... | |
struct | MACDriver |
Structure representing a MAC driver. More... | |
struct | MACTransmitDescriptor |
Structure representing a transmit descriptor. More... | |
struct | MACReceiveDescriptor |
Structure representing a receive descriptor. More... | |
Functions | |
void | macInit (void) |
MAC Driver initialization. More... | |
void | macObjectInit (MACDriver *macp) |
Initialize the standard part of a MACDriver structure. More... | |
void | macStart (MACDriver *macp, const MACConfig *config) |
Configures and activates the MAC peripheral. More... | |
void | macStop (MACDriver *macp) |
Deactivates the MAC peripheral. More... | |
msg_t | macWaitTransmitDescriptor (MACDriver *macp, MACTransmitDescriptor *tdp, sysinterval_t timeout) |
Allocates a transmission descriptor. More... | |
void | macReleaseTransmitDescriptor (MACTransmitDescriptor *tdp) |
Releases a transmit descriptor and starts the transmission of the enqueued data as a single frame. More... | |
msg_t | macWaitReceiveDescriptor (MACDriver *macp, MACReceiveDescriptor *rdp, sysinterval_t timeout) |
Waits for a received frame. More... | |
void | macReleaseReceiveDescriptor (MACReceiveDescriptor *rdp) |
Releases a receive descriptor. More... | |
bool | macPollLinkStatus (MACDriver *macp) |
Updates and returns the link status. More... | |
void | mac_lld_init (void) |
Low level MAC initialization. More... | |
void | mac_lld_start (MACDriver *macp) |
Configures and activates the MAC peripheral. More... | |
void | mac_lld_stop (MACDriver *macp) |
Deactivates the MAC peripheral. More... | |
msg_t | mac_lld_get_transmit_descriptor (MACDriver *macp, MACTransmitDescriptor *tdp) |
Returns a transmission descriptor. More... | |
void | mac_lld_release_transmit_descriptor (MACTransmitDescriptor *tdp) |
Releases a transmit descriptor and starts the transmission of the enqueued data as a single frame. More... | |
msg_t | mac_lld_get_receive_descriptor (MACDriver *macp, MACReceiveDescriptor *rdp) |
Returns a receive descriptor. More... | |
void | mac_lld_release_receive_descriptor (MACReceiveDescriptor *rdp) |
Releases a receive descriptor. More... | |
bool | mac_lld_poll_link_status (MACDriver *macp) |
Updates and returns the link status. More... | |
size_t | mac_lld_write_transmit_descriptor (MACTransmitDescriptor *tdp, uint8_t *buf, size_t size) |
Writes to a transmit descriptor's stream. More... | |
size_t | mac_lld_read_receive_descriptor (MACReceiveDescriptor *rdp, uint8_t *buf, size_t size) |
Reads from a receive descriptor's stream. More... | |
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. More... | |
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. More... | |
Enumerations |
Variables | |
MACDriver | ETHD1 |
MAC1 driver identifier. More... | |
#define MAC_USE_ZERO_COPY FALSE |
#define MAC_USE_EVENTS TRUE |
#define macGetReceiveEventSource | ( | macp | ) | (&(macp)->rdevent) |
#define macWriteTransmitDescriptor | ( | tdp, | |
buf, | |||
size | |||
) | mac_lld_write_transmit_descriptor(tdp, buf, size) |
Writes to a transmit descriptor's stream.
[in] | tdp | pointer to a MACTransmitDescriptor structure |
[in] | buf | pointer to the buffer containing the data to be written |
[in] | size | number of bytes to be written |
size
if the maximum frame size is reached.#define macReadReceiveDescriptor | ( | rdp, | |
buf, | |||
size | |||
) | mac_lld_read_receive_descriptor(rdp, buf, size) |
Reads from a receive descriptor's stream.
[in] | rdp | pointer to a MACReceiveDescriptor structure |
[in] | buf | pointer to the buffer that will receive the read data |
[in] | size | number of bytes to be read |
size
if there are no more bytes to read.#define macGetNextTransmitBuffer | ( | tdp, | |
size, | |||
sizep | |||
) | mac_lld_get_next_transmit_buffer(tdp, size, sizep) |
Returns a pointer to the next transmit buffer in the descriptor chain.
[in] | tdp | pointer to a MACTransmitDescriptor structure |
[in] | size | size of the requested buffer. Specify the frame size on the first call then scale the value down subtracting the amount of data already copied into the previous buffers. |
[out] | sizep | pointer to variable receiving the real buffer size. The returned value can be less than the amount requested, this means that more buffers must be requested in order to fill the frame data entirely. |
#define macGetNextReceiveBuffer | ( | rdp, | |
sizep | |||
) | mac_lld_get_next_receive_buffer(rdp, sizep) |
Returns a pointer to the next receive buffer in the descriptor chain.
[in] | rdp | pointer to a MACReceiveDescriptor structure |
[out] | sizep | pointer to variable receiving the buffer size, it is zero when the last buffer has already been returned. |
NULL | if the buffer chain has been entirely scanned. |
#define MAC_SUPPORTS_ZERO_COPY TRUE |
This implementation supports the zero-copy mode API.
Definition at line 37 of file hal_mac_lld.h.
#define PLATFORM_MAC_USE_MAC1 FALSE |
MAC driver enable switch.
If set to TRUE
the support for MAC1 is included.
FALSE
. Definition at line 53 of file hal_mac_lld.h.
enum macstate_t |
void macInit | ( | void | ) |
MAC Driver initialization.
halInit()
, there is no need to explicitly initialize the driver.Definition at line 64 of file hal_mac.c.
References mac_lld_init().
Referenced by halInit().
void macObjectInit | ( | MACDriver * | macp | ) |
Initialize the standard part of a MACDriver
structure.
[out] | macp | pointer to the MACDriver object |
Definition at line 76 of file hal_mac.c.
References MACDriver::config, MAC_STOP, osalEventObjectInit(), osalThreadQueueObjectInit(), MACDriver::rdevent, MACDriver::rdqueue, MACDriver::state, and MACDriver::tdqueue.
Referenced by mac_lld_init().
Configures and activates the MAC peripheral.
Definition at line 95 of file hal_mac.c.
References MACDriver::config, MAC_ACTIVE, mac_lld_start(), MAC_STOP, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), and MACDriver::state.
void macStop | ( | MACDriver * | macp | ) |
Deactivates the MAC peripheral.
[in] | macp | pointer to the MACDriver object |
Definition at line 115 of file hal_mac.c.
References MACDriver::config, MAC_ACTIVE, mac_lld_stop(), MAC_STOP, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), and MACDriver::state.
msg_t macWaitTransmitDescriptor | ( | MACDriver * | macp, |
MACTransmitDescriptor * | tdp, | ||
sysinterval_t | timeout | ||
) |
Allocates a transmission descriptor.
One of the available transmission descriptors is locked and returned. If a descriptor is not currently available then the invoking thread is queued until one is freed.
[in] | macp | pointer to the MACDriver object |
[out] | tdp | pointer to a MACTransmitDescriptor structure |
[in] | timeout | the number of ticks before the operation timeouts, the following special values are allowed:
|
MSG_OK | the descriptor was obtained. |
MSG_TIMEOUT | the operation timed out, descriptor not initialized. |
Definition at line 150 of file hal_mac.c.
References MAC_ACTIVE, mac_lld_get_transmit_descriptor(), osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), osalThreadEnqueueTimeoutS(), MACDriver::state, and MACDriver::tdqueue.
void macReleaseTransmitDescriptor | ( | MACTransmitDescriptor * | tdp | ) |
Releases a transmit descriptor and starts the transmission of the enqueued data as a single frame.
[in] | tdp | the pointer to the MACTransmitDescriptor structure |
Definition at line 179 of file hal_mac.c.
References mac_lld_release_transmit_descriptor(), and osalDbgCheck.
msg_t macWaitReceiveDescriptor | ( | MACDriver * | macp, |
MACReceiveDescriptor * | rdp, | ||
sysinterval_t | timeout | ||
) |
Waits for a received frame.
Stops until a frame is received and buffered. If a frame is not immediately available then the invoking thread is queued until one is received.
[in] | macp | pointer to the MACDriver object |
[out] | rdp | pointer to a MACReceiveDescriptor structure |
[in] | timeout | the number of ticks before the operation timeouts, the following special values are allowed:
|
MSG_OK | the descriptor was obtained. |
MSG_TIMEOUT | the operation timed out, descriptor not initialized. |
Definition at line 205 of file hal_mac.c.
References MAC_ACTIVE, mac_lld_get_receive_descriptor(), osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), osalThreadEnqueueTimeoutS(), MACDriver::rdqueue, and MACDriver::state.
void macReleaseReceiveDescriptor | ( | MACReceiveDescriptor * | rdp | ) |
Releases a receive descriptor.
The descriptor and its buffer are made available for more incoming frames.
[in] | rdp | the pointer to the MACReceiveDescriptor structure |
Definition at line 234 of file hal_mac.c.
References mac_lld_release_receive_descriptor(), and osalDbgCheck.
bool macPollLinkStatus | ( | MACDriver * | macp | ) |
Updates and returns the link status.
[in] | macp | pointer to the MACDriver object |
true | if the link is active. |
false | if the link is down. |
Definition at line 251 of file hal_mac.c.
References MAC_ACTIVE, mac_lld_poll_link_status(), osalDbgAssert, osalDbgCheck, and MACDriver::state.
void mac_lld_init | ( | void | ) |
Low level MAC initialization.
Definition at line 69 of file hal_mac_lld.c.
References macObjectInit().
Referenced by macInit().
void mac_lld_start | ( | MACDriver * | macp | ) |
Configures and activates the MAC peripheral.
[in] | macp | pointer to the MACDriver object |
Definition at line 84 of file hal_mac_lld.c.
References MAC_STOP, and MACDriver::state.
Referenced by macStart().
void mac_lld_stop | ( | MACDriver * | macp | ) |
Deactivates the MAC peripheral.
[in] | macp | pointer to the MACDriver object |
Definition at line 105 of file hal_mac_lld.c.
References MAC_STOP, and MACDriver::state.
Referenced by macStop().
msg_t mac_lld_get_transmit_descriptor | ( | MACDriver * | macp, |
MACTransmitDescriptor * | tdp | ||
) |
Returns a transmission descriptor.
One of the available transmission descriptors is locked and returned.
[in] | macp | pointer to the MACDriver object |
[out] | tdp | pointer to a MACTransmitDescriptor structure |
MSG_OK | the descriptor has been obtained. |
MSG_TIMEOUT | descriptor not available. |
Definition at line 132 of file hal_mac_lld.c.
Referenced by macWaitTransmitDescriptor().
void mac_lld_release_transmit_descriptor | ( | MACTransmitDescriptor * | tdp | ) |
Releases a transmit descriptor and starts the transmission of the enqueued data as a single frame.
[in] | tdp | the pointer to the MACTransmitDescriptor structure |
Definition at line 149 of file hal_mac_lld.c.
Referenced by macReleaseTransmitDescriptor().
msg_t mac_lld_get_receive_descriptor | ( | MACDriver * | macp, |
MACReceiveDescriptor * | rdp | ||
) |
Returns a receive descriptor.
[in] | macp | pointer to the MACDriver object |
[out] | rdp | pointer to a MACReceiveDescriptor structure |
MSG_OK | the descriptor has been obtained. |
MSG_TIMEOUT | descriptor not available. |
Definition at line 166 of file hal_mac_lld.c.
Referenced by macWaitReceiveDescriptor().
void mac_lld_release_receive_descriptor | ( | MACReceiveDescriptor * | rdp | ) |
Releases a receive descriptor.
The descriptor and its buffer are made available for more incoming frames.
[in] | rdp | the pointer to the MACReceiveDescriptor structure |
Definition at line 184 of file hal_mac_lld.c.
Referenced by macReleaseReceiveDescriptor().
bool mac_lld_poll_link_status | ( | MACDriver * | macp | ) |
Updates and returns the link status.
[in] | macp | pointer to the MACDriver object |
true | if the link is active. |
false | if the link is down. |
Definition at line 200 of file hal_mac_lld.c.
Referenced by macPollLinkStatus().
size_t mac_lld_write_transmit_descriptor | ( | MACTransmitDescriptor * | tdp, |
uint8_t * | buf, | ||
size_t | size | ||
) |
Writes to a transmit descriptor's stream.
[in] | tdp | pointer to a MACTransmitDescriptor structure |
[in] | buf | pointer to the buffer containing the data to be written |
[in] | size | number of bytes to be written |
size
if the maximum frame size is reached.Definition at line 221 of file hal_mac_lld.c.
size_t mac_lld_read_receive_descriptor | ( | MACReceiveDescriptor * | rdp, |
uint8_t * | buf, | ||
size_t | size | ||
) |
Reads from a receive descriptor's stream.
[in] | rdp | pointer to a MACReceiveDescriptor structure |
[in] | buf | pointer to the buffer that will receive the read data |
[in] | size | number of bytes to be read |
size
if there are no more bytes to read.Definition at line 244 of file hal_mac_lld.c.
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.
[in] | tdp | pointer to a MACTransmitDescriptor structure |
[in] | size | size of the requested buffer. Specify the frame size on the first call then scale the value down subtracting the amount of data already copied into the previous buffers. |
[out] | sizep | pointer to variable receiving the buffer size, it is zero when the last buffer has already been returned. Note that a returned size lower than the amount requested means that more buffers must be requested in order to fill the frame data entirely. |
NULL | if the buffer chain has been entirely scanned. |
Definition at line 276 of file hal_mac_lld.c.
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.
[in] | rdp | pointer to a MACReceiveDescriptor structure |
[out] | sizep | pointer to variable receiving the buffer size, it is zero when the last buffer has already been returned. |
NULL | if the buffer chain has been entirely scanned. |
Definition at line 301 of file hal_mac_lld.c.
MACDriver ETHD1 |
MAC1 driver identifier.
Definition at line 45 of file hal_mac_lld.c.