Contiki 3.x
contiki-seedeye-main.c
Go to the documentation of this file.
1 /*
2  * Contiki SeedEye Platform project
3  *
4  * Copyright (c) 2012,
5  * Scuola Superiore Sant'Anna (http://www.sssup.it) and
6  * Consorzio Nazionale Interuniversitario per le Telecomunicazioni
7  * (http://www.cnit.it).
8  *
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in the
18  * documentation and/or other materials provided with the distribution.
19  * 3. Neither the name of the Institute nor the names of its contributors
20  * may be used to endorse or promote products derived from this software
21  * without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  */
36 
37 /**
38  * \addtogroup platform
39  * @{ */
40 
41 /**
42  * \defgroup SeedEye Contiki SEEDEYE Platform
43  *
44  * @{
45  */
46 
47 /**
48  * \file contiki-seedeye-main.c
49  * \brief Main program for the SEEDEYE port.
50  * \author Giovanni Pellerano <giovanni.pellerano@evilaliv3.org>
51  * \date 2012-03-21
52  */
53 
54 #include <contiki.h>
55 #include <clock.h>
56 #include <lib/random.h>
57 #include <dev/leds.h>
58 #include "dev/button-sensor.h"
59 #include "dev/battery-sensor.h"
60 #include <dev/watchdog.h>
61 
62 #include <pic32.h>
63 #include <pic32_clock.h>
64 
65 #include <debug-uart.h>
66 
67 #include <init-net.h>
68 
69 #include <stdio.h>
70 #include <string.h>
71 
72 #define DEBUG 1
73 #if DEBUG
74 #include <stdio.h>
75 #define PRINTF(...) printf(__VA_ARGS__)
76 #else
77 #define PRINTF(...)
78 #endif
79 
80 #if UIP_CONF_ROUTER
81 #ifndef UIP_ROUTER_MODULE
82 #ifdef UIP_CONF_ROUTER_MODULE
83 #define UIP_ROUTER_MODULE UIP_CONF_ROUTER_MODULE
84 #else /* UIP_CONF_ROUTER_MODULE */
85 #define UIP_ROUTER_MODULE rimeroute
86 #endif /* UIP_CONF_ROUTER_MODULE */
87 #endif /* UIP_ROUTER_MODULE */
88 extern const struct uip_router UIP_ROUTER_MODULE;
89 #endif /* UIP_CONF_ROUTER */
90 
91 SENSORS(&button_sensor);
92 
93 /*---------------------------------------------------------------------------*/
94 static void
95 print_processes(struct process *const processes[])
96 {
97  PRINTF("Starting:\n");
98 
99  while(*processes != NULL) {
100  PRINTF(" '%s'\n", (*processes)->name);
101  processes++;
102  }
103 
104  PRINTF("\n");
105 }
106 /*---------------------------------------------------------------------------*/
107 int
108 main(int argc, char **argv)
109 {
110  int32_t r;
111 
112  /* Initalizing main hardware */
113  pic32_init();
114  watchdog_init();
115  leds_init();
116 
117  clock_init();
118 
119  dbg_setup_uart(UART_DEBUG_BAUDRATE);
120 
121  PRINTF("Initialising Node: %d\n", SEEDEYE_ID);
122 
123  PRINTF("CPU Clock: %uMhz\n", pic32_clock_get_system_clock() / 1000000);
124  PRINTF("Peripheral Clock: %uMhz\n", pic32_clock_get_peripheral_clock() / 1000000);
125 
126  random_init(SEEDEYE_ID);
127 
128  process_init();
129  process_start(&etimer_process, NULL);
130  ctimer_init();
131  rtimer_init();
132 
133  energest_init();
134  ENERGEST_ON(ENERGEST_TYPE_CPU);
135 
136  process_start(&sensors_process, NULL);
137  SENSORS_ACTIVATE(battery_sensor);
138 
139  leds_on(LEDS_RED);
140 
141  /* Inizialize Network! */
142 
143  init_net(SEEDEYE_ID);
144 
145  leds_on(LEDS_RED);
146 
147  /* Starting autostarting process */
148  print_processes(autostart_processes);
149  autostart_start(autostart_processes);
150 
151  PRINTF("Processes running\n");
152 
153  leds_off(LEDS_ALL);
154 
155  watchdog_start();
156 
157  /*
158  * This is the scheduler loop.
159  */
160  while(1) {
161 
162  do {
163  /* Reset watchdog. */
165  r = process_run();
166  } while(r > 0);
167 
168  ENERGEST_OFF(ENERGEST_TYPE_CPU);
169  ENERGEST_ON(ENERGEST_TYPE_LPM);
170 
171  watchdog_stop();
172  asm volatile("wait");
173  watchdog_start();
174 
175  ENERGEST_OFF(ENERGEST_TYPE_LPM);
176  ENERGEST_ON(ENERGEST_TYPE_CPU);
177 
178  }
179 
180  return 0;
181 }
182 /*---------------------------------------------------------------------------*/
183 
184 /** @} */
185 /** @} */
186 
#define LEDS_RED
LED1 (Red) -&gt; PC0.
Definition: board.h:89
void watchdog_start(void)
Starts the WDT in watchdog mode if enabled by user configuration, maximum interval.
Definition: watchdog.c:49
void rtimer_init(void)
Initialize the real-time scheduler.
Definition: rtimer.c:61
uint32_t pic32_clock_get_peripheral_clock(void)
Calculate the peripheral clock.
Definition: pic32_clock.c:96
PIC32MX initialization routines.
#define NULL
The null pointer.
uint32_t pic32_clock_get_system_clock(void)
Calculate the system clock.
Definition: pic32_clock.c:82
CLOCK interface for PIC32MX (pic32mx795f512l)
void clock_init(void)
Initialize the clock library.
Definition: clock.c:76
int main(void)
This is main...
Definition: ethconfig.c:49
void process_init(void)
Initialize the process module.
Definition: process.c:208
void random_init(unsigned short seed)
Seed the cc2430 random number generator.
Definition: random.c:41
void watchdog_stop(void)
In watchdog mode, the WDT can not be stopped.
Definition: watchdog.c:58
void watchdog_periodic(void)
Writes the WDT clear sequence.
Definition: watchdog.c:64
void ctimer_init(void)
Initialize the callback timer library.
Definition: ctimer.c:91
void process_start(struct process *p, process_data_t data)
Start a process.
Definition: process.c:99
Network initialization for the SEEDEYE port.
int process_run(void)
Run the system once - call poll handlers and process one event.
Definition: process.c:302
void watchdog_init(void)
Copyright (c) 2014, Analog Devices, Inc.
Definition: watchdog.c:42