main.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* main.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. #ifdef HAVE_CONFIG_H
  22. #include <config.h>
  23. #endif
  24. #include <wolfssl/wolfcrypt/settings.h>
  25. #include <stdio.h>
  26. #include <time.h>
  27. #if defined(WOLFSSL_CMSIS_RTOS)
  28. #include "cmsis_os.h"
  29. #elif defined(WOLFSSL_CMSIS_RTOSv2)
  30. #include "cmsis_os2.h"
  31. #endif
  32. /* Dummy definition for test RTC */
  33. #define RTC_YEAR 2023
  34. #define RTC_MONTH 1
  35. #define RTC_DAY 1
  36. #if defined(STM32F7xx)
  37. #include "stm32f7xx_hal.h"
  38. #elif defined(STM32F4xx)
  39. #include "stm32f4xx_hal.h"
  40. #elif defined(STM32F2xx)
  41. #include "stm32f2xx_hal.h"
  42. #endif
  43. #warning "write MPU specific Set ups\n"
  44. static void SystemClock_Config (void) {
  45. }
  46. static void MPU_Config (void) {
  47. }
  48. static void CPU_CACHE_Enable (void) {
  49. }
  50. #if defined(WOLFSSL_CMSIS_RTOS)
  51. extern uint32_t os_time;
  52. #endif
  53. uint32_t HAL_GetTick(void) {
  54. #if defined(WOLFSSL_CMSIS_RTOS)
  55. return os_time;
  56. #elif defined(WOLFSSL_CMSIS_RTOSv2)
  57. return osKernelGetTickCount();
  58. #endif
  59. }
  60. static time_t epochTime;
  61. time_t time(time_t *t) {
  62. return epochTime;
  63. }
  64. void setTime(time_t t) {
  65. epochTime = t;
  66. }
  67. /*-----------------------------------------------------------------------------
  68. * Initialize a Flash Memory Card
  69. *----------------------------------------------------------------------------*/
  70. #if !defined(NO_FILESYSTEM)
  71. #include "rl_fs.h" /* FileSystem definitions */
  72. static void init_filesystem(void)
  73. {
  74. int32_t retv;
  75. retv = finit ("M0:");
  76. if (retv == fsOK) {
  77. retv = fmount ("M0:");
  78. if (retv == fsOK) {
  79. printf ("Drive M0 ready!\n");
  80. }
  81. else {
  82. printf ("Drive M0 mount failed(%d)!\n", retv);
  83. }
  84. }
  85. else {
  86. printf ("Drive M0 initialization failed!\n");
  87. }
  88. }
  89. #endif
  90. /*-----------------------------------------------------------------------------
  91. * main entry
  92. *----------------------------------------------------------------------------*/
  93. void wolfcrypt_test(void *arg);
  94. int main()
  95. {
  96. void * arg = NULL;
  97. MPU_Config();
  98. CPU_CACHE_Enable();
  99. HAL_Init(); /* Initialize the HAL Library */
  100. SystemClock_Config(); /* Configure the System Clock */
  101. #if !defined(NO_FILESYSTEM)
  102. init_filesystem ();
  103. #endif
  104. setTime((RTC_YEAR-1970)*365*24*60*60 +
  105. RTC_MONTH*30*24*60*60 +
  106. RTC_DAY*24*60*60);
  107. printf("=== Start: Crypt test === \n");
  108. wolfcrypt_test(arg);
  109. printf("=== End: Crypt test ===\n");
  110. return 0;
  111. }