Browse Source

Use the PE mailbox in the struct pdb_config

Clara Hobbs 6 years ago
parent
commit
c29afa1ec6
3 changed files with 9 additions and 14 deletions
  1. 0
    3
      lib/include/policy_engine.h
  2. 8
    10
      lib/src/policy_engine.c
  3. 1
    1
      lib/src/protocol_rx.c

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

@@ -37,9 +37,6 @@
37 37
 /* The Policy Engine thread object */
38 38
 extern thread_t *pdb_pe_thread;
39 39
 
40
-/* Policy Engine thread mailbox */
41
-extern mailbox_t pdb_pe_mailbox;
42
-
43 40
 /*
44 41
  * Start the Policy Engine thread
45 42
  */

+ 8
- 10
lib/src/policy_engine.c View File

@@ -60,9 +60,6 @@ static bool explicit_contract = false;
60 60
 static bool min_power = false;
61 61
 /* Keep track of how many hard resets we've sent */
62 62
 static int hard_reset_counter = 0;
63
-/* Policy Engine thread mailbox */
64
-static msg_t pdb_pe_mailbox_queue[PDB_MSG_POOL_SIZE];
65
-mailbox_t pdb_pe_mailbox;
66 63
 
67 64
 static enum policy_engine_state pe_sink_startup(struct pdb_config *cfg)
68 65
 {
@@ -110,7 +107,7 @@ static enum policy_engine_state pe_sink_wait_cap(struct pdb_config *cfg)
110 107
     /* If we got a message */
111 108
     if (evt & PDB_EVT_PE_MSG_RX) {
112 109
         /* Get the message */
113
-        if (chMBFetch(&pdb_pe_mailbox, (msg_t *) &policy_engine_message, TIME_IMMEDIATE) == MSG_OK) {
110
+        if (chMBFetch(&cfg->pe.mailbox, (msg_t *) &policy_engine_message, TIME_IMMEDIATE) == MSG_OK) {
114 111
             /* If we got a Source_Capabilities message, read it. */
115 112
             if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_SOURCE_CAPABILITIES
116 113
                     && PD_NUMOBJ_GET(policy_engine_message) > 0) {
@@ -181,7 +178,7 @@ static enum policy_engine_state pe_sink_select_cap(struct pdb_config *cfg)
181 178
     }
182 179
 
183 180
     /* Get the response message */
184
-    if (chMBFetch(&pdb_pe_mailbox, (msg_t *) &policy_engine_message, TIME_IMMEDIATE) == MSG_OK) {
181
+    if (chMBFetch(&cfg->pe.mailbox, (msg_t *) &policy_engine_message, TIME_IMMEDIATE) == MSG_OK) {
185 182
         /* If the source accepted our request, wait for the new power */
186 183
         if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_ACCEPT
187 184
                 && PD_NUMOBJ_GET(policy_engine_message) == 0) {
@@ -242,7 +239,7 @@ static enum policy_engine_state pe_sink_transition_sink(struct pdb_config *cfg)
242 239
     }
243 240
 
244 241
     /* If we received a message, read it */
245
-    if (chMBFetch(&pdb_pe_mailbox, (msg_t *) &policy_engine_message, TIME_IMMEDIATE) == MSG_OK) {
242
+    if (chMBFetch(&cfg->pe.mailbox, (msg_t *) &policy_engine_message, TIME_IMMEDIATE) == MSG_OK) {
246 243
         /* If we got a PS_RDY, handle it */
247 244
         if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_PS_RDY
248 245
                 && PD_NUMOBJ_GET(policy_engine_message) == 0) {
@@ -324,7 +321,7 @@ static enum policy_engine_state pe_sink_ready(struct pdb_config *cfg)
324 321
 
325 322
     /* If we received a message */
326 323
     if (evt & PDB_EVT_PE_MSG_RX) {
327
-        if (chMBFetch(&pdb_pe_mailbox, (msg_t *) &policy_engine_message, TIME_IMMEDIATE) == MSG_OK) {
324
+        if (chMBFetch(&cfg->pe.mailbox, (msg_t *) &policy_engine_message, TIME_IMMEDIATE) == MSG_OK) {
328 325
             /* Ignore vendor-defined messages */
329 326
             if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_VENDOR_DEFINED
330 327
                     && PD_NUMOBJ_GET(policy_engine_message) > 0) {
@@ -581,7 +578,7 @@ static enum policy_engine_state pe_sink_send_soft_reset(struct pdb_config *cfg)
581 578
     }
582 579
 
583 580
     /* Get the response message */
584
-    if (chMBFetch(&pdb_pe_mailbox, (msg_t *) &policy_engine_message, TIME_IMMEDIATE) == MSG_OK) {
581
+    if (chMBFetch(&cfg->pe.mailbox, (msg_t *) &policy_engine_message, TIME_IMMEDIATE) == MSG_OK) {
585 582
         /* If the source accepted our soft reset, wait for capabilities. */
586 583
         if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_ACCEPT
587 584
                 && PD_NUMOBJ_GET(policy_engine_message) == 0) {
@@ -659,11 +656,12 @@ static enum policy_engine_state pe_sink_source_unresponsive(struct pdb_config *c
659 656
 /*
660 657
  * Policy Engine state machine thread
661 658
  */
662
-static THD_FUNCTION(PolicyEngine, cfg) {
659
+static THD_FUNCTION(PolicyEngine, vcfg) {
660
+    struct pdb_config *cfg = vcfg;
663 661
     enum policy_engine_state state = PESinkStartup;
664 662
 
665 663
     /* Initialize the mailbox */
666
-    chMBObjectInit(&pdb_pe_mailbox, pdb_pe_mailbox_queue, PDB_MSG_POOL_SIZE);
664
+    chMBObjectInit(&cfg->pe.mailbox, cfg->pe._mailbox_queue, PDB_MSG_POOL_SIZE);
667 665
 
668 666
     while (true) {
669 667
         switch (state) {

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

@@ -138,7 +138,7 @@ static enum protocol_rx_state protocol_rx_store_messageid(struct pdb_config *cfg
138 138
     cfg->prl._rx_messageid = PD_MESSAGEID_GET(cfg->prl._rx_message);
139 139
 
140 140
     /* Pass the message to the policy engine. */
141
-    chMBPost(&pdb_pe_mailbox, (msg_t) cfg->prl._rx_message, TIME_IMMEDIATE);
141
+    chMBPost(&cfg->pe.mailbox, (msg_t) cfg->prl._rx_message, TIME_IMMEDIATE);
142 142
     chEvtSignal(pdb_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. */

Loading…
Cancel
Save