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
 #define PDB_EVT_PE_GET_SOURCE_CAP EVENT_MASK(6)
34
 #define PDB_EVT_PE_GET_SOURCE_CAP EVENT_MASK(6)
35
 #define PDB_EVT_PE_NEW_POWER EVENT_MASK(7)
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
  * Start the Policy Engine thread
38
  * Start the Policy Engine thread
42
  */
39
  */

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

72
 
72
 
73
 static enum hardrst_state hardrst_indicate_hard_reset(struct pdb_config *cfg)
73
 static enum hardrst_state hardrst_indicate_hard_reset(struct pdb_config *cfg)
74
 {
74
 {
75
-    (void) cfg;
76
     /* Tell the PE that we're doing a hard reset */
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
     return PRLHRWaitPE;
78
     return PRLHRWaitPE;
80
 }
79
 }
100
 
99
 
101
 static enum hardrst_state hardrst_hard_reset_requested(struct pdb_config *cfg)
100
 static enum hardrst_state hardrst_hard_reset_requested(struct pdb_config *cfg)
102
 {
101
 {
103
-    (void) cfg;
104
     /* Tell the PE that the hard reset was sent */
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
     return PRLHRWaitPE;
105
     return PRLHRWaitPE;
108
 }
106
 }

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

76
              * Engine thread */
76
              * Engine thread */
77
             if (status.interrupta & FUSB_INTERRUPTA_I_OCP_TEMP
77
             if (status.interrupta & FUSB_INTERRUPTA_I_OCP_TEMP
78
                     && status.status1 & FUSB_STATUS1_OVRTEMP) {
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
 #include "pd.h"
28
 #include "pd.h"
29
 
29
 
30
 
30
 
31
-thread_t *pdb_pe_thread;
32
-
33
 enum policy_engine_state {
31
 enum policy_engine_state {
34
     PESinkStartup,
32
     PESinkStartup,
35
     PESinkDiscovery,
33
     PESinkDiscovery,
709
 
707
 
710
 void pdb_pe_run(struct pdb_config *cfg)
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
             PDB_PRIO_PE, PolicyEngine, cfg);
711
             PDB_PRIO_PE, PolicyEngine, cfg);
714
 }
712
 }

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

139
 
139
 
140
     /* Pass the message to the policy engine. */
140
     /* Pass the message to the policy engine. */
141
     chMBPost(&cfg->pe.mailbox, (msg_t) cfg->prl._rx_message, TIME_IMMEDIATE);
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
     /* Don't check if we got a RESET because we'd do nothing different. */
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
      * we failed to send it */
58
      * we failed to send it */
59
     if (cfg->prl._tx_message != NULL) {
59
     if (cfg->prl._tx_message != NULL) {
60
         /* Tell the policy engine that we failed */
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
         /* Finish failing to send the message */
62
         /* Finish failing to send the message */
63
         cfg->prl._tx_message = NULL;
63
         cfg->prl._tx_message = NULL;
64
     }
64
     }
195
     cfg->prl._tx_messageidcounter = (cfg->prl._tx_messageidcounter + 1) % 8;
195
     cfg->prl._tx_messageidcounter = (cfg->prl._tx_messageidcounter + 1) % 8;
196
 
196
 
197
     /* Tell the policy engine that we failed */
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
     cfg->prl._tx_message = NULL;
200
     cfg->prl._tx_message = NULL;
201
     return PRLTxWaitMessage;
201
     return PRLTxWaitMessage;
207
     cfg->prl._tx_messageidcounter = (cfg->prl._tx_messageidcounter + 1) % 8;
207
     cfg->prl._tx_messageidcounter = (cfg->prl._tx_messageidcounter + 1) % 8;
208
 
208
 
209
     /* Tell the policy engine that we succeeded */
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
     cfg->prl._tx_message = NULL;
212
     cfg->prl._tx_message = NULL;
213
     return PRLTxWaitMessage;
213
     return PRLTxWaitMessage;

+ 1
- 1
src/main.c View File

104
     usbConnectBus(serusbcfg.usbp);
104
     usbConnectBus(serusbcfg.usbp);
105
 
105
 
106
     /* Start the shell */
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
     .status = PDBS_CONFIG_STATUS_VALID
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
  * Helper functions for printing PDOs
59
  * Helper functions for printing PDOs
57
  */
60
  */
175
 
178
 
176
     pdbs_config_flash_update(&tmpcfg);
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
 static void cmd_load(BaseSequentialStream *chp, int argc, char *argv[])
184
 static void cmd_load(BaseSequentialStream *chp, int argc, char *argv[])
329
         /* Set the output status and re-negotiate power */
332
         /* Set the output status and re-negotiate power */
330
         if (strcmp(argv[0], "enable") == 0) {
333
         if (strcmp(argv[0], "enable") == 0) {
331
             pdb_dpm_output_enabled = true;
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
         } else if (strcmp(argv[0], "disable") == 0) {
336
         } else if (strcmp(argv[0], "disable") == 0) {
334
             pdb_dpm_output_enabled = false;
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
         } else {
339
         } else {
337
             /* Or, if the argument was invalid, print a usage message */
340
             /* Or, if the argument was invalid, print a usage message */
338
             chprintf(chp, "Usage: output [enable|disable]\r\n");
341
             chprintf(chp, "Usage: output [enable|disable]\r\n");
454
 /*
457
 /*
455
  * PD Buddy Sink configuration shell
458
  * PD Buddy Sink configuration shell
456
  */
459
  */
457
-void pdbs_shell(void)
460
+void pdbs_shell(struct pdb_config *cfg)
458
 {
461
 {
459
     int n;
462
     int n;
460
     BaseSequentialStream *chp = shell_cfg.io;
463
     BaseSequentialStream *chp = shell_cfg.io;
462
     char *lp, *cmd, *tokp, line[PDB_SHELL_MAX_LINE_LENGTH];
465
     char *lp, *cmd, *tokp, line[PDB_SHELL_MAX_LINE_LENGTH];
463
     char *args[PDB_SHELL_MAX_ARGUMENTS + 1];
466
     char *args[PDB_SHELL_MAX_ARGUMENTS + 1];
464
 
467
 
468
+    pdb_config = cfg;
469
+
465
     while (true) {
470
     while (true) {
466
         /* Print the prompt */
471
         /* Print the prompt */
467
         chprintf(chp, "PDBS) ");
472
         chprintf(chp, "PDBS) ");

+ 3
- 1
src/shell.h View File

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

Loading…
Cancel
Save