37 #include "isr_compat.h"
40 #include "cc1120-arch.h"
44 #include "dev/avr-handler.h"
48 #include "dev/uart0.h"
49 #include "dev/watchdog.h"
51 #include "lib/random.h"
54 #include "dev/button-sensor.h"
55 #include "dev/adxl345.h"
56 #include "sys/clock.h"
58 #include "dev/reset-sensor.h"
60 #if NETSTACK_CONF_WITH_IPV6
66 #include "sys/node-id.h"
71 #include "dev/battery-sensor.h"
72 #include "dev/button-sensor.h"
76 extern unsigned char node_mac[8];
78 #if DCOSYNCH_CONF_ENABLED
79 static struct timer mgt_timer;
82 #ifndef NETSTACK_CONF_WITH_IPV4
83 #define NETSTACK_CONF_WITH_IPV4 0
86 #if NETSTACK_CONF_WITH_IPV4
89 #include "net/uip-fw-drv.h"
94 {
UIP_FW_NETIF(172, 16, 0, 0, 255, 255, 0, 0, uip_over_mesh_send) };
98 #define UIP_OVER_MESH_CHANNEL 8
99 #if NETSTACK_CONF_WITH_IPV4
100 static uint8_t is_gateway;
103 #ifdef EXPERIMENT_SETUP
104 #include "experiment-setup.h"
110 #define PRINTF(...) printf(__VA_ARGS__)
115 void init_platform(
void);
120 force_float_inclusion()
122 extern int __fixsfsi;
123 extern int __floatsisf;
127 return __fixsfsi + __floatsisf + __mulsf3 + __subsf3;
139 force_inclusion(
int d1,
int d2)
141 snprintf(
NULL, 0,
"%d", d1 % d2);
151 memset(&addr, 0,
sizeof(linkaddr_t));
152 #if NETSTACK_CONF_WITH_IPV6
153 memcpy(addr.u8, node_mac,
sizeof(addr.u8));
156 for(i = 0; i <
sizeof(linkaddr_t); ++i) {
157 addr.u8[i] = node_mac[7 - i];
160 addr.u8[0] = node_id & 0xff;
161 addr.u8[1] = node_id >> 8;
173 print_processes(
struct process *
const processes[])
177 while(*processes !=
NULL) {
184 #if NETSTACK_CONF_WITH_IPV4
190 printf(
"%d.%d: making myself the IP network gateway.\n\n",
192 printf(
"IPv4 address of the gateway: %d.%d.%d.%d\n\n",
195 uip_over_mesh_make_announced_gateway();
202 main(
int argc,
char **argv)
211 RADIO_EN_PORT(DIR) |= BV(RADIO_EN_PIN);
212 RADIO_EN_PORT(OUT) |= BV(RADIO_EN_PIN);
215 cc1120_arch_pin_init();
223 #if NETSTACK_CONF_WITH_IPV4
228 #ifndef Z1_SAMPLER_AVR_DISABLE
242 if(!(node_mac[0] | node_mac[1] | node_mac[2] | node_mac[3] |
243 node_mac[4] | node_mac[5] | node_mac[6] | node_mac[7])) {
253 node_mac[6] = node_id >> 8;
254 node_mac[7] = node_id & 0xff;
259 #warning "***** CHANGING DEFAULT MAC *****"
269 node_mac[6] = MACID >> 8;
270 node_mac[7] = MACID & 0xff;
273 #ifdef IEEE_802154_MAC_ADDRESS
276 uint8_t ieee[] = IEEE_802154_MAC_ADDRESS;
277 memcpy(node_mac, ieee,
sizeof(
uip_lladdr.addr));
278 node_mac[7] = node_id & 0xff;
294 NETSTACK_RADIO.init();
297 #ifndef FESHIE_NO_ACC
299 #endif // FESHIE_NO_ACC
307 memset(longaddr, 0,
sizeof(longaddr));
321 PRINTF(CONTIKI_VERSION_STRING
" started. ");
324 reset_sensor.configure(SENSORS_ACTIVE,1);
325 printf(
"Reset Count %d \n",reset_sensor.value(0));
328 PRINTF(
"Node id is set to %u.\n", node_id);
330 PRINTF(
"Node id not set\n");
333 #if NETSTACK_CONF_WITH_IPV6
344 NETSTACK_NETWORK.init();
354 printf(
"Tentative link-local IPv6 address ");
358 lladdr = uip_ds6_get_link_local(-1);
359 for(i = 0; i < 7; ++i) {
360 printf(
"%02x%02x:", lladdr->ipaddr.u8[i * 2],
361 lladdr->ipaddr.u8[i * 2 + 1]);
363 printf(
"%02x%02x\n", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]);
366 if(!UIP_CONF_IPV6_RPL) {
372 printf(
"Tentative global IPv6 address ");
373 for(i = 0; i < 7; ++i) {
375 ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]);
378 ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]);
385 NETSTACK_NETWORK.init();
387 printf(
"%s %s, channel check rate %lu Hz, radio channel %u\n",
388 NETSTACK_MAC.name, NETSTACK_RDC.name,
389 CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1 :
390 NETSTACK_RDC.channel_check_interval()),
391 CC2420_CONF_CHANNEL);
394 #if !NETSTACK_CONF_WITH_IPV4 && !NETSTACK_CONF_WITH_IPV6
399 #ifndef Z1_SAMPLER_AVR_DISABLE
400 uart1_set_input(avr_input_byte);
401 avr_set_output(uart1_writearray);
409 leds_off(LEDS_GREEN);
411 #if TIMESYNCH_CONF_ENABLED
416 #if NETSTACK_CONF_WITH_IPV4
424 uip_ipaddr_t hostaddr,
netmask;
435 uip_over_mesh_set_net(&hostaddr, &netmask);
438 uip_over_mesh_set_gateway_netif(&slipif);
441 uip_over_mesh_init(UIP_OVER_MESH_CHANNEL);
442 printf(
"uIP started with IP address %d.%d.%d.%d\n",
448 ENERGEST_ON(ENERGEST_TYPE_CPU);
450 print_processes(autostart_processes);
451 autostart_start(autostart_processes);
456 #if DCOSYNCH_CONF_ENABLED
464 profile_episode_start();
472 profile_episode_end();
483 static unsigned long irq_energest = 0;
485 #if DCOSYNCH_CONF_ENABLED
494 ENERGEST_OFF(ENERGEST_TYPE_CPU);
495 ENERGEST_ON(ENERGEST_TYPE_LPM);
499 energest_type_set(ENERGEST_TYPE_IRQ, irq_energest);
501 _BIS_SR(GIE | SCG0 | SCG1 | CPUOFF);
511 irq_energest = energest_type_time(ENERGEST_TYPE_IRQ);
514 ENERGEST_OFF(ENERGEST_TYPE_LPM);
515 ENERGEST_ON(ENERGEST_TYPE_CPU);
531 log_message(
char *m1,
char *m2)
533 printf(
"%s%s\n", m1, m2);
void uip_log(char *msg)
Print out a uIP log message.
#define uip_sethostaddr(addr)
Set the IP address of this host.
static uip_ipaddr_t ipaddr
Pointer to prefix information option in uip_buf.
void uart0_init(unsigned long ubr)
Initalize the RS232 port.
void timer_reset(struct timer *t)
Reset the timer with the same interval.
#define uip_ipaddr(addr, addr0, addr1, addr2, addr3)
Construct an IP address from four bytes.
void timesynch_set_authority_level(int level)
Set the authority level of the current time.
static uip_ds6_addr_t * addr
Pointer to a router list entry.
uint8_t slip_send(void)
Send an IP packet from the uIP buffer with SLIP.
Header file for IPv6-related data structures.
void uart1_init(unsigned long ubr)
Initalize the RS232 port.
void timer_set(struct timer *t, clock_time_t interval)
Set a timer.
uip_ipaddr_t ipaddr
The IP address of this interface.
void watchdog_stop(void)
Stops the WDT such that it won't timeout and cause MCU reset.
Header file for tunnelling uIP over Rime mesh
void clock_init(void)
Initialize the clock library.
#define uip_ipaddr_copy(dest, src)
Copy an IP address from one place to another.
Platform configuration for the Z1-feshie platform
void uart1_pin_init(void)
Configure pins for RS232 port.
void i2c_enable(void)
Configure serial controller in I2C mode and set I2C speed.
int process_run(void)
Run the system once - call poll handlers and process one event.
Unicast address structure.
void slip_arch_init(unsigned long ubr)
Initalize the RS232 port and the SLIP driver.
void slip_set_input_callback(void(*c)(void))
Set a function to be called when there is activity on the SLIP interface; used for detecting if a nod...
SENSORS & button_sensor
Copyright (c) 2014, Analog Devices, Inc.
uip_ipaddr_t netmask
The netmask of the interface.
Header file for the Rime stack
#define uip_setnetmask(addr)
Set the netmask.
#define NULL
The null pointer.
#define uip_ipaddr_to_quad(a)
Convert an IP address to four bytes separated by commas.
802.15.4 frame creation and parsing functions
uIP packet forwarding header file.
void linkaddr_set_node_addr(linkaddr_t *t)
Set the address of the current node.
#define UIP_FW_NETIF(ip1, ip2, ip3, ip4, nm1, nm2, nm3, nm4, outputfunc)
Instantiating macro for a uIP network interface.
void watchdog_periodic(void)
Writes the WDT clear sequence.
#define ADDR_TENTATIVE
Possible states for the an address (RFC 4862)
#define CLOCK_SECOND
A second, measured in system clock time.
#define uip_ip6addr(addr, addr0, addr1, addr2, addr3, addr4, addr5, addr6, addr7)
Construct an IPv6 address from eight 16-bit words.
Header file for the uIP TCP/IP stack.
I2C communication device driver header file for Zolertia Z1 sensor node.
void clock_delay(unsigned int delay)
Obsolete delay function but we implement it here since some code still uses it.
void process_start(struct process *p, process_data_t data)
Start a process.
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.
Header file for module for automatically starting and exiting a list of processes.
void clock_wait(clock_time_t t)
Wait for a given number of ticks.
void timesynch_init(void)
Initialize the timesynch module.
void rtimer_init(void)
Initialize the real-time scheduler.
Generic serial I/O process header filer.
CCIF uip_lladdr_t uip_lladdr
Host L2 address.
void uip_init(void)
uIP initialization function.
int process_nevents(void)
Number of events waiting to be processed.
void process_init(void)
Initialize the process module.
void ctimer_init(void)
Initialize the callback timer library.
void linkaddr_copy(linkaddr_t *dest, const linkaddr_t *src)
Copy a Rime address.
linkaddr_t linkaddr_node_addr
The Rime address of the node.
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.
void clock_delay_usec(uint16_t usec)
Delay a given number of microseconds.
Coffee architecture-dependent header for the Zolertia Z1 platform.
Include file for the Contiki low-layer network stack (NETSTACK)
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 uip_fw_default(struct uip_fw_netif *netif)
Register a default network interface.
int timer_expired(struct timer *t)
Check if a timer has expired.
Representation of a uIP network interface.