Browse Source

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 years ago
parent
commit
dd192fd0d5
5 changed files with 25 additions and 5 deletions
  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 View File

55
             chPoolFree(&pdb_msg_pool, (union pd_msg *) pdb_dpm_capabilities);
55
             chPoolFree(&pdb_msg_pool, (union pd_msg *) pdb_dpm_capabilities);
56
         }
56
         }
57
         pdb_dpm_capabilities = capabilities;
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
     /* Get the current configuration */
63
     /* Get the current configuration */

+ 3
- 1
src/device_policy_manager.h View File

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
  * Returns true if sufficient power is available, false otherwise.
45
  * Returns true if sufficient power is available, false otherwise.
44
  */
46
  */

+ 17
- 3
src/policy_engine.c View File

277
     /* Wait for an event */
277
     /* Wait for an event */
278
     if (min_power) {
278
     if (min_power) {
279
         evt = chEvtWaitAnyTimeout(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET
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
     } else {
282
     } else {
283
         evt = chEvtWaitAny(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET
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
     /* If we got reset signaling, transition to default */
288
     /* If we got reset signaling, transition to default */
299
         return PESinkGetSourceCap;
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
     /* If no event was received, the timer ran out. */
316
     /* If no event was received, the timer ran out. */
303
     if (evt == 0) {
317
     if (evt == 0) {
304
         /* Repeat our Request message */
318
         /* Repeat our Request message */

+ 1
- 0
src/policy_engine.h View File

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

+ 1
- 1
src/shell.c View File

175
 
175
 
176
     pdb_config_flash_update(&tmpcfg);
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
 static void cmd_load(BaseSequentialStream *chp, int argc, char *argv[])
181
 static void cmd_load(BaseSequentialStream *chp, int argc, char *argv[])

Loading…
Cancel
Save