Contiki 3.x
contiki-rcb-main.c
1 /*
2  * Copyright (c) 2006, Technical University of Munich
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  * This file is part of the Contiki operating system.
30  *
31  * @(#)$$
32  */
33 
34 #include <avr/pgmspace.h>
35 #include <avr/fuse.h>
36 #include <avr/eeprom.h>
37 #include <stdio.h>
38 
39 #include "lib/mmem.h"
40 #include "loader/symbols-def.h"
41 #include "loader/symtab.h"
42 
43 #if RF230BB //radio driver using contiki core mac
44 #include "radio/rf230bb/rf230bb.h"
45 #include "net/mac/frame802154.h"
46 #include "net/mac/framer-802154.h"
47 #include "net/ipv6/sicslowpan.h"
48 #else //radio driver using Atmel/Cisco 802.15.4'ish MAC
49 #include <stdbool.h>
50 #include "mac.h"
51 #include "sicslowmac.h"
52 #include "sicslowpan.h"
53 #include "ieee-15-4-manager.h"
54 #endif /*RF230BB*/
55 
56 #include "contiki.h"
57 #include "contiki-net.h"
58 #include "contiki-lib.h"
59 
60 #include "dev/rs232.h"
61 #include "dev/serial-line.h"
62 #include "dev/slip.h"
63 
64 
65 #include "sicslowmac.h"
66 
67 FUSES =
68  {
69  .low = 0xe2,
70  .high = 0x99,
71  .extended = 0xff,
72  };
73 
74 PROCESS(rcb_leds, "RCB leds process");
75 
76 #if RF230BB
77 PROCINIT(&etimer_process, &tcpip_process, &rcb_leds);
78 #else
79 PROCINIT(&etimer_process, &mac_process, &tcpip_process, &rcb_leds);
80 #endif
81 
82 /* Put default MAC address in EEPROM */
83 uint8_t mac_address[8] EEMEM = {0x02, 0x11, 0x22, 0xff, 0xfe, 0x33, 0x44, 0x55};
84 
85 #define LED1 (1<<PE2)
86 #define LED2 (1<<PE3)
87 #define LED3 (1<<PE4)
88 
89 #define LEDOff(x) (PORTE |= (x))
90 #define LEDOn(x) (PORTE &= ~(x))
91 
92 
93 void
94 init_lowlevel(void)
95 {
96  /* Second rs232 port for debugging */
97  rs232_init(RS232_PORT_1, USART_BAUD_57600,
98  USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
99 
100  /* Redirect stdout to second port */
101  rs232_redirect_stdout(RS232_PORT_1);
102 
103  DDRE |= LED1 | LED2 | LED3;
104 }
105 
106 
107 static struct etimer et;
108 PROCESS_THREAD(rcb_leds, ev, data)
109 {
110  uint8_t error;
111 
112  PROCESS_BEGIN();
113 
114  if((error = icmp6_new(NULL)) == 0) {
115  while(1) {
116  PROCESS_YIELD();
117 
118 #if UIP_CONF_IPV6
119  if (ev == ICMP6_ECHO_REQUEST) {
120 #else
121  if (1) {
122 #endif
123  LEDOn(LED2);
124  etimer_set(&et, CLOCK_SECOND/10);
125  } else {
126  LEDOff(LED2);
127  }
128  }
129  }
130  PROCESS_END();
131 }
132 
133 
134 int
135 main(void)
136 {
137  //calibrate_rc_osc_32k(); //CO: Had to comment this out
138 
139  /* Initialize hardware */
140  init_lowlevel();
141 
142  /* Clock */
143  clock_init();
144 
145  LEDOff(LED1 | LED2);
146 
147  /* Process subsystem */
148  process_init();
149 
150  /* Register initial processes */
151  procinit_init();
152 
153  /* Autostart processes */
154  autostart_start(autostart_processes);
155 
156  printf_P(PSTR("\n********BOOTING CONTIKI*********\n"));
157 
158  printf_P(PSTR("System online.\n"));
159 
160  /* Main scheduler loop */
161  while(1) {
162  process_run();
163  }
164 
165  return 0;
166 }
void rs232_init(void)
Initialize the RS232 module.
Definition: rs232.c:50
A MAC framer for IEEE 802.15.4
802.15.4 frame creation and parsing functions
#define PROCESS_BEGIN()
Define the beginning of a process.
Definition: process.h:120
Header file for the managed memory allocator
Example glue code between the existing MAC code and the Contiki mac interface.
#define NULL
The null pointer.
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
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
Definition: process.h:273
#define PROCESS_END()
Define the end of a process.
Definition: process.h:131
Header file for the 6lowpan implementation (RFC4944 and draft-hui-6lowpan-hc-01) ...
Generic serial I/O process header filer.
#define ICMP6_ECHO_REQUEST
Echo request.
Definition: uip-icmp6.h:57
#define PROCESS(name, strname)
Declare a process.
Definition: process.h:307
#define PROCESS_YIELD()
Yield the currently running process.
Definition: process.h:164
void etimer_set(struct etimer *et, clock_time_t interval)
Set an event timer.
Definition: etimer.c:177
int process_run(void)
Run the system once - call poll handlers and process one event.
Definition: process.c:302
A timer.
Definition: etimer.h:76
MAC driver header file
#define CLOCK_SECOND
A second, measured in system clock time.
Definition: clock.h:82