Contiki 3.x
contiki-main.c
1 /*
2  * Copyright (c) 2014, 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  * 3. Neither the name of the copyright holder nor the names of its
14  * contributors may be used to endorse or promote products derived
15  * from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28  * OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 /*---------------------------------------------------------------------------*/
31 /**
32  * \addtogroup cc26xx-platforms
33  * @{
34  *
35  * \defgroup cc26xx-srf-tag SmartRF+CC13xx/CC26xx EM, CC2650 SensorTag and LaunchPads
36  *
37  * This platform supports a number of different boards:
38  * - A standard TI SmartRF06EB with a CC26xx EM mounted on it
39  * - A standard TI SmartRF06EB with a CC1310 EM mounted on it
40  * - The new TI SensorTag2.0
41  * - The TI CC2650 LaunchPad
42  * - The TI CC1310 LaunchPad
43  * @{
44  */
45 #include "ti-lib.h"
46 #include "contiki.h"
47 #include "contiki-net.h"
48 #include "leds.h"
49 #include "lpm.h"
50 #include "gpio-interrupt.h"
51 #include "dev/watchdog.h"
52 #include "dev/oscillators.h"
53 #include "ieee-addr.h"
54 #include "vims.h"
55 #include "dev/cc26xx-uart.h"
56 #include "dev/soc-rtc.h"
57 #include "rf-core/rf-core.h"
58 #include "sys_ctrl.h"
59 #include "uart.h"
60 #include "sys/clock.h"
61 #include "sys/rtimer.h"
62 #include "lib/sensors.h"
63 #include "button-sensor.h"
64 #include "dev/serial-line.h"
65 #include "net/mac/frame802154.h"
66 
67 #include "driverlib/driverlib_release.h"
68 
69 #include <stdio.h>
70 /*---------------------------------------------------------------------------*/
71 /** \brief Board specific iniatialisation */
72 void board_init(void);
73 /*---------------------------------------------------------------------------*/
74 static void
75 fade(unsigned char l)
76 {
77  volatile int i;
78  int k, j;
79  for(k = 0; k < 800; ++k) {
80  j = k > 400 ? 800 - k : k;
81 
82  leds_on(l);
83  for(i = 0; i < j; ++i) {
84  __asm("nop");
85  }
86  leds_off(l);
87  for(i = 0; i < 400 - j; ++i) {
88  __asm("nop");
89  }
90  }
91 }
92 /*---------------------------------------------------------------------------*/
93 static void
94 set_rf_params(void)
95 {
96  uint16_t short_addr;
97  uint8_t ext_addr[8];
98  radio_value_t val = 0;
99 
100  ieee_addr_cpy_to(ext_addr, 8);
101 
102  short_addr = ext_addr[7];
103  short_addr |= ext_addr[6] << 8;
104 
105  /* Populate linkaddr_node_addr. Maintain endianness */
106  memcpy(&linkaddr_node_addr, &ext_addr[8 - LINKADDR_SIZE], LINKADDR_SIZE);
107 
108  NETSTACK_RADIO.set_value(RADIO_PARAM_PAN_ID, IEEE802154_PANID);
109  NETSTACK_RADIO.set_value(RADIO_PARAM_16BIT_ADDR, short_addr);
110  NETSTACK_RADIO.set_value(RADIO_PARAM_CHANNEL, RF_CORE_CHANNEL);
111  NETSTACK_RADIO.set_object(RADIO_PARAM_64BIT_ADDR, ext_addr, 8);
112 
113  NETSTACK_RADIO.get_value(RADIO_PARAM_CHANNEL, &val);
114  printf(" RF: Channel %d\n", val);
115 
116 #if STARTUP_CONF_VERBOSE
117  {
118  int i;
119  printf(" Link layer addr: ");
120  for(i = 0; i < LINKADDR_SIZE - 1; i++) {
121  printf("%02x:", linkaddr_node_addr.u8[i]);
122  }
123  printf("%02x\n", linkaddr_node_addr.u8[i]);
124  }
125 #endif
126 }
127 /*---------------------------------------------------------------------------*/
128 /**
129  * \brief Main function for CC26xx-based platforms
130  *
131  * The same main() is used for all supported boards
132  */
133 int
134 main(void)
135 {
136  /* Enable flash cache and prefetch. */
137  ti_lib_vims_mode_set(VIMS_BASE, VIMS_MODE_ENABLED);
138  ti_lib_vims_configure(VIMS_BASE, true, true);
139 
140  ti_lib_int_master_disable();
141 
142  /* Set the LF XOSC as the LF system clock source */
144 
145  lpm_init();
146 
147  board_init();
148 
150 
151  leds_init();
152 
153  /*
154  * Disable I/O pad sleep mode and open I/O latches in the AON IOC interface
155  * This is only relevant when returning from shutdown (which is what froze
156  * latches in the first place. Before doing these things though, we should
157  * allow software to first regain control of pins
158  */
159  ti_lib_pwr_ctrl_io_freeze_disable();
160 
161  fade(LEDS_RED);
162 
163  ti_lib_int_master_enable();
164 
165  soc_rtc_init();
166  clock_init();
167  rtimer_init();
168 
169  watchdog_init();
170  process_init();
171 
172  random_init(0x1234);
173 
174  /* Character I/O Initialisation */
175 #if CC26XX_UART_CONF_ENABLE
177 #endif
178 
179  serial_line_init();
180 
181  printf("Starting " CONTIKI_VERSION_STRING "\n");
182  printf("With DriverLib v%u.%u\n", DRIVERLIB_RELEASE_GROUP,
183  DRIVERLIB_RELEASE_BUILD);
184  printf(BOARD_STRING "\n");
185 
186  process_start(&etimer_process, NULL);
187  ctimer_init();
188 
189  energest_init();
190  ENERGEST_ON(ENERGEST_TYPE_CPU);
191 
192  fade(LEDS_YELLOW);
193 
194  printf(" Net: ");
195  printf("%s\n", NETSTACK_NETWORK.name);
196  printf(" MAC: ");
197  printf("%s\n", NETSTACK_MAC.name);
198  printf(" RDC: ");
199  printf("%s", NETSTACK_RDC.name);
200 
201  if(NETSTACK_RDC.channel_check_interval() != 0) {
202  printf(", Channel Check Interval: %u ticks",
203  NETSTACK_RDC.channel_check_interval());
204  }
205  printf("\n");
206 
207  netstack_init();
208 
209  set_rf_params();
210 
211 #if NETSTACK_CONF_WITH_IPV6
212  memcpy(&uip_lladdr.addr, &linkaddr_node_addr, sizeof(uip_lladdr.addr));
213  queuebuf_init();
214  process_start(&tcpip_process, NULL);
215 #endif /* NETSTACK_CONF_WITH_IPV6 */
216 
217  fade(LEDS_GREEN);
218 
219  process_start(&sensors_process, NULL);
220 
221  autostart_start(autostart_processes);
222 
223  watchdog_start();
224 
225  fade(LEDS_ORANGE);
226 
227  while(1) {
228  uint8_t r;
229  do {
230  r = process_run();
232  } while(r > 0);
233 
234  /* Drop to some low power mode */
235  lpm_drop();
236  }
237 }
238 /*---------------------------------------------------------------------------*/
239 /**
240  * @}
241  * @}
242  */
void cc26xx_uart_init()
Initialises the UART controller, configures I/O control and interrupts.
Definition: cc26xx-uart.c:269
Header file for the real-time timer module.
#define LEDS_ORANGE
LED4 (Orange) -> PC3.
Definition: board.h:83
Header file with macros which rename TI CC26xxware functions.
void ieee_addr_cpy_to(uint8_t *dst, uint8_t len)
Copy the node's IEEE address to a destination memory area.
Definition: ieee-addr.c:45
void lpm_drop()
Drop the cortex to sleep / deep sleep and shut down peripherals.
Definition: lpm.c:459
void lpm_init()
Initialise the low-power mode management module.
Definition: lpm.c:510
void random_init(unsigned short seed)
Seed the cc2538 random number generator.
Definition: random.c:41
Header file for the CC13xx/CC26xx AON RTC driver.
void clock_init(void)
Initialize the clock library.
Definition: clock.c:76
void soc_rtc_init(void)
Initialise the CC13XX/CC26XX AON RTC module.
Definition: soc-rtc.c:72
Header file for the CC13xx/CC26xx GPIO interrupt management.
void oscillators_select_lf_xosc(void)
Set the LF clock source to be the LF XOSC.
Definition: oscillators.c:45
Header file for the CC13xx/CC26xx RF core driver.
int process_run(void)
Run the system once - call poll handlers and process one event.
Definition: process.c:302
#define NULL
The null pointer.
int radio_value_t
Each radio has a set of parameters that designate the current configuration and state of the radio...
Definition: radio.h:88
802.15.4 frame creation and parsing functions
void board_init(void)
Board specific iniatialisation.
Definition: board.c:54
void watchdog_periodic(void)
Writes the WDT clear sequence.
Definition: watchdog.c:64
void process_start(struct process *p, process_data_t data)
Start a process.
Definition: process.c:99
int main(void)
This is main...
Definition: contiki-main.c:456
void gpio_interrupt_init()
Initialise the GPIO interrupt handling module.
void rtimer_init(void)
Initialize the real-time scheduler.
Definition: rtimer.c:61
void watchdog_init(void)
Copyright (c) 2014, Analog Devices, Inc.
Definition: watchdog.c:42
Generic serial I/O process header filer.
CCIF uip_lladdr_t uip_lladdr
Host L2 address.
Definition: uip.c:118
Header file for the CC13xx/CC26xx UART driver.
void process_init(void)
Initialize the process module.
Definition: process.c:208
void ctimer_init(void)
Initialize the callback timer library.
Definition: ctimer.c:91
linkaddr_t linkaddr_node_addr
The Rime address of the node.
Definition: linkaddr.c:48
Header file for the CC13xx/CC26xx oscillator control.
void watchdog_start(void)
Starts the WDT in watchdog mode if enabled by user configuration, maximum interval.
Definition: watchdog.c:49