Contiki-NG
Loading...
Searching...
No Matches
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/button-sensor.h"
60#include "dev/pir-sensor.h"
61#include "dev/vib-sensor.h"
62#include "dev/moteid.h"
63#include "dev/button-hal.h"
64#include "dev/gpio-hal.h"
65
66#if NETSTACK_CONF_WITH_IPV6
67#include "net/ipv6/uip.h"
68#include "net/ipv6/uip-ds6.h"
69#endif /* NETSTACK_CONF_WITH_IPV6 */
70
71/* Sensors */
72SENSORS(&pir_sensor, &vib_sensor);
73
74/*---------------------------------------------------------------------------*/
75/* Needed since the new LEDs API does not provide this prototype */
76void leds_arch_init(void);
77/*---------------------------------------------------------------------------*/
78char simDontFallAsleep = 0;
79
80int simProcessRunValue;
81int simEtimerPending;
82clock_time_t simEtimerNextExpirationTime;
83/*---------------------------------------------------------------------------*/
84static void
85set_lladdr(void)
86{
87 linkaddr_t addr;
88
89 memset(&addr, 0, sizeof(linkaddr_t));
90#if NETSTACK_CONF_WITH_IPV6
91 for(size_t i = 0; i < sizeof(uip_lladdr.addr); i += 2) {
92 addr.u8[i + 1] = simMoteID & 0xff;
93 addr.u8[i + 0] = simMoteID >> 8;
94 }
95#else /* NETSTACK_CONF_WITH_IPV6 */
96 addr.u8[0] = simMoteID & 0xff;
97 addr.u8[1] = simMoteID >> 8;
98#endif /* NETSTACK_CONF_WITH_IPV6 */
100}
101/*---------------------------------------------------------------------------*/
102void
104{
106 leds_arch_init();
107}
108/*---------------------------------------------------------------------------*/
109void
111{
112 set_lladdr();
114}
115/*---------------------------------------------------------------------------*/
116void
118{
119 /* Start serial process */
120 serial_line_init();
121}
122/*---------------------------------------------------------------------------*/
123void
125{
126 while(1) {
127 simProcessRunValue = process_run();
128 while(simProcessRunValue-- > 0) {
129 process_run();
130 }
131 simProcessRunValue = process_nevents();
132
133 /* Check if we must stay awake */
134 if(simDontFallAsleep) {
135 simDontFallAsleep = 0;
136 simProcessRunValue = 1;
137 }
138
139 /* Return to COOJA */
140 cooja_mt_yield();
141 }
142}
143/*---------------------------------------------------------------------------*/
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
void gpio_hal_init()
Initialise the GPIO HAL.
Definition gpio-hal.c:95
static void linkaddr_set_node_addr(linkaddr_t *addr)
Set the address of the current node.
Definition linkaddr.h:124
void platform_main_loop()
The platform's main loop, if provided.
Definition platform.c:124
process_num_events_t process_run(void)
Run the system once - call poll handlers and process one event.
Definition process.c:305
process_num_events_t process_nevents(void)
Number of events waiting to be processed.
Definition process.c:319
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)
Header file for the Packet queue buffer management.
Generic serial I/O process header filer.
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.