53#if (ENABLE_SEMIHOSTING_PRINT == 1)
57#if (ENABLE_BSP_PRINTF)
58 static void _putchar(
char character){
59 #if (ENABLE_SEMIHOSTING_PRINT == 1)
66 static void _putchar_s(
char *p)
68 #if (ENABLE_SEMIHOSTING_PRINT == 1)
76 static void bsp_printHex(uint32_t val)
81 for (
int i = (4*digits)-4; i >= 0; i -= 4) {
82 _putchar(
"0123456789ABCDEF"[(val >> i) % 16]);
86 static void bsp_printHex_lower(uint32_t val)
91 for (
int i = (4*digits)-4; i >= 0; i -= 4) {
92 _putchar(
"0123456789abcdef"[(val >> i) % 16]);
97 #if (ENABLE_FLOATING_POINT_SUPPORT)
99 static void reverse(
char s[])
104 for (i = 0, j = strlen(s)-1; i<j; i++, j--) {
112 static void itos(
int n,
char s[])
120 s[i++] = n % 10 +
'0';
121 }
while ((n /= 10) > 0);
129 static void ftoa(
double n,
char* res1,
char* res2)
138 double fpart = n - (double)ipart;
148 fpart_f = (float)fpart * pow(10, afterpoint);
153 fpart_f = -(fpart_f);
156 for (
int i=afterpoint; i>0; i--)
158 if ((fpart_f<(1 * pow(10, i-1))) && (fpart_f>0))
165 itos((
int)fpart_f, res2);
168 static void print_dec(uint32_t val)
175 static void print_float(
double val)
181 char sval[21], fval[10];
182 ftoa(val, sval, fval);
194 if ((sval[0] !=
'-') && (neg == 1))
210 static void bsp_printf_c(
int c)
215 static void bsp_printf_s(
char *p)
222 static void bsp_printf_d(
int val)
230 while (val || p == buffer) {
231 *(p++) =
'0' + val % 10;
235 bsp_printf_c(*(--p));
238 static void bsp_printf_x(
int val)
244 if((val & (0xFFFFFFF0 <<(4*i))) == 0)
250 bsp_printHex_lower(val);
253 static void bsp_printf_X(
int val)
259 if((val & (0xFFFFFFF0 <<(4*i))) == 0)
267#if (ENABLE_SEMIHOSTING_PRINT == 0)
268 static int bsp_printf(
const char *format, ...)
273 va_start(ap, format);
275 for (i = 0; format[i]; i++){
276 if (format[i] ==
'\n') {
281 if (format[i] ==
'%') {
282 while (format[++i]) {
283 if (format[i] ==
'c') {
284 bsp_printf_c(va_arg(ap,
int));
287 else if (format[i] ==
's') {
288 bsp_printf_s(va_arg(ap,
char*));
291 else if (format[i] ==
'd') {
292 bsp_printf_d(va_arg(ap,
int));
295 else if (format[i] ==
'X') {
296 bsp_printf_X(va_arg(ap,
int));
299 else if (format[i] ==
'x') {
300 bsp_printf_x(va_arg(ap,
int));
303#if (ENABLE_FLOATING_POINT_SUPPORT)
304 else if (format[i] ==
'f') {
305 print_float(va_arg(ap,
double));
308#elif (ENABLE_PRINTF_WARNING)
309 else if (format[i] ==
'f') {
310 bsp_printf_s(
"<Floating point printing not enable. Please Enable it at bsp.h first...>");
316 bsp_printf_c(format[i]);
323 static int bsp_printf(
const char* format, ...)
326 va_start(va, format);
329 const int ret = _vsnprintf(_out_buffer, buffer, (
size_t)-1, format, va);
Board Support Package API definitions.
#define bsp_putChar(c)
Map standard character output to the physical UART.
#define MAX_STRING_BUFFER_SIZE