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

📄 cc2420controlm.nc

📁 Zigbee的nesc源码
💻 NC
📖 第 1 页 / 共 2 页
字号:
    result_t status;    uint8_t _state = FALSE;    atomic {      if (state == INIT_STATE_DONE) {	state = START_STATE;	_state = TRUE;      }    }    if (!_state)      return FAIL;    call HPLChipconControl.start();    //turn on power    call CC2420Control.VREFOn();    // toggle reset    TOSH_CLR_CC_RSTN_PIN();    TOSH_wait();    TOSH_SET_CC_RSTN_PIN();    TOSH_wait();    // turn on crystal, takes about 860 usec,     // chk CC2420 status reg for stablize    status = call CC2420Control.OscillatorOn();    return status;  }  /*************************************************************************   * 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   *************************************************************************/  command result_t CC2420Control.TunePreset(uint8_t chnl) {    int fsctrl;    uint8_t status;        fsctrl = 357 + 5*(chnl-11);    gCurrentParameters[CP_FSCTRL] = (gCurrentParameters[CP_FSCTRL] & 0xfc00) | (fsctrl << CC2420_FSCTRL_FREQ);    status = call HPLChipcon.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 (status & (1 << CC2420_XOSC16M_STABLE))      call HPLChipcon.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   *************************************************************************/  command result_t CC2420Control.TuneManual(uint16_t DesiredFreq) {    int fsctrl;    uint8_t status;       fsctrl = DesiredFreq - 2048;    gCurrentParameters[CP_FSCTRL] = (gCurrentParameters[CP_FSCTRL] & 0xfc00) | (fsctrl << CC2420_FSCTRL_FREQ);    status = call HPLChipcon.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 (status & (1 << CC2420_XOSC16M_STABLE))      call HPLChipcon.cmd(CC2420_SRXON);    return SUCCESS;  }  /*************************************************************************   * Get the current frequency of the radio   */  command uint16_t CC2420Control.GetFrequency() {    return ((gCurrentParameters[CP_FSCTRL] & (0x1FF << CC2420_FSCTRL_FREQ))+2048);  }  /*************************************************************************   * Get the current channel of the radio   */  command uint8_t CC2420Control.GetPreset() {    uint16_t _freq = (gCurrentParameters[CP_FSCTRL] & (0x1FF << CC2420_FSCTRL_FREQ));    _freq = (_freq - 357)/5;    _freq = _freq + 11;    return _freq;  }  /*************************************************************************   * TxMode   * Shift the CC2420 Radio into transmit mode.   * return SUCCESS if the radio was successfully switched to TX mode.   *************************************************************************/  async command result_t CC2420Control.TxMode() {    call HPLChipcon.cmd(CC2420_STXON);    return SUCCESS;  }  /*************************************************************************   * TxModeOnCCA   * Shift the CC2420 Radio into transmit mode when the next clear channel   * is detected.   *   * return SUCCESS if the transmit request has been accepted   *************************************************************************/  async command result_t CC2420Control.TxModeOnCCA() {   call HPLChipcon.cmd(CC2420_STXONCCA);   return SUCCESS;  }  /*************************************************************************   * RxMode   * Shift the CC2420 Radio into receive mode    *************************************************************************/  async command result_t CC2420Control.RxMode() {    call HPLChipcon.cmd(CC2420_SRXON);    return SUCCESS;  }  /*************************************************************************   * SetRFPower   * power = 31 => full power    (0dbm)   *          3 => lowest power  (-25dbm)   * return SUCCESS if the radio power was successfully set   *************************************************************************/  command result_t CC2420Control.SetRFPower(uint8_t power) {    gCurrentParameters[CP_TXCTRL] = (gCurrentParameters[CP_TXCTRL] & (~CC2420_TXCTRL_PAPWR_MASK)) | (power << CC2420_TXCTRL_PAPWR);    call HPLChipcon.write(CC2420_TXCTRL,gCurrentParameters[CP_TXCTRL]);    return SUCCESS;  }  /*************************************************************************   * GetRFPower   * return power seeting   *************************************************************************/  command uint8_t CC2420Control.GetRFPower() {    return (gCurrentParameters[CP_TXCTRL] & CC2420_TXCTRL_PAPWR_MASK); //rfpower;  }  async command result_t CC2420Control.OscillatorOn() {    uint16_t i;    uint8_t status;    i = 0;    // uncomment to measure the startup time from     // high to low to high transitions    // output "1" on the CCA pin#ifdef CC2420_MEASURE_OSCILLATOR_STARTUP      call HPLChipcon.write(CC2420_IOCFG1, 31);      // output oscillator stable on CCA pin      // error in CC2420 datasheet 1.2: SFDMUX and CCAMUX incorrectly labelled      TOSH_uwait(50);#endif    call HPLChipcon.write(CC2420_IOCFG1, 24);    // have an event/interrupt triggered when it starts up    call CCA.startWait(TRUE);        // start the oscillator    status = call HPLChipcon.cmd(CC2420_SXOSCON);   //turn-on crystal    return SUCCESS;  }  async command result_t CC2420Control.OscillatorOff() {    call HPLChipcon.cmd(CC2420_SXOSCOFF);   //turn-off crystal    return SUCCESS;  }  async command result_t CC2420Control.VREFOn(){    TOSH_SET_CC_VREN_PIN();                    //turn-on      // TODO: JP: measure the actual time for VREF to stabilize    TOSH_uwait(600);  // CC2420 spec: 600us max turn on time    return SUCCESS;  }  async command result_t CC2420Control.VREFOff(){    TOSH_CLR_CC_VREN_PIN();                    //turn-off      return SUCCESS;  }  async command result_t CC2420Control.enableAutoAck() {    gCurrentParameters[CP_MDMCTRL0] |= (1 << CC2420_MDMCTRL0_AUTOACK);    return call HPLChipcon.write(CC2420_MDMCTRL0,gCurrentParameters[CP_MDMCTRL0]);  }  async command result_t CC2420Control.disableAutoAck() {    gCurrentParameters[CP_MDMCTRL0] &= ~(1 << CC2420_MDMCTRL0_AUTOACK);    return call HPLChipcon.write(CC2420_MDMCTRL0,gCurrentParameters[CP_MDMCTRL0]);  }  async command result_t CC2420Control.enableAddrDecode() {    gCurrentParameters[CP_MDMCTRL0] |= (1 << CC2420_MDMCTRL0_ADRDECODE);    return call HPLChipcon.write(CC2420_MDMCTRL0,gCurrentParameters[CP_MDMCTRL0]);  }  async command result_t CC2420Control.disableAddrDecode() {    gCurrentParameters[CP_MDMCTRL0] &= ~(1 << CC2420_MDMCTRL0_ADRDECODE);    return call HPLChipcon.write(CC2420_MDMCTRL0,gCurrentParameters[CP_MDMCTRL0]);  }  command result_t CC2420Control.setShortAddress(uint16_t addr) {    addr = toLSB16(addr);    return call HPLChipconRAM.write(CC2420_RAM_SHORTADR, 2, (uint8_t*)&addr);  }  async event result_t HPLChipconRAM.readDone(uint16_t addr, uint8_t length, uint8_t* buffer) {     return SUCCESS;  }  async event result_t HPLChipconRAM.writeDone(uint16_t addr, uint8_t length, uint8_t* buffer) {     return SUCCESS;  }   async event result_t CCA.fired() {     // reset the CCA pin back to the CCA function     call HPLChipcon.write(CC2420_IOCFG1, 0);     post PostOscillatorOn();     return FAIL;   }	}

⌨️ 快捷键说明

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