Merge pull request #4900 from miyazakh/esp_waituntil

Fix wait-until-done in rsa hw primitive acceleration of ESP-IDF port
This commit is contained in:
Chris Conlon
2022-03-04 17:32:06 -07:00
committed by GitHub
5 changed files with 19 additions and 16 deletions

View File

@@ -51,6 +51,8 @@ static const char* const TAG = "wolfssl_mp";
#define MP_NG -1
#define ESP_TIMEOUT(cnt) (cnt >= ESP_RSA_TIMEOUT_CNT)
/* mutex */
static wolfSSL_Mutex mp_mutex;
static int espmp_CryptHwMutexInit = 0;
@@ -59,11 +61,12 @@ static int espmp_CryptHwMutexInit = 0;
*/
static int esp_mp_hw_wait_clean()
{
int timeout = 0;
while(++timeout < ESP_RSA_TIMEOUT && DPORT_REG_READ(RSA_CLEAN_REG) != 1){}
word32 timeout = 0;
while(!ESP_TIMEOUT(++timeout) &&
DPORT_REG_READ(RSA_CLEAN_REG) != 1) { }
if(timeout >= ESP_RSA_TIMEOUT) {
ESP_LOGE(TAG, "waiting hw ready is time-outed.");
if(ESP_TIMEOUT(timeout)) {
ESP_LOGE(TAG, "waiting hw ready is timed out.");
return MP_NG;
}
return MP_OKAY;
@@ -146,19 +149,16 @@ static void process_start(word32 reg)
/* wait until done */
static int wait_uitil_done(word32 reg)
{
int timeout = 0;
word32 timeout = 0;
/* wait until done && not timeout */
while(1) {
if(++timeout < ESP_RSA_TIMEOUT && DPORT_REG_READ(reg) == 1){
break;
}
}
while(!ESP_TIMEOUT(++timeout) &&
DPORT_REG_READ(reg) != 1) { }
/* clear interrupt */
DPORT_REG_WRITE(RSA_INTERRUPT_REG, 1);
if(timeout >= ESP_RSA_TIMEOUT) {
ESP_LOGE(TAG, "rsa operation is time-outed.");
if(ESP_TIMEOUT(timeout)) {
ESP_LOGE(TAG, "rsa operation is timed out.");
return MP_NG;
}