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
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <wolfssl/wolfcrypt/visibility.h>
28 #include <wolfssl/wolfcrypt/logging.h>
29
30 #include <RTL.h>
31 #include <stdio.h>
32 #include "wolfssl_MDK_ARM.h"
33
34 /*-----------------------------------------------------------------------------
35 * Initialize a Flash Memory Card
36 *----------------------------------------------------------------------------*/
37 #if !defined(NO_FILESYSTEM)
init_card(void)38 static void init_card (void)
39 {
40 U32 retv;
41
42 while ((retv = finit (NULL)) != 0) { /* Wait until the Card is ready */
43 if (retv == 1) {
44 printf ("\nSD/MMC Init Failed");
45 printf ("\nInsert Memory card and press key...\n");
46 } else {
47 printf ("\nSD/MMC Card is Unformatted");
48 }
49 }
50 }
51 #endif
52
53
54 /*-----------------------------------------------------------------------------
55 * TCP/IP tasks
56 *----------------------------------------------------------------------------*/
57 #ifdef WOLFSSL_KEIL_TCP_NET
tcp_tick(void)58 __task void tcp_tick (void)
59 {
60
61 WOLFSSL_MSG("Time tick started.") ;
62 #if defined (HAVE_KEIL_RTX)
63 os_itv_set (10);
64 #endif
65
66 while (1) {
67 #if defined (HAVE_KEIL_RTX)
68 os_itv_wait ();
69 #endif
70 /* Timer tick every 100 ms */
71 timer_tick ();
72 }
73 }
74
tcp_poll(void)75 __task void tcp_poll (void)
76 {
77 WOLFSSL_MSG("TCP polling started.") ;
78 while (1) {
79 main_TcpNet ();
80 #if defined (HAVE_KEIL_RTX)
81 os_tsk_pass ();
82 #endif
83 }
84 }
85 #endif
86
87 #if defined(HAVE_KEIL_RTX) && defined(WOLFSSL_MDK_SHELL)
88 #define SHELL_STACKSIZE 1000
89 static unsigned char Shell_stack[SHELL_STACKSIZE] ;
90 #endif
91
92
93 #if defined(WOLFSSL_MDK_SHELL)
94 extern void shell_main(void) ;
95 #endif
96
97 extern void time_main(int) ;
98 extern void benchmark_test(void) ;
99 extern void SER_Init(void) ;
100
101 /*-----------------------------------------------------------------------------
102 * mian entry
103 *----------------------------------------------------------------------------*/
104
105 /*** This is the parent task entry ***/
main_task(void)106 void main_task (void)
107 {
108 #ifdef WOLFSSL_KEIL_TCP_NET
109 init_TcpNet ();
110
111 os_tsk_create (tcp_tick, 2);
112 os_tsk_create (tcp_poll, 1);
113 #endif
114
115 #ifdef WOLFSSL_MDK_SHELL
116 #ifdef HAVE_KEIL_RTX
117 os_tsk_create_user(shell_main, 1, Shell_stack, SHELL_STACKSIZE) ;
118 #else
119 shell_main() ;
120 #endif
121 #else
122
123 /************************************/
124 /*** USER APPLICATION HERE ***/
125 /************************************/
126 printf("USER LOGIC STARTED\n") ;
127
128 #endif
129
130 #ifdef HAVE_KEIL_RTX
131 WOLFSSL_MSG("Terminating tcp_main") ;
132 os_tsk_delete_self ();
133 #endif
134
135 }
136
137
138 int myoptind = 0;
139 char* myoptarg = NULL;
140
141 #if defined(DEBUG_WOLFSSL)
142 extern void wolfSSL_Debugging_ON(void) ;
143 #endif
144
145
146 /*** main entry ***/
147 extern void SystemInit(void);
148
main()149 int main() {
150
151 SystemInit();
152 #if !defined(NO_FILESYSTEM)
153 init_card () ; /* initializing SD card */
154 #endif
155
156 #if defined(DEBUG_WOLFSSL)
157 printf("Turning ON Debug message\n") ;
158 wolfSSL_Debugging_ON() ;
159 #endif
160
161 #ifdef HAVE_KEIL_RTX
162 os_sys_init (main_task) ;
163 #else
164 main_task() ;
165 #endif
166
167 return 0 ; /* There should be no return here */
168
169 }
170