Browse Source

Check for hard reset signaling in more places

The policy engine is supposed to transition to the
PE_SNK_Transition_to_default state from any state when hard reset
signaling is received.  While it still doesn't do that exactly, in every
state that already waited for events, the PDB_EVT_PE_RESET event is also
checked, with the appropriate transition being made if the event is
received.

My justification for not checking for the event in other states is that
if there's no wait, the reset will be received soon by another state
anyway.  Besides, if there's no event handling already, where exactly
would be best to insert a test for the event?
Clara Hobbs 5 years ago
parent
commit
d87660036f
1 changed files with 53 additions and 9 deletions
  1. 53
    9
      src/policy_engine.c

+ 53
- 9
src/policy_engine.c View File

@@ -88,11 +88,15 @@ static enum policy_engine_state pe_sink_wait_cap(void)
88 88
 {
89 89
     /* Fetch a message from the protocol layer */
90 90
     eventmask_t evt = chEvtWaitAnyTimeout(PDB_EVT_PE_MSG_RX
91
-            | PDB_EVT_PE_I_OVRTEMP, PD_T_TYPEC_SINK_WAIT_CAP);
91
+            | PDB_EVT_PE_I_OVRTEMP | PDB_EVT_PE_RESET, PD_T_TYPEC_SINK_WAIT_CAP);
92 92
     /* If we timed out waiting for Source_Capabilities, send a hard reset */
93 93
     if (evt == 0) {
94 94
         return PESinkHardReset;
95 95
     }
96
+    /* If we got reset signaling, transition to default */
97
+    if (evt & PDB_EVT_PE_RESET) {
98
+        return PESinkTransitionDefault;
99
+    }
96 100
     /* If we're too hot, we shouldn't negotiate power yet */
97 101
     if (evt & PDB_EVT_PE_I_OVRTEMP) {
98 102
         return PESinkWaitCap;
@@ -144,17 +148,27 @@ static enum policy_engine_state pe_sink_select_cap(void)
144 148
     /* Transmit the request */
145 149
     chMBPost(&pdb_prltx_mailbox, (msg_t) policy_engine_message, TIME_IMMEDIATE);
146 150
     chEvtSignal(pdb_prltx_thread, PDB_EVT_PRLTX_MSG_TX);
147
-    eventmask_t evt = chEvtWaitAny(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR);
151
+    eventmask_t evt = chEvtWaitAny(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR
152
+            | PDB_EVT_PE_RESET);
148 153
     /* Free the sent message */
149 154
     chPoolFree(&pdb_msg_pool, policy_engine_message);
150 155
     policy_engine_message = NULL;
156
+    /* If we got reset signaling, transition to default */
157
+    if (evt & PDB_EVT_PE_RESET) {
158
+        return PESinkTransitionDefault;
159
+    }
151 160
     /* If the message transmission failed, send a hard reset */
152 161
     if ((evt & PDB_EVT_PE_TX_DONE) == 0) {
153 162
         return PESinkHardReset;
154 163
     }
155 164
 
156 165
     /* Wait for a response */
157
-    evt = chEvtWaitAnyTimeout(PDB_EVT_PE_MSG_RX, PD_T_SENDER_RESPONSE);
166
+    evt = chEvtWaitAnyTimeout(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET,
167
+            PD_T_SENDER_RESPONSE);
168
+    /* If we got reset signaling, transition to default */
169
+    if (evt & PDB_EVT_PE_RESET) {
170
+        return PESinkTransitionDefault;
171
+    }
158 172
     /* If we didn't get a response before the timeout, send a hard reset */
159 173
     if (evt == 0) {
160 174
         return PESinkHardReset;
@@ -207,7 +221,12 @@ static enum policy_engine_state pe_sink_select_cap(void)
207 221
 static enum policy_engine_state pe_sink_transition_sink(void)
208 222
 {
209 223
     /* Wait for the PS_RDY message */
210
-    eventmask_t evt = chEvtWaitAnyTimeout(PDB_EVT_PE_MSG_RX, PD_T_PS_TRANSITION);
224
+    eventmask_t evt = chEvtWaitAnyTimeout(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET,
225
+            PD_T_PS_TRANSITION);
226
+    /* If we got reset signaling, transition to default */
227
+    if (evt & PDB_EVT_PE_RESET) {
228
+        return PESinkTransitionDefault;
229
+    }
211 230
     /* If no message was received, send a hard reset */
212 231
     if (evt == 0) {
213 232
         return PESinkHardReset;
@@ -364,12 +383,17 @@ static enum policy_engine_state pe_sink_give_sink_cap(void)
364 383
     /* Transmit our capabilities */
365 384
     chMBPost(&pdb_prltx_mailbox, (msg_t) snk_cap, TIME_IMMEDIATE);
366 385
     chEvtSignal(pdb_prltx_thread, PDB_EVT_PRLTX_MSG_TX);
367
-    eventmask_t evt = chEvtWaitAny(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR);
386
+    eventmask_t evt = chEvtWaitAny(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR
387
+            | PDB_EVT_PE_RESET);
368 388
 
369 389
     /* Free the Sink_Capabilities message */
370 390
     chPoolFree(&pdb_msg_pool, snk_cap);
371 391
     snk_cap = NULL;
372 392
 
393
+    /* If we got reset signaling, transition to default */
394
+    if (evt & PDB_EVT_PE_RESET) {
395
+        return PESinkTransitionDefault;
396
+    }
373 397
     /* If the message transmission failed, send a hard reset */
374 398
     if ((evt & PDB_EVT_PE_TX_DONE) == 0) {
375 399
         return PESinkHardReset;
@@ -426,10 +450,15 @@ static enum policy_engine_state pe_sink_soft_reset(void)
426 450
     /* Transmit the Accept */
427 451
     chMBPost(&pdb_prltx_mailbox, (msg_t) accept, TIME_IMMEDIATE);
428 452
     chEvtSignal(pdb_prltx_thread, PDB_EVT_PRLTX_MSG_TX);
429
-    eventmask_t evt = chEvtWaitAny(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR);
453
+    eventmask_t evt = chEvtWaitAny(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR
454
+            | PDB_EVT_PE_RESET);
430 455
     /* Free the sent message */
431 456
     chPoolFree(&pdb_msg_pool, accept);
432 457
     accept = NULL;
458
+    /* If we got reset signaling, transition to default */
459
+    if (evt & PDB_EVT_PE_RESET) {
460
+        return PESinkTransitionDefault;
461
+    }
433 462
     /* If the message transmission failed, send a hard reset */
434 463
     if ((evt & PDB_EVT_PE_TX_DONE) == 0) {
435 464
         return PESinkHardReset;
@@ -451,17 +480,27 @@ static enum policy_engine_state pe_sink_send_soft_reset(void)
451 480
     /* Transmit the soft reset */
452 481
     chMBPost(&pdb_prltx_mailbox, (msg_t) softrst, TIME_IMMEDIATE);
453 482
     chEvtSignal(pdb_prltx_thread, PDB_EVT_PRLTX_MSG_TX);
454
-    eventmask_t evt = chEvtWaitAny(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR);
483
+    eventmask_t evt = chEvtWaitAny(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR
484
+            | PDB_EVT_PE_RESET);
455 485
     /* Free the sent message */
456 486
     chPoolFree(&pdb_msg_pool, softrst);
457 487
     softrst = NULL;
488
+    /* If we got reset signaling, transition to default */
489
+    if (evt & PDB_EVT_PE_RESET) {
490
+        return PESinkTransitionDefault;
491
+    }
458 492
     /* If the message transmission failed, send a hard reset */
459 493
     if ((evt & PDB_EVT_PE_TX_DONE) == 0) {
460 494
         return PESinkHardReset;
461 495
     }
462 496
 
463 497
     /* Wait for a response */
464
-    evt = chEvtWaitAnyTimeout(PDB_EVT_PE_MSG_RX, PD_T_SENDER_RESPONSE);
498
+    evt = chEvtWaitAnyTimeout(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET,
499
+            PD_T_SENDER_RESPONSE);
500
+    /* If we got reset signaling, transition to default */
501
+    if (evt & PDB_EVT_PE_RESET) {
502
+        return PESinkTransitionDefault;
503
+    }
465 504
     /* If we didn't get a response before the timeout, send a hard reset */
466 505
     if (evt == 0) {
467 506
         return PESinkHardReset;
@@ -502,12 +541,17 @@ static enum policy_engine_state pe_sink_send_reject(void)
502 541
     /* Transmit the message */
503 542
     chMBPost(&pdb_prltx_mailbox, (msg_t) reject, TIME_IMMEDIATE);
504 543
     chEvtSignal(pdb_prltx_thread, PDB_EVT_PRLTX_MSG_TX);
505
-    eventmask_t evt = chEvtWaitAny(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR);
544
+    eventmask_t evt = chEvtWaitAny(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR
545
+            | PDB_EVT_PE_RESET);
506 546
 
507 547
     /* Free the Reject message */
508 548
     chPoolFree(&pdb_msg_pool, reject);
509 549
     reject = NULL;
510 550
 
551
+    /* If we got reset signaling, transition to default */
552
+    if (evt & PDB_EVT_PE_RESET) {
553
+        return PESinkTransitionDefault;
554
+    }
511 555
     /* If the message transmission failed, send a soft reset */
512 556
     if ((evt & PDB_EVT_PE_TX_DONE) == 0) {
513 557
         return PESinkSendSoftReset;

Loading…
Cancel
Save