wiki:CSMAMAC

Version 15 (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 the beginning of time the code 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.

Steady State

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_enableCSMA();
warpmac_enableEthernetInterrupt();

These function enable the carrier-sensing functionality of the hardware and the Ethernet interrupt.

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


Medium State


Transmit Packet via PHY


Set TIMEOUT Timer


Set BACKOFF Timer


Received Packet via PHY


Checksum


Destination Address


Packet Type


Clear TIMEOUT


Deliver Packet to Sink


Timer Expired


Timer Type


Medium State


Maximum Resends


Drop Packet


Increment Resend Counter