Procházet zdrojové kódy

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 před 7 roky
rodič
revize
a5d26fea93
2 změnil soubory, kde provedl 18 přidání a 2 odebrání
  1. 6
    1
      src/pd.h
  2. 12
    1
      src/policy_engine.c

+ 6
- 1
src/pd.h Zobrazit soubor

@@ -216,6 +216,12 @@
216 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 226
  * Unit conversions
221 227
  *
@@ -242,5 +248,4 @@
242 248
 #define PD_PDI_CA(pdv) ((pdv) % 100)
243 249
 
244 250
 
245
-
246 251
 #endif /* PDB_PD_H */

+ 12
- 1
src/policy_engine.c Zobrazit soubor

@@ -51,6 +51,8 @@ static union pd_msg *policy_engine_message = NULL;
51 51
 static bool capability_match = false;
52 52
 /* Whether or not we have an explicit contract */
53 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 56
 /* Policy Engine thread mailbox */
55 57
 static msg_t pdb_pe_mailbox_queue[PDB_MSG_POOL_SIZE];
56 58
 mailbox_t pdb_pe_mailbox;
@@ -359,11 +361,20 @@ static enum policy_engine_state pe_sink_give_sink_cap(void)
359 361
 
360 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 372
     /* Generate a hard reset signal */
363 373
     chEvtSignal(pdb_hardrst_thread, PDB_EVT_HARDRST_RESET);
364 374
     chEvtWaitAny(PDB_EVT_PE_HARD_SENT);
365 375
 
366
-    /* TODO: maintain HardResetCounter */
376
+    /* Increment HardResetCounter */
377
+    hard_reset_counter++;
367 378
 
368 379
     return PESinkTransitionDefault;
369 380
 }

Loading…
Zrušit
Uložit