diff --git a/targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/api/gpio_api.c b/targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/api/gpio_api.c index c338d84275..81d4be52cb 100755 --- a/targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/api/gpio_api.c +++ b/targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/api/gpio_api.c @@ -71,13 +71,15 @@ void gpio_init(gpio_t *obj, PinName pin) { obj->pin = pin; - if (pin == (PinName)NC) + if (pin == (PinName)NC) { return; + } // Initialize the GPIO driver. This function // initializes the GPIO driver only once globally. - if (!gpio_initialized) + if (!gpio_initialized) { adi_gpio_Init(gpioMemory, ADI_GPIO_MEMORY_SIZE); + } pin_function(pin, MUX_FUNC_0); } @@ -134,11 +136,12 @@ int gpio_read(gpio_t *obj) uint16_t Data; // check whether the pin is configured as input or output - if ((gpio_oen[port] >> pin_num) & 1) + if ((gpio_oen[port] >> pin_num) & 1) { Data = gpio_output_val[port] & (1 << pin_num); - else + } else { // otherwise call GetData adi_gpio_GetData((ADI_GPIO_PORT)port, (1 << pin_num), &Data); + } return ((((uint32_t)Data) >> pin_num) & 1); } diff --git a/targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/api/gpio_irq_api.c b/targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/api/gpio_irq_api.c index ae5b8234c3..3cf237218b 100755 --- a/targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/api/gpio_irq_api.c +++ b/targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/api/gpio_irq_api.c @@ -183,8 +183,9 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32 uint32_t pin_num = pin & 0xFF; // check for valid pin and ID - if ((pin == NC) || (id == 0)) + if ((pin == NC) || (id == 0)) { return -1; + } // make sure gpio driver has been initialized if (!gpio_initialized) { @@ -193,8 +194,9 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32 } // save the handler - if (handler) + if (handler) { irq_handler = handler; + } // disable the interrupt for the given pin disable_pin_interrupt((ADI_GPIO_PORT)port, pin_num); @@ -242,16 +244,18 @@ void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable) uint32_t port = obj->pinname >> GPIO_PORT_SHIFT; uint32_t pin_num = obj->pinname & 0xFF; - if (event == IRQ_NONE) + if (event == IRQ_NONE) { return; + } // read the current polarity register adi_gpio_GetGroupInterruptPolarity((ADI_GPIO_PORT)port, 1 << pin_num, &int_polarity_reg); - if (event == IRQ_RISE) + if (event == IRQ_RISE) { int_polarity_reg |= (1 << pin_num); - else + } else { int_polarity_reg &= ~(1 << pin_num); + } // set the polarity register adi_gpio_SetGroupInterruptPolarity((ADI_GPIO_PORT)port, int_polarity_reg); @@ -259,10 +263,11 @@ void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable) channel_ids[port][pin_num].event = event; // enable interrupt for this pin if enable flag is set - if (enable) + if (enable) { gpio_irq_enable(obj); - else + } else { gpio_irq_disable(obj); + } } /** Enable GPIO IRQ @@ -275,8 +280,9 @@ void gpio_irq_enable(gpio_irq_t *obj) uint32_t port = obj->pinname >> GPIO_PORT_SHIFT; uint32_t pin_num = obj->pinname & 0xFF; - if (channel_ids[port][pin_num].event == IRQ_NONE) + if (channel_ids[port][pin_num].event == IRQ_NONE) { return; + } // Group all RISE interrupts in INTA and FALL interrupts in INTB if (channel_ids[port][pin_num].event == IRQ_RISE) { @@ -302,14 +308,17 @@ void gpio_irq_disable(gpio_irq_t *obj) uint32_t port = obj->pinname >> GPIO_PORT_SHIFT; uint32_t pin_num = obj->pinname & 0xFF; - if (channel_ids[port][pin_num].event == IRQ_NONE) + if (channel_ids[port][pin_num].event == IRQ_NONE) { return; + } // Group all RISE interrupts in INTA and FALL interrupts in INTB - if (channel_ids[port][pin_num].event == IRQ_RISE) + if (channel_ids[port][pin_num].event == IRQ_RISE) { disable_pin_interrupt((ADI_GPIO_PORT)port, pin_num); - else if (channel_ids[port][pin_num].event == IRQ_FALL) + } + else if (channel_ids[port][pin_num].event == IRQ_FALL) { disable_pin_interrupt((ADI_GPIO_PORT)port, pin_num); + } channel_ids[port][pin_num].int_enable = 0; } diff --git a/targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/api/i2c_api.c b/targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/api/i2c_api.c index afa0312f47..f25d80c910 100755 --- a/targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/api/i2c_api.c +++ b/targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/api/i2c_api.c @@ -110,13 +110,15 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) int i2c_start(i2c_t *obj) { - return 0; + /* The Hardware does not support this feature. */ + return -1; } int i2c_stop(i2c_t *obj) { - return 0; + /* The Hardware does not support this feature. */ + return -1; } @@ -204,13 +206,15 @@ void i2c_reset(i2c_t *obj) int i2c_byte_read(i2c_t *obj, int last) { - return 0; + /* The Hardware does not support this feature. */ + return -1; } int i2c_byte_write(i2c_t *obj, int data) { - return 0; + /* The Hardware does not support this feature. */ + return -1; } #endif // #if DEVICE_I2C diff --git a/targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/api/serial_api.c b/targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/api/serial_api.c index 0a118c0cca..c6af733fad 100755 --- a/targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/api/serial_api.c +++ b/targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/api/serial_api.c @@ -53,16 +53,16 @@ #include "PeripheralPins.h" #include "drivers/uart/adi_uart.h" #define ADI_UART_MEMORY_SIZE (ADI_UART_BIDIR_MEMORY_SIZE) -#define ADI_UART_NUM_DEVICES 2 +#define ADI_UART_NUM_DEVICES 2 -static ADI_UART_HANDLE hDevice[ADI_UART_NUM_DEVICES]; +static ADI_UART_HANDLE hDevice[ADI_UART_NUM_DEVICES]; static uint32_t UartDeviceMem[ADI_UART_NUM_DEVICES][(ADI_UART_MEMORY_SIZE + 3)/4]; static uint32_t serial_irq_ids[ADI_UART_NUM_DEVICES] = {0}; static uart_irq_handler irq_handler = NULL; int stdio_uart_inited = 0; serial_t stdio_uart; -int rxbuffer[2]; -int txbuffer[2]; +static int rxbuffer[2]; +static int txbuffer[2]; static void uart_callback(void *pCBParam, uint32_t Event, void *pArg) { diff --git a/targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/api/spi_api.c b/targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/api/spi_api.c index b788e5b2ad..76015a4b2d 100755 --- a/targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/api/spi_api.c +++ b/targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/api/spi_api.c @@ -305,7 +305,28 @@ int spi_master_write(spi_t *obj, int value) */ int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length, char write_fill) { - return 0; + ADI_SPI_TRANSCEIVER transceive; + ADI_SPI_HANDLE SPI_Handle; + ADI_SPI_RESULT SPI_Return = ADI_SPI_SUCCESS; + + transceive.pReceiver = rx_buffer; + transceive.ReceiverBytes = rx_length; /* link transceive data size to the remaining count */ + transceive.nRxIncrement = 1; /* auto increment buffer */ + transceive.pTransmitter = tx_buffer; /* initialize data attributes */ + transceive.TransmitterBytes = tx_length; /* link transceive data size to the remaining count */ + transceive.nTxIncrement = 1; /* auto increment buffer */ + + transceive.bDMA = false; + transceive.bRD_CTL = false; + SPI_Handle = *obj->pSPI_Handle; + SPI_Return = adi_spi_MasterReadWrite(SPI_Handle, &transceive); + if (SPI_Return) { + obj->error = SPI_EVENT_ERROR; + return -1; + } + else { + return((int)tx_length); + } } #endif diff --git a/targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/api/trng_api.c b/targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/api/trng_api.c index 8106f44e59..de9d710697 100755 --- a/targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/api/trng_api.c +++ b/targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/api/trng_api.c @@ -88,18 +88,28 @@ int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_l ADI_RNG_HANDLE RNGhDevice = obj->RNGhDevice; bool bRNGRdy; uint32_t nRandomNum, i; + ADI_RNG_RESULT result; for (i = 0; i < length; i++) { // Loop until the device has data to be read do { - adi_rng_GetRdyStatus(RNGhDevice, &bRNGRdy); + result = adi_rng_GetRdyStatus(RNGhDevice, &bRNGRdy); + if (result != ADI_RNG_SUCCESS) + { + return -1; + } } while (!bRNGRdy); // Read the RNG - adi_rng_GetRngData(RNGhDevice, &nRandomNum); + result = adi_rng_GetRngData(RNGhDevice, &nRandomNum); + + if (result != ADI_RNG_SUCCESS) + { + return -1; + } // Save the output - output[i] = (uint8_t)nRandomNum; + output[i] = (uint8_t)(nRandomNum & 0xFF); } *output_length = length;