mirror of https://github.com/ARMmbed/mbed-os.git
- Added error checking for trng_get_bytes function;
- Added curly brackets to single line conditions in gpio_qpi.c and gpio_irq_api.c; - Changed rx and tx buffers in serial module as local variables; - Minor i2c & spi updates for github pull request; - Added function definition for spi_master_block_write.pull/5144/head
parent
d1b81b2161
commit
5ea792cc9a
|
|
@ -71,13 +71,15 @@ void gpio_init(gpio_t *obj, PinName pin)
|
||||||
{
|
{
|
||||||
obj->pin = pin;
|
obj->pin = pin;
|
||||||
|
|
||||||
if (pin == (PinName)NC)
|
if (pin == (PinName)NC) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize the GPIO driver. This function
|
// Initialize the GPIO driver. This function
|
||||||
// initializes the GPIO driver only once globally.
|
// initializes the GPIO driver only once globally.
|
||||||
if (!gpio_initialized)
|
if (!gpio_initialized) {
|
||||||
adi_gpio_Init(gpioMemory, ADI_GPIO_MEMORY_SIZE);
|
adi_gpio_Init(gpioMemory, ADI_GPIO_MEMORY_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
pin_function(pin, MUX_FUNC_0);
|
pin_function(pin, MUX_FUNC_0);
|
||||||
}
|
}
|
||||||
|
|
@ -134,11 +136,12 @@ int gpio_read(gpio_t *obj)
|
||||||
uint16_t Data;
|
uint16_t Data;
|
||||||
|
|
||||||
// check whether the pin is configured as input or output
|
// 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);
|
Data = gpio_output_val[port] & (1 << pin_num);
|
||||||
else
|
} else {
|
||||||
// otherwise call GetData
|
// otherwise call GetData
|
||||||
adi_gpio_GetData((ADI_GPIO_PORT)port, (1 << pin_num), &Data);
|
adi_gpio_GetData((ADI_GPIO_PORT)port, (1 << pin_num), &Data);
|
||||||
|
}
|
||||||
|
|
||||||
return ((((uint32_t)Data) >> pin_num) & 1);
|
return ((((uint32_t)Data) >> pin_num) & 1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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;
|
uint32_t pin_num = pin & 0xFF;
|
||||||
|
|
||||||
// check for valid pin and ID
|
// check for valid pin and ID
|
||||||
if ((pin == NC) || (id == 0))
|
if ((pin == NC) || (id == 0)) {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// make sure gpio driver has been initialized
|
// make sure gpio driver has been initialized
|
||||||
if (!gpio_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
|
// save the handler
|
||||||
if (handler)
|
if (handler) {
|
||||||
irq_handler = handler;
|
irq_handler = handler;
|
||||||
|
}
|
||||||
|
|
||||||
// disable the interrupt for the given pin
|
// disable the interrupt for the given pin
|
||||||
disable_pin_interrupt((ADI_GPIO_PORT)port, pin_num);
|
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 port = obj->pinname >> GPIO_PORT_SHIFT;
|
||||||
uint32_t pin_num = obj->pinname & 0xFF;
|
uint32_t pin_num = obj->pinname & 0xFF;
|
||||||
|
|
||||||
if (event == IRQ_NONE)
|
if (event == IRQ_NONE) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// read the current polarity register
|
// read the current polarity register
|
||||||
adi_gpio_GetGroupInterruptPolarity((ADI_GPIO_PORT)port, 1 << pin_num, &int_polarity_reg);
|
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);
|
int_polarity_reg |= (1 << pin_num);
|
||||||
else
|
} else {
|
||||||
int_polarity_reg &= ~(1 << pin_num);
|
int_polarity_reg &= ~(1 << pin_num);
|
||||||
|
}
|
||||||
|
|
||||||
// set the polarity register
|
// set the polarity register
|
||||||
adi_gpio_SetGroupInterruptPolarity((ADI_GPIO_PORT)port, int_polarity_reg);
|
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;
|
channel_ids[port][pin_num].event = event;
|
||||||
|
|
||||||
// enable interrupt for this pin if enable flag is set
|
// enable interrupt for this pin if enable flag is set
|
||||||
if (enable)
|
if (enable) {
|
||||||
gpio_irq_enable(obj);
|
gpio_irq_enable(obj);
|
||||||
else
|
} else {
|
||||||
gpio_irq_disable(obj);
|
gpio_irq_disable(obj);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Enable GPIO IRQ
|
/** 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 port = obj->pinname >> GPIO_PORT_SHIFT;
|
||||||
uint32_t pin_num = obj->pinname & 0xFF;
|
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;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Group all RISE interrupts in INTA and FALL interrupts in INTB
|
// 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) {
|
||||||
|
|
@ -302,14 +308,17 @@ void gpio_irq_disable(gpio_irq_t *obj)
|
||||||
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;
|
||||||
|
|
||||||
if (channel_ids[port][pin_num].event == IRQ_NONE)
|
if (channel_ids[port][pin_num].event == IRQ_NONE) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Group all RISE interrupts in INTA and FALL interrupts in INTB
|
// 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);
|
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);
|
disable_pin_interrupt((ADI_GPIO_PORT)port, pin_num);
|
||||||
|
}
|
||||||
|
|
||||||
channel_ids[port][pin_num].int_enable = 0;
|
channel_ids[port][pin_num].int_enable = 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -110,13 +110,15 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl)
|
||||||
|
|
||||||
int i2c_start(i2c_t *obj)
|
int i2c_start(i2c_t *obj)
|
||||||
{
|
{
|
||||||
return 0;
|
/* The Hardware does not support this feature. */
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int i2c_stop(i2c_t *obj)
|
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)
|
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)
|
int i2c_byte_write(i2c_t *obj, int data)
|
||||||
{
|
{
|
||||||
return 0;
|
/* The Hardware does not support this feature. */
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // #if DEVICE_I2C
|
#endif // #if DEVICE_I2C
|
||||||
|
|
|
||||||
|
|
@ -53,16 +53,16 @@
|
||||||
#include "PeripheralPins.h"
|
#include "PeripheralPins.h"
|
||||||
#include "drivers/uart/adi_uart.h"
|
#include "drivers/uart/adi_uart.h"
|
||||||
#define ADI_UART_MEMORY_SIZE (ADI_UART_BIDIR_MEMORY_SIZE)
|
#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 UartDeviceMem[ADI_UART_NUM_DEVICES][(ADI_UART_MEMORY_SIZE + 3)/4];
|
||||||
static uint32_t serial_irq_ids[ADI_UART_NUM_DEVICES] = {0};
|
static uint32_t serial_irq_ids[ADI_UART_NUM_DEVICES] = {0};
|
||||||
static uart_irq_handler irq_handler = NULL;
|
static uart_irq_handler irq_handler = NULL;
|
||||||
int stdio_uart_inited = 0;
|
int stdio_uart_inited = 0;
|
||||||
serial_t stdio_uart;
|
serial_t stdio_uart;
|
||||||
int rxbuffer[2];
|
static int rxbuffer[2];
|
||||||
int txbuffer[2];
|
static int txbuffer[2];
|
||||||
|
|
||||||
static void uart_callback(void *pCBParam, uint32_t Event, void *pArg)
|
static void uart_callback(void *pCBParam, uint32_t Event, void *pArg)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -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)
|
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
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -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;
|
ADI_RNG_HANDLE RNGhDevice = obj->RNGhDevice;
|
||||||
bool bRNGRdy;
|
bool bRNGRdy;
|
||||||
uint32_t nRandomNum, i;
|
uint32_t nRandomNum, i;
|
||||||
|
ADI_RNG_RESULT result;
|
||||||
|
|
||||||
for (i = 0; i < length; i++) {
|
for (i = 0; i < length; i++) {
|
||||||
// Loop until the device has data to be read
|
// Loop until the device has data to be read
|
||||||
do {
|
do {
|
||||||
adi_rng_GetRdyStatus(RNGhDevice, &bRNGRdy);
|
result = adi_rng_GetRdyStatus(RNGhDevice, &bRNGRdy);
|
||||||
|
if (result != ADI_RNG_SUCCESS)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
} while (!bRNGRdy);
|
} while (!bRNGRdy);
|
||||||
|
|
||||||
// Read the RNG
|
// Read the RNG
|
||||||
adi_rng_GetRngData(RNGhDevice, &nRandomNum);
|
result = adi_rng_GetRngData(RNGhDevice, &nRandomNum);
|
||||||
|
|
||||||
|
if (result != ADI_RNG_SUCCESS)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// Save the output
|
// Save the output
|
||||||
output[i] = (uint8_t)nRandomNum;
|
output[i] = (uint8_t)(nRandomNum & 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
*output_length = length;
|
*output_length = length;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue