MySensors Library & Examples  2.3.2
MyHwNRF5.h
1 /*
2  * The MySensors Arduino library handles the wireless radio link and protocol
3  * between your home built sensors/actuators and HA controller of choice.
4  * The sensors forms a self healing radio network with optional repeaters. Each
5  * repeater and gateway builds a routing tables in EEPROM which keeps track of
6  * the
7  * network topology allowing messages to be routed to nodes.
8  *
9  * Created by Henrik Ekblad <[email protected]>
10  * Copyright (C) 2013-2019 Sensnology AB
11  * Copyright (C) 2017 Frank Holtz
12  * Full contributor list:
13  * https://github.com/mysensors/MySensors/graphs/contributors
14  *
15  * Documentation: http://www.mysensors.org
16  * Support Forum: http://forum.mysensors.org
17  *
18  * This program is free software; you can redistribute it and/or
19  * modify it under the terms of the GNU General Public License
20  * version 2 as published by the Free Software Foundation.
21  */
22 #ifndef MyHwNRF5_h
23 #define MyHwNRF5_h
24 
25 #ifdef __cplusplus
26 #include <Arduino.h>
27 #endif
28 
29 #define CRYPTO_LITTLE_ENDIAN
30 
31 #ifndef MY_SERIALDEVICE
32 #define MY_SERIALDEVICE Serial
33 #endif
34 
35 #ifndef MY_DEBUGDEVICE
36 #define MY_DEBUGDEVICE MY_SERIALDEVICE
37 #endif
38 
39 // Define NRF5_SOFTDEVICE when SoftDevice found
40 #if defined(S110) || defined(S130) || defined(S132) || defined(S140)
41 #ifndef SOFTDEVICE_PRESENT
42 #define SOFTDEVICE_PRESENT
43 #endif
44 #endif
45 
46 // Define ARDUINO_ARCH_NRF5, if not defined
47 #ifndef ARDUINO_ARCH_NRF5
48 #define ARDUINO_ARCH_NRF5
49 #endif
50 
51 #include "hal/architecture/NRF5/drivers/nrf5_wiring_digital.c"
53 #include "hal/architecture/NRF5/drivers/nrf_temp.h"
54 #include "drivers/NVM/NVRAM.cpp"
55 #include "drivers/NVM/VirtualPage.cpp"
56 #include <avr/dtostrf.h>
57 #include <nrf.h>
58 #include <SPI.h>
59 
60 // mapping
61 #ifndef strncpy_P
62 #define strncpy_P strncpy
63 #endif
64 #ifndef snprintf_P
65 #define snprintf_P(s, f, ...) snprintf((s), (f), __VA_ARGS__)
66 #endif
67 #ifndef vsnprintf_P
68 #define vsnprintf_P vsnprintf
69 #endif
70 #ifndef printf_P
71 #define printf_P printf
72 #endif
73 
74 // redefine 8 bit types of inttypes.h until fix of https://github.com/sandeepmistry/arduino-nRF5/issues/197
75 #undef PRId8
76 #undef PRIi8
77 #undef PRIo8
78 #undef PRIu8
79 #undef PRIx8
80 #undef PRIX8
81 #undef PRIdLEAST8
82 #undef PRIiLEAST8
83 #undef PRIoLEAST8
84 #undef PRIuLEAST8
85 #undef PRIxLEAST8
86 #undef PRIXLEAST8
87 #undef PRIdFAST8
88 #undef PRIiFAST8
89 #undef PRIoFAST8
90 #undef PRIuFAST8
91 #undef PRIxFAST8
92 #undef PRIXFAST8
93 #define PRId8 "hd"
94 #define PRIi8 "hi"
95 #define PRIo8 "ho"
96 #define PRIu8 "hu"
97 #define PRIx8 "hx"
98 #define PRIX8 "hX"
99 #define PRIdLEAST8 "hd"
100 #define PRIiLEAST8 "hi"
101 #define PRIoLEAST8 "ho"
102 #define PRIuLEAST8 "hu"
103 #define PRIxLEAST8 "hx"
104 #define PRIXLEAST8 "hX"
105 #define PRIdFAST8 "hd"
106 #define PRIiFAST8 "hi"
107 #define PRIoFAST8 "ho"
108 #define PRIuFAST8 "hu"
109 #define PRIxFAST8 "hx"
110 #define PRIXFAST8 "hX"
111 
112 // Define these as macros to save valuable space
113 #define hwDigitalWrite(__pin, __value) digitalWrite(__pin, __value)
114 #define hwDigitalRead(__pin) digitalRead(__pin)
115 #define hwPinMode(__pin, __value) nrf5_pinMode(__pin, __value)
116 #define hwMillis() millis()
117 // TODO: Can nrf5 determine time slept?
118 #define hwGetSleepRemaining() (0ul)
119 
120 bool hwInit(void);
121 void hwWatchdogReset(void);
122 void hwReboot(void);
123 void hwReadConfigBlock(void *buf, void *addr, size_t length);
124 void hwWriteConfigBlock(void *buf, void *addr, size_t length);
125 void hwWriteConfig(const int addr, uint8_t value);
126 uint8_t hwReadConfig(const int addr);
127 void hwRandomNumberInit(void);
128 ssize_t hwGetentropy(void *__buffer, size_t __length);
129 #define MY_HW_HAS_GETENTROPY
130 
131 // SOFTSPI
132 #ifdef MY_SOFTSPI
133 #error Soft SPI is not available on this architecture!
134 #endif
135 #define hwSPI SPI
136 
137 
142 static __inline__ uint8_t __disableIntsRetVal(void)
143 {
144  __disable_irq();
145  return 1;
146 }
147 
152 static __inline__ void __priMaskRestore(const uint32_t *priMask)
153 {
154  __set_PRIMASK(*priMask);
155 }
156 
161 #if __CORTEX_M == 0x04
162 #define NRF_RESET_EVENT(event) \
163  event = 0; \
164  (void)event
165 #else
166 #define NRF_RESET_EVENT(event) event = 0
167 #endif
168 
174 #ifdef NRF_RTC2
175 #define MY_HW_RTC NRF_RTC2
176 #define MY_HW_RTC_IRQ_HANDLER RTC2_IRQHandler
177 #define MY_HW_RTC_IRQN RTC2_IRQn
178 #else
179 #define MY_HW_RTC NRF_RTC0
180 #define MY_HW_RTC_IRQ_HANDLER RTC0_IRQHandler
181 #define MY_HW_RTC_IRQN RTC0_IRQn
182 #endif
183 
186 typedef struct {
189  uint8_t key[16];
192  uint8_t cleartext[16];
195  uint8_t ciphertext[16];
196 } nrf_ecb_t;
197 
198 #if !defined(DOXYGEN) && !defined(CPPCHECK)
199 #define MY_CRITICAL_SECTION \
200  for (uint32_t __savePriMask \
201  __attribute__((__cleanup__(__priMaskRestore))) = __get_PRIMASK(), \
202  __ToDo = __disableIntsRetVal(); \
203  __ToDo; __ToDo = 0)
204 #else
205 #define MY_CRITICAL_SECTION
206 #endif /* DOXYGEN || CPPCHECK */
207 
208 #endif // #ifndef MyHwNRF5_h
wdt.h
nrf_ecb_t
Definition: MyHwNRF5.h:186