浏览代码

Added over-temperature protection

I think so, anyway.  Testing with a heat gun didn't result in the Sink
resetting itself, so I'm not confident that I understand the FUSB302B's
over-temperature sensing mechanism.

I must point out though that I'm not confident that this
over-temperature protection is even useful.  The PD Buddy Sink doesn't
get hot on its own, and if it did, it might not even be from the device
it's powering, making a hard reset useless.  The spec says that we Shall
implement over temperature protection though, and that we Shall send a
Hard Reset message when it engages, so even though I take issue with the
requirement, I'll try to do what the standard says I Shall.
Clara Hobbs 7 年前
父节点
当前提交
5fff5280aa
共有 3 个文件被更改,包括 45 次插入19 次删除
  1. 9
    0
      src/int_n.c
  2. 35
    19
      src/policy_engine.c
  3. 1
    0
      src/policy_engine.h

+ 9
- 0
src/int_n.c 查看文件

@@ -26,6 +26,7 @@
26 26
 #include "protocol_rx.h"
27 27
 #include "protocol_tx.h"
28 28
 #include "hard_reset.h"
29
+#include "policy_engine.h"
29 30
 
30 31
 
31 32
 /*
@@ -70,6 +71,14 @@ static THD_FUNCTION(IntNPoll, arg) {
70 71
                 events |= PDB_EVT_HARDRST_I_HARDSENT;
71 72
             }
72 73
             chEvtSignal(pdb_hardrst_thread, events);
74
+
75
+            /* If the I_OCP_TEMP and OVRTEMP flags are set, tell the Policy
76
+             * Engine thread */
77
+            if (status.interrupta & FUSB_INTERRUPTA_I_OCP_TEMP
78
+                    && status.status1 & FUSB_STATUS1_OVRTEMP) {
79
+                chEvtSignal(pdb_pe_thread, PDB_EVT_PE_I_OVRTEMP);
80
+            }
81
+
73 82
         }
74 83
         chThdSleepMilliseconds(1);
75 84
     }

+ 35
- 19
src/policy_engine.c 查看文件

@@ -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) {

+ 1
- 0
src/policy_engine.h 查看文件

@@ -28,6 +28,7 @@
28 28
 #define PDB_EVT_PE_TX_DONE EVENT_MASK(2)
29 29
 #define PDB_EVT_PE_TX_ERR EVENT_MASK(3)
30 30
 #define PDB_EVT_PE_HARD_SENT EVENT_MASK(4)
31
+#define PDB_EVT_PE_I_OVRTEMP EVENT_MASK(5)
31 32
 
32 33
 /* The Policy Engine thread object */
33 34
 extern thread_t *pdb_pe_thread;

正在加载...
取消
保存