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 /*---------------------------------------------------------------------------*/
66 static 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 /*---------------------------------------------------------------------------*/
89 void
91 {
92  gpio_hal_init();
93  leds_init();
94 }
95 /*---------------------------------------------------------------------------*/
96 void
98 {
99 #ifdef PLATFORM_HAS_BUTTON
100  button_hal_init();
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
115  usb_serial_init();
116 #endif
117 
118 #if NRF52840_USB_DFU_TRIGGER
120 #endif
121 
123 }
124 /*---------------------------------------------------------------------------*/
125 void
127 {
128  process_start(&sensors_process, NULL);
129 }
130 /*---------------------------------------------------------------------------*/
131 void
133 {
134  lpm_drop();
135 }
136 /*---------------------------------------------------------------------------*/
137 /**
138  * @}
139  */
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 populate_link_address(void)
Populates the link address using factory information.
Definition: linkaddr-arch.c:62
void platform_idle()
The platform&#39;s idle/sleep function.
Definition: platform.c:185
void leds_init(void)
Initialise the LED HAL.
Definition: minileds.c:44
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 lpm_drop()
Drop the cortex to sleep / deep sleep and shut down peripherals.
Definition: lpm.c:525
int serial_line_input_byte(unsigned char c)
Get one byte of input from the serial driver.
Definition: serial-line.c:64
void dfu_trigger_usb_init(void)
Initialise the DFU trigger library.
void uart0_init(unsigned long ubr)
Initalize the RS232 port.
Definition: uart0.c:139
Header file for the nRF52840 Dongle DFU trigger library.
void platform_init_stage_three()
Final stage of platform driver initialisation.
Definition: platform.c:169
void random_init(unsigned short seed)
Seed the cc2538 random number generator.
Definition: random.c:84
Generic serial I/O process header filer.
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.
void process_start(struct process *p, process_data_t data)
Start a process.
Definition: process.c:99