wiki:CSMAMAC

Version 21 (modified by chunter, 16 years ago) (diff)

--

Carrier-Sense Medium Access Reference Design (CSMAMAC)

The CSMAMAC is serves as the user-level MAC layer in reference design. The basic algorithm is simple:

  • Do I have a packet to send?
    • If the medium is idle, send it, enter a timeout, and wait for an acknowledgment from the destination
    • If the medium is busy, enter a backoff period and wait for the medium to become idle
  • Did I receive a data packet?
    • If the packet pass checksum and is addressed to me, send an acknowledgment
  • Did no know acknowledgment happen during a timeout period?
    • If the maximum number of retransmits has not occurred, enter a backoff and try retransmitting
    • If the maximum number of retransmits has occurred, drop the packet
  • Did I wait through a backoff period?
    • If the medium is busy, retransmit, increment the total number of resends, enter a timeout, and wait for an acknowledgment from the destination
    • If the medium is busy, enter a backoff period and wait for the medium to become idle

This simple algorithm encompasses much of the behavior in commercial 802.11 MAC/PHY chipsets. This algorithm lends itself nicely to a state diagram, which in turn, translates into C-code that can be executed in the PowerPC of the FPGA on WARP. In the following section, we track the "Life of a Packet" as it might journey through these states.

Life of a Packet

Below is the state-machine representation of the above algorithm. Each state can be "clicked" and is described in detail in the accompanying link. The up-to-date code can be found here: csmaMac.c. The API documentation for the code can be found here: CSMAMAC API


Note: Through all of the following descriptions, a "-" is used in place of arguments to functions when those arguments are not important to the overall purpose of the description. Howeverm, that is not to say that these arguments can be changed to anything and have the code still compile and run successfully. Care must be taken in modifying the reference design.

Idle

There are two purposes of this state: At startup must initialize the framework and WARP hardware, and in the steady state it must sit and wait for an event to take place. This state maps to the

int main()

function of csmaMac.c.

Startup

This block of code calls the following WARPMAC functions:

warpmac_getMyId();

This function reads the current setting on the Dip Switches. The value is used simply to identify the node in the network. For the purposes of the Reference Design, one node must be identified as "0" and the other as "1."

warpmac_init()

This function sets reasonable default values for many of the parameters of the MAC, configures interrupts and exceptions, configures Ethernet, and finally initializes the custom peripherals such as the radio controller, the PHY, the packet detector, and the automatic gain control block.

warpmac_setMacAddr(-);

This function sets the wireless MAC address of the node.

warpmac_setMaxResend(-);
warpmac_setMaxCW(-);
warpmac_setTimeout(-);
warpmac_setSlotTime(-);

These function set up internal parameters of the MAC. The maximum number of resends is the maximum number of times that a packet should be retransmitted, in the event of not receiving an acknowledgment. The maximum contention window defines "how random" backoffs should be in the worst case. The timeout time is the amount of time that the MAC should wait on an acknowledgment before retransmitting. Finally, the slot time is a length of the minimum contention window.

warpmac_setRxBuffer(-,0);
warpmac_setTxBuffer(1);

The newest version of the OFDM PHY supports a large chunk of memory that can be used to queue multiple packets. By default, the system is configured with enough memory to support 4 full-size packets. This block of code instructs the framework to use the first 1/4th of memory to receive packets into, and the second 1/4th of memory to send from. In principle, these functions can be used to help juggle packets in the event of a busy wireless medium. For example, one can receive into a separate piece of memory in order to avoid overwriting a packet that has not been processed by higher layers yet.

warpmac_setGoodPacketHandler(receiveGoodPacket);
warpmac_setBadPacketHandler(receiveBadPacket);
warpmac_setTimerHandler(timerExpire);
warpmac_setEmacHandler(ethernet_callback);

This block of code attaches user-level callbacks to interrupt service routines. These functions perform the behaviors that they sound like: receiving a packet that passes checksum, receiving a packet that fails checksum, processing a timer expiration, and handling Ethernet activity respectively.

warpmac_setChannel(-, -);

This function sets the center frequency of the radio in either the 2.4 or 5 GHz spectrum.

warpmac_setBaseRate(-)

Finally, the base rate modulation order is set. This rate must be agreed upon by all nodes in the network a priori. Within the base rate symbols is a field that specifies the modulation order of the rest of the packet (i.e. the full rate symbols). This enables dynamic modulation for autorate systems.

Steady State

The steady state behavior of the "Idle" state is very simple: it's nothing. At the bottom of the main function is a while loop that spins in place, waiting for an interrupt service routine to be called by a hardware event.


Accepted Packet from Source

This state is entered if a higher layer has a packet it needs transmitted. For the reference design, this means a packet has arrived via Ethernet and needs processing.


Medium State

The purpose of this state is to check to see if the medium has been idle for a DIFS period.

warpmac_carrierSense(-);

Is called and returns a 1 if the medium is idle (and hence the medium can be contented for) and a 0 if the medium is busy (and hence the node must wait).


Transmit Packet via PHY

To transmit a packet over-the-air via the OFDM physical layer, the MAC calls

warpmac_sendOfdm(&txBuffer);

The argument of this function is the Macframe containing the packet's header information. Note, the payload is already sitting inside the OFDM PHY's packet buffer thanks to the Ethernet MAC's built-in DMA engine. The particular packet buffer was designated back in the main function by

warpmac_setTxBuffer(-);

Set TIMEOUT Timer

This state starts the time located on the FPGA fabric in a deterministic countdown mode to wait for an acknowledgment. The framework function called is

warpmac_setTimer(TIMEOUT);

The length of the timeout period was specified back in the main function by

warpmac_setTimeout(-);

Set BACKOFF Timer

This state starts the time located on the FPGA fabric in a channel-dependent countdown mode. The hardware automatically supports automatic pausing of this counter in the event of a busy medium and automatic resumption of the timer during idle periods. The purpose of this function is to wait for a random idle time before attempting to use the medium again. The framework function called is

warpmac_setTimer(BACKOFF);

The length of the backoff period is a function of the current resend count, the slot size, and the maximum contention window size. These parameters were specified back in the main function.


Received Packet via PHY

This state kick-starts the receive states.


Checksum

Either

int receiveGoodPacket(-) 

is called in the event of receiving a packet that passes checksum or

int receiveGoodPacket(-) 

in the event of receiving a packet that fails checksum.


Destination Address


Packet Type


Clear TIMEOUT


Deliver Packet to Sink


Timer Expired


Timer Type


Medium State


Maximum Resends


Drop Packet


Increment Resend Counter