2008-10-14 11:40:30 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2006, Technical University of Munich
|
|
|
|
* 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
|
2010-03-02 17:25:47 +01:00
|
|
|
* Contiki 2.4 kernel for Jackdaw USB stick
|
2008-10-14 11:40:30 +02:00
|
|
|
*
|
|
|
|
* \author
|
2010-03-02 17:25:47 +01:00
|
|
|
* Simon Barner <barner@in.tum.de>
|
|
|
|
* David Kopf <dak664@embarqmail.com>
|
2008-10-14 11:40:30 +02:00
|
|
|
*/
|
|
|
|
|
2010-09-14 18:59:44 +02:00
|
|
|
#define DEBUG 0
|
|
|
|
#if DEBUG
|
|
|
|
#define PRINTF(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
|
|
|
|
#else
|
|
|
|
#define PRINTF(...)
|
|
|
|
#endif
|
|
|
|
|
2008-10-14 11:40:30 +02:00
|
|
|
#include <avr/pgmspace.h>
|
2008-10-14 21:06:51 +02:00
|
|
|
#include <avr/fuse.h>
|
|
|
|
#include <avr/eeprom.h>
|
2010-09-17 23:59:09 +02:00
|
|
|
#include <avr/wdt.h>
|
2008-10-14 11:40:30 +02:00
|
|
|
#include <util/delay.h>
|
|
|
|
#include <stdio.h>
|
2010-02-16 23:17:51 +01:00
|
|
|
#include <string.h>
|
2008-10-14 11:40:30 +02:00
|
|
|
|
2010-02-16 23:17:51 +01:00
|
|
|
#include "lib/mmem.h"
|
|
|
|
#include "loader/symbols-def.h"
|
|
|
|
#include "loader/symtab.h"
|
2008-10-14 11:40:30 +02:00
|
|
|
|
|
|
|
#include "contiki.h"
|
|
|
|
#include "contiki-net.h"
|
|
|
|
#include "contiki-lib.h"
|
|
|
|
#include "contiki-raven.h"
|
|
|
|
|
2010-10-27 16:51:20 +02:00
|
|
|
/* Set ANNOUNCE to send boot messages to USB or RS232 serial port */
|
2010-03-15 19:56:13 +01:00
|
|
|
#define ANNOUNCE 1
|
|
|
|
|
2008-10-14 11:40:30 +02:00
|
|
|
#include "usb_task.h"
|
2010-10-27 16:51:20 +02:00
|
|
|
#if USB_CONF_SERIAL
|
2010-09-17 23:59:09 +02:00
|
|
|
#include "cdc_task.h"
|
2010-10-23 17:26:46 +02:00
|
|
|
#endif
|
|
|
|
#if USB_CONF_RS232
|
2010-09-14 18:59:44 +02:00
|
|
|
#include "dev/rs232.h"
|
2010-03-15 19:56:13 +01:00
|
|
|
#endif
|
2010-09-14 18:59:44 +02:00
|
|
|
|
2008-10-14 11:40:30 +02:00
|
|
|
#include "rndis/rndis_task.h"
|
2010-03-15 19:56:13 +01:00
|
|
|
#if USB_CONF_STORAGE
|
2008-10-14 11:40:30 +02:00
|
|
|
#include "storage/storage_task.h"
|
2010-03-15 19:56:13 +01:00
|
|
|
#endif
|
2008-10-14 11:40:30 +02:00
|
|
|
|
2010-09-17 23:59:09 +02:00
|
|
|
#include "dev/watchdog.h"
|
|
|
|
#include "dev/usb/usb_drv.h"
|
|
|
|
|
|
|
|
#if JACKDAW_CONF_USE_SETTINGS
|
|
|
|
#include "settings.h"
|
|
|
|
#endif
|
|
|
|
|
2010-09-14 18:59:44 +02:00
|
|
|
#if RF230BB //radio driver using contiki core mac
|
|
|
|
#include "radio/rf230bb/rf230bb.h"
|
|
|
|
#include "net/mac/frame802154.h"
|
2010-02-16 23:17:51 +01:00
|
|
|
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
|
|
|
|
extern int rf230_interrupt_flag;
|
|
|
|
extern uint8_t rf230processflag;
|
2010-09-17 23:59:09 +02:00
|
|
|
rimeaddr_t macLongAddr;
|
|
|
|
#define tmp_addr macLongAddr
|
2010-09-14 18:59:44 +02:00
|
|
|
#else //legacy radio driver using Atmel/Cisco 802.15.4'ish MAC
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include "mac.h"
|
|
|
|
#include "sicslowmac.h"
|
|
|
|
#include "sicslowpan.h"
|
|
|
|
#include "ieee-15-4-manager.h"
|
2010-02-18 18:24:12 +01:00
|
|
|
#endif /* RF230BB */
|
2010-02-16 23:17:51 +01:00
|
|
|
|
2010-03-02 17:25:47 +01:00
|
|
|
/* Test rtimers, also useful for pings and time stamps in simulator */
|
|
|
|
#define TESTRTIMER 0
|
|
|
|
#if TESTRTIMER
|
|
|
|
#define PINGS 0
|
|
|
|
#define STAMPS 30
|
|
|
|
uint8_t rtimerflag=1;
|
|
|
|
uint16_t rtime;
|
|
|
|
struct rtimer rt;
|
|
|
|
void rtimercycle(void) {rtimerflag=1;}
|
|
|
|
#endif /* TESTRTIMER */
|
2010-02-16 23:17:51 +01:00
|
|
|
|
2010-09-14 18:59:44 +02:00
|
|
|
#if UIP_CONF_IPV6_RPL
|
2010-08-06 19:39:31 +02:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
/*--------------------------------- RPL ----------------------------------*/
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-09-14 18:59:44 +02:00
|
|
|
/* Set up fallback interface links to direct stack tcpip output to ethernet */
|
|
|
|
static void
|
|
|
|
init(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void mac_LowpanToEthernet(void);
|
|
|
|
static void
|
|
|
|
output(void)
|
|
|
|
{
|
|
|
|
// if(uip_ipaddr_cmp(&last_sender, &UIP_IP_BUF->srcipaddr)) {
|
|
|
|
/* Do not bounce packets back over SLIP if the packet was received
|
|
|
|
over SLIP */
|
|
|
|
// PRINTF("slip-bridge: Destination off-link but no route\n");
|
|
|
|
// } else {
|
|
|
|
PRINTF("SUT: %u\n", uip_len);
|
|
|
|
mac_LowpanToEthernet();
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
const struct uip_fallback_interface rpl_interface = {
|
|
|
|
init, output
|
|
|
|
};
|
2010-08-06 19:39:31 +02:00
|
|
|
|
|
|
|
#define RPL_BORDER_ROUTER 1 //Set to 1 for border router
|
2010-09-14 18:59:44 +02:00
|
|
|
#define RPL_HTTPD_SERVER 0 //Set to 1 for border router web page
|
2010-08-06 19:39:31 +02:00
|
|
|
|
|
|
|
#include "net/rpl/rpl.h"
|
|
|
|
|
|
|
|
#if RPL_BORDER_ROUTER
|
2010-09-14 18:59:44 +02:00
|
|
|
// avr-objdump --section .bss -x ravenusbstick.elf
|
|
|
|
uint16_t dag_id[] PROGMEM = {0x1111, 0x1100, 0, 0, 0, 0, 0, 0x0011};
|
2010-08-06 19:39:31 +02:00
|
|
|
|
2010-09-14 18:59:44 +02:00
|
|
|
PROCESS(border_router_process, "RPL Border Router");
|
2010-08-06 19:39:31 +02:00
|
|
|
PROCESS_THREAD(border_router_process, ev, data)
|
|
|
|
{
|
|
|
|
rpl_dag_t *dag;
|
|
|
|
|
|
|
|
PROCESS_BEGIN();
|
|
|
|
|
|
|
|
PROCESS_PAUSE();
|
|
|
|
|
2010-09-14 18:59:44 +02:00
|
|
|
// printf_P(PSTR("%d neighbors"), UIP_DS6_ADDR_NB);
|
|
|
|
{ char buf[sizeof(dag_id)];
|
|
|
|
memcpy_P(buf,dag_id,sizeof(dag_id));
|
|
|
|
dag = rpl_set_root((uip_ip6addr_t *)buf);
|
|
|
|
}
|
|
|
|
#if 0 //horrible cludge to direct aaaa::11 to internal webserver
|
2010-08-06 19:39:31 +02:00
|
|
|
if(dag != NULL) {
|
|
|
|
uip_ip6addr_t ipaddr;
|
2010-09-14 18:59:44 +02:00
|
|
|
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0x11);
|
|
|
|
// uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0x1);
|
|
|
|
// uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
|
|
|
|
uip_ds6_addr_add(&ipaddr, 0, ADDR_MANUAL);
|
2010-08-06 19:39:31 +02:00
|
|
|
rpl_set_prefix(dag, &ipaddr, 64);
|
|
|
|
PRINTF("created a new RPL dag\n");
|
|
|
|
}
|
2010-09-14 18:59:44 +02:00
|
|
|
#endif
|
2010-08-06 19:39:31 +02:00
|
|
|
|
|
|
|
/* The border router runs with a 100% duty cycle in order to ensure high
|
|
|
|
packet reception rates. */
|
|
|
|
// NETSTACK_MAC.off(1);
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
PROCESS_YIELD();
|
2010-09-14 18:59:44 +02:00
|
|
|
// rpl_repair_dag(rpl_get_dag(RPL_ANY_INSTANCE));
|
|
|
|
|
2010-08-06 19:39:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
PROCESS_END();
|
|
|
|
}
|
|
|
|
#endif /* RPL_BORDER_ROUTER */
|
2010-09-14 18:59:44 +02:00
|
|
|
|
2010-08-06 19:39:31 +02:00
|
|
|
#endif /* UIP_CONF_IPV6_RPL */
|
|
|
|
|
2010-02-28 22:29:19 +01:00
|
|
|
/*-------------------------------------------------------------------------*/
|
2009-07-23 18:16:07 +02:00
|
|
|
/*----------------------Configuration of the .elf file---------------------*/
|
|
|
|
typedef struct {unsigned char B2;unsigned char B1;unsigned char B0;} __signature_t;
|
|
|
|
#define SIGNATURE __signature_t __signature __attribute__((section (".signature")))
|
|
|
|
SIGNATURE = {
|
|
|
|
/* Older AVR-GCCs may not define the SIGNATURE_n bytes so use explicit values */
|
|
|
|
.B2 = 0x82,//SIGNATURE_2, //AT90USB128x
|
|
|
|
.B1 = 0x97,//SIGNATURE_1, //128KB flash
|
|
|
|
.B0 = 0x1E,//SIGNATURE_0, //Atmel
|
|
|
|
};
|
|
|
|
FUSES ={.low = 0xde, .high = 0x99, .extended = 0xff,};
|
2008-10-14 21:06:51 +02:00
|
|
|
|
|
|
|
/* Put default MAC address in EEPROM */
|
2010-09-17 23:59:09 +02:00
|
|
|
#if !JACKDAW_CONF_USE_SETTINGS
|
2008-10-14 21:06:51 +02:00
|
|
|
uint8_t mac_address[8] EEMEM = {0x02, 0x12, 0x13, 0xff, 0xfe, 0x14, 0x15, 0x16};
|
2010-09-17 23:59:09 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static uint8_t get_channel_from_eeprom() {
|
|
|
|
#if JACKDAW_CONF_USE_SETTINGS
|
|
|
|
uint8_t chan = settings_get_uint8(SETTINGS_KEY_CHANNEL, 0);
|
|
|
|
if(!chan)
|
|
|
|
chan = RF_CHANNEL;
|
|
|
|
return chan;
|
|
|
|
#else
|
|
|
|
uint8_t eeprom_channel;
|
|
|
|
uint8_t eeprom_check;
|
|
|
|
|
|
|
|
eeprom_channel = eeprom_read_byte((uint8_t *)9);
|
|
|
|
eeprom_check = eeprom_read_byte((uint8_t *)10);
|
|
|
|
|
|
|
|
if(eeprom_channel==~eeprom_check)
|
|
|
|
return eeprom_channel;
|
|
|
|
return 26;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
get_eui64_from_eeprom(uint8_t macptr[8]) {
|
|
|
|
#if JACKDAW_CONF_USE_SETTINGS
|
|
|
|
size_t size = 8;
|
|
|
|
|
|
|
|
if(settings_get(SETTINGS_KEY_EUI64, 0, (unsigned char*)macptr, &size)==SETTINGS_STATUS_OK)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Fallback to reading the traditional mac address
|
|
|
|
eeprom_read_block ((void *)macptr, 0, 8);
|
|
|
|
#else
|
|
|
|
eeprom_read_block ((void *)macptr, &mac_address, 8);
|
|
|
|
#endif
|
|
|
|
return macptr[0]!=0xFF;
|
|
|
|
}
|
|
|
|
|
2010-10-23 17:26:46 +02:00
|
|
|
#if JACKDAW_CONF_RANDOM_MAC
|
2010-09-17 23:59:09 +02:00
|
|
|
static bool
|
|
|
|
set_eui64_to_eeprom(const uint8_t macptr[8]) {
|
|
|
|
#if JACKDAW_CONF_USE_SETTINGS
|
|
|
|
return settings_set(SETTINGS_KEY_EUI64, macptr, 8)==SETTINGS_STATUS_OK;
|
|
|
|
#else
|
|
|
|
eeprom_write_block((void *)macptr, &mac_address, 8);
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
generate_new_eui64(uint8_t eui64[8]) {
|
|
|
|
eui64[0] = 0x02;
|
|
|
|
eui64[1] = rng_get_uint8();
|
|
|
|
eui64[2] = rng_get_uint8();
|
|
|
|
eui64[3] = 0xFF;
|
|
|
|
eui64[4] = 0xFE;
|
|
|
|
eui64[5] = rng_get_uint8();
|
|
|
|
eui64[6] = rng_get_uint8();
|
|
|
|
eui64[7] = rng_get_uint8();
|
|
|
|
}
|
2010-10-23 17:26:46 +02:00
|
|
|
#endif /* JACKDAW_CONF_RANDOM_MAC */
|
2010-09-17 23:59:09 +02:00
|
|
|
|
|
|
|
static uint16_t
|
|
|
|
get_panid_from_eeprom(void) {
|
|
|
|
#if JACKDAW_CONF_USE_SETTINGS
|
|
|
|
uint16_t x = settings_get_uint16(SETTINGS_KEY_PAN_ID, 0);
|
|
|
|
if(!x)
|
|
|
|
x = IEEE802154_PANID;
|
|
|
|
return x;
|
|
|
|
#else
|
|
|
|
// TODO: Writeme!
|
|
|
|
return IEEE802154_PANID;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint16_t
|
|
|
|
get_panaddr_from_eeprom(void) {
|
|
|
|
#if JACKDAW_CONF_USE_SETTINGS
|
|
|
|
return settings_get_uint16(SETTINGS_KEY_PAN_ADDR, 0);
|
|
|
|
#else
|
|
|
|
// TODO: Writeme!
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-10-14 21:06:51 +02:00
|
|
|
|
2010-03-02 17:25:47 +01:00
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
/*-----------------------------Low level initialization--------------------*/
|
2010-02-28 22:29:19 +01:00
|
|
|
static void initialize(void) {
|
2010-09-17 23:59:09 +02:00
|
|
|
watchdog_init();
|
|
|
|
watchdog_start();
|
2008-10-14 11:40:30 +02:00
|
|
|
|
|
|
|
/* Initialize hardware */
|
2010-09-17 23:59:09 +02:00
|
|
|
// Checks for "finger", jumps to DFU if present.
|
2008-10-14 11:40:30 +02:00
|
|
|
init_lowlevel();
|
2010-02-16 23:17:51 +01:00
|
|
|
|
2008-10-14 11:40:30 +02:00
|
|
|
/* Clock */
|
|
|
|
clock_init();
|
|
|
|
|
2010-10-27 16:51:20 +02:00
|
|
|
#if USB_CONF_RS232
|
2010-03-15 19:56:13 +01:00
|
|
|
/* Use rs232 port for serial out (tx, rx, gnd are the three pads behind jackdaw leds */
|
|
|
|
rs232_init(RS232_PORT_0, USART_BAUD_57600,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
|
|
|
|
/* Redirect stdout to second port */
|
|
|
|
rs232_redirect_stdout(RS232_PORT_0);
|
|
|
|
#if ANNOUNCE
|
|
|
|
printf_P(PSTR("\n\n\n********BOOTING CONTIKI*********\n"));
|
|
|
|
#endif
|
|
|
|
#endif
|
2010-09-17 23:59:09 +02:00
|
|
|
|
|
|
|
Leds_init();
|
|
|
|
|
2010-03-15 19:56:13 +01:00
|
|
|
/* rtimer init needed for low power protocols */
|
2010-02-23 18:35:49 +01:00
|
|
|
rtimer_init();
|
2008-10-14 11:40:30 +02:00
|
|
|
|
2010-02-18 18:24:12 +01:00
|
|
|
/* Process subsystem. */
|
2008-10-14 11:40:30 +02:00
|
|
|
process_init();
|
|
|
|
|
2010-02-18 18:24:12 +01:00
|
|
|
/* etimer process must be started before ctimer init */
|
|
|
|
process_start(&etimer_process, NULL);
|
2010-02-16 23:17:51 +01:00
|
|
|
|
2010-02-23 18:35:49 +01:00
|
|
|
#if RF230BB
|
2010-02-18 18:24:12 +01:00
|
|
|
ctimer_init();
|
2010-02-16 23:17:51 +01:00
|
|
|
/* Start radio and radio receive process */
|
|
|
|
/* Note this starts RF230 process, so must be done after process_init */
|
2010-02-28 22:29:19 +01:00
|
|
|
NETSTACK_RADIO.init();
|
2010-02-16 23:17:51 +01:00
|
|
|
|
|
|
|
/* Set addresses BEFORE starting tcpip process */
|
|
|
|
|
2010-09-17 23:59:09 +02:00
|
|
|
memset(&tmp_addr, 0, sizeof(rimeaddr_t));
|
|
|
|
if(!get_eui64_from_eeprom(tmp_addr.u8)) {
|
|
|
|
#if JACKDAW_CONF_RANDOM_MAC
|
|
|
|
// It doesn't look like we have a valid EUI-64 address
|
|
|
|
// so let's try to make a new one from scratch.
|
|
|
|
Leds_off();
|
|
|
|
Led2_on();
|
|
|
|
generate_new_eui64(tmp_addr.u8);
|
|
|
|
if(!set_eui64_to_eeprom(tmp_addr.u8)) {
|
|
|
|
watchdog_periodic();
|
|
|
|
int i;
|
|
|
|
for(i=0;i<20;i++) {
|
|
|
|
Led1_toggle();
|
|
|
|
_delay_ms(100);
|
|
|
|
}
|
|
|
|
Led1_off();
|
|
|
|
}
|
|
|
|
Led2_off();
|
|
|
|
#else
|
|
|
|
tmp_addr.u8[0]=0x02;
|
|
|
|
tmp_addr.u8[1]=0x12;
|
|
|
|
tmp_addr.u8[2]=0x13;
|
|
|
|
tmp_addr.u8[3]=0xff;
|
|
|
|
tmp_addr.u8[4]=0xfe;
|
|
|
|
tmp_addr.u8[5]=0x14;
|
|
|
|
tmp_addr.u8[6]=0x15;
|
|
|
|
tmp_addr.u8[7]=0x16;
|
|
|
|
#endif /* JACKDAW_CONF_RANDOM_MAC */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//Fix MAC address
|
|
|
|
init_net();
|
|
|
|
|
|
|
|
memcpy(&uip_lladdr.addr, &tmp_addr.u8, 8);
|
|
|
|
rf230_set_pan_addr(
|
|
|
|
get_panid_from_eeprom(),
|
|
|
|
get_panaddr_from_eeprom(),
|
|
|
|
(uint8_t *)&tmp_addr.u8
|
|
|
|
);
|
|
|
|
|
|
|
|
#if JACKDAW_CONF_USE_SETTINGS
|
|
|
|
rf230_set_txpower(settings_get_uint8(SETTINGS_KEY_TXPOWER,0));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
rimeaddr_set_node_addr(&tmp_addr);
|
2010-02-16 23:17:51 +01:00
|
|
|
|
2010-03-02 17:25:47 +01:00
|
|
|
/* Initialize stack protocols */
|
2010-02-23 18:35:49 +01:00
|
|
|
queuebuf_init();
|
|
|
|
NETSTACK_RDC.init();
|
|
|
|
NETSTACK_MAC.init();
|
|
|
|
NETSTACK_NETWORK.init();
|
2010-02-16 23:17:51 +01:00
|
|
|
|
2010-09-17 23:59:09 +02:00
|
|
|
rf230_set_channel(get_channel_from_eeprom());
|
|
|
|
|
2010-03-15 19:56:13 +01:00
|
|
|
#if ANNOUNCE && USB_CONF_RS232
|
2010-09-17 23:59:09 +02:00
|
|
|
printf_P(PSTR("MAC address %x:%x:%x:%x:%x:%x:%x:%x\n\r"),tmp_addr.u8[0],tmp_addr.u8[1],tmp_addr.u8[2],tmp_addr.u8[3],tmp_addr.u8[4],tmp_addr.u8[5],tmp_addr.u8[6],tmp_addr.u8[7]);
|
2010-03-15 19:56:13 +01:00
|
|
|
printf_P(PSTR("%s %s, channel %u"),NETSTACK_MAC.name, NETSTACK_RDC.name,rf230_get_channel());
|
|
|
|
if (NETSTACK_RDC.channel_check_interval) {
|
|
|
|
unsigned short tmp;
|
|
|
|
tmp=CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval == 0 ? 1:\
|
|
|
|
NETSTACK_RDC.channel_check_interval());
|
|
|
|
if (tmp<65535) printf_P(PSTR(", check rate %u Hz"),tmp);
|
|
|
|
}
|
|
|
|
printf_P(PSTR("\n"));
|
|
|
|
#endif
|
|
|
|
|
2010-08-03 21:55:42 +02:00
|
|
|
#if UIP_CONF_IPV6_RPL
|
2010-08-06 19:39:31 +02:00
|
|
|
#if RPL_BORDER_ROUTER
|
|
|
|
process_start(&tcpip_process, NULL);
|
|
|
|
process_start(&border_router_process, NULL);
|
2010-09-14 18:59:44 +02:00
|
|
|
PRINTF ("RPL Border Router Started\n");
|
2010-08-06 19:39:31 +02:00
|
|
|
#else
|
|
|
|
process_start(&tcpip_process, NULL);
|
2010-09-14 18:59:44 +02:00
|
|
|
PRINTF ("RPL Started\n");
|
|
|
|
#endif
|
|
|
|
#if RPL_HTTPD_SERVER
|
|
|
|
extern struct process httpd_process;
|
|
|
|
process_start(&httpd_process, NULL);
|
|
|
|
PRINTF ("Webserver Started\n");
|
2010-08-03 21:55:42 +02:00
|
|
|
#endif
|
2010-08-06 19:39:31 +02:00
|
|
|
#endif /* UIP_CONF_IPV6_RPL */
|
2010-08-03 21:55:42 +02:00
|
|
|
|
2010-03-15 19:56:13 +01:00
|
|
|
#else /* RF230BB */
|
2010-02-18 18:24:12 +01:00
|
|
|
/* The order of starting these is important! */
|
|
|
|
process_start(&mac_process, NULL);
|
|
|
|
process_start(&tcpip_process, NULL);
|
2010-03-15 19:56:13 +01:00
|
|
|
#endif /* RF230BB */
|
2010-02-18 18:24:12 +01:00
|
|
|
|
2008-10-14 11:40:30 +02:00
|
|
|
/* Setup USB */
|
2008-10-14 21:06:51 +02:00
|
|
|
process_start(&usb_process, NULL);
|
2010-10-27 16:51:20 +02:00
|
|
|
#if USB_CONF_SERIAL
|
2008-10-14 21:06:51 +02:00
|
|
|
process_start(&cdc_process, NULL);
|
2010-03-15 19:56:13 +01:00
|
|
|
#endif
|
2010-09-17 23:59:09 +02:00
|
|
|
process_start(&usb_eth_process, NULL);
|
2010-03-15 19:56:13 +01:00
|
|
|
#if USB_CONF_STORAGE
|
2008-10-14 21:06:51 +02:00
|
|
|
process_start(&storage_process, NULL);
|
2010-03-15 19:56:13 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ANNOUNCE
|
2010-10-27 16:51:20 +02:00
|
|
|
#if USB_CONF_SERIAL&&!USB_CONF_RS232
|
2010-03-15 19:56:13 +01:00
|
|
|
{unsigned short i;
|
|
|
|
printf_P(PSTR("\n\n\n********BOOTING CONTIKI*********\n\r"));
|
|
|
|
/* Allow USB CDC to keep up with printfs */
|
|
|
|
for (i=0;i<8000;i++) process_run();
|
|
|
|
#if RF230BB
|
2010-09-17 23:59:09 +02:00
|
|
|
printf_P(PSTR("MAC address %x:%x:%x:%x:%x:%x:%x:%x\n\r"),tmp_addr.u8[0],tmp_addr.u8[1],tmp_addr.u8[2],tmp_addr.u8[3],tmp_addr.u8[4],tmp_addr.u8[5],tmp_addr.u8[6],tmp_addr.u8[7]);
|
2010-03-15 19:56:13 +01:00
|
|
|
for (i=0;i<8000;i++) process_run();
|
|
|
|
printf_P(PSTR("%s %s, channel %u"),NETSTACK_MAC.name, NETSTACK_RDC.name,rf230_get_channel());
|
|
|
|
if (NETSTACK_RDC.channel_check_interval) {
|
|
|
|
i=CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval == 0 ? 1:\
|
|
|
|
NETSTACK_RDC.channel_check_interval());
|
|
|
|
if (i<65535) printf_P(PSTR(", check rate %u Hz"),i);
|
|
|
|
}
|
|
|
|
printf_P(PSTR("\n\r"));
|
|
|
|
for (i=0;i<8000;i++) process_run();
|
|
|
|
#endif /* RF230BB */
|
|
|
|
printf_P(PSTR("System online.\n\r"));
|
|
|
|
}
|
2010-10-27 16:51:20 +02:00
|
|
|
#elif USB_CONF_RS232
|
2010-10-23 17:26:46 +02:00
|
|
|
printf_P(PSTR("System online.\n"));
|
2010-10-27 16:51:20 +02:00
|
|
|
#endif
|
2010-03-15 19:56:13 +01:00
|
|
|
#endif /* ANNOUNCE */
|
2010-02-28 22:29:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
/*---------------------------------Main Routine----------------------------*/
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
|
|
|
/* GCC depends on register r1 set to 0 (?) */
|
|
|
|
asm volatile ("clr r1");
|
2010-02-16 23:17:51 +01:00
|
|
|
|
2010-02-28 22:29:19 +01:00
|
|
|
/* Initialize in a subroutine to maximize stack space */
|
|
|
|
initialize();
|
2010-09-14 18:59:44 +02:00
|
|
|
#if DEBUG
|
|
|
|
{struct process *p;
|
|
|
|
for(p = PROCESS_LIST();p != NULL; p = ((struct process *)p->next)) {
|
|
|
|
printf_P(PSTR("Process=%p Thread=%p Name=\"%s\" \n"),p,p->thread,p->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2008-10-14 11:40:30 +02:00
|
|
|
while(1) {
|
|
|
|
process_run();
|
2010-02-28 22:29:19 +01:00
|
|
|
|
2010-09-17 23:59:09 +02:00
|
|
|
watchdog_periodic();
|
|
|
|
|
2010-02-28 22:29:19 +01:00
|
|
|
#if TESTRTIMER
|
|
|
|
if (rtimerflag) { //8 seconds is maximum interval, my jackdaw 4% slow
|
|
|
|
rtimer_set(&rt, RTIMER_NOW()+ RTIMER_ARCH_SECOND*1UL, 1,(void *) rtimercycle, NULL);
|
|
|
|
rtimerflag=0;
|
|
|
|
#if STAMPS
|
|
|
|
if ((rtime%STAMPS)==0) {
|
|
|
|
printf("%us ",rtime);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
rtime+=1;
|
|
|
|
#if PINGS
|
|
|
|
if ((rtime%PINGS)==0) {
|
|
|
|
PRINTF("**Ping\n");
|
|
|
|
pingsomebody();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif /* TESTRTIMER */
|
|
|
|
|
2010-03-02 17:25:47 +01:00
|
|
|
//Use with RF230BB DEBUGFLOW to show path through driver
|
2010-02-28 22:29:19 +01:00
|
|
|
//Warning, Jackdaw doesn't handle simultaneous radio and USB interrupts very well.
|
2010-03-02 17:25:47 +01:00
|
|
|
#if RF230BB&&0
|
|
|
|
extern uint8_t debugflowsize,debugflow[];
|
|
|
|
if (debugflowsize) {
|
|
|
|
debugflow[debugflowsize]=0;
|
|
|
|
printf("%s",debugflow);
|
|
|
|
debugflowsize=0;
|
|
|
|
}
|
2010-02-18 18:24:12 +01:00
|
|
|
#endif
|
2010-02-16 23:17:51 +01:00
|
|
|
|
2010-03-02 17:25:47 +01:00
|
|
|
#if RF230BB&&0
|
2010-02-28 22:29:19 +01:00
|
|
|
if (rf230processflag) {
|
|
|
|
printf("**RF230 process flag %u\n\r",rf230processflag);
|
|
|
|
rf230processflag=0;
|
|
|
|
}
|
|
|
|
if (rf230_interrupt_flag) {
|
|
|
|
// if (rf230_interrupt_flag!=11) {
|
|
|
|
printf("**RF230 Interrupt %u\n\r",rf230_interrupt_flag);
|
|
|
|
// }
|
|
|
|
rf230_interrupt_flag=0;
|
|
|
|
}
|
2010-03-02 17:25:47 +01:00
|
|
|
#endif
|
2008-10-14 11:40:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|