Browse Source

Maintain HardResetCounter

It's simpler than I realized.  All that's left to do here is the
fallback mechanism for when the Sink is configured for 5 V.  This means
that yet again, a TODO was replaced with another, less critical TODO.
Clara Hobbs 7 years ago
parent
commit
a5d26fea93
2 changed files with 18 additions and 2 deletions
  1. 6
    1
      src/pd.h
  2. 12
    1
      src/policy_engine.c

+ 6
- 1
src/pd.h View File

216
 #define PD_T_TYPEC_SINK_WAIT_CAP MS2ST(465)
216
 #define PD_T_TYPEC_SINK_WAIT_CAP MS2ST(465)
217
 
217
 
218
 
218
 
219
+/*
220
+ * Counter maximums
221
+ */
222
+#define PD_N_HARD_RESET_COUNT 2
223
+
224
+
219
 /*
225
 /*
220
  * Unit conversions
226
  * Unit conversions
221
  *
227
  *
242
 #define PD_PDI_CA(pdv) ((pdv) % 100)
248
 #define PD_PDI_CA(pdv) ((pdv) % 100)
243
 
249
 
244
 
250
 
245
-
246
 #endif /* PDB_PD_H */
251
 #endif /* PDB_PD_H */

+ 12
- 1
src/policy_engine.c View File

51
 static bool capability_match = false;
51
 static bool capability_match = false;
52
 /* Whether or not we have an explicit contract */
52
 /* Whether or not we have an explicit contract */
53
 static bool explicit_contract = false;
53
 static bool explicit_contract = false;
54
+/* Keep track of how many hard resets we've sent */
55
+static int hard_reset_counter = 0;
54
 /* Policy Engine thread mailbox */
56
 /* Policy Engine thread mailbox */
55
 static msg_t pdb_pe_mailbox_queue[PDB_MSG_POOL_SIZE];
57
 static msg_t pdb_pe_mailbox_queue[PDB_MSG_POOL_SIZE];
56
 mailbox_t pdb_pe_mailbox;
58
 mailbox_t pdb_pe_mailbox;
359
 
361
 
360
 static enum policy_engine_state pe_sink_hard_reset(void)
362
 static enum policy_engine_state pe_sink_hard_reset(void)
361
 {
363
 {
364
+    /* If we've already sent the maximum number of hard resets, give up */
365
+    if (hard_reset_counter > PD_N_HARD_RESET_COUNT) {
366
+        pdb_dpm_output_off();
367
+        /* TODO: Fall back to USB BC or Type-C power if configured for 5 V. */
368
+        for (;;)
369
+            chThdSleepMilliseconds(1000);
370
+    }
371
+
362
     /* Generate a hard reset signal */
372
     /* Generate a hard reset signal */
363
     chEvtSignal(pdb_hardrst_thread, PDB_EVT_HARDRST_RESET);
373
     chEvtSignal(pdb_hardrst_thread, PDB_EVT_HARDRST_RESET);
364
     chEvtWaitAny(PDB_EVT_PE_HARD_SENT);
374
     chEvtWaitAny(PDB_EVT_PE_HARD_SENT);
365
 
375
 
366
-    /* TODO: maintain HardResetCounter */
376
+    /* Increment HardResetCounter */
377
+    hard_reset_counter++;
367
 
378
 
368
     return PESinkTransitionDefault;
379
     return PESinkTransitionDefault;
369
 }
380
 }

Loading…
Cancel
Save