Contiki-NG
platform.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010, Swedish Institute of Computer Science.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the Institute nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 */
30
31/**
32 * \file
33 * COOJA Contiki mote main file.
34 * \author
35 * Fredrik Osterlind <fros@sics.se>
36 */
37
38#include <stdint.h>
39#include <stdio.h>
40#include <string.h>
41
42#include "contiki.h"
43#include "sys/cc.h"
44#include "sys/cooja_mt.h"
45/*---------------------------------------------------------------------------*/
46/* Log configuration */
47#include "sys/log.h"
48#define LOG_MODULE "Cooja"
49#define LOG_LEVEL LOG_LEVEL_MAIN
50
51#include "lib/random.h"
52#include "lib/simEnvChange.h"
53
54#include "net/netstack.h"
55#include "net/queuebuf.h"
56
57#include "dev/eeprom.h"
58#include "dev/serial-line.h"
59#include "dev/cooja-radio.h"
60#include "dev/button-sensor.h"
61#include "dev/pir-sensor.h"
62#include "dev/vib-sensor.h"
63#include "dev/moteid.h"
64#include "dev/button-hal.h"
65#include "dev/gpio-hal.h"
66
67#include "sys/node-id.h"
68#include "services/rpl-border-router/rpl-border-router.h"
69#if BUILD_WITH_ORCHESTRA
70#include "orchestra.h"
71#endif /* BUILD_WITH_ORCHESTRA */
72#if BUILD_WITH_SHELL
73#include "serial-shell.h"
74#endif /* BUILD_WITH_SHELL */
75
76#if NETSTACK_CONF_WITH_IPV6
77#include "net/ipv6/uip.h"
78#include "net/ipv6/uip-ds6.h"
79#endif /* NETSTACK_CONF_WITH_IPV6 */
80
81/* Simulation mote interfaces */
82SIM_INTERFACE_NAME(moteid_interface);
83SIM_INTERFACE_NAME(vib_interface);
84SIM_INTERFACE_NAME(rs232_interface);
85SIM_INTERFACE_NAME(simlog_interface);
86SIM_INTERFACE_NAME(beep_interface);
87SIM_INTERFACE_NAME(radio_interface);
88SIM_INTERFACE_NAME(button_interface);
89SIM_INTERFACE_NAME(pir_interface);
90SIM_INTERFACE_NAME(clock_interface);
91SIM_INTERFACE_NAME(leds_interface);
92SIM_INTERFACE_NAME(cfs_interface);
93SIM_INTERFACE_NAME(eeprom_interface);
94SIM_INTERFACES(&vib_interface, &moteid_interface, &rs232_interface, &simlog_interface, &beep_interface, &radio_interface, &button_interface, &pir_interface, &clock_interface, &leds_interface, &cfs_interface, &eeprom_interface);
95
96/* Sensors */
97SENSORS(&button_sensor, &pir_sensor, &vib_sensor);
98
99/*---------------------------------------------------------------------------*/
100/* Needed since the new LEDs API does not provide this prototype */
101void leds_arch_init(void);
102/*---------------------------------------------------------------------------*/
103static void
104set_lladdr(void)
105{
106 linkaddr_t addr;
107
108 memset(&addr, 0, sizeof(linkaddr_t));
109#if NETSTACK_CONF_WITH_IPV6
110 for(size_t i = 0; i < sizeof(uip_lladdr.addr); i += 2) {
111 addr.u8[i + 1] = simMoteID & 0xff;
112 addr.u8[i + 0] = simMoteID >> 8;
113 }
114#else /* NETSTACK_CONF_WITH_IPV6 */
115 addr.u8[0] = simMoteID & 0xff;
116 addr.u8[1] = simMoteID >> 8;
117#endif /* NETSTACK_CONF_WITH_IPV6 */
119}
120/*---------------------------------------------------------------------------*/
121void
123{
125 leds_arch_init();
126 return;
127}
128/*---------------------------------------------------------------------------*/
129void
131{
132 set_lladdr();
134}
135/*---------------------------------------------------------------------------*/
136void
138{
139 /* Initialize eeprom */
140 eeprom_init();
141 /* Start serial process */
142 serial_line_init();
143}
144/*---------------------------------------------------------------------------*/
145void
147{
148 while(1) {
149 simProcessRunValue = process_run();
150 while(simProcessRunValue-- > 0) {
151 process_run();
152 }
153 simProcessRunValue = process_nevents();
154
155 /* Check if we must stay awake */
156 if(simDontFallAsleep) {
157 simDontFallAsleep = 0;
158 simProcessRunValue = 1;
159 }
160
161 /* Return to COOJA */
162 cooja_mt_yield();
163 }
164}
165/*---------------------------------------------------------------------------*/
Header file for the button HAL.
Default definitions of C compiler quirk work-arounds.
EEPROM functions.
Header file for the GPIO HAL.
void button_hal_init()
Initialise the button HAL.
Definition: button-hal.c:213
void platform_init_stage_three()
Final stage of platform driver initialisation.
Definition: platform.c:169
void platform_init_stage_one(void)
Basic (Stage 1) platform driver initialisation.
Definition: platform.c:114
void platform_init_stage_two()
Stage 2 of platform driver initialisation.
Definition: platform.c:123
bool eeprom_init(void)
Initialize the EEPROM module.
Definition: eeprom.c:79
void gpio_hal_init()
Initialise the GPIO HAL.
Definition: gpio-hal.c:95
void linkaddr_set_node_addr(linkaddr_t *t)
Set the address of the current node.
Definition: linkaddr.c:75
void platform_main_loop()
The platform's main loop, if provided.
Definition: platform.c:146
int process_run(void)
Run the system once - call poll handlers and process one event.
Definition: process.c:302
int process_nevents(void)
Number of events waiting to be processed.
Definition: process.c:316
uip_lladdr_t uip_lladdr
Host L2 address.
Definition: uip6.c:107
Header file for the logging system.
Include file for the Contiki low-layer network stack (NETSTACK)
Node-id (simple 16-bit identifiers) handling.
Orchestra header file.
Header file for the Packet queue buffer management.
Generic serial I/O process header filer.
A shell back-end for the serial port.
Header file for IPv6-related data structures.
static uip_ds6_addr_t * addr
Pointer to a nbr cache entry.
Definition: uip-nd6.c:107
Header file for the uIP TCP/IP stack.
SENSORS & button_sensor
Exports global symbols for the sensor API.
Definition: z1-sensors.c:46