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 7 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
     bool _min_power;
42
     bool _min_power;
43
     /* The number of hard resets we've sent */
43
     /* The number of hard resets we've sent */
44
     int8_t _hard_reset_counter;
44
     int8_t _hard_reset_counter;
45
+    /* The result of the last Type-C Current match comparison */
46
+    int8_t _old_tcc_match;
45
     /* Queue for the PE mailbox */
47
     /* Queue for the PE mailbox */
46
     msg_t _mailbox_queue[PDB_MSG_POOL_SIZE];
48
     msg_t _mailbox_queue[PDB_MSG_POOL_SIZE];
47
 };
49
 };

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

623
  */
623
  */
624
 static enum policy_engine_state pe_sink_source_unresponsive(struct pdb_config *cfg)
624
 static enum policy_engine_state pe_sink_source_unresponsive(struct pdb_config *cfg)
625
 {
625
 {
626
-    static int old_tcc_match = -1;
627
     int tcc_match = cfg->dpm.evaluate_typec_current(cfg, fusb_get_typec_current());
626
     int tcc_match = cfg->dpm.evaluate_typec_current(cfg, fusb_get_typec_current());
628
 
627
 
629
     /* If the last two readings are the same, set the output */
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
         cfg->dpm.transition_typec(cfg);
630
         cfg->dpm.transition_typec(cfg);
632
     }
631
     }
633
 
632
 
634
     /* Remember whether or not the last measurement succeeded */
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
     /* Wait tPDDebounce between measurements */
636
     /* Wait tPDDebounce between measurements */
638
     chThdSleep(PD_T_PD_DEBOUNCE);
637
     chThdSleep(PD_T_PD_DEBOUNCE);
649
 
648
 
650
     /* Initialize the mailbox */
649
     /* Initialize the mailbox */
651
     chMBObjectInit(&cfg->pe.mailbox, cfg->pe._mailbox_queue, PDB_MSG_POOL_SIZE);
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
     while (true) {
654
     while (true) {
654
         switch (state) {
655
         switch (state) {

Loading…
Cancel
Save