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

📄 mac_rx_engine.c

📁 ucos在NEC平台下的移植
💻 C
📖 第 1 页 / 共 5 页
字号:
            msupSetChannel(pMDI->pMsdu[5], TRUE);
    
            // For orphan responses, with extended destination address, update the short address from the realignment frame
            if (pMDI->dstAddrMode == AM_EXTENDED_64) {
                mlmeSetRequest(MAC_SHORT_ADDRESS, (WORD*) &pMDI->pMsdu[6]);
                macSetState(MAC_STATE_ORPHAN_REALIGNED);
            }
            
            // Clean up before making the call to the higher layer
            cleanUpAfterSwitch = FALSE;
            mschRemoveTask(pTask->priority, 0);
            mrxpReleasePacket(pPacket);
    
            // Indicate realignment to higher layer
            mlmeSyncLossIndication(REALIGNMENT);
        }
        break;

#if MAC_OPT_FFD
    case CMD_ORPHAN_NOTIFICATION:
        // Must have source addressing mode 3 and destination addressing mode 2
        if ((pMDI->srcAddrMode == AM_EXTENDED_64) && (pMDI->dstAddrMode == AM_SHORT_16)) {
    
            // Must have broadcast source and destination PAN
            if ((pMDI->srcPanId == 0xFFFF) && (pMDI->dstPanId == 0xFFFF)) {
                
                // Clean up before making the call to the higher layer
                cleanUpAfterSwitch = FALSE;
                mschRemoveTask(pTask->priority, 0);
                mlmeOrphanIndication(pMDI->srcAddr.Extended, pMDI->securityUse, pMDI->aclEntry);
                mrxpReleasePacket(pPacket);
            }
        }
        break;
#endif
        
#if MAC_OPT_FFD
    case CMD_PAN_ID_CONFLICT_NOTIFICATION:
        // The PAN Coordinator has received a PAN ID conflict notification command from a device on its own PAN
        if ((GET_MF(MF_PAN_COORDINATOR)) && (pMDI->srcPanId == mpib.macPANId)) {

            // Clean up before making the call to the higher layer
            cleanUpAfterSwitch = FALSE;
            mschRemoveTask(pTask->priority, 0);
            mrxpReleasePacket(pPacket);
            mlmeSyncLossIndication(PAN_ID_CONFLICT);
        }
        break;
#endif
        
    default:
        break;
    }

    // Clean up (used when there are no calls to the upper layer
    if (cleanUpAfterSwitch) {
        mschRemoveTask(pTask->priority, MSCH_KEEP_TASK_IN_PROGRESS_BM);
        mrxpReleasePacket(pPacket);
    }
    
} // mrxProcessMacCommand




//-------------------------------------------------------------------------------------------------------
//  void mrxCommStatusIndication(MAC_TASK_INFO *pTask)
//
//  DESCRIPTION:
//      This task is responsible for generating mlme-comm-status.indication upon security failures.
//
//  TASK DATA:
//      A pointer to the MAC_RX_PACKET to be processed
//-------------------------------------------------------------------------------------------------------
void mrxCommStatusIndication(MAC_TASK_INFO *pTask) {
    MAC_RX_PACKET *pPacket = (MAC_RX_PACKET*) pTask->taskData;
    MCPS_DATA_INDICATION *pMDI = &pPacket->mdi;

    ENABLE_FIFOP_INT();

    mlmeCommStatusIndication(pMDI->srcPanId, pMDI->srcAddrMode, &pMDI->srcAddr, pMDI->dstAddrMode, &pMDI->dstAddr, pPacket->securityStatus);

    mschRemoveTask(pTask->priority, 0);
    mrxpReleasePacket(pPacket);
} //mrxCommStatusIndication




//-------------------------------------------------------------------------------------------------------
//  void mrxHandleFifoUnderAndOverflow(void)
//
//  DESCRIPTION:
//      Flushes the RX FIFO if an overflow has occurred (FIFOP and FIFO are both low, when the polarity 
//      of FIFOP has been switched). This function is called by the reception routine in the final stage.
//-------------------------------------------------------------------------------------------------------
void mrxHandleFifoUnderAndOverflow(void) {
    if (CC2420_RXFIFO_OVERFLOW() || mrxInfo.handleFifoUnderflow) {
        DISABLE_GLOBAL_INT();
        FASTSPI_STROBE(CC2420_SFLUSHRX);
        FASTSPI_STROBE(CC2420_SFLUSHRX); // Flush 
        ENABLE_GLOBAL_INT();
    }
} // mrxHandleFifoUnderAndOverflow




//-------------------------------------------------------------------------------------------------------
//  void mrxSetFifopThreshold(UINT8 count)
//
//  DESCRIPTION:
//      Adjusts the FIFOP threshold so that when the FIFOP pin changes when the number of bytes in the RX
//      FIFO exceeds "count".
//
//  ARGUMENTS:
//      UINT8 count
//          The new FIFOP threshold
//-------------------------------------------------------------------------------------------------------
void mrxSetFifopThreshold(UINT8 count) {
    WORD regValue;
    
    // Invert the FIFOP pin
    regValue = 0x0200;
    
    // Set the BCN_ACCEPT bit during active and passive scan
    if (macInfo.state == MAC_STATE_ACTIVE_OR_PASSIVE_SCAN) regValue |= 0x0800;
    
    // Add the byte count
    regValue |= count;
    
    DISABLE_GLOBAL_INT();
    FASTSPI_SETREG(CC2420_IOCFG0, regValue);
    ENABLE_GLOBAL_INT();
    
} // mrxSetFifopThreshold




//-------------------------------------------------------------------------------------------------------
//  SIGNAL(SIG_INTERRUPT0)
//
//  DESCRIPTION:
//      FIFOP interrupt:
//      This interrupt is triggered when the number of bytes in the CC2420 RX FIFO exceeds a configurable
//      threshold (IOCFG0.FIFOP_THRESHOLD). The callback timer is disabled during the execution of this 
//      interrupt. To avoid a long burst of FIFOP interrupts, the interrupt uses timer 1 to turn it back 
//      on a short while after it has returned. It will thereby allow for callbacks and task execution in 
//      between.
//-------------------------------------------------------------------------------------------------------
///SIGNAL(SIG_INTERRUPT0) {
///ISR(INT0_vect){
__interrupt void MD_INTP1() {

///__interrupt void INTP1() {

MAC_RX_PACKET *pPacket =0;///
MCPS_DATA_INDICATION *pMDI=0;///
   ///INT8 length_temp;///

    BYTE reservedTask;
    BYTE dstAddrMode;
    BYTE srcAddrMode;
    BYTE nextState;
    BYTE readLength;
    UINT16 timer1compC;
    BOOL createProcessTask;
    void *pProcessTask;
    WORD processTaskData;

///UART_StartTx("\r\n1\r\n>");   ///
	///DISABLE_GLOBAL_INT();///
	///CLEAR_FIFOP_MASK();///






#if ((MAC_OPT_SECURITY) || (MAC_OPT_ACL_SIZE>0))
    BYTE n;
    BOOL aclEntryFound;
#endif

    //Disable compc on timer 1 so we prevent double fifop interupts.

   //// DISABLE_T3_COMPC_INT();///
    ///DISABLE_T1_COMPC_INT();////
    DISABLE_TIMER51_INT();///!!!!
	
    // Copy the pointer for fast access
    
    ///MAC_RX_PACKET *pPacket = mrxInfo.pMrxPacket;
    ///MCPS_DATA_INDICATION *pMDI = &pPacket->mdi;
    pPacket = mrxInfo.pMrxPacket;///
	pMDI = &pPacket->mdi;///
    
    // Turn off the main MAC interrupts
    DISABLE_FIFOP_INT();
    ///DISABLE_T1_COMPA_INT();
	    DISABLE_T3_COMPA_INT();///

///test++;///

array1[INTP]=COMA;///
INTP++;///

    ENABLE_GLOBAL_INT();

    switch (mrxInfo.state) {
    case MRX_STATE_LEN_FCF_SEQ:
        
        // Reserve task
        reservedTask = mschReserveTask();
        
        // Keep RX on while receiving
        mrxAutoIncrOnCounter();

        if ((macInfo.state != MAC_STATE_ENERGY_SCAN) && (reservedTask != NO_TASK)) {
            mrxInfo.taskNumber = reservedTask;

            // Reserve packet
            pPacket = mrxpReservePacket();
            if (pPacket) {
                mrxInfo.pMrxPacket = pPacket;
                pMDI = &pPacket->mdi;

                // By default, report that the received packet is not found in ACL
                // This value may be overridden at a later stage
                pMDI->aclEntry = 0x08;

                // By default, report successful securityStatus
                pPacket->securityStatus = SUCCESS;

                // Read the packet length, the frame control field and the sequence number
                msupReadFifo((BYTE*)&mrxInfo.length, 4);///
                mrxInfo.length &= 0x7F;
#if MAC_OPT_SECURITY
                // Store the unmodified PSDU length, later to be used
                // for security purposes
                mrxSecurityInfo.securitySetup.clearTextLength = mrxInfo.length;
#endif
                mrxInfo.length -= 5; // 3 for FCF and SN + 2 for FCS
                
                // Get the time stamp (do it now to make sure that it is not overwritten by the acknowledgment)
                DISABLE_GLOBAL_INT();
                pPacket->timeStamp = mtimInfo.captureTime >> 4;
                ENABLE_GLOBAL_INT();

                // Set default security values
                if ((BYTE) mrxInfo.frameControlField & SECURITY_ENABLED_BM) {
                    pMDI->securityUse = TRUE;
                } else {
                    pMDI->securityUse = FALSE;
                }
                
                // Set default MSDU length
                pMDI->msduLength = 0;

                // This packet will be acknowledged if the ack request bit is set
                pPacket->flags &= ~MRXP_FLAG_SACKPEND_ISSUED_BM;
                if ((BYTE) mrxInfo.frameControlField & ACK_REQ_BM) {
                    
                    // Acknowledge with the pending flag set if there is at least one packet in the pending queue
                    DISABLE_GLOBAL_INT();
#if MAC_OPT_FFD
                    
                    if ((SFD_IS_ACTIVE()) && ((mscInfo.scanStatus == MSC_STATUS_FINISHED) || (mscInfo.scanStatus == MSC_STATUS_ORPHAN_REALIGNED) || (mscInfo.scanType == ORPHAN_SCAN))){  

#if MAC_OPT_TRANSMIT_POWER 
                        msupSetTransmitPower();//If changed set the transmit power
#endif            
                        if (miqInfo.firstIndirectPacket != NO_PACKET) {
                            FASTSPI_STROBE(CC2420_SACKPEND);
                            pPacket->flags |= MRXP_FLAG_SACKPEND_ISSUED_BM;
                        } else {
                            FASTSPI_STROBE(CC2420_SACK);
                        }
                    }
#else
                    if ((SFD_IS_ACTIVE()) && ((mscInfo.scanStatus == MSC_STATUS_FINISHED) || (mscInfo.scanStatus == MSC_STATUS_ORPHAN_REALIGNED) || (mscInfo.scanType == ORPHAN_SCAN))){ 
                        FASTSPI_STROBE(CC2420_SACK);
                    }
#endif
                    ENABLE_GLOBAL_INT();
                }
                

                // Set the destination address mode and length (of the fields)
                dstAddrMode = BF(mrxInfo.frameControlField, DEST_ADDR_MODE_BM, DEST_ADDR_MODE_IDX);
                pMDI->dstAddrMode = dstAddrMode;
                if (dstAddrMode) {
                    switch (dstAddrMode) {
                    case AM_SHORT_16:    mrxInfo.rd.a.dstAddrLength = 4;  break;///
                    case AM_EXTENDED_64: mrxInfo.rd.a.dstAddrLength = 10; break;///
                    }
                    mrxInfo.rd.a.pDstAddrStoragePtr = (BYTE*) &pMDI->dstPanId;///
                } else {
                    mrxInfo.rd.a.dstAddrLength = 0;///
                }

                // Set the source address mode and length (of the fields)
                srcAddrMode = BF(mrxInfo.frameControlField, SRC_ADDR_MODE_BM, SRC_ADDR_MODE_IDX);
                pMDI->srcAddrMode = srcAddrMode;
                if (srcAddrMode) {
                    switch (srcAddrMode) {
                    case AM_SHORT_16:    mrxInfo.rd.a.srcAddrLength = 4;  break;///
                    case AM_EXTENDED_64: mrxInfo.rd.a.srcAddrLength = 10; break;///
                    }
                    mrxInfo.rd.a.pSrcAddrStoragePtr = (BYTE*) &pMDI->srcPanId;///
                    if (mrxInfo.frameControlField & INTRA_PAN_BM) {
                        mrxInfo.rd.a.srcAddrLength -= 2;///
                        mrxInfo.rd.a.pSrcAddrStoragePtr += 2;///
                    }
                } else {
                    mrxInfo.rd.a.srcAddrLength = 0;///
                }

                // Set the next state
                if ((mrxInfo.rd.a.dstAddrLength + mrxInfo.rd.a.srcAddrLength) > mrxInfo.length) {///
                    nextState = MRX_STATE_DISCARD_REMAINING;
                    if (mrxInfo.length < 2) mrxSetFifopThreshold(mrxInfo.length + 1);                        

⌨️ 快捷键说明

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