- 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
1 changed files with 65 additions and 56 deletions

View File

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