2015-02-25 12:12:20 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014, Texas Instruments Incorporated - http://www.ti.com/
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the copyright holder nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
|
|
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
/**
|
|
|
|
* \addtogroup cc26xx-platforms
|
|
|
|
* @{
|
|
|
|
*
|
2016-11-06 17:18:30 +00:00
|
|
|
* \defgroup cc26xx-srf-tag SmartRF+CC13xx/CC26xx EM, SensorTags and LaunchPads
|
2015-02-25 12:12:20 +00:00
|
|
|
*
|
2015-08-16 15:55:44 +00:00
|
|
|
* This platform supports a number of different boards:
|
|
|
|
* - A standard TI SmartRF06EB with a CC26xx EM mounted on it
|
|
|
|
* - A standard TI SmartRF06EB with a CC1310 EM mounted on it
|
2016-11-06 17:18:30 +00:00
|
|
|
* - The TI CC2650 SensorTag
|
|
|
|
* - The TI CC1350 SensorTag
|
2016-01-24 16:57:08 +00:00
|
|
|
* - The TI CC2650 LaunchPad
|
2016-03-13 13:03:02 +00:00
|
|
|
* - The TI CC1310 LaunchPad
|
2016-11-06 17:18:30 +00:00
|
|
|
* - The TI CC1350 LaunchPad
|
2015-02-25 12:12:20 +00:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
#include "ti-lib.h"
|
|
|
|
#include "contiki.h"
|
|
|
|
#include "contiki-net.h"
|
|
|
|
#include "lpm.h"
|
2018-02-28 23:03:26 +00:00
|
|
|
#include "dev/leds.h"
|
2017-12-16 22:47:44 +00:00
|
|
|
#include "dev/gpio-hal.h"
|
2015-05-01 16:04:44 +00:00
|
|
|
#include "dev/oscillators.h"
|
2015-02-25 12:12:20 +00:00
|
|
|
#include "ieee-addr.h"
|
2017-12-06 15:10:58 +00:00
|
|
|
#include "ble-addr.h"
|
2015-02-25 12:12:20 +00:00
|
|
|
#include "vims.h"
|
|
|
|
#include "dev/cc26xx-uart.h"
|
2015-08-16 15:55:44 +00:00
|
|
|
#include "dev/soc-rtc.h"
|
2018-02-16 15:16:14 +00:00
|
|
|
#include "dev/serial-line.h"
|
2015-08-16 15:55:44 +00:00
|
|
|
#include "rf-core/rf-core.h"
|
2015-02-25 12:12:20 +00:00
|
|
|
#include "sys_ctrl.h"
|
|
|
|
#include "uart.h"
|
|
|
|
#include "sys/clock.h"
|
|
|
|
#include "sys/rtimer.h"
|
2016-04-25 15:00:19 +00:00
|
|
|
#include "sys/node-id.h"
|
2017-10-14 18:07:38 +00:00
|
|
|
#include "sys/platform.h"
|
2016-06-15 09:31:55 +00:00
|
|
|
#include "lib/random.h"
|
2015-02-25 12:12:20 +00:00
|
|
|
#include "lib/sensors.h"
|
|
|
|
#include "button-sensor.h"
|
|
|
|
#include "dev/serial-line.h"
|
2017-12-18 00:25:35 +00:00
|
|
|
#include "dev/button-hal.h"
|
2017-05-16 16:20:34 +00:00
|
|
|
#include "net/mac/framer/frame802154.h"
|
2017-11-05 17:15:29 +00:00
|
|
|
#include "board-peripherals.h"
|
2015-02-25 12:12:20 +00:00
|
|
|
|
2015-04-20 06:52:46 +00:00
|
|
|
#include "driverlib/driverlib_release.h"
|
2015-02-25 12:12:20 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2017-10-17 23:17:37 +00:00
|
|
|
/* Log configuration */
|
|
|
|
#include "sys/log.h"
|
|
|
|
#define LOG_MODULE "CC26xx/CC13xx"
|
|
|
|
#define LOG_LEVEL LOG_LEVEL_MAIN
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2016-04-25 15:00:19 +00:00
|
|
|
unsigned short node_id = 0;
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2015-08-16 15:55:44 +00:00
|
|
|
/** \brief Board specific iniatialisation */
|
|
|
|
void board_init(void);
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2017-11-05 17:15:29 +00:00
|
|
|
#ifdef BOARD_CONF_HAS_SENSORS
|
|
|
|
#define BOARD_HAS_SENSORS BOARD_CONF_HAS_SENSORS
|
|
|
|
#else
|
|
|
|
#define BOARD_HAS_SENSORS 1
|
|
|
|
#endif
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2015-02-25 12:12:20 +00:00
|
|
|
static void
|
2018-02-28 23:03:26 +00:00
|
|
|
fade(leds_mask_t l)
|
2015-02-25 12:12:20 +00:00
|
|
|
{
|
|
|
|
volatile int i;
|
|
|
|
int k, j;
|
|
|
|
for(k = 0; k < 800; ++k) {
|
|
|
|
j = k > 400 ? 800 - k : k;
|
|
|
|
|
|
|
|
leds_on(l);
|
|
|
|
for(i = 0; i < j; ++i) {
|
|
|
|
__asm("nop");
|
|
|
|
}
|
|
|
|
leds_off(l);
|
|
|
|
for(i = 0; i < 400 - j; ++i) {
|
|
|
|
__asm("nop");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
set_rf_params(void)
|
|
|
|
{
|
|
|
|
uint8_t ext_addr[8];
|
|
|
|
|
2018-03-18 13:10:21 +00:00
|
|
|
#if MAC_CONF_WITH_BLE
|
2017-12-06 15:10:58 +00:00
|
|
|
ble_eui64_addr_cpy_to((uint8_t *)&ext_addr);
|
|
|
|
NETSTACK_RADIO.set_object(RADIO_PARAM_64BIT_ADDR, ext_addr, 8);
|
|
|
|
#else
|
|
|
|
uint16_t short_addr;
|
2015-02-25 12:12:20 +00:00
|
|
|
ieee_addr_cpy_to(ext_addr, 8);
|
|
|
|
|
|
|
|
short_addr = ext_addr[7];
|
|
|
|
short_addr |= ext_addr[6] << 8;
|
|
|
|
|
|
|
|
NETSTACK_RADIO.set_value(RADIO_PARAM_PAN_ID, IEEE802154_PANID);
|
|
|
|
NETSTACK_RADIO.set_value(RADIO_PARAM_16BIT_ADDR, short_addr);
|
2018-04-13 09:29:56 +00:00
|
|
|
NETSTACK_RADIO.set_value(RADIO_PARAM_CHANNEL, IEEE802154_DEFAULT_CHANNEL);
|
2015-02-25 12:12:20 +00:00
|
|
|
NETSTACK_RADIO.set_object(RADIO_PARAM_64BIT_ADDR, ext_addr, 8);
|
|
|
|
|
2017-10-14 18:07:38 +00:00
|
|
|
/* also set the global node id */
|
|
|
|
node_id = short_addr;
|
2017-12-06 15:10:58 +00:00
|
|
|
#endif
|
2015-02-25 12:12:20 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2017-10-14 18:07:38 +00:00
|
|
|
void
|
|
|
|
platform_init_stage_one()
|
2015-02-25 12:12:20 +00:00
|
|
|
{
|
2015-05-01 16:04:44 +00:00
|
|
|
/* Enable flash cache and prefetch. */
|
|
|
|
ti_lib_vims_mode_set(VIMS_BASE, VIMS_MODE_ENABLED);
|
|
|
|
ti_lib_vims_configure(VIMS_BASE, true, true);
|
2015-02-25 12:12:20 +00:00
|
|
|
|
2015-05-01 16:04:44 +00:00
|
|
|
ti_lib_int_master_disable();
|
2015-02-25 12:12:20 +00:00
|
|
|
|
2015-05-01 16:04:44 +00:00
|
|
|
/* Set the LF XOSC as the LF system clock source */
|
|
|
|
oscillators_select_lf_xosc();
|
2015-02-25 12:12:20 +00:00
|
|
|
|
|
|
|
lpm_init();
|
|
|
|
|
|
|
|
board_init();
|
|
|
|
|
2017-12-16 22:47:44 +00:00
|
|
|
gpio_hal_init();
|
2015-02-25 12:12:20 +00:00
|
|
|
|
|
|
|
leds_init();
|
2017-10-14 18:07:38 +00:00
|
|
|
fade(LEDS_RED);
|
2015-02-25 12:12:20 +00:00
|
|
|
|
2015-05-01 16:04:44 +00:00
|
|
|
/*
|
|
|
|
* Disable I/O pad sleep mode and open I/O latches in the AON IOC interface
|
|
|
|
* This is only relevant when returning from shutdown (which is what froze
|
|
|
|
* latches in the first place. Before doing these things though, we should
|
|
|
|
* allow software to first regain control of pins
|
|
|
|
*/
|
|
|
|
ti_lib_pwr_ctrl_io_freeze_disable();
|
|
|
|
|
2017-12-16 22:47:44 +00:00
|
|
|
ti_lib_rom_int_enable(INT_AON_GPIO_EDGE);
|
2015-05-01 16:04:44 +00:00
|
|
|
ti_lib_int_master_enable();
|
|
|
|
|
2015-08-16 15:55:44 +00:00
|
|
|
soc_rtc_init();
|
2017-10-14 18:07:38 +00:00
|
|
|
fade(LEDS_YELLOW);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
platform_init_stage_two()
|
|
|
|
{
|
2015-02-25 12:12:20 +00:00
|
|
|
random_init(0x1234);
|
|
|
|
|
|
|
|
/* Character I/O Initialisation */
|
|
|
|
#if CC26XX_UART_CONF_ENABLE
|
|
|
|
cc26xx_uart_init();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
serial_line_init();
|
|
|
|
|
2018-02-16 15:16:14 +00:00
|
|
|
#if BUILD_WITH_SHELL
|
|
|
|
cc26xx_uart_set_input(serial_line_input_byte);
|
|
|
|
#endif
|
|
|
|
|
2017-10-29 16:36:58 +00:00
|
|
|
/* Populate linkaddr_node_addr */
|
2018-03-18 13:10:21 +00:00
|
|
|
#if MAC_CONF_WITH_BLE
|
2018-01-03 13:51:23 +00:00
|
|
|
uint8_t ext_addr[8];
|
|
|
|
ble_eui64_addr_cpy_to((uint8_t *)&ext_addr);
|
|
|
|
memcpy(&linkaddr_node_addr, &ext_addr[8 - LINKADDR_SIZE], LINKADDR_SIZE);
|
|
|
|
#else
|
2017-10-29 16:36:58 +00:00
|
|
|
ieee_addr_cpy_to(linkaddr_node_addr.u8, LINKADDR_SIZE);
|
2018-01-03 13:51:23 +00:00
|
|
|
#endif
|
2017-12-18 00:25:35 +00:00
|
|
|
|
|
|
|
button_hal_init();
|
|
|
|
|
2017-10-14 18:07:38 +00:00
|
|
|
fade(LEDS_GREEN);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
platform_init_stage_three()
|
|
|
|
{
|
2018-03-11 14:36:40 +00:00
|
|
|
radio_value_t chan = 0;
|
|
|
|
radio_value_t pan = 0;
|
2017-10-29 16:36:58 +00:00
|
|
|
|
|
|
|
set_rf_params();
|
|
|
|
|
|
|
|
NETSTACK_RADIO.get_value(RADIO_PARAM_CHANNEL, &chan);
|
|
|
|
|
2017-10-17 23:17:37 +00:00
|
|
|
LOG_DBG("With DriverLib v%u.%u\n", DRIVERLIB_RELEASE_GROUP,
|
|
|
|
DRIVERLIB_RELEASE_BUILD);
|
|
|
|
LOG_INFO(BOARD_STRING "\n");
|
|
|
|
LOG_DBG("IEEE 802.15.4: %s, Sub-GHz: %s, BLE: %s, Prop: %s\n",
|
|
|
|
ti_lib_chipinfo_supports_ieee_802_15_4() == true ? "Yes" : "No",
|
|
|
|
ti_lib_chipinfo_chip_family_is_cc13xx() == true ? "Yes" : "No",
|
|
|
|
ti_lib_chipinfo_supports_ble() == true ? "Yes" : "No",
|
|
|
|
ti_lib_chipinfo_supports_proprietary() == true ? "Yes" : "No");
|
2018-03-11 14:38:20 +00:00
|
|
|
LOG_INFO(" RF: Channel %d", chan);
|
|
|
|
|
|
|
|
if(NETSTACK_RADIO.get_value(RADIO_PARAM_PAN_ID, &pan) == RADIO_RESULT_OK) {
|
|
|
|
LOG_INFO_(", PANID 0x%04X", pan);
|
|
|
|
}
|
|
|
|
LOG_INFO_("\n");
|
|
|
|
|
2017-10-29 16:36:58 +00:00
|
|
|
LOG_INFO(" Node ID: %d\n", node_id);
|
2015-02-25 12:12:20 +00:00
|
|
|
|
2017-11-05 17:15:29 +00:00
|
|
|
#if BOARD_HAS_SENSORS
|
2015-02-25 12:12:20 +00:00
|
|
|
process_start(&sensors_process, NULL);
|
2017-11-05 17:15:29 +00:00
|
|
|
#endif
|
|
|
|
|
2015-02-25 12:12:20 +00:00
|
|
|
fade(LEDS_ORANGE);
|
2017-10-14 18:07:38 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
platform_idle()
|
|
|
|
{
|
|
|
|
/* Drop to some low power mode */
|
|
|
|
lpm_drop();
|
2015-02-25 12:12:20 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
* @}
|
|
|
|
*/
|