Contiki-Inga 3.x
contiki-main.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/
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  *
14  * 3. Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived
16  * from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29  * OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 /**
32  * \addtogroup platform
33  * @{
34  *
35  * \defgroup cc2538 The cc2538 Development Kit platform
36  *
37  * The cc2538DK is the new platform by Texas Instruments, based on the
38  * cc2530 SoC with an ARM Cortex-M3 core.
39  * @{
40  *
41  * \file
42  * Main module for the cc2538dk platform
43  */
44 /*---------------------------------------------------------------------------*/
45 #include "contiki.h"
46 #include "dev/leds.h"
47 #include "dev/sys-ctrl.h"
48 #include "dev/scb.h"
49 #include "dev/nvic.h"
50 #include "dev/uart.h"
51 #include "dev/watchdog.h"
52 #include "dev/ioc.h"
53 #include "dev/button-sensor.h"
54 #include "dev/serial-line.h"
55 #include "dev/slip.h"
56 #include "dev/cc2538-rf.h"
57 #include "dev/udma.h"
58 #include "usb/usb-serial.h"
59 #include "lib/random.h"
60 #include "net/netstack.h"
61 #include "net/queuebuf.h"
62 #include "net/ip/tcpip.h"
63 #include "net/ip/uip.h"
64 #include "net/mac/frame802154.h"
65 #include "cpu.h"
66 #include "reg.h"
67 #include "ieee-addr.h"
68 #include "lpm.h"
69 
70 #include <stdint.h>
71 #include <string.h>
72 #include <stdio.h>
73 /*---------------------------------------------------------------------------*/
74 #if STARTUP_CONF_VERBOSE
75 #define PRINTF(...) printf(__VA_ARGS__)
76 #else
77 #define PRINTF(...)
78 #endif
79 
80 #if UART_CONF_ENABLE
81 #define PUTS(s) puts(s)
82 #else
83 #define PUTS(s)
84 #endif
85 /*---------------------------------------------------------------------------*/
86 static void
87 fade(unsigned char l)
88 {
89  volatile int i;
90  int k, j;
91  for(k = 0; k < 800; ++k) {
92  j = k > 400 ? 800 - k : k;
93 
94  leds_on(l);
95  for(i = 0; i < j; ++i) {
96  asm("nop");
97  }
98  leds_off(l);
99  for(i = 0; i < 400 - j; ++i) {
100  asm("nop");
101  }
102  }
103 }
104 /*---------------------------------------------------------------------------*/
105 static void
106 set_rime_addr()
107 {
108  ieee_addr_cpy_to(&linkaddr_node_addr.u8[0], LINKADDR_SIZE);
109 
110 #if STARTUP_CONF_VERBOSE
111  {
112  int i;
113  printf("Rime configured with address ");
114  for(i = 0; i < LINKADDR_SIZE - 1; i++) {
115  printf("%02x:", linkaddr_node_addr.u8[i]);
116  }
117  printf("%02x\n", linkaddr_node_addr.u8[i]);
118  }
119 #endif
120 
121 }
122 /*---------------------------------------------------------------------------*/
123 /**
124  * \brief Main routine for the cc2538dk platform
125  */
126 int
127 main(void)
128 {
129  nvic_init();
130  ioc_init();
131  sys_ctrl_init();
132  clock_init();
133  lpm_init();
134  rtimer_init();
135  gpio_init();
136 
137  leds_init();
138  fade(LEDS_YELLOW);
139 
140  process_init();
141 
142  watchdog_init();
144 
145  /*
146  * Character I/O Initialisation.
147  * When the UART receives a character it will call serial_line_input_byte to
148  * notify the core. The same applies for the USB driver.
149  *
150  * If slip-arch is also linked in afterwards (e.g. if we are a border router)
151  * it will overwrite one of the two peripheral input callbacks. Characters
152  * received over the relevant peripheral will be handled by
153  * slip_input_byte instead
154  */
155 #if UART_CONF_ENABLE
156  uart_init();
157  uart_set_input(serial_line_input_byte);
158 #endif
159 
160 #if USB_SERIAL_CONF_ENABLE
161  usb_serial_init();
162  usb_serial_set_input(serial_line_input_byte);
163 #endif
164 
165  serial_line_init();
166 
168  fade(LEDS_GREEN);
169 
170  PUTS(CONTIKI_VERSION_STRING);
171  PUTS(BOARD_STRING);
172 
173  PRINTF(" Net: ");
174  PRINTF("%s\n", NETSTACK_NETWORK.name);
175  PRINTF(" MAC: ");
176  PRINTF("%s\n", NETSTACK_MAC.name);
177  PRINTF(" RDC: ");
178  PRINTF("%s\n", NETSTACK_RDC.name);
179 
180  /* Initialise the H/W RNG engine. */
181  random_init(0);
182 
183  udma_init();
184 
185  process_start(&etimer_process, NULL);
186  ctimer_init();
187 
188  set_rime_addr();
189  netstack_init();
190  cc2538_rf_set_addr(IEEE802154_PANID);
191 
192 #if UIP_CONF_IPV6
193  memcpy(&uip_lladdr.addr, &linkaddr_node_addr, sizeof(uip_lladdr.addr));
194  queuebuf_init();
195  process_start(&tcpip_process, NULL);
196 #endif /* UIP_CONF_IPV6 */
197 
198  process_start(&sensors_process, NULL);
199 
200  energest_init();
201  ENERGEST_ON(ENERGEST_TYPE_CPU);
202 
203  autostart_start(autostart_processes);
204 
205  watchdog_start();
206  fade(LEDS_ORANGE);
207 
208  while(1) {
209  uint8_t r;
210  do {
211  /* Reset watchdog and handle polls and events */
213 
214  r = process_run();
215  } while(r > 0);
216 
217  /* We have serviced all pending events. Enter a Low-Power mode. */
218  lpm_enter();
219  }
220 }
221 /*---------------------------------------------------------------------------*/
222 
223 /**
224  * @}
225  * @}
226  */