void chb_reset() { CHB_RST_DISABLE(); CHB_SLPTR_DISABLE(); // wait a bit while transceiver wakes up chb_delay_us(TIME_P_ON_TO_CLKM_AVAIL); // reset the device CHB_RST_ENABLE(); chb_delay_us(TIME_RST_PULSE_WIDTH); CHB_RST_DISABLE(); // check that we have the part number that we're expecting while (1) { // if you're stuck in this loop, that means that you're not reading // the version and part number register correctly. possible that version number // changes. if so, update version num in header file if ((chb_reg_read(VERSION_NUM) == CHB_AT86RF212_VER_NUM) && (chb_reg_read(PART_NUM) == CHB_AT86RF212_PART_NUM)) { break; } } }
error_t chb_reset() { CHB_RST_DISABLE(); CHB_SLPTR_DISABLE(); // wait a bit while transceiver wakes up chb_delay_us(TIME_P_ON_TO_CLKM_AVAIL); // reset the device CHB_RST_ENABLE(); chb_delay_us(TIME_RST_PULSE_WIDTH); CHB_RST_DISABLE(); // check that we have the part number that we're expecting // if you're stuck here, that means that you're not reading // the version and part number register correctly. possible that version number // changes. if so, update version num in header file if ((chb_reg_read(VERSION_NUM) == CHB_AT86RF212_VER_NUM) && (chb_reg_read(PART_NUM) == CHB_AT86RF212_PART_NUM)) { return ERROR_NONE; } else { return ERROR_DEVICENOTINITIALISED; } }
U8 chb_tx(U8 *hdr, U8 *data, U8 len) { U8 state = chb_get_state(); pcb_t *pcb = chb_get_pcb(); if ((state == BUSY_TX) || (state == BUSY_TX_ARET)) { return RADIO_WRONG_STATE; } // TODO: check why we need to transition to the off state before we go to tx_aret_on chb_set_state(TRX_OFF); chb_set_state(TX_ARET_ON); // TODO: try and start the frame transmission by writing TX_START command instead of toggling // sleep pin...i just feel like it's kind of weird... // write frame to buffer. first write header into buffer (add 1 for len byte), then data. chb_frame_write(hdr, CHB_HDR_SZ + 1, data, len); // TEST - check data in buffer //{ // U8 i, len, tmp[30]; // // len = 1 + CHB_HDR_SZ + len; // chb_sram_read(0, len, tmp); // for (i=0; i<len; i++) // { // printf("%02X ", tmp[i]); // } // printf("\n"); // state = chb_get_state(); // printf("State = %02X.\n", state); //} //TEST //Do frame transmission. Toggle the SLP_TR pin to initiate the frame transmission. CHB_SLPTR_ENABLE(); CHB_SLPTR_DISABLE(); // wait for the transmission to end, signalled by the TRX END flag while (!pcb->tx_end); pcb->tx_end = false; // check the status of the transmission return chb_get_status(); }
void chb_sleep(U8 enb) { if (enb) { // first we need to go to TRX OFF state chb_set_state(TRX_OFF); // set the SLPTR pin CHB_SLPTR_ENABLE(); } else { // make sure the SLPTR pin is low first CHB_SLPTR_DISABLE(); // we need to allow some time for the PLL to lock chb_delay_us(TIME_SLEEP_TO_TRX_OFF); // Turn the transceiver back on chb_set_state(RX_STATE); } }
U8 chb_set_state(U8 state) { U8 curr_state, delay; // if we're sleeping then don't allow transition if (gpioGetValue(CHB_SLPTRPORT, CHB_SLPTRPIN)) { return RADIO_WRONG_STATE; } // if we're in a transition state, wait for the state to become stable curr_state = chb_get_state(); if ((curr_state == BUSY_TX_ARET) || (curr_state == BUSY_RX_AACK) || (curr_state == BUSY_RX) || (curr_state == BUSY_TX)) { while (chb_get_state() == curr_state); } // At this point it is clear that the requested new_state is: // TRX_OFF, RX_ON, PLL_ON, RX_AACK_ON or TX_ARET_ON. // we need to handle some special cases before we transition to the new state switch (state) { case TRX_OFF: /* Go to TRX_OFF from any state. */ CHB_SLPTR_DISABLE(); chb_reg_read_mod_write(TRX_STATE, CMD_FORCE_TRX_OFF, 0x1f); chb_delay_us(TIME_ALL_STATES_TRX_OFF); break; case TX_ARET_ON: if (curr_state == RX_AACK_ON) { /* First do intermediate state transition to PLL_ON, then to TX_ARET_ON. */ chb_reg_read_mod_write(TRX_STATE, CMD_PLL_ON, 0x1f); chb_delay_us(TIME_RX_ON_PLL_ON); } break; case RX_AACK_ON: if (curr_state == TX_ARET_ON) { /* First do intermediate state transition to RX_ON, then to RX_AACK_ON. */ chb_reg_read_mod_write(TRX_STATE, CMD_PLL_ON, 0x1f); chb_delay_us(TIME_RX_ON_PLL_ON); } break; } /* Now we're okay to transition to any new state. */ chb_reg_read_mod_write(TRX_STATE, state, 0x1f); /* When the PLL is active most states can be reached in 1us. However, from */ /* TRX_OFF the PLL needs time to activate. */ delay = (curr_state == TRX_OFF) ? TIME_TRX_OFF_PLL_ON : TIME_RX_ON_PLL_ON; chb_delay_us(delay); if (chb_get_state() == state) { return RADIO_SUCCESS; } return RADIO_TIMED_OUT; }