/* ****************************************************************************************************************** * *Function Name : UART_printf * *Description : This function is to formatedly output through UART, similar to ANSI C function printf(). * This function can support and only support the following Conversion Specifiers: * %d Signed decimal integer. * %u Unsigned decimal integer. * %x Unsigned hexadecimal integer, using hex digits 0f. * %X Unsigned hexadecimal integer, using hex digits 0F. * %c Single character. * %s Character string. * %p A pointer. * *Input : refer to ANSI C function printf(). * *Output : void, different form ANSI C function printf(). * *call for : void int_to_string_dec( __s32 input, char * str ), defined in format_transformed.c. * void int_to_string_hex( __s32 input, char * str ); defined in format_transformed.c. * void Uint_to_string_dec( __u32 input, char * str ); defined in format_transformed.c. * void UART_putchar( __s32 ch); defined in boot loader. * void UART_puts( const char * string ); defined in boot loader. * *Others : None at present. * ******************************************************************************************************************* */ void UART_printf2( const char * str, ...) { char string[13]; char *p; __s32 hex_flag ; va_list argp; va_start( argp, str ); while( *str ) { if( *str == '%' ) { ++str; p = string; hex_flag = HEX_X; switch( *str ) { case 'd': int_to_string_dec( va_arg( argp, __s32 ), string ); UART_puts_no_newline( p ); ++str; break; case 'x': hex_flag = HEX_x; // jump to " case 'X' " case 'p': case 'X': int_to_string_hex( va_arg( argp, __s32 ), string, hex_flag ); UART_puts_no_newline( p ); ++str; break; case 'u': Uint_to_string_dec( va_arg( argp, __s32 ), string ); UART_puts_no_newline( p ); ++str; break; case 'c': UART_putchar( va_arg( argp, __s32 ) ); ++str; break; case 's': UART_puts_no_newline( va_arg( argp, char * ) ); ++str; break; default : UART_putchar( '%' ); // if current character is not Conversion Specifiers 'dxpXucs', UART_putchar( *str ); // output directly '%' and current character, and then ++str; // let 'str' point to next character. } } else { if( *str == '\n' ) // if current character is '\n', insert and output '\r' UART_putchar( '\r' ); UART_putchar( *str++ ); } } va_end( argp ); }
/* ************************************************************************************************************ * * function * * 函数名称: * * 参数列表: * * 返回值 : * * 说明 : * * ************************************************************************************************************ */ void wlibc_uprintf( const char * str, ...) { char string[16], str_store[256]; char *p, *q = str_store; __s32 hex_flag ; va_list argp; va_start( argp, str ); while( *str ) { if( *str == '%' ) { ++str; p = string; hex_flag = HEX_X; switch( *str ) { case 'd': int_to_string_dec( va_arg( argp, __s32 ), string ); q += mem_puts( p, q ); ++str; break; case 'x': hex_flag = HEX_x; // jump to " case 'X' " case 'p': case 'X': int_to_string_hex( va_arg( argp, __s32 ), string, hex_flag ); q += mem_puts( p, q ); ++str; break; case 'u': Uint_to_string_dec( va_arg( argp, __s32 ), string ); q += mem_puts( p, q ); ++str; break; case 'c': *q++ = va_arg( argp, __s32 ); ++str; break; case 's': q += mem_puts( va_arg( argp, char * ), q ); ++str; break; case 'l': { __u32 high; __u32 low; if( str[1] == 'l' && ( str[2] == 'x' || str[2] == 'X' ) ) { low = va_arg( argp, __u32 ); high = va_arg( argp, __u32 ); if( str[2] == 'x' ) hex_flag = 'x'; else hex_flag = 'X'; int_to_string_hex( high, string, hex_flag ); q += mem_puts( p, q ); int_to_string_hex( low, string, hex_flag ); q += mem_puts( p+2, q ); str += 3; break; } else { int_to_string_dec( va_arg( argp, __s32 ), string ); q += mem_puts( p, q ); ++str; break; } } default : *q++ = '%'; // if current character is not Conversion Specifiers 'dxpXucs', *q++ = *str++; // output directly '%' and current character, and then // let 'str' point to next character. } } else { if( *str == '\n' ) // if current character is '\n', insert and output '\r'