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