ChibiOS/RT
2.5.1
MAC Driver
Collaboration diagram for MAC Driver:

Detailed Description

Generic MAC driver.

This module implements a generic MAC (Media Access Control) driver for Ethernet controllers.

Precondition:
In order to use the MAC driver the HAL_USE_MAC option must be enabled in halconf.h.

Functions

void macInit (void)
 MAC Driver initialization.
void macObjectInit (MACDriver *macp)
 Initialize the standard part of a MACDriver structure.
void macStart (MACDriver *macp, const MACConfig *config)
 Configures and activates the MAC peripheral.
void macStop (MACDriver *macp)
 Deactivates the MAC peripheral.
msg_t macWaitTransmitDescriptor (MACDriver *macp, MACTransmitDescriptor *tdp, systime_t time)
 Allocates a transmission descriptor.
void macReleaseTransmitDescriptor (MACTransmitDescriptor *tdp)
 Releases a transmit descriptor and starts the transmission of the enqueued data as a single frame.
msg_t macWaitReceiveDescriptor (MACDriver *macp, MACReceiveDescriptor *rdp, systime_t time)
 Waits for a received frame.
void macReleaseReceiveDescriptor (MACReceiveDescriptor *rdp)
 Releases a receive descriptor.
bool_t macPollLinkStatus (MACDriver *macp)
 Updates and returns the link status.

MAC configuration options

#define MAC_USE_EVENTS   TRUE
 Enables an event sources for incoming packets.

Macro Functions

#define macGetReceiveEventSource(macp)   (&(macp)->rdevent)
 Returns the received frames event source.
#define macWriteTransmitDescriptor(tdp, buf, size)   mac_lld_write_transmit_descriptor(tdp, buf, size)
 Writes to a transmit descriptor's stream.
#define macReadReceiveDescriptor(rdp, buf, size)   mac_lld_read_receive_descriptor(rdp, buf, size)
 Reads from a receive descriptor's stream.

Typedefs

typedef struct MACDriver MACDriver
 Type of a structure representing a MAC driver.

Enumerations

enum  macstate_t { MAC_UNINIT = 0, MAC_STOP = 1, MAC_ACTIVE = 2 }
 Driver state machine possible states. More...

Function Documentation

void macInit ( void  )

MAC Driver initialization.

Note:
This function is implicitly invoked by halInit(), there is no need to explicitly initialize the driver.
Function Class:
Initializer, this function just initializes an object and can be invoked before the kernel is initialized.

Definition at line 65 of file mac.c.

Referenced by halInit().

void macObjectInit ( MACDriver macp)

Initialize the standard part of a MACDriver structure.

Parameters:
[out]macppointer to the MACDriver object
Function Class:
Initializer, this function just initializes an object and can be invoked before the kernel is initialized.

Definition at line 77 of file mac.c.

References chEvtInit, chSemInit(), and MAC_STOP.

Here is the call graph for this function:

void macStart ( MACDriver macp,
const MACConfig *  config 
)

Configures and activates the MAC peripheral.

Parameters:
[in]macppointer to the MACDriver object
[in]configpointer to the MACConfig object
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 96 of file mac.c.

References chDbgAssert, chDbgCheck, chSysLock, chSysUnlock, MAC_ACTIVE, and MAC_STOP.

void macStop ( MACDriver macp)

Deactivates the MAC peripheral.

Parameters:
[in]macppointer to the MACDriver object
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 116 of file mac.c.

References chDbgAssert, chDbgCheck, chSysLock, chSysUnlock, MAC_ACTIVE, and MAC_STOP.

msg_t macWaitTransmitDescriptor ( MACDriver macp,
MACTransmitDescriptor *  tdp,
systime_t  time 
)

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.

Parameters:
[in]macppointer to the MACDriver object
[out]tdppointer to a MACTransmitDescriptor structure
[in]timethe number of ticks before the operation timeouts, the following special values are allowed:
  • TIME_IMMEDIATE immediate timeout.
  • TIME_INFINITE no timeout.
Returns:
The operation status.
Return values:
RDY_OKthe descriptor was obtained.
RDY_TIMEOUTthe operation timed out, descriptor not initialized.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 147 of file mac.c.

References chDbgAssert, chDbgCheck, chSemWaitTimeoutS(), chSysLock, chSysUnlock, chTimeNow, MAC_ACTIVE, RDY_OK, RDY_TIMEOUT, and TIME_INFINITE.

Here is the call graph for this function:

void macReleaseTransmitDescriptor ( MACTransmitDescriptor *  tdp)

Releases a transmit descriptor and starts the transmission of the enqueued data as a single frame.

Parameters:
[in]tdpthe pointer to the MACTransmitDescriptor structure
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 180 of file mac.c.

References chDbgCheck.

msg_t macWaitReceiveDescriptor ( MACDriver macp,
MACReceiveDescriptor *  rdp,
systime_t  time 
)

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.

Parameters:
[in]macppointer to the MACDriver object
[out]rdppointer to a MACReceiveDescriptor structure
[in]timethe number of ticks before the operation timeouts, the following special values are allowed:
  • TIME_IMMEDIATE immediate timeout.
  • TIME_INFINITE no timeout.
Returns:
The operation status.
Return values:
RDY_OKthe descriptor was obtained.
RDY_TIMEOUTthe operation timed out, descriptor not initialized.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 206 of file mac.c.

References chDbgAssert, chDbgCheck, chSemWaitTimeoutS(), chSysLock, chSysUnlock, chTimeNow, MAC_ACTIVE, RDY_OK, RDY_TIMEOUT, and TIME_INFINITE.

Here is the call graph for this function:

void macReleaseReceiveDescriptor ( MACReceiveDescriptor *  rdp)

Releases a receive descriptor.

The descriptor and its buffer are made available for more incoming frames.

Parameters:
[in]rdpthe pointer to the MACReceiveDescriptor structure
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 240 of file mac.c.

References chDbgCheck.

bool_t macPollLinkStatus ( MACDriver macp)

Updates and returns the link status.

Parameters:
[in]macppointer to the MACDriver object
Returns:
The link status.
Return values:
TRUEif the link is active.
FALSEif the link is down.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 257 of file mac.c.

References chDbgAssert, chDbgCheck, and MAC_ACTIVE.


Define Documentation

#define MAC_USE_EVENTS   TRUE

Enables an event sources for incoming packets.

Definition at line 49 of file mac.h.

#define macGetReceiveEventSource (   macp)    (&(macp)->rdevent)

Returns the received frames event source.

Parameters:
[in]macppointer to the MACDriver object
Returns:
The pointer to the EventSource structure.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 102 of file mac.h.

#define macWriteTransmitDescriptor (   tdp,
  buf,
  size 
)    mac_lld_write_transmit_descriptor(tdp, buf, size)

Writes to a transmit descriptor's stream.

Parameters:
[in]tdppointer to a MACTransmitDescriptor structure
[in]bufpointer to the buffer containing the data to be written
[in]sizenumber of bytes to be written
Returns:
The number of bytes written into the descriptor's stream, this value can be less than the amount specified in the parameter size if the maximum frame size is reached.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 118 of file mac.h.

#define macReadReceiveDescriptor (   rdp,
  buf,
  size 
)    mac_lld_read_receive_descriptor(rdp, buf, size)

Reads from a receive descriptor's stream.

Parameters:
[in]rdppointer to a MACReceiveDescriptor structure
[in]bufpointer to the buffer that will receive the read data
[in]sizenumber of bytes to be read
Returns:
The number of bytes read from the descriptor's stream, this value can be less than the amount specified in the parameter size if there are no more bytes to read.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 133 of file mac.h.


Typedef Documentation

typedef struct MACDriver MACDriver

Type of a structure representing a MAC driver.

Definition at line 81 of file mac.h.


Enumeration Type Documentation

enum macstate_t

Driver state machine possible states.

Enumerator:
MAC_UNINIT 

Not initialized.

MAC_STOP 

Stopped.

MAC_ACTIVE 

Active.

Definition at line 72 of file mac.h.