2015-02-25 13:12:20 +01: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
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* \defgroup cc26xx-srf-tag SmartRF+CC26xx EM and the CC26xx SensorTag 2.0
|
|
|
|
*
|
|
|
|
* This platform supports two different boards:
|
|
|
|
* 1) A standard TI SmartRF06EB with a CC26xx EM mounted on it and
|
|
|
|
* 2) The new TI SensorTag2.0
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
#include "ti-lib.h"
|
|
|
|
#include "contiki.h"
|
|
|
|
#include "contiki-net.h"
|
|
|
|
#include "leds.h"
|
|
|
|
#include "lpm.h"
|
|
|
|
#include "gpio-interrupt.h"
|
|
|
|
#include "dev/watchdog.h"
|
2015-05-01 18:04:44 +02:00
|
|
|
#include "dev/oscillators.h"
|
2015-02-25 13:12:20 +01:00
|
|
|
#include "ieee-addr.h"
|
|
|
|
#include "vims.h"
|
|
|
|
#include "cc26xx-model.h"
|
|
|
|
#include "dev/cc26xx-uart.h"
|
|
|
|
#include "dev/cc26xx-rtc.h"
|
|
|
|
#include "dev/cc26xx-rf.h"
|
|
|
|
#include "sys_ctrl.h"
|
|
|
|
#include "uart.h"
|
|
|
|
#include "sys/clock.h"
|
|
|
|
#include "sys/rtimer.h"
|
|
|
|
#include "lib/sensors.h"
|
|
|
|
#include "button-sensor.h"
|
|
|
|
#include "dev/serial-line.h"
|
|
|
|
#include "net/mac/frame802154.h"
|
|
|
|
|
2015-04-20 08:52:46 +02:00
|
|
|
#include "driverlib/driverlib_release.h"
|
2015-02-25 13:12:20 +01:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
fade(unsigned char l)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
uint16_t short_addr;
|
|
|
|
uint8_t ext_addr[8];
|
|
|
|
radio_value_t val = 0;
|
|
|
|
|
|
|
|
ieee_addr_cpy_to(ext_addr, 8);
|
|
|
|
|
|
|
|
short_addr = ext_addr[7];
|
|
|
|
short_addr |= ext_addr[6] << 8;
|
|
|
|
|
|
|
|
/* Populate linkaddr_node_addr. Maintain endianness */
|
|
|
|
memcpy(&linkaddr_node_addr, &ext_addr[8 - LINKADDR_SIZE], LINKADDR_SIZE);
|
|
|
|
|
|
|
|
NETSTACK_RADIO.set_value(RADIO_PARAM_PAN_ID, IEEE802154_PANID);
|
|
|
|
NETSTACK_RADIO.set_value(RADIO_PARAM_16BIT_ADDR, short_addr);
|
|
|
|
NETSTACK_RADIO.set_value(RADIO_PARAM_CHANNEL, CC26XX_RF_CHANNEL);
|
|
|
|
NETSTACK_RADIO.set_object(RADIO_PARAM_64BIT_ADDR, ext_addr, 8);
|
|
|
|
|
|
|
|
NETSTACK_RADIO.get_value(RADIO_PARAM_CHANNEL, &val);
|
|
|
|
printf(" RF: Channel %d\n", val);
|
|
|
|
|
|
|
|
#if STARTUP_CONF_VERBOSE
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
printf(" Link layer addr: ");
|
|
|
|
for(i = 0; i < LINKADDR_SIZE - 1; i++) {
|
|
|
|
printf("%02x:", linkaddr_node_addr.u8[i]);
|
|
|
|
}
|
|
|
|
printf("%02x\n", linkaddr_node_addr.u8[i]);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
/**
|
|
|
|
* \brief Main function for CC26xx-based platforms
|
|
|
|
*
|
|
|
|
* The same main() is used for both Srf+CC26xxEM as well as for the SensorTag
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
2015-05-01 18:04:44 +02: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 13:12:20 +01:00
|
|
|
|
2015-05-01 18:04:44 +02:00
|
|
|
ti_lib_int_master_disable();
|
2015-02-25 13:12:20 +01:00
|
|
|
|
2015-05-01 18:04:44 +02:00
|
|
|
/* Set the LF XOSC as the LF system clock source */
|
|
|
|
oscillators_select_lf_xosc();
|
2015-02-25 13:12:20 +01:00
|
|
|
|
|
|
|
lpm_init();
|
|
|
|
|
|
|
|
board_init();
|
|
|
|
|
|
|
|
gpio_interrupt_init();
|
|
|
|
|
|
|
|
leds_init();
|
|
|
|
|
2015-05-01 18:04:44 +02: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();
|
|
|
|
|
2015-02-25 13:12:20 +01:00
|
|
|
fade(LEDS_RED);
|
|
|
|
|
2015-05-01 18:04:44 +02:00
|
|
|
ti_lib_int_master_enable();
|
|
|
|
|
2015-02-25 13:12:20 +01:00
|
|
|
cc26xx_rtc_init();
|
|
|
|
clock_init();
|
|
|
|
rtimer_init();
|
|
|
|
|
|
|
|
watchdog_init();
|
|
|
|
process_init();
|
|
|
|
|
|
|
|
random_init(0x1234);
|
|
|
|
|
|
|
|
/* Character I/O Initialisation */
|
|
|
|
#if CC26XX_UART_CONF_ENABLE
|
|
|
|
cc26xx_uart_init();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
serial_line_init();
|
|
|
|
|
|
|
|
printf("Starting " CONTIKI_VERSION_STRING "\n");
|
2015-04-20 08:52:46 +02:00
|
|
|
printf("With DriverLib v%u.%u\n", DRIVERLIB_RELEASE_GROUP,
|
|
|
|
DRIVERLIB_RELEASE_BUILD);
|
2015-02-25 13:12:20 +01:00
|
|
|
printf(BOARD_STRING " using CC%u\n", CC26XX_MODEL_CPU_VARIANT);
|
|
|
|
|
|
|
|
process_start(&etimer_process, NULL);
|
|
|
|
ctimer_init();
|
|
|
|
|
|
|
|
energest_init();
|
|
|
|
ENERGEST_ON(ENERGEST_TYPE_CPU);
|
|
|
|
|
|
|
|
fade(LEDS_YELLOW);
|
|
|
|
|
|
|
|
printf(" Net: ");
|
|
|
|
printf("%s\n", NETSTACK_NETWORK.name);
|
|
|
|
printf(" MAC: ");
|
|
|
|
printf("%s\n", NETSTACK_MAC.name);
|
|
|
|
printf(" RDC: ");
|
|
|
|
printf("%s", NETSTACK_RDC.name);
|
|
|
|
|
|
|
|
if(NETSTACK_RDC.channel_check_interval() != 0) {
|
|
|
|
printf(", Channel Check Interval: %u ticks",
|
|
|
|
NETSTACK_RDC.channel_check_interval());
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
netstack_init();
|
|
|
|
|
|
|
|
set_rf_params();
|
|
|
|
|
|
|
|
#if NETSTACK_CONF_WITH_IPV6
|
|
|
|
memcpy(&uip_lladdr.addr, &linkaddr_node_addr, sizeof(uip_lladdr.addr));
|
|
|
|
queuebuf_init();
|
|
|
|
process_start(&tcpip_process, NULL);
|
|
|
|
#endif /* NETSTACK_CONF_WITH_IPV6 */
|
|
|
|
|
|
|
|
fade(LEDS_GREEN);
|
|
|
|
|
|
|
|
process_start(&sensors_process, NULL);
|
|
|
|
|
|
|
|
autostart_start(autostart_processes);
|
|
|
|
|
|
|
|
watchdog_start();
|
|
|
|
|
|
|
|
fade(LEDS_ORANGE);
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
uint8_t r;
|
|
|
|
do {
|
|
|
|
r = process_run();
|
|
|
|
watchdog_periodic();
|
|
|
|
} while(r > 0);
|
|
|
|
|
|
|
|
/* Drop to some low power mode */
|
|
|
|
lpm_drop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
* @}
|
|
|
|
*/
|