mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-12-23 01:29:33 +00:00
Improvement batch.
This commit is contained in:
parent
b13e9dde90
commit
836eae63cb
@ -54,17 +54,17 @@
|
||||
#define CC1020_STATUS7 0x4B
|
||||
|
||||
// For CC1020_STATUS
|
||||
#define LOCK_CONTINUOUS 0x10
|
||||
#define CAL_COMPLETE 0x80
|
||||
#define PA_POWER 0x0F // initial default for output power
|
||||
#define LOCK_NOK 0x00
|
||||
#define LOCK_OK 0x01
|
||||
#define LOCK_RECAL_OK 0x02
|
||||
#define CAL_TIMEOUT 0x7FFE
|
||||
#define LOCK_TIMEOUT 0x7FFE
|
||||
#define RESET_TIMEOUT 0x7FFE
|
||||
#define TX_CURRENT 0x87
|
||||
#define RX_CURRENT 0x86
|
||||
#define LOCK_CONTINUOUS 0x10
|
||||
#define CAL_COMPLETE 0x80
|
||||
#define PA_POWER 0x0F // initial default for output power
|
||||
#define LOCK_NOK 0x00
|
||||
#define LOCK_OK 0x01
|
||||
#define LOCK_RECAL_OK 0x02
|
||||
#define CAL_TIMEOUT 0x7FFE
|
||||
#define LOCK_TIMEOUT 0x7FFE
|
||||
#define RESET_TIMEOUT 0x7FFE
|
||||
#define TX_CURRENT 0x87
|
||||
#define RX_CURRENT 0x86
|
||||
|
||||
// CC1020 driver configuration
|
||||
#define CC1020_BUFFERSIZE 250
|
||||
@ -99,14 +99,14 @@
|
||||
#define ACK_TIMEOUT_115 4 // In RADIO_STROKE ticks
|
||||
#define ACK_TIMEOUT_19 16
|
||||
|
||||
#define MHZ_869525 1
|
||||
#define MHZ_869525 1
|
||||
|
||||
const u8_t cc1020_config_19200[41] = {
|
||||
0x01, // 0x00, MAIN
|
||||
0x0F, // 0x01, INTERFACE
|
||||
0xFF, // 0x02, RESET
|
||||
0x8F, // 0x03, SEQUENCING
|
||||
//869.525 bei 50kHz
|
||||
// 869.525 at 50kHz
|
||||
0x3A, // 0x04, FREQ_2A
|
||||
0x32, // 0x05, FREQ_1A
|
||||
0x97, // 0x06, FREQ_0A // 19200
|
||||
@ -152,7 +152,7 @@ const u8_t cc1020_config_115200[41] = {
|
||||
0x0F, // 0x01, INTERFACE
|
||||
0xFF, // 0x02, RESET
|
||||
0x8F, // 0x03, SEQUENCING
|
||||
// 869.525 bei 200kHz
|
||||
// 869.525 at 200kHz
|
||||
0x3A, // 0x04, FREQ_2A
|
||||
0x32, // 0x05, FREQ_1A
|
||||
0x97, // 0x06, FREQ_0A // 19200
|
||||
@ -204,17 +204,21 @@ enum cc1020_state {
|
||||
* @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};
|
||||
#define HDRSIZE 1 // number of bytes in header
|
||||
#define TAILSIZE 2 // number of bytes in tail
|
||||
#define TAIL 0xFA
|
||||
__attribute__((packed))
|
||||
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
|
||||
|
@ -84,7 +84,7 @@ static enum cc1020_rxstate cc1020_rxstate = CC1020_RX_SEARCHING;
|
||||
static unsigned short cc1020_rxlen = 0;
|
||||
|
||||
/// 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
|
||||
static unsigned char cc1020_pa_power = PA_POWER;
|
||||
@ -109,7 +109,6 @@ void
|
||||
cc1020_init(const u8_t *config)
|
||||
{
|
||||
cc1020_event = process_alloc_event();
|
||||
printf("cc1020_event = %d\n", cc1020_event);
|
||||
|
||||
cc1020_setupPD();
|
||||
cc1020_reset();
|
||||
@ -138,7 +137,6 @@ int
|
||||
cc1020_on(void)
|
||||
{
|
||||
if (cc1020_power_mode == CC1020_ALWAYS_ON) {
|
||||
|
||||
// Switch to receive mode
|
||||
cc1020_set_rx();
|
||||
} else {
|
||||
@ -152,6 +150,7 @@ cc1020_off(void)
|
||||
{
|
||||
if (cc1020_rxstate == CC1020_OFF)
|
||||
return;
|
||||
|
||||
LNA_POWER_OFF(); // power down lna
|
||||
_DINT();
|
||||
cc1020_rxstate = CC1020_OFF;
|
||||
@ -175,7 +174,7 @@ cc1020_set_rx(void)
|
||||
UCTL0 |= CHAR | SYNC; // 8-bit character, SPI, Slave mode
|
||||
|
||||
// CKPH works also, but not CKPH+CKPL or none of them!!
|
||||
UTCTL0 = CKPL + STC;
|
||||
UTCTL0 = CKPL | STC;
|
||||
URCTL0 = 0x00;
|
||||
UBR00 = 0x00; // No baudrate divider
|
||||
UBR10 = 0x00; // settings for a spi
|
||||
@ -202,7 +201,6 @@ cc1020_set_rx(void)
|
||||
void
|
||||
cc1020_set_tx(void)
|
||||
{
|
||||
|
||||
// configure radio rx
|
||||
LNA_POWER_OFF(); // power down LNA
|
||||
_DINT();
|
||||
@ -222,19 +220,18 @@ cc1020_set_tx(void)
|
||||
}
|
||||
|
||||
void
|
||||
cc1020_set_receiver(void (*recv) (void))
|
||||
cc1020_set_receiver(void (*recv)(void))
|
||||
{
|
||||
printf("cc1020_set_receiver\n");
|
||||
receiver_callback = recv;
|
||||
}
|
||||
|
||||
__inline void
|
||||
void
|
||||
cc1020_set_power_mode(enum cc1020_power_mode mode)
|
||||
{
|
||||
cc1020_power_mode = mode;
|
||||
}
|
||||
|
||||
__inline void
|
||||
void
|
||||
cc1020_set_power(u8_t pa_power)
|
||||
{
|
||||
cc1020_pa_power = pa_power;
|
||||
@ -260,7 +257,7 @@ cc1020_read(u8_t *buf, unsigned int bufsize)
|
||||
return 0;
|
||||
}
|
||||
|
||||
__inline u8_t
|
||||
u8_t
|
||||
cc1020_get_rssi(void)
|
||||
{
|
||||
return rssi;
|
||||
@ -276,8 +273,7 @@ cc1020_send(u8_t *buf, unsigned int len)
|
||||
if (cc1020_txlen > 0)
|
||||
return 0;
|
||||
|
||||
// prefix
|
||||
// (preamble+syncword are already in buffer)
|
||||
/* The preamble and the sync word are already in buffer. */
|
||||
cc1020_txlen = PREAMBLESIZE + SYNCWDSIZE;
|
||||
|
||||
// header
|
||||
@ -288,8 +284,8 @@ cc1020_send(u8_t *buf, unsigned int len)
|
||||
cc1020_txlen += len;
|
||||
|
||||
// suffix
|
||||
cc1020_txbuf[cc1020_txlen++] = 0xFA;
|
||||
cc1020_txbuf[cc1020_txlen++] = 0xFA;
|
||||
cc1020_txbuf[cc1020_txlen++] = TAIL;
|
||||
cc1020_txbuf[cc1020_txlen++] = TAIL;
|
||||
|
||||
process_poll(&cc1020_sender_process);
|
||||
|
||||
@ -318,7 +314,6 @@ interrupt(UART0RX_VECTOR) cc1020_rxhandler(void)
|
||||
shiftbuf.b2 = shiftbuf.b3;
|
||||
shiftbuf.b3 = shiftbuf.b4;
|
||||
shiftbuf.b4 = RXBUF0;
|
||||
|
||||
if (shiftbuf.i1 == 0xAAD3 && shiftbuf.i2 == 0x9100) {
|
||||
// 0 AA D3 91 00 | FF 00 |
|
||||
syncbs = 0;
|
||||
@ -348,9 +343,10 @@ interrupt(UART0RX_VECTOR) cc1020_rxhandler(void)
|
||||
return;
|
||||
}
|
||||
|
||||
cc1020_rxstate = CC1020_RX_RECEIVE;
|
||||
// Signal "Channel busy"
|
||||
// Update RSSI.
|
||||
rssi = cc1020_read_reg(CC1020_RSS);
|
||||
|
||||
cc1020_rxstate = CC1020_RX_RECEIVE;
|
||||
break;
|
||||
case CC1020_RX_RECEIVE:
|
||||
if (syncbs == 0) {
|
||||
@ -360,30 +356,29 @@ interrupt(UART0RX_VECTOR) cc1020_rxhandler(void)
|
||||
shiftbuf.b4 = RXBUF0;
|
||||
|
||||
if (syncbs < 0) {
|
||||
shiftbuf.i1 = shiftbuf.i2 << -syncbs;
|
||||
cc1020_rxbuf[cc1020_rxlen] = shiftbuf.b1;
|
||||
shiftbuf.i1 = shiftbuf.i2 << -syncbs;
|
||||
cc1020_rxbuf[cc1020_rxlen] = shiftbuf.b1;
|
||||
} else {
|
||||
shiftbuf.i1 = shiftbuf.i2 >> syncbs;
|
||||
cc1020_rxbuf[cc1020_rxlen] = shiftbuf.b2;
|
||||
shiftbuf.i1 = shiftbuf.i2 >> syncbs;
|
||||
cc1020_rxbuf[cc1020_rxlen] = shiftbuf.b2;
|
||||
}
|
||||
}
|
||||
|
||||
cc1020_rxlen++;
|
||||
if (cc1020_rxlen > HDRSIZE) {
|
||||
if (cc1020_rxlen == ((struct cc1020_header *) cc1020_rxbuf)->length) {
|
||||
// disable receiver
|
||||
DISABLE_RX_IRQ();
|
||||
cc1020_rxstate = CC1020_RX_PROCESSING;
|
||||
printf("read %u bytes.\n", cc1020_rxlen);
|
||||
// disable receiver
|
||||
DISABLE_RX_IRQ();
|
||||
cc1020_rxstate = CC1020_RX_PROCESSING;
|
||||
|
||||
// call receiver to copy from buffer
|
||||
if (receiver_callback != NULL)
|
||||
receiver_callback();
|
||||
// call receiver to copy from buffer
|
||||
if (receiver_callback != NULL)
|
||||
receiver_callback();
|
||||
|
||||
// reset receiver
|
||||
cc1020_rxlen = 0;
|
||||
cc1020_rxstate = CC1020_RX_SEARCHING;
|
||||
ENABLE_RX_IRQ();
|
||||
// reset receiver
|
||||
cc1020_rxlen = 0;
|
||||
cc1020_rxstate = CC1020_RX_SEARCHING;
|
||||
ENABLE_RX_IRQ();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -60,15 +60,15 @@ extern const u8_t cc1020_config_115200[];
|
||||
|
||||
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);
|
||||
|
||||
@ -86,9 +86,9 @@ unsigned int cc1020_read(u8_t *buf, unsigned int bufsize);
|
||||
*
|
||||
* 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;
|
||||
|
||||
|
@ -69,7 +69,7 @@ interrupt(DACDMA_VECTOR) irq_dacdma(void)
|
||||
}
|
||||
|
||||
void
|
||||
dma_transfer(char *buf, unsigned len)
|
||||
dma_transfer(unsigned char *buf, unsigned len)
|
||||
{
|
||||
// Configure DMA Channel 0 for UART0 TXIFG.
|
||||
DMACTL0 = DMA0TSEL_4;
|
||||
|
@ -28,12 +28,12 @@
|
||||
*
|
||||
* 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
|
||||
#define DMA_H
|
||||
|
||||
void dma_transfer(char *, unsigned);
|
||||
void dma_transfer(unsigned char *, unsigned);
|
||||
|
||||
#endif
|
||||
|
@ -7,7 +7,7 @@
|
||||
void
|
||||
slip_arch_writeb(unsigned char c)
|
||||
{
|
||||
rs232_send(c);
|
||||
rs232_send(c);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
@ -52,5 +52,5 @@ putchar(int c)
|
||||
void
|
||||
slip_arch_init(unsigned long ubr)
|
||||
{
|
||||
rs232_set_input(slip_input_byte);
|
||||
rs232_set_input(slip_input_byte);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user