1 /*
2  * Copyright 2017 NXP
3  * All rights reserved.
4  *
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  *
8  */
9 
10 #ifndef _FSL_STR_H
11 #define _FSL_STR_H
12 
13 #include "fsl_common.h"
14 
15 /*!
16  * @addtogroup debugconsole
17  * @{
18  */
19 
20 /*******************************************************************************
21  * Definitions
22  ******************************************************************************/
23 
24 /*! @brief Definition to printf the float number. */
25 #ifndef PRINTF_FLOAT_ENABLE
26 #define PRINTF_FLOAT_ENABLE 0U
27 #endif /* PRINTF_FLOAT_ENABLE */
28 
29 /*! @brief Definition to scanf the float number. */
30 #ifndef SCANF_FLOAT_ENABLE
31 #define SCANF_FLOAT_ENABLE 0U
32 #endif /* SCANF_FLOAT_ENABLE */
33 
34 /*! @brief Definition to support advanced format specifier for printf. */
35 #ifndef PRINTF_ADVANCED_ENABLE
36 #define PRINTF_ADVANCED_ENABLE 0U
37 #endif /* PRINTF_ADVANCED_ENABLE */
38 
39 /*! @brief Definition to support advanced format specifier for scanf. */
40 #ifndef SCANF_ADVANCED_ENABLE
41 #define SCANF_ADVANCED_ENABLE 0U
42 #endif /* SCANF_ADVANCED_ENABLE */
43 
44 /*******************************************************************************
45  * Prototypes
46  ******************************************************************************/
47 #if (defined(PRINTF_ADVANCED_ENABLE) && (PRINTF_ADVANCED_ENABLE > 0U))
48 /*! @brief Specification modifier flags for printf. */
49 enum _debugconsole_printf_flag
50 {
51     kPRINTF_Minus             = 0x01U,  /*!< Minus FLag. */
52     kPRINTF_Plus              = 0x02U,  /*!< Plus Flag. */
53     kPRINTF_Space             = 0x04U,  /*!< Space Flag. */
54     kPRINTF_Zero              = 0x08U,  /*!< Zero Flag. */
55     kPRINTF_Pound             = 0x10U,  /*!< Pound Flag. */
56     kPRINTF_LengthChar        = 0x20U,  /*!< Length: Char Flag. */
57     kPRINTF_LengthShortInt    = 0x40U,  /*!< Length: Short Int Flag. */
58     kPRINTF_LengthLongInt     = 0x80U,  /*!< Length: Long Int Flag. */
59     kPRINTF_LengthLongLongInt = 0x100U, /*!< Length: Long Long Int Flag. */
60 };
61 #endif /* PRINTF_ADVANCED_ENABLE */
62 
63 /*! @brief Specification modifier flags for scanf. */
64 enum _debugconsole_scanf_flag
65 {
66     kSCANF_Suppress   = 0x2U,    /*!< Suppress Flag. */
67     kSCANF_DestMask   = 0x7cU,   /*!< Destination Mask. */
68     kSCANF_DestChar   = 0x4U,    /*!< Destination Char Flag. */
69     kSCANF_DestString = 0x8U,    /*!< Destination String FLag. */
70     kSCANF_DestSet    = 0x10U,   /*!< Destination Set Flag. */
71     kSCANF_DestInt    = 0x20U,   /*!< Destination Int Flag. */
72     kSCANF_DestFloat  = 0x30U,   /*!< Destination Float Flag. */
73     kSCANF_LengthMask = 0x1f00U, /*!< Length Mask Flag. */
74 #if (defined(SCANF_ADVANCED_ENABLE) && (SCANF_ADVANCED_ENABLE > 0U))
75     kSCANF_LengthChar        = 0x100U, /*!< Length Char Flag. */
76     kSCANF_LengthShortInt    = 0x200U, /*!< Length ShortInt Flag. */
77     kSCANF_LengthLongInt     = 0x400U, /*!< Length LongInt Flag. */
78     kSCANF_LengthLongLongInt = 0x800U, /*!< Length LongLongInt Flag. */
79 #endif                                 /* SCANF_ADVANCED_ENABLE */
80 #if (defined(SCANF_FLOAT_ENABLE) && (SCANF_FLOAT_ENABLE > 0))
81     kSCANF_LengthLongLongDouble = 0x1000U, /*!< Length LongLongDuoble Flag. */
82 #endif                                     /*PRINTF_FLOAT_ENABLE */
83     kSCANF_TypeSinged = 0x2000U,           /*!< TypeSinged Flag. */
84 };
85 
86 #if defined(__cplusplus)
87 extern "C" {
88 #endif /* __cplusplus */
89 
90 /*!
91  * @brief A function pointer which is used when format printf log.
92  */
93 typedef void (*printfCb)(char *buf, int32_t *indicator, char val, int len);
94 
95 /*!
96  * @brief This function outputs its parameters according to a formatted string.
97  *
98  * @note I/O is performed by calling given function pointer using following
99  * (*func_ptr)(c);
100  *
101  * @param[in] fmt   Format string for printf.
102  * @param[in] ap  Arguments to printf.
103  * @param[in] buf  pointer to the buffer
104  * @param cb print callbck function pointer
105  *
106  * @return Number of characters to be print
107  */
108 int StrFormatPrintf(const char *fmt, va_list ap, char *buf, printfCb cb);
109 
110 /*!
111  * @brief Converts an input line of ASCII characters based upon a provided
112  * string format.
113  *
114  * @param[in] line_ptr The input line of ASCII data.
115  * @param[in] format   Format first points to the format string.
116  * @param[in] args_ptr The list of parameters.
117  *
118  * @return Number of input items converted and assigned.
119  * @retval IO_EOF When line_ptr is empty string "".
120  */
121 int StrFormatScanf(const char *line_ptr, char *format, va_list args_ptr);
122 
123 #if defined(__cplusplus)
124 }
125 #endif /* __cplusplus */
126 
127 /*! @} */
128 
129 #endif /* _FSL_STR_H */
130