Merge branch '0xc0170-dev_error_assert'

pull/353/head
Bogdan Marinescu 2014-06-11 15:51:01 +01:00
commit fb9ea201d4
217 changed files with 1186 additions and 1312 deletions

View File

@ -0,0 +1,50 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBED_ASSERT_H
#define MBED_ASSERT_H
#ifdef __cplusplus
extern "C" {
#endif
/** Internal mbed assert function which is invoked when MBED_ASSERT macro failes.
* This function is active only if NDEBUG is not defined prior to including this
* assert header file.
* In case of MBED_ASSERT failing condition, the assertation message is printed
* to stderr and mbed_die() is called.
* @param expr Expresion to be checked.
* @param file File where assertation failed.
* @param line Failing assertation line number.
*/
void mbed_assert_internal(const char *expr, const char *file, int line);
#ifdef __cplusplus
}
#endif
#ifdef NDEBUG
#define MBED_ASSERT(expr) ((void)0)
#else
#define MBED_ASSERT(expr) \
do { \
if (!(expr)) { \
mbed_assert_internal(#expr, __FILE__, __LINE__); \
} \
} while (0)
#endif
#endif

View File

@ -0,0 +1,32 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "mbed_assert.h"
#include "device.h"
#if DEVICE_STDIO_MESSAGES
#include <stdio.h>
#endif
#include <stdlib.h>
#include "mbed_interface.h"
void mbed_assert_internal(const char *expr, const char *file, int line)
{
#if DEVICE_STDIO_MESSAGES
fprintf(stderr, "mbed assertation failed: %s, file: %s, line %d \n", expr, file, line);
#endif
mbed_die();
}

View File

@ -17,7 +17,8 @@
#include "error.h" #include "error.h"
void pinmap_pinout(PinName pin, const PinMap *map) { void pinmap_pinout(PinName pin, const PinMap *map) {
if (pin == NC) return; if (pin == NC)
return;
while (map->pin != NC) { while (map->pin != NC) {
if (map->pin == pin) { if (map->pin == pin) {
@ -33,11 +34,14 @@ void pinmap_pinout(PinName pin, const PinMap *map) {
uint32_t pinmap_merge(uint32_t a, uint32_t b) { uint32_t pinmap_merge(uint32_t a, uint32_t b) {
// both are the same (inc both NC) // both are the same (inc both NC)
if (a == b) return a; if (a == b)
return a;
// one (or both) is not connected // one (or both) is not connected
if (a == (uint32_t)NC) return b; if (a == (uint32_t)NC)
if (b == (uint32_t)NC) return a; return b;
if (b == (uint32_t)NC)
return a;
// mis-match error case // mis-match error case
error("pinmap mis-match"); error("pinmap mis-match");

View File

@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "analogin_api.h" #include "analogin_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
#include "clk_freqs.h" #include "clk_freqs.h"
static const PinMap PinMap_ADC[] = { static const PinMap PinMap_ADC[] = {
@ -38,8 +38,7 @@ static const PinMap PinMap_ADC[] = {
void analogin_init(analogin_t *obj, PinName pin) { void analogin_init(analogin_t *obj, PinName pin) {
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC); obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
if (obj->adc == (ADCName)NC) MBED_ASSERT(obj->adc != (ADCName)NC);
error("ADC pin mapping failed");
SIM->SCGC6 |= SIM_SCGC6_ADC0_MASK; SIM->SCGC6 |= SIM_SCGC6_ADC0_MASK;

View File

@ -13,19 +13,21 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "gpio_api.h" #include "gpio_api.h"
#include "pinmap.h" #include "pinmap.h"
uint32_t gpio_set(PinName pin) { uint32_t gpio_set(PinName pin) {
MBED_ASSERT(pin != (PinName)NC);
pin_function(pin, 1); pin_function(pin, 1);
return 1 << ((pin & 0x7F) >> 2); return 1 << ((pin & 0x7F) >> 2);
} }
void gpio_init(gpio_t *obj, PinName pin) { void gpio_init(gpio_t *obj, PinName pin) {
if(pin == NC) obj->pin = pin;
if (pin == (PinName)NC)
return; return;
obj->pin = pin;
obj->mask = gpio_set(pin); obj->mask = gpio_set(pin);
unsigned int port = (unsigned int)pin >> PORT_SHIFT; unsigned int port = (unsigned int)pin >> PORT_SHIFT;
@ -42,6 +44,7 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
} }
void gpio_dir(gpio_t *obj, PinDirection direction) { void gpio_dir(gpio_t *obj, PinDirection direction) {
MBED_ASSERT(obj->pin != (PinName)NC);
switch (direction) { switch (direction) {
case PIN_INPUT : case PIN_INPUT :
*obj->reg_dir &= ~obj->mask; *obj->reg_dir &= ~obj->mask;

View File

@ -16,6 +16,8 @@
#ifndef MBED_GPIO_OBJECT_H #ifndef MBED_GPIO_OBJECT_H
#define MBED_GPIO_OBJECT_H #define MBED_GPIO_OBJECT_H
#include "mbed_assert.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -31,6 +33,7 @@ typedef struct {
} gpio_t; } gpio_t;
static inline void gpio_write(gpio_t *obj, int value) { static inline void gpio_write(gpio_t *obj, int value) {
MBED_ASSERT(obj->pin != (PinName)NC);
if (value) { if (value) {
*obj->reg_set = obj->mask; *obj->reg_set = obj->mask;
} else { } else {
@ -39,6 +42,7 @@ static inline void gpio_write(gpio_t *obj, int value) {
} }
static inline int gpio_read(gpio_t *obj) { static inline int gpio_read(gpio_t *obj) {
MBED_ASSERT(obj->pin != (PinName)NC);
return ((*obj->reg_in & obj->mask) ? 1 : 0); return ((*obj->reg_in & obj->mask) ? 1 : 0);
} }

View File

@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "i2c_api.h" #include "i2c_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
#include "clk_freqs.h" #include "clk_freqs.h"
static const PinMap PinMap_I2C_SDA[] = { 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_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA);
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL); I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
obj->i2c = (I2C_Type*)pinmap_merge(i2c_sda, i2c_scl); obj->i2c = (I2C_Type*)pinmap_merge(i2c_sda, i2c_scl);
if ((int)obj->i2c == NC) MBED_ASSERT((int)obj->i2c != NC);
error("I2C pin mapping failed");
SIM->SCGC4 |= SIM_SCGC4_I2C0_MASK; SIM->SCGC4 |= SIM_SCGC4_I2C0_MASK;
SIM->SCGC5 |= SIM_SCGC5_PORTB_MASK; SIM->SCGC5 |= SIM_SCGC5_PORTB_MASK;

View File

@ -13,12 +13,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
void pin_function(PinName pin, int function) { void pin_function(PinName pin, int function) {
if (pin == (PinName)NC) MBED_ASSERT(pin != (PinName)NC);
return;
uint32_t port_n = (uint32_t)pin >> PORT_SHIFT; uint32_t port_n = (uint32_t)pin >> PORT_SHIFT;
uint32_t pin_n = (uint32_t)(pin & 0x7C) >> 2; uint32_t pin_n = (uint32_t)(pin & 0x7C) >> 2;
@ -31,8 +30,7 @@ void pin_function(PinName pin, int function) {
} }
void pin_mode(PinName pin, PinMode mode) { void pin_mode(PinName pin, PinMode mode) {
if (pin == (PinName)NC) { return; } MBED_ASSERT(pin != (PinName)NC);
__IO uint32_t* pin_pcr = (__IO uint32_t*)(PORTA_BASE + pin); __IO uint32_t* pin_pcr = (__IO uint32_t*)(PORTA_BASE + pin);
// pin pullup bits: [1:0] -> 11 = (0x3) // pin pullup bits: [1:0] -> 11 = (0x3)

View File

@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "pwmout_api.h" #include "pwmout_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
static const PinMap PinMap_PWM[] = { static const PinMap PinMap_PWM[] = {
// LEDs // LEDs
@ -53,8 +53,7 @@ static float pwm_clock = 0;
void pwmout_init(pwmout_t* obj, PinName pin) { void pwmout_init(pwmout_t* obj, PinName pin) {
// determine the channel // determine the channel
PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM); PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
if (pwm == (PWMName)NC) MBED_ASSERT(pwm != (PWMName)NC);
error("PwmOut pin mapping failed");
uint32_t clkdiv = 0; uint32_t clkdiv = 0;
float clkval = SystemCoreClock / 1000000.0f; float clkval = SystemCoreClock / 1000000.0f;

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "serial_api.h" #include "serial_api.h"
// math.h required for floating point operations for baud rate calculation // math.h required for floating point operations for baud rate calculation
@ -22,7 +23,6 @@
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
static const PinMap PinMap_UART_TX[] = { static const PinMap PinMap_UART_TX[] = {
{PTB17, UART_0, 3}, {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_tx = (UARTName)pinmap_peripheral(tx, PinMap_UART_TX);
UARTName uart_rx = (UARTName)pinmap_peripheral(rx, PinMap_UART_RX); UARTName uart_rx = (UARTName)pinmap_peripheral(rx, PinMap_UART_RX);
UARTName uart = (UARTName)pinmap_merge(uart_tx, uart_rx); UARTName uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
if ((int)uart == NC) MBED_ASSERT((int)uart != NC);
error("Serial pinout mapping failed");
obj->uart = (UART_Type *)uart; obj->uart = (UART_Type *)uart;
// enable clk // enable clk
@ -117,6 +116,9 @@ void serial_baud(serial_t *obj, int baudrate) {
} }
void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) { void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) {
MBED_ASSERT((stop_bits == 1) || (stop_bits == 2));
MBED_ASSERT((parity == ParityNone) || (parity == ParityOdd) || (parity == ParityEven));
MBED_ASSERT((data_bits == 8) || (data_bits == 9));
// save C2 state // save C2 state
uint32_t c2_state = (obj->uart->C2 & (UART_C2_RE_MASK | UART_C2_TE_MASK)); uint32_t c2_state = (obj->uart->C2 & (UART_C2_RE_MASK | UART_C2_TE_MASK));
@ -125,9 +127,6 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
obj->uart->C2 &= ~(UART_C2_RE_MASK | UART_C2_TE_MASK); obj->uart->C2 &= ~(UART_C2_RE_MASK | UART_C2_TE_MASK);
// 8 data bits = 0 ... 9 data bits = 1 // 8 data bits = 0 ... 9 data bits = 1
if ((data_bits < 8) || (data_bits > 9))
error("Invalid number of bits (%d) in serial format, should be 8..9", data_bits);
data_bits -= 8; data_bits -= 8;
uint32_t parity_enable, parity_select; uint32_t parity_enable, parity_select;
@ -136,22 +135,16 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
case ParityOdd : parity_enable = 1; parity_select = 1; data_bits++; break; case ParityOdd : parity_enable = 1; parity_select = 1; data_bits++; break;
case ParityEven: parity_enable = 1; parity_select = 0; data_bits++; break; case ParityEven: parity_enable = 1; parity_select = 0; data_bits++; break;
default: default:
error("Invalid serial parity setting"); break;
return;
} }
// 1 stop bits = 0, 2 stop bits = 1
if ((stop_bits != 1) && (stop_bits != 2))
error("Invalid stop bits specified");
stop_bits -= 1; stop_bits -= 1;
uint32_t m10 = 0; uint32_t m10 = 0;
// 9 data bits + parity // 9 data bits + parity - only uart0 support
if (data_bits == 2) { if (data_bits == 2) {
// only uart0 supports 10 bit communication MBED_ASSERT(obj->index == 0);
if (obj->index != 0)
error("Invalid number of bits (9) to be used with parity");
data_bits = 0; data_bits = 0;
m10 = 1; m10 = 1;
} }

View File

@ -13,13 +13,13 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "spi_api.h" #include "spi_api.h"
#include <math.h> #include <math.h>
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
#include "clk_freqs.h" #include "clk_freqs.h"
static const PinMap PinMap_SPI_SCLK[] = { 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); SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
obj->spi = (SPI_Type*)pinmap_merge(spi_data, spi_cntl); obj->spi = (SPI_Type*)pinmap_merge(spi_data, spi_cntl);
if ((int)obj->spi == NC) { MBED_ASSERT((int)obj->spi != NC);
error("SPI pinout mapping failed");
}
SIM->SCGC5 |= SIM_SCGC5_PORTC_MASK | SIM_SCGC5_PORTD_MASK; SIM->SCGC5 |= SIM_SCGC5_PORTC_MASK | SIM_SCGC5_PORTD_MASK;
SIM->SCGC6 |= SIM_SCGC6_SPI0_MASK; SIM->SCGC6 |= SIM_SCGC6_SPI0_MASK;
@ -90,13 +88,8 @@ void spi_free(spi_t *obj) {
// [TODO] // [TODO]
} }
void spi_format(spi_t *obj, int bits, int mode, int slave) { void spi_format(spi_t *obj, int bits, int mode, int slave) {
if ((bits < 4) || (bits > 16)) MBED_ASSERT((bits > 4) || (bits < 16));
error("SPI: Only frames between 4 and 16-bit supported"); MBED_ASSERT((mode >= 0) && (mode <= 3));
if ((mode < 0) || (mode > 3)) {
error("SPI mode unsupported");
}
uint32_t polarity = (mode & 0x2) ? 1 : 0; uint32_t polarity = (mode & 0x2) ? 1 : 0;
uint32_t phase = (mode & 0x1) ? 1 : 0; uint32_t phase = (mode & 0x1) ? 1 : 0;

View File

@ -19,7 +19,6 @@
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
static const PinMap PinMap_SPI_SCLK[] = { static const PinMap PinMap_SPI_SCLK[] = {
{PTB0, SPI_0, 3}, {PTB0, SPI_0, 3},
@ -51,9 +50,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); SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
obj->spi = (SPI_Type*)pinmap_merge(spi_data, spi_cntl); obj->spi = (SPI_Type*)pinmap_merge(spi_data, spi_cntl);
if ((int)obj->spi == NC) { MBED_ASSERT((int)obj->spi != NC);
error("SPI pinout mapping failed");
}
// enable power and clocking // enable power and clocking
switch ((int)obj->spi) { switch ((int)obj->spi) {
@ -87,13 +84,8 @@ void spi_free(spi_t *obj) {
// [TODO] // [TODO]
} }
void spi_format(spi_t *obj, int bits, int mode, int slave) { void spi_format(spi_t *obj, int bits, int mode, int slave) {
if (bits != 8) { MBED_ASSERT(bits == 8);
error("Only 8bits SPI supported"); MBED_ASSERT((mode >= 0) && (mode <= 3));
}
if ((mode < 0) || (mode > 3)) {
error("SPI mode unsupported");
}
uint8_t polarity = (mode & 0x2) ? 1 : 0; uint8_t polarity = (mode & 0x2) ? 1 : 0;
uint8_t phase = (mode & 0x1) ? 1 : 0; uint8_t phase = (mode & 0x1) ? 1 : 0;

View File

@ -19,7 +19,6 @@
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
#include "clk_freqs.h" #include "clk_freqs.h"
#include "PeripheralPins.h" #include "PeripheralPins.h"
@ -33,9 +32,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); SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
obj->spi = (SPI_Type*)pinmap_merge(spi_data, spi_cntl); obj->spi = (SPI_Type*)pinmap_merge(spi_data, spi_cntl);
if ((int)obj->spi == NC) { MBED_ASSERT((int)obj->spi != NC);
error("SPI pinout mapping failed");
}
// enable power and clocking // enable power and clocking
switch ((int)obj->spi) { switch ((int)obj->spi) {
@ -67,13 +64,8 @@ void spi_free(spi_t *obj) {
// [TODO] // [TODO]
} }
void spi_format(spi_t *obj, int bits, int mode, int slave) { void spi_format(spi_t *obj, int bits, int mode, int slave) {
if (bits != 8) { MBED_ASSERT(bits == 8);
error("Only 8bits SPI supported"); MBED_ASSERT((mode >= 0) && (mode <= 3));
}
if ((mode < 0) || (mode > 3)) {
error("SPI mode unsupported");
}
uint8_t polarity = (mode & 0x2) ? 1 : 0; uint8_t polarity = (mode & 0x2) ? 1 : 0;
uint8_t phase = (mode & 0x1) ? 1 : 0; uint8_t phase = (mode & 0x1) ? 1 : 0;

View File

@ -13,13 +13,13 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "spi_api.h" #include "spi_api.h"
#include <math.h> #include <math.h>
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
static const PinMap PinMap_SPI_SCLK[] = { static const PinMap PinMap_SPI_SCLK[] = {
{PTA15, SPI_0, 2}, {PTA15, SPI_0, 2},
@ -90,9 +90,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); SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
obj->spi = (SPI_Type*)pinmap_merge(spi_data, spi_cntl); obj->spi = (SPI_Type*)pinmap_merge(spi_data, spi_cntl);
if ((int)obj->spi == NC) { MBED_ASSERT((int)obj->spi != NC);
error("SPI pinout mapping failed");
}
// enable power and clocking // enable power and clocking
switch ((int)obj->spi) { switch ((int)obj->spi) {
@ -125,13 +123,8 @@ void spi_free(spi_t *obj) {
// [TODO] // [TODO]
} }
void spi_format(spi_t *obj, int bits, int mode, int slave) { void spi_format(spi_t *obj, int bits, int mode, int slave) {
if ((bits != 8) && (bits != 16)) { MBED_ASSERT((bits == 8) || (bits == 16));
error("Only 8/16 bits SPI supported"); MBED_ASSERT((mode >= 0) && (mode <= 3));
}
if ((mode < 0) || (mode > 3)) {
error("SPI mode unsupported");
}
uint8_t polarity = (mode & 0x2) ? 1 : 0; uint8_t polarity = (mode & 0x2) ? 1 : 0;
uint8_t phase = (mode & 0x1) ? 1 : 0; uint8_t phase = (mode & 0x1) ? 1 : 0;

View File

@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "analogin_api.h" #include "analogin_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
#include "clk_freqs.h" #include "clk_freqs.h"
#include "PeripheralPins.h" #include "PeripheralPins.h"
@ -27,9 +27,7 @@
void analogin_init(analogin_t *obj, PinName pin) { void analogin_init(analogin_t *obj, PinName pin) {
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC); obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
if (obj->adc == (ADCName)NC) { MBED_ASSERT(obj->adc != (ADCName)NC);
error("ADC pin mapping failed");
}
SIM->SCGC6 |= SIM_SCGC6_ADC0_MASK; SIM->SCGC6 |= SIM_SCGC6_ADC0_MASK;

View File

@ -13,21 +13,18 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "analogout_api.h" #include "analogout_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
#include "PeripheralPins.h" #include "PeripheralPins.h"
#define RANGE_12BIT 0xFFF #define RANGE_12BIT 0xFFF
void analogout_init(dac_t *obj, PinName pin) { void analogout_init(dac_t *obj, PinName pin) {
obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC); obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC);
if (obj->dac == (DACName)NC) { MBED_ASSERT(obj->dac != (DACName)NC);
error("DAC pin mapping failed");
}
SIM->SCGC6 |= SIM_SCGC6_DAC0_MASK; SIM->SCGC6 |= SIM_SCGC6_DAC0_MASK;

View File

@ -13,18 +13,21 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "gpio_api.h" #include "gpio_api.h"
#include "pinmap.h" #include "pinmap.h"
uint32_t gpio_set(PinName pin) { uint32_t gpio_set(PinName pin) {
MBED_ASSERT(pin != (PinName)NC);
pin_function(pin, 1); pin_function(pin, 1);
return 1 << ((pin & 0x7F) >> 2); return 1 << ((pin & 0x7F) >> 2);
} }
void gpio_init(gpio_t *obj, PinName pin) { void gpio_init(gpio_t *obj, PinName pin) {
if(pin == (PinName)NC) return;
obj->pin = pin; obj->pin = pin;
if (pin == (PinName)NC)
return;
obj->mask = gpio_set(pin); obj->mask = gpio_set(pin);
unsigned int port = (unsigned int)pin >> PORT_SHIFT; unsigned int port = (unsigned int)pin >> PORT_SHIFT;
@ -41,8 +44,13 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
} }
void gpio_dir(gpio_t *obj, PinDirection direction) { void gpio_dir(gpio_t *obj, PinDirection direction) {
MBED_ASSERT(obj->pin != (PinName)NC);
switch (direction) { switch (direction) {
case PIN_INPUT : *obj->reg_dir &= ~obj->mask; break; case PIN_INPUT :
case PIN_OUTPUT: *obj->reg_dir |= obj->mask; break; *obj->reg_dir &= ~obj->mask;
break;
case PIN_OUTPUT:
*obj->reg_dir |= obj->mask;
break;
} }
} }

View File

@ -16,6 +16,8 @@
#ifndef MBED_GPIO_OBJECT_H #ifndef MBED_GPIO_OBJECT_H
#define MBED_GPIO_OBJECT_H #define MBED_GPIO_OBJECT_H
#include "mbed_assert.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -31,6 +33,7 @@ typedef struct {
} gpio_t; } gpio_t;
static inline void gpio_write(gpio_t *obj, int value) { static inline void gpio_write(gpio_t *obj, int value) {
MBED_ASSERT(obj->pin != (PinName)NC);
if (value) if (value)
*obj->reg_set = obj->mask; *obj->reg_set = obj->mask;
else else
@ -38,6 +41,7 @@ static inline void gpio_write(gpio_t *obj, int value) {
} }
static inline int gpio_read(gpio_t *obj) { static inline int gpio_read(gpio_t *obj) {
MBED_ASSERT(obj->pin != (PinName)NC);
return ((*obj->reg_in & obj->mask) ? 1 : 0); return ((*obj->reg_in & obj->mask) ? 1 : 0);
} }

View File

@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "i2c_api.h" #include "i2c_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
#include "clk_freqs.h" #include "clk_freqs.h"
#include "PeripheralPins.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_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA);
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL); I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
obj->i2c = (I2C_Type*)pinmap_merge(i2c_sda, i2c_scl); obj->i2c = (I2C_Type*)pinmap_merge(i2c_sda, i2c_scl);
if ((int)obj->i2c == NC) { MBED_ASSERT((int)obj->i2c != NC);
error("I2C pin mapping failed");
}
// enable power // enable power
switch ((int)obj->i2c) { switch ((int)obj->i2c) {

View File

@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
void pin_function(PinName pin, int function) { void pin_function(PinName pin, int function) {
if (pin == (PinName)NC) return; MBED_ASSERT(pin != (PinName)NC);
uint32_t port_n = (uint32_t)pin >> PORT_SHIFT; uint32_t port_n = (uint32_t)pin >> PORT_SHIFT;
uint32_t pin_n = (uint32_t)(pin & 0x7C) >> 2; uint32_t pin_n = (uint32_t)(pin & 0x7C) >> 2;
@ -30,7 +30,7 @@ void pin_function(PinName pin, int function) {
} }
void pin_mode(PinName pin, PinMode mode) { void pin_mode(PinName pin, PinMode mode) {
if (pin == (PinName)NC) { return; } MBED_ASSERT(pin != (PinName)NC);
__IO uint32_t* pin_pcr = (__IO uint32_t*)(PORTA_BASE + pin); __IO uint32_t* pin_pcr = (__IO uint32_t*)(PORTA_BASE + pin);

View File

@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "pwmout_api.h" #include "pwmout_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
#include "clk_freqs.h" #include "clk_freqs.h"
#include "PeripheralPins.h" #include "PeripheralPins.h"
@ -26,9 +26,8 @@ static float pwm_clock;
void pwmout_init(pwmout_t* obj, PinName pin) { void pwmout_init(pwmout_t* obj, PinName pin) {
// determine the channel // determine the channel
PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM); PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
if (pwm == (PWMName)NC) MBED_ASSERT(pwm != (PWMName)NC);
error("PwmOut pin mapping failed");
uint32_t clkdiv = 0; uint32_t clkdiv = 0;
float clkval; float clkval;
if (mcgpllfll_frequency()) { if (mcgpllfll_frequency()) {
@ -37,11 +36,11 @@ void pwmout_init(pwmout_t* obj, PinName pin) {
} else { } else {
SIM->SOPT2 |= SIM_SOPT2_TPMSRC(2); // Clock source: ExtOsc SIM->SOPT2 |= SIM_SOPT2_TPMSRC(2); // Clock source: ExtOsc
clkval = extosc_frequency() / 1000000.0f; clkval = extosc_frequency() / 1000000.0f;
} }
while (clkval > 1) { while (clkval > 1) {
clkdiv++; clkdiv++;
clkval /= 2.0; clkval /= 2.0;
if (clkdiv == 7) if (clkdiv == 7)
break; break;
} }

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "serial_api.h" #include "serial_api.h"
// math.h required for floating point operations for baud rate calculation // math.h required for floating point operations for baud rate calculation
@ -22,7 +23,6 @@
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
#include "clk_freqs.h" #include "clk_freqs.h"
#include "PeripheralPins.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_tx = (UARTName)pinmap_peripheral(tx, PinMap_UART_TX);
UARTName uart_rx = (UARTName)pinmap_peripheral(rx, PinMap_UART_RX); UARTName uart_rx = (UARTName)pinmap_peripheral(rx, PinMap_UART_RX);
UARTName uart = (UARTName)pinmap_merge(uart_tx, uart_rx); UARTName uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
if ((int)uart == NC) { MBED_ASSERT((int)uart != NC);
error("Serial pinout mapping failed");
}
obj->uart = (UARTLP_Type *)uart; obj->uart = (UARTLP_Type *)uart;
// enable clk // enable clk
@ -150,17 +148,16 @@ void serial_baud(serial_t *obj, int baudrate) {
} }
void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) { void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) {
MBED_ASSERT((stop_bits == 1) || (stop_bits == 2));
MBED_ASSERT((parity == ParityNone) || (parity == ParityOdd) || (parity == ParityEven));
MBED_ASSERT(data_bits == 8); // TODO: Support other number of data bits (also in the write method!)
// save C2 state // save C2 state
uint8_t c2_state = (obj->uart->C2 & (UARTLP_C2_RE_MASK | UARTLP_C2_TE_MASK)); uint8_t c2_state = (obj->uart->C2 & (UARTLP_C2_RE_MASK | UARTLP_C2_TE_MASK));
// Disable UART before changing registers // Disable UART before changing registers
obj->uart->C2 &= ~(UARTLP_C2_RE_MASK | UARTLP_C2_TE_MASK); obj->uart->C2 &= ~(UARTLP_C2_RE_MASK | UARTLP_C2_TE_MASK);
// TODO: Support other number of data bits (also in the write method!)
if ((data_bits < 8) || (data_bits > 8)) {
error("Invalid number of bits (%d) in serial format, should be 8", data_bits);
}
uint8_t parity_enable, parity_select; uint8_t parity_enable, parity_select;
switch (parity) { switch (parity) {
@ -168,14 +165,9 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
case ParityOdd : parity_enable = 1; parity_select = 1; data_bits++; break; case ParityOdd : parity_enable = 1; parity_select = 1; data_bits++; break;
case ParityEven: parity_enable = 1; parity_select = 0; data_bits++; break; case ParityEven: parity_enable = 1; parity_select = 0; data_bits++; break;
default: default:
error("Invalid serial parity setting"); break;
return;
} }
// 1 stop bits = 0, 2 stop bits = 1
if ((stop_bits != 1) && (stop_bits != 2)) {
error("Invalid stop bits specified");
}
stop_bits -= 1; stop_bits -= 1;
// data bits, parity and parity mode // data bits, parity and parity mode
@ -290,7 +282,7 @@ void serial_pinout_tx(PinName tx) {
} }
void serial_break_set(serial_t *obj) { 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) { void serial_break_clear(serial_t *obj) {

View File

@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "analogin_api.h" #include "analogin_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
#include "PeripheralNames.h" #include "PeripheralNames.h"
#include "fsl_adc_hal.h" #include "fsl_adc_hal.h"
#include "fsl_clock_manager.h" #include "fsl_clock_manager.h"
@ -49,9 +49,8 @@ static const PinMap PinMap_ADC[] = {
void analogin_init(analogin_t *obj, PinName pin) { void analogin_init(analogin_t *obj, PinName pin) {
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC); obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
if (obj->adc == (ADCName)NC) { MBED_ASSERT(obj->adc != (ADCName)NC);
error("ADC pin mapping failed");
}
uint32_t instance = obj->adc >> ADC_INSTANCE_SHIFT; uint32_t instance = obj->adc >> ADC_INSTANCE_SHIFT;
clock_manager_set_gate(kClockModuleADC, instance, true); clock_manager_set_gate(kClockModuleADC, instance, true);

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "gpio_api.h" #include "gpio_api.h"
#include "pinmap.h" #include "pinmap.h"
#include "fsl_port_hal.h" #include "fsl_port_hal.h"
@ -20,6 +21,7 @@
#include "fsl_sim_hal.h" #include "fsl_sim_hal.h"
uint32_t gpio_set(PinName pin) { uint32_t gpio_set(PinName pin) {
MBED_ASSERT(pin != (PinName)NC);
uint32_t pin_num = pin & 0xFF; uint32_t pin_num = pin & 0xFF;
pin_function(pin, (int)kPortMuxAsGpio); pin_function(pin, (int)kPortMuxAsGpio);
@ -27,11 +29,10 @@ uint32_t gpio_set(PinName pin) {
} }
void gpio_init(gpio_t *obj, PinName pin) { void gpio_init(gpio_t *obj, PinName pin) {
if (pin == NC) {
return;
}
obj->pinName = pin; obj->pinName = pin;
if (pin == (PinName)NC)
return;
uint32_t port = pin >> GPIO_PORT_SHIFT; uint32_t port = pin >> GPIO_PORT_SHIFT;
uint32_t pin_num = pin & 0xFF; uint32_t pin_num = pin & 0xFF;
clock_hal_set_gate(kSimClockModulePORT, port, true); clock_hal_set_gate(kSimClockModulePORT, port, true);
@ -43,6 +44,7 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
} }
void gpio_dir(gpio_t *obj, PinDirection direction) { void gpio_dir(gpio_t *obj, PinDirection direction) {
MBED_ASSERT(obj->pinName != (PinName)NC);
uint32_t port = obj->pinName >> GPIO_PORT_SHIFT; uint32_t port = obj->pinName >> GPIO_PORT_SHIFT;
uint32_t pin_num = obj->pinName & 0xFF; uint32_t pin_num = obj->pinName & 0xFF;

View File

@ -16,6 +16,7 @@
#ifndef MBED_GPIO_OBJECT_H #ifndef MBED_GPIO_OBJECT_H
#define MBED_GPIO_OBJECT_H #define MBED_GPIO_OBJECT_H
#include "mbed_assert.h"
#include "fsl_gpio_hal.h" #include "fsl_gpio_hal.h"
#ifdef __cplusplus #ifdef __cplusplus
@ -27,6 +28,7 @@ typedef struct {
} gpio_t; } gpio_t;
static inline void gpio_write(gpio_t *obj, int value) { static inline void gpio_write(gpio_t *obj, int value) {
MBED_ASSERT(obj->pinName != (PinName)NC);
uint32_t port = obj->pinName >> GPIO_PORT_SHIFT; uint32_t port = obj->pinName >> GPIO_PORT_SHIFT;
uint32_t pin = obj->pinName & 0xFF; uint32_t pin = obj->pinName & 0xFF;
@ -34,6 +36,7 @@ static inline void gpio_write(gpio_t *obj, int value) {
} }
static inline int gpio_read(gpio_t *obj) { static inline int gpio_read(gpio_t *obj) {
MBED_ASSERT(obj->pinName != (PinName)NC);
uint32_t port = obj->pinName >> GPIO_PORT_SHIFT; uint32_t port = obj->pinName >> GPIO_PORT_SHIFT;
uint32_t pin = obj->pinName & 0xFF; uint32_t pin = obj->pinName & 0xFF;

View File

@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "i2c_api.h" #include "i2c_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
#include "fsl_clock_manager.h" #include "fsl_clock_manager.h"
#include "fsl_i2c_hal.h" #include "fsl_i2c_hal.h"
#include "fsl_port_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_sda = pinmap_peripheral(sda, PinMap_I2C_SDA);
uint32_t i2c_scl = pinmap_peripheral(scl, PinMap_I2C_SCL); uint32_t i2c_scl = pinmap_peripheral(scl, PinMap_I2C_SCL);
obj->instance = pinmap_merge(i2c_sda, i2c_scl); obj->instance = pinmap_merge(i2c_sda, i2c_scl);
if ((int)obj->instance == NC) { MBED_ASSERT((int)obj->instance != NC);
error("I2C pin mapping failed");
}
clock_manager_set_gate(kClockModuleI2C, obj->instance, true); clock_manager_set_gate(kClockModuleI2C, obj->instance, true);
clock_manager_set_gate(kClockModulePORT, sda >> GPIO_PORT_SHIFT, true); clock_manager_set_gate(kClockModulePORT, sda >> GPIO_PORT_SHIFT, true);

View File

@ -13,25 +13,20 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h" #include "error.h"
#include "fsl_clock_manager.h" #include "fsl_clock_manager.h"
#include "fsl_port_hal.h" #include "fsl_port_hal.h"
void pin_function(PinName pin, int function) { void pin_function(PinName pin, int function) {
if (pin == (PinName)NC) { MBED_ASSERT(pin != (PinName)NC);
return;
}
clock_manager_set_gate(kClockModulePORT, pin >> GPIO_PORT_SHIFT, true); clock_manager_set_gate(kClockModulePORT, pin >> GPIO_PORT_SHIFT, true);
port_hal_mux_control(pin >> GPIO_PORT_SHIFT, pin & 0xFF, (port_mux_t)function); port_hal_mux_control(pin >> GPIO_PORT_SHIFT, pin & 0xFF, (port_mux_t)function);
} }
void pin_mode(PinName pin, PinMode mode) { void pin_mode(PinName pin, PinMode mode) {
if (pin == (PinName)NC) { MBED_ASSERT(pin != (PinName)NC);
return;
}
uint32_t instance = pin >> GPIO_PORT_SHIFT; uint32_t instance = pin >> GPIO_PORT_SHIFT;
uint32_t pinName = pin & 0xFF; uint32_t pinName = pin & 0xFF;

View File

@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "pwmout_api.h" #include "pwmout_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
#include "fsl_ftm_hal.h" #include "fsl_ftm_hal.h"
#include "fsl_mcg_hal.h" #include "fsl_mcg_hal.h"
#include "fsl_clock_manager.h" #include "fsl_clock_manager.h"
@ -73,9 +73,8 @@ static float pwm_clock_mhz;
void pwmout_init(pwmout_t* obj, PinName pin) { void pwmout_init(pwmout_t* obj, PinName pin) {
PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM); PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
if (pwm == (PWMName)NC) { MBED_ASSERT(pwm != (PWMName)NC);
error("PwmOut pin mapping failed");
}
obj->pwm_name = pwm; obj->pwm_name = pwm;
uint32_t pwm_base_clock; uint32_t pwm_base_clock;

View File

@ -17,12 +17,12 @@
// math.h required for floating point operations for baud rate calculation // math.h required for floating point operations for baud rate calculation
#include <math.h> #include <math.h>
#include "mbed_assert.h"
#include <string.h> #include <string.h>
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
#include "fsl_uart_hal.h" #include "fsl_uart_hal.h"
#include "fsl_clock_manager.h" #include "fsl_clock_manager.h"
#include "fsl_uart_features.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_tx = pinmap_peripheral(tx, PinMap_UART_TX);
uint32_t uart_rx = pinmap_peripheral(rx, PinMap_UART_RX); uint32_t uart_rx = pinmap_peripheral(rx, PinMap_UART_RX);
obj->index = (UARTName)pinmap_merge(uart_tx, uart_rx); obj->index = (UARTName)pinmap_merge(uart_tx, uart_rx);
if ((int)obj->index == NC) { MBED_ASSERT((int)obj->index != NC);
error("Serial pinout mapping failed");
}
uart_config_t uart_config; uart_config_t uart_config;
uart_config.baudRate = 9600; uart_config.baudRate = 9600;

View File

@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "spi_api.h"
#include <math.h> #include <math.h>
#include "mbed_assert.h"
#include "spi_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.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); uint32_t spi_cntl = pinmap_merge(spi_sclk, spi_ssel);
obj->instance = pinmap_merge(spi_data, spi_cntl); obj->instance = pinmap_merge(spi_data, spi_cntl);
if ((int)obj->instance == NC) { MBED_ASSERT((int)obj->instance != NC);
error("SPI pinout mapping failed");
}
// enable power and clocking // enable power and clocking
clock_manager_set_gate(kClockModuleSPI, obj->instance, true); clock_manager_set_gate(kClockModuleSPI, obj->instance, true);

View File

@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "analogin_api.h" #include "analogin_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
#define ANALOGIN_MEDIAN_FILTER 1 #define ANALOGIN_MEDIAN_FILTER 1
#define ADC_10BIT_RANGE 0x3FF #define ADC_10BIT_RANGE 0x3FF
@ -37,9 +37,7 @@ void analogin_init(analogin_t *obj, PinName pin) {
const PinMap *map = PinMap_ADC; const PinMap *map = PinMap_ADC;
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC); //(NRF_ADC_Type *) obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC); //(NRF_ADC_Type *)
if (obj->adc == (ADCName)NC) { MBED_ASSERT(obj->adc != (ADCName)NC);
error("ADC pin mapping failed");
}
while (map->pin != NC) { while (map->pin != NC) {
if (map->pin == pin){ if (map->pin == pin){
@ -50,12 +48,12 @@ void analogin_init(analogin_t *obj, PinName pin) {
} }
obj->adc_pin = (uint8_t)analogInputPin; obj->adc_pin = (uint8_t)analogInputPin;
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) | NRF_ADC->CONFIG = (ADC_CONFIG_RES_10bit << ADC_CONFIG_RES_Pos) |
(ADC_CONFIG_INPSEL_AnalogInputOneThirdPrescaling<< ADC_CONFIG_INPSEL_Pos) | (ADC_CONFIG_INPSEL_AnalogInputOneThirdPrescaling<< ADC_CONFIG_INPSEL_Pos) |
(ADC_CONFIG_REFSEL_SupplyOneThirdPrescaling << ADC_CONFIG_REFSEL_Pos) | (ADC_CONFIG_REFSEL_SupplyOneThirdPrescaling << ADC_CONFIG_REFSEL_Pos) |
(analogInputPin << ADC_CONFIG_PSEL_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) { uint16_t analogin_read_u16(analogin_t *obj) {

View File

@ -13,14 +13,16 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "gpio_api.h" #include "gpio_api.h"
#include "pinmap.h" #include "pinmap.h"
void gpio_init(gpio_t *obj, PinName pin) { void gpio_init(gpio_t *obj, PinName pin) {
if(pin == NC) return;
obj->pin = pin; obj->pin = pin;
obj->mask = (1ul<<pin); if (pin == (PinName)NC)
return;
obj->mask = (1ul << pin);
obj->reg_set = &NRF_GPIO->OUTSET; obj->reg_set = &NRF_GPIO->OUTSET;
obj->reg_clr = &NRF_GPIO->OUTCLR; obj->reg_clr = &NRF_GPIO->OUTCLR;
@ -33,20 +35,21 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
} }
void gpio_dir(gpio_t *obj, PinDirection direction) { void gpio_dir(gpio_t *obj, PinDirection direction) {
MBED_ASSERT(obj->pin != (PinName)NC);
switch (direction) { switch (direction) {
case PIN_INPUT : case PIN_INPUT :
NRF_GPIO->PIN_CNF[obj->pin] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) NRF_GPIO->PIN_CNF[obj->pin] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
| (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
| (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
| (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos); | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos);
break; break;
case PIN_OUTPUT: case PIN_OUTPUT:
NRF_GPIO->PIN_CNF[obj->pin] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) NRF_GPIO->PIN_CNF[obj->pin] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
| (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
| (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos)
| (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
| (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos); | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
break; break;
} }
} }

View File

@ -16,6 +16,8 @@
#ifndef MBED_GPIO_OBJECT_H #ifndef MBED_GPIO_OBJECT_H
#define MBED_GPIO_OBJECT_H #define MBED_GPIO_OBJECT_H
#include "mbed_assert.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -31,6 +33,7 @@ typedef struct {
} gpio_t; } gpio_t;
static inline void gpio_write(gpio_t *obj, int value) { static inline void gpio_write(gpio_t *obj, int value) {
MBED_ASSERT(obj->pin != (PinName)NC);
if (value) if (value)
*obj->reg_set = obj->mask; *obj->reg_set = obj->mask;
else else
@ -38,6 +41,7 @@ static inline void gpio_write(gpio_t *obj, int value) {
} }
static inline int gpio_read(gpio_t *obj) { static inline int gpio_read(gpio_t *obj) {
MBED_ASSERT(obj->pin != (PinName)NC);
return ((*obj->reg_in & obj->mask) ? 1 : 0); return ((*obj->reg_in & obj->mask) ? 1 : 0);
} }

View File

@ -13,12 +13,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "i2c_api.h" #include "i2c_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
static const PinMap PinMap_I2C_SDA[] = { static const PinMap PinMap_I2C_SDA[] = {
{p22, I2C_0, 1}, {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)); (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos));
obj->i2c->PSELSCL = scl; obj->i2c->PSELSCL = scl;
obj->i2c->PSELSDA = sda; obj->i2c->PSELSDA = sda;
// set default frequency at 100k // set default frequency at 100k
i2c_frequency(obj, frequency); i2c_frequency(obj, frequency);
i2c_interface_enable(obj); 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); I2CName i2c = (I2CName)pinmap_merge(i2c_sda,i2c_scl);
obj->i2c = (NRF_TWI_Type *)i2c; obj->i2c = (NRF_TWI_Type *)i2c;
if ((int)obj->i2c == NC) { MBED_ASSERT((int)obj->i2c != NC);
error("I2C pin mapping failed");
}
obj->scl=scl; obj->scl=scl;
obj->sda=sda; obj->sda=sda;
obj->i2c->EVENTS_ERROR = 0; obj->i2c->EVENTS_ERROR = 0;
obj->i2c->ENABLE = TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos; obj->i2c->ENABLE = TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos;
obj->i2c->POWER = 0; obj->i2c->POWER = 0;
for(int i=0;i<100;i++){ for(int i=0;i<100;i++){
} }
obj->i2c->POWER = 1; obj->i2c->POWER = 1;
twi_master_init(obj,sda,scl,100000); twi_master_init(obj,sda,scl,100000);
} }
void i2c_reset(i2c_t *obj) { void i2c_reset(i2c_t *obj) {
obj->i2c->EVENTS_ERROR = 0; obj->i2c->EVENTS_ERROR = 0;
obj->i2c->ENABLE = TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos; obj->i2c->ENABLE = TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos;
obj->i2c->POWER = 0; obj->i2c->POWER = 0;
for(int i=0;i<100;i++){ 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); twi_master_init(obj,obj->sda,obj->scl,obj->freq);
} }
@ -107,7 +103,7 @@ int i2c_stop(i2c_t *obj) {
timeOut--; timeOut--;
if(timeOut<0) if(timeOut<0)
return 1; return 1;
} }
addrSet = 0; addrSet = 0;
i2c_reset(obj); i2c_reset(obj);
return 0; return 0;
@ -122,7 +118,7 @@ int i2c_do_write(i2c_t *obj, int value) {
if(timeOut<0) if(timeOut<0)
return 1; return 1;
} }
obj->i2c->EVENTS_TXDSENT = 0; obj->i2c->EVENTS_TXDSENT = 0;
return 0; return 0;
} }
@ -166,17 +162,17 @@ void i2c_frequency(i2c_t *obj, int hz) {
} }
int checkError(i2c_t *obj){ int checkError(i2c_t *obj){
if (obj->i2c->EVENTS_ERROR == 1){ if (obj->i2c->EVENTS_ERROR == 1){
if (obj->i2c->ERRORSRC & TWI_ERRORSRC_ANACK_Msk){ if (obj->i2c->ERRORSRC & TWI_ERRORSRC_ANACK_Msk){
obj->i2c->EVENTS_ERROR = 0; obj->i2c->EVENTS_ERROR = 0;
obj->i2c->TASKS_STOP = 1; obj->i2c->TASKS_STOP = 1;
return I2C_ERROR_BUS_BUSY; return I2C_ERROR_BUS_BUSY;
} }
obj->i2c->EVENTS_ERROR = 0; obj->i2c->EVENTS_ERROR = 0;
obj->i2c->TASKS_STOP = 1; obj->i2c->TASKS_STOP = 1;
return I2C_ERROR_NO_SLAVE; return I2C_ERROR_NO_SLAVE;
} }
return 0; 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 // Read in all except last byte
for (count = 0; count < (length - 1); count++) { for (count = 0; count < (length - 1); count++) {
status = i2c_do_read(obj,&data[count], 0); status = i2c_do_read(obj,&data[count], 0);
if (status) { if (status) {
errorResult = checkError(obj); errorResult = checkError(obj);
i2c_reset(obj); i2c_reset(obj);
if(errorResult<0){ 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){ while(!obj->i2c->EVENTS_STOPPED){
} }
obj->i2c->EVENTS_STOPPED = 0; obj->i2c->EVENTS_STOPPED = 0;
} }
return length; return length;
} }
@ -219,7 +215,7 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
int status, errorResult; int status, errorResult;
obj->i2c->ADDRESS = (address>>1); obj->i2c->ADDRESS = (address>>1);
obj->i2c->SHORTS = 0; obj->i2c->SHORTS = 0;
obj->i2c->TASKS_STARTTX = 1; obj->i2c->TASKS_STARTTX = 1;
for (int i=0; i<length; i++) { for (int i=0; i<length; i++) {
status = i2c_do_write(obj, data[i]); status = i2c_do_write(obj, data[i]);
@ -264,7 +260,7 @@ int i2c_byte_write(i2c_t *obj, int data) {
obj->i2c->TASKS_STARTRX = 1; obj->i2c->TASKS_STARTRX = 1;
} }
else{ else{
obj->i2c->TASKS_STARTTX = 1; obj->i2c->TASKS_STARTTX = 1;
} }
} }
else{ else{

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h" #include "error.h"
@ -20,10 +21,10 @@ void pin_function(PinName pin, int function) {
} }
void pin_mode(PinName pin, PinMode mode) { void pin_mode(PinName pin, PinMode mode) {
if (pin == (PinName)NC) { return; } MBED_ASSERT(pin != (PinName)NC);
uint32_t pin_number = (uint32_t)pin; uint32_t pin_number = (uint32_t)pin;
NRF_GPIO->PIN_CNF[pin_number] &= ~GPIO_PIN_CNF_PULL_Msk; NRF_GPIO->PIN_CNF[pin_number] &= ~GPIO_PIN_CNF_PULL_Msk;
NRF_GPIO->PIN_CNF[pin_number] |= (mode<<GPIO_PIN_CNF_PULL_Pos); NRF_GPIO->PIN_CNF[pin_number] |= (mode << GPIO_PIN_CNF_PULL_Pos);
} }

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "pwmout_api.h" #include "pwmout_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
@ -43,8 +44,8 @@ static const PinMap PinMap_PWM[] = {
{p19, PWM_1, 1}, {p19, PWM_1, 1},
{p20, PWM_1, 1}, {p20, PWM_1, 1},
{p21, PWM_1, 1}, {p21, PWM_1, 1},
{p22, PWM_1, 1}, {p22, PWM_1, 1},
{p23, PWM_1, 1}, {p23, PWM_1, 1},
{p24, PWM_1, 1}, {p24, PWM_1, 1},
{p25, PWM_1, 1}, {p25, PWM_1, 1},
{p28, PWM_1, 1}, {p28, PWM_1, 1},
@ -54,7 +55,7 @@ static const PinMap PinMap_PWM[] = {
}; };
static NRF_TIMER_Type *Timers[1] = { static NRF_TIMER_Type *Timers[1] = {
NRF_TIMER2 NRF_TIMER2
}; };
uint8_t PWM_taken[NO_PWMS] = {0,0}; uint8_t PWM_taken[NO_PWMS] = {0,0};
@ -67,34 +68,34 @@ uint16_t ACTUAL_PULSE[NO_PWMS] = {0,0};
*/ */
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
void TIMER2_IRQHandler(void) void TIMER2_IRQHandler(void)
{ {
static uint16_t CCVal1 = 2501; static uint16_t CCVal1 = 2501;
static uint16_t CCVal2 = 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->INTENSET & TIMER_INTENSET_COMPARE1_Msk) != 0)){
NRF_TIMER2->CC[0] = CCVal1; NRF_TIMER2->CC[0] = CCVal1;
NRF_TIMER2->EVENTS_COMPARE[1] = 0; NRF_TIMER2->EVENTS_COMPARE[1] = 0;
NRF_TIMER2->CC[1] = (NRF_TIMER2->CC[1] + PERIOD[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->INTENSET & TIMER_INTENSET_COMPARE3_Msk) != 0)){
NRF_TIMER2->CC[2] = CCVal2; NRF_TIMER2->CC[2] = CCVal2;
NRF_TIMER2->EVENTS_COMPARE[3] = 0; NRF_TIMER2->EVENTS_COMPARE[3] = 0;
NRF_TIMER2->CC[3] = (NRF_TIMER2->CC[3] + PERIOD[1]); 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 #ifdef __cplusplus
} }
#endif #endif
/** @brief Function for initializing the Timer peripherals. /** @brief Function for initializing the Timer peripherals.
*/ */
void timer_init(uint8_t pwmChoice) void timer_init(uint8_t pwmChoice)
@ -102,10 +103,10 @@ void timer_init(uint8_t pwmChoice)
NRF_TIMER_Type *timer = Timers[pwmChoice/2]; NRF_TIMER_Type *timer = Timers[pwmChoice/2];
if(!(pwmChoice%2)){ if(!(pwmChoice%2)){
timer->POWER = 0; timer->POWER = 0;
timer->POWER = 1; timer->POWER = 1;
timer->MODE = TIMER_MODE_MODE_Timer; timer->MODE = TIMER_MODE_MODE_Timer;
timer->BITMODE = TIMER_BITMODE_BITMODE_16Bit << TIMER_BITMODE_BITMODE_Pos; timer->BITMODE = TIMER_BITMODE_BITMODE_16Bit << TIMER_BITMODE_BITMODE_Pos;
timer->PRESCALER = 7;//8us ticks timer->PRESCALER = 7;//8us ticks
} }
if(pwmChoice%2){ 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 */ /* Three NOPs are required to make sure configuration is written before setting tasks or getting events */
__NOP(); __NOP();
__NOP(); __NOP();
__NOP(); __NOP();
/* Launch the task to take the GPIOTE channel output to the desired level */ /* Launch the task to take the GPIOTE channel output to the desired level */
NRF_GPIOTE->TASKS_OUT[channel_number] = 1; 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. */ 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) | NRF_GPIOTE->CONFIG[channel_number] = (GPIOTE_CONFIG_MODE_Task << GPIOTE_CONFIG_MODE_Pos) |
((uint32_t)pin << GPIOTE_CONFIG_PSEL_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 */ /* Three NOPs are required to make sure configuration is written before setting tasks or getting events */
__NOP(); __NOP();
__NOP(); __NOP();
__NOP(); __NOP();
} }
/** @brief Function for initializing the Programmable Peripheral Interconnect peripheral. /** @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 // 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].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+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].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+1].EEP = (uint32_t)&timer->EVENTS_COMPARE[channel_number+1-(4*(channel_number/4))];
// Enable PPI channels. // Enable PPI channels.
NRF_PPI->CHEN |= (1 << channel_number) NRF_PPI->CHEN |= (1 << channel_number)
@ -213,10 +214,9 @@ void pwmout_init(pwmout_t* obj, PinName pin) {
// determine the channel // determine the channel
uint8_t pwmOutSuccess = 0; uint8_t pwmOutSuccess = 0;
PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM); PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
if (pwm == (PWMName)NC){ MBED_ASSERT(pwm != (PWMName)NC);
error("PwmOut pin mapping failed");
}
if(PWM_taken[(uint8_t)pwm]){ if(PWM_taken[(uint8_t)pwm]){
for(uint8_t i = 1; !pwmOutSuccess && (i<NO_PWMS) ;i++){ for(uint8_t i = 1; !pwmOutSuccess && (i<NO_PWMS) ;i++){
@ -265,14 +265,14 @@ void pwmout_write(pwmout_t* obj, float value) {
value = 0.0; value = 0.0;
} else if (value > 1.0f) { } else if (value > 1.0f) {
value = 1.0; value = 1.0;
} }
oldPulseWidth = ACTUAL_PULSE[obj->pwm]; oldPulseWidth = ACTUAL_PULSE[obj->pwm];
ACTUAL_PULSE[obj->pwm] = PULSE_WIDTH[obj->pwm] = value* PERIOD[obj->pwm]; ACTUAL_PULSE[obj->pwm] = PULSE_WIDTH[obj->pwm] = value* PERIOD[obj->pwm];
if(PULSE_WIDTH[obj->pwm] == 0){ if(PULSE_WIDTH[obj->pwm] == 0){
PULSE_WIDTH[obj->pwm] = 1; PULSE_WIDTH[obj->pwm] = 1;
setModulation(obj,0,0); setModulation(obj,0,0);
} }
else if(PULSE_WIDTH[obj->pwm] == PERIOD[obj->pwm]){ else if(PULSE_WIDTH[obj->pwm] == PERIOD[obj->pwm]){
PULSE_WIDTH[obj->pwm] = PERIOD[obj->pwm]-1; 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]) ){ else if( (oldPulseWidth == 0) || (oldPulseWidth == PERIOD[obj->pwm]) ){
setModulation(obj,1,oldPulseWidth == PERIOD[obj->pwm]); setModulation(obj,1,oldPulseWidth == PERIOD[obj->pwm]);
} }
} }
float pwmout_read(pwmout_t* obj) { float pwmout_read(pwmout_t* obj) {
@ -308,7 +308,7 @@ void pwmout_period_us(pwmout_t* obj, int us) {
} }
else{ else{
PERIOD[obj->pwm] =periodInTicks; PERIOD[obj->pwm] =periodInTicks;
} }
} }
void pwmout_pulsewidth(pwmout_t* obj, float seconds) { 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){ if(PULSE_WIDTH[obj->pwm] == 0){
PULSE_WIDTH[obj->pwm] = 1; PULSE_WIDTH[obj->pwm] = 1;
setModulation(obj,0,0); setModulation(obj,0,0);
} }
else if(PULSE_WIDTH[obj->pwm] == PERIOD[obj->pwm]){ else if(PULSE_WIDTH[obj->pwm] == PERIOD[obj->pwm]){
PULSE_WIDTH[obj->pwm] = PERIOD[obj->pwm]-1; 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]) ){ else if( (oldPulseWidth == 0) || (oldPulseWidth == PERIOD[obj->pwm]) ){
setModulation(obj,1,oldPulseWidth == PERIOD[obj->pwm]); setModulation(obj,1,oldPulseWidth == PERIOD[obj->pwm]);
} }
} }

View File

@ -16,11 +16,12 @@
// math.h required for floating point operations for baud rate calculation // math.h required for floating point operations for baud rate calculation
//#include <math.h> //#include <math.h>
#include <string.h> #include <string.h>
#include "mbed_assert.h"
#include "serial_api.h" #include "serial_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
/****************************************************************************** /******************************************************************************
* INITIALIZATION * 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_rx = (UARTName)pinmap_peripheral(rx, PinMap_UART_RX);
UARTName uart = (UARTName)pinmap_merge(uart_tx, uart_rx); UARTName uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
if ((int)uart == NC) { MBED_ASSERT((int)uart != NC);
error("Serial pinout mapping failed");
}
obj->uart = (NRF_UART_Type *)uart; obj->uart = (NRF_UART_Type *)uart;
//pin configurations -- //pin configurations --
//outputs //outputs
NRF_GPIO->DIR |= (1<<tx);//TX_PIN_NUMBER); NRF_GPIO->DIR |= (1<<tx);//TX_PIN_NUMBER);
NRF_GPIO->DIR |= (1<<RTS_PIN_NUMBER); NRF_GPIO->DIR |= (1<<RTS_PIN_NUMBER);
@ -118,9 +117,9 @@ void serial_baud(serial_t *obj, int baudrate) {
if(baudrate<=1200){ if(baudrate<=1200){
obj->uart->BAUDRATE = UART_BAUDRATE_BAUDRATE_Baud1200; obj->uart->BAUDRATE = UART_BAUDRATE_BAUDRATE_Baud1200;
return; return;
} }
for(int i=1;i<16;i++){ for(int i=1;i<16;i++){
if(baudrate<acceptedSpeeds[i][0]){ if(baudrate<acceptedSpeeds[i][0]){
obj->uart->BAUDRATE = acceptedSpeeds[i-1][1]; obj->uart->BAUDRATE = acceptedSpeeds[i-1][1];
return; 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 // 0: 1 stop bits, 1: 2 stop bits
// int parity_enable, parity_select; // int parity_enable, parity_select;
switch (parity) { switch (parity) {
case ParityNone: case ParityNone:
obj->uart->CONFIG = 0; obj->uart->CONFIG = 0;
break; break;
default: 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) { static inline void uart_irq(uint32_t iir, uint32_t index) {
SerialIrq irq_type; SerialIrq irq_type;
switch (iir) { switch (iir) {
case 1: case 1:
irq_type = TxIrq; irq_type = TxIrq;
break; break;
case 2: case 2:
irq_type = RxIrq; irq_type = RxIrq;
break; break;
default: return; default: return;
@ -165,7 +164,7 @@ static inline void uart_irq(uint32_t iir, uint32_t index) {
} }
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
void UART0_IRQHandler() void UART0_IRQHandler()
{ {
uint32_t irtype =0; uint32_t irtype =0;
@ -180,7 +179,7 @@ void UART0_IRQHandler()
} }
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id) { void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id) {
irq_handler = handler; irq_handler = handler;
serial_irq_ids[obj->index] = id; serial_irq_ids[obj->index] = id;

View File

@ -14,6 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
//#include <math.h> //#include <math.h>
#include "mbed_assert.h"
#include "spi_api.h" #include "spi_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
@ -22,7 +23,7 @@
static const PinMap PinMap_SPI_SCLK[] = { static const PinMap PinMap_SPI_SCLK[] = {
{SPI_PSELSCK0 , SPI_0, 0x01}, {SPI_PSELSCK0 , SPI_0, 0x01},
{SPI_PSELSCK1, SPI_1, 0x02}, {SPI_PSELSCK1, SPI_1, 0x02},
{SPIS_PSELSCK, SPIS, 0x03}, {SPIS_PSELSCK, SPIS, 0x03},
{NC , NC , 0} {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_data = (SPIName)pinmap_merge(spi_mosi, spi_miso);
SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel); SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
SPIName spi = (SPIName)pinmap_merge(spi_data, spi_cntl); SPIName spi = (SPIName)pinmap_merge(spi_data, spi_cntl);
//SPIName //SPIName
if(ssel==NC){ if(ssel==NC){
obj->spi = (NRF_SPI_Type*)spi; obj->spi = (NRF_SPI_Type*)spi;
obj->spis = (NRF_SPIS_Type*)NC; obj->spis = (NRF_SPIS_Type*)NC;
} }
else{ else{
obj->spi = (NRF_SPI_Type*)NC; obj->spi = (NRF_SPI_Type*)NC;
obj->spis = (NRF_SPIS_Type*)spi; obj->spis = (NRF_SPIS_Type*)spi;
} }
MBED_ASSERT((int)obj->spi != NC && (int)obj->spis != NC);
if ((int)obj->spi == NC && (int)obj->spis == NC) {
error("SPI pinout mapping failed"); // pin out the spi pins
}
// pin out the spi pins
if (ssel != NC) {//slave if (ssel != NC) {//slave
obj->spis->POWER=0; obj->spis->POWER=0;
obj->spis->POWER=1; 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->MAXRX=SPIS_MESSAGE_SIZE;
obj->spis->MAXTX=SPIS_MESSAGE_SIZE; obj->spis->MAXTX=SPIS_MESSAGE_SIZE;
obj->spis->TXDPTR = (uint32_t)&m_tx_buf[0]; 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<<SPIS_SHORTS_END_ACQUIRE_Pos); obj->spis->SHORTS = (SPIS_SHORTS_END_ACQUIRE_Enabled<<SPIS_SHORTS_END_ACQUIRE_Pos);
spi_format(obj, 8, 0, 1); // 8 bits, mode 0, slave spi_format(obj, 8, 0, 1); // 8 bits, mode 0, slave
@ -117,7 +116,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
obj->spi->POWER=0; obj->spi->POWER=0;
obj->spi->POWER=1; obj->spi->POWER=1;
//NRF_GPIO->DIR |= (1<<mosi); //NRF_GPIO->DIR |= (1<<mosi);
NRF_GPIO->PIN_CNF[mosi] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) NRF_GPIO->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_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
| (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_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->PSELMISO = miso;
obj->spi->EVENTS_READY = 0U; obj->spi->EVENTS_READY = 0U;
spi_format(obj, 8, 0, 0); // 8 bits, mode 0, master 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 //default to msb first
if(slave){ 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{ 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); spi_enable(obj,slave);
@ -212,7 +211,7 @@ void spi_frequency(spi_t *obj, int hz) {
spi_disable(obj,0); spi_disable(obj,0);
if(hz<250000) { //125Kbps 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 else if(hz<500000){//250Kbps
obj->spi->FREQUENCY = (uint32_t) SPI_FREQUENCY_FREQUENCY_K250; 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; obj->spi->FREQUENCY = (uint32_t) SPI_FREQUENCY_FREQUENCY_M4;
} }
else{//8Mbps else{//8Mbps
obj->spi->FREQUENCY = (uint32_t) SPI_FREQUENCY_FREQUENCY_M8; obj->spi->FREQUENCY = (uint32_t) SPI_FREQUENCY_FREQUENCY_M8;
} }
spi_enable(obj,0); spi_enable(obj,0);
@ -260,7 +259,7 @@ int spi_master_write(spi_t *obj, int value) {
return spi_read(obj); 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); // return (obj->spis->EVENTS_ACQUIRED==1);
//} //}
@ -268,12 +267,12 @@ int spi_slave_receive(spi_t *obj) {
return obj->spis->EVENTS_END; return obj->spis->EVENTS_END;
}; };
int spi_slave_read(spi_t *obj) { int spi_slave_read(spi_t *obj) {
return m_rx_buf[0]; return m_rx_buf[0];
} }
void spi_slave_write(spi_t *obj, int value) { void spi_slave_write(spi_t *obj, int value) {
m_tx_buf[0]= value & 0xFF; m_tx_buf[0]= value & 0xFF;
obj->spis->TASKS_RELEASE=1; obj->spis->TASKS_RELEASE=1;
obj->spis->EVENTS_ACQUIRED=0; obj->spis->EVENTS_ACQUIRED=0;
obj->spis->EVENTS_END=0; obj->spis->EVENTS_END=0;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "analogin_api.h" #include "analogin_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
@ -50,9 +50,8 @@ static const PinMap PinMap_ADC[] = {
void analogin_init(analogin_t *obj, PinName pin) { void analogin_init(analogin_t *obj, PinName pin) {
volatile uint32_t tmp; volatile uint32_t tmp;
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC); obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
if (obj->adc == (uint32_t)NC) { MBED_ASSERT(obj->adc != (ADCName)NC);
error("ADC pin mapping failed");
}
pinmap_pinout(pin, PinMap_ADC); pinmap_pinout(pin, PinMap_ADC);
__IO uint32_t *reg = (__IO uint32_t*)(LPC_IOCON_BASE + (pin & 0x1FF)); __IO uint32_t *reg = (__IO uint32_t*)(LPC_IOCON_BASE + (pin & 0x1FF));

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "gpio_api.h" #include "gpio_api.h"
#include "pinmap.h" #include "pinmap.h"
@ -26,6 +27,7 @@ static void gpio_enable(void) {
} }
uint32_t gpio_set(PinName pin) { uint32_t gpio_set(PinName pin) {
MBED_ASSERT(pin != (PinName)NC);
if (!gpio_enabled) if (!gpio_enabled)
gpio_enable(); gpio_enable();
@ -39,13 +41,14 @@ uint32_t gpio_set(PinName pin) {
} }
void gpio_init(gpio_t *obj, PinName pin) { void gpio_init(gpio_t *obj, PinName pin) {
if(pin == NC) return;
obj->pin = pin; obj->pin = pin;
if (pin == (PinName)NC)
return;
obj->mask = gpio_set(pin); obj->mask = gpio_set(pin);
unsigned int port = (unsigned int)(pin >> PORT_SHIFT); unsigned int port = (unsigned int)(pin >> PORT_SHIFT);
obj->reg_set = &LPC_GPIO_PORT->SET[port]; obj->reg_set = &LPC_GPIO_PORT->SET[port];
obj->reg_clr = &LPC_GPIO_PORT->CLR[port]; obj->reg_clr = &LPC_GPIO_PORT->CLR[port];
obj->reg_in = &LPC_GPIO_PORT->PIN[port]; obj->reg_in = &LPC_GPIO_PORT->PIN[port];
@ -57,8 +60,13 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
} }
void gpio_dir(gpio_t *obj, PinDirection direction) { void gpio_dir(gpio_t *obj, PinDirection direction) {
MBED_ASSERT(obj->pin != (PinName)NC);
switch (direction) { switch (direction) {
case PIN_INPUT : *obj->reg_dir &= ~obj->mask; break; case PIN_INPUT :
case PIN_OUTPUT: *obj->reg_dir |= obj->mask; break; *obj->reg_dir &= ~obj->mask;
break;
case PIN_OUTPUT:
*obj->reg_dir |= obj->mask;
break;
} }
} }

View File

@ -16,6 +16,8 @@
#ifndef MBED_GPIO_OBJECT_H #ifndef MBED_GPIO_OBJECT_H
#define MBED_GPIO_OBJECT_H #define MBED_GPIO_OBJECT_H
#include "mbed_assert.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -31,6 +33,7 @@ typedef struct {
} gpio_t; } gpio_t;
static inline void gpio_write(gpio_t *obj, int value) { static inline void gpio_write(gpio_t *obj, int value) {
MBED_ASSERT(obj->pin != (PinName)NC);
if (value) if (value)
*obj->reg_set = obj->mask; *obj->reg_set = obj->mask;
else else
@ -38,6 +41,7 @@ static inline void gpio_write(gpio_t *obj, int value) {
} }
static inline int gpio_read(gpio_t *obj) { static inline int gpio_read(gpio_t *obj) {
MBED_ASSERT(obj->pin != (PinName)NC);
return ((*obj->reg_in & obj->mask) ? 1 : 0); return ((*obj->reg_in & obj->mask) ? 1 : 0);
} }

View File

@ -13,11 +13,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "i2c_api.h" #include "i2c_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
#if DEVICE_I2C #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_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA);
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL); I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
obj->i2c = (LPC_I2C0_Type *)pinmap_merge(i2c_sda, i2c_scl); obj->i2c = (LPC_I2C0_Type *)pinmap_merge(i2c_sda, i2c_scl);
MBED_ASSERT((int)obj->i2c != NC);
if ((int)obj->i2c == NC) {
error("I2C pin mapping failed");
}
// enable power // enable power
i2c_power_enable(obj); i2c_power_enable(obj);

View File

@ -13,15 +13,12 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h" #include "error.h"
void pin_function(PinName pin, int function) { void pin_function(PinName pin, int function) {
if (pin == (uint32_t)NC) MBED_ASSERT(pin != (PinName)NC);
{
return;
}
__IO uint32_t *reg = (__IO uint32_t*)(LPC_IOCON_BASE + (pin & 0x1FF)); __IO uint32_t *reg = (__IO uint32_t*)(LPC_IOCON_BASE + (pin & 0x1FF));
// pin function bits: [2:0] -> 111 = (0x7) // pin function bits: [2:0] -> 111 = (0x7)
@ -29,11 +26,7 @@ void pin_function(PinName pin, int function) {
} }
void pin_mode(PinName pin, PinMode mode) { void pin_mode(PinName pin, PinMode mode) {
if (pin == (uint32_t)NC) MBED_ASSERT(pin != (PinName)NC);
{
return;
}
if ((pin == P0_4) || (pin == P0_5)) { if ((pin == P0_4) || (pin == P0_5)) {
// The true open-drain pins PIO0_4 and PIO0_5 can be configured for different I2C-bus speeds. // The true open-drain pins PIO0_4 and PIO0_5 can be configured for different I2C-bus speeds.
return; return;

View File

@ -15,6 +15,7 @@
*/ */
// math.h required for floating point operations for baud rate calculation // math.h required for floating point operations for baud rate calculation
#include "mbed_assert.h"
#include <math.h> #include <math.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
@ -22,7 +23,6 @@
#include "serial_api.h" #include "serial_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
#if DEVICE_SERIAL #if DEVICE_SERIAL
@ -82,9 +82,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
UARTName uart_tx = (UARTName)pinmap_peripheral(tx, PinMap_UART_TX); UARTName uart_tx = (UARTName)pinmap_peripheral(tx, PinMap_UART_TX);
UARTName uart_rx = (UARTName)pinmap_peripheral(rx, PinMap_UART_RX); UARTName uart_rx = (UARTName)pinmap_peripheral(rx, PinMap_UART_RX);
UARTName uart = (UARTName)pinmap_merge(uart_tx, uart_rx); UARTName uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
if ((int)uart == NC) { MBED_ASSERT((int)uart != NC);
error("Serial pinout mapping failed");
}
switch (uart) { switch (uart) {
case UART_0: case UART_0:
@ -252,17 +250,14 @@ void serial_baud(serial_t *obj, int baudrate) {
} }
void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) { void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) {
// 0: 1 stop bits, 1: 2 stop bits MBED_ASSERT((stop_bits == 1) || (stop_bits == 2)); // 0: 1 stop bits, 1: 2 stop bits
if (stop_bits != 1 && stop_bits != 2) {
error("Invalid stop bits specified");
}
stop_bits -= 1; stop_bits -= 1;
if (obj->index == 0) { if (obj->index == 0) {
// 0: 5 data bits ... 3: 8 data bits MBED_ASSERT((data_bits > 4) && (data_bits < 9)); // 0: 5 data bits ... 3: 8 data bits
if (data_bits < 5 || data_bits > 8) { MBED_ASSERT((parity == ParityNone) || (parity == ParityOdd) || (parity == ParityEven) ||
error("Invalid number of bits (%d) in serial format, should be 5..8", data_bits); (parity == ParityForced1) || (parity == ParityForced0));
}
data_bits -= 5; data_bits -= 5;
int parity_enable, parity_select; int parity_enable, parity_select;
@ -273,7 +268,6 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
case ParityForced1: parity_enable = 1; parity_select = 2; break; case ParityForced1: parity_enable = 1; parity_select = 2; break;
case ParityForced0: parity_enable = 1; parity_select = 3; break; case ParityForced0: parity_enable = 1; parity_select = 3; break;
default: default:
error("Invalid serial parity setting");
return; return;
} }
@ -284,18 +278,16 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
} }
else { else {
// 0: 7 data bits ... 2: 9 data bits // 0: 7 data bits ... 2: 9 data bits
if (data_bits < 7 || data_bits > 9) { MBED_ASSERT((data_bits > 6) && (data_bits < 10));
error("Invalid number of bits (%d) in serial format, should be 7..9", data_bits); MBED_ASSERT((parity == ParityNone) || (parity == ParityOdd) || (parity == ParityEven));
}
data_bits -= 7; data_bits -= 7;
int paritysel; int paritysel;
switch (parity) { switch (parity) {
case ParityNone: paritysel = 0; break; case ParityNone: paritysel = 0; break;
case ParityEven: paritysel = 2; break; case ParityEven: paritysel = 2; break;
case ParityOdd : paritysel = 3; break; case ParityOdd : paritysel = 3; break;
default: default:
error("Invalid serial parity setting");
return; return;
} }
obj->mini_uart->CFG = (data_bits << 2) obj->mini_uart->CFG = (data_bits << 2)

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include <math.h> #include <math.h>
#include "spi_api.h" #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); SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
obj->spi = (LPC_SSP0_Type*)pinmap_merge(spi_data, spi_cntl); obj->spi = (LPC_SSP0_Type*)pinmap_merge(spi_data, spi_cntl);
MBED_ASSERT((int)obj->spi != NC);
if ((int)obj->spi == NC) {
error("SPI pinout mapping failed");
}
// enable power and clocking // enable power and clocking
switch ((int)obj->spi) { 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) { void spi_format(spi_t *obj, int bits, int mode, int slave) {
ssp_disable(obj); ssp_disable(obj);
MBED_ASSERT(((bits >= 4) && (bits <= 16)) || ((mode >= 0) && (mode <= 3)));
if (!(bits >= 4 && bits <= 16) || !(mode >= 0 && mode <= 3)) {
error("SPI format error");
}
int polarity = (mode & 0x2) ? 1 : 0; int polarity = (mode & 0x2) ? 1 : 0;
int phase = (mode & 0x1) ? 1 : 0; int phase = (mode & 0x1) ? 1 : 0;

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "analogin_api.h" #include "analogin_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
@ -46,9 +47,7 @@ static const PinMap PinMap_ADC[] = {
void analogin_init(analogin_t *obj, PinName pin) { void analogin_init(analogin_t *obj, PinName pin) {
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC); obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
if (obj->adc == (ADCName)NC) { MBED_ASSERT(obj->adc != (ADCName)NC);
error("ADC pin mapping failed");
}
// Power up ADC // Power up ADC
LPC_SYSCON->PDRUNCFG &= ~ (1 << 4); LPC_SYSCON->PDRUNCFG &= ~ (1 << 4);

View File

@ -13,10 +13,12 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "gpio_api.h" #include "gpio_api.h"
#include "pinmap.h" #include "pinmap.h"
uint32_t gpio_set(PinName pin) { uint32_t gpio_set(PinName pin) {
MBED_ASSERT(pin != (PinName)NC);
int f = ((pin == P0_0) || int f = ((pin == P0_0) ||
(pin == P0_10) || (pin == P0_10) ||
(pin == P0_11) || (pin == P0_11) ||
@ -31,9 +33,10 @@ uint32_t gpio_set(PinName pin) {
} }
void gpio_init(gpio_t *obj, PinName pin) { void gpio_init(gpio_t *obj, PinName pin) {
if(pin == NC) return;
obj->pin = pin; obj->pin = pin;
if (pin == (PinName)NC)
return;
obj->mask = gpio_set(pin); obj->mask = gpio_set(pin);
unsigned int port = (unsigned int)pin >> PORT_SHIFT; unsigned int port = (unsigned int)pin >> PORT_SHIFT;
@ -49,8 +52,13 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
} }
void gpio_dir(gpio_t *obj, PinDirection direction) { void gpio_dir(gpio_t *obj, PinDirection direction) {
MBED_ASSERT(obj->pin != (PinName)NC);
switch (direction) { switch (direction) {
case PIN_INPUT : *obj->reg_dir &= ~obj->mask; break; case PIN_INPUT :
case PIN_OUTPUT: *obj->reg_dir |= obj->mask; break; *obj->reg_dir &= ~obj->mask;
break;
case PIN_OUTPUT:
*obj->reg_dir |= obj->mask;
break;
} }
} }

View File

@ -16,6 +16,8 @@
#ifndef MBED_GPIO_OBJECT_H #ifndef MBED_GPIO_OBJECT_H
#define MBED_GPIO_OBJECT_H #define MBED_GPIO_OBJECT_H
#include "mbed_assert.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -31,6 +33,7 @@ typedef struct {
} gpio_t; } gpio_t;
static inline void gpio_write(gpio_t *obj, int value) { static inline void gpio_write(gpio_t *obj, int value) {
MBED_ASSERT(obj->pin != (PinName)NC);
if (value) if (value)
*obj->reg_set = obj->mask; *obj->reg_set = obj->mask;
else else
@ -38,6 +41,7 @@ static inline void gpio_write(gpio_t *obj, int value) {
} }
static inline int gpio_read(gpio_t *obj) { static inline int gpio_read(gpio_t *obj) {
MBED_ASSERT(obj->pin != (PinName)NC);
return ((*obj->reg_in & obj->mask) ? 1 : 0); return ((*obj->reg_in & obj->mask) ? 1 : 0);
} }

View File

@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "i2c_api.h" #include "i2c_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
static const PinMap PinMap_I2C_SDA[] = { static const PinMap PinMap_I2C_SDA[] = {
{P0_5, I2C_0, 1}, {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_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA);
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL); I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
obj->i2c = (LPC_I2C_Type *)pinmap_merge(i2c_sda, i2c_scl); obj->i2c = (LPC_I2C_Type *)pinmap_merge(i2c_sda, i2c_scl);
MBED_ASSERT((int)obj->i2c != NC);
if ((int)obj->i2c == NC) {
error("I2C pin mapping failed");
}
// enable power // enable power
i2c_power_enable(obj); i2c_power_enable(obj);

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h" #include "error.h"
@ -20,27 +21,27 @@
#define LPC_IOCON1_BASE (LPC_IOCON_BASE + 0x60) #define LPC_IOCON1_BASE (LPC_IOCON_BASE + 0x60)
void pin_function(PinName pin, int function) { void pin_function(PinName pin, int function) {
MBED_ASSERT(pin != (PinName)NC);
if (pin == (PinName)NC) return; if (pin == (PinName)NC) return;
uint32_t pin_number = (uint32_t)pin; uint32_t pin_number = (uint32_t)pin;
__IO uint32_t *reg = (pin_number < 32) ? __IO uint32_t *reg = (pin_number < 32) ?
(__IO uint32_t*)(LPC_IOCON0_BASE + 4 * pin_number) : (__IO uint32_t*)(LPC_IOCON0_BASE + 4 * pin_number) :
(__IO uint32_t*)(LPC_IOCON1_BASE + 4 * (pin_number - 32)); (__IO uint32_t*)(LPC_IOCON1_BASE + 4 * (pin_number - 32));
// pin function bits: [2:0] -> 111 = (0x7) // pin function bits: [2:0] -> 111 = (0x7)
*reg = (*reg & ~0x7) | (function & 0x7); *reg = (*reg & ~0x7) | (function & 0x7);
} }
void pin_mode(PinName pin, PinMode mode) { void pin_mode(PinName pin, PinMode mode) {
if (pin == (PinName)NC) { return; } MBED_ASSERT(pin != (PinName)NC);
uint32_t pin_number = (uint32_t)pin; uint32_t pin_number = (uint32_t)pin;
uint32_t drain = ((uint32_t) mode & (uint32_t) OpenDrain) >> 2; uint32_t drain = ((uint32_t) mode & (uint32_t) OpenDrain) >> 2;
__IO uint32_t *reg = (pin_number < 32) ? __IO uint32_t *reg = (pin_number < 32) ?
(__IO uint32_t*)(LPC_IOCON0_BASE + 4 * pin_number) : (__IO uint32_t*)(LPC_IOCON0_BASE + 4 * pin_number) :
(__IO uint32_t*)(LPC_IOCON1_BASE + 4 * (pin_number - 32)); (__IO uint32_t*)(LPC_IOCON1_BASE + 4 * (pin_number - 32));
uint32_t tmp = *reg; uint32_t tmp = *reg;
// pin mode bits: [4:3] -> 11000 = (0x3 << 3) // pin mode bits: [4:3] -> 11000 = (0x3 << 3)

View File

@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "pwmout_api.h" #include "pwmout_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
#define TCR_CNT_EN 0x00000001 #define TCR_CNT_EN 0x00000001
#define TCR_RESET 0x00000002 #define TCR_RESET 0x00000002
@ -69,9 +69,8 @@ static LPC_CTxxBx_Type *Timers[4] = {
void pwmout_init(pwmout_t* obj, PinName pin) { void pwmout_init(pwmout_t* obj, PinName pin) {
// determine the channel // determine the channel
PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM); PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
if (pwm == (PWMName)NC) MBED_ASSERT(pwm != (PWMName)NC);
error("PwmOut pin mapping failed");
obj->pwm = pwm; obj->pwm = pwm;
// Timer registers // Timer registers
@ -143,7 +142,7 @@ void pwmout_period_us(pwmout_t* obj, int us) {
// for 16bit timer, set prescaler to avoid overflow // for 16bit timer, set prescaler to avoid overflow
if (timer == LPC_CT16B0 || timer == LPC_CT16B1) { 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; timer->PR = high_period_ticks;
period_ticks /= (high_period_ticks + 1); period_ticks /= (high_period_ticks + 1);
} }

View File

@ -21,7 +21,6 @@
#include "serial_api.h" #include "serial_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
/****************************************************************************** /******************************************************************************
* INITIALIZATION * 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_tx = (UARTName)pinmap_peripheral(tx, PinMap_UART_TX);
UARTName uart_rx = (UARTName)pinmap_peripheral(rx, PinMap_UART_RX); UARTName uart_rx = (UARTName)pinmap_peripheral(rx, PinMap_UART_RX);
UARTName uart = (UARTName)pinmap_merge(uart_tx, uart_rx); UARTName uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
if ((int)uart == NC) { MBED_ASSERT((int)uart != NC);
error("Serial pinout mapping failed");
}
obj->uart = (LPC_USART_Type *)uart; obj->uart = (LPC_USART_Type *)uart;
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<12); LPC_SYSCON->SYSAHBCLKCTRL |= (1<<12);
@ -188,16 +185,12 @@ void serial_baud(serial_t *obj, int baudrate) {
} }
void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) { void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) {
// 0: 1 stop bits, 1: 2 stop bits MBED_ASSERT((stop_bits == 1) || (stop_bits == 2)); // 0: 1 stop bits, 1: 2 stop bits
if (stop_bits != 1 && stop_bits != 2) { MBED_ASSERT((data_bits > 4) && (data_bits < 9)); // 0: 5 data bits ... 3: 8 data bits
error("Invalid stop bits specified"); MBED_ASSERT((parity == ParityNone) || (parity == ParityOdd) || (parity == ParityEven) ||
} (parity == ParityForced1) || (parity == ParityForced0));
stop_bits -= 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; data_bits -= 5;
int parity_enable, parity_select; int parity_enable, parity_select;
@ -208,8 +201,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 ParityForced1: parity_enable = 1; parity_select = 2; break;
case ParityForced0: parity_enable = 1; parity_select = 3; break; case ParityForced0: parity_enable = 1; parity_select = 3; break;
default: default:
error("Invalid serial parity setting"); break;
return;
} }
obj->uart->LCR = data_bits << 0 obj->uart->LCR = data_bits << 0

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include <math.h> #include <math.h>
#include "spi_api.h" #include "spi_api.h"
#include "cmsis.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); SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
obj->spi = (LPC_SSPx_Type*)pinmap_merge(spi_data, spi_cntl); obj->spi = (LPC_SSPx_Type*)pinmap_merge(spi_data, spi_cntl);
MBED_ASSERT((int)obj->spi != NC);
if ((int)obj->spi == NC) {
error("SPI pinout mapping failed");
}
// enable power and clocking // enable power and clocking
switch ((int)obj->spi) { 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_free(spi_t *obj) {}
void spi_format(spi_t *obj, int bits, int mode, int slave) { void spi_format(spi_t *obj, int bits, int mode, int slave) {
MBED_ASSERT((bits >= 4 && bits <= 16) || (mode >= 0 && mode <= 3));
ssp_disable(obj); ssp_disable(obj);
if (!(bits >= 4 && bits <= 16) || !(mode >= 0 && mode <= 3)) {
error("SPI format error");
}
int polarity = (mode & 0x2) ? 1 : 0; int polarity = (mode & 0x2) ? 1 : 0;
int phase = (mode & 0x1) ? 1 : 0; int phase = (mode & 0x1) ? 1 : 0;

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "analogin_api.h" #include "analogin_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.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) { void analogin_init(analogin_t *obj, PinName pin) {
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC); obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
if (obj->adc == (uint32_t)NC) { MBED_ASSERT(obj->adc != (uint32_t)NC);
error("ADC pin mapping failed");
return;
}
// Power up ADC // Power up ADC
LPC_SYSCON->PDRUNCFG &= ~ (1 << 4); LPC_SYSCON->PDRUNCFG &= ~ (1 << 4);

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "gpio_api.h" #include "gpio_api.h"
#include "pinmap.h" #include "pinmap.h"
#include "reserved_pins.h" #include "reserved_pins.h"
@ -20,24 +21,26 @@
static const PinName reserved_pins[] = TARGET_RESERVED_PINS; static const PinName reserved_pins[] = TARGET_RESERVED_PINS;
uint32_t gpio_set(PinName pin) { uint32_t gpio_set(PinName pin) {
MBED_ASSERT(pin != (PinName)NC);
// PIO default value of following ports are not same as others // PIO default value of following ports are not same as others
unsigned i; unsigned i;
int f = 0; int f = 0;
for (i = 0; i < sizeof(reserved_pins) / sizeof(PinName); i ++) for (i = 0; i < sizeof(reserved_pins) / sizeof(PinName); i ++) {
if (pin == reserved_pins[i]) { if (pin == reserved_pins[i]) {
f = 1; f = 1;
break; break;
} }
}
pin_function(pin, f); pin_function(pin, f);
return ((pin & 0x0F00) >> 8); return ((pin & 0x0F00) >> 8);
} }
void gpio_init(gpio_t *obj, PinName pin) { void gpio_init(gpio_t *obj, PinName pin) {
if(pin == NC) return;
obj->pin = pin; obj->pin = pin;
if (pin == (PinName)NC)
return;
LPC_GPIO_TypeDef *port_reg = ((LPC_GPIO_TypeDef *) (LPC_GPIO0_BASE + (((pin & 0xF000) >> PORT_SHIFT) * 0x10000))); LPC_GPIO_TypeDef *port_reg = ((LPC_GPIO_TypeDef *) (LPC_GPIO0_BASE + (((pin & 0xF000) >> PORT_SHIFT) * 0x10000)));
obj->reg_mask_read = &port_reg->MASKED_ACCESS[1 << gpio_set(pin)]; obj->reg_mask_read = &port_reg->MASKED_ACCESS[1 << gpio_set(pin)];
@ -50,9 +53,14 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
} }
void gpio_dir(gpio_t *obj, PinDirection direction) { void gpio_dir(gpio_t *obj, PinDirection direction) {
MBED_ASSERT(obj->pin != (PinName)NC);
int pin_number = ((obj->pin & 0x0F00) >> 8); int pin_number = ((obj->pin & 0x0F00) >> 8);
switch (direction) { switch (direction) {
case PIN_INPUT : *obj->reg_dir &= ~(1 << pin_number); break; case PIN_INPUT :
case PIN_OUTPUT: *obj->reg_dir |= (1 << pin_number); break; *obj->reg_dir &= ~(1 << pin_number);
break;
case PIN_OUTPUT:
*obj->reg_dir |= (1 << pin_number);
break;
} }
} }

View File

@ -16,6 +16,8 @@
#ifndef MBED_GPIO_OBJECT_H #ifndef MBED_GPIO_OBJECT_H
#define MBED_GPIO_OBJECT_H #define MBED_GPIO_OBJECT_H
#include "mbed_assert.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -28,6 +30,7 @@ typedef struct {
} gpio_t; } gpio_t;
static inline void gpio_write(gpio_t *obj, int value) { static inline void gpio_write(gpio_t *obj, int value) {
MBED_ASSERT(obj->pin != (PinName)NC);
uint32_t pin_number = ((obj->pin & 0x0F00) >> 8); uint32_t pin_number = ((obj->pin & 0x0F00) >> 8);
if (value) if (value)
*obj->reg_write |= (1 << pin_number); *obj->reg_write |= (1 << pin_number);
@ -36,6 +39,7 @@ static inline void gpio_write(gpio_t *obj, int value) {
} }
static inline int gpio_read(gpio_t *obj) { static inline int gpio_read(gpio_t *obj) {
MBED_ASSERT(obj->pin != (PinName)NC);
return ((*obj->reg_mask_read) ? 1 : 0); return ((*obj->reg_mask_read) ? 1 : 0);
} }

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "i2c_api.h" #include "i2c_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.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_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA);
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL); I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
obj->i2c = (LPC_I2C_TypeDef *)pinmap_merge(i2c_sda, i2c_scl); obj->i2c = (LPC_I2C_TypeDef *)pinmap_merge(i2c_sda, i2c_scl);
MBED_ASSERT((int)obj->i2c != NC);
if ((int)obj->i2c == NC) {
error("I2C pin mapping failed");
}
// enable power // enable power
i2c_power_enable(obj); i2c_power_enable(obj);

View File

@ -13,12 +13,12 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h" #include "error.h"
void pin_function(PinName pin, int function) { void pin_function(PinName pin, int function) {
if (pin == (uint32_t)NC) return; MBED_ASSERT(pin != (PinName)NC);
uint32_t offset = (uint32_t)pin & 0xff; uint32_t offset = (uint32_t)pin & 0xff;
__IO uint32_t *reg = (__IO uint32_t*)(LPC_IOCON_BASE + offset); __IO uint32_t *reg = (__IO uint32_t*)(LPC_IOCON_BASE + offset);
@ -27,10 +27,9 @@ void pin_function(PinName pin, int function) {
} }
void pin_mode(PinName pin, PinMode mode) { void pin_mode(PinName pin, PinMode mode) {
if (pin == (uint32_t)NC) { return; } MBED_ASSERT(pin != (PinName)NC);
uint32_t offset = (uint32_t)pin & 0xff; uint32_t offset = (uint32_t)pin & 0xff;
uint32_t drain = ((uint32_t) mode & (uint32_t) OpenDrain) >> 2; uint32_t drain = ((uint32_t)mode & (uint32_t)OpenDrain) >> 2;
__IO uint32_t *reg = (__IO uint32_t*)(LPC_IOCON_BASE + offset); __IO uint32_t *reg = (__IO uint32_t*)(LPC_IOCON_BASE + offset);
uint32_t tmp = *reg; uint32_t tmp = *reg;

View File

@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "pwmout_api.h" #include "pwmout_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
#define TCR_CNT_EN 0x00000001 #define TCR_CNT_EN 0x00000001
#define TCR_RESET 0x00000002 #define TCR_RESET 0x00000002
@ -64,9 +64,8 @@ static LPC_TMR_TypeDef *Timers[3] = {
void pwmout_init(pwmout_t* obj, PinName pin) { void pwmout_init(pwmout_t* obj, PinName pin) {
// determine the channel // determine the channel
PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM); PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
if (pwm == (uint32_t)NC) MBED_ASSERT(pwm != (uint32_t)NC);
error("PwmOut pin mapping failed");
obj->pwm = pwm; obj->pwm = pwm;
// Timer registers // Timer registers

View File

@ -14,6 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
// math.h required for floating point operations for baud rate calculation // math.h required for floating point operations for baud rate calculation
#include "mbed_assert.h"
#include <math.h> #include <math.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
@ -21,7 +22,6 @@
#include "serial_api.h" #include "serial_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
/****************************************************************************** /******************************************************************************
* INITIALIZATION * 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_tx = (UARTName)pinmap_peripheral(tx, PinMap_UART_TX);
UARTName uart_rx = (UARTName)pinmap_peripheral(rx, PinMap_UART_RX); UARTName uart_rx = (UARTName)pinmap_peripheral(rx, PinMap_UART_RX);
UARTName uart = (UARTName)pinmap_merge(uart_tx, uart_rx); UARTName uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
if ((int)uart == NC) { MBED_ASSERT((int)uart != NC);
error("Serial pinout mapping failed");
}
obj->uart = (LPC_UART_TypeDef *)uart; obj->uart = (LPC_UART_TypeDef *)uart;
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<12); LPC_SYSCON->SYSAHBCLKCTRL |= (1<<12);
@ -183,16 +181,12 @@ void serial_baud(serial_t *obj, int baudrate) {
} }
void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) { void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) {
// 0: 1 stop bits, 1: 2 stop bits MBED_ASSERT((stop_bits == 1) || (stop_bits == 2)); // 0: 1 stop bits, 1: 2 stop bits
if (stop_bits != 1 && stop_bits != 2) { MBED_ASSERT((data_bits > 4) && (data_bits < 9)); // 0: 5 data bits ... 3: 8 data bits
error("Invalid stop bits specified"); MBED_ASSERT((parity == ParityNone) || (parity == ParityOdd) || (parity == ParityEven) ||
} (parity == ParityForced1) || (parity == ParityForced0));
stop_bits -= 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; data_bits -= 5;
int parity_enable, parity_select; int parity_enable, parity_select;
@ -203,8 +197,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 ParityForced1: parity_enable = 1; parity_select = 2; break;
case ParityForced0: parity_enable = 1; parity_select = 3; break; case ParityForced0: parity_enable = 1; parity_select = 3; break;
default: default:
error("Invalid serial parity setting"); break;
return;
} }
obj->uart->LCR = data_bits << 0 obj->uart->LCR = data_bits << 0

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include <math.h> #include <math.h>
#include "spi_api.h" #include "spi_api.h"
#include "cmsis.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); SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
obj->spi = (LPC_SSP_TypeDef*)pinmap_merge(spi_data, spi_cntl); obj->spi = (LPC_SSP_TypeDef*)pinmap_merge(spi_data, spi_cntl);
MBED_ASSERT((int)obj->spi != NC);
if ((int)obj->spi == NC) {
error("SPI pinout mapping failed");
}
// enable power and clocking // enable power and clocking
switch ((int)obj->spi) { 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_free(spi_t *obj) {}
void spi_format(spi_t *obj, int bits, int mode, int slave) { void spi_format(spi_t *obj, int bits, int mode, int slave) {
MBED_ASSERT((bits >= 4 && bits <= 16) || (mode >= 0 && mode <= 3));
ssp_disable(obj); ssp_disable(obj);
if (!(bits >= 4 && bits <= 16) || !(mode >= 0 && mode <= 3)) {
error("SPI format error");
}
int polarity = (mode & 0x2) ? 1 : 0; int polarity = (mode & 0x2) ? 1 : 0;
int phase = (mode & 0x1) ? 1 : 0; int phase = (mode & 0x1) ? 1 : 0;

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "analogin_api.h" #include "analogin_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
@ -46,9 +47,7 @@ static const PinMap PinMap_ADC[] = {
void analogin_init(analogin_t *obj, PinName pin) { void analogin_init(analogin_t *obj, PinName pin) {
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC); obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
if (obj->adc == (uint32_t)NC) { MBED_ASSERT(obj->adc != (ADCName)NC);
error("ADC pin mapping failed");
}
// Power up ADC // Power up ADC
LPC_SYSCON->PDRUNCFG &= ~ (1 << 4); LPC_SYSCON->PDRUNCFG &= ~ (1 << 4);

View File

@ -13,24 +13,24 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "gpio_api.h" #include "gpio_api.h"
#include "pinmap.h" #include "pinmap.h"
uint32_t gpio_set(PinName pin) { uint32_t gpio_set(PinName pin) {
int f = ((pin == P0_11) || MBED_ASSERT(pin != (PinName)NC);
(pin == P0_12) || int f = ((pin == P0_11) || (pin == P0_12) ||
(pin == P0_13) || (pin == P0_13) || (pin == P0_14)) ? (1) : (0);
(pin == P0_14)) ? (1) : (0);
pin_function(pin, f); pin_function(pin, f);
return (1 << ((int)pin & 0x1F)); return (1 << ((int)pin & 0x1F));
} }
void gpio_init(gpio_t *obj, PinName pin) { void gpio_init(gpio_t *obj, PinName pin) {
if(pin == NC) return;
obj->pin = pin; obj->pin = pin;
if (pin == (PinName)NC)
return;
obj->mask = gpio_set(pin); obj->mask = gpio_set(pin);
unsigned int port = (unsigned int)pin >> PORT_SHIFT; unsigned int port = (unsigned int)pin >> PORT_SHIFT;
@ -46,8 +46,13 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
} }
void gpio_dir(gpio_t *obj, PinDirection direction) { void gpio_dir(gpio_t *obj, PinDirection direction) {
MBED_ASSERT(obj->pin != (PinName)NC);
switch (direction) { switch (direction) {
case PIN_INPUT : *obj->reg_dir &= ~obj->mask; break; case PIN_INPUT :
case PIN_OUTPUT: *obj->reg_dir |= obj->mask; break; *obj->reg_dir &= ~obj->mask;
break;
case PIN_OUTPUT:
*obj->reg_dir |= obj->mask;
break;
} }
} }

View File

@ -16,6 +16,8 @@
#ifndef MBED_GPIO_OBJECT_H #ifndef MBED_GPIO_OBJECT_H
#define MBED_GPIO_OBJECT_H #define MBED_GPIO_OBJECT_H
#include "mbed_assert.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -31,6 +33,7 @@ typedef struct {
} gpio_t; } gpio_t;
static inline void gpio_write(gpio_t *obj, int value) { static inline void gpio_write(gpio_t *obj, int value) {
MBED_ASSERT(obj->pin != (PinName)NC);
if (value) if (value)
*obj->reg_set = obj->mask; *obj->reg_set = obj->mask;
else else
@ -38,6 +41,7 @@ static inline void gpio_write(gpio_t *obj, int value) {
} }
static inline int gpio_read(gpio_t *obj) { static inline int gpio_read(gpio_t *obj) {
MBED_ASSERT(obj->pin != (PinName)NC);
return ((*obj->reg_in & obj->mask) ? 1 : 0); return ((*obj->reg_in & obj->mask) ? 1 : 0);
} }

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "i2c_api.h" #include "i2c_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.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_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA);
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL); I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
obj->i2c = (LPC_I2C_Type *)pinmap_merge(i2c_sda, i2c_scl); obj->i2c = (LPC_I2C_Type *)pinmap_merge(i2c_sda, i2c_scl);
MBED_ASSERT((int)obj->i2c != NC);
if ((int)obj->i2c == NC) {
error("I2C pin mapping failed");
}
// enable power // enable power
i2c_power_enable(obj); i2c_power_enable(obj);

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h" #include "error.h"
@ -20,7 +21,7 @@
#define LPC_IOCON1_BASE (LPC_IOCON_BASE + 0x60) #define LPC_IOCON1_BASE (LPC_IOCON_BASE + 0x60)
void pin_function(PinName pin, int function) { void pin_function(PinName pin, int function) {
if (pin == (uint32_t)NC) return; MBED_ASSERT(pin != (PinName)NC);
uint32_t pin_number = (uint32_t)pin; uint32_t pin_number = (uint32_t)pin;
@ -33,7 +34,7 @@ void pin_function(PinName pin, int function) {
} }
void pin_mode(PinName pin, PinMode mode) { void pin_mode(PinName pin, PinMode mode) {
if (pin == (uint32_t)NC) { return; } MBED_ASSERT(pin != (PinName)NC);
uint32_t pin_number = (uint32_t)pin; uint32_t pin_number = (uint32_t)pin;
uint32_t drain = ((uint32_t) mode & (uint32_t) OpenDrain) >> 2; uint32_t drain = ((uint32_t) mode & (uint32_t) OpenDrain) >> 2;

View File

@ -13,12 +13,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "pwmout_api.h" #include "pwmout_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
#define TCR_CNT_EN 0x00000001 #define TCR_CNT_EN 0x00000001
#define TCR_RESET 0x00000002 #define TCR_RESET 0x00000002
@ -73,9 +71,8 @@ static unsigned int pwm_clock_mhz;
void pwmout_init(pwmout_t* obj, PinName pin) { void pwmout_init(pwmout_t* obj, PinName pin) {
// determine the channel // determine the channel
PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM); PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
if (pwm == (uint32_t)NC) MBED_ASSERT(pwm != (uint32_t)NC);
error("PwmOut pin mapping failed");
obj->pwm = pwm; obj->pwm = pwm;
// Timer registers // Timer registers

View File

@ -14,6 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
// math.h required for floating point operations for baud rate calculation // math.h required for floating point operations for baud rate calculation
#include "mbed_assert.h"
#include <math.h> #include <math.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
@ -21,7 +22,6 @@
#include "serial_api.h" #include "serial_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
/****************************************************************************** /******************************************************************************
* INITIALIZATION * 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_tx = (UARTName)pinmap_peripheral(tx, PinMap_UART_TX);
UARTName uart_rx = (UARTName)pinmap_peripheral(rx, PinMap_UART_RX); UARTName uart_rx = (UARTName)pinmap_peripheral(rx, PinMap_UART_RX);
UARTName uart = (UARTName)pinmap_merge(uart_tx, uart_rx); UARTName uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
if ((int)uart == NC) { MBED_ASSERT((int)uart != NC);
error("Serial pinout mapping failed");
}
obj->uart = (LPC_USART_Type *)uart; obj->uart = (LPC_USART_Type *)uart;
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<12); LPC_SYSCON->SYSAHBCLKCTRL |= (1<<12);
@ -186,16 +184,12 @@ void serial_baud(serial_t *obj, int baudrate) {
} }
void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) { void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) {
// 0: 1 stop bits, 1: 2 stop bits MBED_ASSERT((stop_bits == 1) || (stop_bits == 2)); // 0: 1 stop bits, 1: 2 stop bits
if (stop_bits != 1 && stop_bits != 2) { MBED_ASSERT((data_bits > 4) && (data_bits < 9)); // 0: 5 data bits ... 3: 8 data bits
error("Invalid stop bits specified"); MBED_ASSERT((parity == ParityNone) || (parity == ParityOdd) || (parity == ParityEven) ||
} (parity == ParityForced1) || (parity == ParityForced0));
stop_bits -= 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; data_bits -= 5;
int parity_enable, parity_select; int parity_enable, parity_select;
@ -206,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 ParityForced1: parity_enable = 1; parity_select = 2; break;
case ParityForced0: parity_enable = 1; parity_select = 3; break; case ParityForced0: parity_enable = 1; parity_select = 3; break;
default: default:
error("Invalid serial parity setting"); break;
return;
} }
obj->uart->LCR = data_bits << 0 obj->uart->LCR = data_bits << 0

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include <math.h> #include <math.h>
#include "spi_api.h" #include "spi_api.h"
#include "cmsis.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); SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
obj->spi = (LPC_SSPx_Type*)pinmap_merge(spi_data, spi_cntl); obj->spi = (LPC_SSPx_Type*)pinmap_merge(spi_data, spi_cntl);
MBED_ASSERT((int)obj->spi != NC);
if ((int)obj->spi == NC) {
error("SPI pinout mapping failed");
}
// enable power and clocking // enable power and clocking
switch ((int)obj->spi) { 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) { void spi_format(spi_t *obj, int bits, int mode, int slave) {
ssp_disable(obj); ssp_disable(obj);
MBED_ASSERT((bits >= 4 && bits <= 16) || (mode >= 0 && mode <= 3));
if (!(bits >= 4 && bits <= 16) || !(mode >= 0 && mode <= 3)) {
error("SPI format error");
}
int polarity = (mode & 0x2) ? 1 : 0; int polarity = (mode & 0x2) ? 1 : 0;
int phase = (mode & 0x1) ? 1 : 0; int phase = (mode & 0x1) ? 1 : 0;

View File

@ -13,11 +13,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "analogin_api.h" #include "analogin_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
#define ANALOGIN_MEDIAN_FILTER 1 #define ANALOGIN_MEDIAN_FILTER 1
@ -55,9 +54,8 @@ static const PinMap PinMap_ADC[] = {
void analogin_init(analogin_t *obj, PinName pin) { void analogin_init(analogin_t *obj, PinName pin) {
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC); obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
if (obj->adc == (uint32_t)NC) { MBED_ASSERT(obj->adc != (ADCName)NC);
error("ADC pin mapping failed");
}
uint32_t port = (pin >> 5); uint32_t port = (pin >> 5);
// enable clock for GPIOx // enable clock for GPIOx
LPC_SYSCON->SYSAHBCLKCTRL0 |= (1UL << (14 + port)); LPC_SYSCON->SYSAHBCLKCTRL0 |= (1UL << (14 + port));

View File

@ -13,15 +13,13 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "analogout_api.h" #include "analogout_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
void analogout_init(dac_t *obj, PinName pin) { void analogout_init(dac_t *obj, PinName pin) {
if (pin != P0_12) { MBED_ASSERT(pin == P0_12);
error("DAC pin mapping failed");
}
LPC_SYSCON->SYSAHBCLKCTRL0 |= (1 << 29); LPC_SYSCON->SYSAHBCLKCTRL0 |= (1 << 29);
LPC_SYSCON->PDRUNCFG &= ~(1 << 12); LPC_SYSCON->PDRUNCFG &= ~(1 << 12);

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "gpio_api.h" #include "gpio_api.h"
#include "pinmap.h" #include "pinmap.h"
@ -26,7 +27,7 @@ static void gpio_enable(void) {
} }
uint32_t gpio_set(PinName pin) { uint32_t gpio_set(PinName pin) {
MBED_ASSERT(pin != (PinName)NC);
if (!gpio_enabled) if (!gpio_enabled)
gpio_enable(); gpio_enable();
@ -34,9 +35,10 @@ uint32_t gpio_set(PinName pin) {
} }
void gpio_init(gpio_t *obj, PinName pin) { void gpio_init(gpio_t *obj, PinName pin) {
if(pin == NC) return;
obj->pin = pin; obj->pin = pin;
if (pin == (PinName)NC)
return;
obj->mask = gpio_set(pin); obj->mask = gpio_set(pin);
unsigned int port = (unsigned int)(pin >> 5); unsigned int port = (unsigned int)(pin >> 5);
@ -52,8 +54,13 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
} }
void gpio_dir(gpio_t *obj, PinDirection direction) { void gpio_dir(gpio_t *obj, PinDirection direction) {
MBED_ASSERT(obj->pin != (PinName)NC);
switch (direction) { switch (direction) {
case PIN_INPUT : *obj->reg_dir &= ~obj->mask; break; case PIN_INPUT :
case PIN_OUTPUT: *obj->reg_dir |= obj->mask; break; *obj->reg_dir &= ~obj->mask;
break;
case PIN_OUTPUT:
*obj->reg_dir |= obj->mask;
break;
} }
} }

View File

@ -16,6 +16,8 @@
#ifndef MBED_GPIO_OBJECT_H #ifndef MBED_GPIO_OBJECT_H
#define MBED_GPIO_OBJECT_H #define MBED_GPIO_OBJECT_H
#include "mbed_assert.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -31,6 +33,8 @@ typedef struct {
} gpio_t; } gpio_t;
static inline void gpio_write(gpio_t *obj, int value) { static inline void gpio_write(gpio_t *obj, int value) {
MBED_ASSERT(obj->pin != (PinName)NC);
if (value) if (value)
*obj->reg_set = obj->mask; *obj->reg_set = obj->mask;
else else
@ -38,6 +42,7 @@ static inline void gpio_write(gpio_t *obj, int value) {
} }
static inline int gpio_read(gpio_t *obj) { static inline int gpio_read(gpio_t *obj) {
MBED_ASSERT(obj->pin != (PinName)NC);
return ((*obj->reg_in & obj->mask) ? 1 : 0); return ((*obj->reg_in & obj->mask) ? 1 : 0);
} }

View File

@ -13,11 +13,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "i2c_api.h" #include "i2c_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
static uint8_t repeated_start = 0; 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) { void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
if ((sda != P0_23) | (scl != P0_22)) { MBED_ASSERT((sda == P0_23) || (scl == P0_22));
error("I2C pin mapping failed");
}
// Enables clock for I2C0 // Enables clock for I2C0
LPC_SYSCON->SYSAHBCLKCTRL1 |= (1 << 13); LPC_SYSCON->SYSAHBCLKCTRL1 |= (1 << 13);

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h" #include "error.h"
@ -20,7 +21,7 @@ void pin_function(PinName pin, int function) {
} }
void pin_mode(PinName pin, PinMode mode) { void pin_mode(PinName pin, PinMode mode) {
if (pin == (uint32_t)NC) { return; } MBED_ASSERT(pin != (PinName)NC);
if ((pin == P0_22) || (pin == P0_23)) { if ((pin == P0_22) || (pin == P0_23)) {
// The true open-drain pins PIO0_22 and PIO0_23 can be configured for different I2C-bus speeds. // The true open-drain pins PIO0_22 and PIO0_23 can be configured for different I2C-bus speeds.

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "pwmout_api.h" #include "pwmout_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
@ -38,9 +38,8 @@ static int get_available_sct(void) {
} }
void pwmout_init(pwmout_t* obj, PinName pin) { void pwmout_init(pwmout_t* obj, PinName pin) {
if (pin == (uint32_t)NC) MBED_ASSERT(pin != (uint32_t)NC);
error("PwmOut pin mapping failed");
int sct_n = get_available_sct(); int sct_n = get_available_sct();
if (sct_n == -1) { if (sct_n == -1) {
error("No available SCT"); error("No available SCT");

View File

@ -14,6 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
// math.h required for floating point operations for baud rate calculation // math.h required for floating point operations for baud rate calculation
#include "mbed_assert.h"
#include <math.h> #include <math.h>
#include <string.h> #include <string.h>
@ -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 ++) { for (int n = 0; n < sizeof(LPC_SWM->PINASSIGN)/sizeof(*LPC_SWM->PINASSIGN); n ++) {
regVal = LPC_SWM->PINASSIGN[n]; regVal = LPC_SWM->PINASSIGN[n];
for (int j = 0; j <= 24; j += 8) { for (int j = 0; j <= 24; j += 8) {
if (((regVal >> j) & 0xFF) == pn) if (((regVal >> j) & 0xFF) == pn)
regVal |= (0xFF << j); regVal |= (0xFF << j);
} }
LPC_SWM->PINASSIGN[n] = regVal; 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) { void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) {
// 0: 1 stop bits, 1: 2 stop bits MBED_ASSERT((stop_bits == 1) || (stop_bits == 2)); // 0: 1 stop bits, 1: 2 stop bits
if (stop_bits != 1 && stop_bits != 2) { MBED_ASSERT((data_bits > 6) && (data_bits < 10)); // 0: 7 data bits ... 2: 9 data bits
error("Invalid stop bits specified"); MBED_ASSERT((parity == ParityNone) || (parity == ParityEven) || (parity == ParityOdd));
}
stop_bits -= 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; data_bits -= 7;
int paritysel; 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 ParityEven: paritysel = 2; break;
case ParityOdd : paritysel = 3; break; case ParityOdd : paritysel = 3; break;
default: default:
error("Invalid serial parity setting"); break;
return;
} }
obj->uart->CFG = (data_bits << 2) obj->uart->CFG = (data_bits << 2)

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include <math.h> #include <math.h>
#include "spi_api.h" #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) { void spi_format(spi_t *obj, int bits, int mode, int slave) {
spi_disable(obj); spi_disable(obj);
MBED_ASSERT((bits >= 1 && bits <= 16) && (mode >= 0 && mode <= 3));
if (!(bits >= 1 && bits <= 16) || !(mode >= 0 && mode <= 3)) {
error("SPI format error");
}
int polarity = (mode & 0x2) ? 1 : 0; int polarity = (mode & 0x2) ? 1 : 0;
int phase = (mode & 0x1) ? 1 : 0; int phase = (mode & 0x1) ? 1 : 0;

View File

@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "analogin_api.h" #include "analogin_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
#define ANALOGIN_MEDIAN_FILTER 1 #define ANALOGIN_MEDIAN_FILTER 1
@ -44,9 +44,7 @@ static const PinMap PinMap_ADC[] = {
void analogin_init(analogin_t *obj, PinName pin) { void analogin_init(analogin_t *obj, PinName pin) {
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC); obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
if (obj->adc == (ADCName)NC) { MBED_ASSERT(obj->adc != (ADCName)NC);
error("ADC pin mapping failed");
}
// ensure power is turned on // ensure power is turned on
LPC_SC->PCONP |= (1 << 12); LPC_SC->PCONP |= (1 << 12);

View File

@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "analogout_api.h" #include "analogout_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
static const PinMap PinMap_DAC[] = { static const PinMap PinMap_DAC[] = {
{P0_26, DAC_0, 2}, {P0_26, DAC_0, 2},
@ -26,9 +26,7 @@ static const PinMap PinMap_DAC[] = {
void analogout_init(dac_t *obj, PinName pin) { void analogout_init(dac_t *obj, PinName pin) {
obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC); obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC);
if (obj->dac == (DACName)NC) { MBED_ASSERT(obj->dac != (DACName)NC);
error("DAC pin mapping failed");
}
// power is on by default, set DAC clk divider is /4 // power is on by default, set DAC clk divider is /4
LPC_SC->PCLKSEL0 &= ~(0x3 << 22); LPC_SC->PCLKSEL0 &= ~(0x3 << 22);

View File

@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "can_api.h" #include "can_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
#include <math.h> #include <math.h>
#include <string.h> #include <string.h>
@ -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_rd = (CANName)pinmap_peripheral(rd, PinMap_CAN_RD);
CANName can_td = (CANName)pinmap_peripheral(td, PinMap_CAN_TD); CANName can_td = (CANName)pinmap_peripheral(td, PinMap_CAN_TD);
obj->dev = (LPC_CAN_TypeDef *)pinmap_merge(can_rd, can_td); obj->dev = (LPC_CAN_TypeDef *)pinmap_merge(can_rd, can_td);
if ((int)obj->dev == NC) { MBED_ASSERT((int)obj->dev != NC);
error("CAN pin mapping failed");
}
switch ((int)obj->dev) { switch ((int)obj->dev) {
case CAN_1: LPC_SC->PCONP |= 1 << 13; break; case CAN_1: LPC_SC->PCONP |= 1 << 13; break;

View File

@ -13,21 +13,23 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "gpio_api.h" #include "gpio_api.h"
#include "pinmap.h" #include "pinmap.h"
uint32_t gpio_set(PinName pin) { uint32_t gpio_set(PinName pin) {
MBED_ASSERT(pin != (PinName)NC);
pin_function(pin, 0); pin_function(pin, 0);
return (1 << ((int)pin & 0x1F)); return (1 << ((int)pin & 0x1F));
} }
void gpio_init(gpio_t *obj, PinName pin) { void gpio_init(gpio_t *obj, PinName pin) {
if(pin == NC) return;
obj->pin = pin; obj->pin = pin;
if (pin == (PinName)NC)
return;
obj->mask = gpio_set(pin); obj->mask = gpio_set(pin);
LPC_GPIO_TypeDef *port_reg = (LPC_GPIO_TypeDef *)((int)pin & ~0x1F);
LPC_GPIO_TypeDef *port_reg = (LPC_GPIO_TypeDef *) ((int)pin & ~0x1F);
obj->reg_set = &port_reg->FIOSET; obj->reg_set = &port_reg->FIOSET;
obj->reg_clr = &port_reg->FIOCLR; obj->reg_clr = &port_reg->FIOCLR;
obj->reg_in = &port_reg->FIOPIN; obj->reg_in = &port_reg->FIOPIN;
@ -39,8 +41,13 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
} }
void gpio_dir(gpio_t *obj, PinDirection direction) { void gpio_dir(gpio_t *obj, PinDirection direction) {
MBED_ASSERT(obj->pin != (PinName)NC);
switch (direction) { switch (direction) {
case PIN_INPUT : *obj->reg_dir &= ~obj->mask; break; case PIN_INPUT :
case PIN_OUTPUT: *obj->reg_dir |= obj->mask; break; *obj->reg_dir &= ~obj->mask;
break;
case PIN_OUTPUT:
*obj->reg_dir |= obj->mask;
break;
} }
} }

View File

@ -16,6 +16,8 @@
#ifndef MBED_GPIO_OBJECT_H #ifndef MBED_GPIO_OBJECT_H
#define MBED_GPIO_OBJECT_H #define MBED_GPIO_OBJECT_H
#include "mbed_assert.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -31,6 +33,7 @@ typedef struct {
} gpio_t; } gpio_t;
static inline void gpio_write(gpio_t *obj, int value) { static inline void gpio_write(gpio_t *obj, int value) {
MBED_ASSERT(obj->pin != (PinName)NC);
if (value) if (value)
*obj->reg_set = obj->mask; *obj->reg_set = obj->mask;
else else
@ -38,6 +41,7 @@ static inline void gpio_write(gpio_t *obj, int value) {
} }
static inline int gpio_read(gpio_t *obj) { static inline int gpio_read(gpio_t *obj) {
MBED_ASSERT(obj->pin != (PinName)NC);
return ((*obj->reg_in & obj->mask) ? 1 : 0); return ((*obj->reg_in & obj->mask) ? 1 : 0);
} }

View File

@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "i2c_api.h" #include "i2c_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
static const PinMap PinMap_I2C_SDA[] = { static const PinMap PinMap_I2C_SDA[] = {
{P0_0 , I2C_1, 3}, {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_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA);
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL); I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
obj->i2c = (LPC_I2C_TypeDef *)pinmap_merge(i2c_sda, i2c_scl); obj->i2c = (LPC_I2C_TypeDef *)pinmap_merge(i2c_sda, i2c_scl);
MBED_ASSERT((int)obj->i2c != NC);
if ((int)obj->i2c == NC) {
error("I2C pin mapping failed");
}
// enable power // enable power
i2c_power_enable(obj); i2c_power_enable(obj);

View File

@ -13,12 +13,13 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h" #include "error.h"
void pin_function(PinName pin, int function) { void pin_function(PinName pin, int function) {
if (pin == (PinName)NC) return; MBED_ASSERT(pin != (PinName)NC);
uint32_t pin_number = (uint32_t)pin - (uint32_t)P0_0; uint32_t pin_number = (uint32_t)pin - (uint32_t)P0_0;
int index = pin_number >> 4; int index = pin_number >> 4;
int offset = (pin_number & 0xF) << 1; int offset = (pin_number & 0xF) << 1;
@ -28,7 +29,7 @@ void pin_function(PinName pin, int function) {
} }
void pin_mode(PinName pin, PinMode mode) { void pin_mode(PinName pin, PinMode mode) {
if (pin == (PinName)NC) { return; } MBED_ASSERT(pin != (PinName)NC);
uint32_t pin_number = (uint32_t)pin - (uint32_t)P0_0; uint32_t pin_number = (uint32_t)pin - (uint32_t)P0_0;
int index = pin_number >> 5; int index = pin_number >> 5;

View File

@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "pwmout_api.h" #include "pwmout_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
#define TCR_CNT_EN 0x00000001 #define TCR_CNT_EN 0x00000001
#define TCR_RESET 0x00000002 #define TCR_RESET 0x00000002
@ -57,9 +57,8 @@ static unsigned int pwm_clock_mhz;
void pwmout_init(pwmout_t* obj, PinName pin) { void pwmout_init(pwmout_t* obj, PinName pin) {
// determine the channel // determine the channel
PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM); PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
if (pwm == (PWMName)NC) MBED_ASSERT(pwm != (PWMName)NC);
error("PwmOut pin mapping failed");
obj->pwm = pwm; obj->pwm = pwm;
obj->MR = PWM_MATCH[pwm]; obj->MR = PWM_MATCH[pwm];

View File

@ -14,6 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
// math.h required for floating point operations for baud rate calculation // math.h required for floating point operations for baud rate calculation
#include "mbed_assert.h"
#include <math.h> #include <math.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
@ -21,7 +22,6 @@
#include "serial_api.h" #include "serial_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
#include "gpio_api.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_tx = (UARTName)pinmap_peripheral(tx, PinMap_UART_TX);
UARTName uart_rx = (UARTName)pinmap_peripheral(rx, PinMap_UART_RX); UARTName uart_rx = (UARTName)pinmap_peripheral(rx, PinMap_UART_RX);
UARTName uart = (UARTName)pinmap_merge(uart_tx, uart_rx); UARTName uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
if ((int)uart == NC) { MBED_ASSERT((int)uart != NC);
error("Serial pinout mapping failed");
}
obj->uart = (LPC_UART_TypeDef *)uart; obj->uart = (LPC_UART_TypeDef *)uart;
// enable power // enable power
@ -150,6 +148,7 @@ void serial_free(serial_t *obj) {
// serial_baud // serial_baud
// set the baud rate, taking in to account the current SystemFrequency // set the baud rate, taking in to account the current SystemFrequency
void serial_baud(serial_t *obj, int baudrate) { void serial_baud(serial_t *obj, int baudrate) {
MBED_ASSERT((int)obj->uart <= UART_3);
// The LPC2300 and LPC1700 have a divider and a fractional divider to control the // The LPC2300 and LPC1700 have a divider and a fractional divider to control the
// baud rate. The formula is: // 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_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_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; 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; uint32_t PCLK = SystemCoreClock;
@ -245,16 +244,12 @@ void serial_baud(serial_t *obj, int baudrate) {
} }
void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) { void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) {
// 0: 1 stop bits, 1: 2 stop bits MBED_ASSERT((stop_bits == 1) || (stop_bits == 2)); // 0: 1 stop bits, 1: 2 stop bits
if (stop_bits != 1 && stop_bits != 2) { MBED_ASSERT((data_bits > 4) && (data_bits < 9)); // 0: 5 data bits ... 3: 8 data bits
error("Invalid stop bits specified"); MBED_ASSERT((parity == ParityNone) || (parity == ParityOdd) || (parity == ParityEven) ||
} (parity == ParityForced1) || (parity == ParityForced0));
stop_bits -= 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; data_bits -= 5;
int parity_enable, parity_select; int parity_enable, parity_select;
@ -265,8 +260,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 ParityForced1: parity_enable = 1; parity_select = 2; break;
case ParityForced0: parity_enable = 1; parity_select = 3; break; case ParityForced0: parity_enable = 1; parity_select = 3; break;
default: default:
error("Invalid serial parity setting"); break;
return;
} }
obj->uart->LCR = data_bits << 0 obj->uart->LCR = data_bits << 0

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include <math.h> #include <math.h>
#include "spi_api.h" #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_data = (SPIName)pinmap_merge(spi_mosi, spi_miso);
SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel); SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
obj->spi = (LPC_SSP_TypeDef*)pinmap_merge(spi_data, spi_cntl); obj->spi = (LPC_SSP_TypeDef*)pinmap_merge(spi_data, spi_cntl);
if ((int)obj->spi == NC) { MBED_ASSERT((int)obj->spi != NC);
error("SPI pinout mapping failed");
}
// enable power and clocking // enable power and clocking
switch ((int)obj->spi) { 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) { void spi_format(spi_t *obj, int bits, int mode, int slave) {
ssp_disable(obj); ssp_disable(obj);
if (!(bits >= 4 && bits <= 16) || !(mode >= 0 && mode <= 3)) { MBED_ASSERT(((bits >= 4) && (bits <= 16)) && (mode >= 0 && mode <= 3));
error("SPI format error");
}
int polarity = (mode & 0x2) ? 1 : 0; int polarity = (mode & 0x2) ? 1 : 0;
int phase = (mode & 0x1) ? 1 : 0; int phase = (mode & 0x1) ? 1 : 0;

View File

@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "analogin_api.h" #include "analogin_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
#define ANALOGIN_MEDIAN_FILTER 1 #define ANALOGIN_MEDIAN_FILTER 1
@ -42,9 +42,7 @@ static const PinMap PinMap_ADC[] = {
void analogin_init(analogin_t *obj, PinName pin) { void analogin_init(analogin_t *obj, PinName pin) {
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC); obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
if (obj->adc == (ADCName)NC) { MBED_ASSERT(obj->adc != (ADCName)NC);
error("ADC pin mapping failed");
}
// ensure power is turned on // ensure power is turned on
LPC_SC->PCONP |= (1 << 12); LPC_SC->PCONP |= (1 << 12);

View File

@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "analogout_api.h" #include "analogout_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
static const PinMap PinMap_DAC[] = { static const PinMap PinMap_DAC[] = {
{P0_26, DAC_0, 2}, {P0_26, DAC_0, 2},
@ -25,9 +25,7 @@ static const PinMap PinMap_DAC[] = {
void analogout_init(dac_t *obj, PinName pin) { void analogout_init(dac_t *obj, PinName pin) {
obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC); obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC);
if (obj->dac == (DACName)NC) { MBED_ASSERT(obj->dac != (DACName)NC);
error("DAC pin mapping failed");
}
// power is on by default, set DAC clk divider is /4 // power is on by default, set DAC clk divider is /4
LPC_SC->PCLKSEL0 &= ~(0x3 << 22); LPC_SC->PCLKSEL0 &= ~(0x3 << 22);

View File

@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "can_api.h" #include "can_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
#include <math.h> #include <math.h>
#include <string.h> #include <string.h>
@ -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_rd = (CANName)pinmap_peripheral(rd, PinMap_CAN_RD);
CANName can_td = (CANName)pinmap_peripheral(td, PinMap_CAN_TD); CANName can_td = (CANName)pinmap_peripheral(td, PinMap_CAN_TD);
obj->dev = (LPC_CAN_TypeDef *)pinmap_merge(can_rd, can_td); obj->dev = (LPC_CAN_TypeDef *)pinmap_merge(can_rd, can_td);
if ((int)obj->dev == NC) { MBED_ASSERT((int)obj->dev != NC);
error("CAN pin mapping failed");
}
switch ((int)obj->dev) { switch ((int)obj->dev) {
case CAN_1: LPC_SC->PCONP |= 1 << 13; break; case CAN_1: LPC_SC->PCONP |= 1 << 13; break;

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "gpio_api.h" #include "gpio_api.h"
#include "pinmap.h" #include "pinmap.h"
@ -25,8 +26,8 @@ uint32_t gpio_set(PinName pin) {
} }
void gpio_init(gpio_t *obj, PinName pin) { void gpio_init(gpio_t *obj, PinName pin) {
if (pin == NC) return; if (pin == (PinName)NC)
return;
obj->pin = pin; obj->pin = pin;
obj->mask = gpio_set(pin); obj->mask = gpio_set(pin);
@ -43,6 +44,8 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
} }
void gpio_dir(gpio_t *obj, PinDirection direction) { void gpio_dir(gpio_t *obj, PinDirection direction) {
if (obj->pin == (PinName)NC)
return;
switch (direction) { switch (direction) {
case PIN_INPUT : *obj->reg_dir &= ~obj->mask; break; case PIN_INPUT : *obj->reg_dir &= ~obj->mask; break;
case PIN_OUTPUT: *obj->reg_dir |= obj->mask; break; case PIN_OUTPUT: *obj->reg_dir |= obj->mask; break;

View File

@ -16,6 +16,8 @@
#ifndef MBED_GPIO_OBJECT_H #ifndef MBED_GPIO_OBJECT_H
#define MBED_GPIO_OBJECT_H #define MBED_GPIO_OBJECT_H
#include "mbed_assert.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -31,6 +33,7 @@ typedef struct {
} gpio_t; } gpio_t;
static inline void gpio_write(gpio_t *obj, int value) { static inline void gpio_write(gpio_t *obj, int value) {
MBED_ASSERT(obj->pin != (PinName)NC);
if (value) if (value)
*obj->reg_set = obj->mask; *obj->reg_set = obj->mask;
else else
@ -38,6 +41,7 @@ static inline void gpio_write(gpio_t *obj, int value) {
} }
static inline int gpio_read(gpio_t *obj) { static inline int gpio_read(gpio_t *obj) {
MBED_ASSERT(obj->pin != (PinName)NC);
return ((*obj->reg_in & obj->mask) ? 1 : 0); return ((*obj->reg_in & obj->mask) ? 1 : 0);
} }

View File

@ -16,7 +16,6 @@
#include "i2c_api.h" #include "i2c_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
static const PinMap PinMap_I2C_SDA[] = { static const PinMap PinMap_I2C_SDA[] = {
{P0_0 , I2C_1, 3}, {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_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA);
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL); I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
obj->i2c = (LPC_I2C_TypeDef *)pinmap_merge(i2c_sda, i2c_scl); obj->i2c = (LPC_I2C_TypeDef *)pinmap_merge(i2c_sda, i2c_scl);
MBED_ASSERT((int)obj->i2c != NC);
if ((int)obj->i2c == NC) {
error("I2C pin mapping failed");
}
// enable power // enable power
i2c_power_enable(obj); i2c_power_enable(obj);

View File

@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h" #include "error.h"
void pin_function(PinName pin, int function) { void pin_function(PinName pin, int function) {
if (pin == (PinName)NC) return; MBED_ASSERT(pin != (PinName)NC);
uint32_t pin_number = (uint32_t)pin - (uint32_t)P0_0; uint32_t pin_number = (uint32_t)pin - (uint32_t)P0_0;
int index = pin_number >> 4; int index = pin_number >> 4;
@ -28,15 +29,13 @@ void pin_function(PinName pin, int function) {
} }
void pin_mode(PinName pin, PinMode mode) { void pin_mode(PinName pin, PinMode mode) {
if (pin == (PinName)NC) { return; } MBED_ASSERT((pin != (PinName)NC) && (mode != OpenDrain));
uint32_t pin_number = (uint32_t)pin - (uint32_t)P0_0; uint32_t pin_number = (uint32_t)pin - (uint32_t)P0_0;
int index = pin_number >> 5; int index = pin_number >> 5;
int offset = pin_number & 0x1F; int offset = pin_number & 0x1F;
uint32_t drain = ((uint32_t) mode & (uint32_t) OpenDrain) >> 2; uint32_t drain = ((uint32_t) mode & (uint32_t) OpenDrain) >> 2;
if (mode == OpenDrain) error("OpenDrain not supported on LPC2368");
if (!drain) { if (!drain) {
index = pin_number >> 4; index = pin_number >> 4;
offset = (pin_number & 0xF) << 1; offset = (pin_number & 0xF) << 1;

View File

@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "pwmout_api.h" #include "pwmout_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
#define TCR_CNT_EN 0x00000001 #define TCR_CNT_EN 0x00000001
#define TCR_RESET 0x00000002 #define TCR_RESET 0x00000002
@ -57,9 +57,8 @@ static unsigned int pwm_clock_mhz;
void pwmout_init(pwmout_t* obj, PinName pin) { void pwmout_init(pwmout_t* obj, PinName pin) {
// determine the channel // determine the channel
PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM); PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
if (pwm == (PWMName)NC) MBED_ASSERT(pwm != (PWMName)NC);
error("PwmOut pin mapping failed");
obj->pwm = pwm; obj->pwm = pwm;
obj->MR = PWM_MATCH[pwm]; obj->MR = PWM_MATCH[pwm];

View File

@ -14,6 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
// math.h required for floating point operations for baud rate calculation // math.h required for floating point operations for baud rate calculation
#include "mbed_assert.h"
#include <math.h> #include <math.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
@ -21,7 +22,6 @@
#include "serial_api.h" #include "serial_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
/****************************************************************************** /******************************************************************************
* INITIALIZATION * 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_tx = (UARTName)pinmap_peripheral(tx, PinMap_UART_TX);
UARTName uart_rx = (UARTName)pinmap_peripheral(rx, PinMap_UART_RX); UARTName uart_rx = (UARTName)pinmap_peripheral(rx, PinMap_UART_RX);
UARTName uart = (UARTName)pinmap_merge(uart_tx, uart_rx); UARTName uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
if ((int)uart == NC) { MBED_ASSERT((int)uart != NC);
error("Serial pinout mapping failed");
}
obj->uart = (LPC_UART_TypeDef *)uart; obj->uart = (LPC_UART_TypeDef *)uart;
// enable power // enable power
@ -123,6 +121,7 @@ void serial_free(serial_t *obj) {
// serial_baud // serial_baud
// set the baud rate, taking in to account the current SystemFrequency // set the baud rate, taking in to account the current SystemFrequency
void serial_baud(serial_t *obj, int baudrate) { void serial_baud(serial_t *obj, int baudrate) {
MBED_ASSERT((int)obj->uart <= UART_3);
// The LPC2300 and LPC1700 have a divider and a fractional divider to control the // The LPC2300 and LPC1700 have a divider and a fractional divider to control the
// baud rate. The formula is: // 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_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_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; 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; uint32_t PCLK = SystemCoreClock;
@ -218,16 +217,12 @@ void serial_baud(serial_t *obj, int baudrate) {
} }
void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) { void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) {
// 0: 1 stop bits, 1: 2 stop bits MBED_ASSERT((stop_bits == 1) || (stop_bits == 2)); // 0: 1 stop bits, 1: 2 stop bits
if (stop_bits != 1 && stop_bits != 2) { MBED_ASSERT((data_bits > 4) && (data_bits < 9)); // 0: 5 data bits ... 3: 8 data bits
error("Invalid stop bits specified"); MBED_ASSERT((parity == ParityNone) || (parity == ParityOdd) || (parity == ParityEven) ||
} (parity == ParityForced1) || (parity == ParityForced0));
stop_bits -= 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; data_bits -= 5;
int parity_enable, parity_select; int parity_enable, parity_select;
@ -238,8 +233,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 ParityForced1: parity_enable = 1; parity_select = 2; break;
case ParityForced0: parity_enable = 1; parity_select = 3; break; case ParityForced0: parity_enable = 1; parity_select = 3; break;
default: default:
error("Invalid serial parity setting"); break;
return;
} }
obj->uart->LCR = data_bits << 0 obj->uart->LCR = data_bits << 0

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include <math.h> #include <math.h>
#include "spi_api.h" #include "spi_api.h"
@ -64,10 +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_data = (SPIName)pinmap_merge(spi_mosi, spi_miso);
SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel); SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
obj->spi = (LPC_SSP_TypeDef*)pinmap_merge(spi_data, spi_cntl); obj->spi = (LPC_SSP_TypeDef*)pinmap_merge(spi_data, spi_cntl);
MBED_ASSERT((int)obj->spi != NC);
if ((int)obj->spi == NC) {
error("SPI pinout mapping failed");
}
// enable power and clocking // enable power and clocking
switch ((int)obj->spi) { switch ((int)obj->spi) {
@ -98,12 +96,9 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
void spi_free(spi_t *obj) {} void spi_free(spi_t *obj) {}
void spi_format(spi_t *obj, int bits, int mode, int slave) { void spi_format(spi_t *obj, int bits, int mode, int slave) {
MBED_ASSERT(((bits >= 4) && (bits <= 16)) && ((mode >= 0) && (mode <= 3)));
ssp_disable(obj); ssp_disable(obj);
if (!(bits >= 4 && bits <= 16) || !(mode >= 0 && mode <= 3)) {
error("SPI format error");
}
int polarity = (mode & 0x2) ? 1 : 0; int polarity = (mode & 0x2) ? 1 : 0;
int phase = (mode & 0x1) ? 1 : 0; int phase = (mode & 0x1) ? 1 : 0;

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "analogin_api.h" #include "analogin_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
@ -43,9 +44,7 @@ static const PinMap PinMap_ADC[] = {
void analogin_init(analogin_t *obj, PinName pin) { void analogin_init(analogin_t *obj, PinName pin) {
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC); obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
if (obj->adc == (ADCName)NC) { MBED_ASSERT(obj->adc != (ADCName)NC);
error("ADC pin mapping failed");
}
// ensure power is turned on // ensure power is turned on
LPC_SC->PCONP |= (1 << 12); LPC_SC->PCONP |= (1 << 12);

View File

@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "mbed_assert.h"
#include "analogout_api.h" #include "analogout_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
static const PinMap PinMap_DAC[] = { static const PinMap PinMap_DAC[] = {
{P0_26, DAC_0, 2}, {P0_26, DAC_0, 2},
@ -25,9 +25,7 @@ static const PinMap PinMap_DAC[] = {
void analogout_init(dac_t *obj, PinName pin) { void analogout_init(dac_t *obj, PinName pin) {
obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC); obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC);
if (obj->dac == (DACName)NC) { MBED_ASSERT(obj->dac != (DACName)NC);
error("DAC pin mapping failed");
}
// DAC enable bit must be set // DAC enable bit must be set
LPC_IOCON->P0_26 |= (1 << 16); // DACEN LPC_IOCON->P0_26 |= (1 << 16); // DACEN

Some files were not shown because too many files have changed in this diff Show More