Skip to content

Commit

Permalink
Merge branch 'mist' into qidevices
Browse files Browse the repository at this point in the history
Signed-off-by: Benoît Thébaudeau <[email protected]>
  • Loading branch information
bthebaudeau committed Nov 8, 2013
2 parents 39b0208 + 39bb2be commit cfd38ce
Show file tree
Hide file tree
Showing 1,582 changed files with 394,507 additions and 313 deletions.
4 changes: 3 additions & 1 deletion Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ CFLAGS += -DCONTIKI=1 -DCONTIKI_TARGET_$(TARGET_UPPERCASE)=1
include $(CONTIKI)/core/net/rime/Makefile.rime
include $(CONTIKI)/core/net/mac/Makefile.mac
SYSTEM = process.c procinit.c autostart.c elfloader.c profile.c \
timetable.c timetable-aggregate.c compower.c serial-line.c
compower.c serial-line.c
THREADS = mt.c
LIBS = memb.c mmem.c timer.c list.c etimer.c ctimer.c energest.c rtimer.c stimer.c trickle-timer.c \
print-stats.c ifft.c crc16.c random.c checkpoint.c ringbuf.c settings.c
Expand Down Expand Up @@ -266,6 +266,8 @@ endif
# in fact the primary target.
.PRECIOUS: %.$(TARGET)

.DELETE_ON_ERROR: $@

# Cancel the predefined implict rule for compiling and linking
# a single C source into a binary to force GNU make to consider
# the match-anything rule below instead.
Expand Down
2 changes: 1 addition & 1 deletion apps/shell/shell-tcpsend.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ SHELL_COMMAND(tcpsend_command,
&shell_tcpsend_process);
/*---------------------------------------------------------------------------*/

#define MAX_SERVERLEN 16
#define MAX_SERVERLEN 64

static uip_ipaddr_t serveraddr;
static char server[MAX_SERVERLEN + 1];
Expand Down
2 changes: 1 addition & 1 deletion apps/shell/shell-udpsend.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ SHELL_COMMAND(udpsend_command,
&shell_udpsend_process);
/*---------------------------------------------------------------------------*/

#define MAX_SERVERLEN 16
#define MAX_SERVERLEN 40

static struct uip_udp_conn *udpconn;

Expand Down
178 changes: 112 additions & 66 deletions core/dev/cc2420.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
*/

#include <string.h>
#include <stdio.h>

#include "contiki.h"

Expand Down Expand Up @@ -61,7 +62,7 @@
#endif /* CC2420_CONF_CHECKSUM */

#ifndef CC2420_CONF_AUTOACK
#define CC2420_CONF_AUTOACK 0
#define CC2420_CONF_AUTOACK 1
#endif /* CC2420_CONF_AUTOACK */

#if CC2420_CONF_CHECKSUM
Expand Down Expand Up @@ -105,6 +106,8 @@ int cc2420_authority_level_of_sender;

int cc2420_packets_seen, cc2420_packets_read;

static uint16_t pan, addr;

static uint8_t volatile pending;

#define BUSYWAIT_UNTIL(cond, max_time) \
Expand Down Expand Up @@ -141,6 +144,8 @@ static int cc2420_cca(void);
signed char cc2420_last_rssi;
uint8_t cc2420_last_correlation;

static int deep_sleep(void);

const struct radio_driver cc2420_driver =
{
cc2420_init,
Expand All @@ -155,6 +160,7 @@ const struct radio_driver cc2420_driver =
pending_packet,
cc2420_on,
cc2420_off,
deep_sleep
};

static uint8_t receive_on;
Expand Down Expand Up @@ -197,11 +203,96 @@ status(void)
return status;
}
/*---------------------------------------------------------------------------*/
static uint8_t locked, lock_on, lock_off;
#define AUTOACK (1 << 4)
#define ADR_DECODE (1 << 11)
#define RXFIFO_PROTECTION (1 << 9)
#define CORR_THR(n) (((n) & 0x1f) << 6)
#define FIFOP_THR(n) ((n) & 0x7f)
#define RXBPF_LOCUR (1 << 13);
/*---------------------------------------------------------------------------*/
static unsigned
getreg(enum cc2420_register regname)
{
unsigned reg;
CC2420_READ_REG(regname, reg);
return reg;
}
/*---------------------------------------------------------------------------*/
static void
setreg(enum cc2420_register regname, unsigned value)
{
CC2420_WRITE_REG(regname, value);
}
/*---------------------------------------------------------------------------*/
static void
powerup(void)
{
/* Turn on the crystal oscillator. */
strobe(CC2420_SXOSCON);
}

static void
configure(void)
{
uint16_t reg;
BUSYWAIT_UNTIL(status() & (BV(CC2420_XOSC16M_STABLE)), RTIMER_SECOND / 100);

/* Turn on/off automatic packet acknowledgment and address decoding. */
reg = getreg(CC2420_MDMCTRL0);

#if CC2420_CONF_AUTOACK
reg |= AUTOACK | ADR_DECODE;
#else
reg &= ~(AUTOACK | ADR_DECODE);
#endif /* CC2420_CONF_AUTOACK */
setreg(CC2420_MDMCTRL0, reg);

/* Set transmission turnaround time to the lower setting (8 symbols
= 0.128 ms) instead of the default (12 symbols = 0.192 ms). */
/* reg = getreg(CC2420_TXCTRL);
reg &= ~(1 << 13);
setreg(CC2420_TXCTRL, reg);*/

/* Change default values as recomended in the data sheet, */
/* correlation threshold = 20, RX bandpass filter = 1.3uA. */
setreg(CC2420_MDMCTRL1, CORR_THR(20));
reg = getreg(CC2420_RXCTRL1);
reg |= RXBPF_LOCUR;
setreg(CC2420_RXCTRL1, reg);

/* Set the FIFOP threshold to maximum. */
setreg(CC2420_IOCFG0, FIFOP_THR(127));

/* Turn off "Security enable" (page 32). */
reg = getreg(CC2420_SECCTRL0);
reg &= ~RXFIFO_PROTECTION;
setreg(CC2420_SECCTRL0, reg);

cc2420_set_pan_addr(pan, addr, NULL);
cc2420_set_channel(channel);

flushrx();

}
/*---------------------------------------------------------------------------*/
static uint8_t locked, lock_on, lock_off, completely_off;

static int
deep_sleep(void)
{
strobe(CC2420_SXOSCOFF);
completely_off = 1;
return 1;
}

static void
on(void)
{
if(completely_off) {
completely_off = 0;
powerup();
configure();
}
CC2420_ENABLE_FIFOP_INT();
strobe(CC2420_SRXON);

Expand Down Expand Up @@ -243,20 +334,6 @@ static void RELEASE_LOCK(void) {
locked--;
}
/*---------------------------------------------------------------------------*/
static unsigned
getreg(enum cc2420_register regname)
{
unsigned reg;
CC2420_READ_REG(regname, reg);
return reg;
}
/*---------------------------------------------------------------------------*/
static void
setreg(enum cc2420_register regname, unsigned value)
{
CC2420_WRITE_REG(regname, value);
}
/*---------------------------------------------------------------------------*/
static void
set_txpower(uint8_t power)
{
Expand All @@ -267,13 +344,6 @@ set_txpower(uint8_t power)
setreg(CC2420_TXCTRL, reg);
}
/*---------------------------------------------------------------------------*/
#define AUTOACK (1 << 4)
#define ADR_DECODE (1 << 11)
#define RXFIFO_PROTECTION (1 << 9)
#define CORR_THR(n) (((n) & 0x1f) << 6)
#define FIFOP_THR(n) ((n) & 0x7f)
#define RXBPF_LOCUR (1 << 13);
/*---------------------------------------------------------------------------*/
int
cc2420_init(void)
{
Expand All @@ -288,51 +358,19 @@ cc2420_init(void)

/* Turn on voltage regulator and reset. */
SET_VREG_ACTIVE();
clock_delay(250);
BUSYWAIT_UNTIL(0, RTIMER_SECOND / 100);
SET_RESET_ACTIVE();
clock_delay(127);
BUSYWAIT_UNTIL(0, RTIMER_SECOND / 100);
SET_RESET_INACTIVE();
clock_delay(125);


/* Turn on the crystal oscillator. */
strobe(CC2420_SXOSCON);

/* Turn on/off automatic packet acknowledgment and address decoding. */
reg = getreg(CC2420_MDMCTRL0);

#if CC2420_CONF_AUTOACK
reg |= AUTOACK | ADR_DECODE;
#else
reg &= ~(AUTOACK | ADR_DECODE);
#endif /* CC2420_CONF_AUTOACK */
setreg(CC2420_MDMCTRL0, reg);

/* Set transmission turnaround time to the lower setting (8 symbols
= 0.128 ms) instead of the default (12 symbols = 0.192 ms). */
/* reg = getreg(CC2420_TXCTRL);
reg &= ~(1 << 13);
setreg(CC2420_TXCTRL, reg);*/
BUSYWAIT_UNTIL(0, RTIMER_SECOND / 100);

pan = 0xffff;
addr = 0x0000;

/* Change default values as recomended in the data sheet, */
/* correlation threshold = 20, RX bandpass filter = 1.3uA. */
setreg(CC2420_MDMCTRL1, CORR_THR(20));
reg = getreg(CC2420_RXCTRL1);
reg |= RXBPF_LOCUR;
setreg(CC2420_RXCTRL1, reg);

/* Set the FIFOP threshold to maximum. */
setreg(CC2420_IOCFG0, FIFOP_THR(127));

/* Turn off "Security enable" (page 32). */
reg = getreg(CC2420_SECCTRL0);
reg &= ~RXFIFO_PROTECTION;
setreg(CC2420_SECCTRL0, reg);

cc2420_set_pan_addr(0xffff, 0x0000, NULL);
cc2420_set_channel(26);
BUSYWAIT_UNTIL(0, RTIMER_SECOND / 100);

powerup();
configure();
flushrx();

process_start(&cc2420_process, NULL);
Expand Down Expand Up @@ -459,6 +497,12 @@ cc2420_prepare(const void *payload, unsigned short payload_len)
/* Wait for any previous transmission to finish. */
/* while(status() & BV(CC2420_TX_ACTIVE));*/

if(completely_off) {
completely_off = 0;
powerup();
configure();
}

/* Write packet to TX FIFO. */
strobe(CC2420_SFLUSHTX);

Expand Down Expand Up @@ -570,15 +614,17 @@ cc2420_set_channel(int c)
}
/*---------------------------------------------------------------------------*/
void
cc2420_set_pan_addr(unsigned pan,
unsigned addr,
cc2420_set_pan_addr(uint16_t newpan,
uint16_t newaddr,
const uint8_t *ieee_addr)
{
uint16_t f = 0;
uint8_t tmp[2];

GET_LOCK();


pan = newpan;
addr = newaddr;
/*
* Writing RAM requires crystal oscillator to be stable.
*/
Expand Down
6 changes: 3 additions & 3 deletions core/dev/cc2420.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ int cc2420_init(void);
int cc2420_set_channel(int channel);
int cc2420_get_channel(void);

void cc2420_set_pan_addr(unsigned pan,
unsigned addr,
const uint8_t *ieee_addr);
void cc2420_set_pan_addr(uint16_t pan,
uint16_t addr,
const uint8_t *ieee_addr);

extern signed char cc2420_last_rssi;
extern uint8_t cc2420_last_correlation;
Expand Down
Loading

0 comments on commit cfd38ce

Please sign in to comment.