k24f_hal.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #include "k24f_hal.h"
  2. #include <stdio.h>
  3. #include "fsl_uart.h"
  4. #include "fsl_gpio.h"
  5. #include "fsl_port.h"
  6. #include "fsl_clock.h"
  7. #include "clock_config.h"
  8. #include "fsl_mmcau.h"
  9. #include "fsl_rnga.h"
  10. #include <stdint.h>
  11. static uint32_t AES_KEY_SCH[44];
  12. void platform_init(void)
  13. {
  14. BOARD_BootClockRUN();
  15. RNGA_Init(RNG);
  16. RNGA_SetMode(RNG, kRNGA_ModeNormal);
  17. }
  18. void init_uart(void)
  19. {
  20. uart_config_t config;
  21. CLOCK_EnableClock(kCLOCK_PortE); //enable port e clock
  22. CLOCK_EnableClock(kCLOCK_Uart1); //enable UART clock
  23. port_pin_config_t uart_pins = {
  24. .pullSelect = kPORT_PullUp,
  25. .slewRate = kPORT_FastSlewRate,
  26. .passiveFilterEnable = kPORT_PassiveFilterDisable,
  27. .driveStrength = kPORT_LowDriveStrength,
  28. .mux = kPORT_MuxAlt3
  29. };
  30. PORT_SetPinConfig(PORTE, 1, &uart_pins);
  31. PORT_SetPinConfig(PORTE, 0, &uart_pins);
  32. UART_GetDefaultConfig(&config);
  33. config.baudRate_Bps = 38400u;
  34. config.rxFifoWatermark = 0;
  35. config.enableTx = true;
  36. config.enableRx = true;
  37. volatile uint32_t uartclock = CLOCK_GetFreq(UART1_CLK_SRC);
  38. UART_Init(UART1, &config, uartclock);
  39. }
  40. void trigger_setup(void)
  41. {
  42. PORT_SetPinMux(PORTE, 3, kPORT_MuxAsGpio);
  43. gpio_pin_config_t trigconf = {
  44. kGPIO_DigitalOutput, 0
  45. };
  46. GPIO_PinInit(GPIOE, 3, &trigconf);
  47. GPIO_WritePinOutput(GPIOE, 3, 0);
  48. }
  49. void trigger_high(void)
  50. {
  51. GPIO_WritePinOutput(GPIOE, 3, 1);
  52. }
  53. void trigger_low(void)
  54. {
  55. GPIO_WritePinOutput(GPIOE, 3, 0);
  56. }
  57. char getch(void)
  58. {
  59. char c;
  60. UART_ReadBlocking(UART1, &c, 1);
  61. return c;
  62. }
  63. void putch(char c)
  64. {
  65. UART_WriteBlocking(UART1, &c, 1);
  66. }
  67. uint32_t get_rand(void)
  68. {
  69. uint32_t value;
  70. RNGA_GetRandomData(RNG, &value, sizeof(value));
  71. return value;
  72. }
  73. //nothing needed?
  74. void HW_AES128_Init(void)
  75. {
  76. }
  77. void HW_AES128_LoadKey(uint8_t* key)
  78. {
  79. MMCAU_AES_SetKey(key, 16, AES_KEY_SCH);
  80. }
  81. void HW_AES128_Enc(uint8_t* pt)
  82. {
  83. MMCAU_AES_EncryptEcb(pt, AES_KEY_SCH, 10, pt);
  84. }
  85. void HW_AES128_Dec(uint8_t *pt)
  86. {
  87. MMCAU_AES_DecryptEcb(pt, AES_KEY_SCH, 10, pt);
  88. }
  89. void HW_AES128_Enc_pretrigger(uint8_t* pt){;}
  90. void HW_AES128_Enc_posttrigger(uint8_t* pt){;}