33 #define PRINTF(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
35 #define ANNOUNCE_BOOT 1 //adds about 600 bytes to program size
37 #define PRINTA(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
44 #define PRINTD(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
52 unsigned char debugflowsize,debugflow[DEBUGFLOWSIZE];
53 #define DEBUGFLOW(c) if (debugflowsize<(DEBUGFLOWSIZE-1)) debugflow[debugflowsize++]=c
58 #include <avr/pgmspace.h>
60 #include <avr/eeprom.h>
63 #include <dev/watchdog.h>
65 #include "loader/symbols-def.h"
66 #include "loader/symtab.h"
68 #if RF230BB //radio driver using contiki core mac
69 #include "radio/rf230bb/rf230bb.h"
74 #else //radio driver using Atmel/Cisco 802.15.4'ish MAC
77 #include "sicslowmac.h"
83 #include "contiki-net.h"
84 #include "contiki-lib.h"
86 #include "dev/rs232.h"
90 #ifdef RAVEN_LCD_INTERFACE
91 #include "raven-lcd.h"
96 #include "httpd-cgi.h"
104 #if UIP_CONF_ROUTER&&0
105 #include "net/routing/rimeroute.h"
106 #include "net/rime/rime-udp.h"
116 #define PERIODICPRINTS 1
121 #define STACKMONITOR 600
125 uint8_t rtimerflag=1;
127 void rtimercycle(
void) {rtimerflag=1;}
135 #include <avr/signature.h>
138 typedef struct {
const unsigned char B2;
const unsigned char B1;
const unsigned char B0;} __signature_t;
139 #define SIGNATURE __signature_t __signature __attribute__((section (".signature")))
147 #if !MCU_CONF_LOW_WEAR
149 FUSES ={.low = 0xe2, .high = 0x99, .extended = 0xff,};
154 rng_get_uint8(
void) {
157 for (i=0,j=0;i<4;i++) {
161 while (ADCSRA&(1<<ADSC));
165 PRINTD(
"rng issues %d\n",j);
171 void initialize(
void)
176 #ifdef RAVEN_LCD_INTERFACE
178 rs232_init(RS232_PORT_0, USART_BAUD_38400,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
183 rs232_init(RS232_PORT_0, USART_BAUD_38400,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
187 rs232_init(RS232_PORT_1, USART_BAUD_57600,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
189 rs232_redirect_stdout(RS232_PORT_1);
192 PRINTD(
"\n\nChecking MCUSR...\n");
193 if(MCUSR & (1<<PORF )) PRINTD(
"Power-on reset.\n");
194 if(MCUSR & (1<<EXTRF)) PRINTD(
"External reset!\n");
195 if(MCUSR & (1<<BORF )) PRINTD(
"Brownout reset!\n");
196 if(MCUSR & (1<<WDRF )) PRINTD(
"Watchdog reset!\n");
197 if(MCUSR & (1<<JTRF )) PRINTD(
"JTAG reset!\n");
201 PRINTD(
"RTIMER_ARCH_SECOND %lu\n",RTIMER_ARCH_SECOND);
202 PRINTD(
"F_CPU %lu\n",
F_CPU);
210 extern uint16_t __bss_end;
211 uint16_t p=(uint16_t)&__bss_end;
213 *(uint16_t *)p = 0x4242;
220 #define CONF_CALIBRATE_OSCCAL 0
221 #if CONF_CALIBRATE_OSCCAL
224 extern uint8_t osccal_calibrated;
226 PRINTD(
"\nBefore calibration OSCCAL=%x\n",OSCCAL);
229 PRINTD(
"Calibrated=%x\n",osccal_calibrated);
238 PRINTA(
"\n*******Booting %s*******\n",CONTIKI_VERSION_STRING);
253 NETSTACK_RADIO.init();
264 if (params_get_eui64(addr.u8)) {
265 PRINTA(
"Random EUI64 address generated\n");
269 memcpy(&
uip_lladdr.addr, &addr.u8,
sizeof(linkaddr_t));
271 rf230_set_pan_addr(params_get_panid(),params_get_panaddr(),(uint8_t *)&addr.u8);
273 node_id=get_panaddr_from_eeprom();
274 addr.u8[1]=node_id&0xff;
275 addr.u8[0]=(node_id&0xff00)>>8;
276 PRINTA(
"Node ID from eeprom: %X\n",node_id);
277 uint16_t inv_node_id=((node_id&0xff00)>>8)+((node_id&0xff)<<8);
279 rf230_set_pan_addr(params_get_panid(),inv_node_id,
NULL);
282 rf230_set_pan_addr(params_get_panid(),params_get_panaddr(),(uint8_t *)&addr.u8);
284 rf230_set_channel(params_get_channel());
285 rf230_set_txpower(params_get_txpower());
288 PRINTA(
"EUI-64 MAC: %x-%x-%x-%x-%x-%x-%x-%x\n",addr.u8[0],addr.u8[1],addr.u8[2],addr.u8[3],addr.u8[4],addr.u8[5],addr.u8[6],addr.u8[7]);
290 PRINTA(
"MAC address ");
292 for (i=
sizeof(linkaddr_t); i>0; i--){
293 PRINTA(
"%x:",addr.u8[i-1]);
302 NETSTACK_NETWORK.init();
305 PRINTA(
"%s %s, channel %u , check rate %u Hz tx power %u\n",NETSTACK_MAC.name, NETSTACK_RDC.name, rf230_get_channel(),
306 CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1:NETSTACK_RDC.channel_check_interval()),
307 rf230_get_txpower());
308 #if UIP_CONF_IPV6_RPL
309 PRINTA(
"RPL Enabled\n");
312 PRINTA(
"Routing Enabled\n");
328 #ifdef RAVEN_LCD_INTERFACE
333 autostart_start(autostart_processes);
339 PRINTA(
"No index.html file found, creating upload.html!\n");
340 PRINTA(
"Formatting FLASH file system for coffee...");
344 int r = cfs_write(fa, &
"It works!", 9);
345 if (r<0) PRINTA(
"Can''t create /index.html!\n");
355 uip_ip6addr_t ipaddr;
357 uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
367 char buf1[40],buf[40];
370 for (i=0;i<UIP_DS6_ADDR_NB;i++) {
371 if (uip_ds6_if.addr_list[i].isused) {
372 httpd_cgi_sprint_ip6(uip_ds6_if.addr_list[i].ipaddr,buf);
373 PRINTA(
"IPv6 Address: %s\n",buf);
377 eeprom_read_block (buf1,eemem_server_name,
sizeof(eemem_server_name));
378 eeprom_read_block (buf,eemem_domain_name,
sizeof(eemem_domain_name));
380 buf1[
sizeof(eemem_server_name)]=0;
382 buf[
sizeof(eemem_domain_name)]=0;
383 size=httpd_fs_get_size();
385 PRINTA(
".%s online with fixed %u byte web content\n",buf,size);
386 #elif COFFEE_FILES==1
387 PRINTA(
".%s online with static %u byte EEPROM file system\n",buf,size);
388 #elif COFFEE_FILES==2
389 PRINTA(
".%s online with dynamic %u KB EEPROM file system\n",buf,size>>10);
390 #elif COFFEE_FILES==3
391 PRINTA(
".%s online with static %u byte program memory file system\n",buf,size);
392 #elif COFFEE_FILES==4
393 PRINTA(
".%s online with dynamic %u KB program memory file system\n",buf,size>>10);
404 #if ROUTES && UIP_CONF_IPV6
406 ipaddr_add(
const uip_ipaddr_t *addr)
410 for(i = 0, f = 0; i <
sizeof(uip_ipaddr_t); i += 2) {
411 a = (addr->u8[i] << 8) + addr->u8[i + 1];
412 if(a == 0 && f >= 0) {
413 if(f++ == 0) PRINTF(
"::");
450 NETSTACK_RDC.input();
457 extern uint8_t rf230_calibrated;
458 if (rf230_calibrated) {
459 PRINTD(
"\nRF230 calibrated!\n");
467 debugflow[debugflowsize]=0;
468 PRINTF(
"%s",debugflow);
488 if ((clocktime%STAMPS)==0) {
493 extern volatile unsigned long radioontime;
494 PRINTF(
"%u(%u)s\n",clocktime,radioontime);
496 PRINTF(
"%us\n",clocktime);
505 #if PINGS && UIP_CONF_IPV6
506 extern void raven_ping6(
void);
507 if ((clocktime%PINGS)==1) {
513 #if ROUTES && UIP_CONF_IPV6
514 if ((clocktime%ROUTES)==2) {
519 PRINTF(
"\nAddresses [%u max]\n",UIP_DS6_ADDR_NB);
520 for (i=0;i<UIP_DS6_ADDR_NB;i++) {
521 if (uip_ds6_if.addr_list[i].isused) {
522 ipaddr_add(&uip_ds6_if.addr_list[i].ipaddr);
526 PRINTF(
"\nNeighbors [%u max]\n",NBR_TABLE_MAX_NEIGHBORS);
527 for(nbr = nbr_table_head(ds6_neighbors);
529 nbr = nbr_table_next(ds6_neighbors, nbr)) {
530 ipaddr_add(&nbr->ipaddr);
534 if (j) PRINTF(
" <none>");
537 PRINTF(
"\nRoutes [%u max]\n",UIP_DS6_ROUTE_NB);
539 for(r = uip_ds6_route_head();
541 r = uip_ds6_route_next(r)) {
542 ipaddr_add(&r->ipaddr);
543 PRINTF(
"/%u (via ", r->length);
544 ipaddr_add(uip_ds6_route_nexthop(r));
545 PRINTF(
") %lus\n", r->state.lifetime);
549 if (j) PRINTF(
" <none>");
550 PRINTF(
"\n---------\n");
555 if ((clocktime%STACKMONITOR)==3) {
556 extern uint16_t __bss_end;
557 uint16_t p=(uint16_t)&__bss_end;
559 if (*(uint16_t *)p != 0x4242) {
560 PRINTF(
"Never-used stack > %d bytes\n",p-(uint16_t)&__bss_end);
564 }
while (p<RAMEND-10);
572 extern uint8_t rf230processflag;
573 if (rf230processflag) {
574 PRINTF(
"rf230p%d",rf230processflag);
580 extern uint8_t rf230_interrupt_flag;
581 if (rf230_interrupt_flag) {
583 PRINTF(
"**RI%u",rf230_interrupt_flag);
585 rf230_interrupt_flag=0;
594 void log_message(
char *m1,
char *m2)
596 PRINTF(
"%s%s\n", m1, m2);
void rs232_init(void)
Initialize the RS232 module.
#define F_CPU
CPU core frequency resulting from the chosen divisors and multipliers.
An entry in the routing table.
A MAC framer for IEEE 802.15.4
void process_poll(struct process *p)
Request a process to be polled.
CCIF uip_lladdr_t uip_lladdr
Host L2 address.
802.15.4 frame creation and parsing functions
int cfs_open(const char *name, int flags)
Open a file.
#define CFS_WRITE
Specify that cfs_open() should open a file for writing.
void watchdog_start(void)
Starts the WDT in watchdog mode if enabled by user configuration, maximum interval.
int rtimer_set(struct rtimer *rtimer, rtimer_clock_t time, rtimer_clock_t duration, rtimer_callback_t func, void *ptr)
Post a real-time task.
void rtimer_init(void)
Initialize the real-time scheduler.
Example glue code between the existing MAC code and the Contiki mac interface.
void calibrate_rc_osc_32k(void)
Calibrate the internal RC oscillator.
void rs232_set_input(int(*f)(unsigned char))
Set an input handler for incoming RS232 data.
#define NULL
The null pointer.
#define CFS_READ
Specify that cfs_open() should open a file for reading.
void clock_init(void)
Initialize the clock library.
int main(void)
This is main...
void packetbuf_set_datalen(uint16_t len)
Set the length of the data in the packetbuf.
void process_init(void)
Initialize the process module.
Header file for the Rime stack
Header file for the 6lowpan implementation (RFC4944 and draft-hui-6lowpan-hc-01) ...
void random_init(unsigned short seed)
Seed the cc2430 random number generator.
void * packetbuf_hdrptr(void)
Get a pointer to the header in the packetbuf, for outbound packets.
Convenience function for printing system statistics
Generic serial I/O process header filer.
void watchdog_periodic(void)
Writes the WDT clear sequence.
void ctimer_init(void)
Initialize the callback timer library.
CCIF unsigned long clock_seconds(void)
Get the current value of the platform seconds.
void packetbuf_clear(void)
Clear and reset the packetbuf.
void process_start(struct process *p, process_data_t data)
Start a process.
int cfs_coffee_format(void)
Format the storage area assigned to Coffee.
#define RTIMER_NOW()
Get the current clock time.
Interface structure (contains all the interface variables)
int process_run(void)
Run the system once - call poll handlers and process one event.
#define PACKETBUF_SIZE
The size of the packetbuf, in bytes.
void linkaddr_set_node_addr(linkaddr_t *t)
Set the address of the current node.
Representation of a real-time task.
void * packetbuf_dataptr(void)
Get a pointer to the data in the packetbuf.
Header for the Coffee file system.
#define uip_ip6addr(addr, addr0, addr1, addr2, addr3, addr4, addr5, addr6, addr7)
Construct an IPv6 address from eight 16-bit words.
void watchdog_init(void)
Copyright (c) 2014, Analog Devices, Inc.
void cfs_close(int fd)
Close an open file.
#define CLOCK_SECOND
A second, measured in system clock time.
An entry in the nbr cache.