iLLD_TC29x  1.0
Ifx_Console.c
Go to the documentation of this file.
1 /**
2  * \file Ifx_Console.c
3  * \brief Main Ifx_Console module implementation file
4  *
5  * \version iLLD_1_0_0_11_0
6  * \copyright Copyright (c) 2013 Infineon Technologies AG. All rights reserved.
7  *
8  *
9  * IMPORTANT NOTICE
10  *
11  *
12  * Infineon Technologies AG (Infineon) is supplying this file for use
13  * exclusively with Infineon's microcontroller products. This file can be freely
14  * distributed within development tools that are supporting such microcontroller
15  * products.
16  *
17  * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
18  * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
19  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
20  * INFINEON SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
21  * OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
22  *
23  */
24 
25 #include <string.h>
26 #include <stdio.h>
27 #include <stdarg.h>
28 
29 #include "Ifx_Console.h"
30 #include "_Utilities/Ifx_Assert.h"
32 
34 
35 /**
36  * \brief Initialize the \ref Ifx_g_console object.
37  * \param standardIo Pointer to the IfxStdIf_DPipe object used by the \ref Ifx_g_console.
38  */
40 {
41  Ifx_g_console.standardIo = standardIo;
42  Ifx_g_console.align = 0;
43 }
44 
45 
46 /**
47  * \brief Print formatted string into \ref Ifx_g_console.
48  * \param format printf-compatible formatted string.
49  * \retval TRUE if the string is printed successfully
50  * \retval FALSE if the function failed.
51  */
52 boolean Ifx_Console_print(pchar format, ...)
53 {
54  if (!Ifx_g_console.standardIo->txDisabled)
55  {
56  char message[STDIF_DPIPE_MAX_PRINT_SIZE + 1];
57  Ifx_SizeT count;
58  va_list args;
59  va_start(args, format);
60  vsprintf((char *)message, format, args);
61  va_end(args);
62  count = (Ifx_SizeT)strlen(message);
64 
65  return IfxStdIf_DPipe_write(Ifx_g_console.standardIo, (void *)message, &count, TIME_INFINITE);
66  }
67  else
68  {
69  return TRUE;
70  }
71 }
72 
73 
74 /**
75  * \brief Print formatted string into \ref Ifx_g_console.
76  * Indented with a number of spaces.
77  * \param format printf-compatible formatted string.
78  * \retval TRUE if the string is printed successfully
79  * \retval FALSE if the function failed.
80  */
81 boolean Ifx_Console_printAlign(pchar format, ...)
82 {
83  if (!Ifx_g_console.standardIo->txDisabled)
84  {
85  char message[STDIF_DPIPE_MAX_PRINT_SIZE + 1];
86  Ifx_SizeT align, count;
87  char spaces[17] = " ";
88  va_list args;
89  va_start(args, format);
90  vsprintf((char *)message, format, args);
91  va_end(args);
92  count = (Ifx_SizeT)strlen(message);
94  align = Ifx_g_console.align;
95 
96  while (align > 0)
97  {
98  Ifx_SizeT scount;
99  scount = __min(align, 10);
100  IfxStdIf_DPipe_write(Ifx_g_console.standardIo, (void *)spaces, &scount, TIME_INFINITE);
101  align = align - scount;
102  }
103 
104  return IfxStdIf_DPipe_write(Ifx_g_console.standardIo, (void *)message, &count, TIME_INFINITE);
105  }
106  else
107  {
108  return TRUE;
109  }
110 }