Use IP over Rime

This commit is contained in:
ksb 2009-07-11 15:07:59 +00:00
parent 88669e1675
commit 3c3714c178
9 changed files with 265 additions and 118 deletions

View file

@ -9,6 +9,8 @@ CONTIKI=../..
CORE=core-nosyms.$(TARGET)
CONTIKI_TARGET_MAIN=contiki-main.c
codeprop: $(CONTIKI)/tools/codeprop.c
cc -g -Wall $< -o $@

View file

@ -1,7 +1,7 @@
STEPPER_ROBOT = leds.c leds-arch.c sam7s-spi.c stepper-process.c stepper.c stepper-interrupt.c stepper-move.c
CODEPROP_SOURCES = codeprop-otf.c ram-segments.c
UIPDRIVERS= cc2420.c cc2420_send_ip.c cc2420_send_uaodv.c cc2420-interrupt.c \
#CODEPROP_SOURCES = codeprop-otf.c ram-segments.c
UIPDRIVERS= cc2420.c cc2420-interrupt.c \
cc2420-spi.c slip.c
CONTIKI_TARGET_DIRS = . stepper
@ -19,7 +19,7 @@ CONTIKI_TARGET_SOURCEFILES += $(SENSORS) $(STEPPER_ROBOT) \
# include $(CONTIKI)/platform/$(TARGET)/apps/Makefile.apps
include $(CONTIKI)/cpu/at91sam7s/Makefile.at91sam7s
include $(CONTIKI)/cpu/arm/at91sam7s/Makefile.at91sam7s
#contiki-$(TARGET).a: ${addprefix $(OBJECTDIR)/,symbols.o}

View file

@ -10,8 +10,8 @@ cc2420_fifop_interrupt (void) /* System Interrupt Handler */
{
ISR_STORE();
ISR_ENABLE_NEST();
__cc2420_intr();
ISR_DISABLE_NEST();
cc2420_interrupt();
ISR_DISABLE_NEST();
*AT91C_AIC_EOICR = 0; /* End of Interrupt */
ISR_RESTORE();
}

View file

@ -13,7 +13,7 @@
#endif
void
__cc2420_arch_init(void)
cc2420_arch_init(void)
{
spi_init();

View file

@ -44,8 +44,8 @@ typedef unsigned int uip_stats_t;
#define SFD_IS_1 (*AT91C_PIOA_PDSR & AT91C_PIO_PA15)
#define CCA_IS_1 1
#define SET_RESET_INACTIVE() cc2420_setreg(CC2420_MAIN, 0xf800);
#define SET_RESET_ACTIVE() cc2420_setreg(CC2420_MAIN, 0x0000);
#define SET_RESET_INACTIVE() setreg(CC2420_MAIN, 0xf800);
#define SET_RESET_ACTIVE() setreg(CC2420_MAIN, 0x0000);
#define SET_VREG_ACTIVE()
#define SET_VREG_INACTIVE()
@ -66,7 +66,7 @@ do { \
#define SPI_DISABLE() (*AT91C_SPI_CR = AT91C_SPI_LASTXFER)
#define CLEAR_FIFOP_INT() /* Cleared by the wrapper */
#define CLEAR_FIFOP_INT() (*AT91C_AIC_ICCR = (1 << AT91C_ID_IRQ1))
#define LOOP_20_SYMBOLS (MCK/28125) /* Assume the loop takes 9 cycles */
@ -76,7 +76,18 @@ do { \
#define UIP_CONF_LOGGING 1
#define UIP_CONF_BUFFER_SIZE 116
#define UIP_CONF_TCP_FORWARD 1
/* USB definitions */
#define USB_EP1_SIZE 64
#define USB_EP2_SIZE 64
#define USB_EP3_SIZE 64
#define USB_RBC_NUM_BLOCKS 16
/* Prefix for relocation sections in ELF files */
#define REL_SECT_PREFIX ".rel"
#define CC_BYTE_ALIGNED __attribute__ ((packed, aligned(1)))
#endif /* __CONTIKI_CONF_H__CDBB4VIH3I__ */

View file

@ -4,9 +4,6 @@
#include <debug-uart.h>
#include <ctype.h>
#include <stdio.h>
#include <net/uip.h>
#include "net/uip-fw-drv.h"
#include "net/uaodv.h"
#include <dev/cc2420.h>
#include <dev/cc2420_const.h>
#include <dev/spi.h>
@ -18,16 +15,62 @@
#include <net/psock.h>
#include <unistd.h>
#include "net/mac/nullmac.h"
#include "net/rime.h"
#include "contiki-main.h"
#ifndef RF_CHANNEL
#define RF_CHANNEL 15
#endif
#if WITH_UIP
#include "net/uip.h"
#include "net/uip-fw.h"
#include "net/uip-fw-drv.h"
#include "net/uip-over-mesh.h"
static struct uip_fw_netif meshif =
{UIP_FW_NETIF(172,16,0,0, 255,255,0,0, uip_over_mesh_send)};
#define UIP_OVER_MESH_CHANNEL 9
uint8_t is_gateway = 0;
struct trickle_conn gateway_trickle;
#endif /* WITH_UIP */
extern char __heap_end__;
extern char __heap_start__;
struct uip_fw_netif cc2420if =
{UIP_FW_NETIF(172,16,0,129, 255,255,0,0, cc2420_send_ip)};
rimeaddr_t node_addr __attribute__((weak)) = {{0,2}};
/*--------------------------------------------------------------------------*/
#if WITH_UIP
/* Receive address of gateway */
static void
trickle_recv(struct trickle_conn *c)
{
if (!is_gateway) {
struct gateway_msg *msg;
msg = rimebuf_dataptr();
printf("%d.%d: gateway message: %d.%d\n",
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
msg->gateway.u8[0], msg->gateway.u8[1]);
uip_over_mesh_set_gateway(&msg->gateway);
}
}
const static struct trickle_callbacks trickle_call = {trickle_recv};
/*---------------------------------------------------------------------------*/
#endif
#if 0
/* Wathcdog is already disabled in startup code */
@ -48,10 +91,6 @@ wdt_reset()
static uip_ipaddr_t gw_addr = {{172,16,0,1}};
#endif
PROCINIT(&etimer_process, &tcpip_process, &cc2420_process,
&uip_fw_process /*, &uaodv_process */
);
int
main()
@ -64,24 +103,65 @@ main()
dbg_setup_uart();
printf("Initialising\n");
leds_arch_init();
leds_init();
clock_init();
uip_sethostaddr(&cc2420if.ipaddr);
uip_setnetmask(&cc2420if.netmask);
/*uip_setdraddr(&gw_addr);*/
cc2420_init();
cc2420_set_chan_pan_addr(RF_CHANNEL, HTONS(0x2024), uip_hostaddr.u16[1], NULL);
process_init();
uip_init();
uip_fw_default(&cc2420if);
tcpip_set_forwarding(1);
process_start(&etimer_process, NULL);
ctimer_init();
enableIRQ();
printf("Beginning CC2420 setup\n");
cc2420_init();
cc2420_set_pan_addr(0x2024, 0, NULL);
cc2420_set_channel(RF_CHANNEL);
rime_init(nullmac_init(&cc2420_driver));
printf("CC2420 setup done\n");
rimeaddr_set_node_addr(&node_addr);
printf("Rime started with address %d.%d\n", node_addr.u8[0], node_addr.u8[1]);
#if WITH_UIP
{
uip_ipaddr_t hostaddr, netmask;
uip_init();
uip_ipaddr(&hostaddr, 172,16,
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1]);
uip_ipaddr(&netmask, 255,255,0,0);
uip_ipaddr_copy(&meshif.ipaddr, &hostaddr);
printf("Host addr\n");
uip_sethostaddr(&hostaddr);
uip_setnetmask(&netmask);
uip_over_mesh_set_net(&hostaddr, &netmask);
/* uip_fw_register(&slipif);*/
/*uip_over_mesh_set_gateway_netif(&slipif);*/
uip_fw_register(&meshif);
uip_fw_default(&meshif);
printf("Mesh init\n");
uip_over_mesh_init(UIP_OVER_MESH_CHANNEL);
printf("uIP started with IP address %d.%d.%d.%d\n",
uip_ipaddr_to_quad(&hostaddr));
}
#endif /* WITH_UIP */
#if WITH_UIP
process_start(&tcpip_process, NULL);
process_start(&uip_fw_process, NULL); /* Start IP output */
trickle_open(&gateway_trickle, CLOCK_SECOND * 4, GATEWAY_TRICKLE_CHANNEL,
&trickle_call);
#endif /* WITH_UIP */
printf("Heap size: %ld bytes\n", &__heap_end__ - (char*)sbrk(0));
printf("Started\n");
procinit_init();
enableIRQ();
cc2420_on();
/* procinit_init(); */
autostart_start(autostart_processes);
printf("Processes running\n");
while(1) {

View file

@ -8,12 +8,17 @@
#include <debug-uart.h>
#include <net/uip-fw-drv.h>
#include <net/uip-over-mesh.h>
#include <dev/slip.h>
#include "contiki-main.h"
/* SLIP interface */
extern struct uip_fw_netif cc2420if;
rimeaddr_t node_addr = {{0,129}};
static struct uip_fw_netif slipif =
{UIP_FW_NETIF(0,0,0,0, 255,255,255,255, slip_send)};
@ -25,6 +30,7 @@ static unsigned char interrupt_buffer[16];
#define DEV_TO_HOST 0x81
#define HOST_TO_DEV 0x02
#define GATEWAY_TRICKLE_CHANNEL 8
void
slip_arch_init(unsigned long ubr)
{
@ -36,6 +42,26 @@ slip_arch_writeb(unsigned char c)
while(usb_send_data(DEV_TO_HOST, &c, 1) != 1);
}
#if WITH_UIP
static void
set_gateway(void)
{
struct gateway_msg msg;
/* Make this node the gateway node, unless it already is the
gateway. */
if(!is_gateway) {
leds_on(LEDS_RED);
printf("%d.%d: making myself the gateway\n",
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]);
uip_over_mesh_set_gateway(&rimeaddr_node_addr);
rimeaddr_copy(&(msg.gateway), &rimeaddr_node_addr);
rimebuf_copyfrom(&msg, sizeof(struct gateway_msg));
trickle_send(&gateway_trickle);
is_gateway = 1;
}
}
#endif /* WITH_UIP */
PROCESS(gateway_process, "Gateway process");
@ -49,14 +75,17 @@ PROCESS_THREAD(gateway_process, ev , data)
usb_cdc_acm_setup();
uip_fw_default(&slipif);
uip_fw_register(&cc2420if);
uip_over_mesh_set_gateway_netif(&slipif);
process_start(&slip_process, NULL);
set_gateway();
while(ev != PROCESS_EVENT_EXIT) {
PROCESS_WAIT_EVENT();
if (ev == PROCESS_EVENT_TIMER) {
leds_toggle(LEDS_YELLOW);
/* printf("FIFOP: %d\n", FIFOP_IS_1); */
etimer_restart(&timer);
} else if (ev == PROCESS_EVENT_MSG) {
const struct usb_user_msg * const msg = data;
@ -81,8 +110,8 @@ PROCESS_THREAD(gateway_process, ev , data)
break;
case USB_USER_MSG_TYPE_EP_OUT(2):
{
unsigned int len = msg->data.length;
/* printf("Received %d:\n", len); */
/*unsigned int len = msg->data.length;
printf("Received %d:\n", len); */
{
unsigned char ch;
unsigned int xfer;

View file

@ -4,9 +4,6 @@
#include <debug-uart.h>
#include <ctype.h>
#include <stdio.h>
#include <net/uip.h>
#include "net/uip-fw-drv.h"
#include "net/uaodv.h"
#include <dev/cc2420.h>
#include <dev/cc2420_const.h>
#include <dev/spi.h>
@ -22,11 +19,33 @@
#include <stepper.h>
#include <stepper-move.h>
#include "net/mac/nullmac.h"
#include "net/rime.h"
#ifndef RF_CHANNEL
#define RF_CHANNEL 15
#endif
#ifndef WITH_UIP
#define WITH_UIP 1
#endif
#if WITH_UIP
#include "net/uip.h"
#include "net/uip-fw.h"
#include "net/uip-fw-drv.h"
#include "net/uip-over-mesh.h"
static struct uip_fw_netif meshif =
{UIP_FW_NETIF(172,16,0,0, 255,255,0,0, uip_over_mesh_send)};
#define UIP_OVER_MESH_CHANNEL 9
#endif /* WITH_UIP */
static rimeaddr_t node_addr = {{0,2}};
extern char __heap_end__;
extern char __heap_start__;
@ -66,69 +85,6 @@ robot_stepper_init()
stepper1_steps_run, stepper1_steps_hold,
(sizeof(stepper1_steps_run) / sizeof(stepper1_steps_run[0])));}
struct uip_fw_netif cc2420if =
{UIP_FW_NETIF(172,16,0,2, 255,255,0,0, cc2420_send_ip)};
#if 0
PROCESS(udprecv_process, "UDP recv process");
PROCESS_THREAD(udprecv_process, ev, data)
{
static struct uip_udp_conn *c;
PROCESS_EXITHANDLER(goto exit);
PROCESS_BEGIN();
printf("udprecv_process starting\n");
{
uip_ipaddr_t any;
uip_ipaddr(&any, 0,0,0,0);
c = udp_new(&any, HTONS(0), NULL);
uip_udp_bind(c, HTONS(4321));
}
while(1) {
PROCESS_YIELD();
if(ev == tcpip_event && uip_newdata()) {
u8_t *src = ((struct uip_udpip_hdr *)uip_buf)->srcipaddr.u8;
printf("%d.%d.%d.%d: %s\n",
src[0], src[1], src[2], src[3], (char *)uip_appdata);
}
}
exit:
/* Contiki does automatic garbage collection of uIP state and we
* need not worry about that. */
printf("udprecv_process exiting\n");
PROCESS_END();
}
PROCESS(wd_test_process, "Watchdog test process");
PROCESS_THREAD(wd_test_process, ev, data)
{
static struct etimer timer;
PROCESS_BEGIN();
printf("tcp_test_process starting\n");
etimer_set(&timer, 25*CLOCK_SECOND);
while(1) {
PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_EXIT ||
ev== PROCESS_EVENT_TIMER);
if (ev == PROCESS_EVENT_EXIT) break;
printf("Blocking execution\n");
while(1);
}
PROCESS_END();
}
#endif
#if 0
/* Wathcdog is already disabled in startup code */
@ -149,10 +105,6 @@ wdt_reset()
static uip_ipaddr_t gw_addr = {{172,16,0,1}};
#endif
PROCINIT(&etimer_process, &tcpip_process, &cc2420_process,
&uip_fw_process /*, &uaodv_process */
);
int
main()
@ -167,23 +119,55 @@ main()
printf("Initialising\n");
leds_arch_init();
clock_init();
uip_sethostaddr(&cc2420if.ipaddr);
uip_setnetmask(&cc2420if.netmask);
/*uip_setdraddr(&gw_addr);*/
cc2420_init();
cc2420_set_chan_pan_addr(RF_CHANNEL, HTONS(0x2024), uip_hostaddr.u16[1], NULL);
process_init();
uip_init();
uip_fw_default(&cc2420if);
tcpip_set_forwarding(1);
process_start(&etimer_process, NULL);
ctimer_init();
robot_stepper_init();
enableIRQ();
cc2420_init();
cc2420_set_pan_addr(0x2024, 0, &uip_hostaddr.u16[1]);
cc2420_set_channel(RF_CHANNEL);
rime_init(nullmac_init(&cc2420_driver));
printf("CC2420 setup done\n");
rimeaddr_set_node_addr(&node_addr);
#if WITH_UIP
{
uip_ipaddr_t hostaddr, netmask;
uip_init();
uip_ipaddr(&hostaddr, 172,16,
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1]);
uip_ipaddr(&netmask, 255,255,0,0);
uip_ipaddr_copy(&meshif.ipaddr, &hostaddr);
printf("Host addr\n");
uip_sethostaddr(&hostaddr);
uip_setnetmask(&netmask);
uip_over_mesh_set_net(&hostaddr, &netmask);
/* uip_fw_register(&slipif);*/
/*uip_over_mesh_set_gateway_netif(&slipif);*/
uip_fw_default(&meshif);
printf("Mesh init\n");
uip_over_mesh_init(UIP_OVER_MESH_CHANNEL);
printf("uIP started with IP address %d.%d.%d.%d\n",
uip_ipaddr_to_quad(&hostaddr));
}
#endif /* WITH_UIP */
#if WITH_UIP
process_start(&tcpip_process, NULL);
process_start(&uip_fw_process, NULL); /* Start IP output */
#endif /* WITH_UIP */
printf("Heap size: %ld bytes\n", &__heap_end__ - (char*)sbrk(0));
printf("Started\n");
robot_stepper_init();
procinit_init();
enableIRQ();
cc2420_on();
autostart_start(autostart_processes);
printf("Processes running\n");
while(1) {

View file

@ -276,7 +276,8 @@ handle_line(const char *input_line, const char *inend, ReplyBuffer *reply)
reply_str(reply, "OK\n");
} else if (input_line[0] == 'p') {
reply_char(reply, 'p');
format_int_hex(&reply->write, REPLY_BUFFER_END(reply), cc2420_last_rssi);
format_int_hex(&reply->write, REPLY_BUFFER_END(reply),
cc2420_last_rssi);
reply_char(reply, ',');
format_uint_hex(&reply->write, REPLY_BUFFER_END(reply),
cc2420_last_correlation);
@ -443,12 +444,52 @@ PROCESS_THREAD(udp_stepper_process, ev, data)
PROCESS_END();
}
static const uint32_t stepper0_steps_acc[] = MICRO_STEP(0,3);
static const uint32_t stepper0_steps_run[] = MICRO_STEP(0,2);
static const uint32_t stepper0_steps_hold[] = MICRO_STEP(0,1);
static const uint32_t stepper1_steps_acc[] = MICRO_STEP(1,3);
static const uint32_t stepper1_steps_run[] = MICRO_STEP(1,2);
static const uint32_t stepper1_steps_hold[] = MICRO_STEP(1,1);
static StepperAccSeq seq_heap[40];
static void
init_seq_heap()
{
unsigned int i;
for(i = 0; i < sizeof(seq_heap)/sizeof(seq_heap[0]); i++) {
seq_heap[i].next = NULL;
stepper_free_seq(&seq_heap[i]);
}
}
static void
robot_stepper_init()
{
disableIRQ();
init_seq_heap();
stepper_init(AT91C_BASE_TC0, AT91C_ID_TC0);
*AT91C_PIOA_OER = STEPPER_INHIBIT;
*AT91C_PIOA_MDER = STEPPER_INHIBIT; /* | STEPPER0_IOMASK; */
*AT91C_PIOA_CODR = STEPPER_INHIBIT;
stepper_init_io(1, STEPPER_IOMASK(0), stepper0_steps_acc,
stepper0_steps_run, stepper0_steps_hold,
(sizeof(stepper0_steps_run) / sizeof(stepper0_steps_run[0])));
stepper_init_io(0, STEPPER_IOMASK(1), stepper1_steps_acc,
stepper1_steps_run, stepper1_steps_hold,
(sizeof(stepper1_steps_run) / sizeof(stepper1_steps_run[0])));
enableIRQ();
}
PROCESS(stepper_process, "Stepper control process");
PROCESS_THREAD(stepper_process, ev, data)
{
PROCESS_EXITHANDLER(goto exit);
PROCESS_BEGIN();
robot_stepper_init();
tcp_listen(HTONS(1010));
process_start(&udp_stepper_process, NULL);