[4415] | 1 | function [phy_tx_start, tx_done, tx_result_out, fsm_state_out] = ... |
---|
| 2 | mac_tx_ctrl_b_fsm(... |
---|
| 3 | pre_wait_postRxTimer1, ... |
---|
| 4 | pre_wait_postRxTimer2, ... |
---|
| 5 | pre_wait_postTxTimer1, ... |
---|
| 6 | req_zero_nav, ... |
---|
| 7 | reset, ... |
---|
| 8 | new_tx, ... |
---|
| 9 | nav_zero, ... |
---|
| 10 | postRxTimer1_done, ... |
---|
| 11 | postRxTimer2_done, ... |
---|
| 12 | postTxTimer1_done, ... |
---|
| 13 | phy_tx_done) |
---|
| 14 | |
---|
| 15 | persistent fsm_state, fsm_state=xl_state(0, {xlUnsigned, 3, 0}); |
---|
| 16 | persistent tx_result, tx_result=xl_state(0, {xlUnsigned, 2, 0}); |
---|
| 17 | |
---|
| 18 | fsm_state_out = fsm_state; |
---|
| 19 | tx_result_out = tx_result; |
---|
| 20 | |
---|
| 21 | %Inputs: |
---|
| 22 | % reset: synchronous reset, forces internal state variables back to default (IDLE state) |
---|
| 23 | % new_tx: Software request for new Tx cycle |
---|
| 24 | % pre_wait_postRxTimer1: Param requiring this Tx occur after postRxTimer 1 expires |
---|
| 25 | % pre_wait_postRxTimer2: Param requiring this Tx occur after postRxTimer 2 expires |
---|
| 26 | % pre_wait_postTxTimer1: Param requiring this Tx occur after postTxTimer 1 expires |
---|
| 27 | % req_zero_nav: Param requiring this Tx be skipped if NAV is nonzero at Tx time |
---|
| 28 | % nav_zero: Indication from MAC if NAV is currently zero (idle) |
---|
| 29 | % postRxTimer1_done: Indication from MAC that postRx Timer 1 is done |
---|
| 30 | % postRxTimer2_done: Indication from MAC that postRx Timer 2 is done |
---|
| 31 | % postTxTimer1_done: Indication from MAC that postTx Timer 1 is done |
---|
| 32 | % phy_tx_done: Indication from PHY that PHY Tx is done |
---|
| 33 | |
---|
| 34 | %Outputs: |
---|
| 35 | % backoff_start: Indication to MAC hw to run idle->backoff process |
---|
| 36 | % phy_tx_start: Indication to PHY to start Tx |
---|
| 37 | % tx_done: Indication to MAC hw that this Tx cycle is complete |
---|
| 38 | % tx_result_out: Status of tx_done (did Tx or did not Tx) |
---|
| 39 | % fsm_state_out: Value of internal state register (for debugging) |
---|
| 40 | |
---|
| 41 | %States: |
---|
| 42 | % ST_IDLE: Waiting for new Tx from MAC sw |
---|
| 43 | % ST_DO_TX: Started PHY Tx, waiting for completion |
---|
| 44 | % ST_DEFERRING: Deferral required, wait for BO to finish |
---|
| 45 | % ST_POST_TX: Finished Tx, waiting for timeout or Rx |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | ST_IDLE = 0; |
---|
| 49 | ST_PRE_TX_WAIT = 1; |
---|
| 50 | ST_CHECK_NAV = 2; |
---|
| 51 | ST_DO_TX = 3; |
---|
| 52 | ST_DONE = 4; |
---|
| 53 | |
---|
| 54 | TX_RESULT_NONE = 0; |
---|
| 55 | TX_RESULT_DID_TX = 1; |
---|
| 56 | TX_RESULT_NO_TX = 2; |
---|
| 57 | |
---|
| 58 | if(reset) |
---|
| 59 | phy_tx_start = 0; |
---|
| 60 | tx_done = 0; |
---|
| 61 | fsm_state = ST_IDLE; |
---|
| 62 | tx_result = TX_RESULT_NONE; |
---|
| 63 | |
---|
| 64 | else |
---|
| 65 | switch double(fsm_state) |
---|
| 66 | |
---|
| 67 | case ST_IDLE |
---|
| 68 | phy_tx_start = 0; |
---|
| 69 | tx_done = 0; |
---|
| 70 | |
---|
| 71 | tx_result = TX_RESULT_NONE; |
---|
| 72 | |
---|
| 73 | if(new_tx) |
---|
| 74 | if(pre_wait_postRxTimer1 || pre_wait_postRxTimer2 || pre_wait_postTxTimer1) |
---|
| 75 | %Tx scheduled for future, some fixed time after previous Tx/Rx |
---|
| 76 | fsm_state = ST_PRE_TX_WAIT; |
---|
| 77 | else |
---|
| 78 | %No waiting - move on to NAV check, then Tx |
---|
| 79 | fsm_state = ST_CHECK_NAV; |
---|
| 80 | end |
---|
| 81 | else |
---|
| 82 | fsm_state = ST_IDLE; |
---|
| 83 | end |
---|
| 84 | |
---|
| 85 | case ST_PRE_TX_WAIT |
---|
| 86 | phy_tx_start = 0; |
---|
| 87 | tx_done = 0; |
---|
| 88 | |
---|
| 89 | tx_result = TX_RESULT_NONE; |
---|
| 90 | |
---|
| 91 | %Stay in PRE_TX_WAIT until the selected timer expires |
---|
| 92 | % MAC must take care if using multiple timers/conditions - only |
---|
| 93 | % the first will trigger a Tx, the others will expire without effect |
---|
| 94 | if( (pre_wait_postRxTimer1 && postRxTimer1_done) || ... |
---|
| 95 | (pre_wait_postRxTimer2 && postRxTimer2_done) || ... |
---|
| 96 | (pre_wait_postTxTimer1 && postTxTimer1_done)) |
---|
| 97 | fsm_state = ST_CHECK_NAV; |
---|
| 98 | else |
---|
| 99 | fsm_state = ST_PRE_TX_WAIT; |
---|
| 100 | end |
---|
| 101 | |
---|
| 102 | case ST_CHECK_NAV |
---|
| 103 | phy_tx_start = 0; |
---|
| 104 | tx_done = 0; |
---|
| 105 | |
---|
| 106 | if( (req_zero_nav && nav_zero) || ~req_zero_nav) |
---|
| 107 | %Either don't care about NAV, or NAV was zero - start Tx |
---|
| 108 | tx_result = TX_RESULT_DID_TX; |
---|
| 109 | fsm_state = ST_DO_TX; |
---|
| 110 | else |
---|
| 111 | %NAV was non-zero at Tx time - skip Tx |
---|
| 112 | tx_result = TX_RESULT_NO_TX; |
---|
| 113 | fsm_state = ST_DONE; |
---|
| 114 | end |
---|
| 115 | |
---|
| 116 | case ST_DO_TX |
---|
| 117 | phy_tx_start = 1; |
---|
| 118 | tx_done = 0; |
---|
| 119 | |
---|
| 120 | % Stay here until PHY Tx finishes |
---|
| 121 | if(phy_tx_done) |
---|
| 122 | fsm_state = ST_DONE; |
---|
| 123 | else |
---|
| 124 | fsm_state = ST_DO_TX; |
---|
| 125 | end |
---|
| 126 | |
---|
| 127 | case ST_DONE |
---|
| 128 | phy_tx_start = 0; |
---|
| 129 | tx_done = 1; |
---|
| 130 | |
---|
| 131 | %Previous state set tx_result - leave it alone so downstream |
---|
| 132 | % logic can latch it when tx_done goes high |
---|
| 133 | |
---|
| 134 | fsm_state = ST_IDLE; |
---|
| 135 | |
---|
| 136 | otherwise |
---|
| 137 | %This case should be impossible; mostly here to appease MATLAB |
---|
| 138 | phy_tx_start = 0; |
---|
| 139 | tx_done = 0; |
---|
| 140 | tx_result = TX_RESULT_NONE; |
---|
| 141 | fsm_state = ST_IDLE; |
---|
| 142 | |
---|
| 143 | end %end switch |
---|
| 144 | end %end else |
---|
| 145 | |
---|
| 146 | end %end function |
---|
| 147 | |
---|