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

📄 phy.c

📁 802.15.4协议的物理层和mac层的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
  }

  async event result_t HPLCC2420RAM.writeDone(uint16_t addr, uint8_t length, uint8_t* buffer) {
     return SUCCESS;
  }
  
 async event result_t HPLCC2420FIFO.RXFIFODone(uint8_t length, uint8_t *data) {
    

    return SUCCESS;     
  }

  async event result_t HPLCC2420FIFO.TXFIFODone(uint8_t length, uint8_t *data) { 
   
     return SUCCESS;
  }
  
  
/*****************************************************************************************************/  
/*******************OTHER FUNCTIONS******************/
/*****************************************************************************************************/ 
  
  
  
  
  
     /************************************************************************
   * SetRegs
   *  - Configure CC2420 registers with current values
   *  - Readback 1st register written to make sure electrical connection OK
   *************************************************************************/
  bool SetRegs(){
    uint16_t data;
	      
    call HPLCC2420.write(CC2420_MAIN,gCurrentParameters[CP_MAIN]);   		    
    call HPLCC2420.write(CC2420_MDMCTRL0, gCurrentParameters[CP_MDMCTRL0]);
    data = call HPLCC2420.read(CC2420_MDMCTRL0);
    if (data != gCurrentParameters[CP_MDMCTRL0]) return FALSE;
    
    call HPLCC2420.write(CC2420_MDMCTRL1, gCurrentParameters[CP_MDMCTRL1]);
    call HPLCC2420.write(CC2420_RSSI, gCurrentParameters[CP_RSSI]);
    call HPLCC2420.write(CC2420_SYNCWORD, gCurrentParameters[CP_SYNCWORD]);
    call HPLCC2420.write(CC2420_TXCTRL, gCurrentParameters[CP_TXCTRL]);
    call HPLCC2420.write(CC2420_RXCTRL0, gCurrentParameters[CP_RXCTRL0]);
    call HPLCC2420.write(CC2420_RXCTRL1, gCurrentParameters[CP_RXCTRL1]);
    call HPLCC2420.write(CC2420_FSCTRL, gCurrentParameters[CP_FSCTRL]);

    call HPLCC2420.write(CC2420_SECCTRL0, gCurrentParameters[CP_SECCTRL0]);
    call HPLCC2420.write(CC2420_SECCTRL1, gCurrentParameters[CP_SECCTRL1]);
    call HPLCC2420.write(CC2420_IOCFG0, gCurrentParameters[CP_IOCFG0]);
    call HPLCC2420.write(CC2420_IOCFG1, gCurrentParameters[CP_IOCFG1]);

    call HPLCC2420.cmd(CC2420_SFLUSHTX);    //flush Tx fifo
    call HPLCC2420.cmd(CC2420_SFLUSHRX);
 
    return TRUE;
  
  }
/*
bool default_CC2420_registers(){
    //uint16_t data;
	      
    call HPLCC2420.write(CC2420_MAIN,0xF800);   		    
    call HPLCC2420.write(CC2420_MDMCTRL0,0x1AE2);
    //data = call HPLCC2420.read(CC2420_MDMCTRL0);
    //if (data != gCurrentParameters[CP_MDMCTRL0]) return FALSE;
    
    call HPLCC2420.write(CC2420_MDMCTRL1, 0x0500);
    call HPLCC2420.write(CC2420_RSSI, 0xE000);
    call HPLCC2420.write(CC2420_SYNCWORD, 0xA70F);
    call HPLCC2420.write(CC2420_TXCTRL, 0xA0FF);
    call HPLCC2420.write(CC2420_RXCTRL0, 0x12E5);
    call HPLCC2420.write(CC2420_RXCTRL1, 0x0A56);
    call HPLCC2420.write(CC2420_FSCTRL, 0x4165);

    call HPLCC2420.write(CC2420_SECCTRL0, 0x03C4);
    call HPLCC2420.write(CC2420_SECCTRL1, 0x0000);
    call HPLCC2420.write(CC2420_IOCFG0, 0x0040);
    call HPLCC2420.write(CC2420_IOCFG1, 0x0000);

    call HPLCC2420.cmd(CC2420_SFLUSHTX);    //flush Tx fifo
    call HPLCC2420.cmd(CC2420_SFLUSHRX);
 
    return TRUE;
  
  }
 */ 
    /*************************************************************************
   * GetRFPower
   * return power seeting
   *************************************************************************/
  uint8_t GetRFPower() {
    return (gCurrentParameters[CP_TXCTRL] & 0x000f); //rfpower;
  }
  
    /*************************************************************************
   * SetRFPower
   * power = 31 => full power    (0dbm)
   *          3 => lowest power  (-25dbm)
   * return SUCCESS if the radio power was successfully set
   *************************************************************************/
result_t SetRFPower(uint8_t power) {
    gCurrentParameters[CP_TXCTRL] = (gCurrentParameters[CP_FSCTRL] & 0xfff0) | (power << CC2420_TXCTRL_PAPWR);
    call HPLCC2420.write(CC2420_TXCTRL,gCurrentParameters[CP_TXCTRL]);
    return SUCCESS;
  }

  /**
   * Turns on the 1.8V references on the CC2420.
   *
   * @return SUCCESS if the VREF has been turned on
   */
   
result_t VREFOn(){
    TOSH_SET_CC_VREN_PIN();                    //turn-on  
    TOSH_uwait(600);  // CC2420 spec: 600us max turn on time
return SUCCESS;
}

  /**
   * Turns off the 1.8V references on the CC2420.
   *
   * @return SUCCESS if the VREF has been turned on
   */
   
result_t VREFOff(){
    TOSH_CLR_CC_VREN_PIN();                    //turn-off  
    return SUCCESS;

}

 /*************************************************************************
   * TunePreset
   * -Set CC2420 channel
   * Valid channel values are 11 through 26.
   * The channels are calculated by:
   *  Freq = 2405 + 5(k-11) MHz for k = 11,12,...,26
   * chnl requested 802.15.4 channel 
   * return Status of the tune operation
   *************************************************************************/
   /*
result_t TunePreset(uint8_t chnl) {
    int fsctrl;
    
    fsctrl = 357 + 5*(chnl-11);
    gCurrentParameters[CP_FSCTRL] = (gCurrentParameters[CP_FSCTRL] & 0xfc00) | (fsctrl << CC2420_FSCTRL_FREQ);
    call HPLCC2420.write(CC2420_FSCTRL, gCurrentParameters[CP_FSCTRL]);
    return SUCCESS;
  }
  */
  
result_t TunePreset(uint8_t chnl) {
    int fsctrl;
    uint8_t status2;
    
    fsctrl = 357 + 5*(chnl-11);
    gCurrentParameters[CP_FSCTRL] = (gCurrentParameters[CP_FSCTRL] & 0xfc00) | (fsctrl << CC2420_FSCTRL_FREQ);
    status2 = call HPLCC2420.write(CC2420_FSCTRL, gCurrentParameters[CP_FSCTRL]);
    // if the oscillator is started, recalibrate for the new frequency
    // if the oscillator is NOT on, we should not transition to RX mode
    if (status2 & (1 << CC2420_XOSC16M_STABLE))
      call HPLCC2420.cmd(CC2420_SRXON);
    return SUCCESS;
  }

  /*************************************************************************
   * TuneManual
   * Tune the radio to a given frequency. Frequencies may be set in
   * 1 MHz steps between 2400 MHz and 2483 MHz
   * 
   * Desiredfreq The desired frequency, in MHz.
   * Return Status of the tune operation
   *************************************************************************/
   
result_t TuneManual(uint16_t DesiredFreq) {
   int fsctrl;
   uint8_t status2;
   fsctrl = DesiredFreq - 2048;
   gCurrentParameters[CP_FSCTRL] = (gCurrentParameters[CP_FSCTRL] & 0xfc00) | (fsctrl << CC2420_FSCTRL_FREQ);
   status2 =call HPLCC2420.write(CC2420_FSCTRL, gCurrentParameters[CP_FSCTRL]);
   if (status2 & (1 << CC2420_XOSC16M_STABLE))
      call HPLCC2420.cmd(CC2420_SRXON);
   return SUCCESS;
  }
  
  
result_t setShortAddress(uint16_t addr) {
    addr = toLSB16(addr);
    return call HPLCC2420RAM.write(CC2420_RAM_SHORTADR, 2, (uint8_t*)&addr);
  }
  
  
    void enableFIFOP(){
    atomic {
	      call FIFOP.startWait(FALSE);
      // enable start of frame delimiter timer capture (timestamping)
			call SFD.enableCapture(TRUE);
	
	/*
      call FIFOP.disable();
      call FIFOP.clear();
      call FIFOP.edge(0);
      call FIFOP.enable();
	  */
    }
    return;
  }
  
   /*********************************************************
   * function: disbleFIFOP
   *  disable CC2420 fifop interrupt
   ********************************************************/
  void disableFIFOP(){
    atomic {
      call FIFOP.disable();
      //call FIFOP.clear();
    }
    return;
  }
  
  
  
    /**
   * Captured an edge transition on the SFD pin
   * Useful for time synchronization as well as determining
   * when a packet has finished transmission
   */
  async event result_t SFD.captured(uint16_t time) {
      return SUCCESS;
  }
}

⌨️ 快捷键说明

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