34 #define PRINTF(FORMAT, args ...) printf_P(PSTR(FORMAT),##args)
36 #define ANNOUNCE_BOOT 1
38 #define PRINTA(FORMAT, args ...) printf_P(PSTR(FORMAT),##args)
45 #define PRINTD(FORMAT, args ...) printf_P(PSTR(FORMAT),##args)
50 #include <avr/pgmspace.h>
52 #include <avr/eeprom.h>
55 #include <dev/watchdog.h>
57 #include "loader/symbols-def.h"
58 #include "loader/symtab.h"
70 #include "contiki-net.h"
71 #include "contiki-lib.h"
73 #include "dev/rs232.h"
79 #include "httpd-cgi.h"
87 #if UIP_CONF_ROUTER && 0
88 #include "net/routing/rimeroute.h"
89 #include "net/rime/rime-udp.h"
97 uint8_t debugflowsize, debugflow[DEBUGFLOWSIZE];
98 #define DEBUGFLOW(c) if(debugflowsize < (DEBUGFLOWSIZE - 1)) debugflow[debugflowsize++] = c
106 #define PERIODICPRINTS 1
111 #define STACKMONITOR 1024
115 uint8_t rtimerflag = 1;
127 uint16_t ledtimer_red, ledtimer_yellow;
135 #include <avr/signature.h>
138 typedef struct {
const unsigned char B2;
139 const unsigned char B1;
140 const unsigned char B0;
142 #define SIGNATURE __signature_t __signature __attribute__((section(".signature")))
152 FUSES = { .low = 0xe2, .high = 0x99, .extended = 0xff, };
155 FUSES = { .low = 0xC2, .high = 0x99, .extended = 0xfe, };
164 j = (PHY_RSSI & 0xc0) + ((PHY_RSSI >> 2) & 0x30) + ((PHY_RSSI >> 4) & 0x0c) + ((PHY_RSSI >> 6) & 0x03);
169 for(i = 0; i < 4; i++) {
173 while(ADCSRA & (1 << ADSC)) ;
178 PRINTD(
"rng issues %d\n", j);
191 rs232_init(RS232_PORT_0, USART_BAUD_38400, USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
192 rs232_redirect_stdout(RS232_PORT_0);
205 if(MCUSR & (1 << PORF)) {
206 PRINTD(
"Power-on reset.\n");
208 if(MCUSR & (1 << EXTRF)) {
209 PRINTD(
"External reset!\n");
211 if(MCUSR & (1 << BORF)) {
212 PRINTD(
"Brownout reset!\n");
214 if(MCUSR & (1 << WDRF)) {
215 PRINTD(
"Watchdog reset!\n");
217 if(MCUSR & (1 << JTRF)) {
218 PRINTD(
"JTAG reset!\n");
229 extern uint16_t __bss_end;
230 uint16_t p = (uint16_t)&__bss_end;
232 *(uint16_t *)p = 0x4242;
234 }
while(p < SP - 10);
238 #define CONF_CALIBRATE_OSCCAL 0
239 #if CONF_CALIBRATE_OSCCAL
242 extern uint8_t osccal_calibrated;
244 PRINTD(
"\nBefore calibration OSCCAL=%x\n", OSCCAL);
245 for(i = 0; i < 10; i++) {
247 PRINTD(
"Calibrated=%x\n", osccal_calibrated);
256 PRINTA(
"\n*******Booting %s*******\n", CONTIKI_VERSION_STRING);
269 NETSTACK_RADIO.init();
283 i2c_probed = i2c_probe();
286 if( i2c_probed & I2C_AT24MAC ) {
287 i2c_at24mac_read((
char *)&eui64, 1);
289 node_id = (eui64[1] << 8) + eui64[7];
292 printf(
"Random EUI64 address generated\n");
299 eui64[6] = node_id >> 8;
300 eui64[7] = node_id & 0xff;
306 #if NETSTACK_CONF_WITH_IPV6
307 memcpy(&addr.u8, &eui64,
sizeof(linkaddr_t));
308 memcpy(&
uip_lladdr.addr, &addr.u8,
sizeof(linkaddr_t));
311 rf230_set_pan_addr(params_get_panid(), params_get_panaddr(), (uint8_t *)&addr.u8);
312 rf230_set_channel(params_get_channel());
313 rf230_set_txpower(params_get_txpower());
315 #if NETSTACK_CONF_WITH_IPV6
316 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]);
318 PRINTA(
"MAC address ");
320 addr.u8[0] = eui64[1] ;
321 addr.u8[1] = eui64[7];
323 for(i =
sizeof(linkaddr_t); i > 0; i--) {
324 PRINTA(
"%x:", addr.u8[i - 1]);
333 NETSTACK_NETWORK.init();
336 PRINTA(
"MAC=%s, RDC=%s, NETWORK=%s, channel=%-u, check-rate-Hz=%-u, tx-power=%-u\n", NETSTACK_MAC.name,
337 NETSTACK_RDC.name, NETSTACK_NETWORK.name, rf230_get_channel(),
338 CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1 : NETSTACK_RDC.channel_check_interval()),
339 rf230_get_txpower());
340 #if UIP_CONF_IPV6_RPL
341 PRINTA(
"RPL Enabled\n");
344 PRINTA(
"Routing Enabled\n");
349 #if NETSTACK_CONF_WITH_IPV6 || NETSTACK_CONF_WITH_IPV4
354 autostart_start(autostart_processes);
360 PRINTA(
"No index.html file found, creating upload.html!\n");
361 PRINTA(
"Formatting FLASH file system for coffee...");
365 int r = cfs_write(fa, &
"It works!", 9);
367 PRINTA(
"Can''t create /index.html!\n");
391 for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
393 httpd_cgi_sprint_ip6(
uip_ds6_if.addr_list[i].ipaddr, buf);
394 PRINTA(
"IPv6 Address: %s\n", buf);
398 eeprom_read_block(buf, eemem_server_name,
sizeof(eemem_server_name));
400 buf[
sizeof(eemem_server_name)] = 0;
403 eeprom_read_block(buf, eemem_domain_name,
sizeof(eemem_domain_name));
405 buf[
sizeof(eemem_domain_name)] = 0;
406 size = httpd_fs_get_size();
408 PRINTA(
".%s online with fixed %u byte web content\n", buf, size);
409 #elif COFFEE_FILES == 1
410 PRINTA(
".%s online with static %u byte EEPROM file system\n", buf, size);
411 #elif COFFEE_FILES == 2
412 PRINTA(
".%s online with dynamic %u KB EEPROM file system\n", buf, size >> 10);
413 #elif COFFEE_FILES == 3
414 PRINTA(
".%s online with static %u byte program memory file system\n", buf, size);
415 #elif COFFEE_FILES == 4
416 PRINTA(
".%s online with dynamic %u KB program memory file system\n", buf, size >> 10);
429 #if ROUTES && NETSTACK_CONF_WITH_IPV6
431 ipaddr_add(
const uip_ipaddr_t *addr)
435 for(i = 0, f = 0; i <
sizeof(uip_ipaddr_t); i += 2) {
436 a = (addr->u8[i] << 8) + addr->u8[i + 1];
437 if(a == 0 && f >= 0) {
458 #if NETSTACK_CONF_WITH_IPV6
469 if(--ledtimer_red == 0) {
473 if(ledtimer_yellow) {
474 if(--ledtimer_yellow == 0) {
475 leds_off(LEDS_YELLOW);
479 leds_off(LEDS_YELLOW);
490 NETSTACK_RDC.input();
497 extern uint8_t rf230_calibrated;
498 if(rf230_calibrated) {
499 PRINTD(
"\nRF230 calibrated!\n");
500 rf230_calibrated = 0;
507 debugflow[debugflowsize] = 0;
508 PRINTF(
"%s", debugflow);
528 if((clocktime % STAMPS) == 0) {
533 extern volatile unsigned long radioontime;
534 PRINTF(
"%u(%u)s\n", clocktime, radioontime);
536 PRINTF(
"%us\n", clocktime);
544 #if PINGS && NETSTACK_CONF_WITH_IPV6
545 extern void raven_ping6(
void);
546 if((clocktime % PINGS) == 1) {
552 #if ROUTES && NETSTACK_CONF_WITH_IPV6
553 if((clocktime % ROUTES) == 2) {
558 PRINTF(
"\nAddresses [%u max]\n", UIP_DS6_ADDR_NB);
559 for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
560 if(uip_ds6_if.addr_list[i].isused) {
561 ipaddr_add(&uip_ds6_if.addr_list[i].ipaddr);
565 PRINTF(
"\nNeighbors [%u max]\n", NBR_TABLE_MAX_NEIGHBORS);
567 for(nbr = nbr_table_head(ds6_neighbors);
569 nbr = nbr_table_next(ds6_neighbors, nbr)) {
570 ipaddr_add(&nbr->ipaddr);
577 PRINTF(
"\nRoutes [%u max]\n", UIP_DS6_ROUTE_NB);
581 for(r = uip_ds6_route_head();
583 r = uip_ds6_route_next(r)) {
584 ipaddr_add(&r->ipaddr);
585 PRINTF(
"/%u (via ", r->length);
586 ipaddr_add(uip_ds6_route_nexthop(r));
587 PRINTF(
") %lus\n", r->state.lifetime);
594 PRINTF(
"\n---------\n");
599 if((clocktime % STACKMONITOR) == 3) {
600 extern uint16_t __bss_end;
601 uint16_t p = (uint16_t)&__bss_end;
603 if(*(uint16_t *)p != 0x4242) {
604 PRINTF(
"Never-used stack > %d bytes\n", p - (uint16_t)&__bss_end);
608 }
while(p < RAMEND - 10);
615 extern uint8_t rf230processflag;
616 if(rf230processflag) {
617 PRINTF(
"rf230p%d", rf230processflag);
618 rf230processflag = 0;
623 extern uint8_t rf230_interrupt_flag;
624 if(rf230_interrupt_flag) {
626 PRINTF(
"**RI%u", rf230_interrupt_flag);
628 rf230_interrupt_flag = 0;
637 log_message(
char *m1,
char *m2)
639 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.
void i2c_init(uint8_t port_sda, uint8_t pin_sda, uint8_t port_scl, uint8_t pin_scl, uint32_t bus_speed)
Initialize the I2C peripheral and pins.
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.
int serial_line_input_byte(unsigned char c)
Get one byte of input from the serial driver.
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