add fflush to exit

enable DEVICE_STDIO_MESSAGES on k64f
remove all line endings from error messages throughout mbed sdk (all targets)
pull/259/head
sg- 2014-04-09 16:24:13 -05:00
parent e20949093c
commit b64e32299f
41 changed files with 67 additions and 59 deletions

View File

@ -37,7 +37,7 @@
* To generate a fatal run-time error, you can use the mbed error() function.
*
* @code
* error("That shouldn't have happened!\n");
* error("That shouldn't have happened!");
* @endcode
*
* If the mbed running the program executes this function, it will print the
@ -48,7 +48,7 @@
*
* @code
* if(x >= 5) {
* error("expected x to be less than 5, but got %d\n", x);
* error("expected x to be less than 5, but got %d", x);
* }
* #endcode
*/

View File

@ -15,6 +15,9 @@
*/
#include "semihost_api.h"
#include "mbed_interface.h"
#if DEVICE_STDIO_MESSAGES
#include <stdio.h>
#endif
#ifdef TOOLCHAIN_GCC_CW
// TODO: Ideally, we would like to define directly "_ExitProcess"
@ -23,6 +26,11 @@ void mbed_exit(int return_code) {
void exit(int return_code) {
#endif
#if DEVICE_STDIO_MESSAGES
fflush(stdout);
fflush(stderr);
#endif
#if DEVICE_SEMIHOST
if (mbed_interface_connected()) {
semihost_exit();

View File

@ -28,7 +28,7 @@ void pinmap_pinout(PinName pin, const PinMap *map) {
}
map++;
}
error("could not pinout\n");
error("could not pinout");
}
uint32_t pinmap_merge(uint32_t a, uint32_t b) {
@ -40,7 +40,7 @@ uint32_t pinmap_merge(uint32_t a, uint32_t b) {
if (b == (uint32_t)NC) return a;
// mis-match error case
error("pinmap mis-match\n");
error("pinmap mis-match");
return (uint32_t)NC;
}
@ -60,6 +60,6 @@ uint32_t pinmap_peripheral(PinName pin, const PinMap* map) {
return (uint32_t)NC;
peripheral = pinmap_find_peripheral(pin, map);
if ((uint32_t)NC == peripheral) // no mapping available
error("pinmap not found for peripheral\n");
error("pinmap not found for peripheral");
return peripheral;
}

View File

@ -386,7 +386,7 @@ extern "C" int mkdir(const char *path, mode_t mode) {
#include "error.h"
namespace __gnu_cxx {
void __verbose_terminate_handler() {
error("Exception\n");
error("Exception");
}
}
extern "C" WEAK void __cxa_pure_virtual(void);

View File

@ -39,7 +39,7 @@ static const PinMap PinMap_ADC[] = {
void analogin_init(analogin_t *obj, PinName pin) {
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
if (obj->adc == (ADCName)NC)
error("ADC pin mapping failed\n");
error("ADC pin mapping failed");
SIM->SCGC6 |= SIM_SCGC6_ADC0_MASK;

View File

@ -108,7 +108,7 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32
break;
default:
error("gpio_irq only supported on port A-E.\n");
error("gpio_irq only supported on port A-E.");
break;
}
NVIC_SetVector(irq_n, vector);

View File

@ -57,7 +57,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
obj->i2c = (I2C_Type*)pinmap_merge(i2c_sda, i2c_scl);
if ((int)obj->i2c == NC)
error("I2C pin mapping failed\n");
error("I2C pin mapping failed");
SIM->SCGC4 |= SIM_SCGC4_I2C0_MASK;
SIM->SCGC5 |= SIM_SCGC5_PORTB_MASK;

View File

@ -54,7 +54,7 @@ void pwmout_init(pwmout_t* obj, PinName pin) {
// determine the channel
PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
if (pwm == (PWMName)NC)
error("PwmOut pin mapping failed\n");
error("PwmOut pin mapping failed");
uint32_t clkdiv = 0;
float clkval = SystemCoreClock / 1000000.0f;

View File

@ -48,7 +48,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
UARTName uart_rx = (UARTName)pinmap_peripheral(rx, PinMap_UART_RX);
UARTName uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
if ((int)uart == NC)
error("Serial pinout mapping failed\n");
error("Serial pinout mapping failed");
obj->uart = (UART_Type *)uart;
// enable clk
@ -126,7 +126,7 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
// 8 data bits = 0 ... 9 data bits = 1
if ((data_bits < 8) || (data_bits > 9))
error("Invalid number of bits (%d) in serial format, should be 8..9\n", data_bits);
error("Invalid number of bits (%d) in serial format, should be 8..9", data_bits);
data_bits -= 8;
@ -136,13 +136,13 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
case ParityOdd : parity_enable = 1; parity_select = 1; data_bits++; break;
case ParityEven: parity_enable = 1; parity_select = 0; data_bits++; break;
default:
error("Invalid serial parity setting\n");
error("Invalid serial parity setting");
return;
}
// 1 stop bits = 0, 2 stop bits = 1
if ((stop_bits != 1) && (stop_bits != 2))
error("Invalid stop bits specified\n");
error("Invalid stop bits specified");
stop_bits -= 1;
uint32_t m10 = 0;
@ -151,7 +151,7 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
if (data_bits == 2) {
// only uart0 supports 10 bit communication
if (obj->index != 0)
error("Invalid number of bits (9) to be used with parity\n");
error("Invalid number of bits (9) to be used with parity");
data_bits = 0;
m10 = 1;
}

View File

@ -57,7 +57,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
obj->spi = (SPI_Type*)pinmap_merge(spi_data, spi_cntl);
if ((int)obj->spi == NC) {
error("SPI pinout mapping failed\n");
error("SPI pinout mapping failed");
}
SIM->SCGC5 |= SIM_SCGC5_PORTC_MASK | SIM_SCGC5_PORTD_MASK;
@ -94,11 +94,11 @@ void spi_free(spi_t *obj) {
}
void spi_format(spi_t *obj, int bits, int mode, int slave) {
if ((bits != 8) && (bits != 16)) {
error("Only 8/16 bits SPI supported\n");
error("Only 8/16 bits SPI supported");
}
if ((mode < 0) || (mode > 3)) {
error("SPI mode unsupported\n");
error("SPI mode unsupported");
}
uint32_t polarity = (mode & 0x2) ? 1 : 0;

View File

@ -99,7 +99,7 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32
break;
default:
error("gpio_irq only supported on Port A and B\n");
error("gpio_irq only supported on Port A and B");
break;
}
NVIC_SetVector(irq_n, vector);

View File

@ -52,7 +52,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
obj->spi = (SPI_Type*)pinmap_merge(spi_data, spi_cntl);
if ((int)obj->spi == NC) {
error("SPI pinout mapping failed\n");
error("SPI pinout mapping failed");
}
// enable power and clocking
@ -88,11 +88,11 @@ void spi_free(spi_t *obj) {
}
void spi_format(spi_t *obj, int bits, int mode, int slave) {
if (bits != 8) {
error("Only 8bits SPI supported\n");
error("Only 8bits SPI supported");
}
if ((mode < 0) || (mode > 3)) {
error("SPI mode unsupported\n");
error("SPI mode unsupported");
}
uint8_t polarity = (mode & 0x2) ? 1 : 0;

View File

@ -89,7 +89,7 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32
break;
default:
error("gpio_irq only supported on port A and D\n");
error("gpio_irq only supported on port A and D");
break;
}
NVIC_SetVector(irq_n, vector);

View File

@ -34,7 +34,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
obj->spi = (SPI_Type*)pinmap_merge(spi_data, spi_cntl);
if ((int)obj->spi == NC) {
error("SPI pinout mapping failed\n");
error("SPI pinout mapping failed");
}
// enable power and clocking
@ -68,11 +68,11 @@ void spi_free(spi_t *obj) {
}
void spi_format(spi_t *obj, int bits, int mode, int slave) {
if (bits != 8) {
error("Only 8bits SPI supported\n");
error("Only 8bits SPI supported");
}
if ((mode < 0) || (mode > 3)) {
error("SPI mode unsupported\n");
error("SPI mode unsupported");
}
uint8_t polarity = (mode & 0x2) ? 1 : 0;

View File

@ -109,7 +109,7 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32
break;
default:
error("gpio_irq only supported on port A,C and D\n");
error("gpio_irq only supported on port A,C and D");
break;
}
NVIC_SetVector(irq_n, vector);

View File

@ -91,7 +91,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
obj->spi = (SPI_Type*)pinmap_merge(spi_data, spi_cntl);
if ((int)obj->spi == NC) {
error("SPI pinout mapping failed\n");
error("SPI pinout mapping failed");
}
// enable power and clocking
@ -126,11 +126,11 @@ void spi_free(spi_t *obj) {
}
void spi_format(spi_t *obj, int bits, int mode, int slave) {
if ((bits != 8) && (bits != 16)) {
error("Only 8/16 bits SPI supported\n");
error("Only 8/16 bits SPI supported");
}
if ((mode < 0) || (mode > 3)) {
error("SPI mode unsupported\n");
error("SPI mode unsupported");
}
uint8_t polarity = (mode & 0x2) ? 1 : 0;

View File

@ -28,7 +28,7 @@
void analogin_init(analogin_t *obj, PinName pin) {
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
if (obj->adc == (ADCName)NC) {
error("ADC pin mapping failed\n");
error("ADC pin mapping failed");
}
SIM->SCGC6 |= SIM_SCGC6_ADC0_MASK;

View File

@ -26,7 +26,7 @@
void analogout_init(dac_t *obj, PinName pin) {
obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC);
if (obj->dac == (DACName)NC) {
error("DAC pin mapping failed\n");
error("DAC pin mapping failed");
}
SIM->SCGC6 |= SIM_SCGC6_DAC0_MASK;

View File

@ -46,7 +46,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
obj->i2c = (I2C_Type*)pinmap_merge(i2c_sda, i2c_scl);
if ((int)obj->i2c == NC) {
error("I2C pin mapping failed\n");
error("I2C pin mapping failed");
}
// enable power

View File

@ -27,7 +27,7 @@ void pwmout_init(pwmout_t* obj, PinName pin) {
// determine the channel
PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
if (pwm == (PWMName)NC)
error("PwmOut pin mapping failed\n");
error("PwmOut pin mapping failed");
uint32_t clkdiv = 0;
float clkval;

View File

@ -62,7 +62,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
UARTName uart_rx = (UARTName)pinmap_peripheral(rx, PinMap_UART_RX);
UARTName uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
if ((int)uart == NC) {
error("Serial pinout mapping failed\n");
error("Serial pinout mapping failed");
}
obj->uart = (UARTLP_Type *)uart;
@ -159,7 +159,7 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
// TODO: Support other number of data bits (also in the write method!)
if ((data_bits < 8) || (data_bits > 8)) {
error("Invalid number of bits (%d) in serial format, should be 8\n", data_bits);
error("Invalid number of bits (%d) in serial format, should be 8", data_bits);
}
uint8_t parity_enable, parity_select;
@ -168,13 +168,13 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
case ParityOdd : parity_enable = 1; parity_select = 1; data_bits++; break;
case ParityEven: parity_enable = 1; parity_select = 0; data_bits++; break;
default:
error("Invalid serial parity setting\n");
error("Invalid serial parity setting");
return;
}
// 1 stop bits = 0, 2 stop bits = 1
if ((stop_bits != 1) && (stop_bits != 2)) {
error("Invalid stop bits specified\n");
error("Invalid stop bits specified");
}
stop_bits -= 1;

View File

@ -50,7 +50,7 @@ static const PinMap PinMap_ADC[] = {
void analogin_init(analogin_t *obj, PinName pin) {
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
if (obj->adc == (ADCName)NC) {
error("ADC pin mapping failed\n");
error("ADC pin mapping failed");
}
uint32_t instance = obj->adc >> ADC_INSTANCE_SHIFT;

View File

@ -29,7 +29,7 @@ const PinMap PinMap_DAC[] = {
void analogout_init(dac_t *obj, PinName pin) {
obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC);
if (obj->dac == (DACName)NC) {
error("DAC pin mapping failed\n");
error("DAC pin mapping failed");
}
SIM->SCGC2 |= SIM_SCGC2_DAC0_MASK;

View File

@ -49,7 +49,7 @@
#define DEVICE_DEBUG_AWARENESS 0
#define DEVICE_STDIO_MESSAGES 0
#define DEVICE_STDIO_MESSAGES 1
#define DEVICE_ERROR_RED 1

View File

@ -109,7 +109,7 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32
break;
default:
error("gpio_irq only supported on port A-E.\n");
error("gpio_irq only supported on port A-E.");
break;
}
NVIC_SetVector(irq_n, vector);

View File

@ -51,7 +51,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
uint32_t i2c_scl = pinmap_peripheral(scl, PinMap_I2C_SCL);
obj->instance = pinmap_merge(i2c_sda, i2c_scl);
if ((int)obj->instance == NC) {
error("I2C pin mapping failed\n");
error("I2C pin mapping failed");
}
clock_manager_set_gate(kClockModuleI2C, obj->instance, true);

View File

@ -74,7 +74,7 @@ static float pwm_clock_mhz;
void pwmout_init(pwmout_t* obj, PinName pin) {
PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
if (pwm == (PWMName)NC) {
error("PwmOut pin mapping failed\n");
error("PwmOut pin mapping failed");
}
obj->pwm_name = pwm;

View File

@ -86,7 +86,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
uint32_t uart_rx = pinmap_peripheral(rx, PinMap_UART_RX);
obj->index = (UARTName)pinmap_merge(uart_tx, uart_rx);
if ((int)obj->index == NC) {
error("Serial pinout mapping failed\n");
error("Serial pinout mapping failed");
}
uart_config_t uart_config;

View File

@ -94,7 +94,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
obj->instance = pinmap_merge(spi_data, spi_cntl);
if ((int)obj->instance == NC) {
error("SPI pinout mapping failed\n");
error("SPI pinout mapping failed");
}
// enable power and clocking
@ -133,7 +133,7 @@ void spi_format(spi_t *obj, int bits, int mode, int slave) {
config.direction = kDspiMsbFirst;
dspi_status_t result = dspi_hal_configure_data_format(obj->instance, kDspiCtar0, &config);
if (result != kStatus_DSPI_Success) {
error("Failed to configure SPI data format\n");
error("Failed to configure SPI data format");
}
if (slave) {

View File

@ -89,7 +89,7 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32
// Interrupts available only on GPIO0 and GPIO2
if (obj->port != LPC_GPIO0_BASE && obj->port != LPC_GPIO2_BASE) {
error("pins on this port cannot generate interrupts\n");
error("pins on this port cannot generate interrupts");
}
// put us in the interrupt table

View File

@ -80,7 +80,7 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32
// Interrupts available only on GPIO0 and GPIO2
if (obj->port != LPC_GPIO0_BASE && obj->port != LPC_GPIO2_BASE) {
error("pins on this port cannot generate interrupts\n");
error("pins on this port cannot generate interrupts");
}
// put us in the interrupt table

View File

@ -102,7 +102,7 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32
// Interrupts available only on GPIO0 and GPIO2
if (obj->port != LPC_GPIO0_BASE && obj->port != LPC_GPIO2_BASE) {
error("pins on this port cannot generate interrupts\n");
error("pins on this port cannot generate interrupts");
}
// put us in the interrupt table

View File

@ -104,7 +104,7 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32
irq_index = 2;
break;
default:
error("This pin is not supported\n");
error("This pin is not supported");
return -1;
}

View File

@ -110,7 +110,7 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32
irq_index = 3;
break;
default:
error("This pin is not supported with InterruptIn.\n");
error("This pin is not supported with InterruptIn.");
return -1;
}

View File

@ -138,7 +138,7 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32
irq_index = 6;
break;
default:
error("InterruptIn error: pin not supported.\n");
error("InterruptIn error: pin not supported.");
return -1;
}

View File

@ -104,7 +104,7 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32
irq_index = 2;
break;
default:
error("This pin is not supported\n");
error("This pin is not supported");
return -1;
}

View File

@ -110,7 +110,7 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32
irq_index = 3;
break;
default:
error("This pin is not supported with InterruptIn.\n");
error("This pin is not supported with InterruptIn.");
return -1;
}

View File

@ -154,7 +154,7 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32
irq_index = 6;
break;
default:
error("This pin is not supported with InterruptIn.\n");
error("This pin is not supported with InterruptIn.");
return -1;
}

View File

@ -138,7 +138,7 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32
irq_index = 6;
break;
default:
error("InterruptIn error: pin not supported.\n");
error("InterruptIn error: pin not supported.");
return -1;
}

View File

@ -110,7 +110,7 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32
irq_index = 3;
break;
default:
error("This pin is not supported with InterruptIn.\n");
error("This pin is not supported with InterruptIn.");
return -1;
}

View File

@ -154,7 +154,7 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32
irq_index = 6;
break;
default:
error("This pin is not supported with InterruptIn.\n");
error("This pin is not supported with InterruptIn.");
return -1;
}