New HAL and SimpleMAC for STM32W108.
This commit is contained in:
parent
c9af578eab
commit
eb588f1aec
89 changed files with 1503 additions and 1883 deletions
|
@ -117,6 +117,7 @@ ADCUser startNextConversion()
|
|||
ADC_CFG = adcConfig[i]; // set the configuration to desired
|
||||
INT_ADCFLAG = 0xFFFF;
|
||||
INT_CFGSET = INT_ADC;
|
||||
break; //see DDTS MBTst38936
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
453
cpu/stm32w108/hal/micro/cortexm3/board.c
Normal file
453
cpu/stm32w108/hal/micro/cortexm3/board.c
Normal file
|
@ -0,0 +1,453 @@
|
|||
/** @file board.c
|
||||
* @brief Board file x STM32W108 Kits boards
|
||||
*
|
||||
* This file implements a software layer to support all the ST kits boards
|
||||
* and deal with the difference in leds, buttons and sensors connected to the board.
|
||||
* This a bit too complex for customer boards adaptation and customer can simplify it
|
||||
* to adapt it to their hardware environment as they normally don't need to have the software
|
||||
* running on several boards.
|
||||
* The boards supported are:
|
||||
* - MB851 A
|
||||
* - MB851 B
|
||||
* - MB851 C
|
||||
* - MB954 A
|
||||
* - MB954 B
|
||||
* - MB950 A
|
||||
* - MB951 A
|
||||
* <!--(C) COPYRIGHT 2010 STMicroelectronics. All rights reserved. -->
|
||||
*/
|
||||
#include PLATFORM_HEADER
|
||||
#include BOARD_HEADER
|
||||
#ifdef EMBERZNET_HAL
|
||||
#include "stack/include/ember.h"
|
||||
#include "stack/include/error.h"
|
||||
#include "hal/hal.h"
|
||||
#define PORTA (0 << 3)
|
||||
#define PORTB (1 << 3)
|
||||
#define PORTC (2 << 3)
|
||||
#else
|
||||
#include "error.h"
|
||||
#include "hal/hal.h"
|
||||
#include "hal/micro/cortexm3/mfg-token.h"
|
||||
#endif
|
||||
#include <string.h>
|
||||
|
||||
const LedResourceType LedsMB851A[] = {
|
||||
{
|
||||
"D1", /* Green LED */
|
||||
PORTB,
|
||||
6
|
||||
},
|
||||
{
|
||||
"D3", /* Yellow LED */
|
||||
PORTB,
|
||||
5
|
||||
}
|
||||
};
|
||||
|
||||
const InfraRedLedResourceType infraRedLedMB851A = {
|
||||
"D5", /* Infrared LED */
|
||||
PORTB,
|
||||
4
|
||||
};
|
||||
|
||||
|
||||
const LedResourceType LedsMB954A[] = {
|
||||
{
|
||||
"D1", /* Green LED */
|
||||
PORTA,
|
||||
5
|
||||
},
|
||||
{
|
||||
"D3", /* Yellow LED */
|
||||
PORTA,
|
||||
0
|
||||
}
|
||||
};
|
||||
|
||||
const ButtonResourceType ButtonsMB851A[] = {
|
||||
{
|
||||
"S1",
|
||||
PORTA,
|
||||
7
|
||||
}
|
||||
};
|
||||
|
||||
const ButtonResourceType ButtonsMB954A[] = {
|
||||
{
|
||||
"S1",
|
||||
PORTB,
|
||||
3
|
||||
}
|
||||
};
|
||||
|
||||
const ButtonResourceType ButtonsMB950A[] = {
|
||||
{
|
||||
"S1",
|
||||
PORTB,
|
||||
3
|
||||
},
|
||||
{
|
||||
"S2",
|
||||
PORTA,
|
||||
7
|
||||
},
|
||||
{
|
||||
"S3",
|
||||
PORTB,
|
||||
7
|
||||
},
|
||||
{
|
||||
"S4",
|
||||
PORTB,
|
||||
0
|
||||
},
|
||||
{
|
||||
"S5",
|
||||
PORTB,
|
||||
6
|
||||
}
|
||||
};
|
||||
|
||||
const TempSensorResourceType tempSensorMB851A = {
|
||||
"STLM20",
|
||||
PORTB,
|
||||
7,
|
||||
FALSE
|
||||
};
|
||||
|
||||
const TempSensorResourceType tempSensorMB954A = {
|
||||
"STLM20",
|
||||
PORTA,
|
||||
4,
|
||||
TRUE
|
||||
};
|
||||
|
||||
const MemsResourceType memsSensor = {
|
||||
"LIS302",
|
||||
0
|
||||
};
|
||||
|
||||
const BoardIOType ioMB851A = {
|
||||
LedsMB851A,
|
||||
ButtonsMB851A,
|
||||
};
|
||||
|
||||
const BoardIOType ioMB954A = {
|
||||
LedsMB954A,
|
||||
ButtonsMB954A,
|
||||
};
|
||||
|
||||
const BoardIOType ioMB950A = {
|
||||
LedsMB954A,
|
||||
ButtonsMB950A,
|
||||
};
|
||||
|
||||
const BoardResourcesType MB851A = {
|
||||
"MB851 A",
|
||||
(BOARD_HAS_MEMS | BOARD_HAS_TEMP_SENSOR | BOARD_HAS_FTDI),
|
||||
BUTTONS_MB851A,
|
||||
LEDS_MB851A,
|
||||
&ioMB851A,
|
||||
&infraRedLedMB851A,
|
||||
&memsSensor,
|
||||
&tempSensorMB851A,
|
||||
};
|
||||
|
||||
const BoardResourcesType MB851B = {
|
||||
"MB851 B",
|
||||
(BOARD_HAS_MEMS | BOARD_HAS_TEMP_SENSOR | BOARD_HAS_FTDI),
|
||||
BUTTONS_MB851B,
|
||||
LEDS_MB851B,
|
||||
&ioMB851A,
|
||||
&infraRedLedMB851A,
|
||||
&memsSensor,
|
||||
&tempSensorMB851A,
|
||||
};
|
||||
|
||||
const BoardResourcesType MB851C = {
|
||||
"MB851 C",
|
||||
(BOARD_HAS_MEMS | BOARD_HAS_TEMP_SENSOR | BOARD_HAS_STM32F | BOARD_HAS_EEPROM),
|
||||
BUTTONS_MB851C,
|
||||
LEDS_MB851C,
|
||||
&ioMB954A,
|
||||
&infraRedLedMB851A,
|
||||
&memsSensor,
|
||||
&tempSensorMB954A,
|
||||
};
|
||||
|
||||
const BoardResourcesType MB954A = {
|
||||
"MB954 A",
|
||||
(BOARD_HAS_MEMS | BOARD_HAS_TEMP_SENSOR | BOARD_HAS_FTDI | BOARD_HAS_PA),
|
||||
BUTTONS_MB954A,
|
||||
LEDS_MB954A,
|
||||
&ioMB954A,
|
||||
&infraRedLedMB851A,
|
||||
&memsSensor,
|
||||
&tempSensorMB954A,
|
||||
};
|
||||
|
||||
const BoardResourcesType MB954B = {
|
||||
"MB954 B",
|
||||
(BOARD_HAS_MEMS | BOARD_HAS_TEMP_SENSOR | BOARD_HAS_STM32F | BOARD_HAS_EEPROM | BOARD_HAS_PA),
|
||||
BUTTONS_MB954B,
|
||||
LEDS_MB954B,
|
||||
&ioMB954A,
|
||||
&infraRedLedMB851A,
|
||||
&memsSensor,
|
||||
&tempSensorMB954A,
|
||||
};
|
||||
|
||||
const BoardResourcesType MB950A = {
|
||||
"MB950 A",
|
||||
(BOARD_HAS_MEMS | BOARD_HAS_TEMP_SENSOR | BOARD_HAS_STM32F),
|
||||
BUTTONS_MB950A,
|
||||
LEDS_MB950A,
|
||||
&ioMB950A,
|
||||
&infraRedLedMB851A,
|
||||
&memsSensor,
|
||||
&tempSensorMB954A,
|
||||
};
|
||||
|
||||
const BoardResourcesType MB951A = {
|
||||
"MB951 A",
|
||||
(BOARD_HAS_STM32F),
|
||||
BUTTONS_MB951A,
|
||||
LEDS_MB951A,
|
||||
&ioMB954A,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static const BoardResourcesType *boardList [] = {
|
||||
&MB851A,
|
||||
&MB851B,
|
||||
&MB851C,
|
||||
&MB954A,
|
||||
&MB954B,
|
||||
&MB950A,
|
||||
&MB951A
|
||||
};
|
||||
|
||||
BoardResourcesType const *boardDescription = NULL;
|
||||
|
||||
#define PORT_NAME(x) ((x == PORTA) ? "A": ((x == PORTB) ? "B" : ((x == PORTC) ? "C": "?")))
|
||||
|
||||
void halBoardInit(void)
|
||||
{
|
||||
char boardName[16];
|
||||
int8s i;
|
||||
boardDescription = NULL;
|
||||
#ifdef EMBERZNET_HAL
|
||||
halCommonGetToken(boardName, TOKEN_MFG_BOARD_NAME);
|
||||
#else
|
||||
halCommonGetMfgToken(boardName, TOKEN_MFG_BOARD_NAME);
|
||||
#endif
|
||||
|
||||
i = 15;
|
||||
while ((i >= 0) && (boardName[i] == 0xFF)) {
|
||||
boardName[i] = 0;
|
||||
i--;
|
||||
}
|
||||
|
||||
for (i = 0; i < (sizeof(boardList)/4) ; i++)
|
||||
if (strcmp(boardName, (boardList[i])->name) == 0) {
|
||||
boardDescription = (BoardResourcesType *) boardList[i];
|
||||
break;
|
||||
}
|
||||
|
||||
if (boardDescription == NULL) {
|
||||
/* Board type not identified default to MB851A also to support legacy boards */
|
||||
boardDescription = (BoardResourcesType *) &MB851A;
|
||||
}
|
||||
return;
|
||||
}
|
||||
BoardResourcesType const *halBoardGetDescription(void)
|
||||
{
|
||||
return boardDescription;
|
||||
}
|
||||
|
||||
void halBoardPowerDown(void)
|
||||
{
|
||||
/* Set everything to input value */
|
||||
GPIO_PACFGL = (GPIOCFG_IN <<PA0_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PA1_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PA2_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PA3_CFG_BIT);
|
||||
GPIO_PACFGH = (GPIOCFG_IN <<PA4_CFG_BIT)| /* PTI EN */
|
||||
(GPIOCFG_IN <<PA5_CFG_BIT)| /* PTI_DATA */
|
||||
(GPIOCFG_IN <<PA6_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PA7_CFG_BIT);
|
||||
GPIO_PBCFGL = (GPIOCFG_IN <<PB0_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PB1_CFG_BIT)| /* Uart TX */
|
||||
(GPIOCFG_IN <<PB2_CFG_BIT)| /* Uart RX */
|
||||
(GPIOCFG_IN <<PB3_CFG_BIT);
|
||||
GPIO_PBCFGH = (GPIOCFG_IN <<PB4_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PB5_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PB6_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PB7_CFG_BIT);
|
||||
GPIO_PCCFGL = (GPIOCFG_IN <<PC0_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PC1_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PC2_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PC3_CFG_BIT);
|
||||
GPIO_PCCFGH = (GPIOCFG_IN <<PC4_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PC5_CFG_BIT)|
|
||||
#ifdef EMBERZNET_HAL
|
||||
(CFG_C6 <<PC6_CFG_BIT)| /* OSC32K */
|
||||
(CFG_C7 <<PC7_CFG_BIT); /* OSC32K */
|
||||
#else
|
||||
(GPIOCFG_IN <<PC6_CFG_BIT)| /* OSC32K */
|
||||
(GPIOCFG_IN <<PC7_CFG_BIT); /* OSC32K */
|
||||
#endif
|
||||
|
||||
#ifdef EMBERZNET_HAL
|
||||
/* Configure GPIO for BUTTONSs */
|
||||
{
|
||||
ButtonResourceType *buttons = (ButtonResourceType *) boardDescription->io->buttons;
|
||||
int8u i;
|
||||
for (i = 0; i < boardDescription->buttons; i++) {
|
||||
halGpioConfig(PORTx_PIN(buttons[i].gpioPort, buttons[i].gpioPin), GPIOCFG_IN_PUD);
|
||||
halGpioSet(PORTx_PIN(buttons[i].gpioPort, buttons[i].gpioPin), GPIOOUT_PULLUP);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/* Configure GPIO for power amplifier */
|
||||
if (boardDescription->flags & BOARD_HAS_PA) {
|
||||
/* SiGe Standby */
|
||||
halGpioConfig(PORTB_PIN(6), GPIOCFG_OUT);
|
||||
halGpioSet(PORTB_PIN(6), 0);
|
||||
}
|
||||
|
||||
}
|
||||
void halBoardPowerUp(void)
|
||||
{
|
||||
/* Set everything to input value */
|
||||
GPIO_PACFGL = (GPIOCFG_IN <<PA0_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PA1_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PA2_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PA3_CFG_BIT);
|
||||
GPIO_PACFGH = (GPIOCFG_IN <<PA4_CFG_BIT)| /* PTI EN */
|
||||
(GPIOCFG_IN <<PA5_CFG_BIT)| /* PTI_DATA */
|
||||
(GPIOCFG_IN <<PA6_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PA7_CFG_BIT);
|
||||
GPIO_PBCFGL = (GPIOCFG_IN <<PB0_CFG_BIT)|
|
||||
(GPIOCFG_OUT_ALT <<PB1_CFG_BIT)| /* Uart TX */
|
||||
(GPIOCFG_IN <<PB2_CFG_BIT)| /* Uart RX */
|
||||
(GPIOCFG_IN <<PB3_CFG_BIT);
|
||||
GPIO_PBCFGH = (GPIOCFG_IN <<PB4_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PB5_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PB6_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PB7_CFG_BIT);
|
||||
GPIO_PCCFGL = (GPIOCFG_IN <<PC0_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PC1_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PC2_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PC3_CFG_BIT);
|
||||
GPIO_PCCFGH = (GPIOCFG_IN <<PC4_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PC5_CFG_BIT)|
|
||||
#ifdef EMBERZNET_HAL
|
||||
(CFG_C6 <<PC6_CFG_BIT)| /* OSC32K */
|
||||
(CFG_C7 <<PC7_CFG_BIT); /* OSC32K */
|
||||
#else
|
||||
(GPIOCFG_IN <<PC6_CFG_BIT)| /* OSC32K */
|
||||
(GPIOCFG_IN <<PC7_CFG_BIT); /* OSC32K */
|
||||
#endif
|
||||
|
||||
/* Configure GPIO for I2C access */
|
||||
if ((boardDescription->flags & BOARD_HAS_MEMS) || (boardDescription->flags & BOARD_HAS_EEPROM)) {
|
||||
halGpioConfig(PORTA_PIN(1), GPIOCFG_OUT_ALT_OD);
|
||||
halGpioConfig(PORTA_PIN(2), GPIOCFG_OUT_ALT_OD);
|
||||
}
|
||||
/* Configure GPIO for ADC access (temp sensor) */
|
||||
if (boardDescription->flags & BOARD_HAS_TEMP_SENSOR) {
|
||||
halGpioConfig(PORTx_PIN(boardDescription->temperatureSensor->gpioPort,
|
||||
boardDescription->temperatureSensor->gpioPin),
|
||||
GPIOCFG_ANALOG);
|
||||
}
|
||||
/* Configure GPIO for LEDs */
|
||||
{
|
||||
LedResourceType *leds = (LedResourceType *) boardDescription->io->leds;
|
||||
int8u i;
|
||||
for (i = 0; i < boardDescription->leds; i++) {
|
||||
/* LED default off */
|
||||
halGpioConfig(PORTx_PIN(leds[i].gpioPort, leds[i].gpioPin), GPIOCFG_OUT);
|
||||
halGpioSet(PORTx_PIN(leds[i].gpioPort, leds[i].gpioPin), 1);
|
||||
}
|
||||
}
|
||||
/* Configure GPIO for BUTTONSs */
|
||||
{
|
||||
ButtonResourceType *buttons = (ButtonResourceType *) boardDescription->io->buttons;
|
||||
int8u i;
|
||||
for (i = 0; i < boardDescription->buttons; i++) {
|
||||
halGpioConfig(PORTx_PIN(buttons[i].gpioPort, buttons[i].gpioPin), GPIOCFG_IN_PUD);
|
||||
halGpioSet(PORTx_PIN(buttons[i].gpioPort, buttons[i].gpioPin), GPIOOUT_PULLUP);
|
||||
}
|
||||
}
|
||||
|
||||
/* Configure GPIO for power amplifier */
|
||||
if (boardDescription->flags & BOARD_HAS_PA) {
|
||||
/* SiGe Ant Sel (default ceramic antenna) */
|
||||
halGpioConfig(PORTB_PIN(5), GPIOCFG_OUT);
|
||||
halGpioSet(PORTB_PIN(5), 1);
|
||||
/* SiGe Standby (default out of standby) */
|
||||
halGpioConfig(PORTB_PIN(6), GPIOCFG_OUT);
|
||||
halGpioSet(PORTB_PIN(6), 1);
|
||||
/* SiGe LNA (default LNA off )*/
|
||||
halGpioConfig(PORTB_PIN(7), GPIOCFG_OUT);
|
||||
halGpioSet(PORTB_PIN(7), 0);
|
||||
/* SiGe nTX Active */
|
||||
halGpioConfig(PORTC_PIN(5), GPIOCFG_OUT_ALT);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#ifdef TEST_COMMANDS
|
||||
#include <stdio.h>
|
||||
void printLeds (LedResourceType *leds)
|
||||
{
|
||||
while (leds->name != NULL) {
|
||||
printf ("Led %s (port:%s, bit:%d)\r\n", leds->name, PORT_NAME(leds->gpioPort), leds->gpioPin);
|
||||
leds++;
|
||||
}
|
||||
}
|
||||
|
||||
void printButtons (ButtonResourceType *buttons)
|
||||
{
|
||||
while (buttons->name != NULL) {
|
||||
printf ("Button %s (port:%s, bit:%d)\r\n", buttons->name, PORT_NAME(buttons->gpioPort), buttons->gpioPin);
|
||||
buttons++;
|
||||
}
|
||||
}
|
||||
|
||||
void boardPrintStringDescription(void)
|
||||
{
|
||||
int8u i = 0;
|
||||
|
||||
while (boardList[i] != NULL) {
|
||||
if ((boardDescription == boardList[i]) || (boardDescription == NULL)) {
|
||||
BoardResourcesType *ptr = boardList[i];
|
||||
printf ("*************************************\r\n");
|
||||
printf ("Board name = %s\r\n", ptr->name);
|
||||
printf ("*************************************\r\n");
|
||||
printLeds(ptr->leds);
|
||||
printButtons(ptr->buttons);
|
||||
if (ptr->mems) {
|
||||
printf ("MEMS = %s\r\n", ptr->mems->name);
|
||||
}
|
||||
if (ptr->temperatureSensor) {
|
||||
printf ("Temp sensor = %s, port:%s, pin:%d, adcFix:%s\r\n",
|
||||
ptr->temperatureSensor->name,
|
||||
PORT_NAME(ptr->temperatureSensor->gpioPort),
|
||||
ptr->temperatureSensor->gpioPin,
|
||||
ptr->temperatureSensor->adcFix ? "Yes" : "No"
|
||||
);
|
||||
}
|
||||
printf ("EEProm:%s\r\n", ptr->EEProm ? "Yes" : "No");
|
||||
printf ("PC i/f:%s\r\n", ptr->FTDInotSTM32 ? "FTDI" : "STM32F");
|
||||
printf ("Power Amplifier:%s\r\n", ptr->PowerAmplifier ? "Yes" : "No");
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
|
@ -12,18 +12,25 @@
|
|||
|
||||
void halInitButton(void)
|
||||
{
|
||||
/* Set GPIO pin to PUD (input pull-up or pull-down) for button S1 */
|
||||
halGpioConfig(BUTTON_S1,GPIOCFG_IN_PUD);
|
||||
/* Set the button S1 gpio pin to pull-up */
|
||||
BUTTON_S1_OUTPUT_GPIO |= GPIOOUT_PULLUP << BUTTON_S1_GPIO_PIN;
|
||||
int8u i;
|
||||
/* Configure GPIO for BUTTONSs */
|
||||
ButtonResourceType *buttons = (ButtonResourceType *) boardDescription->io->buttons;
|
||||
for (i = 0; i < boardDescription->buttons; i++) {
|
||||
halGpioConfig(PORTx_PIN(buttons[i].gpioPort, buttons[i].gpioPin), GPIOCFG_IN_PUD);
|
||||
halGpioSet(PORTx_PIN(buttons[i].gpioPort, buttons[i].gpioPin), GPIOOUT_PULLUP);
|
||||
}
|
||||
}/* end halInitButton() */
|
||||
|
||||
|
||||
int8u halGetButtonStatus(HalBoardButton button)
|
||||
{
|
||||
if (button == BUTTON_S1)
|
||||
return (BUTTON_S1_INPUT_GPIO & (1<<BUTTON_S1_GPIO_PIN)) ? BUTTON_RELEASED : BUTTON_PRESSED;
|
||||
else
|
||||
return BUTTON_UNKNOWN;
|
||||
int8u port = (button >> 3) & 0xf;
|
||||
int8u pin = button & 0x7;
|
||||
|
||||
if (button != DUMMY_BUTTON)
|
||||
{
|
||||
return (BUTTON_INPUT_GPIO(port) & (1 << pin)) ? BUTTON_RELEASED : BUTTON_PRESSED;
|
||||
}
|
||||
return BUTTON_UNKNOWN;
|
||||
}/* end halGetButtonStatus()*/
|
||||
|
||||
|
|
|
@ -22,13 +22,17 @@
|
|||
#error Improper PLATFORM_HEADER
|
||||
#endif
|
||||
|
||||
#define GCC_VERSION (__GNUC__ * 10000 \
|
||||
+ __GNUC_MINOR__ * 100 \
|
||||
+ __GNUC_PATCHLEVEL__)
|
||||
|
||||
#if GCC_VERSION < 40302
|
||||
#error Only GNU C version later than 4.3.2 are supported
|
||||
#endif
|
||||
#if (__GNUC__ < 4)
|
||||
#error Only GNU C versions later than 4.3.2 are supported
|
||||
#elif (__GNUC__ == 4)
|
||||
#if (__GNUC_MINOR__ < 3)
|
||||
#error Only GNU C versions later than 4.3.2 are supported
|
||||
#elif (__GNUC_MINOR__ == 3)
|
||||
#if (__GNUC_PATCHLEVEL__ < 2)
|
||||
#error Only GNU C versions later than 4.3.2 are supported
|
||||
#endif
|
||||
#endif
|
||||
#endif // __GNUC__
|
||||
|
||||
|
||||
#ifndef DOXYGEN_SHOULD_SKIP_THIS
|
||||
|
@ -36,6 +40,7 @@
|
|||
#include <stdarg.h>
|
||||
#if defined (CORTEXM3_STM32W108)
|
||||
#include "micro/cortexm3/stm32w108/regs.h"
|
||||
#include "micro/cortexm3/stm32w108/stm32w108_type.h"
|
||||
#else
|
||||
#error Unknown CORTEXM3 micro
|
||||
#endif
|
||||
|
@ -169,6 +174,16 @@ typedef unsigned int PointerType;
|
|||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Set the application start and end address.
|
||||
* This are useful to detect whether an image is for bootloader mode or not.
|
||||
* This can be used also to clone image to another node via bootloader.
|
||||
*/
|
||||
#define APPLICATION_IMAGE_START ((u32) &__ApplicationFlashStart)
|
||||
#define APPLICATION_IMAGE_END ((u32) &__ApplicationFlashEnd)
|
||||
extern char __ApplicationFlashStart;
|
||||
extern char __ApplicationFlashEnd;
|
||||
|
||||
/**
|
||||
* @brief Macro to reset the watchdog timer. Note: be very very
|
||||
* careful when using this as you can easily get into an infinite loop if you
|
||||
|
@ -252,6 +267,9 @@ void halInternalResetWatchDog(void);
|
|||
#define VAR_AT_SEGMENT(__variableDeclaration, __segmentName) \
|
||||
__variableDeclaration __attribute__ ((section (__segmentName)))
|
||||
|
||||
#define ALIGN_VAR(__variableDeclaration, alignment) \
|
||||
__variableDeclaration __attribute__ ((aligned(alignment)))
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//@} // end of Miscellaneous Macros
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -33,6 +33,9 @@
|
|||
#include <stdarg.h>
|
||||
#if defined (CORTEXM3_STM32W108)
|
||||
#include "micro/cortexm3/stm32w108/regs.h"
|
||||
#include "micro/cortexm3/stm32w108/stm32w108_type.h"
|
||||
#elif defined (CORTEXM3_STM32F103)
|
||||
#include "stm32f10x.h"
|
||||
#else
|
||||
#error Unknown CORTEXM3 micro
|
||||
#endif
|
||||
|
@ -163,6 +166,15 @@ typedef unsigned int PointerType;
|
|||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Set the application start and end address.
|
||||
* This are useful to detect whether an image is for bootloader mode or not.
|
||||
* This can be used also to clone image to another node via bootloader.
|
||||
*/
|
||||
#define APPLICATION_IMAGE_START ((u32) __section_begin("FLASH_IMAGE"))
|
||||
#define APPLICATION_IMAGE_END ((u32) __section_end ("FLASH_IMAGE"))
|
||||
|
||||
|
||||
/**
|
||||
* @brief Macro to reset the watchdog timer. Note: be very very
|
||||
* careful when using this as you can easily get into an infinite loop if you
|
||||
|
@ -247,6 +259,11 @@ void halInternalResetWatchDog(void);
|
|||
#define VAR_AT_SEGMENT(__variableDeclaration, __segmentName) \
|
||||
__variableDeclaration @ __segmentName
|
||||
|
||||
#define _QUOTEME(a) #a
|
||||
#define QUOTEME(a) _QUOTEME(a)
|
||||
#define ALIGN_VAR(__variableDeclaration, alignment) _Pragma(QUOTEME(data_alignment=alignment)) \
|
||||
__variableDeclaration
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//@} // end of Miscellaneous Macros
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -290,6 +307,8 @@ void halInternalResetWatchDog(void);
|
|||
#pragma segment=__TEXTRW__
|
||||
#pragma segment=__FAT__
|
||||
#pragma segment=__NVM__
|
||||
// Special pragma to get the application image start and end address
|
||||
#pragma segment="FLASH_IMAGE"
|
||||
/**@} */
|
||||
|
||||
//A utility function for inserting barrier instructions. These
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
|
||||
|
||||
|
||||
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_SCANF -D _SMALL_PRINTF -D INTEGER_ONLY -Os -ffunction-sections -mlittle-endian
|
||||
#
|
||||
AROPTS = cq
|
||||
|
||||
SOURCE_DIR = src
|
||||
SOURCE_FILES = small_mprec.c syscalls.c \
|
||||
_SP_printf.c _SP_vfprintf.c _SP_puts.c _SP_sprintf.c _SP_snprintf.c\
|
||||
small_dtoa.c small_wcsrtombs.c small_wcrtomb.c small_wctomb_r.c \
|
||||
scanf.c small_vfsscanf.c sscanf.c small_strtod.c
|
||||
|
||||
|
||||
vpath %.c $(SOURCE_DIR)
|
||||
|
||||
|
||||
SOURCE_OBJS = ${patsubst %.c,%.o,$(SOURCE_FILES)}
|
||||
|
||||
|
||||
LIB = e_stdio_intonly_thumb2.a
|
||||
|
||||
|
||||
|
||||
all: clean $(LIB)
|
||||
|
||||
clean:
|
||||
rm -f $(SOURCE_OBJS) $(LIB)
|
||||
|
||||
|
||||
%.a: $(SOURCE_OBJS)
|
||||
$(AR) $(AROPTS) $@ $^
|
||||
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
#define _SMALL_PRINFT
|
||||
|
||||
#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 */
|
|
@ -1,43 +0,0 @@
|
|||
#include <stdio.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)
|
||||
{
|
||||
#if 1 //VC090825: cleaner and faster version
|
||||
int len = 0;
|
||||
while ( str && (*str) )
|
||||
{
|
||||
__io_putchar ( *(str++) );
|
||||
len++;
|
||||
}
|
||||
#else //VC090825: cleaner, lighter and faster version
|
||||
int len = strlen ( str );
|
||||
_SMALL_PRINTF_puts(str, len, 0) ;
|
||||
#endif //VC090825: cleaner, lighter and faster version
|
||||
__io_putchar ( '\n' );
|
||||
return len;
|
||||
}
|
||||
|
|
@ -1,124 +0,0 @@
|
|||
/*
|
||||
* 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
|
||||
|
||||
|
|
@ -1,393 +0,0 @@
|
|||
/*
|
||||
* 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
|
||||
|
||||
|
File diff suppressed because it is too large
Load diff
|
@ -1,32 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* %W% (Berkeley) %G%
|
||||
*/
|
||||
|
||||
/*
|
||||
* Floating point scanf/printf (input/output) definitions.
|
||||
*/
|
||||
|
||||
#ifdef _NO_LONGDBL
|
||||
/* 11-bit exponent (VAX G floating point) is 308 decimal digits */
|
||||
#define MAXEXP 308
|
||||
#else /* !_NO_LONGDBL */
|
||||
/* 15-bit exponent (Intel extended floating point) is 4932 decimal digits */
|
||||
#define MAXEXP 4932
|
||||
#endif /* !_NO_LONGDBL */
|
||||
/* 128 bit fraction takes up 39 decimal digits; max reasonable precision */
|
||||
#define MAXFRACT 39
|
|
@ -1,38 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* %W% (Berkeley) %G% */
|
||||
#include <_ansi.h>
|
||||
|
||||
/*
|
||||
* I/O descriptors for __sfvwrite().
|
||||
*/
|
||||
struct __siov {
|
||||
_CONST _PTR iov_base;
|
||||
size_t iov_len;
|
||||
};
|
||||
struct __suio {
|
||||
struct __siov *uio_iov;
|
||||
int uio_iovcnt;
|
||||
int uio_resid;
|
||||
};
|
||||
|
||||
|
||||
extern int _EXFUN(__sfvwrite,(FILE *, struct __suio *));
|
||||
extern int _EXFUN(__swsetup,(FILE *));
|
||||
|
||||
|
|
@ -1,89 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* %W% (UofMD/Berkeley) %G%
|
||||
*/
|
||||
|
||||
/*
|
||||
* Information local to this implementation of stdio,
|
||||
* in particular, macros and private variables.
|
||||
*/
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <stdarg.h>
|
||||
#include <reent.h>
|
||||
#include <unistd.h>
|
||||
|
||||
extern int _EXFUN(__svfscanf_r,(struct _reent *,FILE *, _CONST char *,va_list));
|
||||
extern FILE *_EXFUN(__sfp,(struct _reent *));
|
||||
extern int _EXFUN(__sflags,(struct _reent *,_CONST char*, int*));
|
||||
extern int _EXFUN(__srefill,(FILE *));
|
||||
extern _READ_WRITE_RETURN_TYPE _EXFUN(__sread,(void *, char *, int));
|
||||
extern _READ_WRITE_RETURN_TYPE _EXFUN(__swrite,(void *, char const *, int));
|
||||
extern _fpos_t _EXFUN(__sseek,(void *, _fpos_t, int));
|
||||
extern int _EXFUN(__sclose,(void *));
|
||||
extern int _EXFUN(__stextmode,(int));
|
||||
extern void _EXFUN(__sinit,(struct _reent *));
|
||||
extern void _EXFUN(_cleanup_r,(struct _reent *));
|
||||
extern void _EXFUN(__smakebuf,(FILE *));
|
||||
extern int _EXFUN(_fwalk,(struct _reent *, int (*)(FILE *)));
|
||||
struct _glue * _EXFUN(__sfmoreglue,(struct _reent *,int n));
|
||||
extern int _EXFUN(__srefill,(FILE *fp));
|
||||
|
||||
/* Called by the main entry point fns to ensure stdio has been initialized. */
|
||||
|
||||
#define CHECK_INIT(fp) \
|
||||
do \
|
||||
{ \
|
||||
if (!_REENT->__sdidinit) \
|
||||
__sinit (_REENT); \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
/* Return true iff the given FILE cannot be written now. */
|
||||
|
||||
#define cantwrite(fp) \
|
||||
((((fp)->_flags & __SWR) == 0 || (fp)->_bf._base == NULL) && \
|
||||
__swsetup(fp))
|
||||
|
||||
/* Test whether the given stdio file has an active ungetc buffer;
|
||||
release such a buffer, without restoring ordinary unread data. */
|
||||
|
||||
#define HASUB(fp) ((fp)->_ub._base != NULL)
|
||||
#define FREEUB(fp) { \
|
||||
if ((fp)->_ub._base != (fp)->_ubuf) \
|
||||
_free_r(_REENT, (char *)(fp)->_ub._base); \
|
||||
(fp)->_ub._base = NULL; \
|
||||
}
|
||||
|
||||
/* Test for an fgetline() buffer. */
|
||||
|
||||
#define HASLB(fp) ((fp)->_lb._base != NULL)
|
||||
#define FREELB(fp) { _free_r(_REENT,(char *)(fp)->_lb._base); (fp)->_lb._base = NULL; }
|
||||
|
||||
/* WARNING: _dcvt is defined in the stdlib directory, not here! */
|
||||
|
||||
char *_EXFUN(_dcvt,(struct _reent *, char *, double, int, int, char, int));
|
||||
char *_EXFUN(_sicvt,(char *, short, char));
|
||||
char *_EXFUN(_icvt,(char *, int, char));
|
||||
char *_EXFUN(_licvt,(char *, long, char));
|
||||
#ifdef __GNUC__
|
||||
char *_EXFUN(_llicvt,(char *, long long, char));
|
||||
#endif
|
||||
|
||||
#define CVT_BUF_SIZE 128
|
||||
|
||||
#define NDYNAMIC 4 /* add four more whenever necessary */
|
|
@ -1,20 +0,0 @@
|
|||
#ifndef _MBCTYPE_H_
|
||||
|
||||
#define _MBCTYPE_H_
|
||||
|
||||
/* escape character used for JIS encoding */
|
||||
#define ESC_CHAR 0x1b
|
||||
|
||||
/* functions used to support SHIFT_JIS, EUC-JP, and JIS multibyte encodings */
|
||||
|
||||
int _EXFUN(_issjis1, (int c));
|
||||
int _EXFUN(_issjis2, (int c));
|
||||
int _EXFUN(_iseucjp, (int c));
|
||||
int _EXFUN(_isjis, (int c));
|
||||
|
||||
#define _issjis1(c) (((c) >= 0x81 && (c) <= 0x9f) || ((c) >= 0xe0 && (c) <= 0xef))
|
||||
#define _issjis2(c) (((c) >= 0x40 && (c) <= 0x7e) || ((c) >= 0x80 && (c) <= 0xfc))
|
||||
#define _iseucjp(c) ((c) >= 0xa1 && (c) <= 0xfe)
|
||||
#define _isjis(c) ((c) >= 0x21 && (c) <= 0x7e)
|
||||
|
||||
#endif /* _MBCTYPE_H_ */
|
|
@ -1,79 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <stdio.h>
|
||||
#include "local.h"
|
||||
|
||||
#ifdef _HAVE_STDC
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
#include <varargs.h>
|
||||
#endif
|
||||
|
||||
#ifndef _REENT_ONLY
|
||||
|
||||
int
|
||||
#ifdef _HAVE_STDC
|
||||
scanf (const char *fmt, ...)
|
||||
#else
|
||||
scanf (fmt, va_alist)
|
||||
char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
|
||||
//_REENT_SMALL_CHECK_INIT(_stdin_r (_REENT));
|
||||
#ifdef _HAVE_STDC
|
||||
va_start (ap, fmt);
|
||||
#else
|
||||
va_start (ap);
|
||||
#endif
|
||||
ret = __svfscanf_r (_REENT, _stdin_r (_REENT), fmt, ap);
|
||||
va_end (ap);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* !_REENT_ONLY */
|
||||
|
||||
int
|
||||
#ifdef _HAVE_STDC
|
||||
_scanf_r (struct _reent *ptr, const char *fmt, ...)
|
||||
#else
|
||||
_scanf_r (ptr, fmt, va_alist)
|
||||
struct _reent *ptr;
|
||||
char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
|
||||
//_REENT_SMALL_CHECK_INIT(_stdin_r (ptr));
|
||||
#ifdef _HAVE_STDC
|
||||
va_start (ap, fmt);
|
||||
#else
|
||||
va_start (ap);
|
||||
#endif
|
||||
ret = __svfscanf_r (ptr, _stdin_r (ptr), fmt, ap);
|
||||
va_end (ap);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -1,383 +0,0 @@
|
|||
/****************************************************************
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
|
||||
#include <ieeefp.h>
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
#include <errno.h>
|
||||
#include <sys/config.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef __IEEE_LITTLE_ENDIAN
|
||||
#define IEEE_8087
|
||||
#endif
|
||||
|
||||
#ifdef __IEEE_BIG_ENDIAN
|
||||
#define IEEE_MC68k
|
||||
#endif
|
||||
|
||||
#ifdef __Z8000__
|
||||
#define Just_16
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
#include "stdio.h"
|
||||
#define Bug(x) {fprintf(stderr, "%s\n", x); exit(1);}
|
||||
#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
|
||||
|
||||
/* 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
|
||||
|
||||
/* The following definition of Storeinc is appropriate for MIPS processors.
|
||||
* An alternative that might be better on some machines is
|
||||
* #define Storeinc(a,b,c) (*a++ = b << 16 | c & 0xffff)
|
||||
*/
|
||||
#if defined (__IEEE_BYTES_LITTLE_ENDIAN) + defined (IEEE_8087) + defined (VAX)
|
||||
#define Storeinc(a,b,c) (((unsigned short *)a)[1] = (unsigned short)b, \
|
||||
((unsigned short *)a)[0] = (unsigned short)c, a++)
|
||||
#else
|
||||
#define Storeinc(a,b,c) (((unsigned short *)a)[0] = (unsigned short)b, \
|
||||
((unsigned short *)a)[1] = (unsigned short)c, a++)
|
||||
#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
|
||||
|
||||
#ifndef IEEE_Arith
|
||||
#define ROUND_BIASED
|
||||
#endif
|
||||
|
||||
#ifdef RND_PRODQUOT
|
||||
#define rounded_product(a,b) a = rnd_prod(a, b)
|
||||
#define rounded_quotient(a,b) a = rnd_quot(a, b)
|
||||
#ifdef KR_headers
|
||||
extern double rnd_prod(), rnd_quot();
|
||||
#else
|
||||
extern double rnd_prod(double, double), rnd_quot(double, double);
|
||||
#endif
|
||||
#else
|
||||
#define rounded_product(a,b) a *= b
|
||||
#define rounded_quotient(a,b) a /= b
|
||||
#endif
|
||||
|
||||
#define Big0 (Frac_mask1 | Exp_msk1*(DBL_MAX_EXP+Bias-1))
|
||||
#define Big1 ((__uint32_t)0xffffffffL)
|
||||
|
||||
#ifndef Just_16
|
||||
/* When Pack_32 is not defined, we store 16 bits per 32-bit long.
|
||||
* This makes some inner loops simpler and sometimes saves work
|
||||
* during multiplications, but it often seems to make things slightly
|
||||
* slower. Hence the default is now to store 32 bits per long.
|
||||
*/
|
||||
|
||||
#ifndef Pack_32
|
||||
#define Pack_32
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" double strtod(const char *s00, char **se);
|
||||
extern "C" char *dtoa(double d, int mode, int ndigits,
|
||||
int *decpt, int *sign, char **rve);
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct _Bigint _Bigint;
|
||||
|
||||
#if (defined (_SMALL_PRINTF) || defined(SMALL_SCANF) )
|
||||
#define SMALL_LIB
|
||||
#endif
|
||||
|
||||
#ifdef SMALL_LIB
|
||||
|
||||
|
||||
|
||||
|
||||
#define small_Balloc _small_Balloc
|
||||
#define small_Bfree _small_Bfree
|
||||
#define small_multadd _small_multadd
|
||||
#define small_s2b _small_s2b
|
||||
#define small_lo0bits _small_lo0bits
|
||||
#define small_hi0bits _small_hi0bits
|
||||
#define small_i2b _small_i2b
|
||||
#define small_mult _small_multiply
|
||||
#define small_pow5mult _small_pow5mult
|
||||
#define small_lshift _small_lshift
|
||||
#define small_cmp __small_mcmp
|
||||
#define small_diff __small_mdiff
|
||||
#define small_ulp _small_ulp
|
||||
#define small_b2d _small_b2d
|
||||
#define small_d2b _small_d2b
|
||||
#define small_ratio _small_ratio
|
||||
|
||||
#define small_tens __small_mprec_tens
|
||||
#define small_bigtens __small_mprec_bigtens
|
||||
#define small_tinytens __small_mprec_tinytens
|
||||
|
||||
struct _reent ;
|
||||
double _EXFUN(small_ulp,(double x));
|
||||
double _EXFUN(small_b2d,(_Bigint *a , int *e));
|
||||
_Bigint * _EXFUN(small_multadd,(struct _reent *p, _Bigint *, int, int,_Bigint tab[]));
|
||||
_Bigint * _EXFUN(small_s2b,(struct _reent *, const char*, int, int, __ULong,_Bigint tab[]));
|
||||
_Bigint * _EXFUN(small_i2b,(struct _reent *,int,_Bigint tab[]));
|
||||
_Bigint * _EXFUN(small_mult, (struct _reent *, _Bigint *, _Bigint *,_Bigint tab[]));
|
||||
_Bigint * _EXFUN(small_pow5mult, (struct _reent *, _Bigint *, int k,_Bigint tab[]));
|
||||
int _EXFUN(small_hi0bits,(__ULong));
|
||||
int _EXFUN(small_lo0bits,(__ULong *));
|
||||
_Bigint * _EXFUN(small_d2b,(struct _reent *p, double d, int *e, int *bits,_Bigint tab[]));
|
||||
_Bigint * _EXFUN(small_lshift,(struct _reent *p, _Bigint *b, int k,_Bigint tab[]));
|
||||
_Bigint * _EXFUN(small_diff,(struct _reent *p, _Bigint *a, _Bigint *b,_Bigint tab[]));
|
||||
int _EXFUN(small_cmp,(_Bigint *a, _Bigint *b));
|
||||
|
||||
double _EXFUN(small_ratio,(_Bigint *a, _Bigint *b));
|
||||
#define Bcopy(x,y) memcpy((char *)&x->_sign, (char *)&y->_sign, y->_wds*sizeof(__Long) + 2*sizeof(int))
|
||||
|
||||
#if defined(_DOUBLE_IS_32BITS) && defined(__v800)
|
||||
#define n_bigtens 2
|
||||
#else
|
||||
#define n_bigtens 5
|
||||
#endif
|
||||
|
||||
extern _CONST double small_tinytens[];
|
||||
extern _CONST double small_bigtens[];
|
||||
extern _CONST double small_tens[];
|
||||
|
||||
|
||||
double _EXFUN(_small_mprec_log10,(int));
|
||||
|
||||
|
||||
#else // NO SMALL_LIB
|
||||
|
||||
|
||||
|
||||
#define Balloc _Balloc
|
||||
#define Bfree _Bfree
|
||||
#define multadd _multadd
|
||||
#define s2b _s2b
|
||||
#define lo0bits _lo0bits
|
||||
#define hi0bits _hi0bits
|
||||
#define i2b _i2b
|
||||
#define mult _multiply
|
||||
#define pow5mult _pow5mult
|
||||
#define lshift _lshift
|
||||
#define cmp __mcmp
|
||||
#define diff __mdiff
|
||||
#define ulp _ulp
|
||||
#define b2d _b2d
|
||||
#define d2b _d2b
|
||||
#define ratio _ratio
|
||||
|
||||
#define tens __mprec_tens
|
||||
#define bigtens __mprec_bigtens
|
||||
#define tinytens __mprec_tinytens
|
||||
|
||||
struct _reent ;
|
||||
double _EXFUN(ulp,(double x));
|
||||
double _EXFUN(b2d,(_Bigint *a , int *e));
|
||||
_Bigint * _EXFUN(Balloc,(struct _reent *p, int k));
|
||||
void _EXFUN(Bfree,(struct _reent *p, _Bigint *v));
|
||||
_Bigint * _EXFUN(multadd,(struct _reent *p, _Bigint *, int, int));
|
||||
_Bigint * _EXFUN(s2b,(struct _reent *, const char*, int, int, __ULong));
|
||||
_Bigint * _EXFUN(i2b,(struct _reent *,int));
|
||||
_Bigint * _EXFUN(mult, (struct _reent *, _Bigint *, _Bigint *));
|
||||
_Bigint * _EXFUN(pow5mult, (struct _reent *, _Bigint *, int k));
|
||||
int _EXFUN(hi0bits,(__ULong));
|
||||
int _EXFUN(lo0bits,(__ULong *));
|
||||
_Bigint * _EXFUN(d2b,(struct _reent *p, double d, int *e, int *bits));
|
||||
_Bigint * _EXFUN(lshift,(struct _reent *p, _Bigint *b, int k));
|
||||
_Bigint * _EXFUN(diff,(struct _reent *p, _Bigint *a, _Bigint *b));
|
||||
int _EXFUN(cmp,(_Bigint *a, _Bigint *b));
|
||||
|
||||
double _EXFUN(ratio,(_Bigint *a, _Bigint *b));
|
||||
#define Bcopy(x,y) memcpy((char *)&x->_sign, (char *)&y->_sign, y->_wds*sizeof(__Long) + 2*sizeof(int))
|
||||
|
||||
#if defined(_DOUBLE_IS_32BITS) && defined(__v800)
|
||||
#define n_bigtens 2
|
||||
#else
|
||||
#define n_bigtens 5
|
||||
#endif
|
||||
|
||||
extern _CONST double tinytens[];
|
||||
extern _CONST double bigtens[];
|
||||
extern _CONST double tens[];
|
||||
|
||||
|
||||
double _EXFUN(_mprec_log10,(int));
|
||||
|
||||
#endif
|
|
@ -1,936 +0,0 @@
|
|||
/*
|
||||
FUNCTON
|
||||
<<strtod>>, <<strtof>>---string to double or float
|
||||
|
||||
INDEX
|
||||
strtod
|
||||
INDEX
|
||||
_strtod_r
|
||||
INDEX
|
||||
strtof
|
||||
|
||||
ANSI_SYNOPSIS
|
||||
#include <stdlib.h>
|
||||
double strtod(const char *<[str]>, char **<[tail]>);
|
||||
float strtof(const char *<[str]>, char **<[tail]>);
|
||||
|
||||
double _strtod_r(void *<[reent]>,
|
||||
const char *<[str]>, char **<[tail]>);
|
||||
|
||||
TRAD_SYNOPSIS
|
||||
#include <stdlib.h>
|
||||
double strtod(<[str]>,<[tail]>)
|
||||
char *<[str]>;
|
||||
char **<[tail]>;
|
||||
|
||||
float strtof(<[str]>,<[tail]>)
|
||||
char *<[str]>;
|
||||
char **<[tail]>;
|
||||
|
||||
double _strtod_r(<[reent]>,<[str]>,<[tail]>)
|
||||
char *<[reent]>;
|
||||
char *<[str]>;
|
||||
char **<[tail]>;
|
||||
|
||||
DESCRIPTION
|
||||
The function <<strtod>> parses the character string <[str]>,
|
||||
producing a substring which can be converted to a double
|
||||
value. The substring converted is the longest initial
|
||||
subsequence of <[str]>, beginning with the first
|
||||
non-whitespace character, that has the format:
|
||||
.[+|-]<[digits]>[.][<[digits]>][(e|E)[+|-]<[digits]>]
|
||||
The substring contains no characters if <[str]> is empty, consists
|
||||
entirely of whitespace, or if the first non-whitespace
|
||||
character is something other than <<+>>, <<->>, <<.>>, or a
|
||||
digit. If the substring is empty, no conversion is done, and
|
||||
the value of <[str]> is stored in <<*<[tail]>>>. Otherwise,
|
||||
the substring is converted, and a pointer to the final string
|
||||
(which will contain at least the terminating null character of
|
||||
<[str]>) is stored in <<*<[tail]>>>. If you want no
|
||||
assignment to <<*<[tail]>>>, pass a null pointer as <[tail]>.
|
||||
<<strtof>> is identical to <<strtod>> except for its return type.
|
||||
|
||||
This implementation returns the nearest machine number to the
|
||||
input decimal string. Ties are broken by using the IEEE
|
||||
round-even rule.
|
||||
|
||||
The alternate function <<_strtod_r>> is a reentrant version.
|
||||
The extra argument <[reent]> is a pointer to a reentrancy structure.
|
||||
|
||||
RETURNS
|
||||
<<strtod>> returns the converted substring value, if any. If
|
||||
no conversion could be performed, 0 is returned. If the
|
||||
correct value is out of the range of representable values,
|
||||
plus or minus <<HUGE_VAL>> is returned, and <<ERANGE>> is
|
||||
stored in errno. If the correct value would cause underflow, 0
|
||||
is returned and <<ERANGE>> is stored in errno.
|
||||
|
||||
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
|
||||
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
|
||||
*/
|
||||
|
||||
/****************************************************************
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
|
||||
/* Scanf and printf call both the small_mprec.c file if small_scanf
|
||||
* has not been specfied optimizations concerning small_mprec.c and
|
||||
* call of balloc will be performed anyway for scanf.
|
||||
*/
|
||||
|
||||
#ifdef _SMALL_PRINTF
|
||||
#ifndef SMALL_SCANF
|
||||
#define SMALL_SCANF
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <reent.h>
|
||||
#include <string.h>
|
||||
#include "small_mprec.h"
|
||||
|
||||
double
|
||||
_DEFUN (_strtod_r, (ptr, s00, se),
|
||||
struct _reent *ptr _AND
|
||||
_CONST char *s00 _AND
|
||||
char **se)
|
||||
{
|
||||
int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, dsign, e1, esign, i, j,
|
||||
k, nd, nd0, nf, nz, nz0, sign;
|
||||
long e;
|
||||
_CONST char *s, *s0, *s1;
|
||||
double aadj, aadj1, adj;
|
||||
long L;
|
||||
unsigned long z;
|
||||
__ULong y;
|
||||
union double_union rv, rv0;
|
||||
|
||||
_Bigint *bb, *bb1, *bd, *bd0, *bs, *delta;
|
||||
|
||||
#ifdef SMALL_SCANF
|
||||
|
||||
/*
|
||||
* For the SMALL_SCANF implementation for floating points numbers :
|
||||
* - To avoid the call of allocator we defined a buffer for each variable : instead of taking the adress
|
||||
* provided by Balloc variables are initialized to the beginning of the array.
|
||||
* - For some variables many buffers have been declared, in fact for each call of small_lshift we used a
|
||||
* buffer that has not been used at the moment
|
||||
* - This buffers are used in the call of function declared in small_mprec.h
|
||||
* To have more informations look at small_mprec.c
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#define BUF_SIZE 32
|
||||
#define BUF_LSHIFT_SIZE 40
|
||||
|
||||
_Bigint tab_bb[BUF_LSHIFT_SIZE],tab_bb1[BUF_SIZE],tab_bd[BUF_SIZE],tab_bd0[BUF_SIZE],tab_bs[BUF_LSHIFT_SIZE], tab_delta[BUF_LSHIFT_SIZE];
|
||||
_Bigint tab_bblshift[BUF_LSHIFT_SIZE],tab_bslshift[BUF_LSHIFT_SIZE], tab_deltalshift[BUF_LSHIFT_SIZE],tab_bdlshift[BUF_LSHIFT_SIZE];
|
||||
#endif
|
||||
|
||||
sign = nz0 = nz = 0;
|
||||
rv.d = 0.;
|
||||
for (s = s00;; s++)
|
||||
switch (*s)
|
||||
{
|
||||
case '-':
|
||||
sign = 1;
|
||||
/* no break */
|
||||
case '+':
|
||||
if (*++s)
|
||||
goto break2;
|
||||
/* no break */
|
||||
case 0:
|
||||
s = s00;
|
||||
goto ret;
|
||||
case '\t':
|
||||
case '\n':
|
||||
case '\v':
|
||||
case '\f':
|
||||
case '\r':
|
||||
case ' ':
|
||||
continue;
|
||||
default:
|
||||
goto break2;
|
||||
}
|
||||
break2:
|
||||
if (*s == '0')
|
||||
{
|
||||
nz0 = 1;
|
||||
while (*++s == '0');
|
||||
if (!*s)
|
||||
goto ret;
|
||||
}
|
||||
s0 = s;
|
||||
y = z = 0;
|
||||
for (nd = nf = 0; (c = *s) >= '0' && c <= '9'; nd++, s++)
|
||||
if (nd < 9)
|
||||
y = 10 * y + c - '0';
|
||||
else if (nd < 16)
|
||||
z = 10 * z + c - '0';
|
||||
nd0 = nd;
|
||||
if (c == '.')
|
||||
{
|
||||
c = *++s;
|
||||
if (!nd)
|
||||
{
|
||||
for (; c == '0'; c = *++s)
|
||||
nz++;
|
||||
if (c > '0' && c <= '9')
|
||||
{
|
||||
s0 = s;
|
||||
nf += nz;
|
||||
nz = 0;
|
||||
goto have_dig;
|
||||
}
|
||||
goto dig_done;
|
||||
}
|
||||
for (; c >= '0' && c <= '9'; c = *++s)
|
||||
{
|
||||
have_dig:
|
||||
nz++;
|
||||
if (c -= '0')
|
||||
{
|
||||
nf += nz;
|
||||
for (i = 1; i < nz; i++)
|
||||
if (nd++ < 9)
|
||||
y *= 10;
|
||||
else if (nd <= DBL_DIG + 1)
|
||||
z *= 10;
|
||||
if (nd++ < 9)
|
||||
y = 10 * y + c;
|
||||
else if (nd <= DBL_DIG + 1)
|
||||
z = 10 * z + c;
|
||||
nz = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
dig_done:
|
||||
e = 0;
|
||||
if (c == 'e' || c == 'E')
|
||||
{
|
||||
if (!nd && !nz && !nz0)
|
||||
{
|
||||
s = s00;
|
||||
goto ret;
|
||||
}
|
||||
s00 = s;
|
||||
esign = 0;
|
||||
switch (c = *++s)
|
||||
{
|
||||
case '-':
|
||||
esign = 1;
|
||||
case '+':
|
||||
c = *++s;
|
||||
}
|
||||
if (c >= '0' && c <= '9')
|
||||
{
|
||||
while (c == '0')
|
||||
c = *++s;
|
||||
if (c > '0' && c <= '9')
|
||||
{
|
||||
e = c - '0';
|
||||
s1 = s;
|
||||
while ((c = *++s) >= '0' && c <= '9')
|
||||
e = 10 * e + c - '0';
|
||||
if (s - s1 > 8)
|
||||
/* Avoid confusion from exponents
|
||||
* so large that e might overflow.
|
||||
*/
|
||||
e = 9999999L;
|
||||
if (esign)
|
||||
e = -e;
|
||||
}
|
||||
else
|
||||
e = 0;
|
||||
}
|
||||
else
|
||||
s = s00;
|
||||
}
|
||||
if (!nd)
|
||||
{
|
||||
if (!nz && !nz0)
|
||||
s = s00;
|
||||
goto ret;
|
||||
}
|
||||
e1 = e -= nf;
|
||||
|
||||
/* Now we have nd0 digits, starting at s0, followed by a
|
||||
* decimal point, followed by nd-nd0 digits. The number we're
|
||||
* after is the integer represented by those digits times
|
||||
* 10**e */
|
||||
|
||||
if (!nd0)
|
||||
nd0 = nd;
|
||||
k = nd < DBL_DIG + 1 ? nd : DBL_DIG + 1;
|
||||
rv.d = y;
|
||||
if (k > 9)
|
||||
#ifndef SMALL_SCANF
|
||||
rv.d = tens[k - 9] * rv.d + z;
|
||||
#else
|
||||
rv.d = small_tens[k - 9] * rv.d + z;
|
||||
#endif
|
||||
bd0 = 0;
|
||||
if (nd <= DBL_DIG
|
||||
#ifndef RND_PRODQUOT
|
||||
&& FLT_ROUNDS == 1
|
||||
#endif
|
||||
)
|
||||
{
|
||||
if (!e)
|
||||
goto ret;
|
||||
if (e > 0)
|
||||
{
|
||||
if (e <= Ten_pmax)
|
||||
{
|
||||
#ifdef VAX
|
||||
goto vax_ovfl_check;
|
||||
#else
|
||||
#ifndef SMALL_SCANF
|
||||
/* rv.d = */ rounded_product (rv.d, tens[e]);
|
||||
#else
|
||||
rounded_product (rv.d, small_tens[e]);
|
||||
#endif
|
||||
goto ret;
|
||||
#endif
|
||||
}
|
||||
i = DBL_DIG - nd;
|
||||
if (e <= Ten_pmax + i)
|
||||
{
|
||||
/* A fancier test would sometimes let us do
|
||||
* this for larger i values.
|
||||
*/
|
||||
e -= i;
|
||||
#ifndef SMALL_SCANF
|
||||
rv.d *= tens[i];
|
||||
#else
|
||||
rv.d *= small_tens[i];
|
||||
#endif
|
||||
#ifdef VAX
|
||||
/* VAX exponent range is so narrow we must
|
||||
* worry about overflow here...
|
||||
*/
|
||||
vax_ovfl_check:
|
||||
word0 (rv) -= P * Exp_msk1;
|
||||
#ifndef SMALL_SCANF
|
||||
/* rv.d = */ rounded_product (rv.d, tens[e]);
|
||||
#else
|
||||
/* rv.d = */ rounded_product (rv.d, small_tens[e]);
|
||||
#endif
|
||||
if ((word0 (rv) & Exp_mask)
|
||||
> Exp_msk1 * (DBL_MAX_EXP + Bias - 1 - P))
|
||||
goto ovfl;
|
||||
word0 (rv) += P * Exp_msk1;
|
||||
#else
|
||||
#ifndef SMALL_SCANF
|
||||
/* rv.d = */ rounded_product (rv.d, tens[e]);
|
||||
#else
|
||||
/* rv.d = */ rounded_product (rv.d, small_tens[e]);
|
||||
#endif
|
||||
#endif
|
||||
goto ret;
|
||||
}
|
||||
}
|
||||
#ifndef Inaccurate_Divide
|
||||
else if (e >= -Ten_pmax)
|
||||
{
|
||||
#ifndef SMALL_SCANF
|
||||
/* rv.d = */ rounded_quotient (rv.d, tens[-e]);
|
||||
#else
|
||||
/* rv.d = */ rounded_quotient (rv.d, small_tens[-e]);
|
||||
#endif
|
||||
goto ret;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
e1 += nd - k;
|
||||
|
||||
/* Get starting approximation = rv.d * 10**e1 */
|
||||
|
||||
if (e1 > 0)
|
||||
{
|
||||
if ((i = e1 & 15) != 0)
|
||||
#ifndef SMALL_SCANF
|
||||
rv.d *= tens[i];
|
||||
#else
|
||||
rv.d *= small_tens[i];
|
||||
#endif
|
||||
if (e1 &= ~15)
|
||||
{
|
||||
if (e1 > DBL_MAX_10_EXP)
|
||||
{
|
||||
ovfl:
|
||||
ptr->_errno = ERANGE;
|
||||
#ifdef _HAVE_STDC
|
||||
rv.d = HUGE_VAL;
|
||||
#else
|
||||
/* Can't trust HUGE_VAL */
|
||||
#ifdef IEEE_Arith
|
||||
word0 (rv) = Exp_mask;
|
||||
#ifndef _DOUBLE_IS_32BITS
|
||||
word1 (rv) = 0;
|
||||
#endif
|
||||
#else
|
||||
word0 (rv) = Big0;
|
||||
#ifndef _DOUBLE_IS_32BITS
|
||||
word1 (rv) = Big1;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
if (bd0)
|
||||
goto retfree;
|
||||
goto ret;
|
||||
}
|
||||
if (e1 >>= 4)
|
||||
{
|
||||
for (j = 0; e1 > 1; j++, e1 >>= 1)
|
||||
if (e1 & 1)
|
||||
#ifndef SMALL_SCANF
|
||||
rv.d *= bigtens[j];
|
||||
#else
|
||||
rv.d *= small_bigtens[j];
|
||||
#endif
|
||||
|
||||
/* The last multiplication could overflow. */
|
||||
word0 (rv) -= P * Exp_msk1;
|
||||
#ifndef SMALL_SCANF
|
||||
rv.d *= bigtens[j];
|
||||
#else
|
||||
rv.d *= small_bigtens[j];
|
||||
#endif
|
||||
|
||||
if ((z = word0 (rv) & Exp_mask)
|
||||
> Exp_msk1 * (DBL_MAX_EXP + Bias - P))
|
||||
goto ovfl;
|
||||
if (z > Exp_msk1 * (DBL_MAX_EXP + Bias - 1 - P))
|
||||
{
|
||||
/* set to largest number */
|
||||
/* (Can't trust DBL_MAX) */
|
||||
word0 (rv) = Big0;
|
||||
#ifndef _DOUBLE_IS_32BITS
|
||||
word1 (rv) = Big1;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
word0 (rv) += P * Exp_msk1;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else if (e1 < 0)
|
||||
{
|
||||
e1 = -e1;
|
||||
if ((i = e1 & 15) != 0)
|
||||
#ifndef SMALL_SCANF
|
||||
rv.d /= tens[i];
|
||||
#else
|
||||
rv.d /= small_tens[i];
|
||||
#endif
|
||||
if (e1 &= ~15)
|
||||
{
|
||||
e1 >>= 4;
|
||||
if (e1 >= 1 << n_bigtens)
|
||||
goto undfl;
|
||||
for (j = 0; e1 > 1; j++, e1 >>= 1)
|
||||
if (e1 & 1)
|
||||
#ifndef SMALL_SCANF
|
||||
rv.d *= tinytens[j];
|
||||
/* The last multiplication could underflow. */
|
||||
rv0.d = rv.d;
|
||||
rv.d *=tinytens[j];
|
||||
#else
|
||||
rv.d *= small_tinytens[j];
|
||||
/* The last multiplication could underflow. */
|
||||
rv0.d = rv.d;
|
||||
rv.d *= small_tinytens[j];
|
||||
#endif
|
||||
if (!rv.d)
|
||||
{
|
||||
rv.d = 2. * rv0.d;
|
||||
#ifndef SMALL_SCANF
|
||||
rv.d *= tinytens[j];
|
||||
#else
|
||||
rv.d *= small_tinytens[j];
|
||||
#endif
|
||||
if (!rv.d)
|
||||
{
|
||||
undfl:
|
||||
rv.d = 0.;
|
||||
ptr->_errno = ERANGE;
|
||||
if (bd0)
|
||||
goto retfree;
|
||||
goto ret;
|
||||
}
|
||||
#ifndef _DOUBLE_IS_32BITS
|
||||
word0 (rv) = Tiny0;
|
||||
word1 (rv) = Tiny1;
|
||||
#else
|
||||
word0 (rv) = Tiny1;
|
||||
#endif
|
||||
/* The refinement below will clean
|
||||
* this approximation up.
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Now the hard part -- adjusting rv to the correct value.*/
|
||||
|
||||
/* Put digits into bd: true value = bd * 10^e */
|
||||
#ifndef SMALL_SCANF
|
||||
bd0 = s2b (ptr, s0, nd0, nd, y);
|
||||
#else
|
||||
bd0 = small_s2b(ptr,s0, nd0, nd, y, &tab_bd0[0]);
|
||||
#endif
|
||||
|
||||
for (;;)
|
||||
{
|
||||
#ifndef SMALL_SCANF
|
||||
bd = Balloc (ptr, bd0->_k);
|
||||
#else
|
||||
bd = &tab_bd[0];
|
||||
bd->_k = bd0->_k;
|
||||
bd->_maxwds = 1 << (bd0->_k);
|
||||
bd->_sign = bd->_wds =0;
|
||||
|
||||
#endif
|
||||
Bcopy (bd, bd0);
|
||||
#ifndef SMALL_SCANF
|
||||
bb = d2b (ptr, rv.d, &bbe, &bbbits); /* rv.d = bb * 2^bbe */
|
||||
bs = i2b (ptr, 1);
|
||||
#else
|
||||
bb = small_d2b (ptr, rv.d, &bbe, &bbbits, &tab_bb[0]); /* rv.d = bb * 2^bbe */
|
||||
bs = small_i2b (ptr, 1, &tab_bs[0]);
|
||||
#endif
|
||||
if (e >= 0)
|
||||
{
|
||||
bb2 = bb5 = 0;
|
||||
bd2 = bd5 = e;
|
||||
}
|
||||
else
|
||||
{
|
||||
bb2 = bb5 = -e;
|
||||
bd2 = bd5 = 0;
|
||||
}
|
||||
if (bbe >= 0)
|
||||
bb2 += bbe;
|
||||
else
|
||||
bd2 -= bbe;
|
||||
bs2 = bb2;
|
||||
#ifdef Sudden_Underflow
|
||||
#ifdef IBM
|
||||
j = 1 + 4 * P - 3 - bbbits + ((bbe + bbbits - 1) & 3);
|
||||
#else
|
||||
j = P + 1 - bbbits;
|
||||
#endif
|
||||
#else
|
||||
i = bbe + bbbits - 1; /* logb(rv.d) */
|
||||
if (i < Emin) /* denormal */
|
||||
j = bbe + (P - Emin);
|
||||
else
|
||||
j = P + 1 - bbbits;
|
||||
#endif
|
||||
bb2 += j;
|
||||
bd2 += j;
|
||||
i = bb2 < bd2 ? bb2 : bd2;
|
||||
if (i > bs2)
|
||||
i = bs2;
|
||||
if (i > 0)
|
||||
{
|
||||
bb2 -= i;
|
||||
bd2 -= i;
|
||||
bs2 -= i;
|
||||
}
|
||||
if (bb5 > 0)
|
||||
{
|
||||
#ifndef SMALL_SCANF
|
||||
bs = pow5mult (ptr, bs, bb5);
|
||||
bb1 = mult (ptr, bs, bb);
|
||||
Bfree (ptr, bb);
|
||||
bb = bb1;
|
||||
#else
|
||||
if (bs == &tab_bs[0]){
|
||||
bs = small_pow5mult (ptr, bs, bb5,&tab_bslshift[0]);
|
||||
}
|
||||
else{
|
||||
bs = small_pow5mult (ptr, bs, bb5,&tab_bs[0]);
|
||||
}
|
||||
bb1 = small_mult (ptr, bs, bb,&tab_bb1[0]);
|
||||
bb = bb1;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#ifndef SMALL_SCANF
|
||||
if (bb2 > 0)
|
||||
bb = lshift (ptr, bb, bb2);
|
||||
if (bd5 > 0)
|
||||
bd = pow5mult (ptr, bd, bd5);
|
||||
if (bd2 > 0)
|
||||
bd = lshift (ptr, bd, bd2);
|
||||
if (bs2 > 0)
|
||||
bs = lshift (ptr, bs, bs2);
|
||||
delta = diff (ptr, bb, bd);
|
||||
dsign = delta->_sign;
|
||||
delta->_sign = 0;
|
||||
i = cmp (delta, bs);
|
||||
#else
|
||||
if (bb2 > 0){
|
||||
if (bb == &tab_bb[0] ){
|
||||
bb = small_lshift (ptr, bb, bb2,&tab_bblshift[0]);
|
||||
}
|
||||
else {
|
||||
bb = small_lshift (ptr, bb, bb2,&tab_bblshift[0]);
|
||||
}
|
||||
}
|
||||
if (bd5 > 0){
|
||||
if (bd == &tab_bd[0]){
|
||||
bd = small_pow5mult (ptr, bd, bd5, &tab_bdlshift[0]);
|
||||
}
|
||||
else{
|
||||
bd = small_pow5mult (ptr, bd, bd5, &tab_bd[0]);
|
||||
}
|
||||
}
|
||||
if (bd2 > 0){
|
||||
if (bd == &tab_bd[0] ){
|
||||
bd = small_lshift (ptr, bb, bd2,&tab_bdlshift[0]);
|
||||
}
|
||||
else {
|
||||
bd = small_lshift (ptr, bd, bd2,&tab_bd[0]);
|
||||
}
|
||||
}
|
||||
if (bs2 > 0){
|
||||
if ( bs == &tab_bs[0] ){
|
||||
bs = small_lshift (ptr, bs, bs2,&tab_bslshift[0]);
|
||||
}
|
||||
else{
|
||||
bs = small_lshift (ptr, bs, bs2,&tab_bs[0]);
|
||||
}
|
||||
}
|
||||
|
||||
delta = small_diff (ptr, bb, bd,&tab_delta[0]);
|
||||
dsign = delta->_sign;
|
||||
delta->_sign = 0;
|
||||
i = small_cmp (delta, bs);
|
||||
|
||||
#endif
|
||||
if (i < 0)
|
||||
{
|
||||
/* Error is less than half an ulp -- check for
|
||||
* special case of mantissa a power of two.
|
||||
*/
|
||||
if (dsign || word1 (rv) || word0 (rv) & Bndry_mask)
|
||||
break;
|
||||
|
||||
#ifndef SMALL_SCANF
|
||||
delta = lshift (ptr, delta, Log2P);
|
||||
if (cmp (delta, bs) > 0)
|
||||
goto drop_down;
|
||||
#else
|
||||
if (delta == &tab_delta[0]){
|
||||
delta = small_lshift (ptr, delta, Log2P,&tab_deltalshift[0]);
|
||||
}
|
||||
else{
|
||||
delta = small_lshift (ptr, delta, Log2P,&tab_delta[0]);
|
||||
}
|
||||
if (small_cmp (delta, bs) > 0)
|
||||
goto drop_down;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
if (i == 0)
|
||||
{
|
||||
/* exactly half-way between */
|
||||
if (dsign)
|
||||
{
|
||||
if ((word0 (rv) & Bndry_mask1) == Bndry_mask1
|
||||
&& word1 (rv) == 0xffffffff)
|
||||
{
|
||||
/*boundary case -- increment exponent*/
|
||||
word0 (rv) = (word0 (rv) & Exp_mask)
|
||||
+ Exp_msk1
|
||||
#ifdef IBM
|
||||
| Exp_msk1 >> 4
|
||||
#endif
|
||||
;
|
||||
#ifndef _DOUBLE_IS_32BITS
|
||||
word1 (rv) = 0;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (!(word0 (rv) & Bndry_mask) && !word1 (rv))
|
||||
{
|
||||
drop_down:
|
||||
/* boundary case -- decrement exponent */
|
||||
#ifdef Sudden_Underflow
|
||||
L = word0 (rv) & Exp_mask;
|
||||
#ifdef IBM
|
||||
if (L < Exp_msk1)
|
||||
#else
|
||||
if (L <= Exp_msk1)
|
||||
#endif
|
||||
goto undfl;
|
||||
L -= Exp_msk1;
|
||||
#else
|
||||
L = (word0 (rv) & Exp_mask) - Exp_msk1;
|
||||
#endif
|
||||
word0 (rv) = L | Bndry_mask1;
|
||||
#ifndef _DOUBLE_IS_32BITS
|
||||
word1 (rv) = 0xffffffff;
|
||||
#endif
|
||||
#ifdef IBM
|
||||
goto cont;
|
||||
#else
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
#ifndef ROUND_BIASED
|
||||
if (!(word1 (rv) & LSB))
|
||||
break;
|
||||
#endif
|
||||
if (dsign)
|
||||
#ifndef SMALL_SCANF
|
||||
rv.d += ulp (rv.d);
|
||||
#else
|
||||
rv.d += small_ulp (rv.d);
|
||||
#endif
|
||||
#ifndef ROUND_BIASED
|
||||
else
|
||||
{
|
||||
#ifndef SMALL_SCANF
|
||||
rv.d -= ulp (rv.d);
|
||||
#else
|
||||
rv.d -= small_ulp (rv.d);
|
||||
#endif
|
||||
#ifndef Sudden_Underflow
|
||||
if (!rv.d)
|
||||
goto undfl;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
#ifndef SMALL_SCANF
|
||||
if ((aadj = ratio (delta, bs)) <= 2.)
|
||||
{
|
||||
#else
|
||||
if ((aadj = small_ratio (delta, bs)) <= 2.)
|
||||
{
|
||||
#endif
|
||||
if (dsign)
|
||||
aadj = aadj1 = 1.;
|
||||
else if (word1 (rv) || word0 (rv) & Bndry_mask)
|
||||
{
|
||||
#ifndef Sudden_Underflow
|
||||
if (word1 (rv) == Tiny1 && !word0 (rv))
|
||||
goto undfl;
|
||||
#endif
|
||||
aadj = 1.;
|
||||
aadj1 = -1.;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* special case -- power of FLT_RADIX to be */
|
||||
/* rounded down... */
|
||||
|
||||
if (aadj < 2. / FLT_RADIX)
|
||||
aadj = 1. / FLT_RADIX;
|
||||
else
|
||||
aadj *= 0.5;
|
||||
aadj1 = -aadj;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
aadj *= 0.5;
|
||||
aadj1 = dsign ? aadj : -aadj;
|
||||
#ifdef Check_FLT_ROUNDS
|
||||
switch (FLT_ROUNDS)
|
||||
{
|
||||
case 2: /* towards +infinity */
|
||||
aadj1 -= 0.5;
|
||||
break;
|
||||
case 0: /* towards 0 */
|
||||
case 3: /* towards -infinity */
|
||||
aadj1 += 0.5;
|
||||
}
|
||||
#else
|
||||
if (FLT_ROUNDS == 0)
|
||||
aadj1 += 0.5;
|
||||
#endif
|
||||
}
|
||||
y = word0 (rv) & Exp_mask;
|
||||
|
||||
/* Check for overflow */
|
||||
|
||||
if (y == Exp_msk1 * (DBL_MAX_EXP + Bias - 1))
|
||||
{
|
||||
rv0.d = rv.d;
|
||||
word0 (rv) -= P * Exp_msk1;
|
||||
#ifndef SMALL_SCANF
|
||||
adj = aadj1 * ulp (rv.d);
|
||||
#else
|
||||
adj = aadj1 * small_ulp (rv.d);
|
||||
#endif
|
||||
rv.d += adj;
|
||||
if ((word0 (rv) & Exp_mask) >=
|
||||
Exp_msk1 * (DBL_MAX_EXP + Bias - P))
|
||||
{
|
||||
if (word0 (rv0) == Big0 && word1 (rv0) == Big1)
|
||||
goto ovfl;
|
||||
#ifdef _DOUBLE_IS_32BITS
|
||||
word0 (rv) = Big1;
|
||||
#else
|
||||
word0 (rv) = Big0;
|
||||
word1 (rv) = Big1;
|
||||
#endif
|
||||
goto cont;
|
||||
}
|
||||
else
|
||||
word0 (rv) += P * Exp_msk1;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef Sudden_Underflow
|
||||
if ((word0 (rv) & Exp_mask) <= P * Exp_msk1)
|
||||
{
|
||||
rv0.d = rv.d;
|
||||
word0 (rv) += P * Exp_msk1;
|
||||
#ifndef SMALL_SCANF
|
||||
adj = aadj1 * ulp (rv.d);
|
||||
#else
|
||||
adj = aadj1 * small_ulp (rv.d);
|
||||
#endif
|
||||
rv.d += adj;
|
||||
#ifdef IBM
|
||||
if ((word0 (rv) & Exp_mask) < P * Exp_msk1)
|
||||
#else
|
||||
if ((word0 (rv) & Exp_mask) <= P * Exp_msk1)
|
||||
#endif
|
||||
{
|
||||
if (word0 (rv0) == Tiny0
|
||||
&& word1 (rv0) == Tiny1)
|
||||
goto undfl;
|
||||
word0 (rv) = Tiny0;
|
||||
word1 (rv) = Tiny1;
|
||||
goto cont;
|
||||
}
|
||||
else
|
||||
word0 (rv) -= P * Exp_msk1;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifndef SMALL_SCANF
|
||||
adj = aadj1 * ulp (rv.d);
|
||||
#else
|
||||
adj = aadj1 * small_ulp (rv.d);
|
||||
#endif
|
||||
rv.d += adj;
|
||||
}
|
||||
#else
|
||||
/* Compute adj so that the IEEE rounding rules will
|
||||
* correctly round rv.d + adj in some half-way cases.
|
||||
* If rv.d * ulp(rv.d) is denormalized (i.e.,
|
||||
* y <= (P-1)*Exp_msk1), we must adjust aadj to avoid
|
||||
* trouble from bits lost to denormalization;
|
||||
* example: 1.2e-307 .
|
||||
*/
|
||||
if (y <= (P - 1) * Exp_msk1 && aadj >= 1.)
|
||||
{
|
||||
aadj1 = (double) (int) (aadj + 0.5);
|
||||
if (!dsign)
|
||||
aadj1 = -aadj1;
|
||||
}
|
||||
#ifndef SMALL_SCANF
|
||||
adj = aadj1 * ulp (rv.d);
|
||||
#else
|
||||
adj = aadj1 * small_ulp (rv.d);
|
||||
rv.d += adj;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
z = word0 (rv) & Exp_mask;
|
||||
if (y == z)
|
||||
{
|
||||
/* Can we stop now? */
|
||||
L = aadj;
|
||||
aadj -= L;
|
||||
/* The tolerances below are conservative. */
|
||||
if (dsign || word1 (rv) || word0 (rv) & Bndry_mask)
|
||||
{
|
||||
if (aadj < .4999999 || aadj > .5000001)
|
||||
break;
|
||||
}
|
||||
else if (aadj < .4999999 / FLT_RADIX)
|
||||
break;
|
||||
}
|
||||
cont:
|
||||
#ifndef SMALL_SCANF
|
||||
Bfree (ptr, bb);
|
||||
Bfree (ptr, bd);
|
||||
Bfree (ptr, bs);
|
||||
Bfree (ptr, delta);
|
||||
#else
|
||||
;
|
||||
#endif
|
||||
}
|
||||
retfree:
|
||||
#ifndef SMALL_SCANF
|
||||
Bfree (ptr, bb);
|
||||
Bfree (ptr, bd);
|
||||
Bfree (ptr, bs);
|
||||
Bfree (ptr, bd0);
|
||||
Bfree (ptr, delta);
|
||||
#endif
|
||||
ret:
|
||||
if (se)
|
||||
*se = (char *) s;
|
||||
return sign ? -rv.d : rv.d;
|
||||
}
|
||||
|
||||
#ifndef NO_REENT
|
||||
|
||||
double
|
||||
_DEFUN (strtod, (s00, se),
|
||||
_CONST char *s00 _AND char **se)
|
||||
{
|
||||
return _strtod_r (_REENT, s00, se);
|
||||
}
|
||||
|
||||
float
|
||||
_DEFUN (strtof, (s00, se),
|
||||
_CONST char *s00 _AND
|
||||
char **se)
|
||||
{
|
||||
return (float)_strtod_r (_REENT, s00, se);
|
||||
}
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load diff
|
@ -1,59 +0,0 @@
|
|||
#include <reent.h>
|
||||
#include <wchar.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#if defined( _SMALL_PRINTF ) || defined(SMALL_SCANF)
|
||||
#define _ASCII_CAR
|
||||
#endif
|
||||
|
||||
size_t
|
||||
_DEFUN (_wcrtomb_r, (ptr, s, wc, ps),
|
||||
struct _reent *ptr _AND
|
||||
char *s _AND
|
||||
wchar_t wc _AND
|
||||
mbstate_t *ps)
|
||||
{
|
||||
|
||||
#ifndef _ASCII_CAR
|
||||
int retval = 0;
|
||||
char buf[10];
|
||||
|
||||
|
||||
#ifdef MB_CAPABLE
|
||||
if (ps == NULL)
|
||||
{
|
||||
_REENT_CHECK_MISC(ptr);
|
||||
ps = &(_REENT_WCRTOMB_STATE(ptr));
|
||||
}
|
||||
#endif
|
||||
|
||||
if (s == NULL)
|
||||
retval = _wctomb_r (ptr, buf, L'\0', ps);
|
||||
else
|
||||
retval = _wctomb_r (ptr, s, wc, ps);
|
||||
|
||||
if (retval == -1)
|
||||
{
|
||||
ps->__count = 0;
|
||||
ptr->_errno = EILSEQ;
|
||||
return (size_t)(-1);
|
||||
}
|
||||
else
|
||||
return (size_t)retval;
|
||||
#endif
|
||||
int retval = 1 ;
|
||||
return (size_t)retval;
|
||||
}
|
||||
|
||||
#ifndef _REENT_ONLY
|
||||
size_t
|
||||
_DEFUN (wcrtomb, (s, wc, ps),
|
||||
char *s _AND
|
||||
wchar_t wc _AND
|
||||
mbstate_t *ps)
|
||||
{
|
||||
return _wcrtomb_r (_REENT, s, wc, ps);
|
||||
}
|
||||
#endif /* !_REENT_ONLY */
|
|
@ -1,97 +0,0 @@
|
|||
#include <reent.h>
|
||||
#include <wchar.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#if defined( _SMALL_PRINTF ) || defined(SMALL_SCANF)
|
||||
#define _ASCII_CAR
|
||||
#endif
|
||||
|
||||
size_t
|
||||
_DEFUN (_wcsrtombs_r, (r, dst, src, len, ps),
|
||||
struct _reent *r _AND
|
||||
char *dst _AND
|
||||
const wchar_t **src _AND
|
||||
size_t len _AND
|
||||
mbstate_t *ps)
|
||||
{
|
||||
|
||||
|
||||
char *ptr = dst;
|
||||
char buff[10];
|
||||
wchar_t *pwcs;
|
||||
size_t n;
|
||||
int i;
|
||||
|
||||
#ifdef MB_CAPABLE
|
||||
if (ps == NULL)
|
||||
{
|
||||
_REENT_CHECK_MISC(r);
|
||||
ps = &(_REENT_WCSRTOMBS_STATE(r));
|
||||
}
|
||||
#endif
|
||||
|
||||
/* If no dst pointer, treat len as maximum possible value. */
|
||||
if (dst == NULL)
|
||||
len = (size_t)-1;
|
||||
|
||||
n = 0;
|
||||
pwcs = (wchar_t *)(*src);
|
||||
|
||||
while (n < len)
|
||||
{
|
||||
int count = ps->__count;
|
||||
wint_t wch = ps->__value.__wch;
|
||||
#ifndef _ASCII_CAR
|
||||
int bytes = _wcrtomb_r (r, buff, *pwcs, ps);
|
||||
if (bytes == -1)
|
||||
{
|
||||
r->_errno = EILSEQ;
|
||||
ps->__count = 0;
|
||||
return (size_t)-1;
|
||||
}
|
||||
#else
|
||||
int bytes = 1 ;
|
||||
#endif
|
||||
|
||||
if (n <= len - bytes && bytes < len)
|
||||
{
|
||||
n += bytes;
|
||||
if (dst)
|
||||
{
|
||||
for (i = 0; i < bytes; ++i)
|
||||
*ptr++ = buff[i];
|
||||
++(*src);
|
||||
}
|
||||
if (*pwcs++ == 0x00)
|
||||
{
|
||||
if (dst)
|
||||
*src = NULL;
|
||||
ps->__count = 0;
|
||||
return n - 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* not enough room, we must back up state to before _wctomb_r call */
|
||||
ps->__count = count;
|
||||
ps->__value.__wch = wch;
|
||||
len = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
#ifndef _REENT_ONLY
|
||||
size_t
|
||||
_DEFUN (wcsrtombs, (dst, src, len, ps),
|
||||
char *dst _AND
|
||||
const wchar_t **src _AND
|
||||
size_t len _AND
|
||||
mbstate_t *ps)
|
||||
{
|
||||
return _wcsrtombs_r (_REENT, dst, src, len, ps);
|
||||
}
|
||||
#endif /* !_REENT_ONLY */
|
|
@ -1,188 +0,0 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
#include <locale.h>
|
||||
#include "mbctype.h"
|
||||
|
||||
/* The following function concerns caracter coded in more than 0ne byte. For our small_printf we considered only
|
||||
caracters coded in ASCII and therefore all our caracters are coded in 8 bits (One byte)
|
||||
If you need the following treatment because caracter that you use are coded in more than one byte
|
||||
comment the three following lines */
|
||||
|
||||
#if defined( _SMALL_PRINTF ) || defined(SMALL_SCANF)
|
||||
#define _ASCII_CAR
|
||||
#endif
|
||||
|
||||
|
||||
/* for some conversions, we use the __count field as a place to store a state value */
|
||||
#define __state __count
|
||||
|
||||
#ifndef _ASCII_CAR
|
||||
extern char __lc_ctype[12];
|
||||
#endif
|
||||
int
|
||||
_DEFUN (_wctomb_r, (r, s, wchar, state),
|
||||
struct _reent *r _AND
|
||||
char *s _AND
|
||||
wchar_t wchar _AND
|
||||
mbstate_t *state)
|
||||
{
|
||||
|
||||
#ifndef _ASCII_CAR
|
||||
|
||||
if (strlen (__lc_ctype) <= 1)
|
||||
{ /* fall-through */ }
|
||||
else if (!strcmp (__lc_ctype, "C-UTF-8"))
|
||||
{
|
||||
if (s == NULL)
|
||||
return 0; /* UTF-8 encoding is not state-dependent */
|
||||
|
||||
if (wchar <= 0x7f)
|
||||
{
|
||||
*s = wchar;
|
||||
return 1;
|
||||
}
|
||||
else if (wchar >= 0x80 && wchar <= 0x7ff)
|
||||
{
|
||||
*s++ = 0xc0 | ((wchar & 0x7c0) >> 6);
|
||||
*s = 0x80 | (wchar & 0x3f);
|
||||
return 2;
|
||||
}
|
||||
else if (wchar >= 0x800 && wchar <= 0xffff)
|
||||
{
|
||||
/* UTF-16 surrogates -- must not occur in normal UCS-4 data */
|
||||
if (wchar >= 0xd800 && wchar <= 0xdfff)
|
||||
return -1;
|
||||
|
||||
*s++ = 0xe0 | ((wchar & 0xf000) >> 12);
|
||||
*s++ = 0x80 | ((wchar & 0xfc0) >> 6);
|
||||
*s = 0x80 | (wchar & 0x3f);
|
||||
return 3;
|
||||
}
|
||||
else if (wchar >= 0x10000 && wchar <= 0x1fffff)
|
||||
{
|
||||
*s++ = 0xf0 | ((wchar & 0x1c0000) >> 18);
|
||||
*s++ = 0x80 | ((wchar & 0x3f000) >> 12);
|
||||
*s++ = 0x80 | ((wchar & 0xfc0) >> 6);
|
||||
*s = 0x80 | (wchar & 0x3f);
|
||||
return 4;
|
||||
}
|
||||
else if (wchar >= 0x200000 && wchar <= 0x3ffffff)
|
||||
{
|
||||
*s++ = 0xf8 | ((wchar & 0x3000000) >> 24);
|
||||
*s++ = 0x80 | ((wchar & 0xfc0000) >> 18);
|
||||
*s++ = 0x80 | ((wchar & 0x3f000) >> 12);
|
||||
*s++ = 0x80 | ((wchar & 0xfc0) >> 6);
|
||||
*s = 0x80 | (wchar & 0x3f);
|
||||
return 5;
|
||||
}
|
||||
else if (wchar >= 0x4000000 && wchar <= 0x7fffffff)
|
||||
{
|
||||
*s++ = 0xfc | ((wchar & 0x40000000) >> 30);
|
||||
*s++ = 0x80 | ((wchar & 0x3f000000) >> 24);
|
||||
*s++ = 0x80 | ((wchar & 0xfc0000) >> 18);
|
||||
*s++ = 0x80 | ((wchar & 0x3f000) >> 12);
|
||||
*s++ = 0x80 | ((wchar & 0xfc0) >> 6);
|
||||
*s = 0x80 | (wchar & 0x3f);
|
||||
return 6;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
else if (!strcmp (__lc_ctype, "C-SJIS"))
|
||||
{
|
||||
unsigned char char2 = (unsigned char)wchar;
|
||||
unsigned char char1 = (unsigned char)(wchar >> 8);
|
||||
|
||||
if (s == NULL)
|
||||
return 0; /* not state-dependent */
|
||||
|
||||
if (char1 != 0x00)
|
||||
{
|
||||
/* first byte is non-zero..validate multi-byte char */
|
||||
if (_issjis1(char1) && _issjis2(char2))
|
||||
{
|
||||
*s++ = (char)char1;
|
||||
*s = (char)char2;
|
||||
return 2;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (!strcmp (__lc_ctype, "C-EUCJP"))
|
||||
{
|
||||
unsigned char char2 = (unsigned char)wchar;
|
||||
unsigned char char1 = (unsigned char)(wchar >> 8);
|
||||
|
||||
if (s == NULL)
|
||||
return 0; /* not state-dependent */
|
||||
|
||||
if (char1 != 0x00)
|
||||
{
|
||||
/* first byte is non-zero..validate multi-byte char */
|
||||
if (_iseucjp (char1) && _iseucjp (char2))
|
||||
{
|
||||
*s++ = (char)char1;
|
||||
*s = (char)char2;
|
||||
return 2;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (!strcmp (__lc_ctype, "C-JIS"))
|
||||
{
|
||||
int cnt = 0;
|
||||
unsigned char char2 = (unsigned char)wchar;
|
||||
unsigned char char1 = (unsigned char)(wchar >> 8);
|
||||
|
||||
if (s == NULL)
|
||||
return 1; /* state-dependent */
|
||||
|
||||
if (char1 != 0x00)
|
||||
{
|
||||
/* first byte is non-zero..validate multi-byte char */
|
||||
if (_isjis (char1) && _isjis (char2))
|
||||
{
|
||||
if (state->__state == 0)
|
||||
{
|
||||
/* must switch from ASCII to JIS state */
|
||||
state->__state = 1;
|
||||
*s++ = ESC_CHAR;
|
||||
*s++ = '$';
|
||||
*s++ = 'B';
|
||||
cnt = 3;
|
||||
}
|
||||
*s++ = (char)char1;
|
||||
*s = (char)char2;
|
||||
return cnt + 2;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (state->__state != 0)
|
||||
{
|
||||
/* must switch from JIS to ASCII state */
|
||||
state->__state = 0;
|
||||
*s++ = ESC_CHAR;
|
||||
*s++ = '(';
|
||||
*s++ = 'B';
|
||||
cnt = 3;
|
||||
}
|
||||
*s = (char)char2;
|
||||
return cnt + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (s == NULL)
|
||||
return 0;
|
||||
#endif
|
||||
/* otherwise we are dealing with a single byte character */
|
||||
*s = (char) wchar;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -1,453 +0,0 @@
|
|||
/*
|
||||
* 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
|
||||
<<scanf>>, <<fscanf>>, <<sscanf>>---scan and format input
|
||||
|
||||
INDEX
|
||||
scanf
|
||||
INDEX
|
||||
fscanf
|
||||
INDEX
|
||||
sscanf
|
||||
|
||||
ANSI_SYNOPSIS
|
||||
#include <stdio.h>
|
||||
|
||||
int scanf(const char *<[format]> [, <[arg]>, ...]);
|
||||
int fscanf(FILE *<[fd]>, const char *<[format]> [, <[arg]>, ...]);
|
||||
int sscanf(const char *<[str]>, const char *<[format]>
|
||||
[, <[arg]>, ...]);
|
||||
|
||||
int _scanf_r(struct _reent *<[ptr]>, const char *<[format]> [, <[arg]>, ...]);
|
||||
int _fscanf_r(struct _reent *<[ptr]>, FILE *<[fd]>, const char *<[format]> [, <[arg]>, ...]);
|
||||
int _sscanf_r(struct _reent *<[ptr]>, const char *<[str]>, const char *<[format]>
|
||||
[, <[arg]>, ...]);
|
||||
|
||||
|
||||
TRAD_SYNOPSIS
|
||||
#include <stdio.h>
|
||||
|
||||
int scanf(<[format]> [, <[arg]>, ...])
|
||||
char *<[format]>;
|
||||
|
||||
int fscanf(<[fd]>, <[format]> [, <[arg]>, ...]);
|
||||
FILE *<[fd]>;
|
||||
char *<[format]>;
|
||||
|
||||
int sscanf(<[str]>, <[format]> [, <[arg]>, ...]);
|
||||
char *<[str]>;
|
||||
char *<[format]>;
|
||||
|
||||
int _scanf_r(<[ptr]>, <[format]> [, <[arg]>, ...])
|
||||
struct _reent *<[ptr]>;
|
||||
char *<[format]>;
|
||||
|
||||
int _fscanf_r(<[ptr]>, <[fd]>, <[format]> [, <[arg]>, ...]);
|
||||
struct _reent *<[ptr]>;
|
||||
FILE *<[fd]>;
|
||||
char *<[format]>;
|
||||
|
||||
int _sscanf_r(<[ptr]>, <[str]>, <[format]> [, <[arg]>, ...]);
|
||||
struct _reent *<[ptr]>;
|
||||
char *<[str]>;
|
||||
char *<[format]>;
|
||||
|
||||
|
||||
DESCRIPTION
|
||||
<<scanf>> scans a series of input fields from standard input,
|
||||
one character at a time. Each field is interpreted according to
|
||||
a format specifier passed to <<scanf>> in the format string at
|
||||
<<*<[format]>>>. <<scanf>> stores the interpreted input from
|
||||
each field at the address passed to it as the corresponding argument
|
||||
following <[format]>. You must supply the same number of
|
||||
format specifiers and address arguments as there are input fields.
|
||||
|
||||
There must be sufficient address arguments for the given format
|
||||
specifiers; if not the results are unpredictable and likely
|
||||
disasterous. Excess address arguments are merely ignored.
|
||||
|
||||
<<scanf>> often produces unexpected results if the input diverges from
|
||||
an expected pattern. Since the combination of <<gets>> or <<fgets>>
|
||||
followed by <<sscanf>> is safe and easy, that is the preferred way
|
||||
to be certain that a program is synchronized with input at the end
|
||||
of a line.
|
||||
|
||||
<<fscanf>> and <<sscanf>> are identical to <<scanf>>, other than the
|
||||
source of input: <<fscanf>> reads from a file, and <<sscanf>>
|
||||
from a string.
|
||||
|
||||
The routines <<_scanf_r>>, <<_fscanf_r>>, and <<_sscanf_r>> are reentrant
|
||||
versions of <<scanf>>, <<fscanf>>, and <<sscanf>> that take an additional
|
||||
first argument pointing to a reentrancy structure.
|
||||
|
||||
The string at <<*<[format]>>> is a character sequence composed
|
||||
of zero or more directives. Directives are composed of
|
||||
one or more whitespace characters, non-whitespace characters,
|
||||
and format specifications.
|
||||
|
||||
Whitespace characters are blank (<< >>), tab (<<\t>>), or
|
||||
newline (<<\n>>).
|
||||
When <<scanf>> encounters a whitespace character in the format string
|
||||
it will read (but not store) all consecutive whitespace characters
|
||||
up to the next non-whitespace character in the input.
|
||||
|
||||
Non-whitespace characters are all other ASCII characters except the
|
||||
percent sign (<<%>>). When <<scanf>> encounters a non-whitespace
|
||||
character in the format string it will read, but not store
|
||||
a matching non-whitespace character.
|
||||
|
||||
Format specifications tell <<scanf>> to read and convert characters
|
||||
from the input field into specific types of values, and store then
|
||||
in the locations specified by the address arguments.
|
||||
|
||||
Trailing whitespace is left unread unless explicitly
|
||||
matched in the format string.
|
||||
|
||||
The format specifiers must begin with a percent sign (<<%>>)
|
||||
and have the following form:
|
||||
|
||||
. %[*][<[width]>][<[size]>]<[type]>
|
||||
|
||||
Each format specification begins with the percent character (<<%>>).
|
||||
The other fields are:
|
||||
o+
|
||||
o *
|
||||
an optional marker; if present, it suppresses interpretation and
|
||||
assignment of this input field.
|
||||
|
||||
o <[width]>
|
||||
an optional maximum field width: a decimal integer,
|
||||
which controls the maximum number of characters that
|
||||
will be read before converting the current input field. If the
|
||||
input field has fewer than <[width]> characters, <<scanf>>
|
||||
reads all the characters in the field, and then
|
||||
proceeds with the next field and its format specification.
|
||||
|
||||
If a whitespace or a non-convertable character occurs
|
||||
before <[width]> character are read, the characters up
|
||||
to that character are read, converted, and stored.
|
||||
Then <<scanf>> proceeds to the next format specification.
|
||||
|
||||
o size
|
||||
<<h>>, <<l>>, and <<L>> are optional size characters which
|
||||
override the default way that <<scanf>> interprets the
|
||||
data type of the corresponding argument.
|
||||
|
||||
|
||||
.Modifier Type(s)
|
||||
. hh d, i, o, u, x, n convert input to char,
|
||||
. store in char object
|
||||
.
|
||||
. h d, i, o, u, x, n convert input to short,
|
||||
. store in short object
|
||||
.
|
||||
. h D, I, O, U, X no effect
|
||||
. e, f, c, s, p
|
||||
.
|
||||
. l d, i, o, u, x, n convert input to long,
|
||||
. store in long object
|
||||
.
|
||||
. l e, f, g convert input to double
|
||||
. store in a double object
|
||||
.
|
||||
. l D, I, O, U, X no effect
|
||||
. c, s, p
|
||||
.
|
||||
. ll d, i, o, u, x, n convert to long long,
|
||||
. store in long long
|
||||
.
|
||||
. L d, i, o, u, x, n convert to long long,
|
||||
. store in long long
|
||||
.
|
||||
. L e, f, g, E, G convert to long double,
|
||||
. store in long double
|
||||
.
|
||||
. L all others no effect
|
||||
|
||||
|
||||
o <[type]>
|
||||
|
||||
A character to specify what kind of conversion
|
||||
<<scanf>> performs. Here is a table of the conversion
|
||||
characters:
|
||||
|
||||
o+
|
||||
o %
|
||||
No conversion is done; the percent character (<<%>>) is stored.
|
||||
|
||||
o c
|
||||
Scans one character. Corresponding <[arg]>: <<(char *arg)>>.
|
||||
|
||||
o s
|
||||
Reads a character string into the array supplied.
|
||||
Corresponding <[arg]>: <<(char arg[])>>.
|
||||
|
||||
o [<[pattern]>]
|
||||
Reads a non-empty character string into memory
|
||||
starting at <[arg]>. This area must be large
|
||||
enough to accept the sequence and a
|
||||
terminating null character which will be added
|
||||
automatically. (<[pattern]> is discussed in the paragraph following
|
||||
this table). Corresponding <[arg]>: <<(char *arg)>>.
|
||||
|
||||
o d
|
||||
Reads a decimal integer into the corresponding <[arg]>: <<(int *arg)>>.
|
||||
|
||||
o D
|
||||
Reads a decimal integer into the corresponding
|
||||
<[arg]>: <<(long *arg)>>.
|
||||
|
||||
o o
|
||||
Reads an octal integer into the corresponding <[arg]>: <<(int *arg)>>.
|
||||
|
||||
o O
|
||||
Reads an octal integer into the corresponding <[arg]>: <<(long *arg)>>.
|
||||
|
||||
o u
|
||||
Reads an unsigned decimal integer into the corresponding
|
||||
<[arg]>: <<(unsigned int *arg)>>.
|
||||
|
||||
|
||||
o U
|
||||
Reads an unsigned decimal integer into the corresponding <[arg]>:
|
||||
<<(unsigned long *arg)>>.
|
||||
|
||||
o x,X
|
||||
Read a hexadecimal integer into the corresponding <[arg]>:
|
||||
<<(int *arg)>>.
|
||||
|
||||
o e, f, g
|
||||
Read a floating-point number into the corresponding <[arg]>:
|
||||
<<(float *arg)>>.
|
||||
|
||||
o E, F, G
|
||||
Read a floating-point number into the corresponding <[arg]>:
|
||||
<<(double *arg)>>.
|
||||
|
||||
o i
|
||||
Reads a decimal, octal or hexadecimal integer into the
|
||||
corresponding <[arg]>: <<(int *arg)>>.
|
||||
|
||||
o I
|
||||
Reads a decimal, octal or hexadecimal integer into the
|
||||
corresponding <[arg]>: <<(long *arg)>>.
|
||||
|
||||
o n
|
||||
Stores the number of characters read in the corresponding
|
||||
<[arg]>: <<(int *arg)>>.
|
||||
|
||||
o p
|
||||
Stores a scanned pointer. ANSI C leaves the details
|
||||
to each implementation; this implementation treats
|
||||
<<%p>> exactly the same as <<%U>>. Corresponding
|
||||
<[arg]>: <<(void **arg)>>.
|
||||
o-
|
||||
|
||||
A <[pattern]> of characters surrounded by square brackets can be used
|
||||
instead of the <<s>> type character. <[pattern]> is a set of
|
||||
characters which define a search set of possible characters making up
|
||||
the <<scanf>> input field. If the first character in the brackets is a
|
||||
caret (<<^>>), the search set is inverted to include all ASCII characters
|
||||
except those between the brackets. There is also a range facility
|
||||
which you can use as a shortcut. <<%[0-9] >> matches all decimal digits.
|
||||
The hyphen must not be the first or last character in the set.
|
||||
The character prior to the hyphen must be lexically less than the
|
||||
character after it.
|
||||
|
||||
Here are some <[pattern]> examples:
|
||||
o+
|
||||
o %[abcd]
|
||||
matches strings containing only <<a>>, <<b>>, <<c>>, and <<d>>.
|
||||
|
||||
o %[^abcd]
|
||||
matches strings containing any characters except <<a>>, <<b>>,
|
||||
<<c>>, or <<d>>
|
||||
|
||||
o %[A-DW-Z]
|
||||
matches strings containing <<A>>, <<B>>, <<C>>, <<D>>, <<W>>,
|
||||
<<X>>, <<Y>>, <<Z>>
|
||||
|
||||
o %[z-a]
|
||||
matches the characters <<z>>, <<->>, and <<a>>
|
||||
o-
|
||||
|
||||
Floating point numbers (for field types <<e>>, <<f>>, <<g>>, <<E>>,
|
||||
<<F>>, <<G>>) must correspond to the following general form:
|
||||
|
||||
. [+/-] ddddd[.]ddd [E|e[+|-]ddd]
|
||||
|
||||
where objects inclosed in square brackets are optional, and <<ddd>>
|
||||
represents decimal, octal, or hexadecimal digits.
|
||||
o-
|
||||
|
||||
RETURNS
|
||||
<<scanf>> returns the number of input fields successfully
|
||||
scanned, converted and stored; the return value does
|
||||
not include scanned fields which were not stored.
|
||||
|
||||
If <<scanf>> attempts to read at end-of-file, the return
|
||||
value is <<EOF>>.
|
||||
|
||||
If no fields were stored, the return value is <<0>>.
|
||||
|
||||
<<scanf>> might stop scanning a particular field before
|
||||
reaching the normal field end character, or may
|
||||
terminate entirely.
|
||||
|
||||
<<scanf>> stops scanning and storing the current field
|
||||
and moves to the next input field (if any)
|
||||
in any of the following situations:
|
||||
|
||||
O+
|
||||
o The assignment suppressing character (<<*>>) appears
|
||||
after the <<%>> in the format specification; the current
|
||||
input field is scanned but not stored.
|
||||
|
||||
o <[width]> characters have been read (<[width]> is a
|
||||
width specification, a positive decimal integer).
|
||||
|
||||
o The next character read cannot be converted
|
||||
under the the current format (for example,
|
||||
if a <<Z>> is read when the format is decimal).
|
||||
|
||||
o The next character in the input field does not appear
|
||||
in the search set (or does appear in the inverted search set).
|
||||
O-
|
||||
|
||||
When <<scanf>> stops scanning the current input field for one of
|
||||
these reasons, the next character is considered unread and
|
||||
used as the first character of the following input field, or the
|
||||
first character in a subsequent read operation on the input.
|
||||
|
||||
<<scanf>> will terminate under the following circumstances:
|
||||
|
||||
O+
|
||||
o The next character in the input field conflicts
|
||||
with a corresponding non-whitespace character in the
|
||||
format string.
|
||||
|
||||
o The next character in the input field is <<EOF>>.
|
||||
|
||||
o The format string has been exhausted.
|
||||
O-
|
||||
|
||||
When the format string contains a character sequence that is
|
||||
not part of a format specification, the same character
|
||||
sequence must appear in the input; <<scanf>> will
|
||||
scan but not store the matched characters. If a
|
||||
conflict occurs, the first conflicting character remains in the input
|
||||
as if it had never been read.
|
||||
|
||||
PORTABILITY
|
||||
<<scanf>> is ANSI C.
|
||||
|
||||
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
|
||||
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
|
||||
*/
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <reent.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#ifdef _HAVE_STDC
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
#include <varargs.h>
|
||||
#endif
|
||||
#include "local.h"
|
||||
|
||||
/* | ARGSUSED */
|
||||
/*SUPPRESS 590*/
|
||||
static
|
||||
_READ_WRITE_RETURN_TYPE
|
||||
eofread (cookie, buf, len)
|
||||
_PTR cookie;
|
||||
char *buf;
|
||||
int len;
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef _REENT_ONLY
|
||||
|
||||
#ifdef _HAVE_STDC
|
||||
int
|
||||
_DEFUN (sscanf, (str, fmt), _CONST char *str _AND _CONST char *fmt _DOTS)
|
||||
#else
|
||||
int
|
||||
sscanf (str, fmt, va_alist)
|
||||
_CONST char *str;
|
||||
_CONST char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
FILE f;
|
||||
|
||||
f._flags = __SRD;
|
||||
f._bf._base = f._p = (unsigned char *) str;
|
||||
f._bf._size = f._r = strlen (str);
|
||||
f._read = eofread;
|
||||
f._ub._base = NULL;
|
||||
f._lb._base = NULL;
|
||||
#ifdef _HAVE_STDC
|
||||
va_start (ap, fmt);
|
||||
#else
|
||||
va_start (ap);
|
||||
#endif
|
||||
ret = __svfscanf_r (_REENT, &f, fmt, ap);
|
||||
va_end (ap);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* !_REENT_ONLY */
|
||||
|
||||
#ifdef _HAVE_STDC
|
||||
int
|
||||
_DEFUN (_sscanf_r, (ptr, str, fmt), struct _reent *ptr _AND _CONST char *str _AND _CONST char *fmt _DOTS)
|
||||
#else
|
||||
int
|
||||
_sscanf_r (ptr, str, fmt, va_alist)
|
||||
struct _reent *ptr;
|
||||
_CONST char *str;
|
||||
_CONST char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
FILE f;
|
||||
|
||||
f._flags = __SRD;
|
||||
f._bf._base = f._p = (unsigned char *) str;
|
||||
f._bf._size = f._r = strlen (str);
|
||||
f._read = eofread;
|
||||
f._ub._base = NULL;
|
||||
f._lb._base = NULL;
|
||||
#ifdef _HAVE_STDC
|
||||
va_start (ap, fmt);
|
||||
#else
|
||||
va_start (ap);
|
||||
#endif
|
||||
ret = __svfscanf_r (ptr, &f, fmt, ap);
|
||||
va_end (ap);
|
||||
return ret;
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
/* SWI numbers for RDP (Demon) monitor. */
|
||||
#define SWI_WriteC 0x0
|
||||
#define SWI_Write0 0x2
|
||||
#define SWI_ReadC 0x4
|
||||
#define SWI_CLI 0x5
|
||||
#define SWI_GetEnv 0x10
|
||||
#define SWI_Exit 0x11
|
||||
#define SWI_EnterOS 0x16
|
||||
|
||||
#define SWI_GetErrno 0x60
|
||||
#define SWI_Clock 0x61
|
||||
#define SWI_Time 0x63
|
||||
#define SWI_Remove 0x64
|
||||
#define SWI_Rename 0x65
|
||||
#define SWI_Open 0x66
|
||||
|
||||
#define SWI_Close 0x68
|
||||
#define SWI_Write 0x69
|
||||
#define SWI_Read 0x6a
|
||||
#define SWI_Seek 0x6b
|
||||
#define SWI_Flen 0x6c
|
||||
|
||||
#define SWI_IsTTY 0x6e
|
||||
#define SWI_TmpNam 0x6f
|
||||
#define SWI_InstallHandler 0x70
|
||||
#define SWI_GenerateError 0x71
|
||||
|
||||
|
||||
/* Now the SWI numbers and reason codes for RDI (Angel) monitors. */
|
||||
#define AngelSWI_ARM 0x123456
|
||||
#ifdef __thumb__
|
||||
#define AngelSWI 0xAB
|
||||
#else
|
||||
#define AngelSWI AngelSWI_ARM
|
||||
#endif
|
||||
|
||||
/* The reason codes: */
|
||||
#define AngelSWI_Reason_Open 0x01
|
||||
#define AngelSWI_Reason_Close 0x02
|
||||
#define AngelSWI_Reason_WriteC 0x03
|
||||
#define AngelSWI_Reason_Write0 0x04
|
||||
#define AngelSWI_Reason_Write 0x05
|
||||
#define AngelSWI_Reason_Read 0x06
|
||||
#define AngelSWI_Reason_ReadC 0x07
|
||||
#define AngelSWI_Reason_IsTTY 0x09
|
||||
#define AngelSWI_Reason_Seek 0x0A
|
||||
#define AngelSWI_Reason_FLen 0x0C
|
||||
#define AngelSWI_Reason_TmpNam 0x0D
|
||||
#define AngelSWI_Reason_Remove 0x0E
|
||||
#define AngelSWI_Reason_Rename 0x0F
|
||||
#define AngelSWI_Reason_Clock 0x10
|
||||
#define AngelSWI_Reason_Time 0x11
|
||||
#define AngelSWI_Reason_System 0x12
|
||||
#define AngelSWI_Reason_Errno 0x13
|
||||
#define AngelSWI_Reason_GetCmdLine 0x15
|
||||
#define AngelSWI_Reason_HeapInfo 0x16
|
||||
#define AngelSWI_Reason_EnterSVC 0x17
|
||||
#define AngelSWI_Reason_ReportException 0x18
|
||||
#define ADP_Stopped_ApplicationExit ((2 << 16) + 38)
|
||||
#define ADP_Stopped_RunTimeError ((2 << 16) + 35)
|
|
@ -1,403 +0,0 @@
|
|||
/* Support files for GNU libc. Files in the system namespace go here.
|
||||
Files in the C namespace (ie those that do not start with an
|
||||
underscore) go in .c. */
|
||||
|
||||
|
||||
#if 0
|
||||
|
||||
/*You can comment this three lines if you want to use _gettimeofday and _times*/
|
||||
|
||||
|
||||
#if defined(_SMALL_PRINTF) || defined(SMALL_SCANF)
|
||||
#define NO_TIME
|
||||
#endif
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifndef NO_TIME
|
||||
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/times.h>
|
||||
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <reent.h>
|
||||
#include <unistd.h>
|
||||
#include "swi.h"
|
||||
|
||||
/* Forward prototypes. */
|
||||
|
||||
int _system _PARAMS ((const char *));
|
||||
|
||||
|
||||
|
||||
int _rename _PARAMS ((const char *, const char *));
|
||||
int isatty _PARAMS ((int));
|
||||
|
||||
#ifndef NO_TIME
|
||||
clock_t _times _PARAMS ((struct tms *));
|
||||
int _gettimeofday _PARAMS ((struct timeval *, struct timezone *));
|
||||
#endif
|
||||
|
||||
|
||||
void _raise _PARAMS ((void));
|
||||
|
||||
int _unlink _PARAMS ((void));
|
||||
int _link _PARAMS ((void));
|
||||
|
||||
int _stat _PARAMS ((const char *, struct stat *));
|
||||
|
||||
int _fstat _PARAMS ((int, struct stat *));
|
||||
|
||||
//caddr_t _sbrk _PARAMS ((int));
|
||||
int _getpid _PARAMS ((int));
|
||||
|
||||
int _kill _PARAMS ((int, int));
|
||||
void _exit _PARAMS ((int));
|
||||
int _close _PARAMS ((int));
|
||||
|
||||
int _swiclose _PARAMS ((int));
|
||||
int _open _PARAMS ((const char *, int, ...));
|
||||
int _swiopen _PARAMS ((const char *, int));
|
||||
int _write _PARAMS ((int, char *, int));
|
||||
int _swiwrite _PARAMS ((int, char *, int));
|
||||
int _lseek _PARAMS ((int, int, int));
|
||||
int _swilseek _PARAMS ((int, int, int));
|
||||
int _read _PARAMS ((int, char *, int));
|
||||
int _swiread _PARAMS ((int, char *, int));
|
||||
void initialise_monitor_handles _PARAMS ((void));
|
||||
|
||||
static int wrap _PARAMS ((int));
|
||||
static int error _PARAMS ((int));
|
||||
static int get_errno _PARAMS ((void));
|
||||
static int remap_handle _PARAMS ((int));
|
||||
static int findslot _PARAMS ((int));
|
||||
|
||||
/* Register name faking - works in collusion with the linker. */
|
||||
register char * stack_ptr asm ("sp");
|
||||
|
||||
|
||||
/* following is copied from libc/stdio/local.h to check std streams */
|
||||
extern void _EXFUN(__sinit,(struct _reent *));
|
||||
|
||||
#ifndef _SMALL_PRINTF
|
||||
#define CHECK_INIT(fp) \
|
||||
do \
|
||||
{ \
|
||||
if ((fp)->_data == 0) \
|
||||
(fp)->_data = _REENT; \
|
||||
if (!(fp)->_data->__sdidinit) \
|
||||
__sinit ((fp)->_data); \
|
||||
} \
|
||||
while (0)
|
||||
#endif
|
||||
/* Adjust our internal handles to stay away from std* handles. */
|
||||
#define FILE_HANDLE_OFFSET (0x20)
|
||||
|
||||
static int std_files_checked;
|
||||
static int monitor_stdin;
|
||||
static int monitor_stdout;
|
||||
static int monitor_stderr;
|
||||
|
||||
/* Struct used to keep track of the file position, just so we
|
||||
can implement fseek(fh,x,SEEK_CUR). */
|
||||
typedef struct
|
||||
{
|
||||
int handle;
|
||||
int pos;
|
||||
}
|
||||
poslog;
|
||||
|
||||
#define MAX_OPEN_FILES 20
|
||||
static poslog openfiles [MAX_OPEN_FILES];
|
||||
/*
|
||||
static int findslot (int fh)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < MAX_OPEN_FILES; i ++)
|
||||
if (openfiles[i].handle == fh)
|
||||
break;
|
||||
return i;
|
||||
}
|
||||
*/
|
||||
|
||||
/* Function to convert std(in|out|err) handles to internal versions. */
|
||||
/*
|
||||
static int remap_handle (int fh)
|
||||
{
|
||||
if (!std_files_checked)
|
||||
{
|
||||
CHECK_INIT(stdin);
|
||||
CHECK_INIT(stdout);
|
||||
CHECK_INIT(stderr);
|
||||
std_files_checked = 1;
|
||||
}
|
||||
if (fh == STDIN_FILENO)
|
||||
return monitor_stdin;
|
||||
if (fh == STDOUT_FILENO)
|
||||
return monitor_stdout;
|
||||
if (fh == STDERR_FILENO)
|
||||
return monitor_stderr;
|
||||
|
||||
return fh - FILE_HANDLE_OFFSET;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
void
|
||||
initialise_monitor_handles (void)
|
||||
{
|
||||
int i;
|
||||
|
||||
int fh;
|
||||
const char * name;
|
||||
|
||||
name = ":tt";
|
||||
asm ("mov r0,%2; mov r1, #0; swi %a1; mov %0, r0"
|
||||
: "=r"(fh)
|
||||
: "i" (SWI_Open),"r"(name)
|
||||
: "r0","r1");
|
||||
monitor_stdin = fh;
|
||||
|
||||
name = ":tt";
|
||||
asm ("mov r0,%2; mov r1, #4; swi %a1; mov %0, r0"
|
||||
: "=r"(fh)
|
||||
: "i" (SWI_Open),"r"(name)
|
||||
: "r0","r1");
|
||||
monitor_stdout = monitor_stderr = fh;
|
||||
|
||||
for (i = 0; i < MAX_OPEN_FILES; i ++)
|
||||
openfiles[i].handle = -1;
|
||||
|
||||
openfiles[0].handle = monitor_stdin;
|
||||
openfiles[0].pos = 0;
|
||||
openfiles[1].handle = monitor_stdout;
|
||||
openfiles[1].pos = 0;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
static int get_errno (void)
|
||||
{
|
||||
asm ("swi %a0" :: "i" (SWI_GetErrno));
|
||||
}
|
||||
|
||||
static int error (int result)
|
||||
{
|
||||
errno = get_errno ();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int wrap (int result)
|
||||
{
|
||||
if (result == -1)
|
||||
return error (-1);
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifndef NO_FILE
|
||||
int _read (int file,
|
||||
char * ptr,
|
||||
int len)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _lseek (int file,
|
||||
int ptr,
|
||||
int dir)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern void __io_putchar( char c );
|
||||
|
||||
int _write (int file,
|
||||
char * ptr,
|
||||
int len)
|
||||
{
|
||||
int todo;
|
||||
|
||||
for (todo = 0; todo < len; todo++)
|
||||
{
|
||||
__io_putchar( *ptr++ );
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
int _open (const char * path,
|
||||
int flags,
|
||||
...)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _close (int file)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
void _exit (int n)
|
||||
{
|
||||
/* FIXME: return code is thrown away. */
|
||||
while(1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _kill (int n, int m)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
#if 0 //VC090825: moved to independent lib std_sbrk.lib
|
||||
caddr_t _sbrk (int incr)
|
||||
{
|
||||
extern char end; /* Defined by the linker */
|
||||
static char *heap_end;
|
||||
char *prev_heap_end;
|
||||
|
||||
if (heap_end == 0) {
|
||||
heap_end = &end;
|
||||
}
|
||||
prev_heap_end = heap_end;
|
||||
if (heap_end + incr > stack_ptr)
|
||||
{
|
||||
_write (1, "Heap and stack collision\n", 25);
|
||||
abort ();
|
||||
}
|
||||
|
||||
heap_end += incr;
|
||||
return (caddr_t) prev_heap_end;
|
||||
}
|
||||
#endif //if 0 //VC090825: moved to independent lib std_sbrk.lib
|
||||
|
||||
#endif
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#ifndef NO_FILE
|
||||
int _fstat(int file, struct stat *st)
|
||||
{
|
||||
st->st_mode = S_IFCHR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
int _stat (const char *fname, struct stat *st)
|
||||
{
|
||||
st->st_mode = S_IFCHR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#ifndef NO_FILE
|
||||
int _link (void)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _unlink (void)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
void _raise (void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#ifndef NO_TIME
|
||||
|
||||
int _gettimeofday (struct timeval * tp, struct timezone * tzp)
|
||||
{
|
||||
|
||||
if (tp)
|
||||
{
|
||||
/* Ask the host for the seconds since the Unix epoch. */
|
||||
{
|
||||
int value;
|
||||
asm ("swi %a1; mov %0, r0" : "=r" (value): "i" (SWI_Time) : "r0");
|
||||
tp->tv_sec = value;
|
||||
}
|
||||
tp->tv_usec = 0;
|
||||
}
|
||||
|
||||
/* Return fixed data for the timezone. */
|
||||
if (tzp)
|
||||
{
|
||||
tzp->tz_minuteswest = 0;
|
||||
tzp->tz_dsttime = 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Return a clock that ticks at 100Hz. */
|
||||
clock_t _times (struct tms * tp)
|
||||
{
|
||||
clock_t timeval;
|
||||
|
||||
asm ("swi %a1; mov %0, r0" : "=r" (timeval): "i" (SWI_Clock) : "r0");
|
||||
|
||||
if (tp)
|
||||
{
|
||||
tp->tms_utime = timeval; /* user time */
|
||||
tp->tms_stime = 0; /* system time */
|
||||
tp->tms_cutime = 0; /* user time, children */
|
||||
tp->tms_cstime = 0; /* system time, children */
|
||||
}
|
||||
|
||||
return timeval;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
int isatty (int fd)
|
||||
{
|
||||
return 1;
|
||||
fd = fd;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _system (const char *s)
|
||||
{
|
||||
if (s == NULL)
|
||||
return 0;
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
#ifndef NO_FILE
|
||||
|
||||
int _rename (const char * oldpath, const char * newpath)
|
||||
{
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -1,254 +0,0 @@
|
|||
|
||||
#include "UART0_stdio.h"
|
||||
|
||||
int main() {
|
||||
|
||||
char ent_char ;
|
||||
int ent_dec_pos ;
|
||||
int ent_dec_neg ;
|
||||
int ent_hex ;
|
||||
int ent_oct ;
|
||||
int ent_oct_hex ;
|
||||
long ent_slong ;
|
||||
unsigned short ent_ushort ;
|
||||
unsigned long ent_ulong ;
|
||||
char tab_char[3] ;
|
||||
|
||||
|
||||
char nom [50] ;
|
||||
char mois[50] ;
|
||||
int jour ;
|
||||
int annee ;
|
||||
int *ptr ;
|
||||
char tab[3] ;
|
||||
long double fld ;
|
||||
float flottant ;
|
||||
double f ;
|
||||
double f4 ;
|
||||
long double f1 ;
|
||||
float f2, f3 ;
|
||||
|
||||
|
||||
printf("Entrez un char:");
|
||||
scanf("%c" , &ent_char);
|
||||
printf("%c\n", ent_char);
|
||||
|
||||
|
||||
|
||||
printf("Entrez trois caracteres:\n");
|
||||
scanf("%3c" , tab_char);
|
||||
printf("1er char :%c\n", tab_char[0]);
|
||||
printf("2eme char :%c\n", tab_char[1]);
|
||||
printf("3eme char :%c\n", tab_char[2]);
|
||||
|
||||
printf("Entrez un nombre decimal positif: ");
|
||||
scanf("%d" , &ent_dec_pos);
|
||||
printf("%d\n", ent_dec_pos);
|
||||
|
||||
printf("Entrez un nombre decimal negatif: ");
|
||||
scanf("%d" , &ent_dec_neg);
|
||||
printf("%d\n", ent_dec_neg);
|
||||
|
||||
printf("Entrez un nombre decimal long: ");
|
||||
scanf("%ld" , &ent_slong);
|
||||
printf("%ld\n", ent_slong);
|
||||
|
||||
printf("Entrez un nombre decimal unsigned long: ");
|
||||
scanf("%lu" , &ent_ulong);
|
||||
printf("valeur entree: %lu\n", ent_ulong);
|
||||
|
||||
printf("Entrez un nombre decimal unsigned short: ");
|
||||
scanf("%hu" , &ent_ushort);
|
||||
printf("valeur entree: %lu\n", ent_ushort);
|
||||
|
||||
|
||||
printf("Entrez un nombre en hexa: ");
|
||||
scanf("%x" , &ent_hex);
|
||||
printf("%x\n", ent_hex);
|
||||
|
||||
printf("Entrez un nombre en octal: ");
|
||||
scanf("%o" , &ent_oct);
|
||||
printf("%o \n", ent_oct);
|
||||
|
||||
printf("Entrez un nombre en octal ou hexa (preceder de 0 pour octal et de 0x ou 0X pour hexa), ");
|
||||
scanf("%i" , &ent_oct_hex);
|
||||
printf("valeur entree en decimal : %i \n", ent_oct_hex);
|
||||
|
||||
printf("Entrez une chaine de caracteres: ");
|
||||
scanf("%s" , nom);
|
||||
printf("%s \n", nom);
|
||||
|
||||
printf("Entrez le jour,le mois et l'annee:\n");
|
||||
|
||||
scanf("%d%s%d", &jour, mois, &annee);
|
||||
printf("\njour:%d \n",jour);
|
||||
printf("mois:%s \n",mois);
|
||||
printf("annee:%d \n",annee);
|
||||
|
||||
|
||||
|
||||
// Dans le cas du format %[...] : le scanf se termine lorsqu'un caractere n'appartenant pas a
|
||||
// l'ensemble est detecte, inversement si on specifie %[^...] le scanf s'arrete lorsque'un
|
||||
//caractere de l'ensembles a ete lu
|
||||
|
||||
printf("Entrez une chaine de caracteres en majuscules: ");
|
||||
scanf("%[A-Z]" , nom);
|
||||
printf("%s \n", nom);
|
||||
|
||||
printf("Entrez une chaine de caracteres sans majuscules pour terminer le scanf entrez une majuscule: ");
|
||||
scanf("%[^A-Z]" , nom);
|
||||
printf("%s \n", nom);
|
||||
|
||||
printf("Entrez une adresse memoire quelconque \n");
|
||||
scanf("%p",&ptr);
|
||||
printf("L'adresse %p contient la valeur %d ",ptr,*ptr);
|
||||
|
||||
/* printf("Entrez un caractere: ");
|
||||
scanf("%c" , &ent_char);
|
||||
__io_ungetc(ent_char);
|
||||
scanf("%c" , &ent_char);
|
||||
printf("Apres un scanf suivi d'un ungetc et d'un scanf on a : %c \n", ent_char);
|
||||
|
||||
printf("Entrez une chaine de 2 caracteres\n ");
|
||||
scanf("%s" , nom);
|
||||
printf("la chaine entree est %s \n",nom);
|
||||
ent_char = __io_ungetc(nom[0]);
|
||||
scanf("%c" , nom[0]) ;
|
||||
printf("Apres un ungetc et d'un scanf on a : %s \n", nom);
|
||||
*/
|
||||
|
||||
printf("Entrer un float:\n");
|
||||
scanf("%f",&flottant);
|
||||
printf("Le float entre est %f",flottant);
|
||||
|
||||
printf("Entrer un double float:\n");
|
||||
scanf("%Lf",&f);
|
||||
printf("Le float entre est %Lf\n",f);
|
||||
|
||||
|
||||
printf("Entrer un nombre avec exposant :\n");
|
||||
scanf("%le",&f);
|
||||
printf("Le float entre est %le\n",f);
|
||||
|
||||
// Note : le format %g choisit en fonction de la valeur entree le format le plus
|
||||
// appropriée entre %e et %f
|
||||
|
||||
|
||||
printf("Entrer un nombre avec exposant :\n");
|
||||
scanf("%lg",&f);
|
||||
printf("Le float entre est %lg\n",f);
|
||||
|
||||
printf("Entrer un nombre avec exposant :\n");
|
||||
scanf("%Lg",&fld);
|
||||
printf("Le float entre est %Lg\n",fld);
|
||||
|
||||
|
||||
f1 = 48656568.256479123456789123456789;
|
||||
f = 48656568.256479123456789123456789;
|
||||
f2 = 456.45366;
|
||||
f3 = 456.45362;
|
||||
printf("Test for Floating points numbers printf\n");
|
||||
|
||||
/*Simple test of %f format */
|
||||
printf("double :%lf\n",f);
|
||||
|
||||
/* Test with format specifying first number is equal to minimal number
|
||||
of caracter to be print the second one is number of digits */
|
||||
|
||||
printf("LONG DOUBLE :%Lf - %20.10Lf - %20.15Lf - %20.20Lf - %30.30Lf\n", f1, f1, f1, f1, f1);
|
||||
printf("float2 :%4.2f %+.0e %E \n", 3.1416, 3.1416, 3.1416);
|
||||
|
||||
/*Note: the output should be float2: 3.14 +3e+000 3.141600E+000*/
|
||||
|
||||
printf("float3 :%7.3f\n", 1.2345);
|
||||
printf("float3bis :%7.3lf\n",4865.256479 );
|
||||
printf("float4 :%10.3f\n", 1.2345e3);
|
||||
printf("float5 :%10.3f\n", 1.2345e7);
|
||||
printf("float6 :%12.4e\n", 1.2345);
|
||||
printf("float7 :%12.4e\n", 123.456789e8);
|
||||
printf("float8 :%15.5lf\n",48656568.256479 );
|
||||
printf("float9 :%15.6lf\n",48656568.256479 - 48656568.256478 );
|
||||
printf("float9bis :%-15.6lf%7.4f\n",48656568.256479 - 48656568.256478,1.2345 );
|
||||
printf("float9ter :%15.2lf\n",f2*f3 );
|
||||
|
||||
/*Note : the outputs shoud be
|
||||
for 1.2345, ^^1.235
|
||||
for 1.2345e5, ^^1234.500
|
||||
for 1.2345e7, 12345000.000
|
||||
for 1.2345, ^^1.2345e+00
|
||||
for 123.456789e8, ^^1.2346e+10
|
||||
|
||||
for float 9: 48656568.256479 - 48656568.2563,^^^^^^^^0.00001
|
||||
for float 9bis: 48656568.256479 - 48656568.2563,0.00001^^^^^^^^1.2345
|
||||
for f2*f3 ,^^^^^^208349,92
|
||||
^ is equal to a space */
|
||||
|
||||
|
||||
printf("float10 :01234567 \n" );
|
||||
printf("float11 :%8g|\n", 12.34 );
|
||||
printf("float12 :%8g|\n", 1234.5678 );
|
||||
printf("float13 :%8g|\n", 0.0478 );
|
||||
printf("float14 :%8g|\n", 422121.0 );
|
||||
printf("float15 :%8g|\n", 422121234.345345 );
|
||||
|
||||
/*Note : outputs should be
|
||||
01234567
|
||||
12.34|
|
||||
1234.57|
|
||||
0.0478|
|
||||
422121|
|
||||
4.22121e+08|
|
||||
*/
|
||||
|
||||
|
||||
printf("float16 :%.0f|\n", 1000.123456789123456789 );
|
||||
printf("float17 :%.1f|\n", 2000.123456789123456789 );
|
||||
printf("float18 :%.2f|\n", 3000.123456789123456789 );
|
||||
printf("float19 :%.10f|\n", 4000.123456789123456789 );
|
||||
printf("float20 :%.30f|\n", 5000.123456789123456789 );
|
||||
printf("float21 :%f|\n", 6000.123456789123456789 );
|
||||
printf("float22 :%.f|\n", 7000.123456789123456789 );
|
||||
|
||||
/*Note : outputs should be
|
||||
1000|
|
||||
2000.1|
|
||||
3000.12|
|
||||
4000.1234567891|
|
||||
5000.12345678912333823973312939761|
|
||||
6000.123457|
|
||||
7000|
|
||||
*/
|
||||
|
||||
int a ;
|
||||
char c ;
|
||||
float ft ;
|
||||
int hex ;
|
||||
double db ;
|
||||
char stg[50]="chaine" ;
|
||||
|
||||
a=1;
|
||||
// Test du printf avec une suite de parametres int
|
||||
printf("Test suite de int: \n a=%d\na+1=%d\na+2=%d\na+3=%d\na+4=%d\na+5=%d\na+6=%d\na+7=%d\na+8=%d\na=%d\n",a,a+1,a+2,a+3,a+4,a+5,a+6,a+7,a+8,a);
|
||||
|
||||
//Test du printf avec une suite de floats
|
||||
ft=1.589634 ;
|
||||
printf("Test suite de floats: \nft=%f\nft+0.1=%f\nft+0.01=%f\nft+0.001=%f\nft+0.0001=%f\nft+0.00001=%f\n",ft,ft+0.1,ft+0.01,ft+0.001,ft+0.0001,ft+0.00001);
|
||||
|
||||
// Test du printf avec un melange de formats
|
||||
|
||||
a = 1 ;
|
||||
c ='c' ;
|
||||
ft = 1.963214 ;
|
||||
db = 1.589e+15;
|
||||
hex = 0x0FA ;
|
||||
|
||||
printf("Test avec plusieurs formats:\na=%d\nc=%c\nstg=%s\nft=%6.5f\ndb=%10.2e\nhex=%x\n",a,c,stg,ft,db,hex);
|
||||
printf("Entrez dans l'ordre un int\n un char\n une chaine\nun float\nun float avec exposant\nun hexa \n");
|
||||
scanf("%d%c%s%f%le%x",&a,&c,stg,&ft,&db,&hex);
|
||||
printf("Test avec plusieurs formats apres un scanf:\n a=%d\nc=%c\nstg=%s\nft=%6.5f\ndb=%10.2le\nhex=0x%x\n",a,c,stg,ft,db,hex);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
|
||||
#define FLOATING
|
||||
#define PRINT
|
||||
#define SCANF
|
||||
|
||||
|
||||
int main() {
|
||||
|
||||
char ent_char ;
|
||||
float flottant ;
|
||||
|
||||
#ifndef FLOATING
|
||||
#ifdef PRINT
|
||||
ent_char='a';
|
||||
#endif
|
||||
|
||||
#ifdef SCANF
|
||||
scanf("%c" , &ent_char);
|
||||
#endif
|
||||
|
||||
#ifdef PRINT
|
||||
printf("%c\n", ent_char);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#else
|
||||
#ifdef PRINT
|
||||
flottant = 1.456789;
|
||||
#endif
|
||||
|
||||
#ifdef SCANF
|
||||
scanf("%f" , &flottant);
|
||||
#endif
|
||||
|
||||
#ifdef PRINT
|
||||
printf("%f\n", flottant);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
|
@ -1,87 +0,0 @@
|
|||
|
||||
int main (){
|
||||
double f;
|
||||
|
||||
/*double f4;
|
||||
long double f1;
|
||||
float f2, f3;
|
||||
float flottant;*/
|
||||
|
||||
f = 48656568.256479123456789123456789;
|
||||
/*
|
||||
f1= 48656568.256479123456789123456789;
|
||||
f2 = 456.45366;
|
||||
f3 = 456.45362; */
|
||||
//printf("Test du printf");
|
||||
|
||||
/*Simple test of %f format */
|
||||
printf("double :%lf\n",f);
|
||||
|
||||
/* Test with format specifying first number is equal to minimal number
|
||||
of caracter to be print the second one is number of digits */
|
||||
/*
|
||||
printf("LONG DOUBLE :%Lf - %20.10Lf - %20.15Lf - %20.20Lf - %30.30Lf\n", f1, f1, f1, f1, f1);
|
||||
printf("float2 :%4.2f %+.0e %E \n", 3.1416, 3.1416, 3.1416);*/
|
||||
|
||||
/*Note: the output should be float2: 3.14 +3e+000 3.141600E+000*/
|
||||
/*
|
||||
printf("float3 :%7.3f\n", 1.2345);
|
||||
printf("float3bis :%7.3lf\n",4865.256479 );
|
||||
printf("float4 :%10.3f\n", 1.2345e3);
|
||||
printf("float5 :%10.3f\n", 1.2345e7);
|
||||
printf("float6 :%12.4e\n", 1.2345);
|
||||
printf("float7 :%12.4e\n", 123.456789e8);
|
||||
printf("float8 :%15.5lf\n",48656568.256479 );
|
||||
printf("float9 :%15.6lf\n",48656568.256479 - 48656568.256478 );
|
||||
printf("float9bis :%15.2lf\n",f2*f3 );*/
|
||||
/*Note : the outputs shoud be
|
||||
for 1.2345, ^^1.235
|
||||
for 1.2345e5, ^^1234.500
|
||||
for 1.2345e7, 12345000.000
|
||||
for 1.2345, ^^1.2345e+00
|
||||
for 123.456789e8, ^^1.2346e+10
|
||||
for 48656568.256479 - 48656568.2563,^^^^^^^^0.00001
|
||||
for f2*f3 ,^^^^^^208349,92
|
||||
^ is equal to a space */
|
||||
|
||||
/*
|
||||
printf("float10 :01234567 \n" );
|
||||
printf("float11 :%8g|\n", 12.34 );
|
||||
printf("float12 :%8g|\n", 1234.5678 );
|
||||
printf("float13 :%8g|\n", 0.0478 );
|
||||
printf("float14 :%8g|\n", 422121.0 );
|
||||
printf("float15 :%8g|\n", 422121234.345345 );*/
|
||||
/*Note : outputs should be
|
||||
01234567
|
||||
12.34|
|
||||
1234.57|
|
||||
0.0478|
|
||||
422121|
|
||||
4.22121e+08|
|
||||
*/
|
||||
/*
|
||||
|
||||
printf("float16 :%.0f|\n", 1000.123456789123456789 );
|
||||
printf("float17 :%.1f|\n", 2000.123456789123456789 );
|
||||
printf("float18 :%.2f|\n", 3000.123456789123456789 );
|
||||
printf("float19 :%.10f|\n", 4000.123456789123456789 );
|
||||
printf("float20 :%.30f|\n", 5000.123456789123456789 );
|
||||
printf("float21 :%f|\n", 6000.123456789123456789 );
|
||||
printf("float22 :%.f|\n", 7000.123456789123456789 );
|
||||
*/
|
||||
/*Note : outputs should be
|
||||
1000|
|
||||
2000.1|
|
||||
3000.12|
|
||||
4000.1234567891|
|
||||
5000.12345678912333823973312939761|
|
||||
6000.123457|
|
||||
7000|
|
||||
*/
|
||||
|
||||
|
||||
//while(1);
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
|
||||
|
||||
|
||||
int main() {
|
||||
|
||||
float flottant ;
|
||||
// char c;
|
||||
scanf("%f" , &flottant);
|
||||
// scanf("%c",&c);
|
||||
//while(1);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
|
@ -1,284 +0,0 @@
|
|||
/****************************************************************
|
||||
*
|
||||
* 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
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
34
cpu/stm32w108/hal/micro/cortexm3/iap_bootloader.h
Normal file
34
cpu/stm32w108/hal/micro/cortexm3/iap_bootloader.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
/** @file iap_bootloader.h
|
||||
* @brief IAP bootloader specific definitions
|
||||
* <!--(C) COPYRIGHT 2010 STMicroelectronics. All rights reserved. -->
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Application start address
|
||||
*/
|
||||
#define IAP_BOOTLOADER_APPLICATION_ADDRESS 0x08003000
|
||||
|
||||
/**
|
||||
* @brief Radio PAN ID for OTA bootloader
|
||||
*/
|
||||
#define IAP_BOOTLOADER_PAN_ID 0xb00b
|
||||
|
||||
/**
|
||||
* @brief Signature used for switch to application
|
||||
*/
|
||||
#define IAP_BOOTLOADER_APP_SWITCH_SIGNATURE 0xb001204d
|
||||
|
||||
/**
|
||||
* @brief Radio default channel for OTA bootloader
|
||||
*/
|
||||
#define IAP_BOOTLOADER_DEFAULT_CHANNEL 0x0F
|
||||
|
||||
/**
|
||||
* @brief IAP bootloader uart mode
|
||||
*/
|
||||
#define IAP_BOOTLOADER_MODE_UART 0
|
||||
|
||||
/**
|
||||
* @brief IAP bootloader OTA mode
|
||||
*/
|
||||
#define IAP_BOOTLOADER_MODE_OTA 1
|
|
@ -10,12 +10,6 @@
|
|||
#include "hal/micro/micro-common.h"
|
||||
#include "hal/micro/cortexm3/micro-common.h"
|
||||
|
||||
#define GPIO_PxCLR_BASE (GPIO_PACLR_ADDR)
|
||||
#define GPIO_PxSET_BASE (GPIO_PASET_ADDR)
|
||||
#define GPIO_PxOUT_BASE (GPIO_PAOUT_ADDR)
|
||||
// Each port is offset from the previous port by the same amount
|
||||
#define GPIO_Px_OFFSET (GPIO_PBCFGL_ADDR-GPIO_PACFGL_ADDR)
|
||||
|
||||
void halInitLed(void)
|
||||
{
|
||||
/* Set GPIO pins for Led D1 and Led D3 */
|
||||
|
@ -28,16 +22,12 @@ void halInitLed(void)
|
|||
|
||||
void halSetLed(HalBoardLed led)
|
||||
{
|
||||
if(led/8 < 3) {
|
||||
*((volatile int32u *)(GPIO_PxCLR_BASE+(GPIO_Px_OFFSET*(led/8)))) = BIT(led&7);
|
||||
}
|
||||
halGpioSet(led, 0);
|
||||
}
|
||||
|
||||
void halClearLed(HalBoardLed led)
|
||||
{
|
||||
if(led/8 < 3) {
|
||||
*((volatile int32u *)(GPIO_PxSET_BASE+(GPIO_Px_OFFSET*(led/8)))) = BIT(led&7);
|
||||
}
|
||||
halGpioSet(led, 1);
|
||||
}
|
||||
|
||||
void halToggleLed(HalBoardLed led)
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
#ifndef LOADER
|
||||
#if defined (CORTEXM3_STM32W108)
|
||||
#include "hal/micro/cortexm3/stm32w108/memmap.h"
|
||||
#elif defined (CORTEXM3_STM32F103)
|
||||
#include "hal/micro/cortexm3/stm32f103ret/memmap.h"
|
||||
#else
|
||||
#error no appropriate micro defined
|
||||
#endif
|
||||
|
|
|
@ -250,7 +250,7 @@ void halInternalSetRegTrim(boolean boostMode)
|
|||
// the accuracy of OSCHF (much lower than XTAL).
|
||||
void halCommonDelayMicroseconds(int16u us)
|
||||
{
|
||||
int32u beginTime = MAC_TIMER;
|
||||
int32u beginTime = ReadRegister(MAC_TIMER);
|
||||
|
||||
//If we're not using the XTAL, the MAC Timer is running off OSCHF,
|
||||
//that means the clock is half speed, 6MHz. We need to halve our delay
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
|
||||
#include PLATFORM_HEADER
|
||||
#include BOARD_HEADER
|
||||
#include "error.h"
|
||||
#include "hal/micro/micro-common.h"
|
||||
#include "hal/micro/cortexm3/micro-common.h"
|
||||
|
@ -59,11 +60,16 @@ void halGpioConfig(int32u io, int32u config)
|
|||
*configRegs[io/4] = portcfg | (config <<((io&3)*4));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void halGpioSet(int32u gpio, boolean value)
|
||||
{
|
||||
if(gpio/8 < 3) {
|
||||
if (value) {
|
||||
*((volatile int32u *)(GPIO_PxSET_BASE+(GPIO_Px_OFFSET*(gpio/8)))) = BIT(gpio&7);
|
||||
} else {
|
||||
*((volatile int32u *)(GPIO_PxCLR_BASE+(GPIO_Px_OFFSET*(gpio/8)))) = BIT(gpio&7);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int16u halInternalStartSystemTimer(void)
|
||||
{
|
||||
|
|
|
@ -24,24 +24,35 @@
|
|||
#endif //__STSTATUS_TYPE__
|
||||
#endif // DOXYGEN_SHOULD_SKIP_THIS
|
||||
|
||||
#define PORTA (0 << 3)
|
||||
#define PORTB (1 << 3)
|
||||
#define PORTC (2 << 3)
|
||||
|
||||
/**
|
||||
* @brief Some registers and variables require indentifying GPIO by
|
||||
* a single number instead of the port and pin. This macro converts
|
||||
* Port A pins into a single number.
|
||||
*/
|
||||
#define PORTA_PIN(y) ((0<<3)|y)
|
||||
#define PORTA_PIN(y) (PORTA|y)
|
||||
/**
|
||||
* @brief Some registers and variables require indentifying GPIO by
|
||||
* a single number instead of the port and pin. This macro converts
|
||||
* Port B pins into a single number.
|
||||
*/
|
||||
#define PORTB_PIN(y) ((1<<3)|y)
|
||||
#define PORTB_PIN(y) (PORTB|y)
|
||||
/**
|
||||
* @brief Some registers and variables require indentifying GPIO by
|
||||
* a single number instead of the port and pin. This macro converts
|
||||
* Port C pins into a single number.
|
||||
*/
|
||||
#define PORTC_PIN(y) ((2<<3)|y)
|
||||
#define PORTC_PIN(y) (PORTC|y)
|
||||
|
||||
/**
|
||||
* @brief Some registers and variables require indentifying GPIO by
|
||||
* a single number instead of the port and pin. This macro converts
|
||||
* Port C pins into a single number.
|
||||
*/
|
||||
#define PORTx_PIN(x, y) (x|y)
|
||||
|
||||
/**
|
||||
* @brief Resets the watchdog timer. This function is pointed
|
||||
|
@ -62,6 +73,16 @@ void halInternalResetWatchDog( void );
|
|||
*/
|
||||
void halGpioConfig(int32u io, int32u config);
|
||||
|
||||
/**
|
||||
* @brief Set/Clear single GPIO bit
|
||||
*
|
||||
* @param io The io pin to use, can be specified with the convenience macros
|
||||
* PORTA_PIN(), PORTB_PIN(), PORTC_PIN()
|
||||
* @param value A flag indicating whether to set or clear the io.
|
||||
*
|
||||
*/
|
||||
void halGpioSet(int32u io, boolean value);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Calibrates the internal SlowRC to generate a 1024 Hz (1kHz) clock.
|
||||
|
|
|
@ -6,15 +6,19 @@
|
|||
*/
|
||||
|
||||
#include PLATFORM_HEADER
|
||||
#include BOARD_HEADER
|
||||
#include "error.h"
|
||||
#include "hal/micro/micro-common.h"
|
||||
#include "hal/micro/cortexm3/micro-common.h"
|
||||
#include "micro/system-timer.h"
|
||||
#include "micro/adc.h"
|
||||
#include "micro/cortexm3/memmap.h"
|
||||
#include "micro/cortexm3/iap_bootloader.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
extern void halBoardInit(void);
|
||||
|
||||
void halInit(void)
|
||||
{
|
||||
|
@ -24,6 +28,7 @@ void halInit(void)
|
|||
//be deleted.
|
||||
GPIO_DBGCFG &= ~GPIO_EXTREGEN;
|
||||
halInternalSetRegTrim(FALSE);
|
||||
halBoardInit();
|
||||
halPowerUp();
|
||||
halInternalCalibrateFastRc();
|
||||
|
||||
|
@ -54,6 +59,7 @@ void halReboot(void)
|
|||
|
||||
void halPowerDown(void)
|
||||
{
|
||||
halBoardPowerDown();
|
||||
}
|
||||
|
||||
void halPowerUp(void)
|
||||
|
@ -61,6 +67,7 @@ void halPowerUp(void)
|
|||
halInternalInitAdc();
|
||||
halCommonCalibratePads();
|
||||
halInternalSwitchToXtal();
|
||||
halBoardPowerUp();
|
||||
}
|
||||
|
||||
static int16u seed0 = 0xbeef;
|
||||
|
@ -106,3 +113,43 @@ void halCommonMemSet(void *dest, int8u val, int16u bytes)
|
|||
{
|
||||
memset(dest, val, bytes);
|
||||
}
|
||||
|
||||
#pragma pack(1)
|
||||
typedef struct appSwitchStruct {
|
||||
int32u signature;
|
||||
int8u mode;
|
||||
int8u channel;
|
||||
union {
|
||||
int16u panID;
|
||||
int16u offset;
|
||||
} param;
|
||||
} appSwitchStructType;
|
||||
#pragma pack()
|
||||
static appSwitchStructType *appSwitch = (appSwitchStructType *) RAM_BOTTOM;
|
||||
|
||||
StStatus halBootloaderStart(int8u mode, int8u channel, int16u panID)
|
||||
{
|
||||
if (mode == IAP_BOOTLOADER_MODE_UART) {
|
||||
int8u cut = *(volatile int8u *) 0x08040798;
|
||||
if (!( (halFixedAddressTable.baseTable.type == FIXED_ADDRESS_TABLE_TYPE) &&
|
||||
( ( (halFixedAddressTable.baseTable.version & FAT_MAJOR_VERSION_MASK)
|
||||
== 0x0000 ) &&
|
||||
(halFixedAddressTable.baseTable.version == 0x0003) //checking presence of valid version
|
||||
) && (cut >= 2) && (cut <= 3)))
|
||||
/* Cut not supported */
|
||||
return ST_ERR_FATAL;
|
||||
} else {
|
||||
/* Check that OTA bootloader is at the base of the flash */
|
||||
if (*((int32u *) (MFB_BOTTOM + 28)) == IAP_BOOTLOADER_APP_SWITCH_SIGNATURE) {
|
||||
appSwitch->channel = ((channel >= 11) && (channel <= 26)) ? channel :IAP_BOOTLOADER_DEFAULT_CHANNEL;
|
||||
appSwitch->param.panID = panID;
|
||||
} else {
|
||||
return ST_ERR_FATAL;
|
||||
}
|
||||
}
|
||||
appSwitch->signature = IAP_BOOTLOADER_APP_SWITCH_SIGNATURE;
|
||||
appSwitch->mode = mode;
|
||||
halReboot();
|
||||
|
||||
return (mode <= IAP_BOOTLOADER_MODE_OTA) ? ST_ERR_FATAL: ST_BAD_ARGUMENT;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,30 @@
|
|||
|
||||
#include PLATFORM_HEADER
|
||||
#include "error.h"
|
||||
|
||||
#ifdef NVM_RAM_EMULATION
|
||||
|
||||
static int16u calibrationData[32+2]={
|
||||
0xFFFF, 0xFFFF,
|
||||
0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
|
||||
0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
|
||||
0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
|
||||
0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
|
||||
};
|
||||
|
||||
int8u halCommonReadFromNvm(void *data, int32u offset, int16u length)
|
||||
{
|
||||
halCommonMemCopy(data, ((int8u *) calibrationData) + offset, length);
|
||||
return ST_SUCCESS;
|
||||
}
|
||||
int8u halCommonWriteToNvm(const void *data, int32u offset, int16u length)
|
||||
{
|
||||
halCommonMemCopy(((int8u *) calibrationData) + offset, data, length);
|
||||
return ST_SUCCESS;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
//flash.h gives access to halInternalFlashErase and halInternalFlashWrite.
|
||||
#include "hal/micro/cortexm3/flash.h"
|
||||
//nvm.h includes memmap.h. These two headers define the key parameters:
|
||||
|
@ -375,3 +399,4 @@ int8u halCommonWriteToNvm(const void *data, int32u offset, int16u length)
|
|||
}
|
||||
}
|
||||
|
||||
#endif // NVM_RAM_EMULATION
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
|
||||
|
||||
|
||||
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 $@
|
||||
|
||||
|
||||
|
|
@ -1,78 +0,0 @@
|
|||
#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 */
|
|
@ -1,34 +0,0 @@
|
|||
#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;
|
||||
}
|
||||
|
|
@ -1,124 +0,0 @@
|
|||
/*
|
||||
* 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
|
||||
|
||||
|
|
@ -1,389 +0,0 @@
|
|||
/*
|
||||
* 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
|
||||
|
||||
|
File diff suppressed because it is too large
Load diff
|
@ -1,284 +0,0 @@
|
|||
/****************************************************************
|
||||
*
|
||||
* 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
|
||||
|
||||
|
Binary file not shown.
|
@ -99,9 +99,9 @@ _disableBasePri:
|
|||
_basePriIsDisabled:
|
||||
MRS R0, BASEPRI // read current BASEPRI
|
||||
CMP R0, #INTERRUPTS_DISABLED_PRIORITY
|
||||
ITE le
|
||||
LDRLE R0, =1
|
||||
LDRGT R0, =0
|
||||
ITE lt
|
||||
LDRLT R0, =0
|
||||
LDRGE R0, =1
|
||||
BX LR
|
||||
__CFI__(EndBlock cfiBlock3)
|
||||
|
||||
|
|
|
@ -1,24 +1,221 @@
|
|||
/** @file board.h
|
||||
* @brief Header file x STM32W108 Kits boards
|
||||
* @brief Header file x STM32W108 Kits boards abstraction.
|
||||
* See @ref board for documentation.
|
||||
*
|
||||
*
|
||||
* See hal/micro/cortexm3/stm32w108/board.h for source code.
|
||||
*
|
||||
* <!--(C) COPYRIGHT 2010 STMicroelectronics. All rights reserved. -->
|
||||
*/
|
||||
#ifndef _BOARD_H_
|
||||
#define _BOARD_H_
|
||||
|
||||
#ifdef BOARD_MB851
|
||||
/** @addtogroup board
|
||||
* @brief ST board abstraction layer
|
||||
*
|
||||
* This header defines API and data structures to handle ST boards with thei associated resources
|
||||
* on algorithm behavior.
|
||||
* See hal/micro/cortexm3/stm32w108/board.h for source code.
|
||||
*@{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Define the number of LEDs in the specific board revision
|
||||
*/
|
||||
#define LEDS_MB851A 2
|
||||
/**
|
||||
* @brief Define the number of LEDs in the specific board revision
|
||||
*/
|
||||
#define LEDS_MB851B 2
|
||||
/**
|
||||
* @brief Define the number of LEDs in the specific board revision
|
||||
*/
|
||||
#define LEDS_MB851C 2
|
||||
/**
|
||||
* @brief Define the number of LEDs in the specific board revision
|
||||
*/
|
||||
#define LEDS_MB954A 2
|
||||
/**
|
||||
* @brief Define the number of LEDs in the specific board revision
|
||||
*/
|
||||
#define LEDS_MB954B 2
|
||||
/**
|
||||
* @brief Define the number of LEDs in the specific board revision
|
||||
*/
|
||||
#define LEDS_MB950A 2
|
||||
/**
|
||||
* @brief Define the number of LEDs in the specific board revision
|
||||
*/
|
||||
#define LEDS_MB951A 2
|
||||
|
||||
/**
|
||||
* @brief Define the number of user buttons in the specific board revision
|
||||
*/
|
||||
#define BUTTONS_MB851A 1
|
||||
/**
|
||||
* @brief Define the number of user buttons in the specific board revision
|
||||
*/
|
||||
#define BUTTONS_MB851B 1
|
||||
/**
|
||||
* @brief Define the number of user buttons in the specific board revision
|
||||
*/
|
||||
#define BUTTONS_MB851C 1
|
||||
/**
|
||||
* @brief Define the number of user buttons in the specific board revision
|
||||
*/
|
||||
#define BUTTONS_MB954A 1
|
||||
/**
|
||||
* @brief Define the number of user buttons in the specific board revision
|
||||
*/
|
||||
#define BUTTONS_MB954B 1
|
||||
/**
|
||||
* @brief Define the number of user buttons in the specific board revision
|
||||
*/
|
||||
#define BUTTONS_MB950A 5
|
||||
/**
|
||||
* @brief Define the number of user buttons in the specific board revision
|
||||
*/
|
||||
#define BUTTONS_MB951A 0
|
||||
|
||||
/**
|
||||
* @brief Data structure for led description
|
||||
*/
|
||||
typedef struct LedResourceStruct {
|
||||
/** Name of the LED as printed in the board */
|
||||
char *name;
|
||||
/** GPIO port associated with the LED */
|
||||
int8u gpioPort;
|
||||
/** GPIO pin associated with the LED */
|
||||
int8u gpioPin;
|
||||
} LedResourceType;
|
||||
|
||||
typedef LedResourceType InfraRedLedResourceType;
|
||||
|
||||
/**
|
||||
* @brief Data structure for button description
|
||||
*/
|
||||
typedef struct ButtonResourceStruct {
|
||||
/** Name of the button as printed in the board */
|
||||
char *name;
|
||||
/** GPIO port associated with the button */
|
||||
int8u gpioPort;
|
||||
/** GPIO pin associated with the button */
|
||||
int8u gpioPin;
|
||||
} ButtonResourceType;
|
||||
|
||||
/**
|
||||
* @brief Data structure for MEMS description
|
||||
*/
|
||||
typedef struct MemsResourceStruct {
|
||||
/** Name of the MEMS device */
|
||||
char *name;
|
||||
/** Serial communication port associated with the MEMS */
|
||||
int8u scPort;
|
||||
} MemsResourceType;
|
||||
|
||||
/**
|
||||
* @brief Data structure for temperature sensor description
|
||||
*/
|
||||
typedef struct TempSensorResourceStruct {
|
||||
/** Name of the temperature sensor device */
|
||||
char *name;
|
||||
/** GPIO port associated with the sensor */
|
||||
int8u gpioPort;
|
||||
/** GPIO pin associated with the sensor */
|
||||
int8u gpioPin;
|
||||
/** Flag to indicate whether the ADC range extension bug fix is implemented */
|
||||
boolean adcFix;
|
||||
} TempSensorResourceType;
|
||||
|
||||
/**
|
||||
* @brief Data structure for board user I/O
|
||||
*/
|
||||
typedef struct BoardIOStruct {
|
||||
/** Pointer to LED resources */
|
||||
const LedResourceType *leds;
|
||||
/** Pointer to button resources */
|
||||
const ButtonResourceType *buttons;
|
||||
} BoardIOType;
|
||||
|
||||
/**
|
||||
* @brief Flag to indicate if MEMS is present
|
||||
*/
|
||||
#define BOARD_HAS_MEMS (1 << 0)
|
||||
/**
|
||||
* @brief Flag to indicate if temeprature sensor is present
|
||||
*/
|
||||
#define BOARD_HAS_TEMP_SENSOR (1 << 1)
|
||||
/**
|
||||
* @brief Flag to indicate if external power amplifier is present
|
||||
*/
|
||||
#define BOARD_HAS_PA (1 << 2)
|
||||
/**
|
||||
* @brief Flag to indicate if EEPROM is present
|
||||
*/
|
||||
#define BOARD_HAS_EEPROM (1 << 3)
|
||||
/**
|
||||
* @brief Flag to indicate if FTDI is used as PC interface
|
||||
*/
|
||||
#define BOARD_HAS_FTDI (1 << 4)
|
||||
/**
|
||||
* @brief Flag to indicate if STM32F is used as PC interface
|
||||
*/
|
||||
#define BOARD_HAS_STM32F (1 << 5)
|
||||
|
||||
/**
|
||||
* @brief Data structure describing board features
|
||||
*/
|
||||
typedef struct BoardResourcesStruct {
|
||||
const char *name;
|
||||
const int32u flags;
|
||||
/** Number of buttons */
|
||||
int8u buttons;
|
||||
/** Number of leds */
|
||||
int8u leds;
|
||||
/** Board I/O description */
|
||||
const BoardIOType *io;
|
||||
/** Board infrared led description */
|
||||
const InfraRedLedResourceType* infraredLed;
|
||||
/** Board infrared MEMS description */
|
||||
const MemsResourceType *mems;
|
||||
/** Board infrared temeprature sensor description */
|
||||
const TempSensorResourceType *temperatureSensor;
|
||||
} BoardResourcesType;
|
||||
|
||||
extern BoardResourcesType const *boardDescription;
|
||||
|
||||
// Generic definitions
|
||||
#define GPIO_PxCLR_BASE (GPIO_PACLR_ADDR)
|
||||
#define GPIO_PxSET_BASE (GPIO_PASET_ADDR)
|
||||
#define GPIO_PxOUT_BASE (GPIO_PAOUT_ADDR)
|
||||
#define GPIO_PxIN_BASE (GPIO_PAIN_ADDR)
|
||||
// Each port is offset from the previous port by the same amount
|
||||
#define GPIO_Px_OFFSET (GPIO_PBCFGL_ADDR-GPIO_PACFGL_ADDR)
|
||||
|
||||
|
||||
/* leds definitions */
|
||||
#define LED_D1 PORTB_PIN(6)
|
||||
#define LED_D3 PORTB_PIN(5)
|
||||
#define LED_D1 PORTx_PIN(boardDescription->io->leds[0].gpioPort, boardDescription->io->leds[0].gpioPin) //PORTB_PIN(6)
|
||||
#define LED_D3 PORTx_PIN(boardDescription->io->leds[1].gpioPort, boardDescription->io->leds[1].gpioPin) // PORTB_PIN(5)
|
||||
#define DUMMY_LED 0xff
|
||||
|
||||
|
||||
/** Description buttons definition */
|
||||
#define BUTTON_S1 PORTA_PIN(7)
|
||||
#define BUTTON_S1_INPUT_GPIO GPIO_PAIN
|
||||
#define BUTTON_S1_OUTPUT_GPIO GPIO_PAOUT
|
||||
#define BUTTON_S1_GPIO_PIN PA7_BIT
|
||||
#define BUTTON_S1_WAKE_SOURCE 0x00000080
|
||||
#define BUTTON_Sn(n) (PORTx_PIN(boardDescription->io->buttons[n].gpioPort, boardDescription->io->buttons[n].gpioPin))
|
||||
#define BUTTON_Sn_WAKE_SOURCE(n) (1 << ((boardDescription->io->buttons[n].gpioPin) + (8 * (boardDescription->io->buttons[n].gpioPort >> 3))))
|
||||
#define BUTTON_INPUT_GPIO(port) *((volatile int32u *) (GPIO_PxIN_BASE + GPIO_Px_OFFSET * port))
|
||||
#define DUMMY_BUTTON 0xff
|
||||
|
||||
#define BUTTON_S1 (boardDescription->buttons>0 ? BUTTON_Sn(0): DUMMY_BUTTON)
|
||||
#define BUTTON_S2 (boardDescription->buttons>1 ? BUTTON_Sn(1): DUMMY_BUTTON)
|
||||
#define BUTTON_S3 (boardDescription->buttons>2 ? BUTTON_Sn(2): DUMMY_BUTTON)
|
||||
#define BUTTON_S4 (boardDescription->buttons>3 ? BUTTON_Sn(3): DUMMY_BUTTON)
|
||||
#define BUTTON_S5 (boardDescription->buttons>4 ? BUTTON_Sn(4): DUMMY_BUTTON)
|
||||
|
||||
#define BUTTON_S1_WAKE_SOURCE (boardDescription->buttons>0 ? BUTTON_Sn_WAKE_SOURCE(0): 0)
|
||||
#define BUTTON_S2_WAKE_SOURCE (boardDescription->buttons>1 ? BUTTON_Sn_WAKE_SOURCE(1): 0)
|
||||
#define BUTTON_S3_WAKE_SOURCE (boardDescription->buttons>2 ? BUTTON_Sn_WAKE_SOURCE(2): 0)
|
||||
#define BUTTON_S4_WAKE_SOURCE (boardDescription->buttons>3 ? BUTTON_Sn_WAKE_SOURCE(3): 0)
|
||||
#define BUTTON_S5_WAKE_SOURCE (boardDescription->buttons>4 ? BUTTON_Sn_WAKE_SOURCE(4): 0)
|
||||
|
||||
/** Description uart definition */
|
||||
#define UART_TX PORTB_PIN(1)
|
||||
|
@ -26,8 +223,37 @@
|
|||
#define UART_RX_WAKE_SOURCE 0x00000400
|
||||
|
||||
/** Description temperature sensor GPIO */
|
||||
#define TEMPERATURE_SENSOR_GPIO PORTB_PIN(7)
|
||||
#endif /* BOARD_MB851 */
|
||||
#define TEMPERATURE_SENSOR_GPIO PORTx_PIN(boardDescription->temperatureSensor->gpioPort, boardDescription->temperatureSensor->gpioPin) // PORTB_PIN(7)
|
||||
|
||||
/** @brief Return pointer to board description structure
|
||||
*
|
||||
*
|
||||
* @return Pointer to board description structure
|
||||
*/
|
||||
BoardResourcesType const *halBoardGetDescription(void);
|
||||
/**
|
||||
* @brief Initialize the board description data structure after
|
||||
* autodetect of the boards based on the CIB Board name field
|
||||
* content. In case of invalid CIB data it will default to MB851A.
|
||||
* Customer normally needs to modify this file to adapt it to their specific board.
|
||||
*/
|
||||
void halBoardInit(void);
|
||||
/**
|
||||
* @brief Perform board specific action to power up the system.
|
||||
* This code depends on the actual board features and configure
|
||||
* the stm32w and on board devices for proper operation.
|
||||
* Customer normally needs to modify this file to adapt it to their specific board.
|
||||
*/
|
||||
void halBoardPowerUp(void);
|
||||
/**
|
||||
* @brief Perform board specific action to power down the system, usually before going to deep sleep.
|
||||
* This code depends on the actual board features and configure
|
||||
* the stm32w and on board devices for minimal power consumption.
|
||||
* Customer normally needs to modify this file to adapt it to their specific board.
|
||||
*/
|
||||
void halBoardPowerDown(void);
|
||||
|
||||
#endif /* _BOARD_H_ */
|
||||
|
||||
/** @} // END addtogroup
|
||||
*/
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
#define RESERVED 0
|
||||
//#define DUMMY_MALLOC
|
||||
|
||||
#define IAP_BOOTLOADER_APP_SWITCH_SIGNATURE 0xb001204d
|
||||
#define IAP_BOOTLOADER_MODE_UART 0
|
||||
/* Includes ----------------------------------------------------------------------*/
|
||||
#include PLATFORM_HEADER
|
||||
void NMI_Handler(void);
|
||||
|
@ -72,7 +72,7 @@ VAR_AT_SEGMENT(const HalFixedAddressTableType halFixedAddressTable, __FAT__);
|
|||
/* function prototypes ------------------------------------------------------*/
|
||||
void Reset_Handler(void) __attribute__((__interrupt__));
|
||||
extern int main(void);
|
||||
|
||||
extern void halInternalSwitchToXtal(void);
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
|
@ -121,6 +121,20 @@ void (* const g_pfnVectors[])(void) =
|
|||
halDebugIsr, // 32
|
||||
};
|
||||
|
||||
static void setStackPointer(int32u address) __attribute__((noinline));
|
||||
static void setStackPointer(int32u address)
|
||||
{
|
||||
// This code is needed to generate the instruction below
|
||||
// that GNU ASM is refusing to add
|
||||
// asm("MOVS SP, r0");
|
||||
asm(".short 0x4685");
|
||||
}
|
||||
|
||||
static const int16u blOffset[] = {
|
||||
0x0715 - 0x03ad - 0x68,
|
||||
0x0719 - 0x03ad - 0x6C
|
||||
};
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Reset_Handler
|
||||
* Description : This is the code that gets called when the processor first starts execution
|
||||
|
@ -244,6 +258,21 @@ void Reset_Handler(void)
|
|||
while(1) { ; }
|
||||
}
|
||||
|
||||
//USART bootloader software activation check
|
||||
if ((*((int32u *)RAM_BOTTOM) == IAP_BOOTLOADER_APP_SWITCH_SIGNATURE) && (*((int8u *)(RAM_BOTTOM+4)) == IAP_BOOTLOADER_MODE_UART)){
|
||||
int8u cut = *(volatile int8u *) 0x08040798;
|
||||
int16u offset = 0;
|
||||
typedef void (*EntryPoint)(void);
|
||||
offset = (halFixedAddressTable.baseTable.version == 3) ? blOffset[cut - 2] : 0;
|
||||
*((int32u *)RAM_BOTTOM) = 0;
|
||||
if (offset) {
|
||||
halInternalSwitchToXtal();
|
||||
}
|
||||
EntryPoint entryPoint = (EntryPoint)(*(int32u *)(FIB_BOTTOM+4) - offset);
|
||||
setStackPointer(*(int32u *)FIB_BOTTOM);
|
||||
entryPoint();
|
||||
}
|
||||
|
||||
INTERRUPTS_OFF();
|
||||
asm("CPSIE i");
|
||||
|
||||
|
@ -302,12 +331,10 @@ caddr_t _sbrk ( int incr )
|
|||
return (caddr_t) prev_heap;
|
||||
}
|
||||
#else
|
||||
# ifdef DUMMY_MALLOC
|
||||
caddr_t _sbrk ( int incr )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
int _lseek (int file,
|
||||
int ptr,
|
||||
|
|
|
@ -13,71 +13,65 @@ GROUP(
|
|||
These are used by the startup in order to allocate stacks for the different modes.
|
||||
*/
|
||||
|
||||
__Stack_Size = 0x500 ;
|
||||
__Stack_Size = 0x400 ;
|
||||
|
||||
PROVIDE ( _Stack_Size = __Stack_Size ) ;
|
||||
|
||||
__Stack_Init = _estack - __Stack_Size ;
|
||||
__Stack_Init = 0x20000000;
|
||||
|
||||
_estack = __Stack_Init + __Stack_Size;
|
||||
|
||||
|
||||
/*"PROVIDE" allows to easily override these values from an object file or the commmand line.*/
|
||||
PROVIDE ( _Stack_Init = __Stack_Init ) ;
|
||||
|
||||
/*
|
||||
There will be a link error if there is not this amount of RAM free at the end.
|
||||
*/
|
||||
_Minimum_Stack_Size = 0x500 ;
|
||||
|
||||
|
||||
/*
|
||||
this sends all unreferenced IRQHandlers to reset
|
||||
*/
|
||||
|
||||
PROVIDE(Default_Handler = 0 );
|
||||
PROVIDE(NMI_Handler = Default_Handler );
|
||||
PROVIDE(HardFault_Handler = Default_Handler );
|
||||
PROVIDE(MemManage_Handler = Default_Handler );
|
||||
PROVIDE(BusFault_Handler = Default_Handler );
|
||||
PROVIDE(UsageFault_Handler = Default_Handler );
|
||||
PROVIDE(SVC_Handler = Default_Handler );
|
||||
PROVIDE(DebugMonitor_Handler = Default_Handler );
|
||||
PROVIDE(PendSV_Handler = Default_Handler );
|
||||
PROVIDE(SysTick_Handler = Default_Handler );
|
||||
PROVIDE(halTimer1Isr = Default_Handler );
|
||||
PROVIDE(halTimer2Isr = Default_Handler );
|
||||
PROVIDE(halManagementIsr = Default_Handler );
|
||||
PROVIDE(halBaseBandIsr = Default_Handler );
|
||||
PROVIDE(halSleepTimerIsr = Default_Handler );
|
||||
PROVIDE(halSc1Isr = Default_Handler );
|
||||
PROVIDE(halSc2Isr = Default_Handler );
|
||||
PROVIDE(halSecurityIsr = Default_Handler );
|
||||
PROVIDE(halStackMacTimerIsr = Default_Handler );
|
||||
PROVIDE(stmRadioTransmitIsr = Default_Handler );
|
||||
PROVIDE(stmRadioReceiveIsr = Default_Handler );
|
||||
PROVIDE(halAdcIsr = Default_Handler );
|
||||
PROVIDE(halIrqAIsr = Default_Handler );
|
||||
PROVIDE(halIrqBIsr = Default_Handler );
|
||||
PROVIDE(halIrqCIsr = Default_Handler );
|
||||
PROVIDE(halIrqDIsr = Default_Handler );
|
||||
PROVIDE(halDebugIsr = Default_Handler );
|
||||
/*PROVIDE(stSerialPrintf = printf );*/
|
||||
PROVIDE(NMI_Handler = 0 );
|
||||
PROVIDE(HardFault_Handler = 0 );
|
||||
PROVIDE(MemManage_Handler = 0 );
|
||||
PROVIDE(BusFault_Handler = 0 );
|
||||
PROVIDE(UsageFault_Handler = 0 );
|
||||
PROVIDE(SVC_Handler = 0 );
|
||||
PROVIDE(DebugMonitor_Handler = 0 );
|
||||
PROVIDE(PendSV_Handler = 0 );
|
||||
PROVIDE(SysTick_Handler = 0 );
|
||||
PROVIDE(halTimer1Isr = 0 );
|
||||
PROVIDE(halTimer2Isr = 0 );
|
||||
PROVIDE(halManagementIsr = 0 );
|
||||
PROVIDE(halBaseBandIsr = 0 );
|
||||
PROVIDE(halSleepTimerIsr = 0 );
|
||||
PROVIDE(halSc1Isr = 0 );
|
||||
PROVIDE(halSc2Isr = 0 );
|
||||
PROVIDE(halSecurityIsr = 0 );
|
||||
PROVIDE(halStackMacTimerIsr = 0 );
|
||||
PROVIDE(stmRadioTransmitIsr = 0 );
|
||||
PROVIDE(stmRadioReceiveIsr = 0 );
|
||||
PROVIDE(halAdcIsr = 0 );
|
||||
PROVIDE(halIrqAIsr = 0 );
|
||||
PROVIDE(halIrqBIsr = 0 );
|
||||
PROVIDE(halIrqCIsr = 0 );
|
||||
PROVIDE(halIrqDIsr = 0 );
|
||||
PROVIDE(halDebugIsr = 0 );
|
||||
|
||||
/******************************************************************************/
|
||||
/* Peripheral memory map */
|
||||
/******************************************************************************/
|
||||
/*this allows to compile the ST lib in "non-debug" mode*/
|
||||
|
||||
|
||||
_BOOTLOADER_SIZE = 0x3000 ;
|
||||
_ROM_base = DEFINED(ST_BTL) ? (0x08000000 + _BOOTLOADER_SIZE) : 0x08000000 ;
|
||||
/* include the memory spaces definitions sub-script */
|
||||
MEMORY
|
||||
{
|
||||
RAM_region (xrw) : ORIGIN = 0x20000000, LENGTH = 8K
|
||||
ROM_region (rx) : ORIGIN = 0x08000000, LENGTH = 128K-3K
|
||||
NVM_region (rx) : ORIGIN = 0x0801F400, LENGTH = 3K
|
||||
ROM_region (rx) : ORIGIN = 0x08000000, LENGTH = 128K-2K
|
||||
NVM_region (rx) : ORIGIN = 0x0801F800, LENGTH = 2K
|
||||
FIB_region (ra) : ORIGIN = 0x08040000, LENGTH = 2K
|
||||
}
|
||||
|
||||
/* higher address of the user mode stack */
|
||||
_estack = 0x20002000;
|
||||
|
||||
/* Sections management for FLASH mode */
|
||||
|
||||
|
@ -87,9 +81,12 @@ SECTIONS
|
|||
{
|
||||
|
||||
/* for Cortex devices, the beginning of the startup code is stored in the .isr_vector section, which goes to FLASH */
|
||||
.isr_vector :
|
||||
|
||||
.isr_vector (DEFINED(ST_BTL) ? (0x08000000 + _BOOTLOADER_SIZE) : 0x08000000) :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
__ApplicationFlashStart = . ;
|
||||
/* . = . + _ROM_base ;*/
|
||||
KEEP(*(.isr_vector)) /* Startup code */
|
||||
. = ALIGN(4);
|
||||
} >ROM_region
|
||||
|
@ -113,24 +110,12 @@ SECTIONS
|
|||
*(.rodata*)
|
||||
*(.glue_7)
|
||||
*(.glue_7t)
|
||||
. = ALIGN(1024);
|
||||
*(.elf_text)
|
||||
. = ALIGN(1024);
|
||||
/*. = ALIGN(4);*/
|
||||
|
||||
. = ALIGN(4);
|
||||
_etext = .;
|
||||
/* This is used by the startup in order to initialize the .data section */
|
||||
/* This is used by the startup in order to initialize the .data secion */
|
||||
_sidata = _etext;
|
||||
} >ROM_region
|
||||
|
||||
.coffee 0x08010000 :
|
||||
{
|
||||
_coffee_start = ABSOLUTE(.);
|
||||
. = ALIGN(1024);
|
||||
*(.coffeefiles)
|
||||
. = ORIGIN(NVM_region) - _coffee_start;
|
||||
} > ROM_region = 0x00
|
||||
|
||||
|
||||
NVM (NOLOAD):
|
||||
{
|
||||
. = ALIGN(1024);
|
||||
|
@ -146,6 +131,12 @@ SECTIONS
|
|||
. = ALIGN(4);
|
||||
} > FIB_region
|
||||
|
||||
/*
|
||||
.FAT (NOLOAD):
|
||||
{
|
||||
KEEP(*(.FAT))
|
||||
} > FIB_region
|
||||
*/
|
||||
/* after that it's only debugging information. */
|
||||
|
||||
|
||||
|
@ -153,10 +144,10 @@ SECTIONS
|
|||
The program executes knowing that the data is in the RAM
|
||||
but the loader puts the initial values in the FLASH (inidata).
|
||||
It is one task of the startup to copy the initial values from FLASH to RAM. */
|
||||
.data : AT ( _sidata )
|
||||
.data _estack : AT ( _sidata )
|
||||
{
|
||||
. = ALIGN(4);
|
||||
/* This is used by the startup in order to initialize the .data section */
|
||||
/* This is used by the startup in order to initialize the .data secion */
|
||||
_sdata = . ;
|
||||
|
||||
*(.data)
|
||||
|
@ -165,9 +156,9 @@ SECTIONS
|
|||
. = ALIGN(4);
|
||||
/* This is used by the startup in order to initialize the .data secion */
|
||||
_edata = . ;
|
||||
ASSERT(_sidata + SIZEOF(.data) < LOADADDR(.coffee), ".data section overflow in ROM");
|
||||
} >RAM_region
|
||||
|
||||
|
||||
|
||||
/* This is the uninitialized data section */
|
||||
.bss :
|
||||
|
@ -177,6 +168,7 @@ SECTIONS
|
|||
_sbss = .;
|
||||
|
||||
*(.bss)
|
||||
*(.bss.*)
|
||||
*(COMMON)
|
||||
|
||||
. = ALIGN(4);
|
||||
|
@ -186,21 +178,6 @@ SECTIONS
|
|||
|
||||
PROVIDE ( end = _ebss );
|
||||
PROVIDE ( _end = _ebss );
|
||||
|
||||
/* This is the user stack section
|
||||
This is just to check that there is enough RAM left for the User mode stack
|
||||
It should generate an error if it's full.
|
||||
*/
|
||||
._usrstack :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_susrstack = . ;
|
||||
|
||||
. = . + _Minimum_Stack_Size ;
|
||||
|
||||
. = ALIGN(4);
|
||||
_eusrstack = . ;
|
||||
} >RAM_region
|
||||
|
||||
__exidx_start = .;
|
||||
__exidx_end = .;
|
||||
|
@ -247,3 +224,5 @@ SECTIONS
|
|||
.debug_typenames 0 : { *(.debug_typenames) }
|
||||
.debug_varnames 0 : { *(.debug_varnames) }
|
||||
}
|
||||
|
||||
__ApplicationFlashEnd = _sidata + (_edata - _sdata);
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
define symbol __ICFEDIT_intvec_start__ = 0x08000000;
|
||||
/*-Memory Regions-*/
|
||||
define symbol __ICFEDIT_region_ROM_start__ = 0x08000000;
|
||||
define symbol __ICFEDIT_region_ROM_end__ = 0x0800FFFF;
|
||||
define symbol __ICFEDIT_region_CFS_start__ = 0x08010000; /* Reserved for contiki flash file system. COFFEE_ADDRESS must be changed also in cfs-coffee-arch.h */
|
||||
define symbol __ICFEDIT_region_CFS_end__ = 0x0801F3FF;
|
||||
define symbol __ICFEDIT_region_NVM_start__ = 0x0801F400;
|
||||
define symbol __ICFEDIT_region_NVM_end__ = 0x0801FFFF;
|
||||
define symbol __ICFEDIT_region_FIB_start__ = 0x08040000;
|
||||
define symbol __ICFEDIT_region_FIB_end__ = 0x080407FF;
|
||||
define symbol __ICFEDIT_region_RAM_start__ = 0x20000000;
|
||||
define symbol __ICFEDIT_region_RAM_end__ = 0x20001FFF;
|
||||
/*-Sizes-*/
|
||||
define symbol __ICFEDIT_size_cstack__ = 0x500;
|
||||
|
||||
|
||||
define memory mem with size = 4G;
|
||||
define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__];
|
||||
define region CFS_region = mem:[from __ICFEDIT_region_CFS_start__ to __ICFEDIT_region_CFS_end__];
|
||||
define region NVM_region = mem:[from __ICFEDIT_region_NVM_start__ to __ICFEDIT_region_NVM_end__];
|
||||
define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__];
|
||||
|
||||
define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { };
|
||||
|
||||
initialize by copy { readwrite };
|
||||
do not initialize { section .noinit,
|
||||
section FAT,
|
||||
section NVM };
|
||||
|
||||
place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };
|
||||
|
||||
place at address mem:__ICFEDIT_region_FIB_start__ { section FAT };
|
||||
place in ROM_region { readonly };
|
||||
place in CFS_region { section .coffeefiles };
|
||||
place in NVM_region { section NVM };
|
||||
place in RAM_region { readwrite,
|
||||
block CSTACK };
|
|
@ -1,13 +1,21 @@
|
|||
|
||||
if( isdefinedsymbol(ST_BTL) ) {
|
||||
define symbol __ICFEDIT_intvec_start__ = 0x08003000;
|
||||
define symbol __ICFEDIT_region_ROM_start__ = 0x08003000;
|
||||
} else {
|
||||
define symbol __ICFEDIT_intvec_start__ = 0x08000000;
|
||||
/*-Memory Regions-*/
|
||||
define symbol __ICFEDIT_region_ROM_start__ = 0x08000000;
|
||||
}
|
||||
|
||||
/*-Memory Regions-*/
|
||||
define symbol __ICFEDIT_region_ROM_end__ = 0x0801FFFF;
|
||||
define symbol __ICFEDIT_region_FIB_start__ = 0x08040000;
|
||||
define symbol __ICFEDIT_region_FIB_end__ = 0x080407FF;
|
||||
define symbol __ICFEDIT_region_RAM_start__ = 0x20000000;
|
||||
define symbol __ICFEDIT_region_RAM_end__ = 0x20001FFF;
|
||||
/*-Sizes-*/
|
||||
define symbol __ICFEDIT_size_cstack__ = 0x500;
|
||||
define symbol __ICFEDIT_size_cstack__ = 0x400;
|
||||
|
||||
|
||||
|
||||
define memory mem with size = 4G;
|
||||
|
@ -15,16 +23,17 @@ define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFED
|
|||
define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__];
|
||||
|
||||
define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { };
|
||||
define block FLASH_IMAGE with fixed order { readonly section .intvec, readonly } ;
|
||||
|
||||
initialize by copy { readwrite };
|
||||
do not initialize { section .noinit,
|
||||
section FAT,
|
||||
section NVM };
|
||||
|
||||
place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };
|
||||
|
||||
place at address mem:__ICFEDIT_region_FIB_start__ { section FAT };
|
||||
place in ROM_region { readonly };
|
||||
place in ROM_region { block FLASH_IMAGE };
|
||||
|
||||
place at end of ROM_region { section NVM };
|
||||
place in RAM_region { readwrite,
|
||||
block CSTACK };
|
||||
|
||||
|
|
|
@ -31,10 +31,24 @@ extern "C" {
|
|||
__root __no_init const HalFixedAddressTableType halFixedAddressTable @ __FAT__;
|
||||
|
||||
extern const HalVectorTableType __vector_table[];
|
||||
extern void halInternalSwitchToXtal(void);
|
||||
|
||||
#define IAP_BOOTLOADER_APP_SWITCH_SIGNATURE 0xb001204d
|
||||
#define IAP_BOOTLOADER_MODE_UART 0
|
||||
|
||||
__interwork int __low_level_init(void);
|
||||
|
||||
static void setStackPointer(int32u address)
|
||||
{
|
||||
asm("MOVS SP, r0");
|
||||
}
|
||||
|
||||
static const int16u blOffset[] = {
|
||||
0x0715 - 0x03ad - 0x68,
|
||||
0x0719 - 0x03ad - 0x6C
|
||||
};
|
||||
|
||||
|
||||
__interwork int __low_level_init(void)
|
||||
{
|
||||
//Ensure there is enough margin on VREG_1V8 for stable RAM reads by
|
||||
|
@ -154,6 +168,21 @@ __interwork int __low_level_init(void)
|
|||
while(1) { ; }
|
||||
}
|
||||
|
||||
//USART bootloader software activation check
|
||||
if ((*((int32u *)RAM_BOTTOM) == IAP_BOOTLOADER_APP_SWITCH_SIGNATURE) && (*((int8u *)(RAM_BOTTOM+4)) == IAP_BOOTLOADER_MODE_UART)){
|
||||
int8u cut = *(volatile int8u *) 0x08040798;
|
||||
int16u offset = 0;
|
||||
typedef void (*EntryPoint)(void);
|
||||
offset = (halFixedAddressTable.baseTable.version == 3) ? blOffset[cut - 2] : 0;
|
||||
*((int32u *)RAM_BOTTOM) = 0;
|
||||
if (offset) {
|
||||
halInternalSwitchToXtal();
|
||||
}
|
||||
EntryPoint entryPoint = (EntryPoint)(*(int32u *)(FIB_BOTTOM+4) - offset);
|
||||
setStackPointer(*(int32u *)FIB_BOTTOM);
|
||||
entryPoint();
|
||||
}
|
||||
|
||||
INTERRUPTS_OFF();
|
||||
asm("CPSIE i");
|
||||
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
#define __REGS_H__ 1
|
||||
|
||||
|
||||
#define ReadRegister(a) a
|
||||
#define WriteRegister(a, b) a = b
|
||||
|
||||
/* FLASH_BASE block */
|
||||
#define DATA_FLASH_BASE_BASE (0x00000000u)
|
||||
#define DATA_FLASH_BASE_END (0x0001FFFFu)
|
||||
|
|
|
@ -29,18 +29,17 @@ void temperatureSensor_Init(void)
|
|||
#endif /* ENABLE_ADC_EXTENDED_RANGE_BROKEN */
|
||||
}/* end temperatureSensor_Init() */
|
||||
|
||||
int32u temperatureSensor_GetValue(int8u type)
|
||||
int32u temperatureSensor_GetValue(void)
|
||||
{
|
||||
static int16u ADCvalue;
|
||||
static int16s volts;
|
||||
|
||||
/*
|
||||
NOTE:
|
||||
The ADC extended range is inaccurate due to the high voltage mode bug of the general purpose ADC
|
||||
(see STM32W108 errata). As consequence, it is not reccomended to use this ADC driver for getting
|
||||
the temperature values.
|
||||
*/
|
||||
#ifdef ENABLE_ADC_EXTENDED_RANGE_BROKEN
|
||||
/*
|
||||
NOTE:
|
||||
The ADC extended range is inaccurate due to the high voltage mode bug of the general purpose ADC
|
||||
(see STM32W108 errata). As consequence, it is not reccomended to use this ADC driver for getting
|
||||
the temperature values.
|
||||
*/
|
||||
halStartAdcConversion(ADC_USER_APP, ADC_REF_INT, ADC_SOURCE_ADC2_VREF2, ADC_CONVERSION_TIME_US_4096);
|
||||
|
||||
halReadAdcBlocking(ADC_USER_APP, &ADCvalue); // This blocks for a while, about 4ms.
|
||||
|
@ -49,6 +48,5 @@ int32u temperatureSensor_GetValue(int8u type)
|
|||
volts = halConvertValueToVolts(ADCvalue);
|
||||
|
||||
return ((18641 - (int32s)volts)*100)/1171;
|
||||
#endif /* ENABLE_ADC_EXTENDED_RANGE_BROKEN */
|
||||
}/* end temperatureSensor_GetValue() */
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue