|
@@ -62,7 +62,9 @@ mailbox_t pdb_pe_mailbox;
|
62
|
62
|
|
63
|
63
|
static enum policy_engine_state pe_sink_startup(void)
|
64
|
64
|
{
|
|
65
|
+ /* We don't have an explicit contract currently */
|
65
|
66
|
explicit_contract = false;
|
|
67
|
+ /* Tell the DPM that we've started negotiations */
|
66
|
68
|
pdb_dpm_pd_start();
|
67
|
69
|
|
68
|
70
|
/* No need to reset the protocol layer here. There are two ways into this
|
|
@@ -85,29 +87,37 @@ static enum policy_engine_state pe_sink_discovery(void)
|
85
|
87
|
static enum policy_engine_state pe_sink_wait_cap(void)
|
86
|
88
|
{
|
87
|
89
|
/* Fetch a message from the protocol layer */
|
88
|
|
- eventmask_t evt = chEvtWaitAnyTimeout(PDB_EVT_PE_MSG_RX, PD_T_TYPEC_SINK_WAIT_CAP);
|
|
90
|
+ eventmask_t evt = chEvtWaitAnyTimeout(PDB_EVT_PE_MSG_RX
|
|
91
|
+ | PDB_EVT_PE_I_OVRTEMP, PD_T_TYPEC_SINK_WAIT_CAP);
|
89
|
92
|
/* If we timed out waiting for Source_Capabilities, send a hard reset */
|
90
|
93
|
if (evt == 0) {
|
91
|
94
|
return PESinkHardReset;
|
92
|
95
|
}
|
|
96
|
+ /* If we're too hot, we shouldn't negotiate power yet */
|
|
97
|
+ if (evt & PDB_EVT_PE_I_OVRTEMP) {
|
|
98
|
+ return PESinkWaitCap;
|
|
99
|
+ }
|
93
|
100
|
|
94
|
|
- /* Get the message */
|
95
|
|
- if (chMBFetch(&pdb_pe_mailbox, (msg_t *) &policy_engine_message, TIME_IMMEDIATE) == MSG_OK) {
|
96
|
|
- /* If we got a Source_Capabilities message, read it. */
|
97
|
|
- if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_SOURCE_CAPABILITIES
|
98
|
|
- && PD_NUMOBJ_GET(policy_engine_message) > 0) {
|
99
|
|
- return PESinkEvalCap;
|
100
|
|
- /* If the message was a Soft_Reset, do the soft reset procedure */
|
101
|
|
- } else if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_SOFT_RESET
|
102
|
|
- && PD_NUMOBJ_GET(policy_engine_message) == 0) {
|
103
|
|
- chPoolFree(&pdb_msg_pool, policy_engine_message);
|
104
|
|
- policy_engine_message = NULL;
|
105
|
|
- return PESinkSoftReset;
|
106
|
|
- /* If we got an unexpected message, reset */
|
107
|
|
- } else {
|
108
|
|
- /* Free the received message */
|
109
|
|
- chPoolFree(&pdb_msg_pool, policy_engine_message);
|
110
|
|
- return PESinkHardReset;
|
|
101
|
+ /* If we got a message */
|
|
102
|
+ if (evt & PDB_EVT_PE_MSG_RX) {
|
|
103
|
+ /* Get the message */
|
|
104
|
+ if (chMBFetch(&pdb_pe_mailbox, (msg_t *) &policy_engine_message, TIME_IMMEDIATE) == MSG_OK) {
|
|
105
|
+ /* If we got a Source_Capabilities message, read it. */
|
|
106
|
+ if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_SOURCE_CAPABILITIES
|
|
107
|
+ && PD_NUMOBJ_GET(policy_engine_message) > 0) {
|
|
108
|
+ return PESinkEvalCap;
|
|
109
|
+ /* If the message was a Soft_Reset, do the soft reset procedure */
|
|
110
|
+ } else if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_SOFT_RESET
|
|
111
|
+ && PD_NUMOBJ_GET(policy_engine_message) == 0) {
|
|
112
|
+ chPoolFree(&pdb_msg_pool, policy_engine_message);
|
|
113
|
+ policy_engine_message = NULL;
|
|
114
|
+ return PESinkSoftReset;
|
|
115
|
+ /* If we got an unexpected message, reset */
|
|
116
|
+ } else {
|
|
117
|
+ /* Free the received message */
|
|
118
|
+ chPoolFree(&pdb_msg_pool, policy_engine_message);
|
|
119
|
+ return PESinkHardReset;
|
|
120
|
+ }
|
111
|
121
|
}
|
112
|
122
|
}
|
113
|
123
|
|
|
@@ -236,13 +246,19 @@ static enum policy_engine_state pe_sink_transition_sink(void)
|
236
|
246
|
static enum policy_engine_state pe_sink_ready(void)
|
237
|
247
|
{
|
238
|
248
|
/* Wait for an event */
|
239
|
|
- eventmask_t evt = chEvtWaitAny(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET);
|
|
249
|
+ eventmask_t evt = chEvtWaitAny(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET
|
|
250
|
+ | PDB_EVT_PE_I_OVRTEMP);
|
240
|
251
|
|
241
|
252
|
/* If we got reset signaling, transition to default */
|
242
|
253
|
if (evt & PDB_EVT_PE_RESET) {
|
243
|
254
|
return PESinkTransitionDefault;
|
244
|
255
|
}
|
245
|
256
|
|
|
257
|
+ /* If we overheated, send a hard reset */
|
|
258
|
+ if (evt & PDB_EVT_PE_I_OVRTEMP) {
|
|
259
|
+ return PESinkHardReset;
|
|
260
|
+ }
|
|
261
|
+
|
246
|
262
|
/* If we received a message */
|
247
|
263
|
if (evt & PDB_EVT_PE_MSG_RX) {
|
248
|
264
|
if (chMBFetch(&pdb_pe_mailbox, (msg_t *) &policy_engine_message, TIME_IMMEDIATE) == MSG_OK) {
|