Design and implementation of MAC protocol based on CSMA/CA

Publisher:神光骑士Latest update time:2020-09-03 Source: elecfansKeywords:CSMA Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The advantages of the MAC protocol based on CSMA/CA are its simplicity and robustness. It is suitable for distributed networks. Each node does not need to maintain and dynamically update the status information of the surrounding adjacent nodes. It can independently decide when to access the channel. As long as the upper layer has data to be transmitted, the MAC layer will compete for the channel. Therefore, the application of this protocol is also quite extensive. The development of embedded technology also provides good technical support for the implementation of MAC protocol. This paper builds an embedded development platform based on ARM and FPGA, and designs and implements a MAC protocol based on CSMA/CA on this basis. Since ARM and FPGA are reconfigurable devices themselves, and some protocol parameters in FPGA are set by ARM, the protocol function in FPGA can be adjusted by modifying the ARM code. It is convenient and fast, and there is no need to regenerate the bit file download, which is conducive to the implementation of reconfigurable MAC protocol.


1 Protocol Function Description

1.1 Message Structure

This design implements the basic access mode of the MAC protocol based on CSMA/CA. The communication between nodes only includes data frames (DATA) and acknowledgment frames (ACK). Figure 1 shows the message structure, in which ACK does not have a net data part. Since the wireless communication within the range of one hop is considered, there is no relay node, etc., so there are only source node numbers and destination node numbers.

Design and implementation of MAC protocol based on CSMA/CA

1.2 Network design

The MAC protocol designed in this paper not only meets the basic mechanism of combining physical carrier sensing and virtual carrier sensing to detect channel busyness or idleness, but also includes inter-frame spacing, random backoff, response confirmation and retransmission mechanism.


A node that has data to send will first listen to the medium. If it is busy, it will continue to wait. If the idle time exceeds or equals DIFS or EIFS, it will enter the backoff process. During the backoff process, the node will randomly generate a backoff time to set the backoff timer and continue to listen to the medium. If the idle time reaches a time slot, the backoff timer will subtract a time slot. If the medium becomes busy during this period, the backoff process will be suspended until the idle time of the medium reaches DIFS or EIFS again before continuing the backoff process. When the backoff timer becomes 0, the node is allowed to start sending data, and the timeout retransmission mechanism will also be started. If the desired ACK is not received within the specified time, the data frame will be retransmitted. When the number of node retransmissions exceeds the retransmission threshold, the data frame will be discarded, or if it exceeds the longest allowed transmission time of the data frame, the data frame will also be discarded; when the node receives ACK, it will start preparing for the next data transmission.


The receiving node will immediately reply to the source node ACK when it receives a correct data frame sent to the node. If the node does not receive a correct data frame, it will use EIFS; if it receives a correct data frame but it is not sent to the node, the node will parse the duration, update the NAV, and regard the channel as occupied.


1.3 Functional division

This design makes full use of the flexibility and convenience of ARM to implement the random backoff algorithm and protocol parameter management, such as the number of retransmissions and the setting of the inter-frame interval. The random backoff algorithm uses a value that randomly selects a value in the 2i time slots as the value that the node needs to back off for the i-th backoff. The setting of the protocol parameters is completed by ARM, mainly considering that FPGA is not conducive to parameter modification, which can also enhance the reconfigurability of the protocol. FPGA, with its excellent real-time signal processing advantages, is used to manage the sending and receiving control of MAC frames.

2 Protocol Design

The working state of the MAC layer is mainly determined by physical carrier sensing and virtual carrier sensing (ie: MAC_flag = CS_flag or NAV_flag). When both are displayed as idle, the MAC layer will enter the state of sending data frames. At the same time, the protocol also requires clock counting to participate. IFS_ TI me is the time each node needs to wait before entering the backoff process to realize the function of inter-frame interval; Backoff_ TI me is the time each node backs off in the backoff process; NAV_ TI me is the time for nodes that are not communicating to reserve channels. These three times are also related to the state of the entire protocol. Figure 2 shows a specific implementation flow chart, and the specific implementation process steps are as follows:

Design and implementation of MAC protocol based on CSMA/CA

(1) If MAC_flag is false, it indicates that the channel is idle, and then enter (2); if MAC_flag is true, it means that the channel is now occupied. At this time, no matter what state the node is in, it will enter step 7, except for the node that is sending data. Since the node that is sending data cannot monitor the channel and cannot receive data from other nodes, the carrier sense mechanism is invalid in this state. Therefore, the node that is sending data will not suddenly change from the sending state to the receiving state.

(2) Execute the inter-frame spacing process, decrement the IFS_TIME size , and enter (3) when it reaches 0. The initial value of IFS_time is DIFS.

(3) Backoff process. The backoff time is mainly provided by ARM. When a node experiences a time slot, the backoff time slot number decreases by 1. However, when a node does not completely experience a time slot, the backoff time slot number does not change. After the backoff process ends, it will enter (4).

(4) Determine the transmission type. The initial value of the transmission type Tx_tpye in the design is 1. If Tx_tpye is 0, the node sends ACK. According to the source/destination node number and sequence number in the received data frame, the reply node ACK is assembled, and IFS_time and Backoff_time are initialized for the node to send data frames. At the same time, NAV_flag is set to true, the value of NAV_time is updated, and virtual carrier sensing is continued to avoid the situation where the node sending ACK will occupy the channel first; if Tx_tpye is not 0, it means that the node can start sending data frames, and go to (5).

(5) Before sending a data frame, it is first determined whether the maximum allowed sending time has been exceeded. If so, the data frame is discarded, IFS_time is set to EIFS, Backof_time is initialized, and the timeout timer is stopped. If the maximum allowed sending time has not been exceeded, the node formally sends the data frame and starts a single timeout. After sending, it waits for ACK and then enters (6).

(6) While waiting for the ACK to arrive, determine whether the single transmission time has exceeded. If so, the number of retransmissions is increased. Then determine whether the retransmission threshold has been exceeded. If so, the data frame is discarded. If not, IFS_time is set to EIFS, and ARM's random backoff algorithm is required to re-assign a backoff time slot number based on the number of retransmissions, and at the same time modify the retransmission bit in the data frame for the receiving node to identify.

(7) Save the Backoff_time in the current backoff process and the size of the inter-frame interval IFS_time that just ended, receive the MAC frame and parse the relevant data in it to prepare for the subsequent assembly of ACK, and then enter (8) and set NAV_flag to true to ensure that the MAC layer can process the data.

(8) Check whether the received MAC frame is correct. If not, set IFS_time to EIFS, NAV_flag to false, and NAV_time to 0. Then the node enters the interframe spacing process. If the check is correct, go to (9).

(9) Compare the destination node number parsed by the FPGA with the current node to determine whether it is sent to this node. If it is not sent to this node, then compare whether the current NAV_time value of this node is greater than the NAV in the received MAC frame. If it is greater, this node continues to execute according to the existing NAV_time value; if it is less than the NAV in the received MAC frame, use the NAV in the MAC frame to update the NAV_time value of this node, and then decrease the latest NAV_time value until it reaches 0, and the virtual carrier sense displays idle. However, during the execution of NAV_time decrement, a new MAC frame may be received at any time, and it is not sent to this node. This step must still be executed, and it is not necessary to wait until NAV_time becomes 0 before updating. If it is sent to this node, it will enter (10).

(10) If the node receives a data frame, that is, Rx_type is 1, FPGA uploads the received data frame to ARM; at the same time, IFS_time is updated to SIFS, and Backoff_time is set to 0, so that the time interval between receiving the data frame and sending ACK is SIFS, and Tx_tpye is set to 0, NAV_flag becomes false, and enters (2) to prepare to send ACK. If Rx_type is 0, the node receives ACK, indicating that a data transmission and reception process has ended, the node will initialize related parameters, stop timing, etc., and FPGA releases space, indicating that the data frame has been sent successfully.


3 Simulation Verification

The key to the implementation of MAC protocol based on CSMA/CA lies in the processing of various situations by each node, so the simulation verification of a node protocol function can also prove the correctness of the design. The design of FPGA part is the key in this design, so ModelSim is used to simulate and observe the processing process of node FPGA.


3.1 Channel Contention Process

In the MAC protocol based on CSMA/CA, each node is also unaware of the status of the nodes around it, so when a node competes for a channel, it may detect that the channel is occupied at any time. Figure 3 shows that when a node detects that the physical carrier sense becomes busy during the backoff process, it immediately stops the backoff process and suspends the backoff time slot number at this time, that is, the backoff time slot number is retained as 31. When the channel becomes idle again for more than the inter-frame interval DIFS, the backoff process will continue with the reserved backoff time slot number, and data frames will be sent after it becomes 0. In the figure, you can also see the process of updating NAV after the node receives the correct ACK. The execution flow of the simulation diagram shows that the designed MAC protocol meets the functional requirements of carrier sense mechanism, inter-frame interval, and random backoff.

[1] [2]
Keywords:CSMA Reference address:Design and implementation of MAC protocol based on CSMA/CA

Previous article:How to port Linux 2.4 to embedded systems on ARM platform
Next article:Wireless meteorological data communication system based on ARM microprocessor and Linux

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号