source: ReferenceDesigns/w3_802.11/sysgen/wlan_mac_hw/mcode_blocks/mac_tx_ctrl_a_fsm.m

Last change on this file was 4402, checked in by murphpo, 9 years ago

Ongoing MAC/PHY work for 11n support

File size: 6.2 KB
Line 
1function [backoff_start, phy_tx_start, tx_done, tx_result_out, fsm_state_out] = ...
2    mac_tx_ctrl_a_fsm(...
3        pre_wait_postRxTimer1, ...
4        pre_wait_postTxTimer1, ...
5        post_wait_postTxTimer2, ...
6        reset, ...
7        new_tx, ...
8        postRxTimer1_done, ...
9        postTxTimer1_done, ...
10        postTxTimer2_done, ...
11        backoff_done, ...
12        idle_for_difs, ...
13        phy_tx_done, ...
14        phy_rx_start)
15
16persistent fsm_state, fsm_state=xl_state(0, {xlUnsigned, 3, 0});
17persistent tx_result, tx_result=xl_state(0, {xlUnsigned, 2, 0});
18
19fsm_state_out = fsm_state;
20tx_result_out = tx_result;
21
22%Inputs:
23% reset: synchronous reset, forces internal state variables back to default (IDLE state)
24% new_tx: Software request for new Tx cycle
25% pre_wait_postRxTimer1: Param requiring this Tx occur after postRxTimer 1 expires
26% pre_wait_postTxTimer1: Param requiring this Tx occur after postTxTimer 1 expires
27% post_wait_postTxTimer2: Param requiring this Tx state wait after transmitting for postTxTimer 2 expiration
28% backoff_done: Indication from MAC hw that backoff period is done
29% idle_for_difs: Indication from MAC hw that medium has been idle > DIFS/EIFS
30% phy_tx_done: Indication from PHY that last sample is transmitted
31% phy_rx_start: Indication from PHY that new Rx has started
32
33%Outputs:
34% backoff_start: Indication to MAC hw to run idle->backoff process
35% phy_tx_start: Indication to PHY to start Tx
36% tx_done: Indication to MAC hw that this Tx cycle is complete
37% tx_result_out: Status of tx_done (timeout or rx_started)
38% fsm_state_out: Value of  internal state register (for debugging)
39
40ST_IDLE = 0;
41ST_PRE_TX_WAIT = 1;
42ST_START_BO = 2;
43ST_DEFER = 3;
44ST_DO_TX = 4;
45ST_POST_TX = 5;
46ST_POST_TX_WAIT = 6;
47ST_DONE = 7;
48
49TX_RESULT_NONE = 0;
50TX_RESULT_POSTTX_TIMER_EXPIRED = 1;
51TX_RESULT_RX_STARTED = 2;
52
53if(reset)
54    backoff_start = 0;
55    phy_tx_start = 0;
56    tx_done = 0;
57    fsm_state = ST_IDLE;
58    tx_result = TX_RESULT_NONE;
59
60else
61    switch double(fsm_state)
62
63        case ST_IDLE
64            backoff_start = 0;
65            phy_tx_start = 0;
66            tx_done = 0;
67
68            tx_result = TX_RESULT_NONE;
69
70            if(new_tx)
71                if(pre_wait_postRxTimer1 || pre_wait_postTxTimer1)
72                    %Tx scheduled for future, some fixed time after previous Tx/Rx
73                    fsm_state = ST_PRE_TX_WAIT;
74                elseif(~backoff_done)
75                    %If backoff is already running, use it as our deferral
76                    fsm_state = ST_DEFER;
77                elseif(idle_for_difs)
78                    %If no pre-Tx BO is required, any old backoff has expired and medium has been idle,
79                    % transmit immediately
80                    fsm_state = ST_DO_TX;
81                else
82                    %If medium hasn't been idle, backoff
83                    fsm_state = ST_START_BO;
84                end
85            else
86                fsm_state = ST_IDLE;
87            end
88
89        case ST_PRE_TX_WAIT
90            backoff_start = 0;
91            phy_tx_start = 0;
92            tx_done = 0;
93
94            tx_result = TX_RESULT_NONE;
95           
96            %Stay in PRE_TX_WAIT until the selected timer expires
97            % MAC must take care if using both timers/conditions - only
98            %  the first will trigger a Tx, the other will expire without effect
99            if( (pre_wait_postRxTimer1 && postRxTimer1_done) || (pre_wait_postTxTimer1 && postTxTimer1_done) )
100                fsm_state = ST_DO_TX;
101            else
102                fsm_state = ST_PRE_TX_WAIT;
103            end
104
105        case ST_START_BO
106            %Start the backoff counter, then transition to DEFER
107            backoff_start = 1;
108            phy_tx_start = 0;
109            tx_done = 0;
110
111            tx_result = TX_RESULT_NONE;
112            fsm_state = ST_DEFER;
113
114        case ST_DEFER
115            backoff_start = 0;
116            phy_tx_start = 0;
117            tx_done = 0;
118
119            tx_result = TX_RESULT_NONE;
120
121            %Stay here until backoff completes
122            if(backoff_done)
123                fsm_state = ST_DO_TX;
124            else
125                fsm_state = ST_DEFER;
126            end
127
128        case ST_DO_TX
129            backoff_start = 0;
130            phy_tx_start = 1;
131            tx_done = 0;
132
133            tx_result = TX_RESULT_NONE;
134
135            % Stay here until PHY Tx finishes
136            if(phy_tx_done)
137                fsm_state = ST_POST_TX;
138            else
139                fsm_state = ST_DO_TX;
140            end
141
142        case ST_POST_TX
143            backoff_start = 0;
144            phy_tx_start = 0;
145            tx_done = 0;
146
147            tx_result = TX_RESULT_NONE;
148
149            %If post-Tx timer is selected, transition to wait state
150            if(post_wait_postTxTimer2)
151                fsm_state = ST_POST_TX_WAIT;
152            else
153                fsm_state = ST_DONE;
154            end
155
156        case ST_POST_TX_WAIT
157            backoff_start = 0;
158            phy_tx_start = 0;
159            tx_done = 0;
160
161            % Stay in POST_TX_WAIT until PHY Rx starts or the post-Tx
162            %  timer expires. RX_START gets priority to handle unlikely
163            %  case of RX_START and timer_done asserting in the same cycle
164            if(phy_rx_start)
165                fsm_state = ST_DONE;
166                tx_result = TX_RESULT_RX_STARTED;
167            elseif(postTxTimer2_done)
168                fsm_state = ST_DONE;
169                tx_result = TX_RESULT_POSTTX_TIMER_EXPIRED;
170            else
171                fsm_state = ST_POST_TX_WAIT;
172                tx_result = TX_RESULT_NONE;
173            end
174
175        case ST_DONE
176            backoff_start = 0;
177            phy_tx_start = 0;
178            tx_done = 1;
179
180            %Previous state set tx_result - leave it alone so downstream
181            % logic can latch it when tx_done goes high
182
183            fsm_state = ST_IDLE;
184
185        otherwise
186            %This case should be impossible; mostly here to appease MATLAB
187            backoff_start = 0;
188            phy_tx_start = 0;
189            tx_done = 0;
190            tx_result = TX_RESULT_NONE;
191            fsm_state = ST_IDLE;
192
193    end %end switch
194end %end else
195
196end %end function
197
Note: See TracBrowser for help on using the repository browser.