Browse Source

Refer to the PE thread from the struct pdb_config

Clara Hobbs 7 years ago
parent
commit
f3f0571ebd
9 changed files with 21 additions and 21 deletions
  1. 0
    3
      lib/include/policy_engine.h
  2. 2
    4
      lib/src/hard_reset.c
  3. 1
    1
      lib/src/int_n.c
  4. 1
    3
      lib/src/policy_engine.c
  5. 1
    1
      lib/src/protocol_rx.c
  6. 3
    3
      lib/src/protocol_tx.c
  7. 1
    1
      src/main.c
  8. 9
    4
      src/shell.c
  9. 3
    1
      src/shell.h

+ 0
- 3
lib/include/policy_engine.h View File

@@ -34,9 +34,6 @@
34 34
 #define PDB_EVT_PE_GET_SOURCE_CAP EVENT_MASK(6)
35 35
 #define PDB_EVT_PE_NEW_POWER EVENT_MASK(7)
36 36
 
37
-/* The Policy Engine thread object */
38
-extern thread_t *pdb_pe_thread;
39
-
40 37
 /*
41 38
  * Start the Policy Engine thread
42 39
  */

+ 2
- 4
lib/src/hard_reset.c View File

@@ -72,9 +72,8 @@ static enum hardrst_state hardrst_reset_layer(struct pdb_config *cfg)
72 72
 
73 73
 static enum hardrst_state hardrst_indicate_hard_reset(struct pdb_config *cfg)
74 74
 {
75
-    (void) cfg;
76 75
     /* Tell the PE that we're doing a hard reset */
77
-    chEvtSignal(pdb_pe_thread, PDB_EVT_PE_RESET);
76
+    chEvtSignal(cfg->pe.thread, PDB_EVT_PE_RESET);
78 77
 
79 78
     return PRLHRWaitPE;
80 79
 }
@@ -100,9 +99,8 @@ static enum hardrst_state hardrst_wait_phy(struct pdb_config *cfg)
100 99
 
101 100
 static enum hardrst_state hardrst_hard_reset_requested(struct pdb_config *cfg)
102 101
 {
103
-    (void) cfg;
104 102
     /* Tell the PE that the hard reset was sent */
105
-    chEvtSignal(pdb_pe_thread, PDB_EVT_PE_HARD_SENT);
103
+    chEvtSignal(cfg->pe.thread, PDB_EVT_PE_HARD_SENT);
106 104
 
107 105
     return PRLHRWaitPE;
108 106
 }

+ 1
- 1
lib/src/int_n.c View File

@@ -76,7 +76,7 @@ static THD_FUNCTION(IntNPoll, vcfg) {
76 76
              * Engine thread */
77 77
             if (status.interrupta & FUSB_INTERRUPTA_I_OCP_TEMP
78 78
                     && status.status1 & FUSB_STATUS1_OVRTEMP) {
79
-                chEvtSignal(pdb_pe_thread, PDB_EVT_PE_I_OVRTEMP);
79
+                chEvtSignal(cfg->pe.thread, PDB_EVT_PE_I_OVRTEMP);
80 80
             }
81 81
 
82 82
         }

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

@@ -28,8 +28,6 @@
28 28
 #include "pd.h"
29 29
 
30 30
 
31
-thread_t *pdb_pe_thread;
32
-
33 31
 enum policy_engine_state {
34 32
     PESinkStartup,
35 33
     PESinkDiscovery,
@@ -709,6 +707,6 @@ static THD_FUNCTION(PolicyEngine, vcfg) {
709 707
 
710 708
 void pdb_pe_run(struct pdb_config *cfg)
711 709
 {
712
-    pdb_pe_thread = chThdCreateStatic(cfg->pe._wa, sizeof(cfg->pe._wa),
710
+    cfg->pe.thread = chThdCreateStatic(cfg->pe._wa, sizeof(cfg->pe._wa),
713 711
             PDB_PRIO_PE, PolicyEngine, cfg);
714 712
 }

+ 1
- 1
lib/src/protocol_rx.c View File

@@ -139,7 +139,7 @@ static enum protocol_rx_state protocol_rx_store_messageid(struct pdb_config *cfg
139 139
 
140 140
     /* Pass the message to the policy engine. */
141 141
     chMBPost(&cfg->pe.mailbox, (msg_t) cfg->prl._rx_message, TIME_IMMEDIATE);
142
-    chEvtSignal(pdb_pe_thread, PDB_EVT_PE_MSG_RX);
142
+    chEvtSignal(cfg->pe.thread, PDB_EVT_PE_MSG_RX);
143 143
 
144 144
     /* Don't check if we got a RESET because we'd do nothing different. */
145 145
 

+ 3
- 3
lib/src/protocol_tx.c View File

@@ -58,7 +58,7 @@ static enum protocol_tx_state protocol_tx_phy_reset(struct pdb_config *cfg)
58 58
      * we failed to send it */
59 59
     if (cfg->prl._tx_message != NULL) {
60 60
         /* Tell the policy engine that we failed */
61
-        chEvtSignal(pdb_pe_thread, PDB_EVT_PE_TX_ERR);
61
+        chEvtSignal(cfg->pe.thread, PDB_EVT_PE_TX_ERR);
62 62
         /* Finish failing to send the message */
63 63
         cfg->prl._tx_message = NULL;
64 64
     }
@@ -195,7 +195,7 @@ static enum protocol_tx_state protocol_tx_transmission_error(struct pdb_config *
195 195
     cfg->prl._tx_messageidcounter = (cfg->prl._tx_messageidcounter + 1) % 8;
196 196
 
197 197
     /* Tell the policy engine that we failed */
198
-    chEvtSignal(pdb_pe_thread, PDB_EVT_PE_TX_ERR);
198
+    chEvtSignal(cfg->pe.thread, PDB_EVT_PE_TX_ERR);
199 199
 
200 200
     cfg->prl._tx_message = NULL;
201 201
     return PRLTxWaitMessage;
@@ -207,7 +207,7 @@ static enum protocol_tx_state protocol_tx_message_sent(struct pdb_config *cfg)
207 207
     cfg->prl._tx_messageidcounter = (cfg->prl._tx_messageidcounter + 1) % 8;
208 208
 
209 209
     /* Tell the policy engine that we succeeded */
210
-    chEvtSignal(pdb_pe_thread, PDB_EVT_PE_TX_DONE);
210
+    chEvtSignal(cfg->pe.thread, PDB_EVT_PE_TX_DONE);
211 211
 
212 212
     cfg->prl._tx_message = NULL;
213 213
     return PRLTxWaitMessage;

+ 1
- 1
src/main.c View File

@@ -104,7 +104,7 @@ static void setup(void)
104 104
     usbConnectBus(serusbcfg.usbp);
105 105
 
106 106
     /* Start the shell */
107
-    pdbs_shell();
107
+    pdbs_shell(&pdb_config);
108 108
 }
109 109
 
110 110
 /*

+ 9
- 4
src/shell.c View File

@@ -52,6 +52,9 @@ static struct pdbs_config tmpcfg = {
52 52
     .status = PDBS_CONFIG_STATUS_VALID
53 53
 };
54 54
 
55
+/* Pointer to the PD Buddy firmware library configuration */
56
+static struct pdb_config *pdb_config;
57
+
55 58
 /*
56 59
  * Helper functions for printing PDOs
57 60
  */
@@ -175,7 +178,7 @@ static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[])
175 178
 
176 179
     pdbs_config_flash_update(&tmpcfg);
177 180
 
178
-    chEvtSignal(pdb_pe_thread, PDB_EVT_PE_NEW_POWER);
181
+    chEvtSignal(pdb_config->pe.thread, PDB_EVT_PE_NEW_POWER);
179 182
 }
180 183
 
181 184
 static void cmd_load(BaseSequentialStream *chp, int argc, char *argv[])
@@ -329,10 +332,10 @@ static void cmd_output(BaseSequentialStream *chp, int argc, char *argv[])
329 332
         /* Set the output status and re-negotiate power */
330 333
         if (strcmp(argv[0], "enable") == 0) {
331 334
             pdb_dpm_output_enabled = true;
332
-            chEvtSignal(pdb_pe_thread, PDB_EVT_PE_NEW_POWER);
335
+            chEvtSignal(pdb_config->pe.thread, PDB_EVT_PE_NEW_POWER);
333 336
         } else if (strcmp(argv[0], "disable") == 0) {
334 337
             pdb_dpm_output_enabled = false;
335
-            chEvtSignal(pdb_pe_thread, PDB_EVT_PE_NEW_POWER);
338
+            chEvtSignal(pdb_config->pe.thread, PDB_EVT_PE_NEW_POWER);
336 339
         } else {
337 340
             /* Or, if the argument was invalid, print a usage message */
338 341
             chprintf(chp, "Usage: output [enable|disable]\r\n");
@@ -454,7 +457,7 @@ static bool cmdexec(const struct pdbs_shell_cmd *scp, BaseSequentialStream *chp,
454 457
 /*
455 458
  * PD Buddy Sink configuration shell
456 459
  */
457
-void pdbs_shell(void)
460
+void pdbs_shell(struct pdb_config *cfg)
458 461
 {
459 462
     int n;
460 463
     BaseSequentialStream *chp = shell_cfg.io;
@@ -462,6 +465,8 @@ void pdbs_shell(void)
462 465
     char *lp, *cmd, *tokp, line[PDB_SHELL_MAX_LINE_LENGTH];
463 466
     char *args[PDB_SHELL_MAX_ARGUMENTS + 1];
464 467
 
468
+    pdb_config = cfg;
469
+
465 470
     while (true) {
466 471
         /* Print the prompt */
467 472
         chprintf(chp, "PDBS) ");

+ 3
- 1
src/shell.h View File

@@ -37,6 +37,8 @@
37 37
 
38 38
 #include <ch.h>
39 39
 
40
+#include <pdb.h>
41
+
40 42
 #define PDB_SHELL_MAX_LINE_LENGTH 64
41 43
 #define PDB_SHELL_MAX_ARGUMENTS 2
42 44
 
@@ -55,7 +57,7 @@ struct pdbs_shell_cfg {
55 57
 };
56 58
 
57 59
 
58
-void pdbs_shell(void);
60
+void pdbs_shell(struct pdb_config *cfg);
59 61
 
60 62
 bool shellGetLine(BaseSequentialStream *chp, char *line, unsigned size);
61 63
 

Loading…
Cancel
Save