Browse Source

Use PE private variables from struct pdb_config

Clara Hobbs 6 years ago
parent
commit
5bc226847f
2 changed files with 123 additions and 130 deletions
  1. 8
    2
      lib/include/pdb_pe.h
  2. 115
    128
      lib/src/policy_engine.c

+ 8
- 2
lib/include/pdb_pe.h View File

@@ -29,14 +29,20 @@ struct pdb_pe {
29 29
     THD_WORKING_AREA(_wa, 128);
30 30
     thread_t *thread;
31 31
 
32
+    /* PE mailbox for received PD messages */
32 33
     mailbox_t mailbox;
33 34
 
34
-    union pd_msg *_policy_engine_message;
35
+    /* The received message we're currently working with */
36
+    union pd_msg *_message;
37
+    /* The most recent Request from the DPM */
35 38
     union pd_msg *_last_dpm_request;
36
-    bool _capability_match;
39
+    /* Whether or not we have an explicit contract */
37 40
     bool _explicit_contract;
41
+    /* Whether or not we're receiving minimum power */
38 42
     bool _min_power;
43
+    /* The number of hard resets we've sent */
39 44
     int8_t _hard_reset_counter;
45
+    /* Queue for the PE mailbox */
40 46
     msg_t _mailbox_queue[PDB_MSG_POOL_SIZE];
41 47
 };
42 48
 

+ 115
- 128
lib/src/policy_engine.c View File

@@ -48,23 +48,10 @@ enum policy_engine_state {
48 48
     PESinkSourceUnresponsive
49 49
 };
50 50
 
51
-/* The received message we're currently working with */
52
-static union pd_msg *policy_engine_message = NULL;
53
-/* The most recent Request from the DPM */
54
-static union pd_msg *last_dpm_request = NULL;
55
-/* Whether or not the source capabilities match our required power */
56
-static bool capability_match = false;
57
-/* Whether or not we have an explicit contract */
58
-static bool explicit_contract = false;
59
-/* Whether or not we're receiving minimum power*/
60
-static bool min_power = false;
61
-/* Keep track of how many hard resets we've sent */
62
-static int hard_reset_counter = 0;
63
-
64 51
 static enum policy_engine_state pe_sink_startup(struct pdb_config *cfg)
65 52
 {
66 53
     /* We don't have an explicit contract currently */
67
-    explicit_contract = false;
54
+    cfg->pe._explicit_contract = false;
68 55
     /* Tell the DPM that we've started negotiations */
69 56
     cfg->dpm.pd_start(cfg);
70 57
 
@@ -107,21 +94,21 @@ static enum policy_engine_state pe_sink_wait_cap(struct pdb_config *cfg)
107 94
     /* If we got a message */
108 95
     if (evt & PDB_EVT_PE_MSG_RX) {
109 96
         /* Get the message */
110
-        if (chMBFetch(&cfg->pe.mailbox, (msg_t *) &policy_engine_message, TIME_IMMEDIATE) == MSG_OK) {
97
+        if (chMBFetch(&cfg->pe.mailbox, (msg_t *) &cfg->pe._message, TIME_IMMEDIATE) == MSG_OK) {
111 98
             /* If we got a Source_Capabilities message, read it. */
112
-            if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_SOURCE_CAPABILITIES
113
-                    && PD_NUMOBJ_GET(policy_engine_message) > 0) {
99
+            if (PD_MSGTYPE_GET(cfg->pe._message) == PD_MSGTYPE_SOURCE_CAPABILITIES
100
+                    && PD_NUMOBJ_GET(cfg->pe._message) > 0) {
114 101
                 return PESinkEvalCap;
115 102
             /* If the message was a Soft_Reset, do the soft reset procedure */
116
-            } else if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_SOFT_RESET
117
-                    && PD_NUMOBJ_GET(policy_engine_message) == 0) {
118
-                chPoolFree(&pdb_msg_pool, policy_engine_message);
119
-                policy_engine_message = NULL;
103
+            } else if (PD_MSGTYPE_GET(cfg->pe._message) == PD_MSGTYPE_SOFT_RESET
104
+                    && PD_NUMOBJ_GET(cfg->pe._message) == 0) {
105
+                chPoolFree(&pdb_msg_pool, cfg->pe._message);
106
+                cfg->pe._message = NULL;
120 107
                 return PESinkSoftReset;
121 108
             /* If we got an unexpected message, reset */
122 109
             } else {
123 110
                 /* Free the received message */
124
-                chPoolFree(&pdb_msg_pool, policy_engine_message);
111
+                chPoolFree(&pdb_msg_pool, cfg->pe._message);
125 112
                 return PESinkHardReset;
126 113
             }
127 114
         }
@@ -134,16 +121,16 @@ static enum policy_engine_state pe_sink_wait_cap(struct pdb_config *cfg)
134 121
 static enum policy_engine_state pe_sink_eval_cap(struct pdb_config *cfg)
135 122
 {
136 123
     /* Get a message object for the request if we don't have one already */
137
-    if (last_dpm_request == NULL) {
138
-        last_dpm_request = chPoolAlloc(&pdb_msg_pool);
124
+    if (cfg->pe._last_dpm_request == NULL) {
125
+        cfg->pe._last_dpm_request = chPoolAlloc(&pdb_msg_pool);
139 126
     }
140 127
     /* Ask the DPM what to request */
141
-    capability_match = cfg->dpm.evaluate_capability(cfg, policy_engine_message,
142
-            last_dpm_request);
128
+    cfg->dpm.evaluate_capability(cfg, cfg->pe._message,
129
+            cfg->pe._last_dpm_request);
143 130
     /* It's up to the DPM to free the Source_Capabilities message, which it can
144 131
      * do whenever it sees fit.  Just remove our reference to it since we won't
145 132
      * know when it's no longer valid. */
146
-    policy_engine_message = NULL;
133
+    cfg->pe._message = NULL;
147 134
 
148 135
     return PESinkSelectCap;
149 136
 }
@@ -151,7 +138,7 @@ static enum policy_engine_state pe_sink_eval_cap(struct pdb_config *cfg)
151 138
 static enum policy_engine_state pe_sink_select_cap(struct pdb_config *cfg)
152 139
 {
153 140
     /* Transmit the request */
154
-    chMBPost(&cfg->prl.tx_mailbox, (msg_t) last_dpm_request, TIME_IMMEDIATE);
141
+    chMBPost(&cfg->prl.tx_mailbox, (msg_t) cfg->pe._last_dpm_request, TIME_IMMEDIATE);
155 142
     chEvtSignal(cfg->prl.tx_thread, PDB_EVT_PRLTX_MSG_TX);
156 143
     eventmask_t evt = chEvtWaitAny(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR
157 144
             | PDB_EVT_PE_RESET);
@@ -178,46 +165,46 @@ static enum policy_engine_state pe_sink_select_cap(struct pdb_config *cfg)
178 165
     }
179 166
 
180 167
     /* Get the response message */
181
-    if (chMBFetch(&cfg->pe.mailbox, (msg_t *) &policy_engine_message, TIME_IMMEDIATE) == MSG_OK) {
168
+    if (chMBFetch(&cfg->pe.mailbox, (msg_t *) &cfg->pe._message, TIME_IMMEDIATE) == MSG_OK) {
182 169
         /* If the source accepted our request, wait for the new power */
183
-        if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_ACCEPT
184
-                && PD_NUMOBJ_GET(policy_engine_message) == 0) {
170
+        if (PD_MSGTYPE_GET(cfg->pe._message) == PD_MSGTYPE_ACCEPT
171
+                && PD_NUMOBJ_GET(cfg->pe._message) == 0) {
185 172
             /* Transition to Sink Standby if necessary */
186 173
             cfg->dpm.transition_standby(cfg);
187 174
 
188
-            min_power = false;
175
+            cfg->pe._min_power = false;
189 176
 
190
-            chPoolFree(&pdb_msg_pool, policy_engine_message);
191
-            policy_engine_message = NULL;
177
+            chPoolFree(&pdb_msg_pool, cfg->pe._message);
178
+            cfg->pe._message = NULL;
192 179
             return PESinkTransitionSink;
193 180
         /* If the message was a Soft_Reset, do the soft reset procedure */
194
-        } else if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_SOFT_RESET
195
-                && PD_NUMOBJ_GET(policy_engine_message) == 0) {
196
-            chPoolFree(&pdb_msg_pool, policy_engine_message);
197
-            policy_engine_message = NULL;
181
+        } else if (PD_MSGTYPE_GET(cfg->pe._message) == PD_MSGTYPE_SOFT_RESET
182
+                && PD_NUMOBJ_GET(cfg->pe._message) == 0) {
183
+            chPoolFree(&pdb_msg_pool, cfg->pe._message);
184
+            cfg->pe._message = NULL;
198 185
             return PESinkSoftReset;
199 186
         /* If the message was Wait or Reject */
200
-        } else if ((PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_REJECT
201
-                    || PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_WAIT)
202
-                && PD_NUMOBJ_GET(policy_engine_message) == 0) {
187
+        } else if ((PD_MSGTYPE_GET(cfg->pe._message) == PD_MSGTYPE_REJECT
188
+                    || PD_MSGTYPE_GET(cfg->pe._message) == PD_MSGTYPE_WAIT)
189
+                && PD_NUMOBJ_GET(cfg->pe._message) == 0) {
203 190
             /* If we don't have an explicit contract, wait for capabilities */
204
-            if (!explicit_contract) {
205
-                chPoolFree(&pdb_msg_pool, policy_engine_message);
206
-                policy_engine_message = NULL;
191
+            if (!cfg->pe._explicit_contract) {
192
+                chPoolFree(&pdb_msg_pool, cfg->pe._message);
193
+                cfg->pe._message = NULL;
207 194
                 return PESinkWaitCap;
208 195
             /* If we do have an explicit contract, go to the ready state */
209 196
             } else {
210 197
                 /* If we got here from a Wait message, we Should run
211 198
                  * SinkRequestTimer in the Ready state. */
212
-                min_power = (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_WAIT);
199
+                cfg->pe._min_power = (PD_MSGTYPE_GET(cfg->pe._message) == PD_MSGTYPE_WAIT);
213 200
 
214
-                chPoolFree(&pdb_msg_pool, policy_engine_message);
215
-                policy_engine_message = NULL;
201
+                chPoolFree(&pdb_msg_pool, cfg->pe._message);
202
+                cfg->pe._message = NULL;
216 203
                 return PESinkReady;
217 204
             }
218 205
         } else {
219
-            chPoolFree(&pdb_msg_pool, policy_engine_message);
220
-            policy_engine_message = NULL;
206
+            chPoolFree(&pdb_msg_pool, cfg->pe._message);
207
+            cfg->pe._message = NULL;
221 208
             return PESinkSendSoftReset;
222 209
         }
223 210
     }
@@ -239,20 +226,20 @@ static enum policy_engine_state pe_sink_transition_sink(struct pdb_config *cfg)
239 226
     }
240 227
 
241 228
     /* If we received a message, read it */
242
-    if (chMBFetch(&cfg->pe.mailbox, (msg_t *) &policy_engine_message, TIME_IMMEDIATE) == MSG_OK) {
229
+    if (chMBFetch(&cfg->pe.mailbox, (msg_t *) &cfg->pe._message, TIME_IMMEDIATE) == MSG_OK) {
243 230
         /* If we got a PS_RDY, handle it */
244
-        if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_PS_RDY
245
-                && PD_NUMOBJ_GET(policy_engine_message) == 0) {
231
+        if (PD_MSGTYPE_GET(cfg->pe._message) == PD_MSGTYPE_PS_RDY
232
+                && PD_NUMOBJ_GET(cfg->pe._message) == 0) {
246 233
             /* We just finished negotiating an explicit contract */
247
-            explicit_contract = true;
234
+            cfg->pe._explicit_contract = true;
248 235
 
249 236
             /* Set the output appropriately */
250
-            if (!min_power) {
237
+            if (!cfg->pe._min_power) {
251 238
                 cfg->dpm.transition_requested(cfg);
252 239
             }
253 240
 
254
-            chPoolFree(&pdb_msg_pool, policy_engine_message);
255
-            policy_engine_message = NULL;
241
+            chPoolFree(&pdb_msg_pool, cfg->pe._message);
242
+            cfg->pe._message = NULL;
256 243
             return PESinkReady;
257 244
         /* If there was a protocol error, send a hard reset */
258 245
         } else {
@@ -261,8 +248,8 @@ static enum policy_engine_state pe_sink_transition_sink(struct pdb_config *cfg)
261 248
              */
262 249
             cfg->dpm.transition_default(cfg);
263 250
 
264
-            chPoolFree(&pdb_msg_pool, policy_engine_message);
265
-            policy_engine_message = NULL;
251
+            chPoolFree(&pdb_msg_pool, cfg->pe._message);
252
+            cfg->pe._message = NULL;
266 253
             return PESinkHardReset;
267 254
         }
268 255
     }
@@ -275,7 +262,7 @@ static enum policy_engine_state pe_sink_ready(struct pdb_config *cfg)
275 262
     eventmask_t evt;
276 263
 
277 264
     /* Wait for an event */
278
-    if (min_power) {
265
+    if (cfg->pe._min_power) {
279 266
         evt = chEvtWaitAnyTimeout(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET
280 267
                 | PDB_EVT_PE_I_OVRTEMP | PDB_EVT_PE_GET_SOURCE_CAP
281 268
                 | PDB_EVT_PE_NEW_POWER, PD_T_SINK_REQUEST);
@@ -306,9 +293,9 @@ static enum policy_engine_state pe_sink_ready(struct pdb_config *cfg)
306 293
      * design of this firmware. */
307 294
     if (evt & PDB_EVT_PE_NEW_POWER) {
308 295
         /* Make sure we're evaluating NULL capabilities to use the old ones */
309
-        if (policy_engine_message != NULL) {
310
-            chPoolFree(&pdb_msg_pool, policy_engine_message);
311
-            policy_engine_message = NULL;
296
+        if (cfg->pe._message != NULL) {
297
+            chPoolFree(&pdb_msg_pool, cfg->pe._message);
298
+            cfg->pe._message = NULL;
312 299
         }
313 300
         return PESinkEvalCap;
314 301
     }
@@ -321,94 +308,94 @@ static enum policy_engine_state pe_sink_ready(struct pdb_config *cfg)
321 308
 
322 309
     /* If we received a message */
323 310
     if (evt & PDB_EVT_PE_MSG_RX) {
324
-        if (chMBFetch(&cfg->pe.mailbox, (msg_t *) &policy_engine_message, TIME_IMMEDIATE) == MSG_OK) {
311
+        if (chMBFetch(&cfg->pe.mailbox, (msg_t *) &cfg->pe._message, TIME_IMMEDIATE) == MSG_OK) {
325 312
             /* Ignore vendor-defined messages */
326
-            if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_VENDOR_DEFINED
327
-                    && PD_NUMOBJ_GET(policy_engine_message) > 0) {
328
-                chPoolFree(&pdb_msg_pool, policy_engine_message);
329
-                policy_engine_message = NULL;
313
+            if (PD_MSGTYPE_GET(cfg->pe._message) == PD_MSGTYPE_VENDOR_DEFINED
314
+                    && PD_NUMOBJ_GET(cfg->pe._message) > 0) {
315
+                chPoolFree(&pdb_msg_pool, cfg->pe._message);
316
+                cfg->pe._message = NULL;
330 317
                 return PESinkReady;
331 318
             /* Ignore Ping messages */
332
-            } else if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_PING
333
-                    && PD_NUMOBJ_GET(policy_engine_message) == 0) {
334
-                chPoolFree(&pdb_msg_pool, policy_engine_message);
335
-                policy_engine_message = NULL;
319
+            } else if (PD_MSGTYPE_GET(cfg->pe._message) == PD_MSGTYPE_PING
320
+                    && PD_NUMOBJ_GET(cfg->pe._message) == 0) {
321
+                chPoolFree(&pdb_msg_pool, cfg->pe._message);
322
+                cfg->pe._message = NULL;
336 323
                 return PESinkReady;
337 324
             /* Reject DR_Swap messages */
338
-            } else if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_DR_SWAP
339
-                    && PD_NUMOBJ_GET(policy_engine_message) == 0) {
340
-                chPoolFree(&pdb_msg_pool, policy_engine_message);
341
-                policy_engine_message = NULL;
325
+            } else if (PD_MSGTYPE_GET(cfg->pe._message) == PD_MSGTYPE_DR_SWAP
326
+                    && PD_NUMOBJ_GET(cfg->pe._message) == 0) {
327
+                chPoolFree(&pdb_msg_pool, cfg->pe._message);
328
+                cfg->pe._message = NULL;
342 329
                 return PESinkSendReject;
343 330
             /* Reject Get_Source_Cap messages */
344
-            } else if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_GET_SOURCE_CAP
345
-                    && PD_NUMOBJ_GET(policy_engine_message) == 0) {
346
-                chPoolFree(&pdb_msg_pool, policy_engine_message);
347
-                policy_engine_message = NULL;
331
+            } else if (PD_MSGTYPE_GET(cfg->pe._message) == PD_MSGTYPE_GET_SOURCE_CAP
332
+                    && PD_NUMOBJ_GET(cfg->pe._message) == 0) {
333
+                chPoolFree(&pdb_msg_pool, cfg->pe._message);
334
+                cfg->pe._message = NULL;
348 335
                 return PESinkSendReject;
349 336
             /* Reject PR_Swap messages */
350
-            } else if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_PR_SWAP
351
-                    && PD_NUMOBJ_GET(policy_engine_message) == 0) {
352
-                chPoolFree(&pdb_msg_pool, policy_engine_message);
353
-                policy_engine_message = NULL;
337
+            } else if (PD_MSGTYPE_GET(cfg->pe._message) == PD_MSGTYPE_PR_SWAP
338
+                    && PD_NUMOBJ_GET(cfg->pe._message) == 0) {
339
+                chPoolFree(&pdb_msg_pool, cfg->pe._message);
340
+                cfg->pe._message = NULL;
354 341
                 return PESinkSendReject;
355 342
             /* Reject VCONN_Swap messages */
356
-            } else if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_VCONN_SWAP
357
-                    && PD_NUMOBJ_GET(policy_engine_message) == 0) {
358
-                chPoolFree(&pdb_msg_pool, policy_engine_message);
359
-                policy_engine_message = NULL;
343
+            } else if (PD_MSGTYPE_GET(cfg->pe._message) == PD_MSGTYPE_VCONN_SWAP
344
+                    && PD_NUMOBJ_GET(cfg->pe._message) == 0) {
345
+                chPoolFree(&pdb_msg_pool, cfg->pe._message);
346
+                cfg->pe._message = NULL;
360 347
                 return PESinkSendReject;
361 348
             /* Reject Request messages */
362
-            } else if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_REQUEST
363
-                    && PD_NUMOBJ_GET(policy_engine_message) > 0) {
364
-                chPoolFree(&pdb_msg_pool, policy_engine_message);
365
-                policy_engine_message = NULL;
349
+            } else if (PD_MSGTYPE_GET(cfg->pe._message) == PD_MSGTYPE_REQUEST
350
+                    && PD_NUMOBJ_GET(cfg->pe._message) > 0) {
351
+                chPoolFree(&pdb_msg_pool, cfg->pe._message);
352
+                cfg->pe._message = NULL;
366 353
                 return PESinkSendReject;
367 354
             /* Reject Sink_Capabilities messages */
368
-            } else if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_SINK_CAPABILITIES
369
-                    && PD_NUMOBJ_GET(policy_engine_message) > 0) {
370
-                chPoolFree(&pdb_msg_pool, policy_engine_message);
371
-                policy_engine_message = NULL;
355
+            } else if (PD_MSGTYPE_GET(cfg->pe._message) == PD_MSGTYPE_SINK_CAPABILITIES
356
+                    && PD_NUMOBJ_GET(cfg->pe._message) > 0) {
357
+                chPoolFree(&pdb_msg_pool, cfg->pe._message);
358
+                cfg->pe._message = NULL;
372 359
                 return PESinkSendReject;
373 360
             /* Handle GotoMin messages */
374
-            } else if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_GOTOMIN
375
-                    && PD_NUMOBJ_GET(policy_engine_message) == 0) {
361
+            } else if (PD_MSGTYPE_GET(cfg->pe._message) == PD_MSGTYPE_GOTOMIN
362
+                    && PD_NUMOBJ_GET(cfg->pe._message) == 0) {
376 363
                 if (cfg->dpm.giveback_enabled(cfg)) {
377 364
                     /* Transition to the minimum current level */
378 365
                     cfg->dpm.transition_min(cfg);
379
-                    min_power = true;
366
+                    cfg->pe._min_power = true;
380 367
 
381
-                    chPoolFree(&pdb_msg_pool, policy_engine_message);
382
-                    policy_engine_message = NULL;
368
+                    chPoolFree(&pdb_msg_pool, cfg->pe._message);
369
+                    cfg->pe._message = NULL;
383 370
                     return PESinkTransitionSink;
384 371
                 } else {
385 372
                     /* We don't support GiveBack, so send a Reject */
386
-                    chPoolFree(&pdb_msg_pool, policy_engine_message);
387
-                    policy_engine_message = NULL;
373
+                    chPoolFree(&pdb_msg_pool, cfg->pe._message);
374
+                    cfg->pe._message = NULL;
388 375
                     return PESinkSendReject;
389 376
                 }
390 377
             /* Evaluate new Source_Capabilities */
391
-            } else if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_SOURCE_CAPABILITIES
392
-                    && PD_NUMOBJ_GET(policy_engine_message) > 0) {
378
+            } else if (PD_MSGTYPE_GET(cfg->pe._message) == PD_MSGTYPE_SOURCE_CAPABILITIES
379
+                    && PD_NUMOBJ_GET(cfg->pe._message) > 0) {
393 380
                 /* Don't free the message: we need to keep the
394 381
                  * Source_Capabilities message so we can evaluate it. */
395 382
                 return PESinkEvalCap;
396 383
             /* Give sink capabilities when asked */
397
-            } else if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_GET_SINK_CAP
398
-                    && PD_NUMOBJ_GET(policy_engine_message) == 0) {
399
-                chPoolFree(&pdb_msg_pool, policy_engine_message);
400
-                policy_engine_message = NULL;
384
+            } else if (PD_MSGTYPE_GET(cfg->pe._message) == PD_MSGTYPE_GET_SINK_CAP
385
+                    && PD_NUMOBJ_GET(cfg->pe._message) == 0) {
386
+                chPoolFree(&pdb_msg_pool, cfg->pe._message);
387
+                cfg->pe._message = NULL;
401 388
                 return PESinkGiveSinkCap;
402 389
             /* If the message was a Soft_Reset, do the soft reset procedure */
403
-            } else if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_SOFT_RESET
404
-                    && PD_NUMOBJ_GET(policy_engine_message) == 0) {
405
-                chPoolFree(&pdb_msg_pool, policy_engine_message);
406
-                policy_engine_message = NULL;
390
+            } else if (PD_MSGTYPE_GET(cfg->pe._message) == PD_MSGTYPE_SOFT_RESET
391
+                    && PD_NUMOBJ_GET(cfg->pe._message) == 0) {
392
+                chPoolFree(&pdb_msg_pool, cfg->pe._message);
393
+                cfg->pe._message = NULL;
407 394
                 return PESinkSoftReset;
408 395
             /* If we got an unknown message, send a soft reset */
409 396
             } else {
410
-                chPoolFree(&pdb_msg_pool, policy_engine_message);
411
-                policy_engine_message = NULL;
397
+                chPoolFree(&pdb_msg_pool, cfg->pe._message);
398
+                cfg->pe._message = NULL;
412 399
                 return PESinkSendSoftReset;
413 400
             }
414 401
         }
@@ -477,7 +464,7 @@ static enum policy_engine_state pe_sink_hard_reset(struct pdb_config *cfg)
477 464
 {
478 465
     /* If we've already sent the maximum number of hard resets, assume the
479 466
      * source is unresponsive. */
480
-    if (hard_reset_counter > PD_N_HARD_RESET_COUNT) {
467
+    if (cfg->pe._hard_reset_counter > PD_N_HARD_RESET_COUNT) {
481 468
         return PESinkSourceUnresponsive;
482 469
     }
483 470
 
@@ -486,14 +473,14 @@ static enum policy_engine_state pe_sink_hard_reset(struct pdb_config *cfg)
486 473
     chEvtWaitAny(PDB_EVT_PE_HARD_SENT);
487 474
 
488 475
     /* Increment HardResetCounter */
489
-    hard_reset_counter++;
476
+    cfg->pe._hard_reset_counter++;
490 477
 
491 478
     return PESinkTransitionDefault;
492 479
 }
493 480
 
494 481
 static enum policy_engine_state pe_sink_transition_default(struct pdb_config *cfg)
495 482
 {
496
-    explicit_contract = false;
483
+    cfg->pe._explicit_contract = false;
497 484
 
498 485
     /* Tell the DPM to transition to default power */
499 486
     cfg->dpm.transition_default(cfg);
@@ -578,23 +565,23 @@ static enum policy_engine_state pe_sink_send_soft_reset(struct pdb_config *cfg)
578 565
     }
579 566
 
580 567
     /* Get the response message */
581
-    if (chMBFetch(&cfg->pe.mailbox, (msg_t *) &policy_engine_message, TIME_IMMEDIATE) == MSG_OK) {
568
+    if (chMBFetch(&cfg->pe.mailbox, (msg_t *) &cfg->pe._message, TIME_IMMEDIATE) == MSG_OK) {
582 569
         /* If the source accepted our soft reset, wait for capabilities. */
583
-        if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_ACCEPT
584
-                && PD_NUMOBJ_GET(policy_engine_message) == 0) {
585
-            chPoolFree(&pdb_msg_pool, policy_engine_message);
586
-            policy_engine_message = NULL;
570
+        if (PD_MSGTYPE_GET(cfg->pe._message) == PD_MSGTYPE_ACCEPT
571
+                && PD_NUMOBJ_GET(cfg->pe._message) == 0) {
572
+            chPoolFree(&pdb_msg_pool, cfg->pe._message);
573
+            cfg->pe._message = NULL;
587 574
             return PESinkWaitCap;
588 575
         /* If the message was a Soft_Reset, do the soft reset procedure */
589
-        } else if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_SOFT_RESET
590
-                && PD_NUMOBJ_GET(policy_engine_message) == 0) {
591
-            chPoolFree(&pdb_msg_pool, policy_engine_message);
592
-            policy_engine_message = NULL;
576
+        } else if (PD_MSGTYPE_GET(cfg->pe._message) == PD_MSGTYPE_SOFT_RESET
577
+                && PD_NUMOBJ_GET(cfg->pe._message) == 0) {
578
+            chPoolFree(&pdb_msg_pool, cfg->pe._message);
579
+            cfg->pe._message = NULL;
593 580
             return PESinkSoftReset;
594 581
         /* Otherwise, send a hard reset */
595 582
         } else {
596
-            chPoolFree(&pdb_msg_pool, policy_engine_message);
597
-            policy_engine_message = NULL;
583
+            chPoolFree(&pdb_msg_pool, cfg->pe._message);
584
+            cfg->pe._message = NULL;
598 585
             return PESinkHardReset;
599 586
         }
600 587
     }

Loading…
Cancel
Save