Skip to content

Commit 165b2c6

Browse files
author
Edmund Hsu
committed
Realign ADuCM4x50 and ADuCM302x instance memory blocks
Ensure all instance memory blocks meet 4 byte alignment requirement without relying on compiler's or liker's optional settings: - gpioMemory[] for adi_gpio_Init() - aRtcDevMem0[] for adi_rtc_Open() - i2c_Mem[] or I2C_Mem[] for adi_i2c_Open() - spi_Mem0[], spi_Mem1[], spi_Mem2[] or SPI_Mem[] for adi_spi_Open()
1 parent 7239be2 commit 165b2c6

File tree

14 files changed

+94
-36
lines changed

14 files changed

+94
-36
lines changed

targets/TARGET_Analog_Devices/TARGET_ADUCM302X/TARGET_ADUCM3029/api/gpio_api.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@
4646

4747
#define MUX_FUNC_0 0x0
4848
#define NUM_GPIO_PORTS 4
49-
50-
extern uint8_t gpioMemory[ADI_GPIO_MEMORY_SIZE];
51-
extern uint8_t gpio_initialized;
49+
/*******************************************************************************
50+
ADI_GPIO_DEV_DATA Instance memory containing memory pointer should
51+
guarantee 4 byte alignmnet.
52+
*******************************************************************************/
53+
extern uint32_t gpioMemory[(ADI_GPIO_MEMORY_SIZE + 3)/4];
54+
extern uint8_t gpio_initialized;
5255

5356
static uint16_t gpio_oen[NUM_GPIO_PORTS] = {0};
5457
static uint16_t gpio_output_val[NUM_GPIO_PORTS] = {0};

targets/TARGET_Analog_Devices/TARGET_ADUCM302X/TARGET_ADUCM3029/api/gpio_dev_mem.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,12 @@
3939
******************************************************************************/
4040

4141
#include <drivers/gpio/adi_gpio.h>
42-
42+
/*******************************************************************************
43+
ADI_GPIO_DEV_DATA Instance memory containing memory pointer should
44+
guarantee 4 byte alignmnet.
45+
*******************************************************************************/
4346
// ADI GPIO device driver state memory. Only one state memory is required globally.
44-
uint8_t gpioMemory[ADI_GPIO_MEMORY_SIZE];
47+
uint32_t gpioMemory[(ADI_GPIO_MEMORY_SIZE + 3)/4];
4548

4649
// Flag to indicate whether the GPIO driver has been initialized
47-
uint8_t gpio_initialized = 0;
50+
uint8_t gpio_initialized = 0;

targets/TARGET_Analog_Devices/TARGET_ADUCM302X/TARGET_ADUCM3029/api/gpio_irq_api.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,12 @@ typedef struct {
5353
gpio_irq_event event;
5454
uint8_t int_enable;
5555
} gpio_chan_info_t;
56-
57-
extern uint8_t gpioMemory[ADI_GPIO_MEMORY_SIZE];
58-
extern uint8_t gpio_initialized;
56+
/*******************************************************************************
57+
ADI_GPIO_DEV_DATA Instance memory containing memory pointer should
58+
guarantee 4 byte alignmnet.
59+
*******************************************************************************/
60+
extern uint32_t gpioMemory[(ADI_GPIO_MEMORY_SIZE + 3)/4];
61+
extern uint8_t gpio_initialized;
5962
static gpio_chan_info_t channel_ids[MAX_GPIO_PORTS][MAX_GPIO_LINES];
6063
static gpio_irq_handler irq_handler = NULL;
6164

targets/TARGET_Analog_Devices/TARGET_ADUCM302X/TARGET_ADUCM3029/api/i2c_api.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@
5757
int adi_i2c_memtype = 0;
5858
#endif
5959
#else
60-
static uint8_t i2c_Mem[ADI_I2C_MEMORY_SIZE];
60+
/*******************************************************************************
61+
ADI_I2C_DEV_DATA_TYPE Instance memory containing memory pointer should
62+
guarantee 4 byte alignmnet.
63+
*******************************************************************************/
64+
static uint32_t i2c_Mem[(ADI_I2C_MEMORY_SIZE + 3)/4];
6165
static ADI_I2C_HANDLE i2c_Handle;
6266
#if defined(ADI_DEBUG)
6367
#warning "BUILD_I2C_MI_DYNAMIC is NOT defined. Memory allocation for I2C will be static"
@@ -72,7 +76,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl)
7276
uint32_t i2c_sda = pinmap_peripheral(sda, PinMap_I2C_SDA);
7377
uint32_t i2c_scl = pinmap_peripheral(scl, PinMap_I2C_SCL);
7478
ADI_I2C_HANDLE *pI2C_Handle;
75-
uint8_t *I2C_Mem;
79+
uint32_t *I2C_Mem;
7680
ADI_I2C_RESULT I2C_Return = ADI_I2C_SUCCESS;
7781
uint32_t I2C_DevNum = I2C_0; /* ADuCM3029 only has 1 I2C port */
7882

targets/TARGET_Analog_Devices/TARGET_ADUCM302X/TARGET_ADUCM3029/api/objects.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ struct i2c_s {
7979
ADI_I2C_HANDLE *pI2C_Handle;
8080
#if defined(BUILD_I2C_MI_DYNAMIC)
8181
ADI_I2C_HANDLE I2C_Handle;
82-
uint8_t I2C_Mem[ADI_I2C_MEMORY_SIZE];
82+
/*******************************************************************************
83+
ADI_I2C_DEV_DATA_TYPE Instance memory containing memory pointer should
84+
guarantee 4 byte alignmnet.
85+
*******************************************************************************/
86+
uint32_t I2C_Mem[(ADI_I2C_MEMORY_SIZE + 3)/4];
8387
#endif
8488
};
8589

@@ -90,7 +94,11 @@ struct spi_s {
9094
ADI_SPI_HANDLE *pSPI_Handle;
9195
#if defined(BUILD_SPI_MI_DYNAMIC)
9296
ADI_SPI_HANDLE SPI_Handle;
93-
uint8_t SPI_Mem[ADI_SPI_MEMORY_SIZE];
97+
/*******************************************************************************
98+
ADI_SPI_DEV_DATA_TYPE Instance memory containing memory pointer should
99+
guarantee 4 byte alignmnet.
100+
*******************************************************************************/
101+
uint32_t SPI_Mem[(ADI_SPI_MEMORY_SIZE + 3)/4];
94102
#endif
95103
};
96104

targets/TARGET_Analog_Devices/TARGET_ADUCM302X/TARGET_ADUCM3029/api/rtc_api.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@
4646
#include "adi_pwr.h"
4747

4848
#define RTC_DEVICE_NUM 0
49-
static uint8_t aRtcDevMem0[ADI_RTC_MEMORY_SIZE];
49+
/*******************************************************************************
50+
ADI_RTC_DEVICE Instance memory containing memory pointer should guarantee
51+
4 byte alignmnet.
52+
*******************************************************************************/
53+
static uint32_t aRtcDevMem0[(ADI_RTC_MEMORY_SIZE + 3)/4];
5054
static ADI_RTC_HANDLE hDevice0 = NULL;
5155

5256

targets/TARGET_Analog_Devices/TARGET_ADUCM302X/TARGET_ADUCM3029/api/spi_api.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,16 @@
5959
int adi_spi_memtype = 0;
6060
#endif
6161
#else
62+
/*******************************************************************************
63+
ADI_SPI_DEV_DATA_TYPE Instance memory containing memory pointer should
64+
guarantee 4 byte alignmnet.
65+
*******************************************************************************/
6266
ADI_SPI_HANDLE spi_Handle0;
63-
uint8_t spi_Mem0[ADI_SPI_MEMORY_SIZE];
67+
uint32_t spi_Mem0[(ADI_SPI_MEMORY_SIZE + 3)/4];
6468
ADI_SPI_HANDLE spi_Handle1;
65-
uint8_t spi_Mem1[ADI_SPI_MEMORY_SIZE];
69+
uint32_t spi_Mem1[(ADI_SPI_MEMORY_SIZE + 3)/4];
6670
ADI_SPI_HANDLE spi_Handle2;
67-
uint8_t spi_Mem2[ADI_SPI_MEMORY_SIZE];
71+
uint32_t spi_Mem2[(ADI_SPI_MEMORY_SIZE + 3)/4];
6872
#if defined(ADI_DEBUG)
6973
#warning "BUILD_SPI_MI_DYNAMIC is NOT defined. Memory allocation for SPI will be static"
7074
int adi_spi_memtype = 1;
@@ -92,7 +96,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
9296
uint32_t spi_data = pinmap_merge(spi_mosi, spi_miso);
9397
uint32_t spi_cntl = pinmap_merge(spi_sclk, spi_ssel);
9498
ADI_SPI_HANDLE *pSPI_Handle;
95-
uint8_t *SPI_Mem;
99+
uint32_t *SPI_Mem;
96100
ADI_SPI_RESULT SPI_Return = ADI_SPI_SUCCESS;
97101
uint32_t nDeviceNum = 0;
98102
ADI_SPI_CHIP_SELECT spi_cs = ADI_SPI_CS_NONE;

targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/api/gpio_api.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@
4646

4747
#define MUX_FUNC_0 0x0
4848
#define NUM_GPIO_PORTS 4
49-
50-
extern uint8_t gpioMemory[ADI_GPIO_MEMORY_SIZE];
51-
extern uint8_t gpio_initialized;
49+
/*******************************************************************************
50+
ADI_GPIO_DEV_DATA Instance memory containing memory pointer should
51+
guarantee 4 byte alignmnet.
52+
*******************************************************************************/
53+
extern uint32_t gpioMemory[(ADI_GPIO_MEMORY_SIZE + 3)/4];
54+
extern uint8_t gpio_initialized;
5255

5356
static uint16_t gpio_oen[NUM_GPIO_PORTS] = {0};
5457
static uint16_t gpio_output_val[NUM_GPIO_PORTS] = {0};

targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/api/gpio_dev_mem.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,12 @@
3939
******************************************************************************/
4040

4141
#include <drivers/gpio/adi_gpio.h>
42-
42+
/*******************************************************************************
43+
ADI_GPIO_DEV_DATA Instance memory containing memory pointer should
44+
guarantee 4 byte alignmnet.
45+
*******************************************************************************/
4346
// ADI GPIO device driver state memory. Only one state memory is required globally.
44-
uint8_t gpioMemory[ADI_GPIO_MEMORY_SIZE];
47+
uint32_t gpioMemory[(ADI_GPIO_MEMORY_SIZE +3)/4];
4548

4649
// Flag to indicate whether the GPIO driver has been initialized
47-
uint8_t gpio_initialized = 0;
50+
uint8_t gpio_initialized = 0;

targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/api/gpio_irq_api.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,12 @@ typedef struct {
5252
gpio_irq_event event;
5353
uint8_t int_enable;
5454
} gpio_chan_info_t;
55-
56-
extern uint8_t gpioMemory[ADI_GPIO_MEMORY_SIZE];
57-
extern uint8_t gpio_initialized;
55+
/*******************************************************************************
56+
ADI_GPIO_DEV_DATA Instance memory containing memory pointer should
57+
guarantee 4 byte alignmnet.
58+
*******************************************************************************/
59+
extern uint32_t gpioMemory[(ADI_GPIO_MEMORY_SIZE + 3)/4];
60+
extern uint8_t gpio_initialized;
5861
static gpio_chan_info_t channel_ids[MAX_GPIO_PORTS][MAX_GPIO_LINES];
5962
static gpio_irq_handler irq_handler = NULL;
6063

targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/api/i2c_api.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@
5757
int adi_i2c_memtype = 0;
5858
#endif
5959
#else
60-
static uint8_t i2c_Mem[ADI_I2C_MEMORY_SIZE];
60+
/*******************************************************************************
61+
ADI_I2C_DEV_DATA_TYPE Instance memory containing memory pointer should
62+
guarantee 4 byte alignmnet.
63+
*******************************************************************************/
64+
static uint32_t i2c_Mem[(ADI_I2C_MEMORY_SIZE + 3)/4];
6165
static ADI_I2C_HANDLE i2c_Handle;
6266
#if defined(ADI_DEBUG)
6367
#warning "BUILD_I2C_MI_DYNAMIC is NOT defined. Memory allocation for I2C will be static"
@@ -72,7 +76,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl)
7276
uint32_t i2c_sda = pinmap_peripheral(sda, PinMap_I2C_SDA);
7377
uint32_t i2c_scl = pinmap_peripheral(scl, PinMap_I2C_SCL);
7478
ADI_I2C_HANDLE *pI2C_Handle;
75-
uint8_t *I2C_Mem;
79+
uint32_t *I2C_Mem;
7680
ADI_I2C_RESULT I2C_Return = ADI_I2C_SUCCESS;
7781
uint32_t I2C_DevNum = I2C_0; /* ADuCM4050 only has 1 I2C port */
7882

targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/api/objects.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ struct i2c_s {
7979
ADI_I2C_HANDLE *pI2C_Handle;
8080
#if defined(BUILD_I2C_MI_DYNAMIC)
8181
ADI_I2C_HANDLE I2C_Handle;
82-
uint8_t I2C_Mem[ADI_I2C_MEMORY_SIZE];
82+
/*******************************************************************************
83+
ADI_I2C_DEV_DATA_TYPE Instance memory containing memory pointer should
84+
guarantee 4 byte alignmnet.
85+
*******************************************************************************/
86+
uint32_t I2C_Mem[(ADI_I2C_MEMORY_SIZE + 3)/4];
8387
#endif
8488
};
8589

@@ -90,7 +94,11 @@ struct spi_s {
9094
ADI_SPI_HANDLE *pSPI_Handle;
9195
#if defined(BUILD_SPI_MI_DYNAMIC)
9296
ADI_SPI_HANDLE SPI_Handle;
93-
uint8_t SPI_Mem[ADI_SPI_MEMORY_SIZE];
97+
/*******************************************************************************
98+
ADI_SPI_DEV_DATA_TYPE Instance memory containing memory pointer should
99+
guarantee 4 byte alignmnet.
100+
*******************************************************************************/
101+
uint32_t SPI_Mem[(ADI_SPI_MEMORY_SIZE + 3)/4];
94102
#endif
95103
};
96104

targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/api/rtc_api.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@
4646
#include "adi_pwr.h"
4747

4848
#define RTC_DEVICE_NUM 0
49-
static uint8_t aRtcDevMem0[ADI_RTC_MEMORY_SIZE];
49+
/*******************************************************************************
50+
ADI_RTC_DEVICE Instance memory containing memory pointer should guarantee
51+
4 byte alignmnet.
52+
*******************************************************************************/
53+
static uint32_t aRtcDevMem0[(ADI_RTC_MEMORY_SIZE + 3)/4];
5054
static ADI_RTC_HANDLE hDevice0 = NULL;
5155

5256

targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/api/spi_api.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,16 @@
6161
int adi_spi_memtype = 0;
6262
#endif
6363
#else
64+
/*******************************************************************************
65+
ADI_SPI_DEV_DATA_TYPE Instance memory containing memory pointer should
66+
guarantee 4 byte alignmnet.
67+
*******************************************************************************/
6468
ADI_SPI_HANDLE spi_Handle0;
65-
uint8_t spi_Mem0[ADI_SPI_MEMORY_SIZE];
69+
uint32_t spi_Mem0[(ADI_SPI_MEMORY_SIZE + 3)/4];
6670
ADI_SPI_HANDLE spi_Handle1;
67-
uint8_t spi_Mem1[ADI_SPI_MEMORY_SIZE];
71+
uint32_t spi_Mem1[(ADI_SPI_MEMORY_SIZE + 3)/4];
6872
ADI_SPI_HANDLE spi_Handle2;
69-
uint8_t spi_Mem2[ADI_SPI_MEMORY_SIZE];
73+
uint32_t spi_Mem2[(ADI_SPI_MEMORY_SIZE + 3)/4];
7074
#if defined(ADI_DEBUG)
7175
#warning "BUILD_SPI_MI_DYNAMIC is NOT defined. Memory allocation for SPI will be static"
7276
int adi_spi_memtype = 1;
@@ -94,7 +98,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
9498
uint32_t spi_data = pinmap_merge(spi_mosi, spi_miso);
9599
uint32_t spi_cntl = pinmap_merge(spi_sclk, spi_ssel);
96100
ADI_SPI_HANDLE *pSPI_Handle;
97-
uint8_t *SPI_Mem;
101+
uint32_t *SPI_Mem;
98102
ADI_SPI_RESULT SPI_Return = ADI_SPI_SUCCESS;
99103
uint32_t nDeviceNum = 0;
100104
ADI_SPI_CHIP_SELECT spi_cs = ADI_SPI_CS_NONE;

0 commit comments

Comments
 (0)