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"
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");
267 #if NETSTACK_CONF_WITH_IPV6
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());
281 #if NETSTACK_CONF_WITH_IPV6
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");
311 #if NETSTACK_CONF_WITH_IPV6 || NETSTACK_CONF_WITH_IPV4
315 #ifdef RAVEN_LCD_INTERFACE
320 autostart_start(autostart_processes);
326 PRINTA(
"No index.html file found, creating upload.html!\n");
327 PRINTA(
"Formatting FLASH file system for coffee...");
331 int r = cfs_write(fa, &
"It works!", 9);
332 if (r<0) PRINTA(
"Can''t create /index.html!\n");
343 uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0);
356 for (i=0;i<UIP_DS6_ADDR_NB;i++) {
358 httpd_cgi_sprint_ip6(
uip_ds6_if.addr_list[i].ipaddr,buf);
359 PRINTA(
"IPv6 Address: %s\n",buf);
363 eeprom_read_block (buf,eemem_server_name,
sizeof(eemem_server_name));
365 buf[
sizeof(eemem_server_name)]=0;
368 eeprom_read_block (buf,eemem_domain_name,
sizeof(eemem_domain_name));
370 buf[
sizeof(eemem_domain_name)]=0;
371 size=httpd_fs_get_size();
373 PRINTA(
".%s online with fixed %u byte web content\n",buf,size);
374 #elif COFFEE_FILES==1
375 PRINTA(
".%s online with static %u byte EEPROM file system\n",buf,size);
376 #elif COFFEE_FILES==2
377 PRINTA(
".%s online with dynamic %u KB EEPROM file system\n",buf,size>>10);
378 #elif COFFEE_FILES==3
379 PRINTA(
".%s online with static %u byte program memory file system\n",buf,size);
380 #elif COFFEE_FILES==4
381 PRINTA(
".%s online with dynamic %u KB program memory file system\n",buf,size>>10);
389 #if RF230BB_CONF_LEDONPORTE1
396 #if ROUTES && NETSTACK_CONF_WITH_IPV6
398 ipaddr_add(
const uip_ipaddr_t *addr)
402 for(i = 0, f = 0; i <
sizeof(uip_ipaddr_t); i += 2) {
403 a = (addr->u8[i] << 8) + addr->u8[i + 1];
404 if(a == 0 && f >= 0) {
405 if(f++ == 0) PRINTF(
"::");
424 #if NETSTACK_CONF_WITH_IPV6
436 #if RF230BB_CONF_LEDONPORTE1
439 #if defined(RAVEN_LCD_INTERFACE)&&0
441 extern void raven_ping6(
void);
456 NETSTACK_RDC.input();
463 extern uint8_t rf230_calibrated;
464 if (rf230_calibrated) {
465 PRINTD(
"\nRF230 calibrated!\n");
473 debugflow[debugflowsize]=0;
474 PRINTF(
"%s",debugflow);
494 if ((clocktime%STAMPS)==0) {
499 extern volatile unsigned long radioontime;
500 PRINTF(
"%u(%u)s\n",clocktime,radioontime);
502 PRINTF(
"%us\n",clocktime);
511 #if PINGS && NETSTACK_CONF_WITH_IPV6
512 extern void raven_ping6(
void);
513 if ((clocktime%PINGS)==1) {
519 #if ROUTES && NETSTACK_CONF_WITH_IPV6
520 if ((clocktime%ROUTES)==2) {
525 PRINTF(
"\nAddresses [%u max]\n",UIP_DS6_ADDR_NB);
526 for (i=0;i<UIP_DS6_ADDR_NB;i++) {
527 if (uip_ds6_if.addr_list[i].isused) {
528 ipaddr_add(&uip_ds6_if.addr_list[i].ipaddr);
532 PRINTF(
"\nNeighbors [%u max]\n",NBR_TABLE_MAX_NEIGHBORS);
534 for(nbr = nbr_table_head(ds6_neighbors);
536 nbr = nbr_table_next(ds6_neighbors, nbr)) {
537 ipaddr_add(&nbr->ipaddr);
541 if (j) PRINTF(
" <none>");
542 PRINTF(
"\nRoutes [%u max]\n",UIP_DS6_ROUTE_NB);
545 PRINTF(
"\nRoutes [%u max]\n",UIP_DS6_ROUTE_NB);
547 for(r = uip_ds6_route_head();
549 r = uip_ds6_route_next(r)) {
550 ipaddr_add(&r->ipaddr);
551 PRINTF(
"/%u (via ", r->length);
552 ipaddr_add(uip_ds6_route_nexthop(r));
553 PRINTF(
") %lus\n", r->state.lifetime);
557 if (j) PRINTF(
" <none>");
558 PRINTF(
"\n---------\n");
563 if ((clocktime%STACKMONITOR)==3) {
564 extern uint16_t __bss_end;
565 uint16_t p=(uint16_t)&__bss_end;
567 if (*(uint16_t *)p != 0x4242) {
568 PRINTF(
"Never-used stack > %d bytes\n",p-(uint16_t)&__bss_end);
572 }
while (p<RAMEND-10);
580 extern uint8_t rf230processflag;
581 if (rf230processflag) {
582 PRINTF(
"rf230p%d",rf230processflag);
588 extern uint8_t rf230_interrupt_flag;
589 if (rf230_interrupt_flag) {
591 PRINTF(
"**RI%u",rf230_interrupt_flag);
593 rf230_interrupt_flag=0;
602 void log_message(
char *m1,
char *m2)
604 PRINTF(
"%s%s\n", m1, m2);
void * packetbuf_dataptr(void)
Get a pointer to the data in the packetbuf.
int cfs_open(const char *name, int flags)
Open a file.
void process_poll(struct process *p)
Request a process to be polled.
static uip_ipaddr_t ipaddr
Pointer to prefix information option in uip_buf.
#define CFS_WRITE
Specify that cfs_open() should open a file for writing.
static uip_ds6_addr_t * addr
Pointer to a router list entry.
#define RTIMER_NOW()
Get the current clock time.
void cfs_close(int fd)
Close an open file.
void packetbuf_clear(void)
Clear and reset the packetbuf.
#define CFS_READ
Specify that cfs_open() should open a file for reading.
void random_init(unsigned short seed)
Seed the cc2538 random number generator.
#define PACKETBUF_SIZE
The size of the packetbuf, in bytes.
This file contains radio driver code.
void clock_init(void)
Initialize the clock library.
An entry in the nbr cache.
void * packetbuf_hdrptr(void)
Get a pointer to the header in the packetbuf, for outbound packets.
#define PORTE
Peripheral PORTE base pointer.
int process_run(void)
Run the system once - call poll handlers and process one event.
Interface structure (contains all the interface variables)
Header file for the Rime stack
#define NULL
The null pointer.
static uip_ds6_nbr_t * nbr
Pointer to llao option in uip_buf.
int cfs_coffee_format(void)
Format the storage area assigned to Coffee.
802.15.4 frame creation and parsing functions
void rs232_init(void)
Initialize the RS232 module.
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 linkaddr_set_node_addr(linkaddr_t *t)
Set the address of the current node.
void watchdog_periodic(void)
Writes the WDT clear sequence.
Convenience function for printing system statistics
void calibrate_rc_osc_32k(void)
Calibrate the internal RC oscillator.
#define CLOCK_SECOND
A second, measured in system clock time.
void rs232_set_input(int(*f)(unsigned char))
Set an input handler for incoming RS232 data.
#define uip_ip6addr(addr, addr0, addr1, addr2, addr3, addr4, addr5, addr6, addr7)
Construct an IPv6 address from eight 16-bit words.
void packetbuf_set_datalen(uint16_t len)
Set the length of the data in the packetbuf.
void process_start(struct process *p, process_data_t data)
Start a process.
int main(void)
This is main...
Header for the Coffee file system.
uip_ds6_addr_t * uip_ds6_addr_add(uip_ipaddr_t *ipaddr, unsigned long vlifetime, uint8_t type)
Add a unicast address to the interface.
void rtimer_init(void)
Initialize the real-time scheduler.
void watchdog_init(void)
Copyright (c) 2014, Analog Devices, Inc.
Generic serial I/O process header filer.
CCIF uip_lladdr_t uip_lladdr
Host L2 address.
CCIF unsigned long clock_seconds(void)
Get the current value of the platform seconds.
void process_init(void)
Initialize the process module.
void ctimer_init(void)
Initialize the callback timer library.
uip_ds6_netif_t uip_ds6_if
The single interface.
Representation of a real-time task.
void watchdog_start(void)
Starts the WDT in watchdog mode if enabled by user configuration, maximum interval.
Header file for the 6lowpan implementation (RFC4944 and draft-hui-6lowpan-hc-01) ...
An entry in the routing table.
A MAC framer for IEEE 802.15.4