Contiki-NG
Loading...
Searching...
No Matches
platform.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/
3 * Copyright (c) 2015, Zolertia - http://www.zolertia.com
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its
16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
30 * OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32/**
33 * \addtogroup zoul-core
34 * @{
35 *
36 * \defgroup zoul Zolertia Zoul core module
37 *
38 * The Zoul comprises the CC2538SF53 and CC1200 in a single module
39 * format, which allows a fast reuse of its core components in different
40 * formats and form-factors.
41 * @{
42 *
43 * \file
44 * Main module for the Zolertia Zoul core and based platforms
45 */
46/*---------------------------------------------------------------------------*/
47#include "contiki.h"
48#include "dev/leds.h"
49#include "dev/uart.h"
50#include "dev/button-sensor.h"
51#include "dev/serial-line.h"
52#include "dev/slip.h"
53#include "dev/cc2538-rf.h"
54#include "dev/udma.h"
55#include "dev/crypto.h"
56#include "dev/rtcc.h"
57#include "dev/button-hal.h"
58#include "usb/usb-serial.h"
59#include "lib/sensors.h"
60#include "net/netstack.h"
62#include "net/linkaddr.h"
63#include "sys/platform.h"
64#include "soc.h"
65#include "cpu.h"
66#include "reg.h"
67#include "ieee-addr.h"
68#include "lpm.h"
69
70#include <stdint.h>
71#include <string.h>
72#include <stdio.h>
73#include <stdlib.h>
74/*---------------------------------------------------------------------------*/
75/* Log configuration */
76#include "sys/log.h"
77#define LOG_MODULE "Zoul"
78#define LOG_LEVEL LOG_LEVEL_MAIN
79/*---------------------------------------------------------------------------*/
80/**
81 * \brief Board specific iniatialisation
82 */
83void board_init(void);
84/*---------------------------------------------------------------------------*/
85static void
86fade(leds_mask_t l)
87{
88 volatile int i;
89 int k, j;
90 for(k = 0; k < 800; ++k) {
91 j = k > 400 ? 800 - k : k;
92
93 leds_on(l);
94 for(i = 0; i < j; ++i) {
95 __asm("nop");
96 }
97 leds_off(l);
98 for(i = 0; i < 400 - j; ++i) {
99 __asm("nop");
100 }
101 }
102}
103/*---------------------------------------------------------------------------*/
104static void
105rtc_init(void)
106{
107#if RTC_CONF_INIT
108#if RTC_CONF_SET_FROM_SYS
109 char *next;
110 simple_td_map td;
111#endif
112
113 /* Configure RTC and return structure with all parameters */
114 rtcc_init();
115
116#if RTC_CONF_SET_FROM_SYS
117#ifndef DATE
118#error Could not retrieve date from system
119#endif
120
121 /* Alternatively, for test only, undefine DATE and define it on your own as:
122 * #define DATE "07 06 12 15 16 00 00"
123 * Also note that if you restart the node at a given time, it will use the
124 * already defined DATE, so if you want to update the device date/time you
125 * need to reflash the node.
126 */
127
128 /* Get the system date in the following format: wd dd mm yy hh mm ss */
129 LOG_INFO("Setting RTC from system date: %s\n", DATE);
130
131 /* Configure the RTC with the current values */
132 td.weekdays = (uint8_t)strtol(DATE, &next, 10);
133 td.day = (uint8_t)strtol(next, &next, 10);
134 td.months = (uint8_t)strtol(next, &next, 10);
135 td.years = (uint8_t)strtol(next, &next, 10);
136 td.hours = (uint8_t)strtol(next, &next, 10);
137 td.minutes = (uint8_t)strtol(next, &next, 10);
138 td.seconds = (uint8_t)strtol(next, NULL, 10);
139
140 /* Don't care about the milliseconds... */
141 td.miliseconds = 0;
142
143 /* This example relies on 24h mode */
144 td.mode = RTCC_24H_MODE;
145
146 /*
147 * And to simplify the configuration, it relies on the fact that it will be
148 * executed in the present century
149 */
150 td.century = RTCC_CENTURY_20XX;
151
152 /* Set the time and date */
153 if(rtcc_set_time_date(&td) == AB08_ERROR) {
154 LOG_ERR("Failed to set time and date\n");
155 }
156#endif
157#endif
158}
159/*---------------------------------------------------------------------------*/
160static void
161set_rf_params(void)
162{
163 uint16_t short_addr;
164 uint8_t ext_addr[8];
165
166 ieee_addr_cpy_to(ext_addr, 8);
167
168 short_addr = ext_addr[7];
169 short_addr |= ext_addr[6] << 8;
170
171 NETSTACK_RADIO.set_value(RADIO_PARAM_PAN_ID, IEEE802154_PANID);
172 NETSTACK_RADIO.set_value(RADIO_PARAM_16BIT_ADDR, short_addr);
173 NETSTACK_RADIO.set_value(RADIO_PARAM_CHANNEL, IEEE802154_DEFAULT_CHANNEL);
174 NETSTACK_RADIO.set_object(RADIO_PARAM_64BIT_ADDR, ext_addr, 8);
175}
176/*---------------------------------------------------------------------------*/
177void
179{
180 soc_init();
181
182 leds_init();
183 fade(LEDS_RED);
184}
185/*---------------------------------------------------------------------------*/
186void
188{
189 /*
190 * Character I/O Initialisation.
191 * When the UART receives a character it will call serial_line_input_byte to
192 * notify the core. The same applies for the USB driver.
193 *
194 * If slip-arch is also linked in afterwards (e.g. if we are a border router)
195 * it will overwrite one of the two peripheral input callbacks. Characters
196 * received over the relevant peripheral will be handled by
197 * slip_input_byte instead
198 */
199#if UART_CONF_ENABLE
200 uart_init(0);
201 uart_init(1);
202 uart_set_input(SERIAL_LINE_CONF_UART, serial_line_input_byte);
203#endif
204
205#if USB_SERIAL_CONF_ENABLE
207 usb_serial_set_input(serial_line_input_byte);
208#endif
209
210 serial_line_init();
211
212 udma_init();
213
214#if CRYPTO_CONF_INIT
215 crypto_init();
217#endif
218
219 /* Populate linkaddr_node_addr */
220 ieee_addr_cpy_to(linkaddr_node_addr.u8, LINKADDR_SIZE);
221
222#if PLATFORM_HAS_BUTTON
224#endif
225
227
228 fade(LEDS_BLUE);
229}
230/*---------------------------------------------------------------------------*/
231void
233{
234 LOG_INFO("%s\n", BOARD_STRING);
235
236 set_rf_params();
237
238 board_init();
239
240 rtc_init();
241
243
244 process_start(&sensors_process, NULL);
245
246 fade(LEDS_GREEN);
247}
248/*---------------------------------------------------------------------------*/
249void
251{
252 /* We have serviced all pending events. Enter a Low-Power mode. */
253 lpm_enter();
254}
255/*---------------------------------------------------------------------------*/
256unsigned
257radio_phy_overhead(void) {
258 radio_value_t ret;
259 NETSTACK_RADIO.get_value(RADIO_CONST_PHY_OVERHEAD, &ret);
260 return (unsigned)ret;
261}
262/*---------------------------------------------------------------------------*/
263unsigned
264radio_byte_air_time(void) {
265 radio_value_t ret;
266 NETSTACK_RADIO.get_value(RADIO_CONST_BYTE_AIR_TIME, &ret);
267 return (unsigned)ret;
268}
269/*---------------------------------------------------------------------------*/
270unsigned
271radio_delay_before_tx(void) {
272 radio_value_t ret;
273 NETSTACK_RADIO.get_value(RADIO_CONST_DELAY_BEFORE_TX, &ret);
274 return (unsigned)ret;
275}
276/*---------------------------------------------------------------------------*/
277unsigned
278radio_delay_before_rx(void) {
279 radio_value_t ret;
280 NETSTACK_RADIO.get_value(RADIO_CONST_DELAY_BEFORE_RX, &ret);
281 return (unsigned)ret;
282}
283/*---------------------------------------------------------------------------*/
284unsigned
285radio_delay_before_detect(void) {
286 radio_value_t ret;
287 NETSTACK_RADIO.get_value(RADIO_CONST_DELAY_BEFORE_DETECT, &ret);
288 return (unsigned)ret;
289}
290/*---------------------------------------------------------------------------*/
291uint16_t *
292radio_tsch_timeslot_timing(void) {
293 uint16_t *ret;
294 /* Get and return pointer to TSCH timings in usec */
295 NETSTACK_RADIO.get_object(RADIO_CONST_TSCH_TIMING, &ret, sizeof(ret));
296 return ret;
297}
298/*---------------------------------------------------------------------------*/
299/**
300 * @}
301 * @}
302 */
Header file for the button HAL.
Header file for the cc2538 RF driver.
Header file with prototypes for interrupt control on the cc2538 Cortex-M3 micro.
Header file for the cc2538 AES/SHA cryptoprocessor driver.
802.15.4 frame creation and parsing functions
void button_hal_init()
Initialise the button HAL.
Definition button-hal.c:213
#define INTERRUPTS_ENABLE()
Enables all CPU interrupts.
Definition cpu.h:51
void crypto_init(void)
Enables and resets the AES/SHA cryptoprocessor.
Definition crypto.c:77
void crypto_disable(void)
Disables the AES/SHA cryptoprocessor.
Definition crypto.c:101
void ieee_addr_cpy_to(uint8_t *dst, uint8_t len)
Definition ieee-addr.c:47
void soc_print_info(void)
Prints SoC information.
Definition soc.c:98
void soc_init()
Common initialisation routine for all CC2538-based platforms.
Definition soc.c:120
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 udma_init()
Initialise the uDMA driver.
Definition udma.c:65
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 usb_serial_init()
Initialise the Serial-over-USB process.
Definition usb-serial.c:301
#define SERIAL_LINE_CONF_UART
UART to use with serial line.
void platform_init_stage_three()
Final stage of platform driver initialisation.
Definition platform.c:165
void platform_init_stage_one(void)
Basic (Stage 1) platform driver initialisation.
Definition platform.c:113
void platform_idle()
The platform's idle/sleep function.
Definition platform.c:181
void platform_init_stage_two()
Stage 2 of platform driver initialisation.
Definition platform.c:122
void board_init(void)
Board specific iniatialisation.
Definition board.c:80
void leds_init(void)
Initialise the LED HAL.
Definition minileds.c:44
uint8_t leds_mask_t
An OR mask datatype to represents multiple LEDs.
Definition leds.h:164
void uart_init(void)
Initializa the UART driver.
Definition uart-arch.c:87
linkaddr_t linkaddr_node_addr
The link-layer address of the node.
Definition linkaddr.c:48
void process_start(struct process *p, process_data_t data)
Start a process.
Definition process.c:121
int radio_value_t
Each radio has a set of parameters that designate the current configuration and state of the radio.
Definition radio.h:88
@ RADIO_CONST_PHY_OVERHEAD
The physical layer header (PHR) + MAC layer footer (MFR) overhead in bytes.
Definition radio.h:338
@ RADIO_CONST_BYTE_AIR_TIME
The air time of one byte in usec, e.g.
Definition radio.h:343
@ RADIO_PARAM_CHANNEL
Channel used for radio communication.
Definition radio.h:134
@ RADIO_CONST_DELAY_BEFORE_RX
The delay in usec between turning on the radio and it being actually listening (able to hear a preamb...
Definition radio.h:355
@ RADIO_PARAM_64BIT_ADDR
Long (64 bits) address for the radio, which is used by the address filter.
Definition radio.h:263
@ RADIO_CONST_DELAY_BEFORE_TX
The delay in usec between a call to the radio API's transmit function and the end of SFD transmission...
Definition radio.h:349
@ RADIO_PARAM_PAN_ID
The personal area network identifier (PAN ID), which is used by the h/w frame filtering functionality...
Definition radio.h:150
@ RADIO_CONST_DELAY_BEFORE_DETECT
The delay in usec between the end of SFD reception for an incoming frame and the radio API starting t...
Definition radio.h:361
@ RADIO_PARAM_16BIT_ADDR
The short address (16 bits) for the radio, which is used by the h/w filter.
Definition radio.h:166
int8_t rtcc_init(void)
Initialize the RTCC, configures the I2C bus, interrupts and registers.
Definition rtcc.c:922
int8_t rtcc_set_time_date(simple_td_map *data)
Set the time and date.
Definition rtcc.c:271
Header file for the LED HAL.
Header file for the link-layer address representation.
Header file for the logging system.
#define IEEE802154_DEFAULT_CHANNEL
The default channel for IEEE 802.15.4 networks.
Definition mac.h:52
Include file for the Contiki low-layer network stack (NETSTACK)
Header file for the Contiki-NG main routine.
Header file with register manipulation macro definitions.
Header file for the RE-Mote RF antenna switch.
Generic serial I/O process header filer.
Header file with macro and function declarations for the cc2538 SoC.
Header file for the cc2538 UART driver.
Header file with register, macro and function declarations for the cc2538 micro-DMA controller module...