]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Demo_Projects_Using_FreeRTOS_Simulator/FreeRTOS_Plus_CyaSSL/main.c
Add FreeRTOS-Plus directory.
[freertos] / FreeRTOS-Plus / Demo_Projects_Using_FreeRTOS_Simulator / FreeRTOS_Plus_CyaSSL / main.c
1 /*\r
2     FreeRTOS V7.1.1 - Copyright (C) 2012 Real Time Engineers Ltd.\r
3 \r
4 \r
5     ***************************************************************************\r
6      *                                                                       *\r
7      *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
8      *    Complete, revised, and edited pdf reference manuals are also       *\r
9      *    available.                                                         *\r
10      *                                                                       *\r
11      *    Purchasing FreeRTOS documentation will not only help you, by       *\r
12      *    ensuring you get running as quickly as possible and with an        *\r
13      *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
14      *    the FreeRTOS project to continue with its mission of providing     *\r
15      *    professional grade, cross platform, de facto standard solutions    *\r
16      *    for microcontrollers - completely free of charge!                  *\r
17      *                                                                       *\r
18      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
19      *                                                                       *\r
20      *    Thank you for using FreeRTOS, and thank you for your support!      *\r
21      *                                                                       *\r
22     ***************************************************************************\r
23 \r
24 \r
25     This file is part of the FreeRTOS distribution.\r
26 \r
27     FreeRTOS is free software; you can redistribute it and/or modify it under\r
28     the terms of the GNU General Public License (version 2) as published by the\r
29     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
30     >>>NOTE<<< The modification to the GPL is included to allow you to\r
31     distribute a combined work that includes FreeRTOS without being obliged to\r
32     provide the source code for proprietary components outside of the FreeRTOS\r
33     kernel.  FreeRTOS is distributed in the hope that it will be useful, but\r
34     WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
35     or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
36     more details. You should have received a copy of the GNU General Public\r
37     License and the FreeRTOS license exception along with FreeRTOS; if not it\r
38     can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
39     by writing to Richard Barry, contact details for whom are available on the\r
40     FreeRTOS WEB site.\r
41 \r
42     1 tab == 4 spaces!\r
43     \r
44     ***************************************************************************\r
45      *                                                                       *\r
46      *    Having a problem?  Start by reading the FAQ "My application does   *\r
47      *    not run, what could be wrong?                                      *\r
48      *                                                                       *\r
49      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
50      *                                                                       *\r
51     ***************************************************************************\r
52 \r
53     \r
54     http://www.FreeRTOS.org - Documentation, training, latest information, \r
55     license and contact details.\r
56     \r
57     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
58     including FreeRTOS+Trace - an indispensable productivity tool.\r
59 \r
60     Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell \r
61     the code with commercial support, indemnification, and middleware, under \r
62     the OpenRTOS brand: http://www.OpenRTOS.com.  High Integrity Systems also\r
63     provide a safety engineered and independently SIL3 certified version under \r
64     the SafeRTOS brand: http://www.SafeRTOS.com.\r
65 */\r
66 \r
67 /*\r
68  ******************************************************************************\r
69  * -NOTE- The Win32 port is a simulation (or is that emulation?) only!  Do not\r
70  * expect to get real time behaviour from the Win32 port or this demo\r
71  * application.  It is provided as a convenient development and demonstration\r
72  * test bed only.  This was tested using Windows XP on a dual core laptop.\r
73  *\r
74  * In this example, one simulated millisecond will take approximately 40ms to\r
75  * execute.  See the documentation page for the Windows simulator for an \r
76  * explanation of the slow timing:\r
77  * http://www.freertos.org/FreeRTOS-Windows-Simulator-Emulator-for-Visual-Studio-and-Eclipse-MingW.html\r
78  ******************************************************************************\r
79  *\r
80  * This is a simple FreeRTOS Windows simulator project that makes it easy to \r
81  * evaluate CyaSSL in a FreeRTOS environment on a standard desktop PC, and \r
82  * without any external hardware or interfaces being required.\r
83  *\r
84  * main() creates a TCP server task, which initialises CyaSSL, before creating a\r
85  * TCP client task.  Both the server and client use TLS secured sockets.\r
86  *\r
87  * The client task repeatedly connects to the server, sends 10 messages, then \r
88  * disconnects.  The server task prints the contents of each message to the\r
89  * console as they are received.\r
90  *\r
91  * CyaSSL objects are created and deleted as each socket connects and\r
92  * disconnects respectively.\r
93  *\r
94  * The server task is implemented in SecureTCPServerTask.c, and the client task\r
95  * in SecureTCPClientTask.c.\r
96  *\r
97  * Visit http://www.FreeRTOS.org/ssl for FreeRTOS + CyaSSL for demo \r
98  * documentation.\r
99  *\r
100  */\r
101 \r
102 /* Standard includes. */\r
103 #include <stdio.h>\r
104 #include <stdint.h>\r
105 \r
106 /* FreeRTOS includes. */\r
107 #include <FreeRTOS.h>\r
108 #include "task.h"\r
109 \r
110 /* This application is using the FreeRTOS Windows simulator, which uses the\r
111 FreeRTOS scheduler to schedule FreeRTOS task within the Windows environment.\r
112 The Windows environment must not be allowed to block any Windows threads that\r
113 are running FreeRTOS tasks, unless the FreeRTOS task is running at the FreeRTOS\r
114 idle priority.  For simplicity, this demo uses the Windows TCP/IP stack, the\r
115 API for which can cause Windows threads to block.  Therefore, any FreeRTOS task\r
116 that makes calls to the Windows TCP/IP stack must be assigned the idle priority.\r
117 Note this is only a restriction of the simulated Windows environment - real\r
118 FreeRTOS ports do not have this restriction. */\r
119 #define mainSECURE_SERVER_TASK_PRIORITY         ( tskIDLE_PRIORITY )\r
120 \r
121 \r
122 /*-----------------------------------------------------------*/\r
123 \r
124 /*\r
125  * The task that implements the server side.\r
126  */\r
127 extern void vSecureTCPServerTask( void *pvParameters );\r
128 \r
129 /*-----------------------------------------------------------*/\r
130 \r
131 int main( void )\r
132 {\r
133 const uint32_t ulLongTime_ms = 250UL;\r
134 \r
135         /* Create the TCP server task.  This will itself create the client task\r
136         once it has completed the CyaSSL initialisation. */\r
137         xTaskCreate( vSecureTCPServerTask, ( signed char * ) "Server", configMINIMAL_STACK_SIZE, NULL, mainSECURE_SERVER_TASK_PRIORITY, NULL );\r
138 \r
139         /* Start the task running. */\r
140         vTaskStartScheduler();\r
141 \r
142         /* If all is well, the scheduler will now be running, and the following\r
143         line will never be reached.  If the following line does execute, then\r
144         there was insufficient FreeRTOS heap memory available for the idle and/or\r
145         timer tasks     to be created.  See the memory management section on the\r
146         FreeRTOS web site for more details (this is standard text that is not not \r
147         really applicable to the Win32 simulator port). */\r
148         for( ;; )\r
149         {\r
150                 Sleep( ulLongTime_ms );\r
151         }\r
152 }\r
153 /*-----------------------------------------------------------*/\r
154 \r
155 void vApplicationIdleHook( void )\r
156 {\r
157 const unsigned long ulMSToSleep = 5;\r
158 \r
159         /* This function is called on each cycle of the idle task if\r
160         configUSE_IDLE_HOOK is set to 1 in FreeRTOSConfig.h.  Sleep to reduce CPU \r
161         load. */\r
162         Sleep( ulMSToSleep );\r
163 }\r
164 /*-----------------------------------------------------------*/\r
165 \r
166 void vAssertCalled( void )\r
167 {\r
168 const unsigned long ulLongSleep = 1000UL;\r
169 \r
170         taskDISABLE_INTERRUPTS();\r
171         for( ;; )\r
172         {\r
173                 Sleep( ulLongSleep );\r
174         }\r
175 }\r
176 /*-----------------------------------------------------------*/\r
177 \r