remove some unnecessary instructions and function calls. patch from Jesper Karlsson.

This commit is contained in:
nvt-se 2009-03-24 15:13:11 +00:00
parent 143c7f9cea
commit 15c447e57e

View file

@ -178,7 +178,7 @@ cc1020_set_rx(void)
UBR00 = 0x00; // No baudrate divider UBR00 = 0x00; // No baudrate divider
UBR10 = 0x00; // settings for a spi UBR10 = 0x00; // settings for a spi
UMCTL0 = 0x00; // slave. UMCTL0 = 0x00; // slave.
ME1 |= USPIE0; // Enable USART0 TXD/RXD, disabling does not yield any powersavings ME1 |= URXE0; // Enable USART0 RXD, disabling does not yield any powersavings
P3SEL |= 0x0A; // Select rx line and clk P3SEL |= 0x0A; // Select rx line and clk
UCTL0 &= ~SWRST; // Clear reset bit UCTL0 &= ~SWRST; // Clear reset bit
splx(s); splx(s);
@ -233,6 +233,7 @@ cc1020_send(const void *buf, unsigned short len)
{ {
int try; int try;
int normal_header = HDRSIZE + len; int normal_header = HDRSIZE + len;
int i;
uint16_t rxcrc = 0xFFFF; // For checksum purposes uint16_t rxcrc = 0xFFFF; // For checksum purposes
if(cc1020_state == CC1020_OFF) { if(cc1020_state == CC1020_OFF) {
@ -254,9 +255,8 @@ cc1020_send(const void *buf, unsigned short len)
rxcrc = crc16_add((uint8_t) (normal_header & 0xff), rxcrc); rxcrc = crc16_add((uint8_t) (normal_header & 0xff), rxcrc);
rxcrc = crc16_add((uint8_t) ((normal_header >> 8)& 0xff), rxcrc); rxcrc = crc16_add((uint8_t) ((normal_header >> 8)& 0xff), rxcrc);
int i=0; for(i = 0; i < len; i++) {
for(i=0;i<len;i++){ rxcrc = crc16_add((uint8_t) ((char*)buf)[i], rxcrc);
rxcrc = crc16_add((uint8_t) ((char*)buf)[i], rxcrc);
} }
// data to send // data to send
@ -276,10 +276,11 @@ cc1020_send(const void *buf, unsigned short len)
for(try = 0; try < CC1020_CONF_CCA_TIMEOUT; try++) { for(try = 0; try < CC1020_CONF_CCA_TIMEOUT; try++) {
MS_DELAY(1); MS_DELAY(1);
if(!cc1020_carrier_sense()) { if(!cc1020_carrier_sense()) {
break; break;
} }
} }
if(try == CC1020_CONF_CCA_TIMEOUT) { if(try == CC1020_CONF_CCA_TIMEOUT) {
printf("CCA failed rssi: %d\n", cc1020_get_rssi());
return -3; return -3;
} }
@ -375,7 +376,7 @@ cc1020_off(void)
uint8_t uint8_t
cc1020_get_rssi(void) cc1020_get_rssi(void)
{ {
return cc1020_read_reg(CC1020_RSS); return (cc1020_read_reg(CC1020_RSS) & 0x7F);
} }
uint8_t uint8_t
@ -384,12 +385,10 @@ cc1020_get_packet_rssi(void)
return rssi; return rssi;
} }
int int
cc1020_carrier_sense(void) cc1020_carrier_sense(void)
{ {
return !!(cc1020_read_reg(CC1020_STATUS) & CARRIER_SENSE); return (cc1020_read_reg(CC1020_STATUS) & CARRIER_SENSE);
} }
PROCESS_THREAD(cc1020_receiver_process, ev, data) PROCESS_THREAD(cc1020_receiver_process, ev, data)
@ -416,10 +415,10 @@ PROCESS_THREAD(cc1020_receiver_process, ev, data)
} }
if(expected_crc == actual_crc) { if(expected_crc == actual_crc) {
receiver_callback(&cc1020_driver); receiver_callback(&cc1020_driver);
} else { } else {
RIMESTATS_ADD(badcrc); RIMESTATS_ADD(badcrc);
reset_receiver(); reset_receiver();
} }
} }
} }
@ -477,7 +476,7 @@ interrupt(UART0RX_VECTOR) cc1020_rxhandler(void)
} else { } else {
return; return;
} }
rssi = cc1020_read_reg(CC1020_RSS); rssi = cc1020_get_rssi();
CC1020_SET_OPSTATE(CC1020_RX | CC1020_RX_RECEIVING); CC1020_SET_OPSTATE(CC1020_RX | CC1020_RX_RECEIVING);
} else if(cc1020_state & CC1020_RX_RECEIVING) { } else if(cc1020_state & CC1020_RX_RECEIVING) {
if(syncbs == 0) { if(syncbs == 0) {
@ -499,15 +498,15 @@ interrupt(UART0RX_VECTOR) cc1020_rxhandler(void)
if(cc1020_rxlen == HDRSIZE) { if(cc1020_rxlen == HDRSIZE) {
pktlen = ((struct cc1020_header *)cc1020_rxbuf)->length; pktlen = ((struct cc1020_header *)cc1020_rxbuf)->length;
if(pktlen == 0 || pktlen > sizeof (cc1020_rxbuf)) { if(pktlen == 0 || pktlen > sizeof (cc1020_rxbuf)) {
cc1020_rxlen = 0; cc1020_rxlen = 0;
CC1020_SET_OPSTATE(CC1020_RX | CC1020_RX_SEARCHING); CC1020_SET_OPSTATE(CC1020_RX | CC1020_RX_SEARCHING);
} }
} else if(cc1020_rxlen > HDRSIZE) { } else if(cc1020_rxlen > HDRSIZE) {
if(cc1020_rxlen == pktlen) { if(cc1020_rxlen == pktlen) {
/* Disable interrupts while processing the packet. */ /* Disable interrupts while processing the packet. */
DISABLE_RX_IRQ(); DISABLE_RX_IRQ();
CC1020_SET_OPSTATE(CC1020_RX | CC1020_RX_PROCESSING); CC1020_SET_OPSTATE(CC1020_RX | CC1020_RX_PROCESSING);
_BIC_SR_IRQ(LPM3_bits); _BIC_SR_IRQ(LPM3_bits);
process_poll(&cc1020_receiver_process); process_poll(&cc1020_receiver_process);
} }
} }
@ -517,18 +516,15 @@ interrupt(UART0RX_VECTOR) cc1020_rxhandler(void)
static void static void
cc1020_write_reg(uint8_t addr, uint8_t adata) cc1020_write_reg(uint8_t addr, uint8_t adata)
{ {
unsigned i; unsigned int i;
unsigned char data; uint8_t data;
PSEL_OFF;
data = addr << 1; data = addr << 1;
PSEL_ON; PSEL_ON;
// Send address bits // Send address bits
for(i = 0; i < 7; i++) { for(i = 0; i < 7; i++) {
nop();
PCLK_LOW; PCLK_LOW;
nop();
if(data & 0x80) { if(data & 0x80) {
PDI_HIGH; PDI_HIGH;
} else { } else {
@ -536,24 +532,20 @@ cc1020_write_reg(uint8_t addr, uint8_t adata)
} }
data = data << 1; data = data << 1;
PCLK_HIGH; PCLK_HIGH;
nop();
} }
// Send read/write bit // Send read/write bit
// Ignore bit in data, always use 1 // Ignore bit in data, always use 1
nop();
PCLK_LOW; PCLK_LOW;
PDI_HIGH; PDI_HIGH;
nop();
PCLK_HIGH; PCLK_HIGH;
nop(); nop();
PCLK_LOW;
data = adata; data = adata;
// Send data bits // Send data bits
for(i = 0; i < 8; i++) { for(i = 0; i < 8; i++) {
nop();
PCLK_LOW; PCLK_LOW;
nop();
if(data & 0x80) { if(data & 0x80) {
PDI_HIGH; PDI_HIGH;
} else { } else {
@ -561,30 +553,25 @@ cc1020_write_reg(uint8_t addr, uint8_t adata)
} }
data = data << 1; data = data << 1;
PCLK_HIGH; PCLK_HIGH;
nop();
} }
nop();
PCLK_LOW; PCLK_LOW;
nop();
PSEL_OFF; PSEL_OFF;
} }
static uint8_t static uint8_t
cc1020_read_reg(uint8_t addr) cc1020_read_reg(uint8_t addr)
{ {
unsigned i; unsigned int i;
unsigned char data = 0; uint8_t data;
PSEL_OFF;
data = addr << 1; data = addr << 1;
PSEL_ON; PSEL_ON;
nop();
// Send address bits // Send address bits
for(i = 0; i < 7; i++) { for(i = 0; i < 7; i++) {
nop();
PCLK_LOW; PCLK_LOW;
nop();
if(data & 0x80) { if(data & 0x80) {
PDI_HIGH; PDI_HIGH;
} else { } else {
@ -592,14 +579,13 @@ cc1020_read_reg(uint8_t addr)
} }
data = data << 1; data = data << 1;
PCLK_HIGH; PCLK_HIGH;
nop();
} }
// Send read/write bit // Send read/write bit
// Ignore bit in data, always use 0 // Ignore bit in data, always use 0
nop();
PCLK_LOW; PCLK_LOW;
PDI_LOW; PDI_LOW;
nop();
PCLK_HIGH; PCLK_HIGH;
nop(); nop();
PCLK_LOW; PCLK_LOW;
@ -613,11 +599,9 @@ cc1020_read_reg(uint8_t addr)
if(PDO) { if(PDO) {
data++; data++;
} }
nop();
PCLK_LOW; PCLK_LOW;
} }
nop();
PSEL_OFF; PSEL_OFF;
return data; return data;
@ -697,15 +681,11 @@ cc1020_setupRX(int analog)
char lock_status; char lock_status;
// Switch into RX, switch to freq. reg A // Switch into RX, switch to freq. reg A
cc1020_write_reg(CC1020_MAIN, 0x11); cc1020_write_reg(CC1020_MAIN, 0x01);
// Setup bias current adjustment
cc1020_write_reg(CC1020_ANALOG, analog);
MS_DELAY(1); MS_DELAY(1);
lock_status = cc1020_lock(); lock_status = cc1020_lock();
// Switch RX part of CC1020 on // Switch RX part of CC1020 on
cc1020_write_reg(CC1020_MAIN, 0x01);
cc1020_write_reg(CC1020_INTERFACE, 0x02); cc1020_write_reg(CC1020_INTERFACE, 0x02);
// Return LOCK status to application // Return LOCK status to application
@ -717,9 +697,6 @@ cc1020_setupTX(int analog)
{ {
char lock_status; char lock_status;
// Setup bias current adjustment
cc1020_write_reg(CC1020_ANALOG, analog);
// Switch into TX, switch to freq. reg B // Switch into TX, switch to freq. reg B
cc1020_write_reg(CC1020_MAIN, 0xC1); cc1020_write_reg(CC1020_MAIN, 0xC1);
MS_DELAY(1); MS_DELAY(1);