More clear power down procedure. Now it is required that cc1020_on
is called before anyone can send after the power down.
This commit is contained in:
parent
d5580ae7ee
commit
fb9b800c53
|
@ -241,6 +241,6 @@ struct cc1020_header {
|
|||
/// cc1020 receiver state
|
||||
enum cc1020_rxstate {
|
||||
CC1020_RX_SEARCHING, // searching for preamble + sync word
|
||||
CC1020_RX_RECEIVE, // receiving bytes
|
||||
CC1020_RX_RECEIVING, // receiving bytes
|
||||
CC1020_RX_PROCESSING // processing data in buffer
|
||||
};
|
||||
|
|
|
@ -76,7 +76,7 @@ static enum cc1020_state cc1020_state = CC1020_OFF;
|
|||
static volatile uint8_t cc1020_rxbuf[HDRSIZE + CC1020_BUFFERSIZE];
|
||||
static uint8_t cc1020_txbuf[PREAMBLESIZE + HDRSIZE + CC1020_BUFFERSIZE +
|
||||
TAILSIZE];
|
||||
static enum cc1020_rxstate cc1020_rxstate = CC1020_RX_SEARCHING;
|
||||
static volatile enum cc1020_rxstate cc1020_rxstate = CC1020_RX_SEARCHING;
|
||||
|
||||
/// number of bytes in receive and transmit buffers respectively.
|
||||
static uint16_t cc1020_rxlen;
|
||||
|
@ -199,6 +199,9 @@ cc1020_set_power(uint8_t pa_power)
|
|||
int
|
||||
cc1020_send(const void *buf, unsigned short len)
|
||||
{
|
||||
if (cc1020_state == CC1020_OFF)
|
||||
return -2;
|
||||
|
||||
if (len > CC1020_BUFFERSIZE)
|
||||
return -1;
|
||||
|
||||
|
@ -265,8 +268,8 @@ cc1020_off(void)
|
|||
{
|
||||
int s;
|
||||
|
||||
if (cc1020_rxstate == CC1020_OFF)
|
||||
return 1;
|
||||
// Discard the current read buffer when the radio is shutting down.
|
||||
cc1020_rxlen = 0;
|
||||
|
||||
LNA_POWER_OFF(); // power down lna
|
||||
s = splhigh();
|
||||
|
@ -275,6 +278,7 @@ cc1020_off(void)
|
|||
cc1020_state = CC1020_OFF;
|
||||
splx(s);
|
||||
cc1020_setupPD(); // power down radio
|
||||
cc1020_state = CC1020_OFF;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -335,19 +339,17 @@ interrupt(UART0RX_VECTOR) cc1020_rxhandler(void)
|
|||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
// Update RSSI.
|
||||
rssi = cc1020_read_reg(CC1020_RSS);
|
||||
cc1020_rxstate = CC1020_RX_RECEIVING;
|
||||
|
||||
cc1020_rxstate = CC1020_RX_RECEIVE;
|
||||
break;
|
||||
case CC1020_RX_RECEIVE:
|
||||
case CC1020_RX_RECEIVING:
|
||||
if (syncbs == 0) {
|
||||
cc1020_rxbuf[cc1020_rxlen] = RXBUF0;
|
||||
} else {
|
||||
shiftbuf.b3 = shiftbuf.b4;
|
||||
shiftbuf.b4 = RXBUF0;
|
||||
|
||||
if (syncbs < 0) {
|
||||
shiftbuf.i1 = shiftbuf.i2 << -syncbs;
|
||||
cc1020_rxbuf[cc1020_rxlen] = shiftbuf.b1;
|
||||
|
@ -365,8 +367,9 @@ interrupt(UART0RX_VECTOR) cc1020_rxhandler(void)
|
|||
cc1020_rxstate = CC1020_RX_PROCESSING;
|
||||
|
||||
// call receiver to copy from buffer
|
||||
if (receiver_callback != NULL)
|
||||
if (receiver_callback != NULL) {
|
||||
receiver_callback(&cc1020_driver);
|
||||
}
|
||||
|
||||
// reset receiver
|
||||
cc1020_rxlen = 0;
|
||||
|
@ -387,10 +390,8 @@ PROCESS_THREAD(cc1020_sender_process, ev, data)
|
|||
dma_subscribe(0, &cc1020_sender_process);
|
||||
|
||||
while (1) {
|
||||
PROCESS_WAIT_UNTIL(cc1020_txlen > 0);
|
||||
PROCESS_WAIT_UNTIL(cc1020_txlen > 0 && cc1020_state != CC1020_OFF);
|
||||
|
||||
// Radio could be in OFF or RX mode.
|
||||
if (cc1020_state == CC1020_OFF)
|
||||
cc1020_set_rx();
|
||||
|
||||
if (cc1020_rxstate != CC1020_RX_SEARCHING) {
|
||||
|
@ -414,7 +415,7 @@ PROCESS_THREAD(cc1020_sender_process, ev, data)
|
|||
|
||||
// clean up
|
||||
cc1020_txlen = 0;
|
||||
cc1020_on();
|
||||
cc1020_set_rx();
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
|
@ -643,11 +644,17 @@ cc1020_setupTX(int analog)
|
|||
static void
|
||||
cc1020_setupPD(void)
|
||||
{
|
||||
// Put CC1020 into power-down
|
||||
cc1020_write_reg(CC1020_MAIN, 0x1F);
|
||||
/*
|
||||
* Power down components an reset all registers except MAIN
|
||||
* to their default values.
|
||||
*/
|
||||
cc1020_write_reg(CC1020_MAIN,
|
||||
RESET_N | BIAS_PD | FS_PD | XOSC_PD | PD_MODE_1);
|
||||
|
||||
// Turn off PA to minimise current draw
|
||||
/* Turn off the power amplifier. */
|
||||
cc1020_write_reg(CC1020_PA_POWER, 0x00);
|
||||
|
||||
cc1020_write_reg(CC1020_POWERDOWN, 0x1F);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
Loading…
Reference in a new issue