New HAL and SimpleMAC for STM32W108.
This commit is contained in:
parent
c9af578eab
commit
eb588f1aec
89 changed files with 1503 additions and 1883 deletions
35
cpu/stm32w108/small_printf/Makefile
Normal file
35
cpu/stm32w108/small_printf/Makefile
Normal file
|
@ -0,0 +1,35 @@
|
|||
|
||||
|
||||
|
||||
CC = arm-none-eabi-gcc
|
||||
AR = arm-none-eabi-ar
|
||||
CFLAGS = -mthumb -mcpu=cortex-m3 -I "." -I "C:/Program\ Files/Raisonance/Ride/Lib/ARM/include" \
|
||||
-fsigned-char -D _SMALL_PRINTF -D INTEGER_ONLY -Os -ffunction-sections -mlittle-endian
|
||||
AROPTS = cq
|
||||
|
||||
|
||||
SOURCE_FILES = _SP_printf.c _SP_puts.c _SP_sprintf.c _SP_snprintf.c _SP_vfprintf.c
|
||||
|
||||
|
||||
SOURCE_OBJS = ${patsubst %.c,%.o,$(SOURCE_FILES)}
|
||||
|
||||
|
||||
LIB = smallprintf_thumb2.a
|
||||
|
||||
|
||||
|
||||
all: clean $(LIB)
|
||||
|
||||
clean:
|
||||
rm -f $(LIB)
|
||||
|
||||
|
||||
%.a: $(SOURCE_OBJS)
|
||||
$(AR) $(AROPTS) $@ $^
|
||||
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
|
||||
|
78
cpu/stm32w108/small_printf/_SP_printf.c
Normal file
78
cpu/stm32w108/small_printf/_SP_printf.c
Normal file
|
@ -0,0 +1,78 @@
|
|||
#ifdef INTEGER_ONLY
|
||||
#define _vfprintf_r _vfiprintf_r
|
||||
#define _vfprintf _vfiprintf
|
||||
#define vfprintf vfiprintf
|
||||
#endif
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifndef _SMALL_PRINTF
|
||||
#include "local.h"
|
||||
#endif
|
||||
|
||||
#ifdef _HAVE_STDC
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
#include <varargs.h>
|
||||
#endif
|
||||
|
||||
#ifndef _SMALL_PRINTF
|
||||
|
||||
#ifdef _HAVE_STDC
|
||||
int
|
||||
_printf_r (struct _reent *ptr, const char *fmt, ...)
|
||||
#else
|
||||
int
|
||||
_printf_r (ptr, fmt, va_alist)
|
||||
struct _reent *ptr;
|
||||
char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
|
||||
//_REENT_SMALL_CHECK_INIT(_stdout_r (ptr));
|
||||
#ifdef _HAVE_STDC
|
||||
va_start (ap, fmt);
|
||||
#else
|
||||
va_start (ap);
|
||||
#endif
|
||||
ret = _vfprintf_r (ptr, _stdout_r (ptr), fmt, ap);
|
||||
va_end (ap);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef _REENT_ONLY
|
||||
|
||||
#ifdef _HAVE_STDC
|
||||
int
|
||||
printf (const char *fmt, ...)
|
||||
#else
|
||||
int
|
||||
printf (fmt, va_alist)
|
||||
char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
|
||||
//_REENT_SMALL_CHECK_INIT(_stdout_r (_REENT));
|
||||
#ifdef _HAVE_STDC
|
||||
va_start (ap, fmt);
|
||||
#else
|
||||
va_start (ap);
|
||||
#endif
|
||||
#ifndef _SMALL_PRINTF
|
||||
ret = vfprintf (_stdout_r (_REENT), fmt, ap);
|
||||
#else
|
||||
ret = vfprintf (0, fmt, ap);
|
||||
#endif
|
||||
va_end (ap);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* ! _REENT_ONLY */
|
34
cpu/stm32w108/small_printf/_SP_puts.c
Normal file
34
cpu/stm32w108/small_printf/_SP_puts.c
Normal file
|
@ -0,0 +1,34 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
void __io_putchar ( char );
|
||||
|
||||
void _SMALL_PRINTF_puts(const char *ptr, int len, FILE *fp)
|
||||
{
|
||||
if ( fp && ( fp->_file == -1 ) /* No file => sprintf */
|
||||
&& (fp->_flags & (__SWR | __SSTR) ) )
|
||||
{
|
||||
char *str = fp->_p;
|
||||
|
||||
for ( ; len ; len-- )
|
||||
{
|
||||
*str ++ = *ptr++;
|
||||
}
|
||||
fp->_p = str;
|
||||
}
|
||||
else /* file => printf */
|
||||
{
|
||||
for ( ; len ; len-- )
|
||||
__io_putchar ( *ptr++ );
|
||||
}
|
||||
}
|
||||
|
||||
int puts(const char *str)
|
||||
{
|
||||
int len = strlen ( str );
|
||||
_SMALL_PRINTF_puts(str, len, 0) ;
|
||||
__io_putchar ( '\n' );
|
||||
return len;
|
||||
}
|
||||
|
124
cpu/stm32w108/small_printf/_SP_snprintf.c
Normal file
124
cpu/stm32w108/small_printf/_SP_snprintf.c
Normal file
|
@ -0,0 +1,124 @@
|
|||
/*
|
||||
* Copyright (c) 1990 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by the University of California, Berkeley. The name of the
|
||||
* University may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
/* doc in _SP_sprintf.c */
|
||||
/* This code created by modifying _SP_sprintf.c so copyright inherited. */
|
||||
|
||||
#include <stdio.h>
|
||||
#ifdef _HAVE_STDC
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
#include <varargs.h>
|
||||
#endif
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
#include <_ansi.h>
|
||||
|
||||
#ifndef _SMALL_PRINTF
|
||||
#include "local.h"
|
||||
#else
|
||||
#ifdef INTEGER_ONLY
|
||||
#define _vfprintf_r _vfiprintf_r
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef _SMALL_PRINTF
|
||||
int
|
||||
#ifdef _HAVE_STDC
|
||||
_DEFUN (_snprintf_r, (ptr, str, size, fmt), struct _reent *ptr _AND char *str _AND size_t size _AND _CONST char *fmt _DOTS)
|
||||
#else
|
||||
_snprintf_r (ptr, str, size, fmt, va_alist)
|
||||
struct _reent *ptr;
|
||||
char *str;
|
||||
size_t size;
|
||||
_CONST char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
FILE f;
|
||||
|
||||
if (size > INT_MAX)
|
||||
{
|
||||
ptr->_errno = EOVERFLOW;
|
||||
return EOF;
|
||||
}
|
||||
|
||||
f._flags = __SWR | __SSTR;
|
||||
f._bf._base = f._p = (unsigned char *) str;
|
||||
f._bf._size = f._w = (size > 0 ? size - 1 : 0);
|
||||
f._file = -1; /* No file. */
|
||||
#ifdef _HAVE_STDC
|
||||
va_start (ap, fmt);
|
||||
#else
|
||||
va_start (ap);
|
||||
#endif
|
||||
ret = _vfprintf_r (ptr, &f, fmt, ap);
|
||||
va_end (ap);
|
||||
if (ret < EOF)
|
||||
ptr->_errno = EOVERFLOW;
|
||||
if (size > 0)
|
||||
*f._p = 0;
|
||||
return (ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef _REENT_ONLY
|
||||
int
|
||||
#ifdef _HAVE_STDC
|
||||
_DEFUN (snprintf, (str, size, fmt), char *str _AND size_t size _AND _CONST char *fmt _DOTS)
|
||||
#else
|
||||
snprintf (str, size, fmt, va_alist)
|
||||
char *str;
|
||||
size_t size;
|
||||
_CONST char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
FILE f;
|
||||
|
||||
struct _reent *ptr = _REENT;
|
||||
|
||||
if (size > INT_MAX)
|
||||
{
|
||||
ptr->_errno = EOVERFLOW;
|
||||
return EOF;
|
||||
}
|
||||
|
||||
f._flags = __SWR | __SSTR;
|
||||
f._bf._base = f._p = (unsigned char *) str;
|
||||
f._bf._size = f._w = (size > 0 ? size - 1 : 0);
|
||||
f._file = -1; /* No file. */
|
||||
#ifdef _HAVE_STDC
|
||||
va_start (ap, fmt);
|
||||
#else
|
||||
va_start (ap);
|
||||
#endif
|
||||
ret = _vfprintf_r (ptr, &f, fmt, ap);
|
||||
va_end (ap);
|
||||
if (ret < EOF)
|
||||
ptr->_errno = EOVERFLOW;
|
||||
if (size > 0)
|
||||
*f._p = 0;
|
||||
return (ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
389
cpu/stm32w108/small_printf/_SP_sprintf.c
Normal file
389
cpu/stm32w108/small_printf/_SP_sprintf.c
Normal file
|
@ -0,0 +1,389 @@
|
|||
/*
|
||||
* Copyright (c) 1990 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by the University of California, Berkeley. The name of the
|
||||
* University may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
FUNCTION
|
||||
<<printf>>, <<fprintf>>, <<asprintf>>, <<sprintf>>, <<snprintf>>---format output
|
||||
INDEX
|
||||
fprintf
|
||||
INDEX
|
||||
printf
|
||||
INDEX
|
||||
asprintf
|
||||
INDEX
|
||||
sprintf
|
||||
INDEX
|
||||
snprintf
|
||||
|
||||
ANSI_SYNOPSIS
|
||||
#include <stdio.h>
|
||||
|
||||
int printf(const char *<[format]> [, <[arg]>, ...]);
|
||||
int fprintf(FILE *<[fd]>, const char *<[format]> [, <[arg]>, ...]);
|
||||
int sprintf(char *<[str]>, const char *<[format]> [, <[arg]>, ...]);
|
||||
int asprintf(char **<[strp]>, const char *<[format]> [, <[arg]>, ...]);
|
||||
int snprintf(char *<[str]>, size_t <[size]>, const char *<[format]> [, <[arg]>, ...]);
|
||||
|
||||
TRAD_SYNOPSIS
|
||||
#include <stdio.h>
|
||||
|
||||
int printf(<[format]> [, <[arg]>, ...])
|
||||
char *<[format]>;
|
||||
|
||||
int fprintf(<[fd]>, <[format]> [, <[arg]>, ...]);
|
||||
FILE *<[fd]>;
|
||||
char *<[format]>;
|
||||
|
||||
int asprintf(<[strp]>, <[format]> [, <[arg]>, ...]);
|
||||
char **<[strp]>;
|
||||
char *<[format]>;
|
||||
|
||||
int sprintf(<[str]>, <[format]> [, <[arg]>, ...]);
|
||||
char *<[str]>;
|
||||
char *<[format]>;
|
||||
|
||||
int snprintf(<[str]>, size_t <[size]>, <[format]> [, <[arg]>, ...]);
|
||||
char *<[str]>;
|
||||
size_t <[size]>;
|
||||
char *<[format]>;
|
||||
|
||||
DESCRIPTION
|
||||
<<printf>> accepts a series of arguments, applies to each a
|
||||
format specifier from <<*<[format]>>>, and writes the
|
||||
formatted data to <<stdout>>, terminated with a null character.
|
||||
The behavior of <<printf>> is undefined if there are not enough
|
||||
arguments for the format.
|
||||
<<printf>> returns when it reaches the end of the format string.
|
||||
If there are more arguments than the format requires, excess
|
||||
arguments are ignored.
|
||||
|
||||
<<fprintf>>, <<asprintf>>, <<sprintf>> and <<snprintf>> are identical
|
||||
to <<printf>>, other than the destination of the formatted output:
|
||||
<<fprintf>> sends the output to a specified file <[fd]>, while
|
||||
<<asprintf>> stores the output in a dynamically allocated buffer,
|
||||
while <<sprintf>> stores the output in the specified char array
|
||||
<[str]> and <<snprintf>> limits number of characters written to
|
||||
<[str]> to at most <[size]> (including terminating <<0>>). For
|
||||
<<sprintf>> and <<snprintf>>, the behavior is undefined if the
|
||||
output <<*<[str]>>> overlaps with one of the arguments. For
|
||||
<<asprintf>>, <[strp]> points to a pointer to char which is filled
|
||||
in with the dynamically allocated buffer. <[format]> is a pointer
|
||||
to a charater string containing two types of objects: ordinary
|
||||
characters (other than <<%>>), which are copied unchanged to the
|
||||
output, and conversion specifications, each of which is introduced
|
||||
by <<%>>. (To include <<%>> in the output, use <<%%>> in the format
|
||||
string.) A conversion specification has the following form:
|
||||
|
||||
. %[<[flags]>][<[width]>][.<[prec]>][<[size]>][<[type]>]
|
||||
|
||||
The fields of the conversion specification have the following meanings:
|
||||
|
||||
O+
|
||||
o <[flags]>
|
||||
|
||||
an optional sequence of characters which control
|
||||
output justification, numeric signs, decimal points,
|
||||
trailing zeroes, and octal and hex prefixes.
|
||||
The flag characters are minus (<<->>), plus (<<+>>),
|
||||
space ( ), zero (<<0>>), and sharp (<<#>>). They can
|
||||
appear in any combination.
|
||||
|
||||
o+
|
||||
o -
|
||||
The result of the conversion is left justified, and the right is
|
||||
padded with blanks. If you do not use this flag, the result is right
|
||||
justified, and padded on the left.
|
||||
|
||||
o +
|
||||
The result of a signed conversion (as determined by <[type]>)
|
||||
will always begin with a plus or minus sign. (If you do not use
|
||||
this flag, positive values do not begin with a plus sign.)
|
||||
|
||||
o " " (space)
|
||||
If the first character of a signed conversion specification
|
||||
is not a sign, or if a signed conversion results in no
|
||||
characters, the result will begin with a space. If the
|
||||
space ( ) flag and the plus (<<+>>) flag both appear,
|
||||
the space flag is ignored.
|
||||
|
||||
o 0
|
||||
If the <[type]> character is <<d>>, <<i>>, <<o>>, <<u>>,
|
||||
<<x>>, <<X>>, <<e>>, <<E>>, <<f>>, <<g>>, or <<G>>: leading zeroes,
|
||||
are used to pad the field width (following any indication of sign or
|
||||
base); no spaces are used for padding. If the zero (<<0>>) and
|
||||
minus (<<->>) flags both appear, the zero (<<0>>) flag will
|
||||
be ignored. For <<d>>, <<i>>, <<o>>, <<u>>, <<x>>, and <<X>>
|
||||
conversions, if a precision <[prec]> is specified, the zero (<<0>>)
|
||||
flag is ignored.
|
||||
|
||||
Note that <<0>> is interpreted as a flag, not as the beginning
|
||||
of a field width.
|
||||
|
||||
o #
|
||||
The result is to be converted to an alternative form, according
|
||||
to the next character:
|
||||
|
||||
o+
|
||||
o 0
|
||||
increases precision to force the first digit
|
||||
of the result to be a zero.
|
||||
|
||||
o x
|
||||
a non-zero result will have a <<0x>> prefix.
|
||||
|
||||
o X
|
||||
a non-zero result will have a <<0X>> prefix.
|
||||
|
||||
o e, E or f
|
||||
The result will always contain a decimal point
|
||||
even if no digits follow the point.
|
||||
(Normally, a decimal point appears only if a
|
||||
digit follows it.) Trailing zeroes are removed.
|
||||
|
||||
o g or G
|
||||
same as <<e>> or <<E>>, but trailing zeroes
|
||||
are not removed.
|
||||
|
||||
o all others
|
||||
undefined.
|
||||
|
||||
o-
|
||||
o-
|
||||
|
||||
o <[width]>
|
||||
|
||||
<[width]> is an optional minimum field width. You can either
|
||||
specify it directly as a decimal integer, or indirectly by
|
||||
using instead an asterisk (<<*>>), in which case an <<int>>
|
||||
argument is used as the field width. Negative field widths
|
||||
are not supported; if you attempt to specify a negative field
|
||||
width, it is interpreted as a minus (<<->>) flag followed by a
|
||||
positive field width.
|
||||
|
||||
o <[prec]>
|
||||
|
||||
an optional field; if present, it is introduced with `<<.>>'
|
||||
(a period). This field gives the maximum number of
|
||||
characters to print in a conversion; the minimum number of
|
||||
digits of an integer to print, for conversions with <[type]>
|
||||
<<d>>, <<i>>, <<o>>, <<u>>, <<x>>, and <<X>>; the maximum number of
|
||||
significant digits, for the <<g>> and <<G>> conversions;
|
||||
or the number of digits to print after the decimal
|
||||
point, for <<e>>, <<E>>, and <<f>> conversions. You can specify
|
||||
the precision either directly as a decimal integer or
|
||||
indirectly by using an asterisk (<<*>>), in which case
|
||||
an <<int>> argument is used as the precision. Supplying a negative
|
||||
precision is equivalent to omitting the precision.
|
||||
If only a period is specified the precision is zero.
|
||||
If a precision appears with any other conversion <[type]>
|
||||
than those listed here, the behavior is undefined.
|
||||
|
||||
o <[size]>
|
||||
|
||||
<<h>>, <<l>>, and <<L>> are optional size characters which
|
||||
override the default way that <<printf>> interprets the
|
||||
data type of the corresponding argument. <<h>> forces
|
||||
the following <<d>>, <<i>>, <<o>>, <<u>>, <<x>> or <<X>> conversion
|
||||
<[type]> to apply to a <<short>> or <<unsigned short>>. <<h>> also
|
||||
forces a following <<n>> <[type]> to apply to
|
||||
a pointer to a <<short>>. Similarily, an
|
||||
<<l>> forces the following <<d>>, <<i>>, <<o>>, <<u>>,
|
||||
<<x>> or <<X>> conversion <[type]> to apply to a <<long>> or
|
||||
<<unsigned long>>. <<l>> also forces a following <<n>> <[type]> to
|
||||
apply to a pointer to a <<long>>. <<l>> with <<c>>, <<s>> is
|
||||
equivalent to <<C>>, <<S>> respectively. If an <<h>>
|
||||
or an <<l>> appears with another conversion
|
||||
specifier, the behavior is undefined. <<L>> forces a
|
||||
following <<e>>, <<E>>, <<f>>, <<g>> or <<G>> conversion <[type]> to
|
||||
apply to a <<long double>> argument. If <<L>> appears with
|
||||
any other conversion <[type]>, the behavior is undefined.
|
||||
|
||||
o <[type]>
|
||||
|
||||
<[type]> specifies what kind of conversion <<printf>> performs.
|
||||
Here is a table of these:
|
||||
|
||||
o+
|
||||
o %
|
||||
prints the percent character (<<%>>)
|
||||
|
||||
o c
|
||||
prints <[arg]> as single character
|
||||
|
||||
o C
|
||||
prints wchar_t <[arg]> as single multibyte character
|
||||
|
||||
o s
|
||||
prints characters until precision is reached or a null terminator
|
||||
is encountered; takes a string pointer
|
||||
|
||||
o S
|
||||
converts wchar_t characters to multibyte output characters until
|
||||
precision is reached or a null wchar_t terminator
|
||||
is encountered; takes a wchar_t pointer
|
||||
|
||||
o d
|
||||
prints a signed decimal integer; takes an <<int>> (same as <<i>>)
|
||||
|
||||
o i
|
||||
prints a signed decimal integer; takes an <<int>> (same as <<d>>)
|
||||
|
||||
o o
|
||||
prints a signed octal integer; takes an <<int>>
|
||||
|
||||
o u
|
||||
prints an unsigned decimal integer; takes an <<int>>
|
||||
|
||||
o x
|
||||
prints an unsigned hexadecimal integer (using <<abcdef>> as
|
||||
digits beyond <<9>>); takes an <<int>>
|
||||
|
||||
o X
|
||||
prints an unsigned hexadecimal integer (using <<ABCDEF>> as
|
||||
digits beyond <<9>>); takes an <<int>>
|
||||
|
||||
o f
|
||||
prints a signed value of the form <<[-]9999.9999>>; takes
|
||||
a floating-point number
|
||||
|
||||
o e
|
||||
prints a signed value of the form <<[-]9.9999e[+|-]999>>; takes a
|
||||
floating-point number
|
||||
|
||||
o E
|
||||
prints the same way as <<e>>, but using <<E>> to introduce the
|
||||
exponent; takes a floating-point number
|
||||
|
||||
o g
|
||||
prints a signed value in either <<f>> or <<e>> form, based on given
|
||||
value and precision---trailing zeros and the decimal point are
|
||||
printed only if necessary; takes a floating-point number
|
||||
|
||||
o G
|
||||
prints the same way as <<g>>, but using <<E>> for the exponent if an
|
||||
exponent is needed; takes a floating-point number
|
||||
|
||||
o n
|
||||
stores (in the same object) a count of the characters written;
|
||||
takes a pointer to <<int>>
|
||||
|
||||
o p
|
||||
prints a pointer in an implementation-defined format.
|
||||
This implementation treats the pointer as an
|
||||
<<unsigned long>> (same as <<Lu>>).
|
||||
o-
|
||||
O-
|
||||
|
||||
|
||||
RETURNS
|
||||
<<sprintf>> and <<asprintf>> return the number of bytes in the output string,
|
||||
save that the concluding <<NULL>> is not counted.
|
||||
<<printf>> and <<fprintf>> return the number of characters transmitted.
|
||||
If an error occurs, <<printf>> and <<fprintf>> return <<EOF>> and
|
||||
<<asprintf>> returns -1. No error returns occur for <<sprintf>>.
|
||||
|
||||
PORTABILITY
|
||||
The ANSI C standard specifies that implementations must
|
||||
support at least formatted output of up to 509 characters.
|
||||
|
||||
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
|
||||
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#ifdef _HAVE_STDC
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
#include <varargs.h>
|
||||
#endif
|
||||
#include <limits.h>
|
||||
#include <_ansi.h>
|
||||
|
||||
#ifndef _SMALL_PRINTF
|
||||
#include "local.h"
|
||||
#else
|
||||
#ifdef INTEGER_ONLY
|
||||
#define _vfprintf_r _vfiprintf_r
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef _SMALL_PRINTF
|
||||
int
|
||||
#ifdef _HAVE_STDC
|
||||
_DEFUN (_sprintf_r, (ptr, str, fmt), struct _reent *ptr _AND char *str _AND _CONST char *fmt _DOTS)
|
||||
#else
|
||||
_sprintf_r (ptr, str, fmt, va_alist)
|
||||
struct _reent *ptr;
|
||||
char *str;
|
||||
_CONST char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
FILE f;
|
||||
|
||||
f._flags = __SWR | __SSTR;
|
||||
f._bf._base = f._p = (unsigned char *) str;
|
||||
f._bf._size = f._w = INT_MAX;
|
||||
f._file = -1; /* No file. */
|
||||
#ifdef _HAVE_STDC
|
||||
va_start (ap, fmt);
|
||||
#else
|
||||
va_start (ap);
|
||||
#endif
|
||||
ret = _vfprintf_r (ptr, &f, fmt, ap);
|
||||
va_end (ap);
|
||||
*f._p = 0;
|
||||
return (ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef _REENT_ONLY
|
||||
int
|
||||
#ifdef _HAVE_STDC
|
||||
_DEFUN (sprintf, (str, fmt), char *str _AND _CONST char *fmt _DOTS)
|
||||
#else
|
||||
sprintf (str, fmt, va_alist)
|
||||
char *str;
|
||||
_CONST char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
FILE f;
|
||||
|
||||
f._flags = __SWR | __SSTR;
|
||||
f._bf._base = f._p = (unsigned char *) str;
|
||||
f._bf._size = f._w = INT_MAX;
|
||||
f._file = -1; /* No file. */
|
||||
#ifdef _HAVE_STDC
|
||||
va_start (ap, fmt);
|
||||
#else
|
||||
va_start (ap);
|
||||
#endif
|
||||
ret = _vfprintf_r (_REENT, &f, fmt, ap);
|
||||
va_end (ap);
|
||||
*f._p = 0;
|
||||
return (ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
1774
cpu/stm32w108/small_printf/_SP_vfprintf.c
Normal file
1774
cpu/stm32w108/small_printf/_SP_vfprintf.c
Normal file
File diff suppressed because it is too large
Load diff
284
cpu/stm32w108/small_printf/vfieeefp.h
Normal file
284
cpu/stm32w108/small_printf/vfieeefp.h
Normal file
|
@ -0,0 +1,284 @@
|
|||
/****************************************************************
|
||||
*
|
||||
* The author of this software is David M. Gay.
|
||||
*
|
||||
* Copyright (c) 1991 by AT&T.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose without fee is hereby granted, provided that this entire notice
|
||||
* is included in all copies of any software which is or includes a copy
|
||||
* or modification of this software and in all copies of the supporting
|
||||
* documentation for such software.
|
||||
*
|
||||
* THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
|
||||
* WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR AT&T MAKES ANY
|
||||
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
|
||||
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
|
||||
*
|
||||
***************************************************************/
|
||||
|
||||
/* Please send bug reports to
|
||||
David M. Gay
|
||||
AT&T Bell Laboratories, Room 2C-463
|
||||
600 Mountain Avenue
|
||||
Murray Hill, NJ 07974-2070
|
||||
U.S.A.
|
||||
dmg@research.att.com or research!dmg
|
||||
*/
|
||||
|
||||
/* This header file is a modification of mprec.h that only contains floating
|
||||
point union code. */
|
||||
|
||||
#include <ieeefp.h>
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
#include <errno.h>
|
||||
#include <sys/config.h>
|
||||
|
||||
#ifdef __IEEE_LITTLE_ENDIAN
|
||||
#define IEEE_8087
|
||||
#endif
|
||||
|
||||
#ifdef __IEEE_BIG_ENDIAN
|
||||
#define IEEE_MC68k
|
||||
#endif
|
||||
|
||||
#ifdef __Z8000__
|
||||
#define Just_16
|
||||
#endif
|
||||
|
||||
#ifdef Unsigned_Shifts
|
||||
#define Sign_Extend(a,b) if (b < 0) a |= (__uint32_t)0xffff0000;
|
||||
#else
|
||||
#define Sign_Extend(a,b) /*no-op*/
|
||||
#endif
|
||||
|
||||
#if defined(IEEE_8087) + defined(IEEE_MC68k) + defined(VAX) + defined(IBM) != 1
|
||||
Exactly one of IEEE_8087, IEEE_MC68k, VAX, or IBM should be defined.
|
||||
#endif
|
||||
|
||||
#ifdef WANT_IO_LONG_DBL
|
||||
/* If we are going to examine or modify specific bits in a long double using
|
||||
the lword0 or lwordx macros, then we must wrap the long double inside
|
||||
a union. This is necessary to avoid undefined behavior according to
|
||||
the ANSI C spec. */
|
||||
|
||||
#ifdef IEEE_8087
|
||||
#if LDBL_MANT_DIG == 24
|
||||
struct ldieee
|
||||
{
|
||||
unsigned manh:23;
|
||||
unsigned exp:8;
|
||||
unsigned sign:1;
|
||||
};
|
||||
#elif LDBL_MANT_DIG == 53
|
||||
struct ldieee
|
||||
{
|
||||
unsigned manl:20;
|
||||
unsigned manh:32;
|
||||
unsigned exp:11;
|
||||
unsigned sign:1;
|
||||
};
|
||||
#elif LDBL_MANT_DIG == 64
|
||||
struct ldieee
|
||||
{
|
||||
unsigned manl:32;
|
||||
unsigned manh:32;
|
||||
unsigned exp:15;
|
||||
unsigned sign:1;
|
||||
};
|
||||
#elif LDBL_MANT_DIG > 64
|
||||
struct ldieee
|
||||
{
|
||||
unsigned manl3:16;
|
||||
unsigned manl2:32;
|
||||
unsigned manl:32;
|
||||
unsigned manh:32;
|
||||
unsigned exp:15;
|
||||
unsigned sign:1;
|
||||
};
|
||||
#endif /* LDBL_MANT_DIG */
|
||||
#else /* !IEEE_8087 */
|
||||
#if LDBL_MANT_DIG == 24
|
||||
struct ldieee
|
||||
{
|
||||
unsigned sign:1;
|
||||
unsigned exp:8;
|
||||
unsigned manh:23;
|
||||
};
|
||||
#elif LDBL_MANT_DIG == 53
|
||||
struct ldieee
|
||||
{
|
||||
unsigned sign:1;
|
||||
unsigned exp:11;
|
||||
unsigned manh:32;
|
||||
unsigned manl:20;
|
||||
};
|
||||
#elif LDBL_MANT_DIG == 64
|
||||
struct ldieee
|
||||
{
|
||||
unsigned sign:1;
|
||||
unsigned exp:15;
|
||||
unsigned manh:32;
|
||||
unsigned manl:32;
|
||||
};
|
||||
#elif LDBL_MANT_DIG > 64
|
||||
struct ldieee
|
||||
{
|
||||
unsigned sign:1;
|
||||
unsigned exp:15;
|
||||
unsigned manh:32;
|
||||
unsigned manl:32;
|
||||
unsigned manl2:32;
|
||||
unsigned manl3;16;
|
||||
};
|
||||
#endif /* LDBL_MANT_DIG */
|
||||
#endif /* !IEEE_8087 */
|
||||
#endif /* WANT_IO_LONG_DBL */
|
||||
|
||||
/* If we are going to examine or modify specific bits in a double using
|
||||
the word0 and/or word1 macros, then we must wrap the double inside
|
||||
a union. This is necessary to avoid undefined behavior according to
|
||||
the ANSI C spec. */
|
||||
union double_union
|
||||
{
|
||||
double d;
|
||||
__uint32_t i[2];
|
||||
};
|
||||
|
||||
#ifdef IEEE_8087
|
||||
#define word0(x) (x.i[1])
|
||||
#define word1(x) (x.i[0])
|
||||
#else
|
||||
#define word0(x) (x.i[0])
|
||||
#define word1(x) (x.i[1])
|
||||
#endif
|
||||
|
||||
/* #define P DBL_MANT_DIG */
|
||||
/* Ten_pmax = floor(P*log(2)/log(5)) */
|
||||
/* Bletch = (highest power of 2 < DBL_MAX_10_EXP) / 16 */
|
||||
/* Quick_max = floor((P-1)*log(FLT_RADIX)/log(10) - 1) */
|
||||
/* Int_max = floor(P*log(FLT_RADIX)/log(10) - 1) */
|
||||
|
||||
#if defined(IEEE_8087) + defined(IEEE_MC68k)
|
||||
#if defined (_DOUBLE_IS_32BITS)
|
||||
#define Exp_shift 23
|
||||
#define Exp_shift1 23
|
||||
#define Exp_msk1 ((__uint32_t)0x00800000L)
|
||||
#define Exp_msk11 ((__uint32_t)0x00800000L)
|
||||
#define Exp_mask ((__uint32_t)0x7f800000L)
|
||||
#define P 24
|
||||
#define Bias 127
|
||||
#if 0
|
||||
#define IEEE_Arith /* it is, but the code doesn't handle IEEE singles yet */
|
||||
#endif
|
||||
#define Emin (-126)
|
||||
#define Exp_1 ((__uint32_t)0x3f800000L)
|
||||
#define Exp_11 ((__uint32_t)0x3f800000L)
|
||||
#define Ebits 8
|
||||
#define Frac_mask ((__uint32_t)0x007fffffL)
|
||||
#define Frac_mask1 ((__uint32_t)0x007fffffL)
|
||||
#define Ten_pmax 10
|
||||
#define Sign_bit ((__uint32_t)0x80000000L)
|
||||
#define Ten_pmax 10
|
||||
#define Bletch 2
|
||||
#define Bndry_mask ((__uint32_t)0x007fffffL)
|
||||
#define Bndry_mask1 ((__uint32_t)0x007fffffL)
|
||||
#define LSB 1
|
||||
#define Sign_bit ((__uint32_t)0x80000000L)
|
||||
#define Log2P 1
|
||||
#define Tiny0 0
|
||||
#define Tiny1 1
|
||||
#define Quick_max 5
|
||||
#define Int_max 6
|
||||
#define Infinite(x) (word0(x) == ((__uint32_t)0x7f800000L))
|
||||
#undef word0
|
||||
#undef word1
|
||||
|
||||
#define word0(x) (x.i[0])
|
||||
#define word1(x) 0
|
||||
#else
|
||||
|
||||
#define Exp_shift 20
|
||||
#define Exp_shift1 20
|
||||
#define Exp_msk1 ((__uint32_t)0x100000L)
|
||||
#define Exp_msk11 ((__uint32_t)0x100000L)
|
||||
#define Exp_mask ((__uint32_t)0x7ff00000L)
|
||||
#define P 53
|
||||
#define Bias 1023
|
||||
#define IEEE_Arith
|
||||
#define Emin (-1022)
|
||||
#define Exp_1 ((__uint32_t)0x3ff00000L)
|
||||
#define Exp_11 ((__uint32_t)0x3ff00000L)
|
||||
#define Ebits 11
|
||||
#define Frac_mask ((__uint32_t)0xfffffL)
|
||||
#define Frac_mask1 ((__uint32_t)0xfffffL)
|
||||
#define Ten_pmax 22
|
||||
#define Bletch 0x10
|
||||
#define Bndry_mask ((__uint32_t)0xfffffL)
|
||||
#define Bndry_mask1 ((__uint32_t)0xfffffL)
|
||||
#define LSB 1
|
||||
#define Sign_bit ((__uint32_t)0x80000000L)
|
||||
#define Log2P 1
|
||||
#define Tiny0 0
|
||||
#define Tiny1 1
|
||||
#define Quick_max 14
|
||||
#define Int_max 14
|
||||
#define Infinite(x) (word0(x) == ((__uint32_t)0x7ff00000L)) /* sufficient test for here */
|
||||
#endif
|
||||
|
||||
#else
|
||||
#undef Sudden_Underflow
|
||||
#define Sudden_Underflow
|
||||
#ifdef IBM
|
||||
#define Exp_shift 24
|
||||
#define Exp_shift1 24
|
||||
#define Exp_msk1 ((__uint32_t)0x1000000L)
|
||||
#define Exp_msk11 ((__uint32_t)0x1000000L)
|
||||
#define Exp_mask ((__uint32_t)0x7f000000L)
|
||||
#define P 14
|
||||
#define Bias 65
|
||||
#define Exp_1 ((__uint32_t)0x41000000L)
|
||||
#define Exp_11 ((__uint32_t)0x41000000L)
|
||||
#define Ebits 8 /* exponent has 7 bits, but 8 is the right value in b2d */
|
||||
#define Frac_mask ((__uint32_t)0xffffffL)
|
||||
#define Frac_mask1 ((__uint32_t)0xffffffL)
|
||||
#define Bletch 4
|
||||
#define Ten_pmax 22
|
||||
#define Bndry_mask ((__uint32_t)0xefffffL)
|
||||
#define Bndry_mask1 ((__uint32_t)0xffffffL)
|
||||
#define LSB 1
|
||||
#define Sign_bit ((__uint32_t)0x80000000L)
|
||||
#define Log2P 4
|
||||
#define Tiny0 ((__uint32_t)0x100000L)
|
||||
#define Tiny1 0
|
||||
#define Quick_max 14
|
||||
#define Int_max 15
|
||||
#else /* VAX */
|
||||
#define Exp_shift 23
|
||||
#define Exp_shift1 7
|
||||
#define Exp_msk1 0x80
|
||||
#define Exp_msk11 ((__uint32_t)0x800000L)
|
||||
#define Exp_mask ((__uint32_t)0x7f80L)
|
||||
#define P 56
|
||||
#define Bias 129
|
||||
#define Exp_1 ((__uint32_t)0x40800000L)
|
||||
#define Exp_11 ((__uint32_t)0x4080L)
|
||||
#define Ebits 8
|
||||
#define Frac_mask ((__uint32_t)0x7fffffL)
|
||||
#define Frac_mask1 ((__uint32_t)0xffff007fL)
|
||||
#define Ten_pmax 24
|
||||
#define Bletch 2
|
||||
#define Bndry_mask ((__uint32_t)0xffff007fL)
|
||||
#define Bndry_mask1 ((__uint32_t)0xffff007fL)
|
||||
#define LSB ((__uint32_t)0x10000L)
|
||||
#define Sign_bit ((__uint32_t)0x8000L)
|
||||
#define Log2P 1
|
||||
#define Tiny0 0x80
|
||||
#define Tiny1 0
|
||||
#define Quick_max 15
|
||||
#define Int_max 15
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue