瀏覽代碼

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 年之前
父節點
當前提交
e710199cf0
共有 1 個文件被更改,包括 9 次插入2 次删除
  1. 9
    2
      src/device_policy_manager.c

+ 9
- 2
src/device_policy_manager.c 查看文件

@@ -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…
取消
儲存