Contiki-NG
platform.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, SensorTags 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 TI CC2650 SensorTag
41  * - The TI CC1350 SensorTag
42  * - The TI CC2650 LaunchPad
43  * - The TI CC1310 LaunchPad
44  * - The TI CC1350 LaunchPad
45  * @{
46  */
47 #include "ti-lib.h"
48 #include "contiki.h"
49 #include "contiki-net.h"
50 #include "lpm.h"
51 #include "dev/leds.h"
52 #include "dev/gpio-hal.h"
53 #include "dev/oscillators.h"
54 #include "ieee-addr.h"
55 #include "ble-addr.h"
56 #include "vims.h"
57 #include "dev/cc26xx-uart.h"
58 #include "dev/soc-rtc.h"
59 #include "dev/serial-line.h"
60 #include "rf-core/rf-core.h"
61 #include "sys_ctrl.h"
62 #include "uart.h"
63 #include "sys/clock.h"
64 #include "sys/rtimer.h"
65 #include "sys/node-id.h"
66 #include "sys/platform.h"
67 #include "lib/random.h"
68 #include "lib/sensors.h"
69 #include "button-sensor.h"
70 #include "dev/serial-line.h"
71 #include "dev/button-hal.h"
73 #include "board-peripherals.h"
74 
75 #include "driverlib/driverlib_release.h"
76 
77 #include <stdio.h>
78 /*---------------------------------------------------------------------------*/
79 /* Log configuration */
80 #include "sys/log.h"
81 #define LOG_MODULE "CC26xx/CC13xx"
82 #define LOG_LEVEL LOG_LEVEL_MAIN
83 /*---------------------------------------------------------------------------*/
84 /** \brief Board specific iniatialisation */
85 void board_init(void);
86 /*---------------------------------------------------------------------------*/
87 #ifdef BOARD_CONF_HAS_SENSORS
88 #define BOARD_HAS_SENSORS BOARD_CONF_HAS_SENSORS
89 #else
90 #define BOARD_HAS_SENSORS 1
91 #endif
92 /*---------------------------------------------------------------------------*/
93 static void
94 fade(leds_mask_t l)
95 {
96  volatile int i;
97  int k, j;
98  for(k = 0; k < 800; ++k) {
99  j = k > 400 ? 800 - k : k;
100 
101  leds_on(l);
102  for(i = 0; i < j; ++i) {
103  __asm("nop");
104  }
105  leds_off(l);
106  for(i = 0; i < 400 - j; ++i) {
107  __asm("nop");
108  }
109  }
110 }
111 /*---------------------------------------------------------------------------*/
112 static void
113 set_rf_params(void)
114 {
115  uint8_t ext_addr[8];
116 
117 #if MAC_CONF_WITH_BLE
118  ble_eui64_addr_cpy_to((uint8_t *)&ext_addr);
119  NETSTACK_RADIO.set_object(RADIO_PARAM_64BIT_ADDR, ext_addr, 8);
120 #else
121  uint16_t short_addr;
122  ieee_addr_cpy_to(ext_addr, 8);
123 
124  short_addr = ext_addr[7];
125  short_addr |= ext_addr[6] << 8;
126 
127  NETSTACK_RADIO.set_value(RADIO_PARAM_PAN_ID, IEEE802154_PANID);
128  NETSTACK_RADIO.set_value(RADIO_PARAM_16BIT_ADDR, short_addr);
129  NETSTACK_RADIO.set_value(RADIO_PARAM_CHANNEL, IEEE802154_DEFAULT_CHANNEL);
130  NETSTACK_RADIO.set_object(RADIO_PARAM_64BIT_ADDR, ext_addr, 8);
131 #endif
132 }
133 /*---------------------------------------------------------------------------*/
134 void
136 {
137  /* Enable flash cache and prefetch. */
138  ti_lib_vims_mode_set(VIMS_BASE, VIMS_MODE_ENABLED);
139  ti_lib_vims_configure(VIMS_BASE, true, true);
140 
141  ti_lib_int_master_disable();
142 
143  /* Set the LF XOSC as the LF system clock source */
145 
146  lpm_init();
147 
148  board_init();
149 
150  gpio_hal_init();
151 
152  leds_init();
153  fade(LEDS_RED);
154 
155  /*
156  * Disable I/O pad sleep mode and open I/O latches in the AON IOC interface
157  * This is only relevant when returning from shutdown (which is what froze
158  * latches in the first place. Before doing these things though, we should
159  * allow software to first regain control of pins
160  */
161  ti_lib_aon_ioc_freeze_disable();
162  HWREG(AON_SYSCTL_BASE + AON_SYSCTL_O_SLEEPCTL) = 1;
163  ti_lib_sys_ctrl_aon_sync();
164 
165  ti_lib_int_enable(INT_AON_GPIO_EDGE);
166  ti_lib_int_master_enable();
167 
168  soc_rtc_init();
169  fade(LEDS_YELLOW);
170 }
171 /*---------------------------------------------------------------------------*/
172 void
174 {
175  random_init(0x1234);
176 
177  /* Character I/O Initialisation */
178 #if CC26XX_UART_CONF_ENABLE
180 #endif
181 
182  serial_line_init();
183 
184 #if BUILD_WITH_SHELL
186 #endif
187 
188  /* Populate linkaddr_node_addr */
189 #if MAC_CONF_WITH_BLE
190  uint8_t ext_addr[8];
191  ble_eui64_addr_cpy_to((uint8_t *)&ext_addr);
192  memcpy(&linkaddr_node_addr, &ext_addr[8 - LINKADDR_SIZE], LINKADDR_SIZE);
193 #else
194  ieee_addr_cpy_to(linkaddr_node_addr.u8, LINKADDR_SIZE);
195 #endif
196 
197  button_hal_init();
198 
199  fade(LEDS_GREEN);
200 }
201 /*---------------------------------------------------------------------------*/
202 void
204 {
205  radio_value_t chan = 0;
206  radio_value_t pan = 0;
207 
208  set_rf_params();
209 
210  NETSTACK_RADIO.get_value(RADIO_PARAM_CHANNEL, &chan);
211 
212  LOG_DBG("With DriverLib v%u.%u\n", DRIVERLIB_RELEASE_GROUP,
213  DRIVERLIB_RELEASE_BUILD);
214  LOG_INFO(BOARD_STRING "\n");
215  LOG_DBG("IEEE 802.15.4: %s, Sub-GHz: %s, BLE: %s, Prop: %s\n",
216  ti_lib_chipinfo_supports_ieee_802_15_4() == true ? "Yes" : "No",
217  ti_lib_chipinfo_chip_family_is_cc13xx() == true ? "Yes" : "No",
218  ti_lib_chipinfo_supports_ble() == true ? "Yes" : "No",
219  ti_lib_chipinfo_supports_proprietary() == true ? "Yes" : "No");
220  LOG_INFO(" RF: Channel %d", chan);
221 
222  if(NETSTACK_RADIO.get_value(RADIO_PARAM_PAN_ID, &pan) == RADIO_RESULT_OK) {
223  LOG_INFO_(", PANID 0x%04X", pan);
224  }
225  LOG_INFO_("\n");
226 
227 #if BOARD_HAS_SENSORS
228  process_start(&sensors_process, NULL);
229 #endif
230 
231  fade(LEDS_ORANGE);
232 }
233 /*---------------------------------------------------------------------------*/
234 void
236 {
237  /* Drop to some low power mode */
238  lpm_drop();
239 }
240 /*---------------------------------------------------------------------------*/
241 /**
242  * @}
243  * @}
244  */
Header file for the cc2538 UART driver.
Header file with macros which rename TI CC26xxware functions.
void platform_init_stage_two()
Stage 2 of platform driver initialisation.
Definition: platform.c:123
void platform_idle()
The platform&#39;s idle/sleep function.
Definition: platform.c:185
void ble_eui64_addr_cpy_to(uint8_t *dst)
Copy the node&#39;s EUI64 address that is based on its factory BLE address to a destination memory area...
Definition: ble-addr.c:67
void leds_init(void)
Initialise the LED HAL.
Definition: minileds.c:44
void oscillators_select_lf_xosc(void)
Set the LF clock source to be the LF XOSC.
Definition: oscillators.c:45
Node-id (simple 16-bit identifiers) handling.
Header file for the Contiki-NG main routine.
Header file for the CC13xx/CC26xx RF core driver.
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
void leds_on(unsigned char leds)
Turn on multiple LEDs.
Definition: minileds.c:63
void leds_off(unsigned char leds)
Turn off multiple LEDs.
Definition: minileds.c:69
void gpio_hal_init()
Initialise the GPIO HAL.
Definition: gpio-hal.c:95
linkaddr_t linkaddr_node_addr
The link-layer address of the node.
Definition: linkaddr.c:48
void ieee_addr_cpy_to(uint8_t *dst, uint8_t len)
Copy the node&#39;s IEEE address to a destination memory area.
Definition: ieee-addr.c:46
#define IEEE802154_DEFAULT_CHANNEL
The default channel for IEEE 802.15.4 networks.
Definition: mac.h:52
Header file for the CC13xx/CC26xx oscillator control.
void lpm_drop()
Drop the cortex to sleep / deep sleep and shut down peripherals.
Definition: lpm.c:525
int serial_line_input_byte(unsigned char c)
Get one byte of input from the serial driver.
Definition: serial-line.c:64
void board_init(void)
Board specific iniatialisation.
Definition: board.c:51
void cc26xx_uart_init()
Initialises the UART controller, configures I/O control and interrupts.
Definition: cc26xx-uart.c:268
void soc_rtc_init(void)
Initialise the CC13XX/CC26XX AON RTC module.
Definition: soc-rtc.c:71
Header file for the real-time timer module.
void cc26xx_uart_set_input(int(*input)(unsigned char c))
Assigns a callback to be called when the UART receives a byte.
Definition: cc26xx-uart.c:313
802.15.4 frame creation and parsing functions
void platform_init_stage_three()
Final stage of platform driver initialisation.
Definition: platform.c:169
Header file for the CC13xx/CC26xx UART driver.
void random_init(unsigned short seed)
Seed the cc2538 random number generator.
Definition: random.c:84
Generic serial I/O process header filer.
void lpm_init()
Initialise the low-power mode management module.
Definition: lpm.c:557
Header file for the GPIO HAL.
void button_hal_init()
Initialise the button HAL.
Definition: button-hal.c:178
Header file for the logging system
Header file for the CC13xx/CC26xx AON RTC driver.
Header file for the LED HAL.
void platform_init_stage_one(void)
Basic (Stage 1) platform driver initialisation.
Definition: platform.c:114
Header file for the button HAL.
uint8_t leds_mask_t
An OR mask datatype to represents multiple LEDs.
Definition: leds.h:164
void process_start(struct process *p, process_data_t data)
Start a process.
Definition: process.c:99