Browse Source

Move old_typec_match to the new structs

It was a hidden static variable of the policy engine, which would've
been a problem in a multi-port device.  Now it won't be anymore.
Clara Hobbs 6 years ago
parent
commit
c93b6b4909
2 changed files with 6 additions and 3 deletions
  1. 2
    0
      lib/include/pdb_pe.h
  2. 4
    3
      lib/src/policy_engine.c

+ 2
- 0
lib/include/pdb_pe.h View File

@@ -42,6 +42,8 @@ struct pdb_pe {
42 42
     bool _min_power;
43 43
     /* The number of hard resets we've sent */
44 44
     int8_t _hard_reset_counter;
45
+    /* The result of the last Type-C Current match comparison */
46
+    int8_t _old_tcc_match;
45 47
     /* Queue for the PE mailbox */
46 48
     msg_t _mailbox_queue[PDB_MSG_POOL_SIZE];
47 49
 };

+ 4
- 3
lib/src/policy_engine.c View File

@@ -623,16 +623,15 @@ static enum policy_engine_state pe_sink_send_reject(struct pdb_config *cfg)
623 623
  */
624 624
 static enum policy_engine_state pe_sink_source_unresponsive(struct pdb_config *cfg)
625 625
 {
626
-    static int old_tcc_match = -1;
627 626
     int tcc_match = cfg->dpm.evaluate_typec_current(cfg, fusb_get_typec_current());
628 627
 
629 628
     /* If the last two readings are the same, set the output */
630
-    if (old_tcc_match == tcc_match) {
629
+    if (cfg->pe._old_tcc_match == tcc_match) {
631 630
         cfg->dpm.transition_typec(cfg);
632 631
     }
633 632
 
634 633
     /* Remember whether or not the last measurement succeeded */
635
-    old_tcc_match = tcc_match;
634
+    cfg->pe._old_tcc_match = tcc_match;
636 635
 
637 636
     /* Wait tPDDebounce between measurements */
638 637
     chThdSleep(PD_T_PD_DEBOUNCE);
@@ -649,6 +648,8 @@ static THD_FUNCTION(PolicyEngine, vcfg) {
649 648
 
650 649
     /* Initialize the mailbox */
651 650
     chMBObjectInit(&cfg->pe.mailbox, cfg->pe._mailbox_queue, PDB_MSG_POOL_SIZE);
651
+    /* Initialize the old_tcc_match */
652
+    cfg->pe._old_tcc_match = -1;
652 653
 
653 654
     while (true) {
654 655
         switch (state) {

Loading…
Cancel
Save