Smart-Home am Beispiel der Präsenzerkennung im Raum Projektarbeit Lennart Heimbs, Johannes Krug, Sebastian Dohle und Kevin Holzschuh bei Prof. Oliver Hofmann SS2019
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MyHwNRF5.h 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 <henrik.ekblad@mysensors.org>
  10. * Copyright (C) 2013-2018 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. #ifdef __cplusplus
  25. #include <Arduino.h>
  26. #endif
  27. #define CRYPTO_LITTLE_ENDIAN
  28. #ifndef MY_SERIALDEVICE
  29. #define MY_SERIALDEVICE Serial
  30. #endif
  31. #ifndef MY_DEBUGDEVICE
  32. #define MY_DEBUGDEVICE MY_SERIALDEVICE
  33. #endif
  34. // Define NRF5_SOFTDEVICE when SoftDevice found
  35. #if defined(S110) || defined(S130) || defined(S132) || defined(S140)
  36. #ifndef SOFTDEVICE_PRESENT
  37. #define SOFTDEVICE_PRESENT
  38. #endif
  39. #endif
  40. // Define ARDUINO_ARCH_NRF5, if not defined
  41. #ifndef ARDUINO_ARCH_NRF5
  42. #define ARDUINO_ARCH_NRF5
  43. #endif
  44. #include "hal/architecture/NRF5/drivers/nrf5_wiring_digital.c"
  45. #include "hal/architecture/NRF5/drivers/wdt.h"
  46. #include "hal/architecture/NRF5/drivers/nrf_temp.h"
  47. #include "drivers/NVM/NVRAM.h"
  48. #include "drivers/NVM/VirtualPage.h"
  49. #include <avr/dtostrf.h>
  50. #include <nrf.h>
  51. // mapping
  52. #ifndef strncpy_P
  53. #define strncpy_P strncpy
  54. #endif
  55. #ifndef snprintf_P
  56. #define snprintf_P(s, f, ...) snprintf((s), (f), __VA_ARGS__)
  57. #endif
  58. #ifndef vsnprintf_P
  59. #define vsnprintf_P vsnprintf
  60. #endif
  61. #ifndef printf_P
  62. #define printf_P printf
  63. #endif
  64. // redefine 8 bit types of inttypes.h until fix of https://github.com/sandeepmistry/arduino-nRF5/issues/197
  65. #undef PRId8
  66. #undef PRIi8
  67. #undef PRIo8
  68. #undef PRIu8
  69. #undef PRIx8
  70. #undef PRIX8
  71. #undef PRIdLEAST8
  72. #undef PRIiLEAST8
  73. #undef PRIoLEAST8
  74. #undef PRIuLEAST8
  75. #undef PRIxLEAST8
  76. #undef PRIXLEAST8
  77. #undef PRIdFAST8
  78. #undef PRIiFAST8
  79. #undef PRIoFAST8
  80. #undef PRIuFAST8
  81. #undef PRIxFAST8
  82. #undef PRIXFAST8
  83. #define PRId8 "hd"
  84. #define PRIi8 "hi"
  85. #define PRIo8 "ho"
  86. #define PRIu8 "hu"
  87. #define PRIx8 "hx"
  88. #define PRIX8 "hX"
  89. #define PRIdLEAST8 "hd"
  90. #define PRIiLEAST8 "hi"
  91. #define PRIoLEAST8 "ho"
  92. #define PRIuLEAST8 "hu"
  93. #define PRIxLEAST8 "hx"
  94. #define PRIXLEAST8 "hX"
  95. #define PRIdFAST8 "hd"
  96. #define PRIiFAST8 "hi"
  97. #define PRIoFAST8 "ho"
  98. #define PRIuFAST8 "hu"
  99. #define PRIxFAST8 "hx"
  100. #define PRIXFAST8 "hX"
  101. // Define these as macros to save valuable space
  102. #define hwDigitalWrite(__pin, __value) digitalWrite(__pin, __value)
  103. #define hwDigitalRead(__pin) digitalRead(__pin)
  104. #define hwPinMode(__pin, __value) nrf5_pinMode(__pin, __value)
  105. #define hwMillis() millis()
  106. bool hwInit(void);
  107. void hwWatchdogReset(void);
  108. void hwReboot(void);
  109. void hwReadConfigBlock(void *buf, void *addr, size_t length);
  110. void hwWriteConfigBlock(void *buf, void *addr, size_t length);
  111. void hwWriteConfig(const int addr, uint8_t value);
  112. uint8_t hwReadConfig(const int addr);
  113. void hwRandomNumberInit(void);
  114. ssize_t hwGetentropy(void *__buffer, size_t __length);
  115. #define MY_HW_HAS_GETENTROPY
  116. /**
  117. * Disable all interrupts.
  118. * Helper function for MY_CRITICAL_SECTION.
  119. */
  120. static __inline__ uint8_t __disableIntsRetVal(void)
  121. {
  122. __disable_irq();
  123. return 1;
  124. }
  125. /**
  126. * Restore priority mask register.
  127. * Helper function for MY_CRITICAL_SECTION.
  128. */
  129. static __inline__ void __priMaskRestore(const uint32_t *priMask)
  130. {
  131. __set_PRIMASK(*priMask);
  132. }
  133. /**
  134. * Reset events and read back on nRF52
  135. * http://infocenter.nordicsemi.com/pdf/nRF52_Series_Migration_v1.0.pdf
  136. */
  137. #if __CORTEX_M == 0x04
  138. #define NRF_RESET_EVENT(event) \
  139. event = 0; \
  140. (void)event
  141. #else
  142. #define NRF_RESET_EVENT(event) event = 0
  143. #endif
  144. /**
  145. * RTC to use for hwSleep
  146. * RTC1 is used by arduino-nRF5
  147. * RTC2 is used on nRF52
  148. * RTC0 is used on nRF51. This conflicts with SoftDevice!
  149. */
  150. #ifdef NRF_RTC2
  151. #define MY_HW_RTC NRF_RTC2
  152. #define MY_HW_RTC_IRQ_HANDLER RTC2_IRQHandler
  153. #define MY_HW_RTC_IRQN RTC2_IRQn
  154. #else
  155. #define MY_HW_RTC NRF_RTC0
  156. #define MY_HW_RTC_IRQ_HANDLER RTC0_IRQHandler
  157. #define MY_HW_RTC_IRQN RTC0_IRQn
  158. #endif
  159. /** Datastructure for AES ECB unit
  160. */
  161. typedef struct {
  162. /** AES Key
  163. */
  164. uint8_t key[16];
  165. /** Unencrypted data
  166. */
  167. uint8_t cleartext[16];
  168. /** Encrypted data
  169. */
  170. uint8_t ciphertext[16];
  171. } nrf_ecb_t;
  172. #if !defined(DOXYGEN) && !defined(CPPCHECK)
  173. #define MY_CRITICAL_SECTION \
  174. for (uint32_t __savePriMask \
  175. __attribute__((__cleanup__(__priMaskRestore))) = __get_PRIMASK(), \
  176. __ToDo = __disableIntsRetVal(); \
  177. __ToDo; __ToDo = 0)
  178. #else
  179. #define MY_CRITICAL_SECTION
  180. #endif /* DOXYGEN || CPPCHECK */
  181. #endif // #ifndef MyHwNRF5_h