mac_backoff_timer.lst

来自「TI的基于ZIGBEE2006的协议栈」· LST 代码 · 共 1,132 行 · 第 1/5 页

LST
1,132
字号
     44          
     45          /* ------------------------------------------------------------------------------------------------
     46           *                                            Defines
     47           * ------------------------------------------------------------------------------------------------
     48           */
     49          #define COMPARE_STATE_ROLLOVER_BV                 BV(0)
     50          #define COMPARE_STATE_TRIGGER_BV                  BV(1)
     51          #define COMPARE_STATE_ARM_BV                      BV(2)
     52          
     53          #define COMPARE_STATE_TRIGGER                     COMPARE_STATE_TRIGGER_BV
     54          #define COMPARE_STATE_ROLLOVER                    COMPARE_STATE_ROLLOVER_BV
     55          #define COMPARE_STATE_ROLLOVER_AND_TRIGGER        (COMPARE_STATE_ROLLOVER_BV | COMPARE_STATE_TRIGGER_BV)
     56          #define COMPARE_STATE_ROLLOVER_AND_ARM_TRIGGER    (COMPARE_STATE_ROLLOVER_BV | COMPARE_STATE_ARM_BV)
     57          
     58          
     59          /*
     60           *  The datasheet mentions a small delay on both receive and transmit side of approximately
     61           *  two microseconds.  The precise characterization is given below.
     62           *  (This data is not given in rev 1.03 datasheet)
     63           */
     64          #define RX_TX_PROP_DELAY_AVG_USEC         ((MAC_RADIO_RX_TX_PROP_DELAY_MIN_USEC + MAC_RADIO_RX_TX_PROP_DELAY_MAX_USEC) / 2)
     65          #define RX_TX_PROP_DELAY_AVG_TIMER_TICKS  ((uint16)(MAC_RADIO_TIMER_TICKS_PER_USEC() * RX_TX_PROP_DELAY_AVG_USEC + 0.5))
     66          
     67          /*
     68           *  For slotted receives, the SFD signal is expected to occur on a specifc symbol boundary.
     69           *  This does *not* correspond to the backoff boundary.  The SFD signal occurs at an
     70           *  offset from the backoff boundary.  This is done for efficiency of related algorithms.
     71           *
     72           *  Once transmit is strobed there is a fixed delay until the SFD signal occurs.  The frame
     73           *  does not start over-the-air transmit until after an internal radio delay of 12 symbols.
     74           *  Once transmitting over-the-air, the preamble is sent (8 symbols) followed by the
     75           *  SFD field (2 symbols). After the SFD field completes, the SFD signal occurs.  This
     76           *  adds up to a total of 22 symbols from strobe to SFD signal.
     77           *
     78           *  Since 22 symbols spans more than a backoff (20 symbols) the modulus operation is used
     79           *  to find the symbol offset which is 2 symbols.
     80           *
     81           *  This math is derived formally via the pre-processor.
     82           */
     83          #define SYMBOLS_FROM_STROBE_TO_PREAMBLE   12 /* from datasheet */
     84          #define SYMBOLS_FROM_PREAMBLE_TO_SFD      (MAC_SPEC_PREAMBLE_FIELD_LENGTH + MAC_SPEC_SFD_FIELD_LENGTH)
     85          #define SYMBOLS_FROM_STROBE_TO_SFD        (SYMBOLS_FROM_STROBE_TO_PREAMBLE + SYMBOLS_FROM_PREAMBLE_TO_SFD)
     86          #define SYMBOLS_EXPECTED_AT_SFD           (SYMBOLS_FROM_STROBE_TO_SFD % MAC_A_UNIT_BACKOFF_PERIOD)
     87          
     88          /* after all that formal math, make sure the result is as expected */
     89          #if (SYMBOLS_EXPECTED_AT_SFD != 2)
     90          #error "ERROR! Internal problem with pre-processor math of slotted alignment."
     91          #endif
     92          
     93          
     94          /*
     95           *  The expected SFD signal occurs at the symbol offset *plus* a small internal propagation delay
     96           *  internal to the radio.  This delay is given as the sum of a receive side delay and a transmit
     97           *  side delay.  When this delay is subtracted from the internal timer, the internal time base
     98           *  actually becomes the actual receive time *minus* the transmit delay.  This works out though.
     99           *  The transmit logic does *not* take into account this delay.  Since the timer is skewed by the
    100           *  transmit delay already, the transmits go out precisely on time.
    101           */
    102          #define TIMER_TICKS_EXPECTED_AT_SFD   ((SYMBOLS_EXPECTED_AT_SFD * MAC_RADIO_TIMER_TICKS_PER_SYMBOL()) \
    103                                                    + RX_TX_PROP_DELAY_AVG_TIMER_TICKS)
    104          
    105          
    106          /* ------------------------------------------------------------------------------------------------
    107           *                                         Local Variables
    108           * ------------------------------------------------------------------------------------------------
    109           */

   \                                 In segment XDATA_Z, align 1, keep-with-next
   \   000000                REQUIRE __INIT_XDATA_Z
    110          static uint32 backoffTimerRollover;
   \                     ??backoffTimerRollover:
   \   000000                DS 4

   \                                 In segment XDATA_Z, align 1, keep-with-next
   \   000000                REQUIRE __INIT_XDATA_Z
    111          static uint32 backoffTimerTrigger;
   \                     ??backoffTimerTrigger:
   \   000000                DS 4

   \                                 In segment XDATA_Z, align 1, keep-with-next
   \   000000                REQUIRE __INIT_XDATA_Z
    112          static uint8 compareState;
   \                     ??compareState:
   \   000000                DS 1
    113          
    114          
    115          /**************************************************************************************************
    116           * @fn          macBackoffTimerInit
    117           *
    118           * @brief       Intializes backoff timer.
    119           *
    120           * @param       none
    121           *
    122           * @return      none
    123           **************************************************************************************************
    124           */

   \                                 In segment BANKED_CODE, align 1, keep-with-next
    125          void macBackoffTimerInit(void)
   \                     macBackoffTimerInit:
    126          {
   \   000000   74F4         MOV     A,#-0xc
   \   000002   12....       LCALL   ?BANKED_ENTER_XDATA
   \   000005                ; Saved register size: 12
   \   000005                ; Auto size: 0
    127            compareState = COMPARE_STATE_ROLLOVER;
   \   000005   7401         MOV     A,#0x1
   \   000007   90....       MOV     DPTR,#??compareState
   \   00000A   F0           MOVX    @DPTR,A
    128            MAC_RADIO_BACKOFF_SET_COUNT(0);
   \   00000B                ; Setup parameters for call to function macMcuOverflowSetCount
   \   00000B   90....       MOV     DPTR,#__Constant_0
   \   00000E   78..         MOV     R0,#?V0 + 0
   \   000010   12....       LCALL   ?L_MOV_X
   \   000013   AA..         MOV     R2,?V0 + 0
   \   000015   AB..         MOV     R3,?V0 + 1
   \   000017   AC..         MOV     R4,?V0 + 2
   \   000019   AD..         MOV     R5,?V0 + 3
   \   00001B   90....       MOV     DPTR,#(macMcuOverflowSetCount & 0xffff)
   \   00001E   74..         MOV     A,#((macMcuOverflowSetCount >> 16) & 0xff)
   \   000020   12....       LCALL   ?BCALL               ; Banked call to: DPTR()
    129            macBackoffTimerSetRollover(MAC_BACKOFF_TIMER_DEFAULT_ROLLOVER);
   \   000023                ; Setup parameters for call to function macBackoffTimerSetRollover
   \   000023   90....       MOV     DPTR,#__Constant_c0000
   \   000026   78..         MOV     R0,#?V0 + 0
   \   000028   12....       LCALL   ?L_MOV_X
   \   00002B   AA..         MOV     R2,?V0 + 0
   \   00002D   AB..         MOV     R3,?V0 + 1
   \   00002F   AC..         MOV     R4,?V0 + 2
   \   000031   AD..         MOV     R5,?V0 + 3
   \   000033   90....       MOV     DPTR,#(macBackoffTimerSetRollover & 0xffff)
   \   000036   74..         MOV     A,#((macBackoffTimerSetRollover >> 16) & 0xff)
   \   000038   12....       LCALL   ?BCALL               ; Banked call to: DPTR()
    130            MAC_RADIO_BACKOFF_COMPARE_CLEAR_INTERRUPT();
   \   00003B   75C3C3       MOV     0xc3,#-0x3d
    131            MAC_RADIO_BACKOFF_COMPARE_ENABLE_INTERRUPT();
   \   00003E                ; Setup parameters for call to function macMcuOrT2PEROF2
   \   00003E   7920         MOV     R1,#0x20
   \   000040   90....       MOV     DPTR,#(macMcuOrT2PEROF2 & 0xffff)
   \   000043   74..         MOV     A,#((macMcuOrT2PEROF2 >> 16) & 0xff)
   \   000045   12....       LCALL   ?BCALL               ; Banked call to: DPTR()
    132          }
   \   000048   02....       LJMP    ?Subroutine1 & 0xFFFF

   \                                 In segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine1:
   \   000000   7F04         MOV     R7,#0x4
   \   000002   02....       LJMP    ?BANKED_LEAVE_XDATA
    133          
    134          
    135          /**************************************************************************************************
    136           * @fn          macBackoffTimerReset
    137           *
    138           * @brief       Resets backoff timer.
    139           *
    140           * @param       none
    141           *
    142           * @return      none
    143           **************************************************************************************************
    144           */

   \                                 In segment BANKED_CODE, align 1, keep-with-next
    145          void macBackoffTimerReset(void)
   \                     macBackoffTimerReset:
    146          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 0
    147            MAC_RADIO_BACKOFF_COMPARE_DISABLE_INTERRUPT();
   \   000004                ; Setup parameters for call to function macMcuAndT2PEROF2
   \   000004   79DF         MOV     R1,#-0x21
   \   000006   90....       MOV     DPTR,#(macMcuAndT2PEROF2 & 0xffff)
   \   000009   74..         MOV     A,#((macMcuAndT2PEROF2 >> 16) & 0xff)
   \   00000B   12....       LCALL   ?BCALL               ; Banked call to: DPTR()
    148            macBackoffTimerInit();
   \   00000E                ; Setup parameters for call to function macBackoffTimerInit
   \   00000E   90....       MOV     DPTR,#(macBackoffTimerInit & 0xffff)
   \   000011   74..         MOV     A,#((macBackoffTimerInit >> 16) & 0xff)
   \   000013   12....       LCALL   ?BCALL               ; Banked call to: DPTR()
    149          }
   \   000016   D083         POP     DPH
   \   000018   D082         POP     DPL
   \   00001A   02....       LJMP    ?BRET
    150          
    151          
    152          /**************************************************************************************************
    153           * @fn          macBackoffTimerSetRollover
    154           *
    155           * @brief       Set rollover count of backoff timer.
    156           *
    157           * @param       rolloverBackoff - backoff count where count is reset to zero
    158           *
    159           * @return      none
    160           **************************************************************************************************
    161           */

   \                                 In segment BANKED_CODE, align 1, keep-with-next
    162          void macBackoffTimerSetRollover(uint32 rolloverBackoff)
   \                     macBackoffTimerSetRollover:
    163          {
   \   000000   74F0         MOV     A,#-0x10
   \   000002   12....       LCALL   ?BANKED_ENTER_XDATA
   \   000005                ; Saved register size: 16
   \   000005                ; Auto size: 0
   \   000005   8A..         MOV     ?V0 + 0,R2
   \   000007   8B..         MOV     ?V0 + 1,R3
   \   000009   8C..         MOV     ?V0 + 2,R4
   \   00000B   8D..         MOV     ?V0 + 3,R5
    164            halIntState_t  s;
    165          
    166            MAC_ASSERT(rolloverBackoff > MAC_RADIO_BACKOFF_COUNT());  /* rollover value must be greater than count */
   \   00000D                ; Setup parameters for call to function macMcuOverflowCount
   \   00000D   90....       MOV     DPTR,#(macMcuOverflowCount & 0xffff)
   \   000010   74..         MOV     A,#((macMcuOverflowCount >> 16) & 0xff)
   \   000012   12....       LCALL   ?BCALL               ; Banked call to: DPTR()
   \   000015   8A..         MOV     ?V0 + 4,R2
   \   000017   8B..         MOV     ?V0 + 5,R3
   \   000019   8C..         MOV     ?V0 + 6,R4
   \   00001B   8D..         MOV     ?V0 + 7,R5
   \   00001D   78..         MOV     R0,#?V0 + 0
   \   00001F   79..         MOV     R1,#?V0 + 4
   \   000021   12....       LCALL   ?UL_GT
   \   000024   4008         JC      ??macBackoffTimerSetRollover_0
   \   000026                ; Setup parameters for call to function halAssertHandler
   \   000026   90....       MOV     DPTR,#(halAssertHandler & 0xffff)
   \   000029   74..         MOV     A,#((halAssertHandler >> 16) & 0xff)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?