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
 /* The Policy Engine thread object */
37
 /* The Policy Engine thread object */
38
 extern thread_t *pdb_pe_thread;
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
  * Start the Policy Engine thread
41
  * Start the Policy Engine thread
45
  */
42
  */

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

60
 static bool min_power = false;
60
 static bool min_power = false;
61
 /* Keep track of how many hard resets we've sent */
61
 /* Keep track of how many hard resets we've sent */
62
 static int hard_reset_counter = 0;
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
 static enum policy_engine_state pe_sink_startup(struct pdb_config *cfg)
64
 static enum policy_engine_state pe_sink_startup(struct pdb_config *cfg)
68
 {
65
 {
110
     /* If we got a message */
107
     /* If we got a message */
111
     if (evt & PDB_EVT_PE_MSG_RX) {
108
     if (evt & PDB_EVT_PE_MSG_RX) {
112
         /* Get the message */
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
             /* If we got a Source_Capabilities message, read it. */
111
             /* If we got a Source_Capabilities message, read it. */
115
             if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_SOURCE_CAPABILITIES
112
             if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_SOURCE_CAPABILITIES
116
                     && PD_NUMOBJ_GET(policy_engine_message) > 0) {
113
                     && PD_NUMOBJ_GET(policy_engine_message) > 0) {
181
     }
178
     }
182
 
179
 
183
     /* Get the response message */
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
         /* If the source accepted our request, wait for the new power */
182
         /* If the source accepted our request, wait for the new power */
186
         if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_ACCEPT
183
         if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_ACCEPT
187
                 && PD_NUMOBJ_GET(policy_engine_message) == 0) {
184
                 && PD_NUMOBJ_GET(policy_engine_message) == 0) {
242
     }
239
     }
243
 
240
 
244
     /* If we received a message, read it */
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
         /* If we got a PS_RDY, handle it */
243
         /* If we got a PS_RDY, handle it */
247
         if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_PS_RDY
244
         if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_PS_RDY
248
                 && PD_NUMOBJ_GET(policy_engine_message) == 0) {
245
                 && PD_NUMOBJ_GET(policy_engine_message) == 0) {
324
 
321
 
325
     /* If we received a message */
322
     /* If we received a message */
326
     if (evt & PDB_EVT_PE_MSG_RX) {
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
             /* Ignore vendor-defined messages */
325
             /* Ignore vendor-defined messages */
329
             if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_VENDOR_DEFINED
326
             if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_VENDOR_DEFINED
330
                     && PD_NUMOBJ_GET(policy_engine_message) > 0) {
327
                     && PD_NUMOBJ_GET(policy_engine_message) > 0) {
581
     }
578
     }
582
 
579
 
583
     /* Get the response message */
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
         /* If the source accepted our soft reset, wait for capabilities. */
582
         /* If the source accepted our soft reset, wait for capabilities. */
586
         if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_ACCEPT
583
         if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_ACCEPT
587
                 && PD_NUMOBJ_GET(policy_engine_message) == 0) {
584
                 && PD_NUMOBJ_GET(policy_engine_message) == 0) {
659
 /*
656
 /*
660
  * Policy Engine state machine thread
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
     enum policy_engine_state state = PESinkStartup;
661
     enum policy_engine_state state = PESinkStartup;
664
 
662
 
665
     /* Initialize the mailbox */
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
     while (true) {
666
     while (true) {
669
         switch (state) {
667
         switch (state) {

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

138
     cfg->prl._rx_messageid = PD_MESSAGEID_GET(cfg->prl._rx_message);
138
     cfg->prl._rx_messageid = PD_MESSAGEID_GET(cfg->prl._rx_message);
139
 
139
 
140
     /* Pass the message to the policy engine. */
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
     chEvtSignal(pdb_pe_thread, PDB_EVT_PE_MSG_RX);
142
     chEvtSignal(pdb_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. */

Loading…
Cancel
Save