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 7 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
 {
88
 {
89
     /* Fetch a message from the protocol layer */
89
     /* Fetch a message from the protocol layer */
90
     eventmask_t evt = chEvtWaitAnyTimeout(PDB_EVT_PE_MSG_RX
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
     /* If we timed out waiting for Source_Capabilities, send a hard reset */
92
     /* If we timed out waiting for Source_Capabilities, send a hard reset */
93
     if (evt == 0) {
93
     if (evt == 0) {
94
         return PESinkHardReset;
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
     /* If we're too hot, we shouldn't negotiate power yet */
100
     /* If we're too hot, we shouldn't negotiate power yet */
97
     if (evt & PDB_EVT_PE_I_OVRTEMP) {
101
     if (evt & PDB_EVT_PE_I_OVRTEMP) {
98
         return PESinkWaitCap;
102
         return PESinkWaitCap;
144
     /* Transmit the request */
148
     /* Transmit the request */
145
     chMBPost(&pdb_prltx_mailbox, (msg_t) policy_engine_message, TIME_IMMEDIATE);
149
     chMBPost(&pdb_prltx_mailbox, (msg_t) policy_engine_message, TIME_IMMEDIATE);
146
     chEvtSignal(pdb_prltx_thread, PDB_EVT_PRLTX_MSG_TX);
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
     /* Free the sent message */
153
     /* Free the sent message */
149
     chPoolFree(&pdb_msg_pool, policy_engine_message);
154
     chPoolFree(&pdb_msg_pool, policy_engine_message);
150
     policy_engine_message = NULL;
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
     /* If the message transmission failed, send a hard reset */
160
     /* If the message transmission failed, send a hard reset */
152
     if ((evt & PDB_EVT_PE_TX_DONE) == 0) {
161
     if ((evt & PDB_EVT_PE_TX_DONE) == 0) {
153
         return PESinkHardReset;
162
         return PESinkHardReset;
154
     }
163
     }
155
 
164
 
156
     /* Wait for a response */
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
     /* If we didn't get a response before the timeout, send a hard reset */
172
     /* If we didn't get a response before the timeout, send a hard reset */
159
     if (evt == 0) {
173
     if (evt == 0) {
160
         return PESinkHardReset;
174
         return PESinkHardReset;
207
 static enum policy_engine_state pe_sink_transition_sink(void)
221
 static enum policy_engine_state pe_sink_transition_sink(void)
208
 {
222
 {
209
     /* Wait for the PS_RDY message */
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
     /* If no message was received, send a hard reset */
230
     /* If no message was received, send a hard reset */
212
     if (evt == 0) {
231
     if (evt == 0) {
213
         return PESinkHardReset;
232
         return PESinkHardReset;
364
     /* Transmit our capabilities */
383
     /* Transmit our capabilities */
365
     chMBPost(&pdb_prltx_mailbox, (msg_t) snk_cap, TIME_IMMEDIATE);
384
     chMBPost(&pdb_prltx_mailbox, (msg_t) snk_cap, TIME_IMMEDIATE);
366
     chEvtSignal(pdb_prltx_thread, PDB_EVT_PRLTX_MSG_TX);
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
     /* Free the Sink_Capabilities message */
389
     /* Free the Sink_Capabilities message */
370
     chPoolFree(&pdb_msg_pool, snk_cap);
390
     chPoolFree(&pdb_msg_pool, snk_cap);
371
     snk_cap = NULL;
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
     /* If the message transmission failed, send a hard reset */
397
     /* If the message transmission failed, send a hard reset */
374
     if ((evt & PDB_EVT_PE_TX_DONE) == 0) {
398
     if ((evt & PDB_EVT_PE_TX_DONE) == 0) {
375
         return PESinkHardReset;
399
         return PESinkHardReset;
426
     /* Transmit the Accept */
450
     /* Transmit the Accept */
427
     chMBPost(&pdb_prltx_mailbox, (msg_t) accept, TIME_IMMEDIATE);
451
     chMBPost(&pdb_prltx_mailbox, (msg_t) accept, TIME_IMMEDIATE);
428
     chEvtSignal(pdb_prltx_thread, PDB_EVT_PRLTX_MSG_TX);
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
     /* Free the sent message */
455
     /* Free the sent message */
431
     chPoolFree(&pdb_msg_pool, accept);
456
     chPoolFree(&pdb_msg_pool, accept);
432
     accept = NULL;
457
     accept = NULL;
458
+    /* If we got reset signaling, transition to default */
459
+    if (evt & PDB_EVT_PE_RESET) {
460
+        return PESinkTransitionDefault;
461
+    }
433
     /* If the message transmission failed, send a hard reset */
462
     /* If the message transmission failed, send a hard reset */
434
     if ((evt & PDB_EVT_PE_TX_DONE) == 0) {
463
     if ((evt & PDB_EVT_PE_TX_DONE) == 0) {
435
         return PESinkHardReset;
464
         return PESinkHardReset;
451
     /* Transmit the soft reset */
480
     /* Transmit the soft reset */
452
     chMBPost(&pdb_prltx_mailbox, (msg_t) softrst, TIME_IMMEDIATE);
481
     chMBPost(&pdb_prltx_mailbox, (msg_t) softrst, TIME_IMMEDIATE);
453
     chEvtSignal(pdb_prltx_thread, PDB_EVT_PRLTX_MSG_TX);
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
     /* Free the sent message */
485
     /* Free the sent message */
456
     chPoolFree(&pdb_msg_pool, softrst);
486
     chPoolFree(&pdb_msg_pool, softrst);
457
     softrst = NULL;
487
     softrst = NULL;
488
+    /* If we got reset signaling, transition to default */
489
+    if (evt & PDB_EVT_PE_RESET) {
490
+        return PESinkTransitionDefault;
491
+    }
458
     /* If the message transmission failed, send a hard reset */
492
     /* If the message transmission failed, send a hard reset */
459
     if ((evt & PDB_EVT_PE_TX_DONE) == 0) {
493
     if ((evt & PDB_EVT_PE_TX_DONE) == 0) {
460
         return PESinkHardReset;
494
         return PESinkHardReset;
461
     }
495
     }
462
 
496
 
463
     /* Wait for a response */
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
     /* If we didn't get a response before the timeout, send a hard reset */
504
     /* If we didn't get a response before the timeout, send a hard reset */
466
     if (evt == 0) {
505
     if (evt == 0) {
467
         return PESinkHardReset;
506
         return PESinkHardReset;
502
     /* Transmit the message */
541
     /* Transmit the message */
503
     chMBPost(&pdb_prltx_mailbox, (msg_t) reject, TIME_IMMEDIATE);
542
     chMBPost(&pdb_prltx_mailbox, (msg_t) reject, TIME_IMMEDIATE);
504
     chEvtSignal(pdb_prltx_thread, PDB_EVT_PRLTX_MSG_TX);
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
     /* Free the Reject message */
547
     /* Free the Reject message */
508
     chPoolFree(&pdb_msg_pool, reject);
548
     chPoolFree(&pdb_msg_pool, reject);
509
     reject = NULL;
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
     /* If the message transmission failed, send a soft reset */
555
     /* If the message transmission failed, send a soft reset */
512
     if ((evt & PDB_EVT_PE_TX_DONE) == 0) {
556
     if ((evt & PDB_EVT_PE_TX_DONE) == 0) {
513
         return PESinkSendSoftReset;
557
         return PESinkSendSoftReset;

Loading…
Cancel
Save