xmega_hal.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. #include "hal.h"
  16. #include "xmega_hal.h"
  17. void platform_init(void)
  18. {
  19. OSC.XOSCCTRL = 0x00;
  20. OSC.PLLCTRL = 0x00;
  21. OSC.CTRL |= OSC_XOSCEN_bm;
  22. //wait for clock
  23. while((OSC.STATUS & OSC_XOSCRDY_bm) == 0);
  24. //Switch clock source
  25. CCP = CCP_IOREG_gc;
  26. CLK.CTRL = CLK_SCLKSEL_XOSC_gc;
  27. //Turn off other sources besides external
  28. OSC.CTRL = OSC_XOSCEN_bm;
  29. #if PLATFORM == CW303
  30. PORTA.DIRSET = PIN5_bm | PIN6_bm;
  31. PORTA.OUTSET = PIN5_bm | PIN6_bm;
  32. #endif
  33. }
  34. #if HWCRYPTO
  35. #include "XMEGA_AES_driver.h"
  36. static uint8_t enckey[16];
  37. void HW_AES128_Init(void)
  38. {
  39. return;
  40. }
  41. void HW_AES128_LoadKey(uint8_t * key)
  42. {
  43. for(uint8_t i=0; i < 16; i++){
  44. enckey[i] = key[i];
  45. }
  46. }
  47. void HW_AES128_Enc(uint8_t * pt)
  48. {
  49. AES_encrypt(pt, pt, enckey);
  50. }
  51. #endif