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

📄 setrxtxstate.c

📁 freescale的基于802.15.4的无线通讯例程
💻 C
📖 第 1 页 / 共 2 页
字号:
/************************************************************************************
* Implements SetTrxStateRequest Primitive.
*
* Author(s):
*   Thomas O. Jensen, Jesper Thomsen
*
* (c) Copyright 2004, Freescale, Inc.  All rights reserved.
*
* Freescale Confidential Proprietary
* Digianswer Confidential
*
* No part of this document must be reproduced in any form - including copied,
* transcribed, printed or by any electronic means - without specific written
* permission from Freescale.
*
* Last Inspected:
* Last Tested:
************************************************************************************/

#include "MacPhyGlobalHdr.h"
#include "Mc1319xDrv.h"
#include "IrqControlLib.h"
#include "phy.h"
#include "PhyMacMsg.h"
#include "MacPhy.h"

/************************************************************************************
*************************************************************************************
* Private macros
*************************************************************************************
************************************************************************************/

/************************************************************************************
*************************************************************************************
* Private prototypes
*************************************************************************************
************************************************************************************/
/************************************************************************************
*************************************************************************************
* Public type definitions
*************************************************************************************
************************************************************************************/
/************************************************************************************
*************************************************************************************
* Public memory declarations
*************************************************************************************
************************************************************************************/

/************************************************************************************
*************************************************************************************
* Private memory declarations
*************************************************************************************
************************************************************************************/
volatile bool_t mClockReadFlag;

/************************************************************************************
*************************************************************************************
* Public functions
*************************************************************************************
************************************************************************************/

void LowLevelReadClockSync(zbClock24_t *pRetClk)
{
  /* Must be called from a place protected against Abel interrupts. */
  MC1319xDrv_ReadSpiSync(ABEL_CURR_TIME_LSB_REG,  (uint16_t*)pRetClk); // HACK: Always clear latch if set by async call. 
  MC1319xDrv_ReadSpiSyncBurst(ABEL_CURR_TIME_MSB_REG, (uint16_t*)pRetClk);
  mClockReadFlag=TRUE;    // Set semaphore
}

void LowLevelReadClockAsync(zbClock24_t *pRetClk)
{
  /* May be called from anywhere. But is slower than the one above*/
  do{
    uint16_t* pRetClkTmp = (uint16_t*)pRetClk;              // Prevent unoptimal HCS08 code through local variable
    mClockReadFlag=FALSE;                                   // Clear semaphore 
    MC1319xDrv_ReadSpiAsyncBurst(ABEL_CURR_TIME_MSB_REG, pRetClkTmp);
  } while(mClockReadFlag);                                  // Check if sync clock read interrupted async read
}

void InitRxFastAction(void){
    // Init RxStream function pointer
  gIsrFastAction = IrqStreamingRxFirst;  
}

void InitRxPointers(void)
{
  // Init rx buffer pointer and index
  gpPhyPacketHead = gpPhyRxData->rxData;
  gPhyMacDataRxIndex = gRxDataIndexOffset_c;  // Do this to comply with structure index. If removed, update filter index values!!!!!!
}



/************************************************************************************
* Restart broken Rx sequence.
*
* Interface assumptions:
*
* THIS FUNCTION MAY ONLY BE CALLED FROM THE RXSTREAM INTERRUPT OR FROM macRxFilterProcess
*
*
* Return value:
*   NONE
*
* Revision history:
*
*    Date    Author    Comments
*   ------   ------    --------
*   071003   JT        Created
*
************************************************************************************/
void ReStartRx(void)
{
    // Setup Rx action immediately 
  mpfPendingSetup = SetupImmediateRx; 
  SetupPendingProtected(); // Not really pending at this point, but this saves code! (clears mpfPendingSetup)
  gIsrAsyncTailFunction = DummyFastIsr;

#ifdef I_AM_A_SNIFFER
  if (gpRxDataToBeSentOnHostInterface != NULL) GREEN_LED_TOGGLE; // We have not emptied the previous packets (mainloop to slow)
  if (gpPhyRxData == &gRxDataBuffer) {
    gpPhyRxData = &gRxDataBuffer2; // Sets the pointer to the other buffer, so that we can empty the first buffer from the mainloop
    gpRxDataToBeSentOnHostInterface = &gRxDataBuffer; 
  }
  else {
    gpPhyRxData = &gRxDataBuffer; // ...and the other way around
    gpRxDataToBeSentOnHostInterface = &gRxDataBuffer2;
  }
#endif /*I_AM_A_SNIFFER*/
  
  InitRxFastAction();
  InitRxPointers();

#if USE_INTERRUPT_RXEOF  // 
    // Clear MC1319x Status Register   
    // and handle if RxTimeouts occured just now
    // NOTE: This will only be necessary when using the EOF interrupt for Rx. 
    // NOTE: Removed when using GPIO1 polling because of known HW issue: 
    //       Reading the status register while interrupts occur eliminates the interrupt
  {
    uint16_t retReg;
    MC1319xDrv_ReadSpiAsync(ABEL_reg24, &retReg);  // Clears all pending MC1319x interrupt 
    IrqControlLib_AckMC1319xIrq();                // Ack irqs in mcu if any latched
    if (retReg & cTMR4_IRQ) RxTimeout();          // If timeout occured just now act accordingly
  }
#else
    // HACK: When Using GPIO polling it has been observed that an Rx Stream Irq has occurred in rare circumstances on CRC invalid
    // To ensure this is always cleared perform a dummy read of the data register
  {
    uint16_t dummy; 
    MC1319xDrv_ReadSpiSync(RX_DATA, &dummy); // Read rx data register to clear RxStream irq 
    IrqControlLib_AckMC1319xIrq();          // Ack irq (clears latch in mcu if any)
  }

#endif // USE_INTERRUPT_RXEOF
 
  RXFILTER_PROFILING_CLRPIN_1;
}


/************************************************************************************
* Set event trigger. Used for timed actions.
*
* Interface assumptions:
*
*
* Return value:
*   NONE
*
* Revision history:
*
*    Date    Author    Comments
*   ------   ------    --------
*   170903   TOJ,JT    Created
*
************************************************************************************/
void PhySyncSetEventTrigger(zbClock16_t startTime)
{
  startTime = startTime - gAbelWarmupTimeSym_c;
  MC1319xDrv_WriteSpiSync(ABEL_TMR2_PRIME_REG, startTime); // Set new T2' timer trigger
}

/************************************************************************************
* Set event timeout. Used for timed actions.
*
* Interface assumptions:
*
*
* Return value:
*   NONE
*
* Revision history:
*
*    Date    Author    Comments
*   ------   ------    --------
*   170903   TOJ,JT    Created
*
************************************************************************************/
void PhySyncSetEventTimeout(zbClock24_t* pEndTime )
{ 
  MC1319xDrv_WriteSpiSyncBurst(ABEL_TMR4_HI_REG, (uint16_t*)pEndTime); // Set new TC4 timeout. This will arm the timeout!
}

/************************************************************************************
* Kill event timeout
*
* Interface assumptions:
*
*
* Return value:
*   NONE
*
* Revision history:
*
*    Date    Author    Comments
*   ------   ------    --------
*   170903   TOJ,JT    Created
*
************************************************************************************/
void DisableEventTimeout(void)
{
    // Disabling the timer prevents future interrupts, and clears pending interrupts in Abel.
    // Both the irq level pin and reg 0x24 (bit3) are cleared
    // In case a pending timer interrupt is cleared we must remember to "ack" the irq in the MCU 
  MC1319xDrv_WriteSpiAsync(ABEL_TMR4_HI_REG, 0x8000);
  IrqControlLib_AckMC1319xIrq();
}

//-----------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------
// Correlation threshold commands
//-----------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------

#ifndef DO_NOT_TOGGLE_SYNCH_THRESHOLD
// HACK: Set threshold to normal for Rx
void SetCorrThresholdNormal(){
  MC1319xDrv_WriteSpiSync(ABEL_reg38, 0x0008); // Set correlation threshold to normal value
}

// HACK: CCA-Rx issue. Set threshold to max value for Ed and Cca to prevent correlation
void SetCorrThresholdHigh(){
  MC1319xDrv_WriteSpiSync(ABEL_reg38, 0x03FF); // Set correlation threshold to high value
}
#else //DO_NOT_TOGGLE_SYNCH_THRESHOLD

⌨️ 快捷键说明

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