Improvement batch.

This commit is contained in:
nvt-se 2007-07-05 08:35:13 +00:00
parent b13e9dde90
commit 836eae63cb
6 changed files with 64 additions and 65 deletions

View file

@ -54,17 +54,17 @@
#define CC1020_STATUS7 0x4B #define CC1020_STATUS7 0x4B
// For CC1020_STATUS // For CC1020_STATUS
#define LOCK_CONTINUOUS 0x10 #define LOCK_CONTINUOUS 0x10
#define CAL_COMPLETE 0x80 #define CAL_COMPLETE 0x80
#define PA_POWER 0x0F // initial default for output power #define PA_POWER 0x0F // initial default for output power
#define LOCK_NOK 0x00 #define LOCK_NOK 0x00
#define LOCK_OK 0x01 #define LOCK_OK 0x01
#define LOCK_RECAL_OK 0x02 #define LOCK_RECAL_OK 0x02
#define CAL_TIMEOUT 0x7FFE #define CAL_TIMEOUT 0x7FFE
#define LOCK_TIMEOUT 0x7FFE #define LOCK_TIMEOUT 0x7FFE
#define RESET_TIMEOUT 0x7FFE #define RESET_TIMEOUT 0x7FFE
#define TX_CURRENT 0x87 #define TX_CURRENT 0x87
#define RX_CURRENT 0x86 #define RX_CURRENT 0x86
// CC1020 driver configuration // CC1020 driver configuration
#define CC1020_BUFFERSIZE 250 #define CC1020_BUFFERSIZE 250
@ -99,14 +99,14 @@
#define ACK_TIMEOUT_115 4 // In RADIO_STROKE ticks #define ACK_TIMEOUT_115 4 // In RADIO_STROKE ticks
#define ACK_TIMEOUT_19 16 #define ACK_TIMEOUT_19 16
#define MHZ_869525 1 #define MHZ_869525 1
const u8_t cc1020_config_19200[41] = { const u8_t cc1020_config_19200[41] = {
0x01, // 0x00, MAIN 0x01, // 0x00, MAIN
0x0F, // 0x01, INTERFACE 0x0F, // 0x01, INTERFACE
0xFF, // 0x02, RESET 0xFF, // 0x02, RESET
0x8F, // 0x03, SEQUENCING 0x8F, // 0x03, SEQUENCING
//869.525 bei 50kHz // 869.525 at 50kHz
0x3A, // 0x04, FREQ_2A 0x3A, // 0x04, FREQ_2A
0x32, // 0x05, FREQ_1A 0x32, // 0x05, FREQ_1A
0x97, // 0x06, FREQ_0A // 19200 0x97, // 0x06, FREQ_0A // 19200
@ -152,7 +152,7 @@ const u8_t cc1020_config_115200[41] = {
0x0F, // 0x01, INTERFACE 0x0F, // 0x01, INTERFACE
0xFF, // 0x02, RESET 0xFF, // 0x02, RESET
0x8F, // 0x03, SEQUENCING 0x8F, // 0x03, SEQUENCING
// 869.525 bei 200kHz // 869.525 at 200kHz
0x3A, // 0x04, FREQ_2A 0x3A, // 0x04, FREQ_2A
0x32, // 0x05, FREQ_1A 0x32, // 0x05, FREQ_1A
0x97, // 0x06, FREQ_0A // 19200 0x97, // 0x06, FREQ_0A // 19200
@ -204,17 +204,21 @@ enum cc1020_state {
* @name Packet specification * @name Packet specification
* @{ * @{
*/ */
#define PREAMBLESIZE 6 // number of bytes in preamble
#define PREAMBLE 0xAA
#define SYNCWDSIZE 2 // number of bytes in syncword
const u8_t syncword[2] = {0xD3,0x91}; const u8_t syncword[2] = {0xD3,0x91};
#define HDRSIZE 1 // number of bytes in header
#define TAILSIZE 2 // number of bytes in tail
#define TAIL 0xFA
__attribute__((packed)) __attribute__((packed))
struct cc1020_header { struct cc1020_header {
u8_t length; // header: number of bytes in packet (incl. header) u8_t length; // header: number of bytes in packet including header
}; };
#define PREAMBLESIZE 6
#define PREAMBLE 0xAA
#define TAILSIZE 2
#define TAIL 0xFA
#define SYNCWDSIZE (sizeof (syncword))
#define HDRSIZE (sizeof (struct cc1020_header))
///@} ///@}
/// cc1020 receiver state /// cc1020 receiver state

View file

@ -84,7 +84,7 @@ static enum cc1020_rxstate cc1020_rxstate = CC1020_RX_SEARCHING;
static unsigned short cc1020_rxlen = 0; static unsigned short cc1020_rxlen = 0;
/// received signal strength indicator reading for last received packet /// received signal strength indicator reading for last received packet
static unsigned char rssi; static volatile unsigned char rssi;
/// callback when a packet has been received /// callback when a packet has been received
static unsigned char cc1020_pa_power = PA_POWER; static unsigned char cc1020_pa_power = PA_POWER;
@ -109,7 +109,6 @@ void
cc1020_init(const u8_t *config) cc1020_init(const u8_t *config)
{ {
cc1020_event = process_alloc_event(); cc1020_event = process_alloc_event();
printf("cc1020_event = %d\n", cc1020_event);
cc1020_setupPD(); cc1020_setupPD();
cc1020_reset(); cc1020_reset();
@ -138,7 +137,6 @@ int
cc1020_on(void) cc1020_on(void)
{ {
if (cc1020_power_mode == CC1020_ALWAYS_ON) { if (cc1020_power_mode == CC1020_ALWAYS_ON) {
// Switch to receive mode // Switch to receive mode
cc1020_set_rx(); cc1020_set_rx();
} else { } else {
@ -152,6 +150,7 @@ cc1020_off(void)
{ {
if (cc1020_rxstate == CC1020_OFF) if (cc1020_rxstate == CC1020_OFF)
return; return;
LNA_POWER_OFF(); // power down lna LNA_POWER_OFF(); // power down lna
_DINT(); _DINT();
cc1020_rxstate = CC1020_OFF; cc1020_rxstate = CC1020_OFF;
@ -175,7 +174,7 @@ cc1020_set_rx(void)
UCTL0 |= CHAR | SYNC; // 8-bit character, SPI, Slave mode UCTL0 |= CHAR | SYNC; // 8-bit character, SPI, Slave mode
// CKPH works also, but not CKPH+CKPL or none of them!! // CKPH works also, but not CKPH+CKPL or none of them!!
UTCTL0 = CKPL + STC; UTCTL0 = CKPL | STC;
URCTL0 = 0x00; URCTL0 = 0x00;
UBR00 = 0x00; // No baudrate divider UBR00 = 0x00; // No baudrate divider
UBR10 = 0x00; // settings for a spi UBR10 = 0x00; // settings for a spi
@ -202,7 +201,6 @@ cc1020_set_rx(void)
void void
cc1020_set_tx(void) cc1020_set_tx(void)
{ {
// configure radio rx // configure radio rx
LNA_POWER_OFF(); // power down LNA LNA_POWER_OFF(); // power down LNA
_DINT(); _DINT();
@ -222,19 +220,18 @@ cc1020_set_tx(void)
} }
void void
cc1020_set_receiver(void (*recv) (void)) cc1020_set_receiver(void (*recv)(void))
{ {
printf("cc1020_set_receiver\n");
receiver_callback = recv; receiver_callback = recv;
} }
__inline void void
cc1020_set_power_mode(enum cc1020_power_mode mode) cc1020_set_power_mode(enum cc1020_power_mode mode)
{ {
cc1020_power_mode = mode; cc1020_power_mode = mode;
} }
__inline void void
cc1020_set_power(u8_t pa_power) cc1020_set_power(u8_t pa_power)
{ {
cc1020_pa_power = pa_power; cc1020_pa_power = pa_power;
@ -260,7 +257,7 @@ cc1020_read(u8_t *buf, unsigned int bufsize)
return 0; return 0;
} }
__inline u8_t u8_t
cc1020_get_rssi(void) cc1020_get_rssi(void)
{ {
return rssi; return rssi;
@ -276,8 +273,7 @@ cc1020_send(u8_t *buf, unsigned int len)
if (cc1020_txlen > 0) if (cc1020_txlen > 0)
return 0; return 0;
// prefix /* The preamble and the sync word are already in buffer. */
// (preamble+syncword are already in buffer)
cc1020_txlen = PREAMBLESIZE + SYNCWDSIZE; cc1020_txlen = PREAMBLESIZE + SYNCWDSIZE;
// header // header
@ -288,8 +284,8 @@ cc1020_send(u8_t *buf, unsigned int len)
cc1020_txlen += len; cc1020_txlen += len;
// suffix // suffix
cc1020_txbuf[cc1020_txlen++] = 0xFA; cc1020_txbuf[cc1020_txlen++] = TAIL;
cc1020_txbuf[cc1020_txlen++] = 0xFA; cc1020_txbuf[cc1020_txlen++] = TAIL;
process_poll(&cc1020_sender_process); process_poll(&cc1020_sender_process);
@ -318,7 +314,6 @@ interrupt(UART0RX_VECTOR) cc1020_rxhandler(void)
shiftbuf.b2 = shiftbuf.b3; shiftbuf.b2 = shiftbuf.b3;
shiftbuf.b3 = shiftbuf.b4; shiftbuf.b3 = shiftbuf.b4;
shiftbuf.b4 = RXBUF0; shiftbuf.b4 = RXBUF0;
if (shiftbuf.i1 == 0xAAD3 && shiftbuf.i2 == 0x9100) { if (shiftbuf.i1 == 0xAAD3 && shiftbuf.i2 == 0x9100) {
// 0 AA D3 91 00 | FF 00 | // 0 AA D3 91 00 | FF 00 |
syncbs = 0; syncbs = 0;
@ -348,9 +343,10 @@ interrupt(UART0RX_VECTOR) cc1020_rxhandler(void)
return; return;
} }
cc1020_rxstate = CC1020_RX_RECEIVE; // Update RSSI.
// Signal "Channel busy"
rssi = cc1020_read_reg(CC1020_RSS); rssi = cc1020_read_reg(CC1020_RSS);
cc1020_rxstate = CC1020_RX_RECEIVE;
break; break;
case CC1020_RX_RECEIVE: case CC1020_RX_RECEIVE:
if (syncbs == 0) { if (syncbs == 0) {
@ -360,30 +356,29 @@ interrupt(UART0RX_VECTOR) cc1020_rxhandler(void)
shiftbuf.b4 = RXBUF0; shiftbuf.b4 = RXBUF0;
if (syncbs < 0) { if (syncbs < 0) {
shiftbuf.i1 = shiftbuf.i2 << -syncbs; shiftbuf.i1 = shiftbuf.i2 << -syncbs;
cc1020_rxbuf[cc1020_rxlen] = shiftbuf.b1; cc1020_rxbuf[cc1020_rxlen] = shiftbuf.b1;
} else { } else {
shiftbuf.i1 = shiftbuf.i2 >> syncbs; shiftbuf.i1 = shiftbuf.i2 >> syncbs;
cc1020_rxbuf[cc1020_rxlen] = shiftbuf.b2; cc1020_rxbuf[cc1020_rxlen] = shiftbuf.b2;
} }
} }
cc1020_rxlen++; cc1020_rxlen++;
if (cc1020_rxlen > HDRSIZE) { if (cc1020_rxlen > HDRSIZE) {
if (cc1020_rxlen == ((struct cc1020_header *) cc1020_rxbuf)->length) { if (cc1020_rxlen == ((struct cc1020_header *) cc1020_rxbuf)->length) {
// disable receiver // disable receiver
DISABLE_RX_IRQ(); DISABLE_RX_IRQ();
cc1020_rxstate = CC1020_RX_PROCESSING; cc1020_rxstate = CC1020_RX_PROCESSING;
printf("read %u bytes.\n", cc1020_rxlen);
// call receiver to copy from buffer // call receiver to copy from buffer
if (receiver_callback != NULL) if (receiver_callback != NULL)
receiver_callback(); receiver_callback();
// reset receiver // reset receiver
cc1020_rxlen = 0; cc1020_rxlen = 0;
cc1020_rxstate = CC1020_RX_SEARCHING; cc1020_rxstate = CC1020_RX_SEARCHING;
ENABLE_RX_IRQ(); ENABLE_RX_IRQ();
} }
} }
break; break;

View file

@ -60,15 +60,15 @@ extern const u8_t cc1020_config_115200[];
void cc1020_init(const u8_t* config); void cc1020_init(const u8_t* config);
int cc1020_on(); int cc1020_on(void);
void cc1020_set_rx(); void cc1020_set_rx(void);
void cc1020_set_tx(); void cc1020_set_tx(void);
void cc1020_off(); void cc1020_off(void);
void cc1020_set_receiver(void (* recv)(void)); void cc1020_set_receiver(void (*recv)(void));
void cc1020_set_power_mode(enum cc1020_power_mode mode); void cc1020_set_power_mode(enum cc1020_power_mode mode);
@ -86,9 +86,9 @@ unsigned int cc1020_read(u8_t *buf, unsigned int bufsize);
* *
* Best to call in packet handler * Best to call in packet handler
*/ */
u8_t cc1020_get_rssi(); u8_t cc1020_get_rssi(void);
unsigned int cc1020_send(u8_t* buf, unsigned int bufsize); unsigned int cc1020_send(u8_t *buf, unsigned int bufsize);
extern const struct radio_driver cc1020_driver; extern const struct radio_driver cc1020_driver;

View file

@ -69,7 +69,7 @@ interrupt(DACDMA_VECTOR) irq_dacdma(void)
} }
void void
dma_transfer(char *buf, unsigned len) dma_transfer(unsigned char *buf, unsigned len)
{ {
// Configure DMA Channel 0 for UART0 TXIFG. // Configure DMA Channel 0 for UART0 TXIFG.
DMACTL0 = DMA0TSEL_4; DMACTL0 = DMA0TSEL_4;

View file

@ -28,12 +28,12 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: dma.h,v 1.2 2007/06/28 14:41:17 nvt-se Exp $ * $Id: dma.h,v 1.3 2007/07/05 08:35:13 nvt-se Exp $
*/ */
#ifndef DMA_H #ifndef DMA_H
#define DMA_H #define DMA_H
void dma_transfer(char *, unsigned); void dma_transfer(unsigned char *, unsigned);
#endif #endif

View file

@ -7,7 +7,7 @@
void void
slip_arch_writeb(unsigned char c) slip_arch_writeb(unsigned char c)
{ {
rs232_send(c); rs232_send(c);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -52,5 +52,5 @@ putchar(int c)
void void
slip_arch_init(unsigned long ubr) slip_arch_init(unsigned long ubr)
{ {
rs232_set_input(slip_input_byte); rs232_set_input(slip_input_byte);
} }