Switched to the NETSTACK API.

This commit is contained in:
nvt-se 2010-03-04 14:16:30 +00:00
parent 7543d53603
commit 2aa9d22f34
6 changed files with 105 additions and 119 deletions

View File

@ -1,7 +1,7 @@
SENSORS = sensors.c sht11.c SENSORS = sensors.c sht11.c
MSB = dma.c infomem.c node-id.c \ MSB = dma.c infomem.c node-id.c \
msb430-uart1.c rs232.c \ msb430-uart1.c rs232.c \
cc1020.c cc1020-uip.c adc.c init-net-rime.c \ cc1020.c cc1020-uip.c adc.c \
msb430-slip-arch.c sd.c sd-arch.c \ msb430-slip-arch.c sd.c sd-arch.c \
cfs-coffee.c cfs-coffee-arch.c cfs-coffee.c cfs-coffee-arch.c

View File

@ -6,6 +6,14 @@
#define WITH_SD 0 #define WITH_SD 0
#define NETSTACK_CONF_RADIO cc1020_driver
#define NETSTACK_CONF_RDC nullrdc_driver
#define NETSTACK_CONF_MAC nullmac_driver
#define NETSTACK_CONF_NETWORK rime_driver
#define NETSTACK_CONF_FRAMER framer_null
#define MAC_CONF_CHANNEL_CHECK_RATE 8
#define ENERGEST_CONF_ON 1 #define ENERGEST_CONF_ON 1
#define IRQ_PORT1 0x01 #define IRQ_PORT1 0x01

View File

@ -120,13 +120,24 @@ main(void)
} }
#endif #endif
/* System services */ node_id_restore();
/* System timers */
process_start(&etimer_process, NULL); process_start(&etimer_process, NULL);
ctimer_init(); ctimer_init();
node_id_restore(); /* Networking stack. */
NETSTACK_RADIO.init();
init_net(); NETSTACK_RDC.init();
NETSTACK_MAC.init();
NETSTACK_NETWORK.init();
{
rimeaddr_t rimeaddr;
rimeaddr.u8[0] = node_id & 0xff;
rimeaddr.u8[1] = node_id >> 8;
rimeaddr_set_node_addr(&rimeaddr);
}
energest_init(); energest_init();
@ -136,8 +147,11 @@ main(void)
leds_off(LEDS_ALL); leds_off(LEDS_ALL);
printf(CONTIKI_VERSION_STRING " started. Node id %u, using %s.\n", printf("%d.%d: %s %s, channel check rate %u Hz\n",
node_id, rime_mac->name); rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
NETSTACK_MAC.name, NETSTACK_RDC.name,
CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ?
1 : (unsigned)NETSTACK_RDC.channel_check_interval()));
autostart_start(autostart_processes); autostart_start(autostart_processes);

View File

@ -94,13 +94,28 @@ static uint8_t cc1020_pa_power = PA_POWER;
static volatile char dma_done; static volatile char dma_done;
static void (*receiver_callback)(const struct radio_driver *); /* Radio driver AAPI functions. */
static int cc1020_init(void);
static int cc1020_prepare(const void *payload, unsigned short payload_len);
static int cc1020_transmit(unsigned short transmit_len);
static int cc1020_send(const void *payload, unsigned short payload_len);
static int cc1020_read(void *buf, unsigned short buf_len);
static int cc1020_channel_clear(void);
static int cc1020_receiving_packet(void);
static int cc1020_pending_packet(void);
static int cc1020_on(void);
static int cc1020_off(void);
const struct radio_driver cc1020_driver = const struct radio_driver cc1020_driver =
{ {
cc1020_init,
cc1020_prepare,
cc1020_transmit,
cc1020_send, cc1020_send,
cc1020_read, cc1020_read,
cc1020_set_receiver, cc1020_channel_clear,
cc1020_receiving_packet,
cc1020_pending_packet,
cc1020_on, cc1020_on,
cc1020_off cc1020_off
}; };
@ -130,12 +145,12 @@ reset_receiver(void)
} }
} }
void static int
cc1020_init(const uint8_t *config) cc1020_init(void)
{ {
cc1020_setupPD(); cc1020_setupPD();
cc1020_reset(); cc1020_reset();
cc1020_load_config(config); cc1020_load_config(cc1020_config_19200);
/* init tx buffer with preamble + syncword */ /* init tx buffer with preamble + syncword */
memset(cc1020_txbuf, PREAMBLE, PREAMBLE_SIZE); memset(cc1020_txbuf, PREAMBLE, PREAMBLE_SIZE);
@ -146,12 +161,14 @@ cc1020_init(const uint8_t *config)
cc1020_wakeupRX(RX_CURRENT); cc1020_wakeupRX(RX_CURRENT);
if(!cc1020_calibrate()) { if(!cc1020_calibrate()) {
PRINTF("cc1020: rx calibration failed\n"); PRINTF("cc1020: rx calibration failed\n");
return -1;
} }
/* calibrate transmitter */ /* calibrate transmitter */
cc1020_wakeupTX(TX_CURRENT); cc1020_wakeupTX(TX_CURRENT);
if(!cc1020_calibrate()) { if(!cc1020_calibrate()) {
PRINTF("cc1020: tx calibration failed\n"); PRINTF("cc1020: tx calibration failed\n");
return -1;
} }
/* power down */ /* power down */
@ -159,6 +176,8 @@ cc1020_init(const uint8_t *config)
process_start(&cc1020_receiver_process, NULL); process_start(&cc1020_receiver_process, NULL);
dma_subscribe(0, dma_callback); dma_subscribe(0, dma_callback);
return 0;
} }
void void
@ -231,10 +250,21 @@ cc1020_set_power(uint8_t pa_power)
cc1020_pa_power = pa_power; cc1020_pa_power = pa_power;
} }
int static int
cc1020_prepare(const void *payload, unsigned short payload_len)
{
return -1;
}
static int
cc1020_transmit(unsigned short transmit_len)
{
return 0;
}
static int
cc1020_send(const void *buf, unsigned short len) cc1020_send(const void *buf, unsigned short len)
{ {
int try;
int normal_header = HDR_SIZE + len; int normal_header = HDR_SIZE + len;
uint16_t rxcrc = 0xffff; /* For checksum purposes */ uint16_t rxcrc = 0xffff; /* For checksum purposes */
rtimer_clock_t timeout_time; rtimer_clock_t timeout_time;
@ -280,23 +310,6 @@ cc1020_send(const void *buf, unsigned short len)
cc1020_txbuf[cc1020_txlen++] = TAIL; cc1020_txbuf[cc1020_txlen++] = TAIL;
cc1020_txbuf[cc1020_txlen++] = TAIL; cc1020_txbuf[cc1020_txlen++] = TAIL;
/* Wait for the medium to become idle. */
if(cc1020_carrier_sense()) {
for(try = 0; try < CC1020_CONF_CCA_TIMEOUT; try++) {
MS_DELAY(1);
if(!cc1020_carrier_sense()) {
break;
}
}
if(try == CC1020_CONF_CCA_TIMEOUT) {
PRINTF("cc1020: CCA failed (RSSI %d)\n", cc1020_get_rssi());
return RADIO_TX_ERR;
}
/* Then wait for a short pseudo-random time before sending. */
clock_delay(100 * ((random_rand() + 1) & 0xf));
}
/* Switch to transceive mode. */ /* Switch to transceive mode. */
cc1020_set_tx(); cc1020_set_tx();
@ -319,7 +332,7 @@ cc1020_send(const void *buf, unsigned short len)
return RADIO_TX_OK; return RADIO_TX_OK;
} }
int static int
cc1020_read(void *buf, unsigned short size) cc1020_read(void *buf, unsigned short size)
{ {
unsigned len; unsigned len;
@ -336,16 +349,27 @@ cc1020_read(void *buf, unsigned short size)
memcpy(buf, (char *)cc1020_rxbuf + HDR_SIZE, len); memcpy(buf, (char *)cc1020_rxbuf + HDR_SIZE, len);
RIMESTATS_ADD(llrx); RIMESTATS_ADD(llrx);
reset_receiver(); reset_receiver();
return len; return len;
} }
void static int
cc1020_set_receiver(void (*recv)(const struct radio_driver *)) cc1020_channel_clear(void)
{ {
receiver_callback = recv; return (cc1020_read_reg(CC1020_STATUS) & CARRIER_SENSE);
}
static int
cc1020_receiving_packet(void)
{
return cc1020_state & CC1020_RX_RECEIVING;
}
static int
cc1020_pending_packet(void)
{
return cc1020_state & CC1020_RX_PROCESSING;
} }
int int
@ -398,40 +422,36 @@ cc1020_get_packet_rssi(void)
return rssi; return rssi;
} }
int
cc1020_carrier_sense(void)
{
return (cc1020_read_reg(CC1020_STATUS) & CARRIER_SENSE);
}
PROCESS_THREAD(cc1020_receiver_process, ev, data) PROCESS_THREAD(cc1020_receiver_process, ev, data)
{ {
int len;
PROCESS_BEGIN(); PROCESS_BEGIN();
while(1) { while(1) {
ev = PROCESS_EVENT_NONE; ev = PROCESS_EVENT_NONE;
PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL); PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
if(receiver_callback != NULL) {
/* Verify the checksum. */
uint16_t expected_crc = 0xffff;
uint16_t actual_crc;
actual_crc = (cc1020_rxbuf[cc1020_rxlen - CRC_SIZE] << 8) | /* Verify the checksum. */
cc1020_rxbuf[cc1020_rxlen - CRC_SIZE + 1]; uint16_t expected_crc = 0xffff;
cc1020_rxlen -= CRC_SIZE; uint16_t actual_crc;
actual_crc = (cc1020_rxbuf[cc1020_rxlen - CRC_SIZE] << 8) |
cc1020_rxbuf[cc1020_rxlen - CRC_SIZE + 1];
cc1020_rxlen -= CRC_SIZE;
expected_crc = crc16_add(cc1020_rxlen & 0xff, expected_crc); expected_crc = crc16_add(cc1020_rxlen & 0xff, expected_crc);
expected_crc = crc16_add((cc1020_rxlen >> 8) & 0xff, expected_crc); expected_crc = crc16_add((cc1020_rxlen >> 8) & 0xff, expected_crc);
expected_crc = crc16_data((char *)&cc1020_rxbuf[HDR_SIZE], expected_crc = crc16_data((char *)&cc1020_rxbuf[HDR_SIZE],
cc1020_rxlen - HDR_SIZE, expected_crc); cc1020_rxlen - HDR_SIZE, expected_crc);
if(expected_crc == actual_crc) { if(expected_crc == actual_crc) {
receiver_callback(&cc1020_driver); len = cc1020_read(packetbuf_dataptr(), PACKETBUF_SIZE);
} else { packetbuf_set_datalen(len);
RIMESTATS_ADD(badcrc); NETSTACK_RDC.input();
reset_receiver(); } else {
} RIMESTATS_ADD(badcrc);
reset_receiver();
} }
} }

View File

@ -53,7 +53,9 @@ Berlin, 2006
extern const uint8_t cc1020_config_19200[]; extern const uint8_t cc1020_config_19200[];
extern const uint8_t cc1020_config_115200[]; extern const uint8_t cc1020_config_115200[];
#if 0
void cc1020_init(const uint8_t* config); void cc1020_init(const uint8_t* config);
#endif
void cc1020_set_rx(void); void cc1020_set_rx(void);
void cc1020_set_tx(void); void cc1020_set_tx(void);
void cc1020_set_power(uint8_t pa_power); void cc1020_set_power(uint8_t pa_power);
@ -61,13 +63,13 @@ int cc1020_carrier_sense(void);
uint8_t cc1020_get_rssi(void); uint8_t cc1020_get_rssi(void);
uint8_t cc1020_get_packet_rssi(void); uint8_t cc1020_get_packet_rssi(void);
int cc1020_sending(void); int cc1020_sending(void);
#if 0
int cc1020_send(const void *buf, unsigned short size); int cc1020_send(const void *buf, unsigned short size);
int cc1020_read(void *buf, unsigned short size); int cc1020_read(void *buf, unsigned short size);
void cc1020_set_receiver(void (*recv)(const struct radio_driver *)); void cc1020_set_receiver(void (*recv)(const struct radio_driver *));
int cc1020_on(void); int cc1020_on(void);
int cc1020_off(void); int cc1020_off(void);
#endif
extern const struct radio_driver cc1020_driver; extern const struct radio_driver cc1020_driver;
PROCESS_NAME(cc1020_sender_process); PROCESS_NAME(cc1020_sender_process);

View File

@ -1,58 +0,0 @@
/*
* Copyright (c) 2007, Swedish Institute of Computer Science
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
*/
/**
* \file
* Rime initialization for the MSB-430 port.
* \author
* Nicolas Tsiftes <nvt@sics.se>
*/
#include "contiki.h"
#include "node-id.h"
#include "dev/cc1020.h"
#include "net/mac/nullmac.h"
#include "net/mac/lpp.h"
#include "net/rime.h"
#include "contiki-msb430.h"
void
init_net(void)
{
rimeaddr_t rimeaddr;
cc1020_init(cc1020_config_19200);
rime_init(lpp_init(&cc1020_driver));
rimeaddr.u8[0] = node_id & 0xff;
rimeaddr.u8[1] = node_id >> 8;
rimeaddr_set_node_addr(&rimeaddr);
}