You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2019/12/17 09:27:47 UTC

[GitHub] [mynewt-core] utzig commented on a change in pull request #2134: hw/drivers/crypto: Add crypto_in_use flag.

utzig commented on a change in pull request #2134: hw/drivers/crypto: Add crypto_in_use flag.
URL: https://github.com/apache/mynewt-core/pull/2134#discussion_r358682029
 
 

 ##########
 File path: hw/drivers/crypto/crypto_nrf52/src/crypto_nrf52.c
 ##########
 @@ -34,27 +34,34 @@ struct aes_128_data {
 static bool
 nrf52_crypto_ecb_start(const struct aes_128_data *crypto_data)
 {
-    int ctr = 0x100000;
-    bool rc = true;
+    bool rc;
+    uint32_t end;
+    uint32_t err;
 
+    /* Just to be sure, always stop ECB and clear END/ERROR registers */
+    NRF_ECB->TASKS_STOPECB = 1;
+    NRF_ECB->EVENTS_ENDECB = 0;
+    NRF_ECB->EVENTS_ERRORECB = 0;
+
+    /* Set the data pointer and start ECB */
     NRF_ECB->ECBDATAPTR = (uint32_t)crypto_data;
     NRF_ECB->TASKS_STARTECB = 1;
 
-    while (ctr-- > 0) {
-        if (NRF_ECB->EVENTS_ENDECB) {
+    while (1) {
+        end = NRF_ECB->EVENTS_ENDECB;
+        err = NRF_ECB->EVENTS_ERRORECB;
+        if (end || err) {
+            if (err) {
 
 Review comment:
   You could eliminate this `if` / `else` and `rc` variable by doing `return (err == 0);` at the end, although it would be less readable I suppose. I agree with @andrzej-kaczmarek on using `bool` for `in_use`, otherwise everything looks ok.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services