mbed library sources

Dependents:   Marvino mbot

Fork of mbed-src by mbed official

Revision:
610:813dcc80987e
Parent:
573:ad23fe03a082
--- a/targets/cmsis/TARGET_STM/TARGET_STM32F7/stm32f7xx_hal_hash_ex.c	Fri Aug 14 12:45:09 2015 +0100
+++ b/targets/cmsis/TARGET_STM/TARGET_STM32F7/stm32f7xx_hal_hash_ex.c	Fri Aug 14 13:15:17 2015 +0100
@@ -2,8 +2,8 @@
   ******************************************************************************
   * @file    stm32f7xx_hal_hash_ex.c
   * @author  MCD Application Team
-  * @version V1.0.0
-  * @date    12-May-2015
+  * @version V1.0.1
+  * @date    25-June-2015
   * @brief   HASH HAL Extension module driver.
   *          This file provides firmware functions to manage the following 
   *          functionalities of HASH peripheral:
@@ -264,7 +264,7 @@
         buffersize = hhash->Init.KeySize;
       }
       /* Configure the number of valid bits in last word of the message */
-      HASH->STR |= 8 * (buffersize % 4);
+      MODIFY_REG(HASH->STR, HASH_STR_NBLW, 8 * (buffersize % 4));
       
       /* Set the HASH DMA transfer complete */
       hhash->hdmain->XferCpltCallback = HASHEx_DMAXferCplt;
@@ -924,15 +924,7 @@
   
   /* Process Locked */
   __HAL_LOCK(hhash);
-  
-  if(hhash->HashITCounter == 0)
-  {
-    hhash->HashITCounter = 1;
-  }
-  else
-  {
-    hhash->HashITCounter = 0;
-  }
+
   if(hhash->State == HAL_HASH_STATE_READY)
   {
     /* Change the HASH state */
@@ -951,7 +943,8 @@
          the message digest of a new message */
       HASH->CR |= HASH_CR_INIT;
     }
-    
+    /* Reset interrupt counter */
+    hhash->HashITCounter = 0;
     /* Set the phase */
     hhash->Phase = HAL_HASH_PHASE_PROCESS;
     
@@ -976,11 +969,16 @@
       hhash->State = HAL_HASH_STATE_READY;
       /* Call digest computation complete callback */
       HAL_HASH_DgstCpltCallback(hhash);
+      /* Process Unlocked */
+      __HAL_UNLOCK(hhash);
+      
+      /* Return function status */
+      return HAL_OK;
     }
   }
   if(__HAL_HASH_GET_FLAG(HASH_FLAG_DINIS))
   {
-    if(hhash->HashInCount > 64)
+    if(hhash->HashInCount >= 68)
     {
       inputaddr = (uint32_t)hhash->pHashInBuffPtr;
       /* Write the Input block in the Data IN register */
@@ -1000,8 +998,11 @@
         }
         else
         {
-          hhash->HashInCount -= 64;
+           hhash->HashInCount = 0;
+          hhash->pHashInBuffPtr+= hhash->HashInCount;
         }
+        /* Set Interrupt counter */
+        hhash->HashITCounter = 1;
       }
       else
       {
@@ -1025,7 +1026,10 @@
       {
         inputcounter = (inputcounter+4-inputcounter%4);
       }
-      
+      else if ((inputcounter < 4) && (inputcounter != 0))
+      {
+        inputcounter = 4;
+      }
       /* Write the Input block in the Data IN register */
       for(buffercounter = 0; buffercounter < inputcounter/4; buffercounter++)
       {
@@ -1036,9 +1040,9 @@
       __HAL_HASH_START_DIGEST();
       /* Reset buffer counter */
       hhash->HashInCount = 0;
+      /* Call Input data transfer complete callback */
+      HAL_HASH_InCpltCallback(hhash);
     }
-    /* Call Input data transfer complete callback */
-    HAL_HASH_InCpltCallback(hhash);
   }
   
   /* Process Unlocked */
@@ -1068,15 +1072,7 @@
   
   /* Process Locked */
   __HAL_LOCK(hhash);
-  
-  if(hhash->HashITCounter == 0)
-  {
-    hhash->HashITCounter = 1;
-  }
-  else
-  {
-    hhash->HashITCounter = 0;
-  }
+
   if(hhash->State == HAL_HASH_STATE_READY)
   {
     /* Change the HASH state */
@@ -1096,6 +1092,9 @@
       HASH->CR |= HASH_CR_INIT;
     }
     
+    /* Reset interrupt counter */
+    hhash->HashITCounter = 0;
+    
     /* Set the phase */
     hhash->Phase = HAL_HASH_PHASE_PROCESS;
     
@@ -1120,11 +1119,17 @@
       hhash->State = HAL_HASH_STATE_READY;
       /* Call digest computation complete callback */
       HAL_HASH_DgstCpltCallback(hhash);
+      
+      /* Process Unlocked */
+      __HAL_UNLOCK(hhash);
+      
+      /* Return function status */
+      return HAL_OK;
     }
   }
   if(__HAL_HASH_GET_FLAG(HASH_FLAG_DINIS))
   {
-    if(hhash->HashInCount > 64)
+    if(hhash->HashInCount >= 68)
     {
       inputaddr = (uint32_t)hhash->pHashInBuffPtr;
       /* Write the Input block in the Data IN register */
@@ -1145,8 +1150,11 @@
         }
         else
         {
-          hhash->HashInCount -= 64;
+          hhash->HashInCount = 0;
+          hhash->pHashInBuffPtr+= hhash->HashInCount;
         }
+        /* Set Interrupt counter */
+        hhash->HashITCounter = 1;
       }
       else
       {
@@ -1170,6 +1178,10 @@
       {
         inputcounter = (inputcounter+4-inputcounter%4);
       }
+      else if ((inputcounter < 4) && (inputcounter != 0))
+      {
+        inputcounter = 4;
+      }
       
       /* Write the Input block in the Data IN register */
       for(buffercounter = 0; buffercounter < inputcounter/4; buffercounter++)
@@ -1181,9 +1193,9 @@
       __HAL_HASH_START_DIGEST();
       /* Reset buffer counter */
       hhash->HashInCount = 0;
+      /* Call Input data transfer complete callback */
+      HAL_HASH_InCpltCallback(hhash);
     }
-    /* Call Input data transfer complete callback */
-    HAL_HASH_InCpltCallback(hhash);
   }
   
   /* Process Unlocked */