Contiki-NG
Loading...
Searching...
No Matches
platform.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2020 Yago Fontoura do Rosario <yago.rosario@hotmail.com.br>
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/*---------------------------------------------------------------------------*/
31/**
32 * \addtogroup nrf-platforms
33 * @{
34 *
35 * \file
36 * Platform implementation for nRF
37 * \author
38 * Yago Fontoura do Rosario <yago.rosario@hotmail.com.br>
39 */
40/*---------------------------------------------------------------------------*/
41#include "contiki.h"
42
43#include "dev/gpio-hal.h"
44#include "dev/button-hal.h"
45#include "dev/leds.h"
46#include "dev/serial-line.h"
47#include "lib/csprng.h"
48
49#include "int-master.h"
50#include "sensors.h"
51#include "uarte-arch.h"
52#include "linkaddr-arch.h"
53#include "reset-arch.h"
54
55#include "lpm.h"
56#include "nrfx_config.h"
57#include "usb.h"
58
59/*---------------------------------------------------------------------------*/
60/* Log configuration */
61#include "sys/log.h"
62#define LOG_MODULE "NRF"
63#define LOG_LEVEL LOG_LEVEL_MAIN
64/*---------------------------------------------------------------------------*/
65#if NRF_HARDFAULT_HANDLER_EXTENDED
66void hardfault_print_saved_crash(void);
67#endif
68/*---------------------------------------------------------------------------*/
69__attribute__((weak)) void
70platform_init_board(void)
71{
72}
73/*---------------------------------------------------------------------------*/
74__attribute__((weak)) void
75platform_init_board_stage_two(void)
76{
77}
78/*---------------------------------------------------------------------------*/
79void
81{
83 platform_init_board();
84 leds_init();
85}
86/*---------------------------------------------------------------------------*/
87static void
88feed_csprng(void)
89{
90#if defined(NRF_RNG) && CSPRNG_ENABLED
91 struct csprng_seed seed;
92
93 NRF_RNG->TASKS_START = 1;
94 for(size_t i = 0; i < sizeof(seed); i++) {
95 NRF_RNG->EVENTS_VALRDY = 0;
96 while(!NRF_RNG->EVENTS_VALRDY);
97 ((uint8_t *)&seed)[i] = NRF_RNG->VALUE;
98 }
99 NRF_RNG->TASKS_STOP = 1;
100 csprng_feed(&seed);
101#endif /* defined(NRF_RNG) && CSPRNG_ENABLED */
102}
103/*---------------------------------------------------------------------------*/
104void
106{
107 platform_init_board_stage_two();
109
110 /* There are two images of everything when building with
111 * TrustZone, and uarte can only be initialized once,
112 * so initialize in the secure mode. */
113#if NRF_HAS_UARTE && !defined(NRF_TRUSTZONE_NONSECURE)
114 uarte_init();
115#if NRF_HARDFAULT_HANDLER_EXTENDED
116 hardfault_print_saved_crash();
117#endif
118#endif /* NRF_HAS_UARTE */
119
120#if NRF_HAS_USB && defined(NRF_NATIVE_USB) && NRF_NATIVE_USB == 1
121 usb_init();
122#endif /* NRF_HAS_USB && defined(NRF_NATIVE_USB) && NRF_NATIVE_USB == 1 */
123
124 serial_line_init();
125
126#if BUILD_WITH_SHELL
127#if PLATFORM_DBG_CONF_USB
128 usb_set_input(serial_line_input_byte);
129#else /* PLATFORM_DBG_CONF_USB */
130 uarte_set_input(serial_line_input_byte);
131#endif /* PLATFORM_DBG_CONF_USB */
132#endif /* BUILD_WITH_SHELL */
133
135
136 feed_csprng();
137
138 reset_debug();
139}
140/*---------------------------------------------------------------------------*/
141void
143{
144 process_start(&sensors_process, NULL);
145}
146/*---------------------------------------------------------------------------*/
147void
149{
150 lpm_drop();
151}
152/*---------------------------------------------------------------------------*/
153/**
154 * @}
155 */
Header file for the button HAL.
An OFB-AES-128-based CSPRNG.
Header file for the GPIO HAL.
void button_hal_init()
Initialise the button HAL.
Definition button-hal.c:213
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 lpm_drop()
Drop the cortex to sleep / deep sleep and shut down peripherals.
Definition lpm.c:525
void csprng_feed(struct csprng_seed *new_seed)
Mixes a new seed with the current one.
Definition csprng.c:58
void leds_init(void)
Initialise the LED HAL.
Definition minileds.c:44
void populate_link_address(void)
Populates the link address using factory information.
void gpio_hal_init()
Initialise the GPIO HAL.
Definition gpio-hal.c:95
void reset_debug(void)
Logs the reset reason.
Definition reset-arch.c:60
void uarte_init(void)
Initializa the UARTE driver.
void uarte_set_input(int(*input)(unsigned char c))
Sets the input handler called in the event handler.
void usb_set_input(int(*input)(unsigned char c))
Sets the input handler called in the event handler.
Definition usb.c:79
void usb_init(void)
Initialize the USB driver.
Definition usb.c:85
void process_start(struct process *p, process_data_t data)
Start a process.
Definition process.c:121
Header file for the LED HAL.
Header file for the logging system.
Configuration for the nrf platform.
Reset reason implementation for the nRF.
Generic serial I/O process header filer.
This is the structure of a seed.
Definition csprng.h:72
UARTE header file for the nRF.