1 |
/* |
---|
2 |
FreeRTOS V5.4.1 - Copyright (C) 2009 Real Time Engineers Ltd. |
---|
3 |
|
---|
4 |
This file is part of the FreeRTOS distribution. |
---|
5 |
|
---|
6 |
FreeRTOS is free software; you can redistribute it and/or modify it under |
---|
7 |
the terms of the GNU General Public License (version 2) as published by the |
---|
8 |
Free Software Foundation and modified by the FreeRTOS exception. |
---|
9 |
**NOTE** The exception to the GPL is included to allow you to distribute a |
---|
10 |
combined work that includes FreeRTOS without being obliged to provide the |
---|
11 |
source code for proprietary components outside of the FreeRTOS kernel. |
---|
12 |
Alternative commercial license and support terms are also available upon |
---|
13 |
request. See the licensing section of http://www.FreeRTOS.org for full |
---|
14 |
license details. |
---|
15 |
|
---|
16 |
FreeRTOS is distributed in the hope that it will be useful, but WITHOUT |
---|
17 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
18 |
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
---|
19 |
more details. |
---|
20 |
|
---|
21 |
You should have received a copy of the GNU General Public License along |
---|
22 |
with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59 |
---|
23 |
Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
---|
24 |
|
---|
25 |
|
---|
26 |
*************************************************************************** |
---|
27 |
* * |
---|
28 |
* Looking for a quick start? Then check out the FreeRTOS eBook! * |
---|
29 |
* See http://www.FreeRTOS.org/Documentation for details * |
---|
30 |
* * |
---|
31 |
*************************************************************************** |
---|
32 |
|
---|
33 |
1 tab == 4 spaces! |
---|
34 |
|
---|
35 |
Please ensure to read the configuration and relevant port sections of the |
---|
36 |
online documentation. |
---|
37 |
|
---|
38 |
http://www.FreeRTOS.org - Documentation, latest information, license and |
---|
39 |
contact details. |
---|
40 |
|
---|
41 |
http://www.SafeRTOS.com - A version that is certified for use in safety |
---|
42 |
critical systems. |
---|
43 |
|
---|
44 |
http://www.OpenRTOS.com - Commercial support, development, porting, |
---|
45 |
licensing and training services. |
---|
46 |
*/ |
---|
47 |
|
---|
48 |
/** |
---|
49 |
* Manages a queue of strings that are waiting to be displayed. This is used to |
---|
50 |
* ensure mutual exclusion of console output. |
---|
51 |
* |
---|
52 |
* A task wishing to display a message will call vPrintDisplayMessage (), with a |
---|
53 |
* pointer to the string as the parameter. The pointer is posted onto the |
---|
54 |
* xPrintQueue queue. |
---|
55 |
* |
---|
56 |
* The task spawned in main. c blocks on xPrintQueue. When a message becomes |
---|
57 |
* available it calls pcPrintGetNextMessage () to obtain a pointer to the next |
---|
58 |
* string, then uses the functions defined in the portable layer FileIO. c to |
---|
59 |
* display the message. |
---|
60 |
* |
---|
61 |
* <b>NOTE:</b> |
---|
62 |
* Using console IO can disrupt real time performance - depending on the port. |
---|
63 |
* Standard C IO routines are not designed for real time applications. While |
---|
64 |
* standard IO is useful for demonstration and debugging an alternative method |
---|
65 |
* should be used if you actually require console IO as part of your application. |
---|
66 |
* |
---|
67 |
* \page PrintC print.c |
---|
68 |
* \ingroup DemoFiles |
---|
69 |
* <HR> |
---|
70 |
*/ |
---|
71 |
|
---|
72 |
/* |
---|
73 |
Changes from V2.0.0 |
---|
74 |
|
---|
75 |
+ Delay periods are now specified using variables and constants of |
---|
76 |
portTickType rather than unsigned portLONG. |
---|
77 |
*/ |
---|
78 |
|
---|
79 |
#include <stdlib.h> |
---|
80 |
|
---|
81 |
/* Scheduler include files. */ |
---|
82 |
#include "FreeRTOS.h" |
---|
83 |
#include "queue.h" |
---|
84 |
|
---|
85 |
/* Demo program include files. */ |
---|
86 |
#include "print.h" |
---|
87 |
|
---|
88 |
static xQueueHandle xPrintQueue; |
---|
89 |
|
---|
90 |
/*-----------------------------------------------------------*/ |
---|
91 |
|
---|
92 |
void vPrintInitialise( void ) |
---|
93 |
{ |
---|
94 |
const unsigned portBASE_TYPE uxQueueSize = 20; |
---|
95 |
|
---|
96 |
/* Create the queue on which errors will be reported. */ |
---|
97 |
xPrintQueue = xQueueCreate( uxQueueSize, ( unsigned portBASE_TYPE ) sizeof( portCHAR * ) ); |
---|
98 |
} |
---|
99 |
/*-----------------------------------------------------------*/ |
---|
100 |
|
---|
101 |
void vPrintDisplayMessage( const portCHAR * const * ppcMessageToSend ) |
---|
102 |
{ |
---|
103 |
#ifdef USE_STDIO |
---|
104 |
xQueueSend( xPrintQueue, ( void * ) ppcMessageToSend, ( portTickType ) 0 ); |
---|
105 |
#else |
---|
106 |
/* Stop warnings. */ |
---|
107 |
( void ) ppcMessageToSend; |
---|
108 |
#endif |
---|
109 |
} |
---|
110 |
/*-----------------------------------------------------------*/ |
---|
111 |
|
---|
112 |
const portCHAR *pcPrintGetNextMessage( portTickType xPrintRate ) |
---|
113 |
{ |
---|
114 |
portCHAR *pcMessage; |
---|
115 |
|
---|
116 |
if( xQueueReceive( xPrintQueue, &pcMessage, xPrintRate ) == pdPASS ) |
---|
117 |
{ |
---|
118 |
return pcMessage; |
---|
119 |
} |
---|
120 |
else |
---|
121 |
{ |
---|
122 |
return NULL; |
---|
123 |
} |
---|
124 |
} |
---|
125 |
|
---|
126 |
|
---|