Contiki-NG
platform.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, 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  *
14  * 3. Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived
16  * from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29  * OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 /**
32  * \addtogroup cc2538-platforms
33  * @{
34  *
35  * \defgroup cc2538dk The cc2538 Development Kit platform
36  *
37  * The cc2538DK is a platform by Texas Instruments, based on the
38  * cc2538 SoC with an ARM Cortex-M3 core.
39  * @{
40  *
41  * \file
42  * Main module for the cc2538dk platform
43  */
44 /*---------------------------------------------------------------------------*/
45 #include "contiki.h"
46 #include "dev/adc.h"
47 #include "dev/leds.h"
48 #include "dev/uart.h"
49 #include "dev/serial-line.h"
50 #include "dev/slip.h"
51 #include "dev/cc2538-rf.h"
52 #include "dev/udma.h"
53 #include "dev/crypto.h"
54 #include "dev/button-hal.h"
55 #include "usb/usb-serial.h"
56 #include "lib/random.h"
57 #include "lib/sensors.h"
58 #include "net/netstack.h"
60 #include "net/linkaddr.h"
61 #include "sys/platform.h"
62 #include "soc.h"
63 #include "cpu.h"
64 #include "reg.h"
65 #include "ieee-addr.h"
66 #include "lpm.h"
67 
68 #include <stdint.h>
69 #include <string.h>
70 #include <stdio.h>
71 /*---------------------------------------------------------------------------*/
72 /* Log configuration */
73 #include "sys/log.h"
74 #define LOG_MODULE "CC2538DK"
75 #define LOG_LEVEL LOG_LEVEL_MAIN
76 /*---------------------------------------------------------------------------*/
77 static void
78 fade(leds_mask_t l)
79 {
80  volatile int i;
81  int k, j;
82  for(k = 0; k < 800; ++k) {
83  j = k > 400 ? 800 - k : k;
84 
85  leds_on(l);
86  for(i = 0; i < j; ++i) {
87  __asm("nop");
88  }
89  leds_off(l);
90  for(i = 0; i < 400 - j; ++i) {
91  __asm("nop");
92  }
93  }
94 }
95 /*---------------------------------------------------------------------------*/
96 static void
97 set_rf_params(void)
98 {
99  uint16_t short_addr;
100  uint8_t ext_addr[8];
101 
102  ieee_addr_cpy_to(ext_addr, 8);
103 
104  short_addr = ext_addr[7];
105  short_addr |= ext_addr[6] << 8;
106 
107  NETSTACK_RADIO.set_value(RADIO_PARAM_PAN_ID, IEEE802154_PANID);
108  NETSTACK_RADIO.set_value(RADIO_PARAM_16BIT_ADDR, short_addr);
109  NETSTACK_RADIO.set_value(RADIO_PARAM_CHANNEL, IEEE802154_DEFAULT_CHANNEL);
110  NETSTACK_RADIO.set_object(RADIO_PARAM_64BIT_ADDR, ext_addr, 8);
111 }
112 /*---------------------------------------------------------------------------*/
113 void
115 {
116  soc_init();
117 
118  leds_init();
119  fade(LEDS_YELLOW);
120 }
121 /*---------------------------------------------------------------------------*/
122 void
124 {
125  /*
126  * Character I/O Initialisation.
127  * When the UART receives a character it will call serial_line_input_byte to
128  * notify the core. The same applies for the USB driver.
129  *
130  * If slip-arch is also linked in afterwards (e.g. if we are a border router)
131  * it will overwrite one of the two peripheral input callbacks. Characters
132  * received over the relevant peripheral will be handled by
133  * slip_input_byte instead
134  */
135 #if UART_CONF_ENABLE
136  uart_init(0);
137  uart_init(1);
139 #endif
140 
141 #if USB_SERIAL_CONF_ENABLE
142  usb_serial_init();
144 #endif
145 
146  serial_line_init();
147 
148  /* Initialise the H/W RNG engine. */
149  random_init(0);
150 
151  udma_init();
152 
153 #if CRYPTO_CONF_INIT
154  crypto_init();
155  crypto_disable();
156 #endif
157 
158  /* Populate linkaddr_node_addr */
159  ieee_addr_cpy_to(linkaddr_node_addr.u8, LINKADDR_SIZE);
160 
161  button_hal_init();
162 
164 
165  fade(LEDS_GREEN);
166 }
167 /*---------------------------------------------------------------------------*/
168 void
170 {
171  LOG_INFO("%s\n", BOARD_STRING);
172 
173  set_rf_params();
174 
175  soc_print_info();
176 
177  adc_init();
178 
179  process_start(&sensors_process, NULL);
180 
181  fade(LEDS_ORANGE);
182 }
183 /*---------------------------------------------------------------------------*/
184 void
186 {
187  /* We have serviced all pending events. Enter a Low-Power mode. */
188  lpm_enter();
189 }
190 /*---------------------------------------------------------------------------*/
191 /**
192  * @}
193  * @}
194  */
Header file for the cc2538 UART driver.
#define SERIAL_LINE_CONF_UART
UART to use with serial line.
Definition: cc2538-conf.h:126
Header file for the cc2538 RF driver.
void usb_serial_init()
Initialise the Serial-over-USB process.
Definition: usb-serial.c:301
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
Header file for the cc2538 AES/SHA cryptoprocessor driver.
Header file for the link-layer address representation
void leds_init(void)
Initialise the LED HAL.
Definition: minileds.c:44
void uart_init(uint8_t uart)
Initialises the UART controller, configures I/O control and interrupts.
Definition: uart.c:241
void soc_print_info(void)
Prints SoC information.
Definition: soc.c:97
Header file with register manipulation macro definitions.
Header file for the Contiki-NG main routine.
void adc_init(void)
Initializes the ADC controller.
Definition: adc.c:50
Header file for the cc2538 ADC driver.
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
Header file with register, macro and function declarations for the cc2538 micro-DMA controller module...
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
int serial_line_input_byte(unsigned char c)
Get one byte of input from the serial driver.
Definition: serial-line.c:65
#define INTERRUPTS_ENABLE()
Enables all CPU interrupts.
Definition: cpu.h:51
Header file for cc2538&#39;s UART-like I/O over USB.
void uart_set_input(uint8_t uart, int(*input)(unsigned char c))
Assigns a callback to be called when the UART receives a byte.
Definition: uart.c:334
void soc_init()
Common initialisation routine for all CC2538-based platforms.
Definition: soc.c:119
802.15.4 frame creation and parsing functions
Header file with prototypes for interrupt control on the cc2538 Cortex-M3 micro.
void platform_init_stage_three()
Final stage of platform driver initialisation.
Definition: platform.c:169
void crypto_disable(void)
Disables the AES/SHA cryptoprocessor.
Definition: crypto.c:101
Header file with macro and function declarations for the cc2538 SoC.
void random_init(unsigned short seed)
Seed the cc2538 random number generator.
Definition: random.c:84
void udma_init()
Initialise the uDMA driver.
Definition: udma.c:57
Generic serial I/O process header filer.
Include file for the Contiki low-layer network stack (NETSTACK)
void button_hal_init()
Initialise the button HAL.
Definition: button-hal.c:168
Header file for the logging system
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
void usb_serial_set_input(int(*input)(unsigned char c))
Set an input hook for bytes received over USB.
Definition: usb-serial.c:295
void crypto_init(void)
Enables and resets the AES/SHA cryptoprocessor.
Definition: crypto.c:77