+/rtos

git clone https://git.julia.blue/+/rtos

Vivek MalneediMerge branch 'master' of github.com:EE445M-Sp20/lab-6-vm22967_jbr2558021d2d4

master
4.9 KiB118 linesraw
1///////////////////////////////////////////////////////////////////////////////
2// \author (c) Marco Paland (info@paland.com)
3//             2014-2019, PALANDesign Hannover, Germany
4//
5// \license The MIT License (MIT)
6//
7// Permission is hereby granted, free of charge, to any person obtaining a copy
8// of this software and associated documentation files (the "Software"), to deal
9// in the Software without restriction, including without limitation the rights
10// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11// copies of the Software, and to permit persons to whom the Software is
12// furnished to do so, subject to the following conditions:
13//
14// The above copyright notice and this permission notice shall be included in
15// all copies or substantial portions of the Software.
16//
17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23// THE SOFTWARE.
24//
25// \brief Tiny printf, sprintf and snprintf implementation, optimized for speed
26// on
27//        embedded systems with a very limited resources.
28//        Use this instead of bloated standard/newlib printf.
29//        These routines are thread safe and reentrant.
30//
31///////////////////////////////////////////////////////////////////////////////
32
33#pragma once
34
35#define PRINTF_DISABLE_SUPPORT_FLOAT
36#define PRINTF_DISABLE_SUPPORT_EXPONENTIAL
37#define PRINTF_DISABLE_SUPPORT_LONG_LONG
38#define PRINTF_DISABLE_SUPPORT_PTRDIFF_T
39
40#include <stdarg.h>
41#include <stddef.h>
42
43#ifdef __cplusplus
44extern "C" {
45#endif
46
47/**
48 * Output a character to a custom device like UART, used by the printf()
49 * function This function is declared here only. You have to write your custom
50 * implementation somewhere \param character Character to output
51 */
52void _putchar(char character);
53
54/**
55 * Tiny printf implementation
56 * You have to implement _putchar if you use printf()
57 * To avoid conflicts with the regular printf() API it is overridden by macro
58 * defines and internal underscore-appended functions like printf_() are used
59 * \param format A string that specifies the format of the output
60 * \return The number of characters that are written into the array, not
61 * counting the terminating null character
62 */
63#define printf printf_
64int printf_(const char* format, ...);
65
66/**
67 * Tiny sprintf implementation
68 * Due to security reasons (buffer overflow) YOU SHOULD CONSIDER USING
69 * (V)SNPRINTF INSTEAD! \param buffer A pointer to the buffer where to store the
70 * formatted string. MUST be big enough to store the output! \param format A
71 * string that specifies the format of the output \return The number of
72 * characters that are WRITTEN into the buffer, not counting the terminating
73 * null character
74 */
75#define sprintf sprintf_
76int sprintf_(char* buffer, const char* format, ...);
77
78/**
79 * Tiny snprintf/vsnprintf implementation
80 * \param buffer A pointer to the buffer where to store the formatted string
81 * \param count The maximum number of characters to store in the buffer,
82 * including a terminating null character \param format A string that specifies
83 * the format of the output \param va A value identifying a variable arguments
84 * list \return The number of characters that COULD have been written into the
85 * buffer, not counting the terminating null character. A value equal or larger
86 * than count indicates truncation. Only when the returned value is non-negative
87 * and less than count, the string has been completely written.
88 */
89#define snprintf snprintf_
90#define vsnprintf vsnprintf_
91int snprintf_(char* buffer, size_t count, const char* format, ...);
92int vsnprintf_(char* buffer, size_t count, const char* format, va_list va);
93
94/**
95 * Tiny vprintf implementation
96 * \param format A string that specifies the format of the output
97 * \param va A value identifying a variable arguments list
98 * \return The number of characters that are WRITTEN into the buffer, not
99 * counting the terminating null character
100 */
101#define vprintf vprintf_
102int vprintf_(const char* format, va_list va);
103
104/**
105 * printf with output function
106 * You may use this as dynamic alternative to printf() with its fixed _putchar()
107 * output \param out An output function which takes one character and an
108 * argument pointer \param arg An argument pointer for user data passed to
109 * output function \param format A string that specifies the format of the
110 * output \return The number of characters that are sent to the output function,
111 * not counting the terminating null character
112 */
113int fctprintf(void (*out)(char character, void* arg), void* arg,
114              const char* format, ...);
115
116#ifdef __cplusplus
117}
118#endif