Explorar el Código

Only get configuration once in Type-C Current mode

Before, we were doing the O(1) configuration loading operation every
15 ms, which just made me feel dirty.  Now we do it only the first time
we check the available Type-C Current, and then cache its location.
This works because it never moves without rebooting into setup mode.
Clara Hobbs hace 7 años
padre
commit
e710199cf0
Se han modificado 1 ficheros con 9 adiciones y 2 borrados
  1. 9
    2
      src/device_policy_manager.c

+ 9
- 2
src/device_policy_manager.c Ver fichero

@@ -116,8 +116,15 @@ void pdb_dpm_get_sink_capability(union pd_msg *cap)
116 116
 
117 117
 bool pdb_dpm_evaluate_typec_current(void)
118 118
 {
119
-    /* Get the current configuration */
120
-    struct pdb_config *cfg = pdb_config_flash_read();
119
+    static bool cfg_set = false;
120
+    static struct pdb_config *cfg = NULL;
121
+
122
+    /* Only get the configuration the first time this function runs, since its
123
+     * location will never change without rebooting into setup mode. */
124
+    if (!cfg_set) {
125
+        cfg = pdb_config_flash_read();
126
+        cfg_set = true;
127
+    }
121 128
 
122 129
     /* If we have no configuration or don't want 5 V, Type-C Current can't
123 130
      * possibly satisfy our needs */

Loading…
Cancelar
Guardar