2013-01-12 22:44:42 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2012, 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.
|
|
|
|
*/
|
|
|
|
/**
|
2015-02-14 01:13:21 +00:00
|
|
|
* \addtogroup cc2538-platforms
|
2013-01-12 22:44:42 +00:00
|
|
|
* @{
|
|
|
|
*
|
2015-02-14 01:13:21 +00:00
|
|
|
* \defgroup cc2538dk The cc2538 Development Kit platform
|
2013-01-12 22:44:42 +00:00
|
|
|
*
|
2015-02-14 01:09:24 +00:00
|
|
|
* The cc2538DK is a platform by Texas Instruments, based on the
|
|
|
|
* cc2538 SoC with an ARM Cortex-M3 core.
|
2013-01-12 22:44:42 +00:00
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* \file
|
|
|
|
* Main module for the cc2538dk platform
|
|
|
|
*/
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
#include "contiki.h"
|
2015-02-11 17:06:20 +00:00
|
|
|
#include "dev/adc.h"
|
2013-01-12 22:44:42 +00:00
|
|
|
#include "dev/leds.h"
|
|
|
|
#include "dev/sys-ctrl.h"
|
|
|
|
#include "dev/nvic.h"
|
|
|
|
#include "dev/uart.h"
|
|
|
|
#include "dev/watchdog.h"
|
|
|
|
#include "dev/ioc.h"
|
|
|
|
#include "dev/button-sensor.h"
|
|
|
|
#include "dev/serial-line.h"
|
|
|
|
#include "dev/slip.h"
|
|
|
|
#include "dev/cc2538-rf.h"
|
|
|
|
#include "dev/udma.h"
|
2015-10-21 08:18:04 +00:00
|
|
|
#include "dev/crypto.h"
|
2013-01-12 22:44:42 +00:00
|
|
|
#include "usb/usb-serial.h"
|
|
|
|
#include "lib/random.h"
|
|
|
|
#include "net/netstack.h"
|
|
|
|
#include "net/queuebuf.h"
|
2013-11-22 08:17:54 +00:00
|
|
|
#include "net/ip/tcpip.h"
|
|
|
|
#include "net/ip/uip.h"
|
2017-05-16 16:20:34 +00:00
|
|
|
#include "net/mac/framer/frame802154.h"
|
2016-06-11 21:19:21 +00:00
|
|
|
#include "soc.h"
|
2013-01-12 22:44:42 +00:00
|
|
|
#include "cpu.h"
|
|
|
|
#include "reg.h"
|
|
|
|
#include "ieee-addr.h"
|
|
|
|
#include "lpm.h"
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
#if STARTUP_CONF_VERBOSE
|
|
|
|
#define PRINTF(...) printf(__VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#define PRINTF(...)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if UART_CONF_ENABLE
|
|
|
|
#define PUTS(s) puts(s)
|
|
|
|
#else
|
|
|
|
#define PUTS(s)
|
|
|
|
#endif
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
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
|
2014-04-22 18:28:38 +00:00
|
|
|
set_rf_params(void)
|
2013-01-12 22:44:42 +00:00
|
|
|
{
|
2014-04-22 18:28:38 +00:00
|
|
|
uint16_t short_addr;
|
|
|
|
uint8_t ext_addr[8];
|
|
|
|
|
|
|
|
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);
|
2013-01-12 22:44:42 +00:00
|
|
|
|
|
|
|
#if STARTUP_CONF_VERBOSE
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
printf("Rime configured with address ");
|
2013-12-12 22:58:52 +00:00
|
|
|
for(i = 0; i < LINKADDR_SIZE - 1; i++) {
|
|
|
|
printf("%02x:", linkaddr_node_addr.u8[i]);
|
2013-01-12 22:44:42 +00:00
|
|
|
}
|
2013-12-12 22:58:52 +00:00
|
|
|
printf("%02x\n", linkaddr_node_addr.u8[i]);
|
2013-01-12 22:44:42 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-04-22 18:28:38 +00:00
|
|
|
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, CC2538_RF_CHANNEL);
|
|
|
|
NETSTACK_RADIO.set_object(RADIO_PARAM_64BIT_ADDR, ext_addr, 8);
|
2013-01-12 22:44:42 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
/**
|
|
|
|
* \brief Main routine for the cc2538dk platform
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
|
|
|
nvic_init();
|
2013-11-04 20:34:53 +00:00
|
|
|
ioc_init();
|
2013-01-12 22:44:42 +00:00
|
|
|
sys_ctrl_init();
|
|
|
|
clock_init();
|
|
|
|
lpm_init();
|
|
|
|
rtimer_init();
|
|
|
|
gpio_init();
|
|
|
|
|
|
|
|
leds_init();
|
|
|
|
fade(LEDS_YELLOW);
|
|
|
|
|
|
|
|
process_init();
|
|
|
|
|
|
|
|
watchdog_init();
|
|
|
|
button_sensor_init();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Character I/O Initialisation.
|
|
|
|
* When the UART receives a character it will call serial_line_input_byte to
|
|
|
|
* notify the core. The same applies for the USB driver.
|
|
|
|
*
|
|
|
|
* If slip-arch is also linked in afterwards (e.g. if we are a border router)
|
|
|
|
* it will overwrite one of the two peripheral input callbacks. Characters
|
|
|
|
* received over the relevant peripheral will be handled by
|
|
|
|
* slip_input_byte instead
|
|
|
|
*/
|
|
|
|
#if UART_CONF_ENABLE
|
2014-04-04 17:33:11 +00:00
|
|
|
uart_init(0);
|
|
|
|
uart_init(1);
|
|
|
|
uart_set_input(SERIAL_LINE_CONF_UART, serial_line_input_byte);
|
2013-01-12 22:44:42 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if USB_SERIAL_CONF_ENABLE
|
|
|
|
usb_serial_init();
|
|
|
|
usb_serial_set_input(serial_line_input_byte);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
serial_line_init();
|
|
|
|
|
|
|
|
INTERRUPTS_ENABLE();
|
|
|
|
fade(LEDS_GREEN);
|
|
|
|
|
|
|
|
PUTS(CONTIKI_VERSION_STRING);
|
|
|
|
PUTS(BOARD_STRING);
|
2016-06-11 21:19:21 +00:00
|
|
|
#if STARTUP_CONF_VERBOSE
|
|
|
|
soc_print_info();
|
|
|
|
#endif
|
2013-01-12 22:44:42 +00:00
|
|
|
|
|
|
|
PRINTF(" Net: ");
|
|
|
|
PRINTF("%s\n", NETSTACK_NETWORK.name);
|
|
|
|
PRINTF(" MAC: ");
|
|
|
|
PRINTF("%s\n", NETSTACK_MAC.name);
|
|
|
|
|
|
|
|
/* Initialise the H/W RNG engine. */
|
|
|
|
random_init(0);
|
|
|
|
|
|
|
|
udma_init();
|
|
|
|
|
|
|
|
process_start(&etimer_process, NULL);
|
|
|
|
ctimer_init();
|
|
|
|
|
2014-04-22 18:28:38 +00:00
|
|
|
set_rf_params();
|
2015-10-21 08:18:04 +00:00
|
|
|
|
|
|
|
#if CRYPTO_CONF_INIT
|
|
|
|
crypto_init();
|
|
|
|
crypto_disable();
|
|
|
|
#endif
|
|
|
|
|
2013-01-12 22:44:42 +00:00
|
|
|
netstack_init();
|
|
|
|
|
2014-12-01 20:02:57 +00:00
|
|
|
#if NETSTACK_CONF_WITH_IPV6
|
2013-12-12 22:58:52 +00:00
|
|
|
memcpy(&uip_lladdr.addr, &linkaddr_node_addr, sizeof(uip_lladdr.addr));
|
2013-01-12 22:44:42 +00:00
|
|
|
queuebuf_init();
|
|
|
|
process_start(&tcpip_process, NULL);
|
2014-12-01 20:02:57 +00:00
|
|
|
#endif /* NETSTACK_CONF_WITH_IPV6 */
|
2013-01-12 22:44:42 +00:00
|
|
|
|
2015-02-11 17:06:20 +00:00
|
|
|
adc_init();
|
|
|
|
|
2013-01-12 22:44:42 +00:00
|
|
|
process_start(&sensors_process, NULL);
|
|
|
|
|
|
|
|
energest_init();
|
|
|
|
ENERGEST_ON(ENERGEST_TYPE_CPU);
|
|
|
|
|
|
|
|
autostart_start(autostart_processes);
|
|
|
|
|
|
|
|
watchdog_start();
|
|
|
|
fade(LEDS_ORANGE);
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
uint8_t r;
|
|
|
|
do {
|
|
|
|
/* Reset watchdog and handle polls and events */
|
|
|
|
watchdog_periodic();
|
|
|
|
|
|
|
|
r = process_run();
|
|
|
|
} while(r > 0);
|
|
|
|
|
|
|
|
/* We have serviced all pending events. Enter a Low-Power mode. */
|
|
|
|
lpm_enter();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
* @}
|
|
|
|
*/
|