main.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /* main.c
  2. *
  3. * Copyright (C) 2006-2024 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. #ifdef HAVE_CONFIG_H
  22. #include <config.h>
  23. #endif
  24. #include <wolfssl/wolfcrypt/settings.h>
  25. #include "wolfcrypt/test/test.h"
  26. #include <stdio.h>
  27. #include <time.h>
  28. #if defined(WOLFSSL_CMSIS_RTOS)
  29. #include "cmsis_os.h"
  30. #elif defined(WOLFSSL_CMSIS_RTOSv2)
  31. #include "cmsis_os2.h"
  32. #endif
  33. /* Dummy definition for test RTC */
  34. #define RTC_YEAR 2023
  35. #define RTC_MONTH 1
  36. #define RTC_DAY 1
  37. #define RTC_MONTH 1
  38. #define RTC_DAY 1
  39. #if defined(STM32F7xx)
  40. #include "stm32f7xx_hal.h"
  41. #elif defined(STM32F4xx)
  42. #include "stm32f4xx_hal.h"
  43. #elif defined(STM32F2xx)
  44. #include "stm32f2xx_hal.h"
  45. #endif
  46. #warning "write MPU specific Set ups\n"
  47. static void SystemClock_Config (void) {
  48. }
  49. static void MPU_Config (void) {
  50. }
  51. static void CPU_CACHE_Enable (void) {
  52. }
  53. #if defined(WOLFSSL_CMSIS_RTOS) || defined(WOLFSSL_CMSIS_RTOSv2)
  54. #if defined(WOLFSSL_CMSIS_RTOS)
  55. extern uint32_t os_time;
  56. #endif
  57. uint32_t HAL_GetTick(void)
  58. {
  59. #if defined(WOLFSSL_CMSIS_RTOS)
  60. return os_time;
  61. #elif defined(WOLFSSL_CMSIS_RTOSv2)
  62. return osKernelGetTickCount();
  63. #endif
  64. }
  65. double current_time(int reset)
  66. {
  67. if (reset)
  68. return 0;
  69. #if defined(WOLFSSL_CMSIS_RTOS)
  70. return (double)os_time / 1000.0;
  71. #elif defined(WOLFSSL_CMSIS_RTOSv2)
  72. return (double)osKernelGetTickCount() / 1000.0;
  73. #endif
  74. }
  75. #else
  76. #include <stdint.h>
  77. #define DWT ((DWT_Type *) (0xE0001000UL) )
  78. typedef struct
  79. {
  80. uint32_t CTRL; /*!< Offset: 0x000 (R/W) Control Register */
  81. uint32_t CYCCNT; /*!< Offset: 0x004 (R/W) Cycle Count Register */
  82. } DWT_Type;
  83. extern uint32_t SystemCoreClock;
  84. double current_time(int reset)
  85. {
  86. if (reset) DWT->CYCCNT = 0;
  87. return ((double)DWT->CYCCNT/SystemCoreClock);
  88. }
  89. #endif
  90. static time_t epochTime;
  91. time_t time(time_t *t)
  92. {
  93. return epochTime;
  94. }
  95. void setTime(time_t t)
  96. {
  97. epochTime = t;
  98. }
  99. /*-----------------------------------------------------------------------------
  100. * Initialize a Flash Memory Card
  101. *----------------------------------------------------------------------------*/
  102. #if !defined(NO_FILESYSTEM)
  103. #include "rl_fs.h" /* FileSystem definitions */
  104. static void init_filesystem(void)
  105. {
  106. int32_t retv;
  107. retv = finit ("M0:");
  108. if (retv == fsOK) {
  109. retv = fmount ("M0:");
  110. if (retv == fsOK) {
  111. printf ("Drive M0 ready!\n");
  112. }
  113. else {
  114. printf ("Drive M0 mount failed(%d)!\n", retv);
  115. }
  116. }
  117. else {
  118. printf ("Drive M0 initialization failed!\n");
  119. }
  120. }
  121. #endif
  122. /*-----------------------------------------------------------------------------
  123. * main entry
  124. *----------------------------------------------------------------------------*/
  125. void benchmark_test(void *arg);
  126. int main()
  127. {
  128. void * arg = NULL;
  129. MPU_Config();
  130. CPU_CACHE_Enable();
  131. HAL_Init(); /* Initialize the HAL Library */
  132. SystemClock_Config(); /* Configure the System Clock */
  133. #if !defined(NO_FILESYSTEM)
  134. init_filesystem ();
  135. #endif
  136. setTime((RTC_YEAR-1970)*365*24*60*60 +
  137. RTC_MONTH*30*24*60*60 +
  138. RTC_DAY*24*60*60);
  139. printf("=== Start: Crypt Benchmark ===\n");
  140. benchmark_test(arg);
  141. printf("=== End: Crypt Benchmark ===\n");
  142. return 0;
  143. }