]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/Common/Full/print.c
Fix some build issues in older kernel demo projects.
[freertos] / FreeRTOS / Demo / Common / Full / print.c
1 /*\r
2  * FreeRTOS Kernel V10.1.0\r
3  * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
6  * this software and associated documentation files (the "Software"), to deal in\r
7  * the Software without restriction, including without limitation the rights to\r
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
9  * the Software, and to permit persons to whom the Software is furnished to do so,\r
10  * subject to the following conditions:\r
11  *\r
12  * The above copyright notice and this permission notice shall be included in all\r
13  * copies or substantial portions of the Software.\r
14  *\r
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 /**\r
29  * Manages a queue of strings that are waiting to be displayed.  This is used to \r
30  * ensure mutual exclusion of console output.\r
31  *\r
32  * A task wishing to display a message will call vPrintDisplayMessage (), with a \r
33  * pointer to the string as the parameter. The pointer is posted onto the \r
34  * xPrintQueue queue.\r
35  *\r
36  * The task spawned in main. c blocks on xPrintQueue.  When a message becomes \r
37  * available it calls pcPrintGetNextMessage () to obtain a pointer to the next \r
38  * string, then uses the functions defined in the portable layer FileIO. c to \r
39  * display the message.\r
40  *\r
41  * <b>NOTE:</b>\r
42  * Using console IO can disrupt real time performance - depending on the port.  \r
43  * Standard C IO routines are not designed for real time applications.  While \r
44  * standard IO is useful for demonstration and debugging an alternative method \r
45  * should be used if you actually require console IO as part of your application.\r
46  *\r
47  * \page PrintC print.c\r
48  * \ingroup DemoFiles\r
49  * <HR>\r
50  */\r
51 \r
52 /*\r
53 Changes from V2.0.0\r
54 \r
55         + Delay periods are now specified using variables and constants of\r
56           TickType_t rather than unsigned long.\r
57 */\r
58 \r
59 #include <stdlib.h>\r
60 \r
61 /* Scheduler include files. */\r
62 #include "FreeRTOS.h"\r
63 #include "queue.h"\r
64 \r
65 /* Demo program include files. */\r
66 #include "print.h"\r
67 \r
68 static QueueHandle_t xPrintQueue;\r
69 \r
70 /*-----------------------------------------------------------*/\r
71 \r
72 void vPrintInitialise( void )\r
73 {\r
74 const unsigned portBASE_TYPE uxQueueSize = 20;\r
75 \r
76         /* Create the queue on which errors will be reported. */\r
77         xPrintQueue = xQueueCreate( uxQueueSize, ( unsigned portBASE_TYPE ) sizeof( char * ) );\r
78 }\r
79 /*-----------------------------------------------------------*/\r
80 \r
81 void vPrintDisplayMessage( const char * const * ppcMessageToSend )\r
82 {\r
83         #ifdef USE_STDIO\r
84                 xQueueSend( xPrintQueue, ( void * ) ppcMessageToSend, ( TickType_t ) 0 );\r
85         #else\r
86         /* Stop warnings. */\r
87                 ( void ) ppcMessageToSend;\r
88         #endif\r
89 }\r
90 /*-----------------------------------------------------------*/\r
91 \r
92 const char *pcPrintGetNextMessage( TickType_t xPrintRate )\r
93 {\r
94 char *pcMessage;\r
95 \r
96         if( xQueueReceive( xPrintQueue, &pcMessage, xPrintRate ) == pdPASS )\r
97         {\r
98                 return pcMessage;\r
99         }\r
100         else\r
101         {\r
102                 return NULL;\r
103         }\r
104 }\r
105 \r
106 \r