Removed the unused function cc2420_cca_valid and replaced some macros

with functions in CC2420. This reduces the code size with over 400 bytes.
This commit is contained in:
Niclas Finne 2014-04-11 12:58:49 +02:00
parent 207f1987ee
commit 271ac4413f

View file

@ -137,7 +137,7 @@ int cc2420_authority_level_of_sender;
int cc2420_packets_seen, cc2420_packets_read; int cc2420_packets_seen, cc2420_packets_read;
static uint8_t volatile pending; /* static uint8_t volatile pending; */
#define BUSYWAIT_UNTIL(cond, max_time) \ #define BUSYWAIT_UNTIL(cond, max_time) \
do { \ do { \
@ -294,6 +294,12 @@ const struct radio_driver cc2420_driver =
}; };
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void
strobe(enum cc2420_register regname)
{
CC2420_STROBE(regname);
}
/*---------------------------------------------------------------------------*/
static void static void
getrxdata(void *buf, int len) getrxdata(void *buf, int len)
@ -310,15 +316,12 @@ flushrx(void)
{ {
uint8_t dummy; uint8_t dummy;
CC2420_READ_FIFO_BYTE(dummy); getrxbyte(&dummy);
CC2420_STROBE(CC2420_SFLUSHRX); strobe(CC2420_SFLUSHRX);
CC2420_STROBE(CC2420_SFLUSHRX); strobe(CC2420_SFLUSHRX);
} if(dummy) {
/*---------------------------------------------------------------------------*/ /* avoid unused variable compiler warning */
static void }
strobe(enum cc2420_register regname)
{
CC2420_STROBE(regname);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static unsigned int static unsigned int
@ -329,6 +332,18 @@ status(void)
return status; return status;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void
wait_for_status(unsigned int mask)
{
BUSYWAIT_UNTIL((status() & mask), RTIMER_SECOND / 10);
}
/*---------------------------------------------------------------------------*/
static void
wait_for_not_status(unsigned int mask)
{
BUSYWAIT_UNTIL(!(status() & mask), RTIMER_SECOND / 10);
}
/*---------------------------------------------------------------------------*/
static uint8_t locked, lock_on, lock_off; static uint8_t locked, lock_on, lock_off;
static void static void
@ -337,7 +352,7 @@ on(void)
CC2420_ENABLE_FIFOP_INT(); CC2420_ENABLE_FIFOP_INT();
strobe(CC2420_SRXON); strobe(CC2420_SRXON);
BUSYWAIT_UNTIL(status() & (BV(CC2420_XOSC16M_STABLE)), RTIMER_SECOND / 100); wait_for_status(BV(CC2420_XOSC16M_STABLE));
ENERGEST_ON(ENERGEST_TYPE_LISTEN); ENERGEST_ON(ENERGEST_TYPE_LISTEN);
receive_on = 1; receive_on = 1;
@ -349,7 +364,7 @@ off(void)
receive_on = 0; receive_on = 0;
/* Wait for transmission to end before turning radio off. */ /* Wait for transmission to end before turning radio off. */
BUSYWAIT_UNTIL(!(status() & BV(CC2420_TX_ACTIVE)), RTIMER_SECOND / 10); wait_for_not_status(BV(CC2420_TX_ACTIVE));
ENERGEST_OFF(ENERGEST_TYPE_LISTEN); ENERGEST_OFF(ENERGEST_TYPE_LISTEN);
strobe(CC2420_SRFOFF); strobe(CC2420_SRFOFF);
@ -390,6 +405,12 @@ setreg(enum cc2420_register regname, unsigned value)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
write_ram(const void *buf, uint16_t addr, int count)
{
CC2420_WRITE_RAM(buf, addr, count);
}
/*---------------------------------------------------------------------------*/
static void
set_txpower(uint8_t power) set_txpower(uint8_t power)
{ {
uint16_t reg; uint16_t reg;
@ -476,7 +497,6 @@ static int
cc2420_transmit(unsigned short payload_len) cc2420_transmit(unsigned short payload_len)
{ {
int i, txpower; int i, txpower;
uint8_t total_len;
#if CC2420_CONF_CHECKSUM #if CC2420_CONF_CHECKSUM
uint16_t checksum; uint16_t checksum;
#endif /* CC2420_CONF_CHECKSUM */ #endif /* CC2420_CONF_CHECKSUM */
@ -491,8 +511,6 @@ cc2420_transmit(unsigned short payload_len)
set_txpower(packetbuf_attr(PACKETBUF_ATTR_RADIO_TXPOWER) - 1); set_txpower(packetbuf_attr(PACKETBUF_ATTR_RADIO_TXPOWER) - 1);
} }
total_len = payload_len + AUX_LEN;
/* The TX FIFO can only hold one packet. Make sure to not overrun /* The TX FIFO can only hold one packet. Make sure to not overrun
* FIFO by waiting for transmission to start here and synchronizing * FIFO by waiting for transmission to start here and synchronizing
* with the CC2420_TX_ACTIVE check in cc2420_send. * with the CC2420_TX_ACTIVE check in cc2420_send.
@ -508,7 +526,7 @@ cc2420_transmit(unsigned short payload_len)
#if WITH_SEND_CCA #if WITH_SEND_CCA
strobe(CC2420_SRXON); strobe(CC2420_SRXON);
BUSYWAIT_UNTIL(status() & BV(CC2420_RSSI_VALID), RTIMER_SECOND / 10); wait_for_status(BV(CC2420_RSSI_VALID));
strobe(CC2420_STXONCCA); strobe(CC2420_STXONCCA);
#else /* WITH_SEND_CCA */ #else /* WITH_SEND_CCA */
strobe(CC2420_STXON); strobe(CC2420_STXON);
@ -521,7 +539,7 @@ cc2420_transmit(unsigned short payload_len)
if(packetbuf_attr(PACKETBUF_ATTR_PACKET_TYPE) == if(packetbuf_attr(PACKETBUF_ATTR_PACKET_TYPE) ==
PACKETBUF_ATTR_PACKET_TYPE_TIMESTAMP) { PACKETBUF_ATTR_PACKET_TYPE_TIMESTAMP) {
/* Write timestamp to last two bytes of packet in TXFIFO. */ /* Write timestamp to last two bytes of packet in TXFIFO. */
CC2420_WRITE_RAM(&sfd_timestamp, CC2420RAM_TXFIFO + payload_len - 1, 2); write_ram(&sfd_timestamp, CC2420RAM_TXFIFO + payload_len - 1, 2);
} }
} }
@ -538,7 +556,7 @@ cc2420_transmit(unsigned short payload_len)
ENERGEST_ON(ENERGEST_TYPE_TRANSMIT); ENERGEST_ON(ENERGEST_TYPE_TRANSMIT);
/* We wait until transmission has ended so that we get an /* We wait until transmission has ended so that we get an
accurate measurement of the transmission time.*/ accurate measurement of the transmission time.*/
BUSYWAIT_UNTIL(!(status() & BV(CC2420_TX_ACTIVE)), RTIMER_SECOND / 10); wait_for_not_status(BV(CC2420_TX_ACTIVE));
#ifdef ENERGEST_CONF_LEVELDEVICE_LEVELS #ifdef ENERGEST_CONF_LEVELDEVICE_LEVELS
ENERGEST_OFF_LEVEL(ENERGEST_TYPE_TRANSMIT,cc2420_get_txpower()); ENERGEST_OFF_LEVEL(ENERGEST_TYPE_TRANSMIT,cc2420_get_txpower());
@ -685,10 +703,10 @@ cc2420_set_channel(int c)
/* /*
* Writing RAM requires crystal oscillator to be stable. * Writing RAM requires crystal oscillator to be stable.
*/ */
BUSYWAIT_UNTIL((status() & (BV(CC2420_XOSC16M_STABLE))), RTIMER_SECOND / 10); wait_for_status(BV(CC2420_XOSC16M_STABLE));
/* Wait for any transmission to end. */ /* Wait for any transmission to end. */
BUSYWAIT_UNTIL(!(status() & BV(CC2420_TX_ACTIVE)), RTIMER_SECOND / 10); wait_for_not_status(BV(CC2420_TX_ACTIVE));
setreg(CC2420_FSCTRL, f); setreg(CC2420_FSCTRL, f);
@ -715,22 +733,22 @@ cc2420_set_pan_addr(unsigned pan,
/* /*
* Writing RAM requires crystal oscillator to be stable. * Writing RAM requires crystal oscillator to be stable.
*/ */
BUSYWAIT_UNTIL(status() & (BV(CC2420_XOSC16M_STABLE)), RTIMER_SECOND / 10); wait_for_status(BV(CC2420_XOSC16M_STABLE));
tmp[0] = pan & 0xff; tmp[0] = pan & 0xff;
tmp[1] = pan >> 8; tmp[1] = pan >> 8;
CC2420_WRITE_RAM(&tmp, CC2420RAM_PANID, 2); write_ram(&tmp, CC2420RAM_PANID, 2);
tmp[0] = addr & 0xff; tmp[0] = addr & 0xff;
tmp[1] = addr >> 8; tmp[1] = addr >> 8;
CC2420_WRITE_RAM(&tmp, CC2420RAM_SHORTADDR, 2); write_ram(&tmp, CC2420RAM_SHORTADDR, 2);
if(ieee_addr != NULL) { if(ieee_addr != NULL) {
uint8_t tmp_addr[8]; uint8_t tmp_addr[8];
/* LSB first, MSB last for 802.15.4 addresses in CC2420 */ /* LSB first, MSB last for 802.15.4 addresses in CC2420 */
for (f = 0; f < 8; f++) { for (f = 0; f < 8; f++) {
tmp_addr[7 - f] = ieee_addr[f]; tmp_addr[7 - f] = ieee_addr[f];
} }
CC2420_WRITE_RAM(tmp_addr, CC2420RAM_IEEEADDR, 8); write_ram(tmp_addr, CC2420RAM_IEEEADDR, 8);
} }
RELEASE_LOCK(); RELEASE_LOCK();
} }
@ -745,7 +763,7 @@ cc2420_interrupt(void)
process_poll(&cc2420_process); process_poll(&cc2420_process);
last_packet_timestamp = cc2420_sfd_start_time; last_packet_timestamp = cc2420_sfd_start_time;
pending++; /* pending++; */
cc2420_packets_seen++; cc2420_packets_seen++;
return 1; return 1;
} }
@ -790,7 +808,7 @@ cc2420_read(void *buf, unsigned short bufsize)
return 0; return 0;
}*/ }*/
pending = 0; /* pending = 0; */
GET_LOCK(); GET_LOCK();
@ -906,7 +924,7 @@ cc2420_rssi(void)
radio_was_off = 1; radio_was_off = 1;
cc2420_on(); cc2420_on();
} }
BUSYWAIT_UNTIL(status() & BV(CC2420_RSSI_VALID), RTIMER_SECOND / 100); wait_for_status(BV(CC2420_RSSI_VALID));
rssi = (int)((signed char)getreg(CC2420_RSSI)); rssi = (int)((signed char)getreg(CC2420_RSSI));
@ -925,19 +943,6 @@ detected_energy(void)
} }
*/ */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
int
cc2420_cca_valid(void)
{
int valid;
if(locked) {
return 1;
}
GET_LOCK();
valid = !!(status() & BV(CC2420_RSSI_VALID));
RELEASE_LOCK();
return valid;
}
/*---------------------------------------------------------------------------*/
static int static int
cc2420_cca(void) cc2420_cca(void)
{ {
@ -967,7 +972,7 @@ cc2420_cca(void)
return 1; return 1;
} }
BUSYWAIT_UNTIL(status() & BV(CC2420_RSSI_VALID), RTIMER_SECOND / 100); wait_for_status(BV(CC2420_RSSI_VALID));
cca = CC2420_CCA_IS_1; cca = CC2420_CCA_IS_1;