ChibiOS/HAL 9.0.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
.MAC event flags | |
#define | MAC_FLAGS_TX (1U << 0) |
#define | MAC_FLAGS_RX (1U << 1) |
MAC configuration options | |
#define | MAC_USE_ZERO_COPY FALSE |
Enables an event sources for incoming packets. | |
#define | MAC_USE_EVENTS TRUE |
Enables an event sources for incoming packets. |
Low level driver helper macros | |
#define | __mac_callback(macp) |
MAC callback. | |
#define | __mac_tx_wakeup(macp) |
MAC TX wakeup and event. | |
#define | __mac_rx_wakeup(macp) |
MAC RX wakeup and event. |
Macro Functions | |
#define | macSetCallbackX(macp, f) |
Associates a callback to the MAC instance. | |
#define | macGetEventSource(macp) |
Returns the driver events source. | |
#define | macGetTransmitDescriptorX(macp, tdp) |
Returns a transmission descriptor. | |
#define | macReleaseTransmitDescriptorX(tdp) |
Releases a transmit descriptor and starts the transmission of the enqueued data as a single frame. | |
#define | macGetReceiveDescriptorX(macp, rdp) |
Returns a receive descriptor. | |
#define | macReleaseReceiveDescriptorX(rdp) |
Releases a receive descriptor. | |
#define | macWriteTransmitDescriptor(tdp, buf, size) |
Writes to a transmit descriptor's stream. | |
#define | macReadReceiveDescriptor(rdp, buf, size) |
Reads from a receive descriptor's stream. | |
#define | macGetNextTransmitBuffer(tdp, size, sizep) |
Returns a pointer to the next transmit buffer in the descriptor chain. | |
#define | macGetNextReceiveBuffer(rdp, sizep) |
Returns a pointer to the next receive buffer in the descriptor chain. |
PLATFORM configuration options | |
#define | PLATFORM_MAC_USE_MAC1 FALSE |
MAC driver enable switch. |
Data Structures | |
struct | hal_mac_config |
Driver configuration structure. More... | |
struct | hal_mac_driver |
Structure representing a MAC driver. More... | |
struct | hal_mac_transmit_descriptor |
Structure representing a MAC transmit descriptor. More... | |
struct | hal_mac_receive_descriptor |
Structure representing a MAC receive descriptor. More... |
Macros | |
#define | MAC_SUPPORTS_ZERO_COPY TRUE |
This implementation supports the zero-copy mode API. | |
#define | mac_lld_driver_fields |
Low level fields of the MAC driver structure. | |
#define | mac_lld_config_fields |
Low level fields of the MAC configuration structure. | |
#define | mac_lld_transmit_descriptor_fields |
Low level fields of the MAC transmit descriptor structure. | |
#define | mac_lld_receive_descriptor_fields |
Low level fields of the MAC receive descriptor structure. |
Typedefs | |
typedef struct hal_mac_driver | MACDriver |
Type of a structure representing a MAC driver. | |
typedef struct hal_mac_config | MACConfig |
Type of structure representing a MAC configuration. | |
typedef struct hal_mac_transmit_descriptor | MACTransmitDescriptor |
Type of structure representing a MAC transmit descriptor. | |
typedef struct hal_mac_receive_descriptor | MACReceiveDescriptor |
Type of structure representing a MAC receive descriptor. | |
typedef void(* | maccb_t) (MACDriver *macp) |
Generic ETH notification callback type. |
Enumerations | |
enum | macstate_t { MAC_UNINIT = 0 , MAC_STOP = 1 , MAC_ACTIVE = 2 } |
Driver state machine possible states. More... |
Functions | |
void | macInit (void) |
MAC Driver initialization. | |
void | macObjectInit (MACDriver *macp) |
Initialize the standard part of a MACDriver structure. | |
msg_t | macStart (MACDriver *macp, const MACConfig *config) |
Configures and activates the MAC peripheral. | |
void | macStop (MACDriver *macp) |
Deactivates the MAC peripheral. | |
eventflags_t | macGetAndClearEventsI (MACDriver *macp) |
Get and clears MAC event flags. | |
msg_t | macWaitTransmitDescriptor (MACDriver *macp, MACTransmitDescriptor *tdp, sysinterval_t timeout) |
Allocates a transmission descriptor. | |
msg_t | macWaitReceiveDescriptor (MACDriver *macp, MACReceiveDescriptor *rdp, sysinterval_t timeout) |
Waits for a received frame. | |
bool | macPollLinkStatus (MACDriver *macp) |
Updates and returns the link status. | |
void | macReleaseTransmitDescriptor (MACTransmitDescriptor *tdp) |
void | macReleaseReceiveDescriptor (MACReceiveDescriptor *rdp) |
void | mac_lld_init (void) |
Low level MAC initialization. | |
void | mac_lld_start (MACDriver *macp) |
Configures and activates the MAC peripheral. | |
void | mac_lld_stop (MACDriver *macp) |
Deactivates the MAC peripheral. | |
msg_t | mac_lld_get_transmit_descriptor (MACDriver *macp, MACTransmitDescriptor *tdp) |
Returns a transmission descriptor. | |
void | mac_lld_release_transmit_descriptor (MACTransmitDescriptor *tdp) |
Releases a transmit descriptor and starts the transmission of the enqueued data as a single frame. | |
msg_t | mac_lld_get_receive_descriptor (MACDriver *macp, MACReceiveDescriptor *rdp) |
Returns a receive descriptor. | |
void | mac_lld_release_receive_descriptor (MACReceiveDescriptor *rdp) |
Releases a receive descriptor. | |
bool | mac_lld_poll_link_status (MACDriver *macp) |
Updates and returns the link status. | |
size_t | mac_lld_write_transmit_descriptor (MACTransmitDescriptor *tdp, uint8_t *buf, size_t size) |
Writes to a transmit descriptor's stream. | |
size_t | mac_lld_read_receive_descriptor (MACReceiveDescriptor *rdp, uint8_t *buf, size_t size) |
Reads from a receive descriptor's stream. | |
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. | |
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. |
Variables | |
MACDriver | ETHD1 |
MAC1 driver identifier. |
#define MAC_USE_ZERO_COPY FALSE |
#define MAC_USE_EVENTS TRUE |
#define __mac_callback | ( | macp | ) |
#define __mac_tx_wakeup | ( | macp | ) |
MAC TX wakeup and event.
[in] | macp | pointer to the MACDriver object |
#define __mac_rx_wakeup | ( | macp | ) |
MAC RX wakeup and event.
[in] | macp | pointer to the MACDriver object |
#define macSetCallbackX | ( | macp, | |
f ) |
#define macGetEventSource | ( | macp | ) |
Returns the driver events source.
[in] | macp | pointer to the MACDriver object |
EventSource
structure.#define macGetTransmitDescriptorX | ( | macp, | |
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 310 of file hal_mac.h.
Referenced by macWaitTransmitDescriptor().
#define macReleaseTransmitDescriptorX | ( | 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 |
#define macGetReceiveDescriptorX | ( | macp, | |
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 335 of file hal_mac.h.
Referenced by macWaitReceiveDescriptor().
#define macReleaseReceiveDescriptorX | ( | 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 |
#define macWriteTransmitDescriptor | ( | 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 ) |
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 ) |
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 ) |
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.
#define mac_lld_driver_fields |
Low level fields of the MAC driver structure.
Definition at line 72 of file hal_mac_lld.h.
#define mac_lld_config_fields |
Low level fields of the MAC configuration structure.
Definition at line 77 of file hal_mac_lld.h.
#define mac_lld_transmit_descriptor_fields |
Low level fields of the MAC transmit descriptor structure.
Definition at line 82 of file hal_mac_lld.h.
#define mac_lld_receive_descriptor_fields |
Low level fields of the MAC receive descriptor structure.
Definition at line 87 of file hal_mac_lld.h.
typedef struct hal_mac_driver MACDriver |
typedef struct hal_mac_config MACConfig |
typedef struct hal_mac_transmit_descriptor MACTransmitDescriptor |
typedef struct hal_mac_receive_descriptor MACReceiveDescriptor |
typedef void(* maccb_t) (MACDriver *macp) |
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 hal_mac_driver::arg, hal_mac_driver::cb, hal_mac_driver::config, hal_mac_driver::es, hal_mac_driver::flags, MAC_STOP, osalEventObjectInit(), osalThreadQueueObjectInit(), hal_mac_driver::rdqueue, hal_mac_driver::state, and hal_mac_driver::tdqueue.
Referenced by mac_lld_init().
Configures and activates the MAC peripheral.
Definition at line 99 of file hal_mac.c.
References hal_mac_driver::config, HAL_RET_SUCCESS, MAC_ACTIVE, mac_lld_start(), MAC_STOP, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), and hal_mac_driver::state.
void macStop | ( | MACDriver * | macp | ) |
Deactivates the MAC peripheral.
[in] | macp | pointer to the MACDriver object |
Definition at line 136 of file hal_mac.c.
References hal_mac_driver::config, MAC_ACTIVE, mac_lld_stop(), MAC_STOP, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), and hal_mac_driver::state.
eventflags_t macGetAndClearEventsI | ( | MACDriver * | macp | ) |
Get and clears MAC event flags.
[in] | macp | pointer to the MACDriver object |
Definition at line 160 of file hal_mac.c.
References hal_mac_driver::flags.
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 187 of file hal_mac.c.
References MAC_ACTIVE, macGetTransmitDescriptorX, MSG_OK, MSG_TIMEOUT, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), osalThreadEnqueueTimeoutS(), hal_mac_driver::state, and hal_mac_driver::tdqueue.
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 227 of file hal_mac.c.
References MAC_ACTIVE, macGetReceiveDescriptorX, MSG_OK, MSG_TIMEOUT, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), osalThreadEnqueueTimeoutS(), hal_mac_driver::rdqueue, and hal_mac_driver::state.
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 259 of file hal_mac.c.
References MAC_ACTIVE, mac_lld_poll_link_status(), osalDbgAssert, osalDbgCheck, and hal_mac_driver::state.
void macReleaseTransmitDescriptor | ( | MACTransmitDescriptor * | tdp | ) |
void macReleaseReceiveDescriptor | ( | MACReceiveDescriptor * | rdp | ) |
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 hal_mac_driver::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 hal_mac_driver::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.
References MSG_OK.
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.
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.
References MSG_OK.
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.
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.