Contiki-NG
nrf52840-def.h
1 /*
2  * Copyright (c) 2017, George Oikonomou - http://www.spd.gr
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  *
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  * 3. Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived
16  * from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29  * OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 /*---------------------------------------------------------------------------*/
32 #ifndef NRF52840_DEF_H_
33 #define NRF52840_DEF_H_
34 /*---------------------------------------------------------------------------*/
35 #include "cm4/cm4-def.h"
36 /*---------------------------------------------------------------------------*/
37 /* Path to headers with implementation of mutexes, atomic and memory barriers */
38 #define MUTEX_CONF_ARCH_HEADER_PATH "mutex-cortex.h"
39 #define ATOMIC_CONF_ARCH_HEADER_PATH "atomic-cortex.h"
40 #define MEMORY_BARRIER_CONF_ARCH_HEADER_PATH "memory-barrier-cortex.h"
41 /*---------------------------------------------------------------------------*/
42 /* Do the math in 32bits to save precision.
43  * Round to nearest integer rather than truncate. */
44 #define US_TO_RTIMERTICKS(US) ((US) >= 0 ? \
45  (((int32_t)(US) * (RTIMER_ARCH_SECOND) + 500000) / 1000000L) : \
46  ((int32_t)(US) * (RTIMER_ARCH_SECOND) - 500000) / 1000000L)
47 
48 #define RTIMERTICKS_TO_US(T) ((T) >= 0 ? \
49  (((int32_t)(T) * 1000000L + ((RTIMER_ARCH_SECOND) / 2)) / (RTIMER_ARCH_SECOND)) : \
50  ((int32_t)(T) * 1000000L - ((RTIMER_ARCH_SECOND) / 2)) / (RTIMER_ARCH_SECOND))
51 
52 /* A 64-bit version because the 32-bit one cannot handle T >= 4295 ticks.
53  Intended only for positive values of T. */
54 #define RTIMERTICKS_TO_US_64(T) ((uint32_t)(((uint64_t)(T) * 1000000 + ((RTIMER_ARCH_SECOND) / 2)) / (RTIMER_ARCH_SECOND)))
55 /*---------------------------------------------------------------------------*/
56 #define RADIO_PHY_OVERHEAD 3
57 #define RADIO_BYTE_AIR_TIME 32
58 #define RADIO_SHR_LEN 5 /* Synch word + SFD */
59 #define RADIO_DELAY_BEFORE_TX \
60  ((unsigned)US_TO_RTIMERTICKS(RADIO_SHR_LEN * RADIO_BYTE_AIR_TIME))
61 /* Very conservative value moved over from CC2538 */
62 #define RADIO_DELAY_BEFORE_RX ((unsigned)US_TO_RTIMERTICKS(250))
63 #define RADIO_DELAY_BEFORE_DETECT 0
64 
65 #define TSCH_CONF_HW_FRAME_FILTERING 0
66 #define TSCH_CONF_RADIO_ON_DURING_TIMESLOT 1
67 
68 /* Use hardware timestamps.
69  * Disabling this greatly impacts TSCH sync, especially on preview devkits.
70  */
71 #ifndef TSCH_CONF_RESYNC_WITH_SFD_TIMESTAMPS
72 #define TSCH_CONF_RESYNC_WITH_SFD_TIMESTAMPS 1
73 #define TSCH_CONF_TIMESYNC_REMOVE_JITTER 0
74 #endif
75 
76 #ifndef TSCH_CONF_BASE_DRIFT_PPM
77 /*
78  * The drift compared to "true" 10ms slots.
79  * Enable adaptive sync to enable compensation for this.
80  * Slot length 10000 usec
81  * 1000000 / 62500 = 16 usec / rtimer tick
82  * 10 ms is 625 ticks, exactly
83  * Real slot duration 10000 usec
84  */
85 #define TSCH_CONF_BASE_DRIFT_PPM 0
86 #endif
87 /*---------------------------------------------------------------------------*/
88 /* Enable S/W ACKs with CSMA */
89 #define CSMA_CONF_SEND_SOFT_ACK 1
90 /*---------------------------------------------------------------------------*/
91 #define RTIMER_ARCH_SECOND 62500
92 /*---------------------------------------------------------------------------*/
93 #define GPIO_HAL_CONF_ARCH_HDR_PATH "dev/gpio-hal-arch.h"
94 /*---------------------------------------------------------------------------*/
95 #define GPIO_HAL_CONF_ARCH_SW_TOGGLE 0
96 /*---------------------------------------------------------------------------*/
97 #endif /* NRF52840_DEF_H_ */
98 /*---------------------------------------------------------------------------*/
Compiler and data type definitions for all CM4-based CPUs.