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;
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -61,8 +61,8 @@ 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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue