Improvement batch.
This commit is contained in:
parent
b13e9dde90
commit
836eae63cb
|
@ -106,7 +106,7 @@ const u8_t cc1020_config_19200[41] = {
|
|||
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();
|
||||
|
@ -224,17 +222,16 @@ cc1020_set_tx(void)
|
|||
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) {
|
||||
|
@ -374,7 +370,6 @@ interrupt(UART0RX_VECTOR) cc1020_rxhandler(void)
|
|||
// disable receiver
|
||||
DISABLE_RX_IRQ();
|
||||
cc1020_rxstate = CC1020_RX_PROCESSING;
|
||||
printf("read %u bytes.\n", cc1020_rxlen);
|
||||
|
||||
// call receiver to copy from buffer
|
||||
if (receiver_callback != NULL)
|
||||
|
|
|
@ -60,13 +60,13 @@ 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));
|
||||
|
||||
|
@ -86,7 +86,7 @@ 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);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue