32 #define PRINTF(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
34 #define ANNOUNCE_BOOT 1 //adds about 600 bytes to program size
36 #define PRINTA(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
43 #define PRINTD(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
48 #include <avr/pgmspace.h>
50 #include <avr/eeprom.h>
53 #include <dev/watchdog.h>
55 #include "loader/symbols-def.h"
56 #include "loader/symtab.h"
59 #include "radio/rf230bb/rf230bb.h"
65 #include "contiki-net.h"
66 #include "contiki-lib.h"
68 #include "dev/rs232.h"
72 #ifdef RAVEN_LCD_INTERFACE
73 #include "raven-lcd.h"
78 #include "httpd-cgi.h"
86 #if UIP_CONF_ROUTER&&0
87 #include "net/routing/rimeroute.h"
88 #include "net/rime/rime-udp.h"
96 uint8_t debugflowsize,debugflow[DEBUGFLOWSIZE];
97 #define DEBUGFLOW(c) if (debugflowsize<(DEBUGFLOWSIZE-1)) debugflow[debugflowsize++]=c
105 #define PERIODICPRINTS 1
110 #define STACKMONITOR 1024
114 uint8_t rtimerflag=1;
116 void rtimercycle(
void) {rtimerflag=1;}
126 #include <avr/signature.h>
129 typedef struct {
const unsigned char B2;
const unsigned char B1;
const unsigned char B0;} __signature_t;
130 #define SIGNATURE __signature_t __signature __attribute__((section (".signature")))
140 FUSES ={.low = 0xe2, .high = 0x99, .extended = 0xff,};
143 FUSES ={.low = 0xC2, .high = 0x99, .extended = 0xfe,};
147 rng_get_uint8(
void) {
151 j = (PHY_RSSI&0xc0) + ((PHY_RSSI>>2)&0x30) + ((PHY_RSSI>>4)&0x0c) + ((PHY_RSSI>>6)&0x03);
160 while (ADCSRA&(1<<ADSC));
165 PRINTD(
"rng issues %d\n",j);
171 void initialize(
void)
179 #if !RF230BB_CONF_LEDONPORTE1 //Conflicts with USART0
180 #ifdef RAVEN_LCD_INTERFACE
181 rs232_init(RS232_PORT_0, USART_BAUD_38400,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
185 rs232_init(RS232_PORT_0, USART_BAUD_38400,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
190 rs232_init(RS232_PORT_1, USART_BAUD_57600,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
192 #if RF230BB_CONF_LEDONPORTE1 || defined(RAVEN_LCD_INTERFACE)
193 rs232_redirect_stdout(RS232_PORT_1);
195 rs232_redirect_stdout(RS232_PORT_0);
199 if(MCUSR & (1<<PORF )) PRINTD(
"Power-on reset.\n");
200 if(MCUSR & (1<<EXTRF)) PRINTD(
"External reset!\n");
201 if(MCUSR & (1<<BORF )) PRINTD(
"Brownout reset!\n");
202 if(MCUSR & (1<<WDRF )) PRINTD(
"Watchdog reset!\n");
203 if(MCUSR & (1<<JTRF )) PRINTD(
"JTAG reset!\n");
211 extern uint16_t __bss_end;
212 uint16_t p=(uint16_t)&__bss_end;
214 *(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);
251 NETSTACK_RADIO.init();
263 if (params_get_eui64(addr.u8)) {
264 PRINTA(
"Random EUI64 address generated\n");
268 memcpy(&
uip_lladdr.addr, &addr.u8,
sizeof(linkaddr_t));
270 node_id=get_panaddr_from_eeprom();
271 addr.u8[1]=node_id&0xff;
272 addr.u8[0]=(node_id&0xff00)>>8;
273 PRINTA(
"Node ID from eeprom: %X\n",node_id);
277 rf230_set_pan_addr(params_get_panid(),params_get_panaddr(),(uint8_t *)&addr.u8);
278 rf230_set_channel(params_get_channel());
279 rf230_set_txpower(params_get_txpower());
282 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]);
284 PRINTA(
"MAC address ");
286 for (i=
sizeof(linkaddr_t); i>0; i--){
287 PRINTA(
"%x:",addr.u8[i-1]);
296 NETSTACK_NETWORK.init();
299 PRINTA(
"%s %s, channel %u , check rate %u Hz tx power %u\n",NETSTACK_MAC.name, NETSTACK_RDC.name, rf230_get_channel(),
300 CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1:NETSTACK_RDC.channel_check_interval()),
301 rf230_get_txpower());
302 #if UIP_CONF_IPV6_RPL
303 PRINTA(
"RPL Enabled\n");
306 PRINTA(
"Routing Enabled\n");
313 #ifdef RAVEN_LCD_INTERFACE
318 autostart_start(autostart_processes);
324 PRINTA(
"No index.html file found, creating upload.html!\n");
325 PRINTA(
"Formatting FLASH file system for coffee...");
329 int r = cfs_write(fa, &
"It works!", 9);
330 if (r<0) PRINTA(
"Can''t create /index.html!\n");
340 uip_ip6addr_t ipaddr;
342 uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
354 for (i=0;i<UIP_DS6_ADDR_NB;i++) {
355 if (uip_ds6_if.addr_list[i].isused) {
356 httpd_cgi_sprint_ip6(uip_ds6_if.addr_list[i].ipaddr,buf);
357 PRINTA(
"IPv6 Address: %s\n",buf);
361 eeprom_read_block (buf,eemem_server_name,
sizeof(eemem_server_name));
363 buf[
sizeof(eemem_server_name)]=0;
366 eeprom_read_block (buf,eemem_domain_name,
sizeof(eemem_domain_name));
368 buf[
sizeof(eemem_domain_name)]=0;
369 size=httpd_fs_get_size();
371 PRINTA(
".%s online with fixed %u byte web content\n",buf,size);
372 #elif COFFEE_FILES==1
373 PRINTA(
".%s online with static %u byte EEPROM file system\n",buf,size);
374 #elif COFFEE_FILES==2
375 PRINTA(
".%s online with dynamic %u KB EEPROM file system\n",buf,size>>10);
376 #elif COFFEE_FILES==3
377 PRINTA(
".%s online with static %u byte program memory file system\n",buf,size);
378 #elif COFFEE_FILES==4
379 PRINTA(
".%s online with dynamic %u KB program memory file system\n",buf,size>>10);
387 #if RF230BB_CONF_LEDONPORTE1
394 #if ROUTES && UIP_CONF_IPV6
396 ipaddr_add(
const uip_ipaddr_t *addr)
400 for(i = 0, f = 0; i <
sizeof(uip_ipaddr_t); i += 2) {
401 a = (addr->u8[i] << 8) + addr->u8[i + 1];
402 if(a == 0 && f >= 0) {
403 if(f++ == 0) PRINTF(
"::");
434 #if RF230BB_CONF_LEDONPORTE1
437 #if defined(RAVEN_LCD_INTERFACE)&&0
439 extern void raven_ping6(
void);
454 NETSTACK_RDC.input();
461 extern uint8_t rf230_calibrated;
462 if (rf230_calibrated) {
463 PRINTD(
"\nRF230 calibrated!\n");
471 debugflow[debugflowsize]=0;
472 PRINTF(
"%s",debugflow);
492 if ((clocktime%STAMPS)==0) {
497 extern volatile unsigned long radioontime;
498 PRINTF(
"%u(%u)s\n",clocktime,radioontime);
500 PRINTF(
"%us\n",clocktime);
509 #if PINGS && UIP_CONF_IPV6
510 extern void raven_ping6(
void);
511 if ((clocktime%PINGS)==1) {
517 #if ROUTES && UIP_CONF_IPV6
518 if ((clocktime%ROUTES)==2) {
523 PRINTF(
"\nAddresses [%u max]\n",UIP_DS6_ADDR_NB);
524 for (i=0;i<UIP_DS6_ADDR_NB;i++) {
525 if (uip_ds6_if.addr_list[i].isused) {
526 ipaddr_add(&uip_ds6_if.addr_list[i].ipaddr);
530 PRINTF(
"\nNeighbors [%u max]\n",NBR_TABLE_MAX_NEIGHBORS);
532 for(nbr = nbr_table_head(ds6_neighbors);
534 nbr = nbr_table_next(ds6_neighbors, nbr)) {
535 ipaddr_add(&nbr->ipaddr);
539 if (j) PRINTF(
" <none>");
540 PRINTF(
"\nRoutes [%u max]\n",UIP_DS6_ROUTE_NB);
543 PRINTF(
"\nRoutes [%u max]\n",UIP_DS6_ROUTE_NB);
545 for(r = uip_ds6_route_head();
547 r = uip_ds6_route_next(r)) {
548 ipaddr_add(&r->ipaddr);
549 PRINTF(
"/%u (via ", r->length);
550 ipaddr_add(uip_ds6_route_nexthop(r));
551 PRINTF(
") %lus\n", r->state.lifetime);
555 if (j) PRINTF(
" <none>");
556 PRINTF(
"\n---------\n");
561 if ((clocktime%STACKMONITOR)==3) {
562 extern uint16_t __bss_end;
563 uint16_t p=(uint16_t)&__bss_end;
565 if (*(uint16_t *)p != 0x4242) {
566 PRINTF(
"Never-used stack > %d bytes\n",p-(uint16_t)&__bss_end);
570 }
while (p<RAMEND-10);
578 extern uint8_t rf230processflag;
579 if (rf230processflag) {
580 PRINTF(
"rf230p%d",rf230processflag);
586 extern uint8_t rf230_interrupt_flag;
587 if (rf230_interrupt_flag) {
589 PRINTF(
"**RI%u",rf230_interrupt_flag);
591 rf230_interrupt_flag=0;
600 void log_message(
char *m1,
char *m2)
602 PRINTF(
"%s%s\n", m1, m2);
void rs232_init(void)
Initialize the RS232 module.
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 PORTE
Peripheral PORTE base pointer.
#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.
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.