hal.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. This file is part of the ChipWhisperer Example Targets
  3. Copyright (C) 2012-2015 NewAE Technology Inc.
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #ifndef HAL_H_
  16. #define HAL_H_
  17. #include <stdint.h>
  18. void platform_init(void);
  19. //PLATFORM Define Types
  20. #define CW301_AVR 1
  21. #define CW301_XMEGA 2
  22. #define CW303 3
  23. #define CW304 4
  24. #define CW308_MEGARF 8
  25. #define CW308_PIC24FJ 10
  26. #define CW308_SAM4L 11
  27. #define CW308_SI4010 12
  28. #define CW308_MPC5748G 13
  29. #define CW308_STM32F0 14
  30. #define CW308_STM32F1 15
  31. #define CW308_STM32F2 16
  32. #define CW308_STM32F3 17
  33. #define CW308_STM32F4 18
  34. #define CW308_CC2538 19
  35. #define CW308_K24F 20
  36. #define CW308_NRF52840 21
  37. #define CW308_AURIX 22
  38. #define CW308_SAML11 23
  39. #define CW308_EFM32TG11B 24
  40. #define CW308_K82F 25
  41. #define CW308_LPC55S6X 26
  42. #define CW308_PSOC62 27
  43. #define CW308_IMXRT1062 28
  44. #define CW308_FE310 29
  45. #define CW308_EFR32MG21A 30
  46. #define CW308_EFM32GG11 31
  47. #define CW308_STM32L5 32
  48. #define CW308_STM32L4 33
  49. #define CW308_RX65N 34
  50. #define CW308_MPC5676R 35
  51. //HAL_TYPE Define Types
  52. #define HAL_avr 1
  53. #define HAL_xmega 2
  54. #define HAL_pic24f 3
  55. #define HAL_sam4l 4
  56. #define HAL_stm32f0 5
  57. #define HAL_stm32f1 6
  58. #define HAL_stm32f2 7
  59. #define HAL_stm32f3 8
  60. #define HAL_stm32f4 9
  61. #define HAL_cc2538 10
  62. #define HAL_k24f 11
  63. #define HAL_nrf52840 12
  64. #define HAL_stm32f0_nano 13
  65. #define HAL_aurix 14
  66. #define HAL_saml11 15
  67. #define HAL_efm32tg11b 16
  68. #define HAL_k82f 17
  69. #define HAL_lpc55s6x 18
  70. #define HAL_psoc62 19
  71. #define HAL_imxrt1062 20
  72. #define HAL_fe310 21
  73. #define HAL_efr32mg21a 22
  74. #define HAL_efm32gg11 23
  75. #define HAL_stm32l5 24
  76. #define HAL_stm32l4 25
  77. #define HAL_rx65n 26
  78. #define HAL_mpc5676r 27
  79. #if HAL_TYPE == HAL_avr
  80. #include <avr/io.h>
  81. #include <util/delay.h>
  82. #include "avr/avr_hal.h"
  83. #elif HAL_TYPE == HAL_xmega
  84. #include <avr/io.h>
  85. #include <util/delay.h>
  86. #include "xmega/xmega_hal.h"
  87. #include "xmega/avr_compiler.h"
  88. #elif HAL_TYPE == HAL_pic24f
  89. #include <xc.h>
  90. #include "pic24f/pic24f_hal.h"
  91. #include "pic24f/uart.h"
  92. #elif HAL_TYPE == HAL_sam4l
  93. #include "sam4l/sam4l_hal.h"
  94. #elif HAL_TYPE == HAL_stm32f0
  95. #include "stm32f0/stm32f0_hal.h"
  96. #elif HAL_TYPE == HAL_stm32f1
  97. #include "stm32f1/stm32f1_hal.h"
  98. #elif HAL_TYPE == HAL_stm32f2
  99. #include "stm32f2/stm32f2_hal.h"
  100. #elif HAL_TYPE == HAL_stm32f3
  101. #include "stm32f3/stm32f3_hal.h"
  102. #ifdef SECCAN
  103. #include "stm32f3/stm32f3_hal_seccan.h"
  104. #endif
  105. #elif HAL_TYPE == HAL_stm32f4
  106. #include "stm32f4/stm32f4_hal.h"
  107. #elif HAL_TYPE == HAL_cc2538
  108. #include "cc2538/cc2538_hal.h"
  109. #elif HAL_TYPE == HAL_k24f
  110. #include "k24f/k24f_hal.h"
  111. #elif HAL_TYPE == HAL_k82f
  112. #include "k82f/k82f_hal.h"
  113. #elif HAL_TYPE == HAL_nrf52840
  114. #include "nrf52840/nrf52840_hal.h"
  115. #elif HAL_TYPE == HAL_stm32f0_nano
  116. #include "stm32f0/stm32f0_hal.h"
  117. #elif HAL_TYPE == HAL_aurix
  118. #include "aurix/aurix_hal.h"
  119. #elif HAL_TYPE == HAL_saml11
  120. #include "saml11/saml11_hal.h"
  121. #elif HAL_TYPE == HAL_efm32tg11b
  122. #include "efm32tg11b/efm32tg11b_hal.h"
  123. #elif HAL_TYPE == HAL_lpc55s6x
  124. #include "lpc55s6x/lpc55s6x_hal.h"
  125. #elif HAL_TYPE == HAL_psoc62
  126. #include "psoc62/psoc62_hal.h"
  127. #elif HAL_TYPE == HAL_imxrt1062
  128. #include "imxrt1062/imxrt1062_hal.h"
  129. #elif HAL_TYPE == HAL_fe310
  130. #include "fe310/fe310_hal.h"
  131. #elif HAL_TYPE == HAL_efr32mg21a
  132. #include "efr32mg21a/efr32mg21a_hal.h"
  133. #elif HAL_TYPE == HAL_efm32gg11
  134. #include "efm32gg11/efm32gg11_hal.h"
  135. #elif HAL_TYPE == HAL_stm32l5
  136. #include "stm32l5/stm32l5_hal.h"
  137. #elif HAL_TYPE == HAL_stm32l4
  138. #include "stm32l4/stm32l4_hal.h"
  139. #elif HAL_TYPE == HAL_rx65n
  140. #include "rx65n/rx65n_hal.h"
  141. #elif HAL_TYPE == HAL_mpc5676r
  142. #include "mpc5676r/MPC5676R_hal.h"
  143. #else
  144. #error "Unsupported HAL Type"
  145. #endif
  146. #if PLATFORM == CW308_MEGARF
  147. #undef trigger_setup
  148. #undef trigger_high
  149. #undef trigger_low
  150. #define trigger_setup() DDRD |= 0x02
  151. #define trigger_high() PORTD |= 0x02
  152. #define trigger_low() PORTD &= ~(0x02)
  153. #define HW_AES128_Init(); AES_CTRL = 0x00;
  154. #define HW_AES128_LoadKey(key); for (uint8_t i = 0; i < 16; i++){ \
  155. AES_KEY = *(key+i); \
  156. }
  157. #define HW_AES128_Enc(pt); for (uint8_t i = 0; i < 16; i++){ \
  158. AES_STATE = *(pt+i); \
  159. } \
  160. \
  161. AES_CTRL |= 1<<AES_REQUEST; \
  162. \
  163. /*Wait for done */ \
  164. while ((AES_STATUS & (1<<AES_DONE)) == 0){ \
  165. ; \
  166. } \
  167. \
  168. for (uint8_t i = 0; i < 16; i++){ \
  169. *(pt+i) = AES_STATE; \
  170. }
  171. #endif
  172. #ifndef led_error
  173. #define led_error(a)
  174. #endif
  175. #ifndef led_ok
  176. #define led_ok(a)
  177. #endif
  178. #endif //HAL_H_