15 #define DEBUG_ADDR 0xf00000d0 17 #define isdigit(c) ('0' <= (c) && (c) <= '9') 18 #define NULL ((void *)0) 20 void putchar(int32_t value)
21 {
volatile uint32_t* DEBUG = (
volatile uint32_t*) DEBUG_ADDR;
25 void *memcpy(
void *dst,
const void *src, uint32_t n){
27 const int8_t *r2 = src;
35 static uint32_t divide(
long *n,
int base)
39 res = ((uint32_t)*n) % base;
40 *n = (long)(((uint32_t)*n) / base);
44 static int toint(
const char **s)
47 while (isdigit((
int)**s))
48 i = i * 10 + *((*s)++) -
'0';
52 static void printchar(int8_t **str, int32_t c){
61 static int vsprintf(
char **buf,
const char *fmt, va_list args)
64 const char *digits =
"0123456789abcdef";
66 int width, base, sign, i;
69 for (p = buf; *fmt; fmt++) {
93 printchar(p, (
char)va_arg(args,
int));
96 str = va_arg(args,
char *);
99 for (; *str && width != 0; str++, width--) {
117 num = va_arg(args,
long);
118 if (sign && num < 0) {
128 tmp[i++] = digits[divide(&num, base)];
133 printchar(p, tmp[i]);
140 int32_t printf(
const int8_t *fmt, ...){
145 v = vsprintf(0, fmt, args);
150 int32_t sprintf(int8_t *out,
const int8_t *fmt, ...){
155 v = vsprintf(&out, fmt, args);
166 int8_t *itoa(int32_t i, int8_t *s, int32_t base){
167 int8_t *ptr = s, *ptr1 = s, tmp_char;
170 if (base < 2 || base > 36) {
177 *ptr++ =
"zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz" [35 + (tmp_value - i * base)];
191 int32_t ftoa(
float f, int8_t *outbuf, int32_t precision){
192 int32_t mantissa, int_part, frac_part, exp2, i;
206 exp2 = (fl.l >> 23) - 127;
207 mantissa = (fl.l & 0xffffff) | 0x800000;
218 int_part = mantissa << (exp2 - 23);
221 int_part = mantissa >> (23 - exp2);
222 frac_part = (mantissa << (exp2 + 1)) & 0xffffff;
224 frac_part = (mantissa & 0xffffff) >> (-(exp2 + 1));
234 itoa(int_part, p, 10);
240 for (i = 0; i < precision; i++){
241 frac_part = (frac_part << 3) + (frac_part << 1);
242 *p = (frac_part >> 24) +
'0';
244 frac_part = frac_part & 0xffffff;
257 #endif //__HF_PRINTF__ Definition: hf-printf.h:160