diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_K20D5M/analogin_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_K20D5M/analogin_api.c index def4d5129b..25a92d8c42 100644 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_K20D5M/analogin_api.c +++ b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_K20D5M/analogin_api.c @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "analogin_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" #include "clk_freqs.h" static const PinMap PinMap_ADC[] = { @@ -38,8 +38,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"); + assert(obj->adc != (ADCName)NC); SIM->SCGC6 |= SIM_SCGC6_ADC0_MASK; diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_K20D5M/i2c_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_K20D5M/i2c_api.c index d6d476d6f0..3b966a25bc 100644 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_K20D5M/i2c_api.c +++ b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_K20D5M/i2c_api.c @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "i2c_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" #include "clk_freqs.h" static const PinMap PinMap_I2C_SDA[] = { @@ -54,8 +54,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) { I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA); 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"); + assert((int)obj->i2c != NC); SIM->SCGC4 |= SIM_SCGC4_I2C0_MASK; SIM->SCGC5 |= SIM_SCGC5_PORTB_MASK; diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_K20D5M/pwmout_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_K20D5M/pwmout_api.c index 35b8901149..7de84ad758 100644 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_K20D5M/pwmout_api.c +++ b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_K20D5M/pwmout_api.c @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "pwmout_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" static const PinMap PinMap_PWM[] = { // LEDs @@ -53,8 +53,7 @@ static float pwm_clock = 0; 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"); + assert(pwm != (PWMName)NC); uint32_t clkdiv = 0; float clkval = SystemCoreClock / 1000000.0f; diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_K20D5M/serial_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_K20D5M/serial_api.c index 7d61305f2f..9e8e782421 100644 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_K20D5M/serial_api.c +++ b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_K20D5M/serial_api.c @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "serial_api.h" // math.h required for floating point operations for baud rate calculation @@ -22,7 +23,6 @@ #include "cmsis.h" #include "pinmap.h" -#include "error.h" static const PinMap PinMap_UART_TX[] = { {PTB17, UART_0, 3}, @@ -47,8 +47,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) { UARTName uart_tx = (UARTName)pinmap_peripheral(tx, PinMap_UART_TX); 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"); + assert((int)uart != NC); obj->uart = (UART_Type *)uart; // enable clk diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_K20D5M/spi_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_K20D5M/spi_api.c index 3075a33a49..8f4f2e62e9 100644 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_K20D5M/spi_api.c +++ b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_K20D5M/spi_api.c @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "spi_api.h" #include #include "cmsis.h" #include "pinmap.h" -#include "error.h" #include "clk_freqs.h" static const PinMap PinMap_SPI_SCLK[] = { @@ -56,9 +56,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel); obj->spi = (SPI_Type*)pinmap_merge(spi_data, spi_cntl); - if ((int)obj->spi == NC) { - error("SPI pinout mapping failed"); - } + assert((int)obj->spi != NC); SIM->SCGC5 |= SIM_SCGC5_PORTC_MASK | SIM_SCGC5_PORTD_MASK; SIM->SCGC6 |= SIM_SCGC6_SPI0_MASK; diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/analogin_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/analogin_api.c index e4146cca27..fb472adb92 100644 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/analogin_api.c +++ b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/analogin_api.c @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "analogin_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" #include "clk_freqs.h" #include "PeripheralPins.h" @@ -27,9 +27,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"); - } + assert(obj->adc != (ADCName)NC); SIM->SCGC6 |= SIM_SCGC6_ADC0_MASK; diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/analogout_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/analogout_api.c index 31252fe8ac..c15dcd6a42 100644 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/analogout_api.c +++ b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/analogout_api.c @@ -13,21 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "analogout_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" #include "PeripheralPins.h" #define RANGE_12BIT 0xFFF - 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"); - } + assert(obj->dac != (DACName)NC); SIM->SCGC6 |= SIM_SCGC6_DAC0_MASK; diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/i2c_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/i2c_api.c index b0d80da6f9..0c1504c123 100644 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/i2c_api.c +++ b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/i2c_api.c @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "i2c_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" #include "clk_freqs.h" #include "PeripheralPins.h" @@ -43,9 +43,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) { I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA); 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"); - } + assert(obj->i2c != (PinName)NC); // enable power switch ((int)obj->i2c) { diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/pwmout_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/pwmout_api.c index 2101758480..ff80c95ccc 100644 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/pwmout_api.c +++ b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/pwmout_api.c @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "pwmout_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" #include "clk_freqs.h" #include "PeripheralPins.h" @@ -26,9 +26,8 @@ static float pwm_clock; 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"); - + assert(pwm != (PWMName)NC); + uint32_t clkdiv = 0; float clkval; if (mcgpllfll_frequency()) { @@ -37,11 +36,11 @@ void pwmout_init(pwmout_t* obj, PinName pin) { } else { SIM->SOPT2 |= SIM_SOPT2_TPMSRC(2); // Clock source: ExtOsc clkval = extosc_frequency() / 1000000.0f; - } + } while (clkval > 1) { clkdiv++; - clkval /= 2.0; + clkval /= 2.0; if (clkdiv == 7) break; } diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/serial_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/serial_api.c index feaeb9f031..1114260890 100644 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/serial_api.c +++ b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/serial_api.c @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "serial_api.h" // math.h required for floating point operations for baud rate calculation @@ -22,7 +23,6 @@ #include "cmsis.h" #include "pinmap.h" -#include "error.h" #include "clk_freqs.h" #include "PeripheralPins.h" @@ -61,9 +61,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) { UARTName uart_tx = (UARTName)pinmap_peripheral(tx, PinMap_UART_TX); 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"); - } + assert((int)uart != NC); obj->uart = (UARTLP_Type *)uart; // enable clk @@ -290,7 +288,7 @@ void serial_pinout_tx(PinName tx) { } void serial_break_set(serial_t *obj) { - obj->uart->C2 |= UARTLP_C2_SBK_MASK; + obj->uart->C2 |= UARTLP_C2_SBK_MASK; } void serial_break_clear(serial_t *obj) { diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/analogin_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/analogin_api.c index 215deb6182..0404e0e2cf 100644 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/analogin_api.c +++ b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/analogin_api.c @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "analogin_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" #include "PeripheralNames.h" #include "fsl_adc_hal.h" #include "fsl_clock_manager.h" @@ -49,9 +49,8 @@ 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"); - } + assert(obj->adc != (ADCName)NC); + uint32_t instance = obj->adc >> ADC_INSTANCE_SHIFT; clock_manager_set_gate(kClockModuleADC, instance, true); diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/i2c_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/i2c_api.c index 9203de63c8..3dbdbf8228 100644 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/i2c_api.c +++ b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/i2c_api.c @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "i2c_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" #include "fsl_clock_manager.h" #include "fsl_i2c_hal.h" #include "fsl_port_hal.h" @@ -50,9 +50,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) { uint32_t i2c_sda = pinmap_peripheral(sda, PinMap_I2C_SDA); 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"); - } + assert((int)obj->instance != NC); clock_manager_set_gate(kClockModuleI2C, obj->instance, true); clock_manager_set_gate(kClockModulePORT, sda >> GPIO_PORT_SHIFT, true); diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/pwmout_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/pwmout_api.c index 6d7244cfe2..21777c91f1 100644 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/pwmout_api.c +++ b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/pwmout_api.c @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "pwmout_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" #include "fsl_ftm_hal.h" #include "fsl_mcg_hal.h" #include "fsl_clock_manager.h" @@ -73,9 +73,8 @@ 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"); - } + assert(pwm != (PWMName)NC); + obj->pwm_name = pwm; uint32_t pwm_base_clock; diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/serial_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/serial_api.c index 2be80cc4af..7a4cacda79 100644 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/serial_api.c +++ b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/serial_api.c @@ -17,12 +17,12 @@ // math.h required for floating point operations for baud rate calculation #include +#include #include #include "cmsis.h" #include "pinmap.h" -#include "error.h" #include "fsl_uart_hal.h" #include "fsl_clock_manager.h" #include "fsl_uart_features.h" @@ -85,9 +85,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) { uint32_t uart_tx = pinmap_peripheral(tx, PinMap_UART_TX); 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"); - } + assert((int)obj->index != NC); uart_config_t uart_config; uart_config.baudRate = 9600; diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/spi_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/spi_api.c index 78a94f47e1..8998af6a73 100644 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/spi_api.c +++ b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/spi_api.c @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "spi_api.h" - #include +#include +#include "spi_api.h" #include "cmsis.h" #include "pinmap.h" #include "error.h" @@ -93,9 +93,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel uint32_t spi_cntl = pinmap_merge(spi_sclk, spi_ssel); obj->instance = pinmap_merge(spi_data, spi_cntl); - if ((int)obj->instance == NC) { - error("SPI pinout mapping failed"); - } + assert((int)obj->instance != NC); // enable power and clocking clock_manager_set_gate(kClockModuleSPI, obj->instance, true); diff --git a/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_NRF51822/analogin_api.c b/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_NRF51822/analogin_api.c index 74c848d4e2..77aefb7ad8 100644 --- a/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_NRF51822/analogin_api.c +++ b/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_NRF51822/analogin_api.c @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "analogin_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" #define ANALOGIN_MEDIAN_FILTER 1 #define ADC_10BIT_RANGE 0x3FF @@ -37,9 +37,7 @@ void analogin_init(analogin_t *obj, PinName pin) { const PinMap *map = PinMap_ADC; obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC); //(NRF_ADC_Type *) - if (obj->adc == (ADCName)NC) { - error("ADC pin mapping failed"); - } + assert(obj->adc != (ADCName)NC); while (map->pin != NC) { if (map->pin == pin){ @@ -49,12 +47,12 @@ void analogin_init(analogin_t *obj, PinName pin) { map++; } - NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Enabled; + NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Enabled; NRF_ADC->CONFIG = (ADC_CONFIG_RES_10bit << ADC_CONFIG_RES_Pos) | (ADC_CONFIG_INPSEL_AnalogInputOneThirdPrescaling<< ADC_CONFIG_INPSEL_Pos) | (ADC_CONFIG_REFSEL_SupplyOneThirdPrescaling << ADC_CONFIG_REFSEL_Pos) | (analogInputPin << ADC_CONFIG_PSEL_Pos) | - (ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos); + (ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos); } uint16_t analogin_read_u16(analogin_t *obj) { diff --git a/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_NRF51822/i2c_api.c b/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_NRF51822/i2c_api.c index c8a2a05ba4..9de494a563 100644 --- a/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_NRF51822/i2c_api.c +++ b/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_NRF51822/i2c_api.c @@ -13,12 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "i2c_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" - - static const PinMap PinMap_I2C_SDA[] = { {p22, I2C_0, 1}, @@ -52,7 +50,7 @@ void twi_master_init(i2c_t *obj, PinName sda, PinName scl, int frequency) { (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)); obj->i2c->PSELSCL = scl; - obj->i2c->PSELSDA = sda; + obj->i2c->PSELSDA = sda; // set default frequency at 100k i2c_frequency(obj, frequency); i2c_interface_enable(obj); @@ -64,30 +62,28 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) { I2CName i2c = (I2CName)pinmap_merge(i2c_sda,i2c_scl); obj->i2c = (NRF_TWI_Type *)i2c; - if ((int)obj->i2c == NC) { - error("I2C pin mapping failed"); - } + assert((int)obj->i2c != NC); obj->scl=scl; obj->sda=sda; obj->i2c->EVENTS_ERROR = 0; - obj->i2c->ENABLE = TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos; - obj->i2c->POWER = 0; + obj->i2c->ENABLE = TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos; + obj->i2c->POWER = 0; for(int i=0;i<100;i++){ } - obj->i2c->POWER = 1; + obj->i2c->POWER = 1; twi_master_init(obj,sda,scl,100000); } void i2c_reset(i2c_t *obj) { obj->i2c->EVENTS_ERROR = 0; - obj->i2c->ENABLE = TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos; - obj->i2c->POWER = 0; + obj->i2c->ENABLE = TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos; + obj->i2c->POWER = 0; for(int i=0;i<100;i++){ } - obj->i2c->POWER = 1; + obj->i2c->POWER = 1; twi_master_init(obj,obj->sda,obj->scl,obj->freq); } @@ -107,7 +103,7 @@ int i2c_stop(i2c_t *obj) { timeOut--; if(timeOut<0) return 1; - } + } addrSet = 0; i2c_reset(obj); return 0; @@ -122,7 +118,7 @@ int i2c_do_write(i2c_t *obj, int value) { if(timeOut<0) return 1; } - obj->i2c->EVENTS_TXDSENT = 0; + obj->i2c->EVENTS_TXDSENT = 0; return 0; } @@ -166,17 +162,17 @@ void i2c_frequency(i2c_t *obj, int hz) { } int checkError(i2c_t *obj){ - if (obj->i2c->EVENTS_ERROR == 1){ - if (obj->i2c->ERRORSRC & TWI_ERRORSRC_ANACK_Msk){ + if (obj->i2c->EVENTS_ERROR == 1){ + if (obj->i2c->ERRORSRC & TWI_ERRORSRC_ANACK_Msk){ obj->i2c->EVENTS_ERROR = 0; - obj->i2c->TASKS_STOP = 1; + obj->i2c->TASKS_STOP = 1; return I2C_ERROR_BUS_BUSY; } obj->i2c->EVENTS_ERROR = 0; obj->i2c->TASKS_STOP = 1; - return I2C_ERROR_NO_SLAVE; - } + return I2C_ERROR_NO_SLAVE; + } return 0; } @@ -190,7 +186,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) { // Read in all except last byte for (count = 0; count < (length - 1); count++) { status = i2c_do_read(obj,&data[count], 0); - if (status) { + if (status) { errorResult = checkError(obj); i2c_reset(obj); if(errorResult<0){ @@ -211,7 +207,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) { while(!obj->i2c->EVENTS_STOPPED){ } obj->i2c->EVENTS_STOPPED = 0; - } + } return length; } @@ -219,7 +215,7 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) { int status, errorResult; obj->i2c->ADDRESS = (address>>1); obj->i2c->SHORTS = 0; - obj->i2c->TASKS_STARTTX = 1; + obj->i2c->TASKS_STARTTX = 1; for (int i=0; ii2c->TASKS_STARTRX = 1; } else{ - obj->i2c->TASKS_STARTTX = 1; + obj->i2c->TASKS_STARTTX = 1; } } else{ diff --git a/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_NRF51822/pwmout_api.c b/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_NRF51822/pwmout_api.c index e0a672fd8b..3a692d2585 100644 --- a/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_NRF51822/pwmout_api.c +++ b/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_NRF51822/pwmout_api.c @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "pwmout_api.h" #include "cmsis.h" #include "pinmap.h" @@ -43,8 +44,8 @@ static const PinMap PinMap_PWM[] = { {p19, PWM_1, 1}, {p20, PWM_1, 1}, {p21, PWM_1, 1}, - {p22, PWM_1, 1}, - {p23, PWM_1, 1}, + {p22, PWM_1, 1}, + {p23, PWM_1, 1}, {p24, PWM_1, 1}, {p25, PWM_1, 1}, {p28, PWM_1, 1}, @@ -54,7 +55,7 @@ static const PinMap PinMap_PWM[] = { }; static NRF_TIMER_Type *Timers[1] = { - NRF_TIMER2 + NRF_TIMER2 }; uint8_t PWM_taken[NO_PWMS] = {0,0}; @@ -67,34 +68,34 @@ uint16_t ACTUAL_PULSE[NO_PWMS] = {0,0}; */ #ifdef __cplusplus extern "C" { -#endif +#endif void TIMER2_IRQHandler(void) { static uint16_t CCVal1 = 2501; static uint16_t CCVal2 = 2501; - if ((NRF_TIMER2->EVENTS_COMPARE[1] != 0) && + if ((NRF_TIMER2->EVENTS_COMPARE[1] != 0) && ((NRF_TIMER2->INTENSET & TIMER_INTENSET_COMPARE1_Msk) != 0)){ - NRF_TIMER2->CC[0] = CCVal1; + NRF_TIMER2->CC[0] = CCVal1; NRF_TIMER2->EVENTS_COMPARE[1] = 0; NRF_TIMER2->CC[1] = (NRF_TIMER2->CC[1] + PERIOD[0]); - CCVal1 = NRF_TIMER2->CC[1] + PULSE_WIDTH[0]; + CCVal1 = NRF_TIMER2->CC[1] + PULSE_WIDTH[0]; } - if ((NRF_TIMER2->EVENTS_COMPARE[3] != 0) && + if ((NRF_TIMER2->EVENTS_COMPARE[3] != 0) && ((NRF_TIMER2->INTENSET & TIMER_INTENSET_COMPARE3_Msk) != 0)){ NRF_TIMER2->CC[2] = CCVal2; NRF_TIMER2->EVENTS_COMPARE[3] = 0; NRF_TIMER2->CC[3] = (NRF_TIMER2->CC[3] + PERIOD[1]); - CCVal2 = NRF_TIMER2->CC[3] + PULSE_WIDTH[1]; - } + CCVal2 = NRF_TIMER2->CC[3] + PULSE_WIDTH[1]; + } } #ifdef __cplusplus } -#endif +#endif /** @brief Function for initializing the Timer peripherals. */ void timer_init(uint8_t pwmChoice) @@ -102,10 +103,10 @@ void timer_init(uint8_t pwmChoice) NRF_TIMER_Type *timer = Timers[pwmChoice/2]; if(!(pwmChoice%2)){ timer->POWER = 0; - timer->POWER = 1; - timer->MODE = TIMER_MODE_MODE_Timer; + timer->POWER = 1; + timer->MODE = TIMER_MODE_MODE_Timer; timer->BITMODE = TIMER_BITMODE_BITMODE_16Bit << TIMER_BITMODE_BITMODE_Pos; - timer->PRESCALER = 7;//8us ticks + timer->PRESCALER = 7;//8us ticks } if(pwmChoice%2){ @@ -148,11 +149,11 @@ void gpiote_init(PinName pin,uint8_t channel_number) /* Three NOPs are required to make sure configuration is written before setting tasks or getting events */ __NOP(); __NOP(); - __NOP(); + __NOP(); /* Launch the task to take the GPIOTE channel output to the desired level */ NRF_GPIOTE->TASKS_OUT[channel_number] = 1; - /* Finally configure the channel as the caller expects. If OUTINIT works, the channel is configured properly. + /* Finally configure the channel as the caller expects. If OUTINIT works, the channel is configured properly. If it does not, the channel output inheritance sets the proper level. */ NRF_GPIOTE->CONFIG[channel_number] = (GPIOTE_CONFIG_MODE_Task << GPIOTE_CONFIG_MODE_Pos) | ((uint32_t)pin << GPIOTE_CONFIG_PSEL_Pos) | @@ -162,7 +163,7 @@ void gpiote_init(PinName pin,uint8_t channel_number) /* Three NOPs are required to make sure configuration is written before setting tasks or getting events */ __NOP(); __NOP(); - __NOP(); + __NOP(); } /** @brief Function for initializing the Programmable Peripheral Interconnect peripheral. */ @@ -175,8 +176,8 @@ static void ppi_init(uint8_t pwm) // Configure PPI channel 0 to toggle ADVERTISING_LED_PIN_NO on every TIMER1 COMPARE[0] match NRF_PPI->CH[channel_number].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[pwm]; NRF_PPI->CH[channel_number+1].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[pwm]; - NRF_PPI->CH[channel_number].EEP = (uint32_t)&timer->EVENTS_COMPARE[channel_number-(4*(channel_number/4))]; - NRF_PPI->CH[channel_number+1].EEP = (uint32_t)&timer->EVENTS_COMPARE[channel_number+1-(4*(channel_number/4))]; + NRF_PPI->CH[channel_number].EEP = (uint32_t)&timer->EVENTS_COMPARE[channel_number-(4*(channel_number/4))]; + NRF_PPI->CH[channel_number+1].EEP = (uint32_t)&timer->EVENTS_COMPARE[channel_number+1-(4*(channel_number/4))]; // Enable PPI channels. NRF_PPI->CHEN |= (1 << channel_number) @@ -213,10 +214,9 @@ void pwmout_init(pwmout_t* obj, PinName pin) { // determine the channel uint8_t pwmOutSuccess = 0; PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM); - - if (pwm == (PWMName)NC){ - error("PwmOut pin mapping failed"); - } + + assert(pwm != (PWMName)NC); + if(PWM_taken[(uint8_t)pwm]){ for(uint8_t i = 1; !pwmOutSuccess && (i 1.0f) { value = 1.0; - } + } oldPulseWidth = ACTUAL_PULSE[obj->pwm]; ACTUAL_PULSE[obj->pwm] = PULSE_WIDTH[obj->pwm] = value* PERIOD[obj->pwm]; if(PULSE_WIDTH[obj->pwm] == 0){ PULSE_WIDTH[obj->pwm] = 1; - setModulation(obj,0,0); + setModulation(obj,0,0); } else if(PULSE_WIDTH[obj->pwm] == PERIOD[obj->pwm]){ PULSE_WIDTH[obj->pwm] = PERIOD[obj->pwm]-1; @@ -280,7 +280,7 @@ void pwmout_write(pwmout_t* obj, float value) { } else if( (oldPulseWidth == 0) || (oldPulseWidth == PERIOD[obj->pwm]) ){ setModulation(obj,1,oldPulseWidth == PERIOD[obj->pwm]); - } + } } float pwmout_read(pwmout_t* obj) { @@ -308,7 +308,7 @@ void pwmout_period_us(pwmout_t* obj, int us) { } else{ PERIOD[obj->pwm] =periodInTicks; - } + } } void pwmout_pulsewidth(pwmout_t* obj, float seconds) { @@ -327,7 +327,7 @@ void pwmout_pulsewidth_us(pwmout_t* obj, int us) { if(PULSE_WIDTH[obj->pwm] == 0){ PULSE_WIDTH[obj->pwm] = 1; - setModulation(obj,0,0); + setModulation(obj,0,0); } else if(PULSE_WIDTH[obj->pwm] == PERIOD[obj->pwm]){ PULSE_WIDTH[obj->pwm] = PERIOD[obj->pwm]-1; @@ -335,5 +335,5 @@ void pwmout_pulsewidth_us(pwmout_t* obj, int us) { } else if( (oldPulseWidth == 0) || (oldPulseWidth == PERIOD[obj->pwm]) ){ setModulation(obj,1,oldPulseWidth == PERIOD[obj->pwm]); - } + } } diff --git a/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_NRF51822/serial_api.c b/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_NRF51822/serial_api.c index c4c6f26ef3..cde0c5c59a 100644 --- a/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_NRF51822/serial_api.c +++ b/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_NRF51822/serial_api.c @@ -16,11 +16,12 @@ // math.h required for floating point operations for baud rate calculation //#include #include +#include #include "serial_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" + /****************************************************************************** * INITIALIZATION ******************************************************************************/ @@ -65,14 +66,12 @@ 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"); - } + assert((int)uart != NC); obj->uart = (NRF_UART_Type *)uart; - //pin configurations -- - //outputs + //pin configurations -- + //outputs NRF_GPIO->DIR |= (1<DIR |= (1<uart->BAUDRATE = UART_BAUDRATE_BAUDRATE_Baud1200; return; - } + } - for(int i=1;i<16;i++){ + for(int i=1;i<16;i++){ if(baudrateuart->BAUDRATE = acceptedSpeeds[i-1][1]; return; @@ -133,7 +132,7 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b // 0: 1 stop bits, 1: 2 stop bits // int parity_enable, parity_select; switch (parity) { - case ParityNone: + case ParityNone: obj->uart->CONFIG = 0; break; default: @@ -149,11 +148,11 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b static inline void uart_irq(uint32_t iir, uint32_t index) { SerialIrq irq_type; switch (iir) { - case 1: - irq_type = TxIrq; + case 1: + irq_type = TxIrq; break; - case 2: - irq_type = RxIrq; + case 2: + irq_type = RxIrq; break; default: return; @@ -165,7 +164,7 @@ static inline void uart_irq(uint32_t iir, uint32_t index) { } #ifdef __cplusplus extern "C" { -#endif +#endif void UART0_IRQHandler() { uint32_t irtype =0; @@ -180,7 +179,7 @@ void UART0_IRQHandler() } #ifdef __cplusplus } -#endif +#endif void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id) { irq_handler = handler; serial_irq_ids[obj->index] = id; diff --git a/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_NRF51822/spi_api.c b/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_NRF51822/spi_api.c index b403aa4aa5..2d3c47b0ce 100644 --- a/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_NRF51822/spi_api.c +++ b/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_NRF51822/spi_api.c @@ -14,6 +14,7 @@ * limitations under the License. */ //#include +#include #include "spi_api.h" #include "cmsis.h" #include "pinmap.h" @@ -22,7 +23,7 @@ static const PinMap PinMap_SPI_SCLK[] = { {SPI_PSELSCK0 , SPI_0, 0x01}, {SPI_PSELSCK1, SPI_1, 0x02}, - {SPIS_PSELSCK, SPIS, 0x03}, + {SPIS_PSELSCK, SPIS, 0x03}, {NC , NC , 0} }; @@ -59,20 +60,18 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel SPIName spi_data = (SPIName)pinmap_merge(spi_mosi, spi_miso); SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel); SPIName spi = (SPIName)pinmap_merge(spi_data, spi_cntl); - //SPIName + //SPIName if(ssel==NC){ obj->spi = (NRF_SPI_Type*)spi; obj->spis = (NRF_SPIS_Type*)NC; } else{ obj->spi = (NRF_SPI_Type*)NC; - obj->spis = (NRF_SPIS_Type*)spi; + obj->spis = (NRF_SPIS_Type*)spi; } - - if ((int)obj->spi == NC && (int)obj->spis == NC) { - error("SPI pinout mapping failed"); - } - // pin out the spi pins + assert((int)obj->spi != NC && (int)obj->spis != NC); + + // pin out the spi pins if (ssel != NC) {//slave obj->spis->POWER=0; obj->spis->POWER=1; @@ -108,7 +107,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel obj->spis->MAXRX=SPIS_MESSAGE_SIZE; obj->spis->MAXTX=SPIS_MESSAGE_SIZE; obj->spis->TXDPTR = (uint32_t)&m_tx_buf[0]; - obj->spis->RXDPTR = (uint32_t)&m_rx_buf[0]; + obj->spis->RXDPTR = (uint32_t)&m_rx_buf[0]; obj->spis->SHORTS = (SPIS_SHORTS_END_ACQUIRE_Enabled<spi->POWER=0; obj->spi->POWER=1; - //NRF_GPIO->DIR |= (1<DIR |= (1<PIN_CNF[mosi] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) @@ -141,10 +140,10 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel obj->spi->PSELMISO = miso; - obj->spi->EVENTS_READY = 0U; + obj->spi->EVENTS_READY = 0U; spi_format(obj, 8, 0, 0); // 8 bits, mode 0, master - spi_frequency(obj, 1000000); + spi_frequency(obj, 1000000); } } @@ -197,10 +196,10 @@ void spi_format(spi_t *obj, int bits, int mode, int slave) { } //default to msb first if(slave){ - obj->spis->CONFIG = (config_mode | (SPI_CONFIG_ORDER_MsbFirst << SPI_CONFIG_ORDER_Pos) ); + obj->spis->CONFIG = (config_mode | (SPI_CONFIG_ORDER_MsbFirst << SPI_CONFIG_ORDER_Pos) ); } else{ - obj->spi->CONFIG = (config_mode | (SPI_CONFIG_ORDER_MsbFirst << SPI_CONFIG_ORDER_Pos) ); + obj->spi->CONFIG = (config_mode | (SPI_CONFIG_ORDER_MsbFirst << SPI_CONFIG_ORDER_Pos) ); } spi_enable(obj,slave); @@ -212,7 +211,7 @@ void spi_frequency(spi_t *obj, int hz) { spi_disable(obj,0); if(hz<250000) { //125Kbps - obj->spi->FREQUENCY = (uint32_t) SPI_FREQUENCY_FREQUENCY_K125; + obj->spi->FREQUENCY = (uint32_t) SPI_FREQUENCY_FREQUENCY_K125; } else if(hz<500000){//250Kbps obj->spi->FREQUENCY = (uint32_t) SPI_FREQUENCY_FREQUENCY_K250; @@ -230,7 +229,7 @@ void spi_frequency(spi_t *obj, int hz) { obj->spi->FREQUENCY = (uint32_t) SPI_FREQUENCY_FREQUENCY_M4; } else{//8Mbps - obj->spi->FREQUENCY = (uint32_t) SPI_FREQUENCY_FREQUENCY_M8; + obj->spi->FREQUENCY = (uint32_t) SPI_FREQUENCY_FREQUENCY_M8; } spi_enable(obj,0); @@ -260,7 +259,7 @@ int spi_master_write(spi_t *obj, int value) { return spi_read(obj); } -//static inline int spis_writeable(spi_t *obj) { +//static inline int spis_writeable(spi_t *obj) { // return (obj->spis->EVENTS_ACQUIRED==1); //} @@ -268,12 +267,12 @@ int spi_slave_receive(spi_t *obj) { return obj->spis->EVENTS_END; }; -int spi_slave_read(spi_t *obj) { +int spi_slave_read(spi_t *obj) { return m_rx_buf[0]; } -void spi_slave_write(spi_t *obj, int value) { - m_tx_buf[0]= value & 0xFF; +void spi_slave_write(spi_t *obj, int value) { + m_tx_buf[0]= value & 0xFF; obj->spis->TASKS_RELEASE=1; obj->spis->EVENTS_ACQUIRED=0; obj->spis->EVENTS_END=0; diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11U6X/analogin_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11U6X/analogin_api.c index 88641ddeb5..2c642a49c7 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11U6X/analogin_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11U6X/analogin_api.c @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +#include #include "analogin_api.h" #include "cmsis.h" #include "pinmap.h" @@ -50,9 +50,8 @@ static const PinMap PinMap_ADC[] = { void analogin_init(analogin_t *obj, PinName pin) { volatile uint32_t tmp; obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC); - if (obj->adc == (uint32_t)NC) { - error("ADC pin mapping failed"); - } + assert(obj->adc != (ADCName)NC); + pinmap_pinout(pin, PinMap_ADC); // ADC Powered diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11U6X/i2c_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11U6X/i2c_api.c index d1e771d334..29b2d137a2 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11U6X/i2c_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11U6X/i2c_api.c @@ -13,11 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +#include #include "i2c_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" #if DEVICE_I2C @@ -96,10 +95,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) { I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA); I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL); obj->i2c = (LPC_I2C0_Type *)pinmap_merge(i2c_sda, i2c_scl); - - if ((int)obj->i2c == NC) { - error("I2C pin mapping failed"); - } + assert((int)obj->i2c != NC); // enable power i2c_power_enable(obj); diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11U6X/serial_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11U6X/serial_api.c index a2ac8fe1c5..4854c3bac7 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11U6X/serial_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11U6X/serial_api.c @@ -14,6 +14,7 @@ * limitations under the License. */ // math.h required for floating point operations for baud rate calculation +#include #include #include #include @@ -21,7 +22,6 @@ #include "serial_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" #if DEVICE_SERIAL #warning "[TODO] support from UART_1 to UART_4" @@ -68,10 +68,8 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) { UARTName uart_tx = (UARTName)pinmap_peripheral(tx, PinMap_UART_TX); 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"); - } - + assert((int)uart != NC); + obj->uart = (LPC_USART0_Type *)uart; LPC_SYSCON->SYSAHBCLKCTRL |= ((1<<12) | (1<<20) | (1<<21) | (1<<22)); @@ -205,16 +203,11 @@ void serial_baud(serial_t *obj, int baudrate) { } void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) { - // 0: 1 stop bits, 1: 2 stop bits - if (stop_bits != 1 && stop_bits != 2) { - error("Invalid stop bits specified"); - } + assert((stop_bits == 1) || (stop_bits == 2)); // 0: 1 stop bits, 1: 2 stop bits + assert((data_bits > 4) || (data_bits < 9)); // 0: 5 data bits ... 3: 8 data bits + assert(parity < (ParityForced0 + 1)); + stop_bits -= 1; - - // 0: 5 data bits ... 3: 8 data bits - if (data_bits < 5 || data_bits > 8) { - error("Invalid number of bits (%d) in serial format, should be 5..8", data_bits); - } data_bits -= 5; int parity_enable, parity_select; @@ -225,8 +218,7 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b case ParityForced1: parity_enable = 1; parity_select = 2; break; case ParityForced0: parity_enable = 1; parity_select = 3; break; default: - error("Invalid serial parity setting"); - return; + break; } obj->uart->LCR = data_bits << 0 diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11U6X/spi_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11U6X/spi_api.c index 4c01e37cfa..6bc0c81eea 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11U6X/spi_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11U6X/spi_api.c @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include #include "spi_api.h" @@ -68,10 +69,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel); obj->spi = (LPC_SSP0_Type*)pinmap_merge(spi_data, spi_cntl); - - if ((int)obj->spi == NC) { - error("SPI pinout mapping failed"); - } + assert((int)obj->spi == NC); // enable power and clocking switch ((int)obj->spi) { @@ -111,10 +109,7 @@ void spi_free(spi_t *obj) {} void spi_format(spi_t *obj, int bits, int mode, int slave) { ssp_disable(obj); - - if (!(bits >= 4 && bits <= 16) || !(mode >= 0 && mode <= 3)) { - error("SPI format error"); - } + assert((bits >= 4 && bits <= 16) || (mode >= 0 && mode <= 3)); int polarity = (mode & 0x2) ? 1 : 0; int phase = (mode & 0x1) ? 1 : 0; diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/analogin_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/analogin_api.c index 9078d2c002..bea83258a4 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/analogin_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/analogin_api.c @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "analogin_api.h" #include "cmsis.h" #include "pinmap.h" @@ -46,9 +47,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"); - } + assert(obj->adc != (ADCName)NC); // Power up ADC LPC_SYSCON->PDRUNCFG &= ~ (1 << 4); diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/i2c_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/i2c_api.c index 374751c331..e1ea6fcd5d 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/i2c_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/i2c_api.c @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "i2c_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" static const PinMap PinMap_I2C_SDA[] = { {P0_5, I2C_0, 1}, @@ -87,10 +87,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) { I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA); I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL); obj->i2c = (LPC_I2C_Type *)pinmap_merge(i2c_sda, i2c_scl); - - if ((int)obj->i2c == NC) { - error("I2C pin mapping failed"); - } + assert((int)obj->i2c != NC); // enable power i2c_power_enable(obj); diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/pwmout_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/pwmout_api.c index 29ebdbe000..932f16d1a8 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/pwmout_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/pwmout_api.c @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "pwmout_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" #define TCR_CNT_EN 0x00000001 #define TCR_RESET 0x00000002 @@ -69,9 +69,8 @@ static LPC_CTxxBx_Type *Timers[4] = { 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"); - + assert(pwm != (PWMName)NC); + obj->pwm = pwm; // Timer registers @@ -143,7 +142,7 @@ void pwmout_period_us(pwmout_t* obj, int us) { // for 16bit timer, set prescaler to avoid overflow if (timer == LPC_CT16B0 || timer == LPC_CT16B1) { - uint16_t high_period_ticks = period_ticks >> 16; + uint16_t high_period_ticks = period_ticks >> 16; timer->PR = high_period_ticks; period_ticks /= (high_period_ticks + 1); } diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/serial_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/serial_api.c index 123dd6af0d..24afea0403 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/serial_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/serial_api.c @@ -21,7 +21,6 @@ #include "serial_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" /****************************************************************************** * INITIALIZATION @@ -55,10 +54,8 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) { UARTName uart_tx = (UARTName)pinmap_peripheral(tx, PinMap_UART_TX); 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"); - } - + assert((int)uart != NC); + obj->uart = (LPC_USART_Type *)uart; LPC_SYSCON->SYSAHBCLKCTRL |= (1<<12); @@ -188,16 +185,11 @@ void serial_baud(serial_t *obj, int baudrate) { } void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) { - // 0: 1 stop bits, 1: 2 stop bits - if (stop_bits != 1 && stop_bits != 2) { - error("Invalid stop bits specified"); - } + assert((stop_bits == 1) || (stop_bits == 2)); // 0: 1 stop bits, 1: 2 stop bits + assert((data_bits > 4) || (data_bits < 9)); // 0: 5 data bits ... 3: 8 data bits + assert(parity < (ParityForced0 + 1)); + stop_bits -= 1; - - // 0: 5 data bits ... 3: 8 data bits - if (data_bits < 5 || data_bits > 8) { - error("Invalid number of bits (%d) in serial format, should be 5..8", data_bits); - } data_bits -= 5; int parity_enable, parity_select; @@ -208,8 +200,7 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b case ParityForced1: parity_enable = 1; parity_select = 2; break; case ParityForced0: parity_enable = 1; parity_select = 3; break; default: - error("Invalid serial parity setting"); - return; + break; } obj->uart->LCR = data_bits << 0 diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/spi_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/spi_api.c index 1018d9c543..d08902c751 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/spi_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/spi_api.c @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include #include "spi_api.h" #include "cmsis.h" @@ -62,10 +63,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel); obj->spi = (LPC_SSPx_Type*)pinmap_merge(spi_data, spi_cntl); - - if ((int)obj->spi == NC) { - error("SPI pinout mapping failed"); - } + assert((int)obj->spi != NC); // enable power and clocking switch ((int)obj->spi) { @@ -104,12 +102,10 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel void spi_free(spi_t *obj) {} void spi_format(spi_t *obj, int bits, int mode, int slave) { + assert((bits >= 4 && bits <= 16) || (mode >= 0 && mode <= 3)); + ssp_disable(obj); - if (!(bits >= 4 && bits <= 16) || !(mode >= 0 && mode <= 3)) { - error("SPI format error"); - } - int polarity = (mode & 0x2) ? 1 : 0; int phase = (mode & 0x1) ? 1 : 0; @@ -157,7 +153,8 @@ void spi_frequency(spi_t *obj, int hz) { // divider obj->spi->CR0 &= ~(0xFFFF << 8); - obj->spi->CR0 |= (divider - 1) << 8; + obj->spi->CR0 |= (divider - 1) << 8 + ; ssp_enable(obj); return; } diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/analogin_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/analogin_api.c index 1d8610a420..2f1ccd0d3c 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/analogin_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/analogin_api.c @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "analogin_api.h" #include "cmsis.h" #include "pinmap.h" @@ -43,10 +44,7 @@ static inline int div_round_up(int x, int y) { void analogin_init(analogin_t *obj, PinName pin) { obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC); - if (obj->adc == (uint32_t)NC) { - error("ADC pin mapping failed"); - return; - } + assert(obj->adc != (uint32_t)NC); // Power up ADC LPC_SYSCON->PDRUNCFG &= ~ (1 << 4); diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/i2c_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/i2c_api.c index 9a58c8e93a..da0e9ed7d8 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/i2c_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/i2c_api.c @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "i2c_api.h" #include "cmsis.h" #include "pinmap.h" @@ -87,10 +88,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) { I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA); I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL); obj->i2c = (LPC_I2C_TypeDef *)pinmap_merge(i2c_sda, i2c_scl); - - if ((int)obj->i2c == NC) { - error("I2C pin mapping failed"); - } + assert((int)obj->i2c != NC); // enable power i2c_power_enable(obj); diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/pwmout_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/pwmout_api.c index 6fff9b67c1..ad84b2103b 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/pwmout_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/pwmout_api.c @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "pwmout_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" #define TCR_CNT_EN 0x00000001 #define TCR_RESET 0x00000002 @@ -64,9 +64,8 @@ static LPC_TMR_TypeDef *Timers[3] = { void pwmout_init(pwmout_t* obj, PinName pin) { // determine the channel PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM); - if (pwm == (uint32_t)NC) - error("PwmOut pin mapping failed"); - + assert(pwm != (uint32_t)NC); + obj->pwm = pwm; // Timer registers diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/serial_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/serial_api.c index 55bfc1a5a8..09c2c86f92 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/serial_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/serial_api.c @@ -14,6 +14,7 @@ * limitations under the License. */ // math.h required for floating point operations for baud rate calculation +#include #include #include #include @@ -21,7 +22,6 @@ #include "serial_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" /****************************************************************************** * INITIALIZATION @@ -57,9 +57,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) { UARTName uart_tx = (UARTName)pinmap_peripheral(tx, PinMap_UART_TX); 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"); - } + assert((int)uart != NC); obj->uart = (LPC_UART_TypeDef *)uart; LPC_SYSCON->SYSAHBCLKCTRL |= (1<<12); @@ -183,16 +181,11 @@ void serial_baud(serial_t *obj, int baudrate) { } void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) { - // 0: 1 stop bits, 1: 2 stop bits - if (stop_bits != 1 && stop_bits != 2) { - error("Invalid stop bits specified"); - } + assert((stop_bits == 1) || (stop_bits == 2)); // 0: 1 stop bits, 1: 2 stop bits + assert((data_bits > 4) || (data_bits < 9)); // 0: 5 data bits ... 3: 8 data bits + assert(parity < (ParityForced0 + 1)); + stop_bits -= 1; - - // 0: 5 data bits ... 3: 8 data bits - if (data_bits < 5 || data_bits > 8) { - error("Invalid number of bits (%d) in serial format, should be 5..8", data_bits); - } data_bits -= 5; int parity_enable, parity_select; @@ -203,8 +196,7 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b case ParityForced1: parity_enable = 1; parity_select = 2; break; case ParityForced0: parity_enable = 1; parity_select = 3; break; default: - error("Invalid serial parity setting"); - return; + break; } obj->uart->LCR = data_bits << 0 diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/spi_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/spi_api.c index f7380b4ac0..efe45b341d 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/spi_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/spi_api.c @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include #include "spi_api.h" #include "cmsis.h" @@ -58,10 +59,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel); obj->spi = (LPC_SSP_TypeDef*)pinmap_merge(spi_data, spi_cntl); - - if ((int)obj->spi == NC) { - error("SPI pinout mapping failed"); - } + assert((int)obj->spi != NC); // enable power and clocking switch ((int)obj->spi) { @@ -100,12 +98,9 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel void spi_free(spi_t *obj) {} void spi_format(spi_t *obj, int bits, int mode, int slave) { + assert((bits >= 4 && bits <= 16) || (mode >= 0 && mode <= 3)); ssp_disable(obj); - if (!(bits >= 4 && bits <= 16) || !(mode >= 0 && mode <= 3)) { - error("SPI format error"); - } - int polarity = (mode & 0x2) ? 1 : 0; int phase = (mode & 0x1) ? 1 : 0; diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC13XX/analogin_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC13XX/analogin_api.c index 43a7a237a8..bea83258a4 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC13XX/analogin_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC13XX/analogin_api.c @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "analogin_api.h" #include "cmsis.h" #include "pinmap.h" @@ -46,9 +47,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 == (uint32_t)NC) { - error("ADC pin mapping failed"); - } + assert(obj->adc != (ADCName)NC); // Power up ADC LPC_SYSCON->PDRUNCFG &= ~ (1 << 4); diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC13XX/i2c_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC13XX/i2c_api.c index 374751c331..7c4c2b24c6 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC13XX/i2c_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC13XX/i2c_api.c @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "i2c_api.h" #include "cmsis.h" #include "pinmap.h" @@ -87,10 +88,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) { I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA); I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL); obj->i2c = (LPC_I2C_Type *)pinmap_merge(i2c_sda, i2c_scl); - - if ((int)obj->i2c == NC) { - error("I2C pin mapping failed"); - } + assert((int)obj->i2c != NC); // enable power i2c_power_enable(obj); diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC13XX/pwmout_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC13XX/pwmout_api.c index 6019056f21..a77c39724d 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC13XX/pwmout_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC13XX/pwmout_api.c @@ -13,12 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - - +#include #include "pwmout_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" #define TCR_CNT_EN 0x00000001 #define TCR_RESET 0x00000002 @@ -73,9 +71,8 @@ static unsigned int pwm_clock_mhz; void pwmout_init(pwmout_t* obj, PinName pin) { // determine the channel PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM); - if (pwm == (uint32_t)NC) - error("PwmOut pin mapping failed"); - + assert(pwm != (uint32_t)NC); + obj->pwm = pwm; // Timer registers diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC13XX/serial_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC13XX/serial_api.c index 3b405a2c68..32a68f7607 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC13XX/serial_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC13XX/serial_api.c @@ -14,6 +14,7 @@ * limitations under the License. */ // math.h required for floating point operations for baud rate calculation +#include #include #include #include @@ -21,7 +22,6 @@ #include "serial_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" /****************************************************************************** * INITIALIZATION @@ -55,9 +55,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) { UARTName uart_tx = (UARTName)pinmap_peripheral(tx, PinMap_UART_TX); 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"); - } + assert((int)uart != NC); obj->uart = (LPC_USART_Type *)uart; LPC_SYSCON->SYSAHBCLKCTRL |= (1<<12); @@ -186,16 +184,11 @@ void serial_baud(serial_t *obj, int baudrate) { } void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) { - // 0: 1 stop bits, 1: 2 stop bits - if (stop_bits != 1 && stop_bits != 2) { - error("Invalid stop bits specified"); - } + assert((stop_bits == 1) || (stop_bits == 2)); // 0: 1 stop bits, 1: 2 stop bits + assert((data_bits > 4) || (data_bits < 9)); // 0: 5 data bits ... 3: 8 data bits + assert(parity < (ParityForced0 + 1)); + stop_bits -= 1; - - // 0: 5 data bits ... 3: 8 data bits - if (data_bits < 5 || data_bits > 8) { - error("Invalid number of bits (%d) in serial format, should be 5..8", data_bits); - } data_bits -= 5; int parity_enable, parity_select; @@ -206,8 +199,7 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b case ParityForced1: parity_enable = 1; parity_select = 2; break; case ParityForced0: parity_enable = 1; parity_select = 3; break; default: - error("Invalid serial parity setting"); - return; + break; } obj->uart->LCR = data_bits << 0 diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC13XX/spi_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC13XX/spi_api.c index 1018d9c543..0382a13f3e 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC13XX/spi_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC13XX/spi_api.c @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include #include "spi_api.h" #include "cmsis.h" @@ -62,10 +63,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel); obj->spi = (LPC_SSPx_Type*)pinmap_merge(spi_data, spi_cntl); - - if ((int)obj->spi == NC) { - error("SPI pinout mapping failed"); - } + assert((int)obj->spi != NC); // enable power and clocking switch ((int)obj->spi) { @@ -105,10 +103,7 @@ void spi_free(spi_t *obj) {} void spi_format(spi_t *obj, int bits, int mode, int slave) { ssp_disable(obj); - - if (!(bits >= 4 && bits <= 16) || !(mode >= 0 && mode <= 3)) { - error("SPI format error"); - } + assert((bits >= 4 && bits <= 16) || (mode >= 0 && mode <= 3)); int polarity = (mode & 0x2) ? 1 : 0; int phase = (mode & 0x1) ? 1 : 0; diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC15XX/analogin_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC15XX/analogin_api.c index d5059fd5a0..6408ccae88 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC15XX/analogin_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC15XX/analogin_api.c @@ -13,11 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +#include #include "analogin_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" #define ANALOGIN_MEDIAN_FILTER 1 @@ -55,9 +54,8 @@ static const PinMap PinMap_ADC[] = { void analogin_init(analogin_t *obj, PinName pin) { obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC); - if (obj->adc == (uint32_t)NC) { - error("ADC pin mapping failed"); - } + assert(obj->adc != (ADCName)NC); + uint32_t port = (pin >> 5); // enable clock for GPIOx LPC_SYSCON->SYSAHBCLKCTRL0 |= (1UL << (14 + port)); diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC15XX/analogout_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC15XX/analogout_api.c index e2c6acf9ef..143a37b4c4 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC15XX/analogout_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC15XX/analogout_api.c @@ -13,15 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "analogout_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" void analogout_init(dac_t *obj, PinName pin) { - if (pin != P0_12) { - error("DAC pin mapping failed"); - } + assert(pin == P0_12); LPC_SYSCON->SYSAHBCLKCTRL0 |= (1 << 29); LPC_SYSCON->PDRUNCFG &= ~(1 << 12); diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC15XX/i2c_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC15XX/i2c_api.c index 09d7ec6b55..afecd74670 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC15XX/i2c_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC15XX/i2c_api.c @@ -13,11 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +#include #include "i2c_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" static uint8_t repeated_start = 0; @@ -42,9 +41,7 @@ static inline void i2c_interface_enable(i2c_t *obj) { } void i2c_init(i2c_t *obj, PinName sda, PinName scl) { - if ((sda != P0_23) | (scl != P0_22)) { - error("I2C pin mapping failed"); - } + assert((sda == P0_23) || (scl == P0_22)); // Enables clock for I2C0 LPC_SYSCON->SYSAHBCLKCTRL1 |= (1 << 13); diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC15XX/pwmout_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC15XX/pwmout_api.c index 2ebcf155ba..a24db78b65 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC15XX/pwmout_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC15XX/pwmout_api.c @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +#include #include "pwmout_api.h" #include "cmsis.h" #include "pinmap.h" @@ -38,9 +38,8 @@ static int get_available_sct(void) { } void pwmout_init(pwmout_t* obj, PinName pin) { - if (pin == (uint32_t)NC) - error("PwmOut pin mapping failed"); - + assert(pin != (uint32_t)NC); + int sct_n = get_available_sct(); if (sct_n == -1) { error("No available SCT"); diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC15XX/serial_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC15XX/serial_api.c index 462b765f63..e4e2bc3166 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC15XX/serial_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC15XX/serial_api.c @@ -14,6 +14,7 @@ * limitations under the License. */ // math.h required for floating point operations for baud rate calculation +#include #include #include @@ -91,7 +92,7 @@ static void switch_pin(const SWM_Map *swm, PinName pn) for (int n = 0; n < sizeof(LPC_SWM->PINASSIGN)/sizeof(*LPC_SWM->PINASSIGN); n ++) { regVal = LPC_SWM->PINASSIGN[n]; for (int j = 0; j <= 24; j += 8) { - if (((regVal >> j) & 0xFF) == pn) + if (((regVal >> j) & 0xFF) == pn) regVal |= (0xFF << j); } LPC_SWM->PINASSIGN[n] = regVal; @@ -195,16 +196,11 @@ void serial_baud(serial_t *obj, int baudrate) { } void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) { - // 0: 1 stop bits, 1: 2 stop bits - if (stop_bits != 1 && stop_bits != 2) { - error("Invalid stop bits specified"); - } + assert((stop_bits == 1) || (stop_bits == 2)); // 0: 1 stop bits, 1: 2 stop bits + assert((data_bits > 6) || (data_bits < 10)); // 0: 7 data bits ... 2: 9 data bits + assert(parity < (ParityEven + 1)); + stop_bits -= 1; - - // 0: 7 data bits ... 2: 9 data bits - if (data_bits < 7 || data_bits > 9) { - error("Invalid number of bits (%d) in serial format, should be 7..9", data_bits); - } data_bits -= 7; int paritysel; @@ -213,8 +209,7 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b case ParityEven: paritysel = 2; break; case ParityOdd : paritysel = 3; break; default: - error("Invalid serial parity setting"); - return; + break; } obj->uart->CFG = (data_bits << 2) diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC15XX/spi_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC15XX/spi_api.c index 9d38588e43..81455d5329 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC15XX/spi_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC15XX/spi_api.c @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include #include "spi_api.h" @@ -126,10 +127,7 @@ void spi_free(spi_t *obj) {} void spi_format(spi_t *obj, int bits, int mode, int slave) { spi_disable(obj); - - if (!(bits >= 1 && bits <= 16) || !(mode >= 0 && mode <= 3)) { - error("SPI format error"); - } + assert((bits >= 1 && bits <= 16) || (mode >= 0 && mode <= 3)); int polarity = (mode & 0x2) ? 1 : 0; int phase = (mode & 0x1) ? 1 : 0; diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/analogin_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/analogin_api.c index 982845b2c2..32e1ab4dd1 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/analogin_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/analogin_api.c @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "analogin_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" #define ANALOGIN_MEDIAN_FILTER 1 @@ -44,9 +44,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"); - } + assert(obj->adc != (ADCName)NC); // ensure power is turned on LPC_SC->PCONP |= (1 << 12); diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/analogout_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/analogout_api.c index 103b644f17..4804db09d3 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/analogout_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/analogout_api.c @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "analogout_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" static const PinMap PinMap_DAC[] = { {P0_26, DAC_0, 2}, @@ -26,9 +26,7 @@ static 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"); - } + assert(obj->dac == (DACName)NC); // power is on by default, set DAC clk divider is /4 LPC_SC->PCLKSEL0 &= ~(0x3 << 22); diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/can_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/can_api.c index 35b62ba241..d68e1f62a7 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/can_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/can_api.c @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "can_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" #include #include @@ -258,9 +258,7 @@ void can_init(can_t *obj, PinName rd, PinName td) { CANName can_rd = (CANName)pinmap_peripheral(rd, PinMap_CAN_RD); CANName can_td = (CANName)pinmap_peripheral(td, PinMap_CAN_TD); obj->dev = (LPC_CAN_TypeDef *)pinmap_merge(can_rd, can_td); - if ((int)obj->dev == NC) { - error("CAN pin mapping failed"); - } + assert((int)obj->dev != NC); switch ((int)obj->dev) { case CAN_1: LPC_SC->PCONP |= 1 << 13; break; diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/i2c_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/i2c_api.c index 3a405016be..ceb6abd089 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/i2c_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/i2c_api.c @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "i2c_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" static const PinMap PinMap_I2C_SDA[] = { {P0_0 , I2C_1, 3}, @@ -96,10 +96,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) { I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA); I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL); obj->i2c = (LPC_I2C_TypeDef *)pinmap_merge(i2c_sda, i2c_scl); - - if ((int)obj->i2c == NC) { - error("I2C pin mapping failed"); - } + assert((int)obj->i2c != NC); // enable power i2c_power_enable(obj); diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/pwmout_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/pwmout_api.c index b4e8bc6acf..83d5bc9d69 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/pwmout_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/pwmout_api.c @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "pwmout_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" #define TCR_CNT_EN 0x00000001 #define TCR_RESET 0x00000002 @@ -57,9 +57,8 @@ static unsigned int pwm_clock_mhz; 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"); - + assert(pwm != (PWMName)NC); + obj->pwm = pwm; obj->MR = PWM_MATCH[pwm]; diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/serial_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/serial_api.c index c9bbee6bf0..5f6f7fbec7 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/serial_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/serial_api.c @@ -14,6 +14,7 @@ * limitations under the License. */ // math.h required for floating point operations for baud rate calculation +#include #include #include #include @@ -21,7 +22,6 @@ #include "serial_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" #include "gpio_api.h" /****************************************************************************** @@ -89,9 +89,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) { UARTName uart_tx = (UARTName)pinmap_peripheral(tx, PinMap_UART_TX); 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"); - } + assert((int)uart != NC); obj->uart = (LPC_UART_TypeDef *)uart; // enable power @@ -150,6 +148,7 @@ void serial_free(serial_t *obj) { // serial_baud // set the baud rate, taking in to account the current SystemFrequency void serial_baud(serial_t *obj, int baudrate) { + assert((int)obj->uart <= UART_3); // The LPC2300 and LPC1700 have a divider and a fractional divider to control the // baud rate. The formula is: // @@ -165,7 +164,7 @@ void serial_baud(serial_t *obj, int baudrate) { case UART_1: LPC_SC->PCLKSEL0 &= ~(0x3 << 8); LPC_SC->PCLKSEL0 |= (0x1 << 8); break; case UART_2: LPC_SC->PCLKSEL1 &= ~(0x3 << 16); LPC_SC->PCLKSEL1 |= (0x1 << 16); break; case UART_3: LPC_SC->PCLKSEL1 &= ~(0x3 << 18); LPC_SC->PCLKSEL1 |= (0x1 << 18); break; - default: error("serial_baud"); break; + default: break; } uint32_t PCLK = SystemCoreClock; @@ -245,16 +244,11 @@ void serial_baud(serial_t *obj, int baudrate) { } void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) { - // 0: 1 stop bits, 1: 2 stop bits - if (stop_bits != 1 && stop_bits != 2) { - error("Invalid stop bits specified"); - } + assert((stop_bits == 1) || (stop_bits == 2)); // 0: 1 stop bits, 1: 2 stop bits + assert((data_bits > 4) || (data_bits < 9)); // 0: 5 data bits ... 3: 8 data bits + assert(parity < (ParityForced0 + 1)); + stop_bits -= 1; - - // 0: 5 data bits ... 3: 8 data bits - if (data_bits < 5 || data_bits > 8) { - error("Invalid number of bits (%d) in serial format, should be 5..8", data_bits); - } data_bits -= 5; int parity_enable, parity_select; @@ -265,8 +259,7 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b case ParityForced1: parity_enable = 1; parity_select = 2; break; case ParityForced0: parity_enable = 1; parity_select = 3; break; default: - error("Invalid serial parity setting"); - return; + break; } obj->uart->LCR = data_bits << 0 diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/spi_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/spi_api.c index f45254657c..66ec890c18 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/spi_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/spi_api.c @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include #include "spi_api.h" @@ -64,9 +65,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel SPIName spi_data = (SPIName)pinmap_merge(spi_mosi, spi_miso); SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel); obj->spi = (LPC_SSP_TypeDef*)pinmap_merge(spi_data, spi_cntl); - if ((int)obj->spi == NC) { - error("SPI pinout mapping failed"); - } + assert((int)obj->spi != NC); // enable power and clocking switch ((int)obj->spi) { @@ -98,9 +97,7 @@ void spi_free(spi_t *obj) {} void spi_format(spi_t *obj, int bits, int mode, int slave) { ssp_disable(obj); - if (!(bits >= 4 && bits <= 16) || !(mode >= 0 && mode <= 3)) { - error("SPI format error"); - } + assert((bits >= 4 && bits <= 16) || (mode >= 0 && mode <= 3)); int polarity = (mode & 0x2) ? 1 : 0; int phase = (mode & 0x1) ? 1 : 0; diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/analogin_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/analogin_api.c index 0958fbaf7a..823a3e91e3 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/analogin_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/analogin_api.c @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "analogin_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" #define ANALOGIN_MEDIAN_FILTER 1 @@ -42,9 +42,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"); - } + assert(obj->adc != (ADCName)NC); // ensure power is turned on LPC_SC->PCONP |= (1 << 12); diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/analogout_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/analogout_api.c index 1cb557cead..79464f2b74 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/analogout_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/analogout_api.c @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "analogout_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" static const PinMap PinMap_DAC[] = { {P0_26, DAC_0, 2}, @@ -25,9 +25,7 @@ static 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"); - } + assert(obj->dac != (DACName)NC); // power is on by default, set DAC clk divider is /4 LPC_SC->PCLKSEL0 &= ~(0x3 << 22); diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/can_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/can_api.c index f7ddf5278d..dba2c4f20e 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/can_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/can_api.c @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "can_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" #include #include @@ -161,9 +161,7 @@ void can_init(can_t *obj, PinName rd, PinName td) { CANName can_rd = (CANName)pinmap_peripheral(rd, PinMap_CAN_RD); CANName can_td = (CANName)pinmap_peripheral(td, PinMap_CAN_TD); obj->dev = (LPC_CAN_TypeDef *)pinmap_merge(can_rd, can_td); - if ((int)obj->dev == NC) { - error("CAN pin mapping failed"); - } + assert((int)obj->dev != NC); switch ((int)obj->dev) { case CAN_1: LPC_SC->PCONP |= 1 << 13; break; diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/i2c_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/i2c_api.c index ecb6fb8756..2a53303a6d 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/i2c_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/i2c_api.c @@ -16,7 +16,6 @@ #include "i2c_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" static const PinMap PinMap_I2C_SDA[] = { {P0_0 , I2C_1, 3}, @@ -96,10 +95,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) { I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA); I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL); obj->i2c = (LPC_I2C_TypeDef *)pinmap_merge(i2c_sda, i2c_scl); - - if ((int)obj->i2c == NC) { - error("I2C pin mapping failed"); - } + assert((int)obj->i2c != NC); // enable power i2c_power_enable(obj); diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/pwmout_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/pwmout_api.c index c6da85102d..edec24405d 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/pwmout_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/pwmout_api.c @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "pwmout_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" #define TCR_CNT_EN 0x00000001 #define TCR_RESET 0x00000002 @@ -57,9 +57,8 @@ static unsigned int pwm_clock_mhz; 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"); - + assert(pwm != (PWMName)NC); + obj->pwm = pwm; obj->MR = PWM_MATCH[pwm]; diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/serial_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/serial_api.c index a4a4b311fb..2076a1ccd8 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/serial_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/serial_api.c @@ -14,6 +14,7 @@ * limitations under the License. */ // math.h required for floating point operations for baud rate calculation +#include #include #include #include @@ -21,7 +22,6 @@ #include "serial_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" /****************************************************************************** * INITIALIZATION @@ -65,9 +65,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) { UARTName uart_tx = (UARTName)pinmap_peripheral(tx, PinMap_UART_TX); 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"); - } + assert((int)uart == NC); obj->uart = (LPC_UART_TypeDef *)uart; // enable power @@ -123,6 +121,7 @@ void serial_free(serial_t *obj) { // serial_baud // set the baud rate, taking in to account the current SystemFrequency void serial_baud(serial_t *obj, int baudrate) { + assert((int)obj->uart <= UART_3); // The LPC2300 and LPC1700 have a divider and a fractional divider to control the // baud rate. The formula is: // @@ -138,7 +137,7 @@ void serial_baud(serial_t *obj, int baudrate) { case UART_1: LPC_SC->PCLKSEL0 &= ~(0x3 << 8); LPC_SC->PCLKSEL0 |= (0x1 << 8); break; case UART_2: LPC_SC->PCLKSEL1 &= ~(0x3 << 16); LPC_SC->PCLKSEL1 |= (0x1 << 16); break; case UART_3: LPC_SC->PCLKSEL1 &= ~(0x3 << 18); LPC_SC->PCLKSEL1 |= (0x1 << 18); break; - default: error("serial_baud"); break; + default: break; } uint32_t PCLK = SystemCoreClock; @@ -218,16 +217,11 @@ void serial_baud(serial_t *obj, int baudrate) { } void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) { - // 0: 1 stop bits, 1: 2 stop bits - if (stop_bits != 1 && stop_bits != 2) { - error("Invalid stop bits specified"); - } + assert((stop_bits == 1) || (stop_bits == 2)); // 0: 1 stop bits, 1: 2 stop bits + assert((data_bits > 4) || (data_bits < 9)); // 0: 5 data bits ... 3: 8 data bits + assert(parity < (ParityForced0 + 1)); + stop_bits -= 1; - - // 0: 5 data bits ... 3: 8 data bits - if (data_bits < 5 || data_bits > 8) { - error("Invalid number of bits (%d) in serial format, should be 5..8", data_bits); - } data_bits -= 5; int parity_enable, parity_select; @@ -238,8 +232,7 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b case ParityForced1: parity_enable = 1; parity_select = 2; break; case ParityForced0: parity_enable = 1; parity_select = 3; break; default: - error("Invalid serial parity setting"); - return; + break; } obj->uart->LCR = data_bits << 0 diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/spi_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/spi_api.c index 82fef6a885..63c703c474 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/spi_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/spi_api.c @@ -64,10 +64,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel SPIName spi_data = (SPIName)pinmap_merge(spi_mosi, spi_miso); SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel); obj->spi = (LPC_SSP_TypeDef*)pinmap_merge(spi_data, spi_cntl); - - if ((int)obj->spi == NC) { - error("SPI pinout mapping failed"); - } + assert((int)obj->spi != NC); // enable power and clocking switch ((int)obj->spi) { @@ -98,12 +95,9 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel void spi_free(spi_t *obj) {} void spi_format(spi_t *obj, int bits, int mode, int slave) { + assert((bits >= 4 && bits <= 16) || (mode >= 0 && mode <= 3)); ssp_disable(obj); - if (!(bits >= 4 && bits <= 16) || !(mode >= 0 && mode <= 3)) { - error("SPI format error"); - } - int polarity = (mode & 0x2) ? 1 : 0; int phase = (mode & 0x1) ? 1 : 0; diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/analogin_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/analogin_api.c index 04e28939c5..f48d428576 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/analogin_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/analogin_api.c @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "analogin_api.h" #include "cmsis.h" #include "pinmap.h" @@ -43,9 +44,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"); - } + assert(obj->adc != (ADCName)NC); // ensure power is turned on LPC_SC->PCONP |= (1 << 12); diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/analogout_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/analogout_api.c index e43cc25982..c4b885249e 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/analogout_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/analogout_api.c @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "analogout_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" static const PinMap PinMap_DAC[] = { {P0_26, DAC_0, 2}, @@ -25,9 +25,7 @@ static 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"); - } + assert(obj->dac != (DACName)NC); // DAC enable bit must be set LPC_IOCON->P0_26 |= (1 << 16); // DACEN diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/can_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/can_api.c index 0ff86f93bf..1a86766df0 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/can_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/can_api.c @@ -17,7 +17,6 @@ #include "cmsis.h" #include "pinmap.h" -#include "error.h" #include #include @@ -244,9 +243,7 @@ void can_init(can_t *obj, PinName rd, PinName td) { CANName can_rd = (CANName)pinmap_peripheral(rd, PinMap_CAN_RD); CANName can_td = (CANName)pinmap_peripheral(td, PinMap_CAN_TD); obj->dev = (LPC_CAN_TypeDef *)pinmap_merge(can_rd, can_td); - if ((int)obj->dev == NC) { - error("CAN pin mapping failed"); - } + assert((int)obj->dev != NC); switch ((int)obj->dev) { case CAN_1: LPC_SC->PCONP |= 1 << 13; break; diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/i2c_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/i2c_api.c index 5619a51435..73f3105c17 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/i2c_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/i2c_api.c @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "i2c_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" static const PinMap PinMap_I2C_SDA[] = { {P0_0 , I2C_1, 3}, @@ -108,9 +108,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) { I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA); I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL); obj->i2c = (LPC_I2C_TypeDef *)pinmap_merge(i2c_sda, i2c_scl); - if ((int)obj->i2c == NC) { - error("I2C pin mapping failed"); - } + assert((int)obj->i2c != NC); // enable power i2c_power_enable(obj); diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/pwmout_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/pwmout_api.c index 296eef80f6..08463d0b6d 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/pwmout_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/pwmout_api.c @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "pwmout_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" #define TCR_CNT_EN 0x00000001 #define TCR_RESET 0x00000002 @@ -66,9 +66,8 @@ static unsigned int pwm_clock_mhz; 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"); - + assert(pwm != (PWMName)NC); + obj->channel = pwm; obj->pwm = LPC_PWM0; diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/serial_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/serial_api.c index 26d01224b7..a7b299c474 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/serial_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/serial_api.c @@ -72,9 +72,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) { UARTName uart_tx = (UARTName)pinmap_peripheral(tx, PinMap_UART_TX); 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"); - } + assert((int)uart != NC); obj->uart = (LPC_UART_TypeDef *)uart; // enable power @@ -209,16 +207,11 @@ void serial_baud(serial_t *obj, int baudrate) { } void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) { - // 0: 1 stop bits, 1: 2 stop bits - if (stop_bits != 1 && stop_bits != 2) { - error("Invalid stop bits specified"); - } + assert((stop_bits == 1) || (stop_bits == 2)); // 0: 1 stop bits, 1: 2 stop bits + assert((data_bits > 4) || (data_bits < 9)); // 0: 5 data bits ... 3: 8 data bits + assert(parity < (ParityForced0 + 1)); + stop_bits -= 1; - - // 0: 5 data bits ... 3: 8 data bits - if (data_bits < 5 || data_bits > 8) { - error("Invalid number of bits (%d) in serial format, should be 5..8", data_bits); - } data_bits -= 5; int parity_enable, parity_select; @@ -229,8 +222,7 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b case ParityForced1: parity_enable = 1; parity_select = 2; break; case ParityForced0: parity_enable = 1; parity_select = 3; break; default: - error("Invalid serial parity setting"); - return; + break; } obj->uart->LCR = data_bits << 0 diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/spi_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/spi_api.c index 1dd93555d9..9ee4fe5479 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/spi_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/spi_api.c @@ -84,9 +84,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel SPIName spi_data = (SPIName)pinmap_merge(spi_mosi, spi_miso); SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel); obj->spi = (LPC_SSP_TypeDef*)pinmap_merge(spi_data, spi_cntl); - if ((int)obj->spi == NC) { - error("SPI pinout mapping failed"); - } + assert((int)obj->spi != NC); // enable power and clocking switch ((int)obj->spi) { @@ -118,12 +116,9 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel void spi_free(spi_t *obj) {} void spi_format(spi_t *obj, int bits, int mode, int slave) { + assert((bits >= 4 && bits <= 16) || (mode >= 0 && mode <= 3)); ssp_disable(obj); - if (!(bits >= 4 && bits <= 16) || !(mode >= 0 && mode <= 3)) { - error("SPI format error"); - } - int polarity = (mode & 0x2) ? 1 : 0; int phase = (mode & 0x1) ? 1 : 0; diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/analogin_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/analogin_api.c index 045c0e7c9a..d49f0195e9 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/analogin_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/analogin_api.c @@ -15,10 +15,10 @@ * * Ported to NXP LPC43XX by Micromint USA */ +#include #include "analogin_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" #define ANALOGIN_MEDIAN_FILTER 1 @@ -41,10 +41,7 @@ void analogin_init(analogin_t *obj, PinName pin) { uint8_t num, chan; obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC); - if (obj->adc == (uint32_t)NC) { - error("ADC pin mapping failed"); - } - + assert(obj->adc != (ADCName)NC); // Configure the pin as GPIO input if (pin < SFP_AIO0) { diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/analogout_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/analogout_api.c index 9a2dedaf00..69b7d5cc84 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/analogout_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/analogout_api.c @@ -15,10 +15,10 @@ * * Ported to NXP LPC43XX by Micromint USA */ +#include #include "analogout_api.h" #include "cmsis.h" #include "pinmap.h" -#include "error.h" static const PinMap PinMap_DAC[] = { {P_DAC0 , DAC_0, 0x0}, @@ -27,9 +27,7 @@ static 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"); - } + assert(obj->dac != (DACName)NC); // Configure the pin as GPIO input pin_function(pin, (SCU_PINIO_PULLNONE | 0x0)); diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/serial_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/serial_api.c index 6efec95413..c965cd9517 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/serial_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/serial_api.c @@ -192,16 +192,11 @@ void serial_baud(serial_t *obj, int baudrate) { } void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) { - // 0: 1 stop bits, 1: 2 stop bits - if (stop_bits != 1 && stop_bits != 2) { - error("Invalid stop bits specified"); - } + assert((stop_bits == 1) || (stop_bits == 2)); // 0: 1 stop bits, 1: 2 stop bits + assert((data_bits > 4) || (data_bits < 9)); // 0: 5 data bits ... 3: 8 data bits + assert(parity < (ParityForced0 + 1)); + stop_bits -= 1; - - // 0: 5 data bits ... 3: 8 data bits - if (data_bits < 5 || data_bits > 8) { - error("Invalid number of bits (%d) in serial format, should be 5..8", data_bits); - } data_bits -= 5; int parity_enable, parity_select; @@ -212,8 +207,7 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b case ParityForced1: parity_enable = 1; parity_select = 2; break; case ParityForced0: parity_enable = 1; parity_select = 3; break; default: - error("Invalid serial parity setting"); - return; + break; } obj->uart->LCR = data_bits << 0 diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/spi_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/spi_api.c index 9db8e12a31..0cee578fe7 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/spi_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/spi_api.c @@ -15,6 +15,7 @@ * * Ported to NXP LPC43XX by Micromint USA */ +#include #include #include "spi_api.h" @@ -59,9 +60,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel); obj->spi = (LPC_SSP_T*)pinmap_merge(spi_data, spi_cntl); - if ((int)obj->spi == NC) { - error("SPI pinout mapping failed"); - } + assert((int)obj->spi != NC); // set default format and frequency if (ssel == NC) { @@ -86,12 +85,9 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel void spi_free(spi_t *obj) {} void spi_format(spi_t *obj, int bits, int mode, int slave) { + assert((bits >= 4 && bits <= 16) || (mode >= 0 && mode <= 3)); ssp_disable(obj); - if (!(bits >= 4 && bits <= 16) || !(mode >= 0 && mode <= 3)) { - error("SPI format error"); - } - int polarity = (mode & 0x2) ? 1 : 0; int phase = (mode & 0x1) ? 1 : 0; diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC81X/spi_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC81X/spi_api.c index 41eb3538e6..9c3de9534f 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC81X/spi_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC81X/spi_api.c @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include #include "spi_api.h" @@ -115,13 +116,9 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel void spi_free(spi_t *obj) {} void spi_format(spi_t *obj, int bits, int mode, int slave) { + assert((bits >= 1 && bits <= 16) || (mode >= 0 && mode <= 3)); ssp_disable(obj); - if (!(bits >= 1 && bits <= 16) || !(mode >= 0 && mode <= 3)) { - error("SPI format error"); - } - - int polarity = (mode & 0x2) ? 1 : 0; int phase = (mode & 0x1) ? 1 : 0;