ソースを参照

Request new power without sending Get_Source_Cap

It was never really necessary to update the source capabilities before
making sending a Request message.  It was convenient though, since we
didn't store the previous Source_Capabilities message.  Now we do, so
it's possible to make a new Request based on that.

This commit makes the Sink do just that.  It doesn't follow the spec's
state diagram for this, but it's a minor change that works better with
this firmware's design, so I don't mind.  There's a comment explaining
that too, so future folks won't be confused by it either.
Clara Hobbs 7年前
コミット
dd192fd0d5
5個のファイルの変更25行の追加5行の削除
  1. 3
    0
      src/device_policy_manager.c
  2. 3
    1
      src/device_policy_manager.h
  3. 17
    3
      src/policy_engine.c
  4. 1
    0
      src/policy_engine.h
  5. 1
    1
      src/shell.c

+ 3
- 0
src/device_policy_manager.c ファイルの表示

@@ -55,6 +55,9 @@ bool pdb_dpm_evaluate_capability(const union pd_msg *capabilities, union pd_msg
55 55
             chPoolFree(&pdb_msg_pool, (union pd_msg *) pdb_dpm_capabilities);
56 56
         }
57 57
         pdb_dpm_capabilities = capabilities;
58
+    } else {
59
+        /* No new capabilities; use a shorter name for the stored ones. */
60
+        capabilities = pdb_dpm_capabilities;
58 61
     }
59 62
 
60 63
     /* Get the current configuration */

+ 3
- 1
src/device_policy_manager.h ファイルの表示

@@ -38,7 +38,9 @@ extern const union pd_msg *pdb_dpm_capabilities;
38 38
 
39 39
 
40 40
 /*
41
- * Create a Request message based on the given Source_Capabilities message.
41
+ * Create a Request message based on the given Source_Capabilities message.  If
42
+ * capabilities is NULL, the last non-null Source_Capabilities message passes
43
+ * is used.  If none has been provided, the behavior is undefined.
42 44
  *
43 45
  * Returns true if sufficient power is available, false otherwise.
44 46
  */

+ 17
- 3
src/policy_engine.c ファイルの表示

@@ -277,11 +277,12 @@ static enum policy_engine_state pe_sink_ready(void)
277 277
     /* Wait for an event */
278 278
     if (min_power) {
279 279
         evt = chEvtWaitAnyTimeout(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET
280
-                | PDB_EVT_PE_I_OVRTEMP | PDB_EVT_PE_GET_SOURCE_CAP,
281
-                PD_T_SINK_REQUEST);
280
+                | PDB_EVT_PE_I_OVRTEMP | PDB_EVT_PE_GET_SOURCE_CAP
281
+                | PDB_EVT_PE_NEW_POWER, PD_T_SINK_REQUEST);
282 282
     } else {
283 283
         evt = chEvtWaitAny(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET
284
-                | PDB_EVT_PE_I_OVRTEMP | PDB_EVT_PE_GET_SOURCE_CAP);
284
+                | PDB_EVT_PE_I_OVRTEMP | PDB_EVT_PE_GET_SOURCE_CAP
285
+                | PDB_EVT_PE_NEW_POWER);
285 286
     }
286 287
 
287 288
     /* If we got reset signaling, transition to default */
@@ -299,6 +300,19 @@ static enum policy_engine_state pe_sink_ready(void)
299 300
         return PESinkGetSourceCap;
300 301
     }
301 302
 
303
+    /* If the DPM wants new power, let it figure out what power it wants
304
+     * exactly.  This isn't exactly the transition from the spec (that would be
305
+     * SelectCap, not EvalCap), but this works better with the particular
306
+     * design of this firmware. */
307
+    if (evt & PDB_EVT_PE_NEW_POWER) {
308
+        /* Make sure we're evaluating NULL capabilities to use the old ones */
309
+        if (policy_engine_message != NULL) {
310
+            chPoolFree(&pdb_msg_pool, policy_engine_message);
311
+            policy_engine_message = NULL;
312
+        }
313
+        return PESinkEvalCap;
314
+    }
315
+
302 316
     /* If no event was received, the timer ran out. */
303 317
     if (evt == 0) {
304 318
         /* Repeat our Request message */

+ 1
- 0
src/policy_engine.h ファイルの表示

@@ -30,6 +30,7 @@
30 30
 #define PDB_EVT_PE_HARD_SENT EVENT_MASK(4)
31 31
 #define PDB_EVT_PE_I_OVRTEMP EVENT_MASK(5)
32 32
 #define PDB_EVT_PE_GET_SOURCE_CAP EVENT_MASK(6)
33
+#define PDB_EVT_PE_NEW_POWER EVENT_MASK(7)
33 34
 
34 35
 /* The Policy Engine thread object */
35 36
 extern thread_t *pdb_pe_thread;

+ 1
- 1
src/shell.c ファイルの表示

@@ -175,7 +175,7 @@ static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[])
175 175
 
176 176
     pdb_config_flash_update(&tmpcfg);
177 177
 
178
-    chEvtSignal(pdb_pe_thread, PDB_EVT_PE_GET_SOURCE_CAP);
178
+    chEvtSignal(pdb_pe_thread, PDB_EVT_PE_NEW_POWER);
179 179
 }
180 180
 
181 181
 static void cmd_load(BaseSequentialStream *chp, int argc, char *argv[])

読み込み中…
キャンセル
保存