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