2
0

run_benchmark.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* run_benchmark.c
  2. *
  3. * Copyright (C) 2006-2023 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. #include <stdio.h>
  22. #include "board.h"
  23. #include "fsl_rtc.h"
  24. #include "fsl_trng.h"
  25. #include "FreeRTOS.h"
  26. #include "task.h"
  27. #include "peripherals.h"
  28. #include "pin_mux.h"
  29. #include "clock_config.h"
  30. #include "MIMXRT685S_cm33.h"
  31. #include "fsl_debug_console.h"
  32. #include <wolfssl/wolfcrypt/wc_port.h>
  33. #include "benchmark.h"
  34. #define STACK_DEPTH 60000
  35. /* start the RTC and TRNG */
  36. static void setup()
  37. {
  38. rtc_datetime_t date;
  39. trng_config_t trngConfig;
  40. status_t status;
  41. RTC_Init(RTC);
  42. /* setup a default start date */
  43. date.year = 2022U;
  44. date.month = 8U;
  45. date.day = 17U;
  46. date.hour = 15U;
  47. date.minute = 10;
  48. date.second = 0;
  49. RTC_EnableTimer(RTC, false);
  50. RTC_SetDatetime(RTC, &date);
  51. RTC_EnableTimer(RTC, true);
  52. TRNG_GetDefaultConfig(&trngConfig);
  53. /* Commented in example NXP TRNG as an optional, better random mode */
  54. trngConfig.sampleMode = kTRNG_SampleModeVonNeumann;
  55. /* Initialize TRNG */
  56. status = TRNG_Init(TRNG0, &trngConfig);
  57. if (status != kStatus_Success) {
  58. PRINTF("Issues starting TRNG\n");
  59. }
  60. }
  61. static void doBenchmark(void* params)
  62. {
  63. int ret;
  64. /* initialize wolfCrypt and run tests */
  65. if (wolfCrypt_Init() == 0) {
  66. ret = benchmark_test(NULL);
  67. PRINTF("Return of benchmark_test = %d\r\n", ret);
  68. wolfCrypt_Cleanup();
  69. }
  70. else {
  71. PRINTF("Failed to initialize wolfCrypt\r\n");
  72. }
  73. }
  74. int main(void)
  75. {
  76. TaskHandle_t b = NULL;
  77. /* Init board hardware. */
  78. BOARD_InitBootPins();
  79. BOARD_InitBootClocks();
  80. BOARD_InitBootPeripherals();
  81. #ifndef BOARD_INIT_DEBUG_CONSOLE_PERIPHERAL
  82. /* Init FSL debug console. */
  83. BOARD_InitDebugConsole();
  84. #endif
  85. setup(); /* set the RTC and start the TRNG */
  86. if (xTaskCreate(doBenchmark, "wolfSSL Benchmark", STACK_DEPTH, NULL,
  87. 0, &b) != pdPASS) {
  88. PRINTF("Error creating benchmark task\r\n");
  89. }
  90. vTaskStartScheduler();
  91. TRNG_Deinit(TRNG0);
  92. vTaskDelete(b);
  93. return 0 ;
  94. }