- avoid costly rx state initialization if the radio is already on.

- code formatting.
This commit is contained in:
nvt-se 2009-03-19 14:43:31 +00:00
parent 8f85355f02
commit 6b22fa60e8

View File

@ -141,13 +141,15 @@ cc1020_init(const uint8_t *config)
// calibrate receiver
cc1020_wakeupRX(RX_CURRENT);
if (!cc1020_calibrate())
if(!cc1020_calibrate()) {
printf("rx calibration failed\n");
}
// calibrate transmitter
cc1020_wakeupTX(TX_CURRENT);
if (!cc1020_calibrate())
if(!cc1020_calibrate()) {
printf("tx calibration failed\n");
}
// power down
cc1020_setupPD();
@ -233,11 +235,13 @@ cc1020_send(const void *buf, unsigned short len)
int normal_header = HDRSIZE + len;
uint16_t rxcrc = 0xFFFF; // For checksum purposes
if (cc1020_state == CC1020_OFF)
if(cc1020_state == CC1020_OFF) {
return -2;
}
if (len > CC1020_BUFFERSIZE)
if(len > CC1020_BUFFERSIZE) {
return -1;
}
/* The preamble and the sync word are already in buffer. */
cc1020_txlen = PREAMBLESIZE + SYNCWDSIZE;
@ -260,7 +264,6 @@ cc1020_send(const void *buf, unsigned short len)
cc1020_txlen += len;
// Send checksum
/* printf("send checksum %04hx\n", rxcrc); */
cc1020_txbuf[cc1020_txlen++] = (uint8_t)(rxcrc >> 8);
cc1020_txbuf[cc1020_txlen++] = (uint8_t)(rxcrc & 0xFF);
@ -289,7 +292,7 @@ cc1020_send(const void *buf, unsigned short len)
// Initiate radio transfer.
dma_done = 0;
dma_transfer(&TXBUF0, cc1020_txbuf, cc1020_txlen);
dma_transfer((unsigned char *)&TXBUF0, cc1020_txbuf, cc1020_txlen);
while(!dma_done);
ENERGEST_OFF(ENERGEST_TYPE_TRANSMIT);
@ -311,8 +314,9 @@ cc1020_read(void *buf, unsigned short size)
{
unsigned len;
if (cc1020_rxlen <= HDRSIZE)
if(cc1020_rxlen <= HDRSIZE) {
return 0;
}
len = cc1020_rxlen - HDRSIZE;
if(len > size) {
@ -337,9 +341,10 @@ cc1020_set_receiver(void (*recv)(const struct radio_driver *))
int
cc1020_on(void)
{
if(cc1020_state == CC1020_OFF) {
cc1020_state &= ~CC1020_TURN_OFF;
// Switch to receive mode
cc1020_set_rx();
}
return 1;
}
@ -415,8 +420,6 @@ PROCESS_THREAD(cc1020_receiver_process, ev, data)
} else {
RIMESTATS_ADD(badcrc);
reset_receiver();
/* printf("bad crc. expected: %04hx received: %04hx\n", */
/* expected_crc, actual_crc, cc1020_rxlen); */
}
}
}
@ -526,10 +529,11 @@ cc1020_write_reg(uint8_t addr, uint8_t adata)
nop();
PCLK_LOW;
nop();
if (data & 0x80)
if(data & 0x80) {
PDI_HIGH;
else
} else {
PDI_LOW;
}
data = data << 1;
PCLK_HIGH;
}
@ -550,10 +554,11 @@ cc1020_write_reg(uint8_t addr, uint8_t adata)
nop();
PCLK_LOW;
nop();
if (data & 0x80)
if(data & 0x80) {
PDI_HIGH;
else
} else {
PDI_LOW;
}
data = data << 1;
PCLK_HIGH;
}
@ -580,10 +585,11 @@ cc1020_read_reg(uint8_t addr)
nop();
PCLK_LOW;
nop();
if (data & 0x80)
if(data & 0x80) {
PDI_HIGH;
else
} else {
PDI_LOW;
}
data = data << 1;
PCLK_HIGH;
}
@ -604,8 +610,9 @@ cc1020_read_reg(uint8_t addr)
PCLK_HIGH;
nop();
data = data << 1;
if (PDO)
if(PDO) {
data++;
}
nop();
PCLK_LOW;
}
@ -651,9 +658,10 @@ cc1020_calibrate(void)
// Monitor lock
for(timeout_cnt = LOCK_TIMEOUT; timeout_cnt > 0; timeout_cnt--) {
if (cc1020_read_reg(CC1020_STATUS) & LOCK_CONTINUOUS)
if(cc1020_read_reg(CC1020_STATUS) & LOCK_CONTINUOUS) {
break;
}
}
// Restore PA_POWER
cc1020_write_reg(CC1020_PA_POWER, cc1020_pa_power);
@ -671,9 +679,10 @@ cc1020_lock(void)
// Monitor LOCK, lasts 420 - 510 cycles @ 4505600 = 93 us - 113 us
for(i = LOCK_TIMEOUT; i > 0; i--) {
lock_status = cc1020_read_reg(CC1020_STATUS) & LOCK_CONTINUOUS;
if (lock_status)
if(lock_status) {
break;
}
}
if(lock_status == LOCK_CONTINUOUS) {
return LOCK_OK;