static void chb_radio_init() { U8 ieee_addr[8]; // reset chip chb_reset(); // disable intps while we config the radio chb_reg_write(IRQ_MASK, 0); // force transceiver off while we configure the intps chb_reg_read_mod_write(TRX_STATE, CMD_FORCE_TRX_OFF, 0x1F); // make sure the transceiver is in the off state before proceeding while ((chb_reg_read(TRX_STATUS) & 0x1f) != TRX_OFF); // set radio cfg parameters // **note** uncomment if these will be set to something other than default //chb_reg_read_mod_write(XAH_CTRL_0, CHB_MAX_FRAME_RETRIES << CHB_MAX_FRAME_RETRIES_POS, 0xF << CHB_MAX_FRAME_RETRIES_POS); //chb_reg_read_mod_write(XAH_CTRL_0, CHB_MAX_CSMA_RETRIES << CHB_MAX_CSMA_RETIRES_POS, 0x7 << CHB_MAX_CSMA_RETIRES_POS); //chb_reg_read_mod_write(CSMA_SEED_1, CHB_CSMA_SEED1 << CHB_CSMA_SEED1_POS, 0x7 << CHB_CSMA_SEED1_POS); //chb_ret_write(CSMA_SEED0, CHB_CSMA_SEED0); //chb_reg_read_mod_write(PHY_CC_CCA, CHB_CCA_MODE << CHB_CCA_MODE_POS,0x3 << CHB_CCA_MODE_POS); //chb_reg_write(CCA_THRES, CHB_CCA_ED_THRES); // set frame version that we'll accept chb_reg_read_mod_write(CSMA_SEED_1, CHB_FRM_VER << CHB_FVN_POS, 3 << CHB_FVN_POS); // set interrupt mask // re-enable intps while we config the radio chb_reg_write(IRQ_MASK, (1<<IRQ_RX_START) | (1<<IRQ_TRX_END)); // set autocrc mode chb_reg_read_mod_write(TRX_CTRL_1, 1 << CHB_AUTO_CRC_POS, 1 << CHB_AUTO_CRC_POS); // set up default phy modulation and data rate - OQPSK, 250 kbps, 915 MHz chb_set_mode(CHB_INIT_MODE); chb_set_channel(CHB_CHANNEL); // set fsm state // put trx in rx auto ack mode chb_set_state(RX_AACK_ON); // set pan ID chb_reg_write16(PAN_ID_0, CHB_PAN_ID); // set short addr // NOTE: Possibly get this from EEPROM chb_reg_write16(SHORT_ADDR_0, chb_get_short_addr()); // set long addr // NOTE: Possibly get this from EEPROM chb_get_ieee_addr(ieee_addr); chb_reg_write64(IEEE_ADDR_0, ieee_addr); // enable mcu intp pin on INT4 CFG_CHB_INTP_RISE_EDGE(); while (chb_get_state() != RX_AACK_ON); }
static void chb_radio_init() { U8 ieee_addr[8]; // reset chip chb_reset(); // disable intps while we config the radio chb_reg_write(IRQ_MASK, 0); // force transceiver off while we configure the intps chb_reg_read_mod_write(TRX_STATE, CMD_FORCE_TRX_OFF, 0x1F); // make sure the transceiver is in the off state before proceeding while ((chb_reg_read(TRX_STATUS) & 0x1f) != CHB_TRX_OFF); // set radio cfg parameters // **note** uncomment if these will be set to something other than default //chb_reg_read_mod_write(XAH_CTRL_0, CHB_MAX_FRAME_RETRIES << CHB_MAX_FRAME_RETRIES_POS, 0xF << CHB_MAX_FRAME_RETRIES_POS); //chb_reg_read_mod_write(XAH_CTRL_0, CHB_MAX_CSMA_RETRIES << CHB_MAX_CSMA_RETIRES_POS, 0x7 << CHB_MAX_CSMA_RETIRES_POS); //chb_reg_read_mod_write(CSMA_SEED_1, CHB_CSMA_SEED1 << CHB_CSMA_SEED1_POS, 0x7 << CHB_CSMA_SEED1_POS); //chb_ret_write(CSMA_SEED0, CHB_CSMA_SEED0); //chb_reg_read_mod_write(PHY_CC_CCA, CHB_CCA_MODE << CHB_CCA_MODE_POS,0x3 << CHB_CCA_MODE_POS); //chb_reg_write(CCA_THRES, CHB_CCA_ED_THRES); // set frame version that we'll accept chb_reg_read_mod_write(CSMA_SEED_1, CHB_FRM_VER << CHB_FVN_POS, 3 << CHB_FVN_POS); // set interrupt mask // re-enable intps while we config the radio chb_reg_write(IRQ_MASK, (1<<IRQ_RX_START) | (1<<IRQ_TRX_END)); #if (CHB_PROMISCUOUS == 0) // set autocrc mode chb_reg_read_mod_write(TRX_CTRL_1, 1 << CHB_AUTO_CRC_POS, 1 << CHB_AUTO_CRC_POS); #endif // set up default phy modulation and data rate - OQPSK, 250 kbps, 915 MHz chb_set_mode(CHB_INIT_MODE); chb_set_channel(CHB_CHANNEL); // set fsm state // put trx in rx auto ack mode chb_set_state(RX_STATE); // set pan ID chb_reg_write16(PAN_ID_0, CHB_PAN_ID); // set short addr // NOTE: Possibly get this from EEPROM chb_reg_write16(SHORT_ADDR_0, chb_get_short_addr()); // set long addr // NOTE: Possibly get this from EEPROM chb_get_ieee_addr(ieee_addr); chb_reg_write64(IEEE_ADDR_0, ieee_addr); #if (CHB_CC1190_PRESENT) // set high gain mode pin to output and init to zero CHB_CC1190_HGM_DDIR |= 1<<CHB_CC1190_HGM_PIN; CHB_CC1190_HGM_PORT &= ~(1<<CHB_CC1190_HGM_PIN); // set external power amp on AT86RF212 chb_reg_read_mod_write(TRX_CTRL_1, 1<<CHB_PA_EXT_EN_POS, 1<<CHB_PA_EXT_EN_POS); // set power to 0 dBm if CC1190 is being used. chb_set_pwr(0x24); #endif // enable mcu intp pin CFG_CHB_INTP_RISE_EDGE(); if (chb_get_state() != RX_STATE) { // ERROR occurred initializing the radio. Print out error message. char buf[50]; // grab the error message from flash & print it out strcpy_P(buf, chb_err_init); printf(buf); } }