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); } }