]> git.earman.xyz Git - sensor-watch.git/commitdiff
annotate TRNG erratum, address review comment
authorAlex Maestas <git@se30.xyz>
Mon, 22 Jan 2024 00:30:25 +0000 (00:30 +0000)
committerAlex Maestas <git@se30.xyz>
Mon, 22 Jan 2024 00:39:18 +0000 (00:39 +0000)
movement/watch_faces/complication/randonaut_face.c
movement/watch_faces/complication/toss_up_face.c
watch-library/hardware/watch/watch_private.c
watch-library/shared/watch/watch.h
watch-library/simulator/watch/watch_private.c

index 886aabb788bba2df3e1b7c490a87d0990e18126a..3bbc147f6e0fe13bdb3c56dbe9c25c59b67a7aed 100644 (file)
@@ -357,7 +357,7 @@ static uint32_t _get_true_entropy(void) {
 
     while (!hri_trng_get_INTFLAG_reg(TRNG, TRNG_INTFLAG_DATARDY)); // Wait for TRNG data to be ready
 
-    watch_disable_TRNG(TRNG);
+    watch_disable_TRNG();
     hri_mclk_clear_APBCMASK_TRNG_bit(MCLK);
     return hri_trng_read_DATA_reg(TRNG); // Read a single 32-bit word from TRNG and return it
     #endif
index dedc904299646b20afa8396a0721cba22161b2e5..cf6ca68042a6b1edbbdc9f58261a110f2c02c17e 100644 (file)
@@ -255,7 +255,7 @@ uint32_t get_true_entropy(void) {
 
     while (!hri_trng_get_INTFLAG_reg(TRNG, TRNG_INTFLAG_DATARDY)); // Wait for TRNG data to be ready
 
-    watch_disable_TRNG(TRNG);
+    watch_disable_TRNG();
 
     hri_mclk_clear_APBCMASK_TRNG_bit(MCLK);
     return hri_trng_read_DATA_reg(TRNG); // Read a single 32-bit word from TRNG and return it
index 20f4ee5409b3ce748c7fa0f96a9408d4567a6875..1a33e5c59a225f49c41c4938c878a0cef6db974e 100644 (file)
@@ -110,18 +110,18 @@ int getentropy(void *buf, size_t buflen) {
         }
     }
 
-    watch_disable_TRNG(TRNG);
+    watch_disable_TRNG();
     hri_mclk_clear_APBCMASK_TRNG_bit(MCLK);
 
     return 0;
 }
 
-void watch_disable_TRNG(Trng *hw) {
-    hri_trng_clear_CTRLA_ENABLE_bit(hw);
-    // silicon erratum: the TRNG may leave internal components powered after disable.
-    // the workaround is to clear the register twice.
-    hri_trng_write_CTRLA_reg(hw, 0);
-    hri_trng_write_CTRLA_reg(hw, 0);
+void watch_disable_TRNG() {
+    // per Microchip datasheet clarification DS80000782,
+    // silicon erratum 1.16.1 indicates that the TRNG may leave internal components powered after being disabled.
+    // the workaround is to disable the TRNG by clearing the control register, twice.
+    hri_trng_write_CTRLA_reg(TRNG, 0);
+    hri_trng_write_CTRLA_reg(TRNG, 0);
 }
 
 
index 8ede1f63d88054c7d095f04af348c89ac66aa032..d23954ec1b6af938ccb2c49fddf71a8e583d0b51 100644 (file)
@@ -96,12 +96,8 @@ void watch_reset_to_bootloader(void);
   */
 int read(int file, char *ptr, int len);
 
-#ifdef __EMSCRIPTEN__
-typedef void* Trng;
-#endif
-
-/** @brief Disables the TRNG, working around a silicon erratum.
+/** @brief Disables the TRNG twice in order to work around silicon erratum 1.16.1.
  */
-void watch_disable_TRNG(Trng* hw);
+void watch_disable_TRNG();
 
 #endif /* WATCH_H_ */
index 509a30b987a964af6f24c83de597214846244db2..03e1f08b8c1a43271d0b2b00e117b8a79340464b 100644 (file)
@@ -57,7 +57,7 @@ void _watch_disable_tcc(void) {}
 
 void _watch_enable_usb(void) {}
 
-void watch_disable_TRNG(Trng* hw) {}
+void watch_disable_TRNG() {}
 
 // this function ends up getting called by printf to log stuff to the USB console.
 int _write(int file, char *ptr, int len) {