Contiki-NG
platform.c
Go to the documentation of this file.
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  * This file is part of the Contiki operating system.
31  *
32  */
33 /*---------------------------------------------------------------------------*/
34 /**
35  * \addtogroup openmote-platform
36  * @{
37  *
38  * \file
39  * Main module for the OpenMote platform
40  */
41 /*---------------------------------------------------------------------------*/
42 #include "contiki.h"
43 #include "dev/leds.h"
44 #include "dev/uart.h"
45 #include "dev/i2c.h"
46 #include "dev/button-sensor.h"
47 #include "dev/serial-line.h"
48 #include "dev/slip.h"
49 #include "dev/cc2538-rf.h"
50 #include "dev/udma.h"
51 #include "dev/crypto.h"
52 #include "dev/button-hal.h"
53 #include "usb/usb-serial.h"
54 #include "lib/random.h"
55 #include "lib/sensors.h"
56 #include "net/netstack.h"
58 #include "net/linkaddr.h"
59 #include "sys/platform.h"
60 #include "soc.h"
61 #include "cpu.h"
62 #include "reg.h"
63 #include "ieee-addr.h"
64 #include "lpm.h"
65 
66 #include <stdint.h>
67 #include <string.h>
68 #include <stdio.h>
69 /*---------------------------------------------------------------------------*/
70 /* Log configuration */
71 #include "sys/log.h"
72 #define LOG_MODULE "OpenMote"
73 #define LOG_LEVEL LOG_LEVEL_MAIN
74 /*---------------------------------------------------------------------------*/
75 /**
76  * \brief Board specific iniatialisation
77  */
78 void board_init(void);
79 /*---------------------------------------------------------------------------*/
80 static void
81 fade(leds_mask_t l)
82 {
83  volatile int i;
84  int k, j;
85  for(k = 0; k < 800; ++k) {
86  j = k > 400 ? 800 - k : k;
87 
88  leds_on(l);
89  for(i = 0; i < j; ++i) {
90  __asm("nop");
91  }
92  leds_off(l);
93  for(i = 0; i < 400 - j; ++i) {
94  __asm("nop");
95  }
96  }
97 }
98 /*---------------------------------------------------------------------------*/
99 static void
100 set_rf_params(void)
101 {
102  uint16_t short_addr;
103  uint8_t ext_addr[8];
104 
105  ieee_addr_cpy_to(ext_addr, 8);
106 
107  short_addr = ext_addr[7];
108  short_addr |= ext_addr[6] << 8;
109 
110  NETSTACK_RADIO.set_value(RADIO_PARAM_PAN_ID, IEEE802154_PANID);
111  NETSTACK_RADIO.set_value(RADIO_PARAM_16BIT_ADDR, short_addr);
112  NETSTACK_RADIO.set_value(RADIO_PARAM_CHANNEL, IEEE802154_DEFAULT_CHANNEL);
113  NETSTACK_RADIO.set_object(RADIO_PARAM_64BIT_ADDR, ext_addr, 8);
114 }
115 /*---------------------------------------------------------------------------*/
116 void
118 {
119  soc_init();
120 
121  leds_init();
122  fade(LEDS_RED);
123 }
124 /*---------------------------------------------------------------------------*/
125 void
127 {
128 #if UART_CONF_ENABLE
129  uart_init(0);
130  uart_init(1);
132 #endif
133 
134 #if USB_SERIAL_CONF_ENABLE
135  usb_serial_init();
137 #endif
138 
139  i2c_init(I2C_SDA_PORT, I2C_SDA_PIN, I2C_SCL_PORT, I2C_SCL_PIN, I2C_SCL_NORMAL_BUS_SPEED);
140 
141  serial_line_init();
142 
143  /* Initialise the H/W RNG engine. */
144  random_init(0);
145 
146  udma_init();
147 
148 #if CRYPTO_CONF_INIT
149  crypto_init();
150  crypto_disable();
151 #endif
152 
153  /* Populate linkaddr_node_addr */
154  ieee_addr_cpy_to(linkaddr_node_addr.u8, LINKADDR_SIZE);
155 
156  button_hal_init();
157 
159 
160  fade(LEDS_BLUE);
161 }
162 /*---------------------------------------------------------------------------*/
163 void
165 {
166  LOG_INFO("%s\n", BOARD_STRING);
167 
168  set_rf_params();
169 
170  board_init();
171 
172  soc_print_info();
173 
174  process_start(&sensors_process, NULL);
175 
176  fade(LEDS_GREEN);
177 }
178 /*---------------------------------------------------------------------------*/
179 void
181 {
182  /* We have serviced all pending events. Enter a Low-Power mode. */
183  lpm_enter();
184 }
185 /*---------------------------------------------------------------------------*/
186 /**
187  * @}
188  */
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
The short address (16 bits) for the radio, which is used by the h/w filter.
Definition: radio.h:166
void soc_print_info(void)
Prints SoC information.
Definition: soc.c:97
Channel used for radio communication.
Definition: radio.h:134
Header file with register manipulation macro definitions.
Header file for the Contiki-NG main routine.
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:64
#define INTERRUPTS_ENABLE()
Enables all CPU interrupts.
Definition: cpu.h:51
void board_init(void)
Board specific iniatialisation.
Definition: board.c:51
void i2c_init(uint8_t port_sda, uint8_t pin_sda, uint8_t port_scl, uint8_t pin_scl, uint32_t bus_speed)
Initialize the I2C peripheral and pins.
Definition: i2c.c:49
The personal area network identifier (PAN ID), which is used by the h/w frame filtering functionality...
Definition: radio.h:150
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
Long (64 bits) address for the radio, which is used by the address filter.
Definition: radio.h:255
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:213
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