Skip to content

Commit 034b029

Browse files
jerome-pouillerjhedberg
authored andcommitted
wiseconnect: Get rid of PSRAM_BASE_ADDRESS
PSRAM_BASE_ADDRESS contains an hardware configuration parameter. This parameter belongs to the DT on the Zephyr side. Hence, it can't be defined with a macro. Fortunately, this parameter can be deducted from the Chip Select number. So, this patch introduce a getter to retrieve this value. This is also the opportunity to factorize the code that check the access boundaries. Upstream-status: Pending Signed-off-by: Jérôme Pouiller <[email protected]>
1 parent 1698e8a commit 034b029

File tree

2 files changed

+40
-32
lines changed

2 files changed

+40
-32
lines changed

wiseconnect/components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_psram_handle.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -63,26 +63,6 @@ extern struct sl_psram_info_type_t PSRAM_Device;
6363
#define PSRAM_GPIO_PIN_SET_46_TO_57_CS_1 6 /**< GPIO Pin Set 46 to 57 with Chip Select 1 */
6464
/// @} end group PSRAM_GPIO_PIN_SET
6565

66-
/**
67-
* @addtogroup PSRAM_CHIP_SELECT PSRAM Chip Select and Base Address
68-
* @ingroup PSRAM
69-
* @{
70-
*/
71-
#if (PSRAM_GPIO_PIN_SET_SEL == PSRAM_GPIO_PIN_SET_52_TO_57)
72-
#define PSRAM_BASE_ADDRESS (0x0A000000) /**< Base Address for GPIO Pin Set 52 to 57 */
73-
#elif (PSRAM_GPIO_PIN_SET_SEL == PSRAM_GPIO_PIN_SET_0_TO_5)
74-
#define PSRAM_BASE_ADDRESS (0x0A000000) /**< Base Address for GPIO Pin Set 0 to 5 */
75-
#elif (PSRAM_GPIO_PIN_SET_SEL == PSRAM_GPIO_PIN_SET_46_TO_51_CS_0)
76-
#define PSRAM_BASE_ADDRESS (0x0A000000) /**< Base Address for GPIO Pin Set 46 to 51 with CS 0 */
77-
#elif (PSRAM_GPIO_PIN_SET_SEL == PSRAM_GPIO_PIN_SET_46_TO_51_CS_1)
78-
#define PSRAM_BASE_ADDRESS (0x0B000000) /**< Base Address for GPIO Pin Set 46 to 51 with CS 1 */
79-
#elif (PSRAM_GPIO_PIN_SET_SEL == PSRAM_GPIO_PIN_SET_46_TO_57_CS_0)
80-
#define PSRAM_BASE_ADDRESS (0x0A000000) /**< Base Address for GPIO Pin Set 46 to 57 with CS 0 */
81-
#elif (PSRAM_GPIO_PIN_SET_SEL == PSRAM_GPIO_PIN_SET_46_TO_57_CS_1)
82-
#define PSRAM_BASE_ADDRESS (0x0B000000) /**< Base Address for GPIO Pin Set 46 to 57 with CS 1 */
83-
#endif
84-
/// @} end group PSRAM_CHIP_SELECT
85-
8666
/**
8767
* @addtogroup PSRAM_PIN_CONFIG PSRAM Pin Configuration
8868
* @ingroup PSRAM

wiseconnect/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_psram.c

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,29 @@ __STATIC_INLINE void wait_state_manual()
372372
;
373373
}
374374

375+
sl_psram_return_type_t qspi_check_access(uint32_t addr, uint32_t len)
376+
{
377+
uint32_t ram_start_addr;
378+
379+
if (PSRAM_Device.spi_config.spi_config_2.cs_no == 0) {
380+
ram_start_addr = 0x0A000000;
381+
} else if (PSRAM_Device.spi_config.spi_config_2.cs_no == 1) {
382+
ram_start_addr = 0x0B000000;
383+
} else {
384+
return PSRAM_INVALID_ADDRESS_LENGTH;
385+
}
386+
if (addr < ram_start_addr) {
387+
return PSRAM_INVALID_ADDRESS_LENGTH;
388+
}
389+
if (addr >= ram_start_addr + PSRAM_Device.devDensity / 8) {
390+
return PSRAM_INVALID_ADDRESS_LENGTH;
391+
}
392+
if (addr + len >= ram_start_addr + PSRAM_Device.devDensity / 8) {
393+
return PSRAM_INVALID_ADDRESS_LENGTH;
394+
}
395+
return PSRAM_SUCCESS;
396+
}
397+
375398
/* UDMA controller transfer descriptor chain complete callback */
376399
static void udma_transfer_complete(uint32_t event, uint32_t ch)
377400
{
@@ -1138,6 +1161,7 @@ sl_psram_return_type_t sl_si91x_psram_manual_write_in_blocking_mode(uint32_t add
11381161
uint8_t psramXferBuf[4];
11391162
uint32_t xferAddr;
11401163
uint32_t lengthInBytes = 0;
1164+
sl_psram_return_type_t ret;
11411165

11421166
if (PSRAMStatus.state != initialised) {
11431167
return PSRAM_NOT_INITIALIZED;
@@ -1151,10 +1175,11 @@ sl_psram_return_type_t sl_si91x_psram_manual_write_in_blocking_mode(uint32_t add
11511175
return PSRAM_NULL_ADDRESS;
11521176
}
11531177

1154-
if ((!(addr >= PSRAM_BASE_ADDRESS && addr < (PSRAM_BASE_ADDRESS + (PSRAM_Device.devDensity / 8))))
1155-
|| ((addr + (num_of_elements * hSize)) > (PSRAM_BASE_ADDRESS + (PSRAM_Device.devDensity / 8)))) {
1156-
return PSRAM_INVALID_ADDRESS_LENGTH;
1178+
ret = qspi_check_access(addr, num_of_elements * hSize);
1179+
if (ret) {
1180+
return ret;
11571181
}
1182+
11581183
#if PSRAM_ROW_BOUNDARY_CROSSING_SUPPORTED
11591184
uint32_t rbxOffset;
11601185
rbxOffset = addr % PSRAM_Device.defaultBurstWrapSize;
@@ -1292,6 +1317,7 @@ sl_psram_return_type_t sl_si91x_psram_manual_read_in_blocking_mode(uint32_t addr
12921317
uint8_t psramXferBuf[7];
12931318
uint32_t xferAddr;
12941319
uint32_t lengthInBytes = 0;
1320+
sl_psram_return_type_t ret;
12951321

12961322
if (PSRAMStatus.state != initialised) {
12971323
return PSRAM_NOT_INITIALIZED;
@@ -1305,9 +1331,9 @@ sl_psram_return_type_t sl_si91x_psram_manual_read_in_blocking_mode(uint32_t addr
13051331
return PSRAM_NULL_ADDRESS;
13061332
}
13071333

1308-
if ((!(addr >= PSRAM_BASE_ADDRESS && addr < (PSRAM_BASE_ADDRESS + (PSRAM_Device.devDensity / 8))))
1309-
|| ((addr + (num_of_elements * hSize)) > (PSRAM_BASE_ADDRESS + (PSRAM_Device.devDensity / 8)))) {
1310-
return PSRAM_INVALID_ADDRESS_LENGTH;
1334+
ret = qspi_check_access(addr, num_of_elements * hSize);
1335+
if (ret) {
1336+
return ret;
13111337
}
13121338

13131339
#if PSRAM_ROW_BOUNDARY_CROSSING_SUPPORTED
@@ -1470,6 +1496,7 @@ sl_psram_return_type_t sl_si91x_psram_manual_write_in_dma_mode(uint32_t addr,
14701496
uint32_t lengthInBytes;
14711497
uint8_t psramXferBuf[4];
14721498
uint32_t xferAddr;
1499+
sl_psram_return_type_t ret;
14731500

14741501
if (PSRAMStatus.state != initialised) {
14751502
return PSRAM_NOT_INITIALIZED;
@@ -1483,9 +1510,9 @@ sl_psram_return_type_t sl_si91x_psram_manual_write_in_dma_mode(uint32_t addr,
14831510
return PSRAM_NULL_ADDRESS;
14841511
}
14851512

1486-
if ((!(addr >= PSRAM_BASE_ADDRESS && addr < (PSRAM_BASE_ADDRESS + (PSRAM_Device.devDensity / 8))))
1487-
|| ((addr + (length * hSize)) > (PSRAM_BASE_ADDRESS + (PSRAM_Device.devDensity / 8)))) {
1488-
return PSRAM_INVALID_ADDRESS_LENGTH;
1513+
ret = qspi_check_access(addr, length * hSize);
1514+
if (ret) {
1515+
return ret;
14891516
}
14901517

14911518
lengthInBytes = (length * hSize);
@@ -1720,6 +1747,7 @@ sl_psram_return_type_t sl_si91x_psram_manual_read_in_dma_mode(uint32_t addr,
17201747
uint32_t lengthInBytes;
17211748
uint8_t psramXferBuf[7];
17221749
uint32_t xferAddr;
1750+
sl_psram_return_type_t ret;
17231751

17241752
if (PSRAMStatus.state != initialised) {
17251753
return PSRAM_NOT_INITIALIZED;
@@ -1733,9 +1761,9 @@ sl_psram_return_type_t sl_si91x_psram_manual_read_in_dma_mode(uint32_t addr,
17331761
return PSRAM_NULL_ADDRESS;
17341762
}
17351763

1736-
if ((!(addr >= PSRAM_BASE_ADDRESS && addr < (PSRAM_BASE_ADDRESS + (PSRAM_Device.devDensity / 8))))
1737-
|| ((addr + (length * hSize)) > (PSRAM_BASE_ADDRESS + (PSRAM_Device.devDensity / 8)))) {
1738-
return PSRAM_INVALID_ADDRESS_LENGTH;
1764+
ret = qspi_check_access(addr, length * hSize);
1765+
if (ret) {
1766+
return ret;
17391767
}
17401768

17411769
lengthInBytes = (length * hSize);

0 commit comments

Comments
 (0)