40 #include "dev/uart0.h"
41 #include "dev/watchdog.h"
43 #include "lib/random.h"
46 #include "dev/button-sensor.h"
48 #include "sys/clock.h"
56 #include "sys/node-id.h"
61 #include "dev/battery-sensor.h"
62 #include "dev/button-sensor.h"
63 #include "dev/sht11/sht11-sensor.h"
65 SENSORS(&button_sensor);
67 extern unsigned char node_mac[8];
69 #if DCOSYNCH_CONF_ENABLED
70 static struct timer mgt_timer;
80 #include "net/uip-fw-drv.h"
83 {
UIP_FW_NETIF(192, 168, 1, 2, 255, 255, 255, 255, slip_send) };
85 {
UIP_FW_NETIF(172, 16, 0, 0, 255, 255, 0, 0, uip_over_mesh_send) };
89 #define UIP_OVER_MESH_CHANNEL 8
91 static uint8_t is_gateway;
94 #ifdef EXPERIMENT_SETUP
95 #include "experiment-setup.h"
101 #define PRINTF(...) printf(__VA_ARGS__)
106 void init_platform(
void);
111 force_float_inclusion()
113 extern int __fixsfsi;
114 extern int __floatsisf;
118 return __fixsfsi + __floatsisf + __mulsf3 + __subsf3;
130 force_inclusion(
int d1,
int d2)
132 snprintf(
NULL, 0,
"%d", d1 % d2);
142 memset(&addr, 0,
sizeof(linkaddr_t));
144 memcpy(addr.u8, node_mac,
sizeof(addr.u8));
147 for(i = 0; i <
sizeof(linkaddr_t); ++i) {
148 addr.u8[i] = node_mac[7 - i];
151 addr.u8[0] = node_id & 0xff;
152 addr.u8[1] = node_id >> 8;
156 printf(
"Rime started with address ");
157 for(i = 0; i <
sizeof(addr.u8) - 1; i++) {
158 printf(
"%d.", addr.u8[i]);
160 printf(
"%d\n", addr.u8[i]);
164 print_processes(
struct process *
const processes[])
168 while(*processes !=
NULL) {
169 printf(
" '%s'", (*processes)->name);
181 printf(
"%d.%d: making myself the IP network gateway.\n\n",
183 printf(
"IPv4 address of the gateway: %d.%d.%d.%d\n\n",
186 uip_over_mesh_make_announced_gateway();
193 main(
int argc,
char **argv)
221 if(!(node_mac[0] | node_mac[1] | node_mac[2] | node_mac[3] |
222 node_mac[4] | node_mac[5] | node_mac[6] | node_mac[7])) {
226 PRINTF(
"Node id is not set, using Z1 product ID\n");
239 node_mac[6] = node_id >> 8;
240 node_mac[7] = node_id & 0xff;
245 #warning "***** CHANGING DEFAULT MAC *****"
255 node_mac[6] = MACID >> 8;
256 node_mac[7] = MACID & 0xff;
259 #ifdef IEEE_802154_MAC_ADDRESS
262 uint8_t ieee[] = IEEE_802154_MAC_ADDRESS;
263 memcpy(node_mac, ieee,
sizeof(
uip_lladdr.addr));
264 node_mac[7] = node_id & 0xff;
289 memset(longaddr, 0,
sizeof(longaddr));
291 printf(
"MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
292 longaddr[0], longaddr[1], longaddr[2], longaddr[3],
293 longaddr[4], longaddr[5], longaddr[6], longaddr[7]);
295 cc2420_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr);
301 PRINTF(
"Ref ID: %u\n", SERIALNUM);
303 PRINTF(CONTIKI_VERSION_STRING
" started. ");
306 PRINTF(
"Node id is set to %u.\n", node_id);
308 PRINTF(
"Node id not set\n");
322 NETSTACK_NETWORK.init();
324 printf(
"%s %s, channel check rate %lu Hz, radio channel %u\n",
325 NETSTACK_MAC.name, NETSTACK_RDC.name,
326 CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1 :
327 NETSTACK_RDC.channel_check_interval()),
328 CC2420_CONF_CHANNEL);
332 printf(
"Tentative link-local IPv6 address ");
336 lladdr = uip_ds6_get_link_local(-1);
337 for(i = 0; i < 7; ++i) {
338 printf(
"%02x%02x:", lladdr->ipaddr.u8[i * 2],
339 lladdr->ipaddr.u8[i * 2 + 1]);
341 printf(
"%02x%02x\n", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]);
344 if(!UIP_CONF_IPV6_RPL) {
350 printf(
"Tentative global IPv6 address ");
351 for(i = 0; i < 7; ++i) {
353 ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]);
356 ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]);
363 NETSTACK_NETWORK.init();
365 printf(
"%s %s, channel check rate %lu Hz, radio channel %u\n",
366 NETSTACK_MAC.name, NETSTACK_RDC.name,
367 CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1 :
368 NETSTACK_RDC.channel_check_interval()),
369 CC2420_CONF_CHANNEL);
372 #if !WITH_UIP && !WITH_UIP6
379 #if TIMESYNCH_CONF_ENABLED
389 slip_set_input_callback(set_gateway);
392 uip_ipaddr_t hostaddr,
netmask;
403 uip_over_mesh_set_net(&hostaddr, &netmask);
405 uip_over_mesh_set_gateway_netif(&slipif);
407 uip_over_mesh_init(UIP_OVER_MESH_CHANNEL);
408 printf(
"uIP started with IP address %d.%d.%d.%d\n",
414 ENERGEST_ON(ENERGEST_TYPE_CPU);
416 print_processes(autostart_processes);
417 autostart_start(autostart_processes);
422 #if DCOSYNCH_CONF_ENABLED
443 static unsigned long irq_energest = 0;
445 #if DCOSYNCH_CONF_ENABLED
454 ENERGEST_OFF(ENERGEST_TYPE_CPU);
455 ENERGEST_ON(ENERGEST_TYPE_LPM);
459 energest_type_set(ENERGEST_TYPE_IRQ, irq_energest);
461 _BIS_SR(GIE | SCG0 | SCG1 | CPUOFF);
471 irq_energest = energest_type_time(ENERGEST_TYPE_IRQ);
474 ENERGEST_OFF(ENERGEST_TYPE_LPM);
475 ENERGEST_ON(ENERGEST_TYPE_CPU);
484 log_message(
char *m1,
char *m2)
486 printf(
"%s%s\n", m1, m2);
int serial_line_input_byte(unsigned char c)
Get one byte of input from the serial driver.
#define uip_sethostaddr(addr)
Set the IP address of this host.
linkaddr_t linkaddr_node_addr
The Rime address of the node.
uIP packet forwarding header file.
int process_nevents(void)
Number of events waiting to be processed.
CCIF uip_lladdr_t uip_lladdr
Host L2 address.
802.15.4 frame creation and parsing functions
#define UIP_FW_NETIF(ip1, ip2, ip3, ip4, nm1, nm2, nm3, nm4, outputfunc)
Instantiating macro for a uIP network interface.
Representation of a uIP network interface.
#define LEDS_RED
LED1 (Red) -> PC0.
Unicast address structure.
void timesynch_init(void)
Initialize the timesynch module.
void watchdog_start(void)
Starts the WDT in watchdog mode if enabled by user configuration, maximum interval.
uip_ipaddr_t ipaddr
The IP address of this interface.
Header file for the uIP TCP/IP stack.
void uip_ds6_set_addr_iid(uip_ipaddr_t *ipaddr, uip_lladdr_t *lladdr)
set the last 64 bits of an IP address based on the MAC address
void rtimer_init(void)
Initialize the real-time scheduler.
void uart0_init(unsigned long ubr)
Initalize the RS232 port.
Network interface and stateless autoconfiguration (RFC 4862)
void timer_set(struct timer *t, clock_time_t interval)
Set a timer.
#define NULL
The null pointer.
void uip_log(char *msg)
Print out a uIP log message.
Header file for tunnelling uIP over Rime mesh
void clock_init(void)
Initialize the clock library.
int main(void)
This is main...
void process_init(void)
Initialize the process module.
Header file for the Rime stack
Coffee architecture-dependent header for the Zolertia Z1 platform.
void timesynch_set_authority_level(int level)
Set the authority level of the current time.
#define LEDS_GREEN
LED3 (Green) -> PC2.
void linkaddr_copy(linkaddr_t *dest, const linkaddr_t *src)
Copy a Rime address.
Device drivers header file for adxl345 accelerometer in Zolertia Z1.
void slip_arch_init(unsigned long ubr)
Initalize the RS232 port and the SLIP driver.
void watchdog_stop(void)
In watchdog mode, the WDT can not be stopped.
Generic serial I/O process header filer.
void watchdog_periodic(void)
Writes the WDT clear sequence.
Header file for module for automatically starting and exiting a list of processes.
#define uip_ipaddr_copy(dest, src)
Copy an IP address from one place to another.
void ctimer_init(void)
Initialize the callback timer library.
#define uip_ipaddr_to_quad(a)
Convert an IP address to four bytes separated by commas.
void uip_init(void)
uIP initialization function.
void uip_fw_default(struct uip_fw_netif *netif)
Register a default network interface.
uip_ipaddr_t netmask
The netmask of the interface.
void process_start(struct process *p, process_data_t data)
Start a process.
#define ADDR_TENTATIVE
Possible states for the an address (RFC 4862)
int process_run(void)
Run the system once - call poll handlers and process one event.
void linkaddr_set_node_addr(linkaddr_t *t)
Set the address of the current node.
Header for the Coffee file system.
void clock_wait(clock_time_t t)
Wait for a given number of ticks.
#define uip_ipaddr(addr, addr0, addr1, addr2, addr3)
Construct an IP address from four bytes.
int timer_expired(struct timer *t)
Check if a timer has expired.
#define uip_ip6addr(addr, addr0, addr1, addr2, addr3, addr4, addr5, addr6, addr7)
Construct an IPv6 address from eight 16-bit words.
#define uip_setnetmask(addr)
Set the netmask.
void timer_reset(struct timer *t)
Reset the timer with the same interval.
Include file for the Contiki low-layer network stack (NETSTACK)
#define CLOCK_SECOND
A second, measured in system clock time.