/// makes one attempt to write a change to rx mode /// return 0 on success, -1 on failure after 1 ms timeout int ZigBee_SetModeRx() { uint8_t zigbee_state = ZigBee_ReadState(); // wait until current state permits a transition while(zigbee_state == STATUS_BUSY_RX || zigbee_state == STATUS_BUSY_TX || zigbee_state == STATUS_STATE_TRANSITION) { DelayMicroseconds(100); // should not be required zigbee_state = ZigBee_ReadState(); } // if current state is already STATUS_RX_ON, return success if(zigbee_state == STATUS_RX_ON) { return(0); // success } // request transition ZigBee_WriteReg(REG_TRX_STATE, CMD_RX_ON); // poll state until transition verified // datasheet reports nominal <170 us transition time // timeout and fail after 1 ms for(int i = 0; i < 100; i++) { // TODO: revisit timeout threshold zigbee_state = ZigBee_ReadState(); if (zigbee_state == STATUS_RX_ON) return(0); // success } // zigbee failed to reach state STATUS_RX_ON return(-1); // failure }
int ZigBee_SetModeRx() { uint8_t zigbee_state = ZigBee_ReadState(); while(zigbee_state == STATUS_BUSY_RX || zigbee_state == STATUS_BUSY_TX || zigbee_state == STATUS_STATE_TRANSITION) { zigbee_state = ZigBee_ReadState(); } ZigBee_WriteReg(REG_TRX_STATE, CMD_RX_ON); uint8_t state = 0; for(int i = 0; i < 100; i++) { state = ZigBee_ReadState(); if (state == STATUS_RX_ON) return(0); } return(-1); }
int ZigBee_ForceTrxOff() { uint8_t zigbee_state = ZigBee_ReadState(); while(zigbee_state == STATUS_BUSY_RX || zigbee_state == STATUS_BUSY_TX || zigbee_state == STATUS_STATE_TRANSITION) { zigbee_state = ZigBee_ReadState(); } //write FORCE_TRX_OFF to TRX_STATE ZigBee_WriteReg(REG_TRX_STATE, CMD_FORCE_TRX_OFF); uint8_t state = 0; for(int i = 0; i < 300; i++) { state = ZigBee_ReadState(); if (state == STATUS_TRX_OFF) return(0); } return(-1); }
int ZigBee_PllOn() { uint8_t zigbee_state = ZigBee_ReadState(); while(zigbee_state == STATUS_BUSY_RX || zigbee_state == STATUS_BUSY_TX || zigbee_state == STATUS_STATE_TRANSITION) { zigbee_state = ZigBee_ReadState(); } #if defined(DEBUG) printf("zigbee setting PLL ON\r\n"); #endif ZigBee_WriteReg(REG_TRX_STATE, CMD_PLL_ON); uint8_t state = 0; for(int i = 0; i < 100; i++) { state = ZigBee_ReadState(); if (state == STATUS_PLL_ON) return(0); } return(-1); }