Browse Source

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 7 years ago
parent
commit
e710199cf0
1 changed files with 9 additions and 2 deletions
  1. 9
    2
      src/device_policy_manager.c

+ 9
- 2
src/device_policy_manager.c View File

116
 
116
 
117
 bool pdb_dpm_evaluate_typec_current(void)
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
     /* If we have no configuration or don't want 5 V, Type-C Current can't
129
     /* If we have no configuration or don't want 5 V, Type-C Current can't
123
      * possibly satisfy our needs */
130
      * possibly satisfy our needs */

Loading…
Cancel
Save