int channel_clear(void) { int cca; int radio_was_off = 0; PRINTF("CCA\n"); /* If the radio is locked by an underlying thread (because we are being invoked through an interrupt), we preted that the coast is clear (i.e., no packet is currently being transmitted by a neighbor). */ if(locked) { return 1; } GET_LOCK(); if(!receive_on) { radio_was_off = 1; cc2520_on(); } /* Make sure that the radio really got turned on. */ if(!receive_on) { RELEASE_LOCK(); if(radio_was_off) { cc2520_off(); } return 1; } cca = cc2520ll_channel_clear(); if(radio_was_off) { cc2520_off(); } RELEASE_LOCK(); return cca; }
/*---------------------------------------------------------------------------*/ int cc2520_rssi(void) { int rssi; int radio_was_off = 0; if(locked) { return 0; } GET_LOCK(); if(!receive_on) { radio_was_off = 1; cc2520_on(); } BUSYWAIT_UNTIL(status() & BV(CC2520_RSSI_VALID), RTIMER_SECOND / 100); rssi = (int)((signed char)getreg(CC2520_RSSI)); if(radio_was_off) { cc2520_off(); } RELEASE_LOCK(); return rssi; }
int transmit(unsigned short transmit_len) { cc2520_on(); PRINTF(" transmit: \n"); u16_t res = 0; GET_LOCK(); //PRINTF("Lock acquired\n"); //PRINTF("start transmit2: %u \n", RTIMER_NOW()); res = cc2520ll_transmit(); //PRINTF("end transmit2: %u \n", RTIMER_NOW()); RELEASE_LOCK(); //cc2520_off(); return res; }
/*---------------------------------------------------------------------------*/ static int cc2520_cca(void) { int cca; int radio_was_off = 0; /* If the radio is locked by an underlying thread (because we are being invoked through an interrupt), we preted that the coast is clear (i.e., no packet is currently being transmitted by a neighbor). */ if(locked) { return 1; } GET_LOCK(); if(!receive_on) { radio_was_off = 1; cc2520_on(); } /* Make sure that the radio really got turned on. */ if(!receive_on) { RELEASE_LOCK(); if(radio_was_off) { cc2520_off(); } return 1; } BUSYWAIT_UNTIL(status() & BV(CC2520_RSSI_VALID), RTIMER_SECOND / 100); cca = CC2520_CCA_IS_1; if(radio_was_off) { cc2520_off(); } RELEASE_LOCK(); return cca; }