split SPI code into generic and CC2420-related and renamed constants in CC2420
This commit is contained in:
parent
898c00b812
commit
f7a82a9145
3 changed files with 203 additions and 272 deletions
|
@ -28,7 +28,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* @(#)$Id: cc2420.c,v 1.55 2010/06/21 19:48:00 joxe Exp $
|
||||
* @(#)$Id: cc2420.c,v 1.56 2010/06/23 10:15:28 joxe Exp $
|
||||
*/
|
||||
/*
|
||||
* This code is almost device independent and should be easy to port.
|
||||
|
@ -150,42 +150,38 @@ static uint8_t receive_on;
|
|||
static int channel;
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint8_t rxptr; /* Pointer to the next byte in the rxfifo. */
|
||||
|
||||
static void
|
||||
getrxdata(void *buf, int len)
|
||||
{
|
||||
FASTSPI_READ_FIFO_NO_WAIT(buf, len);
|
||||
rxptr = (rxptr + len) & 0x7f;
|
||||
SPI_READ_FIFO_BUF(buf, len);
|
||||
}
|
||||
static void
|
||||
getrxbyte(uint8_t *byte)
|
||||
{
|
||||
FASTSPI_READ_FIFO_BYTE(*byte);
|
||||
rxptr = (rxptr + 1) & 0x7f;
|
||||
SPI_READ_FIFO_BYTE(*byte);
|
||||
}
|
||||
static void
|
||||
flushrx(void)
|
||||
{
|
||||
uint8_t dummy;
|
||||
|
||||
FASTSPI_READ_FIFO_BYTE(dummy);
|
||||
FASTSPI_STROBE(CC2420_SFLUSHRX);
|
||||
FASTSPI_STROBE(CC2420_SFLUSHRX);
|
||||
rxptr = 0;
|
||||
SPI_READ_FIFO_BYTE(dummy);
|
||||
SPI_STROBE(CC2420_SFLUSHRX);
|
||||
SPI_STROBE(CC2420_SFLUSHRX);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
strobe(enum cc2420_register regname)
|
||||
{
|
||||
FASTSPI_STROBE(regname);
|
||||
SPI_STROBE(regname);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static unsigned int
|
||||
status(void)
|
||||
{
|
||||
uint8_t status;
|
||||
FASTSPI_UPD_STATUS(status);
|
||||
SPI_GET_STATUS(status);
|
||||
return status;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -197,7 +193,7 @@ on(void)
|
|||
/* PRINTF("on\n");*/
|
||||
receive_on = 1;
|
||||
|
||||
ENABLE_FIFOP_INT();
|
||||
CC2420_ENABLE_FIFOP_INT();
|
||||
strobe(CC2420_SRXON);
|
||||
while(!(status() & (BV(CC2420_XOSC16M_STABLE))));
|
||||
ENERGEST_ON(ENERGEST_TYPE_LISTEN);
|
||||
|
@ -214,10 +210,10 @@ off(void)
|
|||
|
||||
ENERGEST_OFF(ENERGEST_TYPE_LISTEN);
|
||||
strobe(CC2420_SRFOFF);
|
||||
DISABLE_FIFOP_INT();
|
||||
CC2420_DISABLE_FIFOP_INT();
|
||||
LEDS_OFF(LEDS_GREEN);
|
||||
|
||||
if(!FIFOP_IS_1) {
|
||||
if(!CC2420_FIFOP_IS_1) {
|
||||
flushrx();
|
||||
}
|
||||
}
|
||||
|
@ -242,14 +238,14 @@ static unsigned
|
|||
getreg(enum cc2420_register regname)
|
||||
{
|
||||
unsigned reg;
|
||||
FASTSPI_GETREG(regname, reg);
|
||||
SPI_READ_REG(regname, reg);
|
||||
return reg;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
setreg(enum cc2420_register regname, unsigned value)
|
||||
{
|
||||
FASTSPI_SETREG(regname, value);
|
||||
SPI_WRITE_REG(regname, value);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
|
@ -276,8 +272,8 @@ cc2420_init(void)
|
|||
{
|
||||
int s = splhigh();
|
||||
cc2420_arch_init(); /* Initalize ports and SPI. */
|
||||
DISABLE_FIFOP_INT();
|
||||
FIFOP_INT_INIT();
|
||||
CC2420_DISABLE_FIFOP_INT();
|
||||
CC2420_FIFOP_INT_INIT();
|
||||
splx(s);
|
||||
}
|
||||
|
||||
|
@ -329,7 +325,7 @@ cc2420_init(void)
|
|||
cc2420_set_channel(26);
|
||||
|
||||
flushrx();
|
||||
|
||||
|
||||
process_start(&cc2420_process, NULL);
|
||||
return 1;
|
||||
}
|
||||
|
@ -377,12 +373,13 @@ cc2420_transmit(unsigned short payload_len)
|
|||
#endif /* WITH_SEND_CCA */
|
||||
|
||||
for(i = LOOP_20_SYMBOLS; i > 0; i--) {
|
||||
if(SFD_IS_1) {
|
||||
if(CC2420_SFD_IS_1) {
|
||||
if(!(status() & BV(CC2420_TX_ACTIVE))) {
|
||||
/* SFD went high but we are not transmitting. This means that
|
||||
we just started receiving a packet, so we drop the
|
||||
transmission. */
|
||||
RELEASE_LOCK();
|
||||
printf("CC2420 Collission\n");
|
||||
return RADIO_TX_COLLISION;
|
||||
}
|
||||
if(receive_on) {
|
||||
|
@ -453,10 +450,10 @@ cc2420_prepare(const void *payload, unsigned short payload_len)
|
|||
checksum = crc16_data(payload, payload_len, 0);
|
||||
#endif /* CC2420_CONF_CHECKSUM */
|
||||
total_len = payload_len + AUX_LEN;
|
||||
FASTSPI_WRITE_FIFO(&total_len, 1);
|
||||
FASTSPI_WRITE_FIFO(payload, payload_len);
|
||||
SPI_WRITE_FIFO_BUF(&total_len, 1);
|
||||
SPI_WRITE_FIFO_BUF(payload, payload_len);
|
||||
#if CC2420_CONF_CHECKSUM
|
||||
FASTSPI_WRITE_FIFO(&checksum, CHECKSUM_LEN);
|
||||
SPI_WRITE_FIFO_BUF(&checksum, CHECKSUM_LEN);
|
||||
#endif /* CC2420_CONF_CHECKSUM */
|
||||
|
||||
RELEASE_LOCK();
|
||||
|
@ -574,18 +571,18 @@ cc2420_set_pan_addr(unsigned pan,
|
|||
|
||||
tmp[0] = pan & 0xff;
|
||||
tmp[1] = pan >> 8;
|
||||
FASTSPI_WRITE_RAM_LE(&tmp, CC2420RAM_PANID, 2, f);
|
||||
SPI_WRITE_RAM(&tmp, CC2420RAM_PANID, 2);
|
||||
|
||||
tmp[0] = addr & 0xff;
|
||||
tmp[1] = addr >> 8;
|
||||
FASTSPI_WRITE_RAM_LE(&tmp, CC2420RAM_SHORTADDR, 2, f);
|
||||
SPI_WRITE_RAM(&tmp, CC2420RAM_SHORTADDR, 2);
|
||||
if(ieee_addr != NULL) {
|
||||
uint8_t tmp_addr[8];
|
||||
/* LSB first, MSB last for 802.15.4 addresses in CC2420 */
|
||||
for (f = 0; f < 8; f++) {
|
||||
tmp_addr[7 - f] = ieee_addr[f];
|
||||
}
|
||||
FASTSPI_WRITE_RAM_LE(tmp_addr, CC2420RAM_IEEEADDR, 8, f);
|
||||
SPI_WRITE_RAM(tmp_addr, CC2420RAM_IEEEADDR, 8);
|
||||
}
|
||||
RELEASE_LOCK();
|
||||
}
|
||||
|
@ -601,7 +598,7 @@ TIMETABLE_AGGREGATE(aggregate_time, 10);
|
|||
int
|
||||
cc2420_interrupt(void)
|
||||
{
|
||||
CLEAR_FIFOP_INT();
|
||||
CC2420_CLEAR_FIFOP_INT();
|
||||
process_poll(&cc2420_process);
|
||||
#if CC2420_TIMETABLE_PROFILING
|
||||
timetable_clear(&cc2420_timetable);
|
||||
|
@ -609,7 +606,6 @@ cc2420_interrupt(void)
|
|||
#endif /* CC2420_TIMETABLE_PROFILING */
|
||||
|
||||
pending++;
|
||||
|
||||
cc2420_packets_seen++;
|
||||
return 1;
|
||||
}
|
||||
|
@ -656,7 +652,7 @@ cc2420_read(void *buf, unsigned short bufsize)
|
|||
uint16_t checksum;
|
||||
#endif /* CC2420_CONF_CHECKSUM */
|
||||
|
||||
if(!FIFOP_IS_1) {
|
||||
if(!CC2420_FIFOP_IS_1) {
|
||||
return 0;
|
||||
}
|
||||
/* if(!pending) {
|
||||
|
@ -724,8 +720,8 @@ cc2420_read(void *buf, unsigned short bufsize)
|
|||
len = AUX_LEN;
|
||||
}
|
||||
|
||||
if(FIFOP_IS_1) {
|
||||
if(!FIFO_IS_1) {
|
||||
if(CC2420_FIFOP_IS_1) {
|
||||
if(!CC2420_FIFO_IS_1) {
|
||||
/* Clean up in case of FIFO overflow! This happens for every
|
||||
* full length frame and is signaled by FIFOP = 1 and FIFO =
|
||||
* 0. */
|
||||
|
@ -831,7 +827,7 @@ cc2420_cca(void)
|
|||
/* printf("cc2420_rssi: RSSI not valid.\n"); */
|
||||
}
|
||||
|
||||
cca = CCA_IS_1;
|
||||
cca = CC2420_CCA_IS_1;
|
||||
|
||||
if(radio_was_off) {
|
||||
cc2420_off();
|
||||
|
@ -843,13 +839,13 @@ cc2420_cca(void)
|
|||
int
|
||||
cc2420_receiving_packet(void)
|
||||
{
|
||||
return SFD_IS_1;
|
||||
return CC2420_SFD_IS_1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
pending_packet(void)
|
||||
{
|
||||
return FIFOP_IS_1;
|
||||
return CC2420_FIFOP_IS_1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue