⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mac_csp_tx.s51

📁 cc2430应用实例
💻 S51
📖 第 1 页 / 共 5 页
字号:
//  376   CSPX = macTxCsmaBackoffDelay;
        MOV	DPTR,#macTxCsmaBackoffDelay
        MOVX	A,@DPTR
        MOV	DPTR,#-0x20ee
        MOVX	@DPTR,A
//  377   if (CSPX != 0)
        MOVX	A,@DPTR
        JZ	??macCspTxGoCsma_0
//  378   {
//  379     CSPX--;
        MOVX	A,@DPTR
        DEC	A
        MOVX	@DPTR,A
//  380   }
//  381 
//  382   /*
//  383    *  Set WEVENT to trigger at the current value of the timer.  This allows
//  384    *  unslotted CSMA to transmit just a little bit sooner.
//  385    */
//  386   CSP_WEVENT_SET_TRIGGER_NOW();
??macCspTxGoCsma_0:
        MOV	A,0xa6
        MOV	0x94,0xa7
        MOV	A,0x94
        JNZ	??macCspTxGoCsma_1
        MOV	0x94,#0x1
//  387 
//  388   /*
//  389    *  Enable interrupt that fires when CSP program stops.
//  390    *  Also enable interrupt that fires when INT instruction
//  391    *  is executed.
//  392    */
//  393   MAC_MCU_CSP_STOP_ENABLE_INTERRUPT();
??macCspTxGoCsma_1:
        ; Setup parameters for call to function macMcuOrRFIM
        MOV	R1,#0x2
        MOV	DPTR,#(macMcuOrRFIM & 0xffff)
        MOV	A,#((macMcuOrRFIM >> 16) & 0xff)
        LCALL	?BCALL               ; Banked call to: DPTR()
//  394   MAC_MCU_CSP_INT_ENABLE_INTERRUPT();
        ; Setup parameters for call to function macMcuOrRFIM
        MOV	R1,#0x1
        MOV	A,#((macMcuOrRFIM >> 16) & 0xff)
        LCALL	?BCALL               ; Banked call to: DPTR()
//  395   
//  396   /*
//  397    *  Turn on the receiver if it is not already on.  Receiver must be 'on' for at
//  398    *  least one backoff before performing clear channel assessment (CCA).
//  399    */
//  400   macRxOn();
        ; Setup parameters for call to function macRxOn
        MOV	DPTR,#(macRxOn & 0xffff)
        MOV	A,#((macRxOn >> 16) & 0xff)
        LCALL	?BCALL               ; Banked call to: DPTR()
//  401 
//  402   /* start the CSP program */
//  403   CSP_START_PROGRAM();
        MOV	0xe1,#-0x2
//  404 }
        SJMP	??Subroutine0_1
        CFI EndBlock cfiBlock6

        RSEG BANKED_CODE:CODE:NOROOT(0)
?Subroutine0:
        CFI Block cfiBlock7 Using cfiCommon0
        CFI NoFunction
        CFI CFA_SP SP+-5
        CFI DPL0 Frame(CFA_SP, 4)
        CFI DPH0 Frame(CFA_SP, 5)
        MOV	0xe1,#0x20
        MOV	0xe1,#-0x21
        MOV	0xe1,#-0x40
??Subroutine0_0:
        MOV	0xe1,#-0x3d
        MOV	0xe1,#0x39
        MOV	0xe1,#0x1
        MOV	0xe1,#-0x42
        MOV	0xe1,#-0x40
        MOV	0xe1,#0x9
        MOV	0xe1,#-0x47
        MOV	0xe1,#0x1
        MOV	0xe1,#-0x41
??Subroutine0_1:
        POP	DPH
        CFI CFA_SP SP+-4
        CFI DPH0 SameValue
        POP	DPL
        CFI CFA_SP SP+-3
        CFI DPL0 SameValue
        LJMP	?BRET
        CFI EndBlock cfiBlock7
//  405 
//  406 
//  407 /**************************************************************************************************
//  408  * @fn          macCspTxPrepSlotted
//  409  *
//  410  * @brief       Prepare CSP for "Slotted" (non-CSMA) transmit.
//  411  *              Load CSP program and set CSP parameters.
//  412  *
//  413  * @param       none
//  414  *
//  415  * @return      none
//  416  **************************************************************************************************
//  417  */

        RSEG BANKED_CODE:CODE:NOROOT(0)
//  418 void macCspTxPrepSlotted(void)
macCspTxPrepSlotted:
        CFI Block cfiBlock8 Using cfiCommon0
        CFI Function macCspTxPrepSlotted
//  419 {
        FUNCALL macCspTxPrepSlotted, ??cspPrepForTxProgram
        LOCFRAME ISTACK, 2, STACK
        ARGFRAME ISTACK, 2, STACK
        PUSH	DPL
        CFI DPL0 Frame(CFA_SP, 4)
        CFI CFA_SP SP+-4
        PUSH	DPH
        CFI DPH0 Frame(CFA_SP, 5)
        CFI CFA_SP SP+-5
        ; Saved register size: 2
        ; Auto size: 0
//  420   cspPrepForTxProgram();
        ; Setup parameters for call to function cspPrepForTxProgram
        MOV	DPTR,#(??cspPrepForTxProgram & 0xffff)
        MOV	A,#((??cspPrepForTxProgram >> 16) & 0xff)
        LCALL	?BCALL               ; Banked call to: DPTR()
//  421 
//  422   /*----------------------------------------------------------------------
//  423    *  Load CSP program :  Slotted transmit (no CSMA)
//  424    */
//  425   
//  426   /* wait for X number of backoffs */
//  427   RFST = WAITX;
        MOV	0xe1,#-0x45
//  428 
//  429   /* just transmit, no CSMA required */
//  430   RFST = STXON;
        SJMP	??Subroutine0_0
        CFI EndBlock cfiBlock8
//  431 
//  432   /*
//  433    *  If the SFD pin is high at this point, there was an RX-TX collision.
//  434    *  In other words, TXON was strobed while receiving.  The CSP variable
//  435    *  CSPY is decremented to indicate this happened.  The rest of the transmit
//  436    *  continues normally.
//  437    */
//  438   RFST = SKIP(2+__SNOP_SKIP__, C_SFD_IS_INACTIVE);
//  439   RFST = WHILE(C_SFD_IS_ACTIVE);
//  440   RFST = DECY;
//  441   RFST = __SNOP__;
//  442   
//  443   /*
//  444    *  Watch the SFD pin to determine when the transmit has finished going out.
//  445    *  The INT instruction causes an interrupt to fire.  The ISR for this interrupt
//  446    *  handles the record the timestamp (which was just captured when SFD went high).
//  447    *  Decrement CSPZ at the last step to indicate transmit was successful.
//  448    */
//  449   RFST = WHILE(C_SFD_IS_INACTIVE);
//  450   RFST = INT;
//  451   RFST = WHILE(C_SFD_IS_ACTIVE);
//  452   RFST = DECZ;
//  453 }
//  454 
//  455 
//  456 /**************************************************************************************************
//  457  * @fn          macCspTxGoSlotted
//  458  *
//  459  * @brief       Run previously loaded CSP program for non-CSMA slotted transmit.   When CSP
//  460  *              program has finished, an interrupt occurs and macCspTxStopIsr() is called.
//  461  *              This ISR will in turn call macTxDoneCallback().
//  462  *
//  463  * @param       none
//  464  *
//  465  * @return      none
//  466  **************************************************************************************************
//  467  */

        RSEG BANKED_CODE:CODE:NOROOT(0)
//  468 void macCspTxGoSlotted(void)
macCspTxGoSlotted:
        CFI Block cfiBlock9 Using cfiCommon0
        CFI Function macCspTxGoSlotted
//  469 {
        FUNCALL macCspTxGoSlotted, macMcuOrRFIM
        LOCFRAME ISTACK, 2, STACK
        ARGFRAME ISTACK, 2, STACK
        FUNCALL macCspTxGoSlotted, macMcuOrRFIM
        LOCFRAME ISTACK, 2, STACK
        ARGFRAME ISTACK, 2, STACK
        PUSH	DPL
        CFI DPL0 Frame(CFA_SP, 4)
        CFI CFA_SP SP+-4
        PUSH	DPH
        CFI DPH0 Frame(CFA_SP, 5)
        CFI CFA_SP SP+-5
        ; Saved register size: 2
        ; Auto size: 0
//  470   halIntState_t  s;
//  471   uint8 lowByteOfBackoffCount;
//  472   uint8 backoffCountdown;
//  473   
//  474   /*
//  475    *  Enable interrupt that fires when CSP program stops.
//  476    *  Also enable interrupt that fires when INT instruction
//  477    *  is executed.
//  478    */
//  479   MAC_MCU_CSP_STOP_ENABLE_INTERRUPT();
        ; Setup parameters for call to function macMcuOrRFIM
        MOV	R1,#0x2
        MOV	DPTR,#(macMcuOrRFIM & 0xffff)
        MOV	A,#((macMcuOrRFIM >> 16) & 0xff)
        LCALL	?BCALL               ; Banked call to: DPTR()
//  480   MAC_MCU_CSP_INT_ENABLE_INTERRUPT();
        ; Setup parameters for call to function macMcuOrRFIM
        MOV	R1,#0x1
        MOV	A,#((macMcuOrRFIM >> 16) & 0xff)
        LCALL	?BCALL               ; Banked call to: DPTR()
//  481 
//  482   /* critical section needed for timer accesses */
//  483   HAL_ENTER_CRITICAL_SECTION(s);
        MOV	C,0xa8.7
        CLR	A
        MOV	0xE0 /* A   */.0,C
        MOV	R3,A
        CLR	0xa8.7
//  484 
//  485   /* store lowest byte of backoff count (same as lowest byte of overflow count) */
//  486   lowByteOfBackoffCount = T2OF0;
        MOV	A,0xa1
        MOV	R4,A
//  487 
//  488   /*
//  489    *  Compute the number of backoffs until time to strobe transmit.  The strobe should
//  490    *  occur one backoff before the SFD pin is expected to go high.  So, the forumla for the
//  491    *  countdown value is to determine when the lower bits would rollover and become zero,
//  492    *  and then subtract one.
//  493    */
//  494   backoffCountdown = SLOTTED_TX_MAX_BACKOFF_COUNTDOWN - (lowByteOfBackoffCount & SLOTTED_TX_BACKOFF_COUNT_ALIGN_BIT_MASK) - 1;
        MOV	A,#0xf
        ANL	A,R4
        MOV	R2,A
        MOV	A,#0xf
        CLR	C
        SUBB	A,R2
        MOV	R2,A
//  495   
//  496   /*
//  497    *  Store backoff countdown value into CSPX.
//  498    *
//  499    *  Note: it is OK if this value is zero.  The WAITX instruction at the top of the
//  500    *  CSP program will immediately continue if CSPX is zero when executed.  However,
//  501    *  if the countdown is zero, it means the transmit function was not called early
//  502    *  enough for a properly timed slotted transmit.  The transmit will be late.
//  503    */
//  504   CSPX = backoffCountdown;
        MOV	DPTR,#-0x20ee
        MOVX	@DPTR,A
//  505 
//  506   /*
//  507    *  The receiver will be turned on during CSP execution, guaranteed.
//  508    *  Since it is not possible to update C variables within the CSP,
//  509    *  the new "on" state of the receiver must be set a little early
//  510    *  here before the CSP is started.
//  511    */
//  512   MAC_RX_WAS_FORCED_ON();
        MOV	A,#0x1
        MOV	DPTR,#macRxOnFlag
        MOVX	@DPTR,A
//  513 
//  514   /* start the CSP program */
//  515   CSP_START_PROGRAM();
        MOV	0xe1,#-0x2
//  516   
//  517   /*
//  518    *  If the previous stored low byte of the backoff count is no longer equal to
//  519    *  the current value, a rollover has occurred.  This means the backoff countdown
//  520    *  stored in CSPX may not be correct.
//  521    *
//  522    *  In this case, the value of CSPX is reloaded to reflect the correct backoff
//  523    *  countdown value (this is one less than what was just used as a rollover has
//  524    *  occurred).  Since it is certain a rollover *just* occurred, there is no danger
//  525    *  of another rollover occurring.  This means the value written to CSPX is guaranteed
//  526    *  to be accurate.
//  527    *
//  528    *  Also, the logic below ensures that the value written to CSPX is at least one.
//  529    *  This is needed for correct operation of the WAITX instruction.  As with an
//  530    *  initial backoff countdown value of zero, if this case does occur, it means the
//  531    *  transmit function was not called early enough for a properly timed slotted transmit.
//  532    *  The transmit will be late.
//  533    *
//  534    *  Finally, worth noting, writes to CSPX may not work if the CSP is executing the WAITX
//  535    *  instruction and a timer rollover occurs.  In this case, however, there is no possibility
//  536    *  of that happening.  If CSPX is updated here, a rollover has just occurred so a
//  537    *  collision is not possible (still within a critical section here too).
//  538    */
//  539   if ((lowByteOfBackoffCount != T2OF0) && (backoffCountdown > 1))
        MOV	A,0xa1
        XRL	A,R4
        JZ	??macCspTxGoSlotted_0

⌨️ 快捷键说明

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