Contiki-NG
platform.c
1/*
2 * Copyright (c) 2015, Nordic Semiconductor
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 Institute nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 */
30/*---------------------------------------------------------------------------*/
31/**
32 * \addtogroup nrf52840dk nRF52840 Development Kit
33 * @{
34 */
35#include "contiki.h"
36#include "nordic_common.h"
37
38#include "sdk_config.h"
39#include "nrfx_gpiote.h"
40#include "nrf.h"
41
42#include "contiki-net.h"
43#include "leds.h"
44#include "lib/sensors.h"
45#include "dev/button-hal.h"
46
47#include "dev/serial-line.h"
48#include "dev/uart0.h"
49#include "usb/usb-serial.h"
50#include "usb/usb-dfu-trigger.h"
51#include "lpm.h"
52
53#include <stdio.h>
54#include <stdint.h>
55#include <string.h>
56
57/*---------------------------------------------------------------------------*/
58/* Log configuration */
59#include "sys/log.h"
60#define LOG_MODULE "NRF52DK"
61#define LOG_LEVEL LOG_LEVEL_MAIN
62/*---------------------------------------------------------------------------*/
63/* Nordic semi OUI */
64#define NORDIC_SEMI_VENDOR_OUI 0xF4CE36
65/*---------------------------------------------------------------------------*/
66static void
68{
69 uint8_t device_address[8];
70 uint32_t device_address_low;
71
72 /*
73 * Populate the link address' 3 MSBs using Nordic's OUI.
74 * For the remaining 5 bytes just use any 40 of the 48 FICR->DEVICEADDR
75 * Those are random, so endianness is irrelevant.
76 */
77 device_address[0] = (NORDIC_SEMI_VENDOR_OUI) >> 16 & 0xFF;
78 device_address[1] = (NORDIC_SEMI_VENDOR_OUI) >> 8 & 0xFF;
79 device_address[2] = NORDIC_SEMI_VENDOR_OUI & 0xFF;
80 device_address[3] = NRF_FICR->DEVICEADDR[1] & 0xFF;
81
82 device_address_low = NRF_FICR->DEVICEADDR[0];
83 memcpy(&device_address[4], &device_address_low, 4);
84
85 memcpy(&linkaddr_node_addr, &device_address[8 - LINKADDR_SIZE],
86 LINKADDR_SIZE);
87}
88/*---------------------------------------------------------------------------*/
89void
91{
93 leds_init();
94}
95/*---------------------------------------------------------------------------*/
96void
98{
99#ifdef PLATFORM_HAS_BUTTON
101#endif
102
103 /* Seed value is ignored since hardware RNG is used. */
104 random_init(0);
105
106#if UART0_ENABLED
107 uart0_init();
108 serial_line_init();
109#if BUILD_WITH_SHELL
110 uart0_set_input(serial_line_input_byte);
111#endif
112#endif
113
114#if NRF52840_NATIVE_USB
116 serial_line_init();
117#if BUILD_WITH_SHELL
119#endif
120#endif
121
122#if NRF52840_USB_DFU_TRIGGER
124#endif
125
127}
128/*---------------------------------------------------------------------------*/
129void
131{
132 process_start(&sensors_process, NULL);
133}
134/*---------------------------------------------------------------------------*/
135void
137{
138 lpm_drop();
139}
140/*---------------------------------------------------------------------------*/
141/**
142 * @}
143 */
Header file for the button HAL.
void button_hal_init()
Initialise the button HAL.
Definition: button-hal.c:213
void random_init(unsigned short seed)
Seed the cc2538 random number generator.
Definition: random.c:84
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
void platform_init_stage_three()
Final stage of platform driver initialisation.
Definition: platform.c:169
void platform_init_stage_one(void)
Basic (Stage 1) platform driver initialisation.
Definition: platform.c:114
void platform_idle()
The platform's idle/sleep function.
Definition: platform.c:185
void platform_init_stage_two()
Stage 2 of platform driver initialisation.
Definition: platform.c:123
void lpm_drop()
Drop the cortex to sleep / deep sleep and shut down peripherals.
Definition: lpm.c:525
void leds_init(void)
Initialise the LED HAL.
Definition: minileds.c:44
void populate_link_address(void)
Populates the link address using factory information.
Definition: linkaddr-arch.c:64
void gpio_hal_init()
Initialise the GPIO HAL.
Definition: gpio-hal.c:95
linkaddr_t linkaddr_node_addr
The link-layer address of the node.
Definition: linkaddr.c:48
void uart0_init(unsigned long ubr)
Initalize the RS232 port.
Definition: uart0.c:139
void dfu_trigger_usb_init(void)
Initialise the DFU trigger library.
void process_start(struct process *p, process_data_t data)
Start a process.
Definition: process.c:99
Header file for the LED HAL.
Header file for the logging system.
Generic serial I/O process header filer.
int serial_line_input_byte(unsigned char c)
Get one byte of input from the serial driver.
Definition: serial-line.c:64
Header file for the nRF52840 Dongle DFU trigger library.