@@ -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 */
376399static 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