/*---------------------------------------------------------------------------*/ PROCESS_THREAD(shell_time_process, ev, data) { struct { uint16_t len; uint16_t clock; uint16_t rtimer; uint16_t timesynch; uint16_t timesynch_authority; uint16_t time[2]; } msg; unsigned long newtime; const char *nextptr; PROCESS_BEGIN(); if(data != NULL) { newtime = shell_strtolong(data, &nextptr); if(data != nextptr) { shell_set_time(newtime); } } msg.clock = (uint16_t)clock_time(); msg.rtimer = (uint16_t)RTIMER_NOW(); #if TIMESYNCH_CONF_ENABLED msg.timesynch = timesynch_time(); msg.timesynch_authority = timesynch_authority_level(); #else msg.timesynch = 0; msg.timesynch_authority = -1; #endif msg.time[0] = (uint16_t)(shell_time() >> 16); msg.time[1] = (uint16_t)(shell_time()); msg.len = 6; shell_output(&time_command, &msg, sizeof(msg), "", 0); PROCESS_END(); }
/*---------------------------------------------------------------------------*/ int cc2420_send(const void *payload, unsigned short payload_len) { int i; uint8_t total_len; struct timestamp timestamp; uint16_t checksum; GET_LOCK(); PRINTF("cc2420: sending %d bytes\n", payload_len); RIMESTATS_ADD(lltx); /* Wait for any previous transmission to finish. */ while(status() & BV(CC2420_TX_ACTIVE)); /* Write packet to TX FIFO. */ strobe(CC2420_SFLUSHTX); checksum = crc16_data(payload, payload_len, 0); total_len = payload_len + AUX_LEN; FASTSPI_WRITE_FIFO(&total_len, 1); FASTSPI_WRITE_FIFO(payload, payload_len); FASTSPI_WRITE_FIFO(&checksum, CHECKSUM_LEN); #if CC2420_CONF_TIMESTAMPS timestamp.authority_level = timesynch_authority_level(); timestamp.time = timesynch_time(); FASTSPI_WRITE_FIFO(×tamp, TIMESTAMP_LEN); #endif /* CC2420_CONF_TIMESTAMPS */ /* The TX FIFO can only hold one packet. Make sure to not overrun * FIFO by waiting for transmission to start here and synchronizing * with the CC2420_TX_ACTIVE check in cc2420_send. * * Note that we may have to wait up to 320 us (20 symbols) before * transmission starts. */ #ifdef TMOTE_SKY #define LOOP_20_SYMBOLS 100 /* 326us (msp430 @ 2.4576MHz) */ #elif __AVR__ #define LOOP_20_SYMBOLS 500 /* XXX */ #endif #if WITH_SEND_CCA strobe(CC2420_SRXON); while(!(status() & BV(CC2420_RSSI_VALID))); strobe(CC2420_STXONCCA); #else /* WITH_SEND_CCA */ strobe(CC2420_STXON); #endif /* WITH_SEND_CCA */ for(i = LOOP_20_SYMBOLS; i > 0; i--) { if(SFD_IS_1) { #if CC2420_CONF_TIMESTAMPS rtimer_clock_t txtime = timesynch_time(); #endif /* CC2420_CONF_TIMESTAMPS */ if(receive_on) { ENERGEST_OFF(ENERGEST_TYPE_LISTEN); } ENERGEST_ON(ENERGEST_TYPE_TRANSMIT); /* We wait until transmission has ended so that we get an accurate measurement of the transmission time.*/ while(status() & BV(CC2420_TX_ACTIVE)); #if CC2420_CONF_TIMESTAMPS setup_time_for_transmission = txtime - timestamp.time; if(num_transmissions < 10000) { total_time_for_transmission += timesynch_time() - txtime; total_transmission_len += total_len; num_transmissions++; } #endif /* CC2420_CONF_TIMESTAMPS */ #ifdef ENERGEST_CONF_LEVELDEVICE_LEVELS ENERGEST_OFF_LEVEL(ENERGEST_TYPE_TRANSMIT,cc2420_get_txpower()); #endif ENERGEST_OFF(ENERGEST_TYPE_TRANSMIT); if(receive_on) { ENERGEST_ON(ENERGEST_TYPE_LISTEN); } RELEASE_LOCK(); return 0; } } /* If we are using WITH_SEND_CCA, we get here if the packet wasn't transmitted because of other channel activity. */ RIMESTATS_ADD(contentiondrop); PRINTF("cc2420: do_send() transmission never started\n"); RELEASE_LOCK(); return -3; /* Transmission never started! */ }
/*---------------------------------------------------------------------------*/ int nrf24l01_send(const void *payload, unsigned short payload_len) { uint8_t total_len,buffer[RF230_MAX_TX_FRAME_LENGTH],*pbuf; uint8_t tx_result = RADIO_TX_ERR; #if RF230_CONF_TIMESTAMPS struct timestamp timestamp; #endif /* RF230_CONF_TIMESTAMPS */ #if RF230_CONF_CHECKSUM uint16_t checksum; #endif /* RF230_CONF_CHECKSUM */ #if RADIOSTATS RF230_sendpackets++; #endif GET_LOCK(); RIMESTATS_ADD(lltx); #if RF230_CONF_CHECKSUM checksum = crc16_data(payload, payload_len, 0); #endif /* RF230_CONF_CHECKSUM */ total_len = payload_len + AUX_LEN; /*Check function parameters and current state.*/ if (total_len > RF230_MAX_TX_FRAME_LENGTH){ #if RADIOSTATS RF230_sendfail++; #endif return -1; } pbuf=&buffer[0]; memcpy(pbuf,payload,payload_len); pbuf+=payload_len; #if RF230_CONF_CHECKSUM memcpy(pbuf,&checksum,CHECKSUM_LEN); pbuf+=CHECKSUM_LEN; #endif /* RF230_CONF_CHECKSUM */ #if RF230_CONF_TIMESTAMPS timestamp.authority_level = timesynch_authority_level(); timestamp.time = timesynch_time(); memcpy(pbuf,×tamp,TIMESTAMP_LEN); pbuf+=TIMESTAMP_LEN; #endif /* RF230_CONF_TIMESTAMPS */ /* If radio is sleeping we have to turn it on first */ // /* if need radio calibrate, do it here */ // /* Wait for any previous transmission to finish. */ //nrf24l01_waitidle(); BUSYWAIT_UNTIL(nrf24l01_status(), RTIMER_SECOND / 100); /* set tx mode */ // /* set some features here like auto ack */ // /* get the current power and save, then adjust the power to send */ // if(packetbuf_attr(PACKETBUF_ATTR_RADIO_TXPOWER) > 0) { nrf24l01_set_txpower(packetbuf_attr(PACKETBUF_ATTR_RADIO_TXPOWER) - 1); } else { nrf24l01_set_txpower(TX_PWR_18DBM); //-18dbm } /* Now start transmitting... */ PRINTF("nrf24l01: sending %d bytes\n", payload_len); //send these data SPI_WRITE_BUF(WR_TX_PLOAD, buffer, total_len); if(1) { #if RF230_CONF_TIMESTAMPS rtimer_clock_t txtime = timesynch_time(); #endif /* RF230_CONF_TIMESTAMPS */ if(rf_radio_on) { ENERGEST_OFF(ENERGEST_TYPE_LISTEN); } ENERGEST_ON(ENERGEST_TYPE_TRANSMIT); /* We wait until transmission has ended so that we get an accurate measurement of the transmission time.*/ //nrf24l01_waitidle(); //radio_set_trx_state(RX_AACK_ON);//Re-enable receive mode BUSYWAIT_UNTIL(isr_event_write.isr_type, RTIMER_SECOND / 100); if(ISR_TX_DS == isr_event_write.isr_type) { tx_result = RADIO_TX_OK; } /*else if(ISR_MAX_RT == state) { tx_result = RADIO_TX_NOACK; }*/ else { tx_result = RADIO_TX_NOACK; } #if RF230_CONF_TIMESTAMPS setup_time_for_transmission = txtime - timestamp.time; if(num_transmissions < 10000) { total_time_for_transmission += timesynch_time() - txtime; total_transmission_len += total_len; num_transmissions++; } #endif /* RF230_CONF_TIMESTAMPS */ #ifdef ENERGEST_CONF_LEVELDEVICE_LEVELS ENERGEST_OFF_LEVEL(ENERGEST_TYPE_TRANSMIT,rf230_get_txpower()); #endif ENERGEST_OFF(ENERGEST_TYPE_TRANSMIT); if(rf_radio_on) { ENERGEST_ON(ENERGEST_TYPE_LISTEN); } RELEASE_LOCK(); return tx_result; } }