Rev | Line | |
---|
[5088] | 1 | function [backoff_start, phy_tx_start, tx_done, fsm_state_out] = ... |
---|
[5673] | 2 | mac_tx_ctrl_cd_fsm(... |
---|
[5088] | 3 | reset, ... |
---|
| 4 | new_tx, ... |
---|
| 5 | require_backoff, ... |
---|
| 6 | backoff_done, ... |
---|
| 7 | idle_for_difs, ... |
---|
| 8 | phy_tx_done) |
---|
| 9 | |
---|
| 10 | persistent fsm_state, fsm_state=xl_state(0, {xlUnsigned, 3, 0}); |
---|
| 11 | |
---|
| 12 | fsm_state_out = fsm_state; |
---|
| 13 | |
---|
| 14 | %Inputs: |
---|
| 15 | % reset: synchronous reset, forces internal state variables back to default (IDLE state) |
---|
| 16 | % new_tx: Software request for new Tx cycle |
---|
| 17 | % backoff_done: Indication from MAC hw that backoff period is done |
---|
| 18 | % idle_for_difs: Indication from MAC hw that medium has been idle > DIFS/EIFS |
---|
| 19 | % phy_tx_done: Indication from PHY that last sample is transmitted |
---|
| 20 | |
---|
| 21 | %Outputs: |
---|
| 22 | % backoff_start: Indication to MAC hw to run idle->backoff process |
---|
| 23 | % phy_tx_start: Indication to PHY to start Tx |
---|
| 24 | % tx_done: Indication to MAC hw that this Tx cycle is complete |
---|
| 25 | % fsm_state_out: Value of internal state register (for debugging) |
---|
| 26 | |
---|
| 27 | ST_IDLE = 0; |
---|
| 28 | ST_START_BO = 1; |
---|
| 29 | ST_DEFER = 2; |
---|
| 30 | ST_DO_TX = 3; |
---|
| 31 | ST_DONE = 4; |
---|
| 32 | |
---|
| 33 | if(reset) |
---|
| 34 | backoff_start = 0; |
---|
| 35 | phy_tx_start = 0; |
---|
| 36 | tx_done = 0; |
---|
| 37 | fsm_state = ST_IDLE; |
---|
| 38 | |
---|
| 39 | else |
---|
| 40 | switch double(fsm_state) |
---|
| 41 | |
---|
| 42 | case ST_IDLE |
---|
| 43 | backoff_start = 0; |
---|
| 44 | phy_tx_start = 0; |
---|
| 45 | tx_done = 0; |
---|
| 46 | |
---|
| 47 | if(new_tx) |
---|
| 48 | if(idle_for_difs && ~require_backoff) |
---|
| 49 | %If medium is already idle and this Tx doesn't require a backoff, start Tx immediately |
---|
| 50 | fsm_state = ST_DO_TX; |
---|
| 51 | else |
---|
| 52 | %Busy medium, or backoff required; start backoff |
---|
| 53 | fsm_state = ST_START_BO; |
---|
| 54 | end |
---|
| 55 | else |
---|
| 56 | %No new Tx this cycle |
---|
| 57 | fsm_state = ST_IDLE; |
---|
| 58 | end |
---|
| 59 | |
---|
| 60 | case ST_START_BO |
---|
| 61 | %Start the backoff counter, then transition to DEFER |
---|
| 62 | backoff_start = 1; |
---|
| 63 | phy_tx_start = 0; |
---|
| 64 | tx_done = 0; |
---|
| 65 | |
---|
| 66 | fsm_state = ST_DEFER; |
---|
| 67 | |
---|
| 68 | case ST_DEFER |
---|
| 69 | backoff_start = 0; |
---|
| 70 | phy_tx_start = 0; |
---|
| 71 | tx_done = 0; |
---|
| 72 | |
---|
| 73 | %Stay here until backoff completes |
---|
| 74 | if(backoff_done) |
---|
| 75 | fsm_state = ST_DO_TX; |
---|
| 76 | else |
---|
| 77 | fsm_state = ST_DEFER; |
---|
| 78 | end |
---|
| 79 | |
---|
| 80 | case ST_DO_TX |
---|
| 81 | backoff_start = 0; |
---|
| 82 | phy_tx_start = 1; |
---|
| 83 | tx_done = 0; |
---|
| 84 | |
---|
| 85 | % Stay here until PHY Tx finishes |
---|
| 86 | if(phy_tx_done) |
---|
| 87 | fsm_state = ST_DONE; |
---|
| 88 | else |
---|
| 89 | fsm_state = ST_DO_TX; |
---|
| 90 | end |
---|
| 91 | |
---|
| 92 | case ST_DONE |
---|
| 93 | backoff_start = 0; |
---|
| 94 | phy_tx_start = 0; |
---|
| 95 | tx_done = 1; |
---|
| 96 | |
---|
| 97 | fsm_state = ST_IDLE; |
---|
| 98 | |
---|
| 99 | otherwise |
---|
| 100 | %This case should be impossible; mostly here to appease MATLAB |
---|
| 101 | backoff_start = 0; |
---|
| 102 | phy_tx_start = 0; |
---|
| 103 | tx_done = 0; |
---|
| 104 | fsm_state = ST_IDLE; |
---|
| 105 | |
---|
| 106 | end %end switch |
---|
| 107 | end %end else |
---|
| 108 | |
---|
| 109 | end %end function |
---|
Note: See
TracBrowser
for help on using the repository browser.