[4402] | 1 | function [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) |
---|
[2088] | 15 | |
---|
| 16 | persistent fsm_state, fsm_state=xl_state(0, {xlUnsigned, 3, 0}); |
---|
| 17 | persistent tx_result, tx_result=xl_state(0, {xlUnsigned, 2, 0}); |
---|
| 18 | |
---|
| 19 | fsm_state_out = fsm_state; |
---|
| 20 | tx_result_out = tx_result; |
---|
| 21 | |
---|
| 22 | %Inputs: |
---|
[4402] | 23 | % reset: synchronous reset, forces internal state variables back to default (IDLE state) |
---|
[2088] | 24 | % new_tx: Software request for new Tx cycle |
---|
[4402] | 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 |
---|
[2088] | 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 | |
---|
| 40 | ST_IDLE = 0; |
---|
[4402] | 41 | ST_PRE_TX_WAIT = 1; |
---|
[2088] | 42 | ST_START_BO = 2; |
---|
| 43 | ST_DEFER = 3; |
---|
[4402] | 44 | ST_DO_TX = 4; |
---|
| 45 | ST_POST_TX = 5; |
---|
| 46 | ST_POST_TX_WAIT = 6; |
---|
| 47 | ST_DONE = 7; |
---|
[2088] | 48 | |
---|
| 49 | TX_RESULT_NONE = 0; |
---|
[4402] | 50 | TX_RESULT_POSTTX_TIMER_EXPIRED = 1; |
---|
[2088] | 51 | TX_RESULT_RX_STARTED = 2; |
---|
| 52 | |
---|
| 53 | if(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 | |
---|
| 60 | else |
---|
| 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) |
---|
[4402] | 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) |
---|
[2088] | 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 | |
---|
[4402] | 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 | |
---|
[2088] | 105 | case ST_START_BO |
---|
[4402] | 106 | %Start the backoff counter, then transition to DEFER |
---|
[2088] | 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 | |
---|
[4402] | 121 | %Stay here until backoff completes |
---|
[2088] | 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 | |
---|
[4402] | 135 | % Stay here until PHY Tx finishes |
---|
[2088] | 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 | |
---|
[4402] | 149 | %If post-Tx timer is selected, transition to wait state |
---|
| 150 | if(post_wait_postTxTimer2) |
---|
[2088] | 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 | |
---|
[4402] | 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 |
---|
[2088] | 164 | if(phy_rx_start) |
---|
| 165 | fsm_state = ST_DONE; |
---|
| 166 | tx_result = TX_RESULT_RX_STARTED; |
---|
[4402] | 167 | elseif(postTxTimer2_done) |
---|
[2088] | 168 | fsm_state = ST_DONE; |
---|
[4402] | 169 | tx_result = TX_RESULT_POSTTX_TIMER_EXPIRED; |
---|
[2088] | 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 |
---|
[4402] | 186 | %This case should be impossible; mostly here to appease MATLAB |
---|
[2088] | 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 |
---|
| 194 | end %end else |
---|
| 195 | |
---|
| 196 | end %end function |
---|
| 197 | |
---|