Преглед изворни кода

Reference the PRLRX thread by the new struct

Clara Hobbs пре 7 година
родитељ
комит
22ead74015
5 измењених фајлова са 50 додато и 43 уклоњено
  1. 21
    16
      lib/src/hard_reset.c
  2. 1
    1
      lib/src/int_n.c
  3. 1
    3
      lib/src/protocol_rx.c
  4. 0
    3
      lib/src/protocol_rx.h
  5. 27
    20
      lib/src/protocol_tx.c

+ 21
- 16
lib/src/hard_reset.c Прегледај датотеку

@@ -42,7 +42,7 @@ enum hardrst_state {
42 42
 /*
43 43
  * PRL_HR_Reset_Layer state
44 44
  */
45
-static enum hardrst_state hardrst_reset_layer(void)
45
+static enum hardrst_state hardrst_reset_layer(struct pdb_config *cfg)
46 46
 {
47 47
     /* First, wait for the signal to run a hard reset. */
48 48
     eventmask_t evt = chEvtWaitAny(PDB_EVT_HARDRST_RESET
@@ -53,7 +53,7 @@ static enum hardrst_state hardrst_reset_layer(void)
53 53
     pdb_prltx_messageidcounter = 0;
54 54
 
55 55
     /* Reset the Protocol RX machine */
56
-    chEvtSignal(pdb_prlrx_thread, PDB_EVT_PRLRX_RESET);
56
+    chEvtSignal(cfg->prl.rx_thread, PDB_EVT_PRLRX_RESET);
57 57
     chThdYield();
58 58
 
59 59
     /* Reset the Protocol TX machine */
@@ -70,24 +70,27 @@ static enum hardrst_state hardrst_reset_layer(void)
70 70
     }
71 71
 }
72 72
 
73
-static enum hardrst_state hardrst_indicate_hard_reset(void)
73
+static enum hardrst_state hardrst_indicate_hard_reset(struct pdb_config *cfg)
74 74
 {
75
+    (void) cfg;
75 76
     /* Tell the PE that we're doing a hard reset */
76 77
     chEvtSignal(pdb_pe_thread, PDB_EVT_PE_RESET);
77 78
 
78 79
     return PRLHRWaitPE;
79 80
 }
80 81
 
81
-static enum hardrst_state hardrst_request_hard_reset(void)
82
+static enum hardrst_state hardrst_request_hard_reset(struct pdb_config *cfg)
82 83
 {
84
+    (void) cfg;
83 85
     /* Tell the PHY to send a hard reset */
84 86
     fusb_send_hardrst();
85 87
 
86 88
     return PRLHRWaitPHY;
87 89
 }
88 90
 
89
-static enum hardrst_state hardrst_wait_phy(void)
91
+static enum hardrst_state hardrst_wait_phy(struct pdb_config *cfg)
90 92
 {
93
+    (void) cfg;
91 94
     /* Wait for the PHY to tell us that it's done sending the hard reset */
92 95
     chEvtWaitAnyTimeout(PDB_EVT_HARDRST_I_HARDSENT, PD_T_HARD_RESET_COMPLETE);
93 96
 
@@ -95,24 +98,27 @@ static enum hardrst_state hardrst_wait_phy(void)
95 98
     return PRLHRHardResetRequested;
96 99
 }
97 100
 
98
-static enum hardrst_state hardrst_hard_reset_requested(void)
101
+static enum hardrst_state hardrst_hard_reset_requested(struct pdb_config *cfg)
99 102
 {
103
+    (void) cfg;
100 104
     /* Tell the PE that the hard reset was sent */
101 105
     chEvtSignal(pdb_pe_thread, PDB_EVT_PE_HARD_SENT);
102 106
 
103 107
     return PRLHRWaitPE;
104 108
 }
105 109
 
106
-static enum hardrst_state hardrst_wait_pe(void)
110
+static enum hardrst_state hardrst_wait_pe(struct pdb_config *cfg)
107 111
 {
112
+    (void) cfg;
108 113
     /* Wait for the PE to tell us that it's done */
109 114
     chEvtWaitAny(PDB_EVT_HARDRST_DONE);
110 115
 
111 116
     return PRLHRComplete;
112 117
 }
113 118
 
114
-static enum hardrst_state hardrst_complete(void)
119
+static enum hardrst_state hardrst_complete(struct pdb_config *cfg)
115 120
 {
121
+    (void) cfg;
116 122
     /* I'm not aware of anything we have to tell the FUSB302B, so just finish
117 123
      * the reset routine. */
118 124
     return PRLHRResetLayer;
@@ -122,31 +128,30 @@ static enum hardrst_state hardrst_complete(void)
122 128
  * Hard Reset state machine thread
123 129
  */
124 130
 static THD_FUNCTION(HardReset, cfg) {
125
-    (void) cfg;
126 131
     enum hardrst_state state = PRLHRResetLayer;
127 132
 
128 133
     while (true) {
129 134
         switch (state) {
130 135
             case PRLHRResetLayer:
131
-                state = hardrst_reset_layer();
136
+                state = hardrst_reset_layer(cfg);
132 137
                 break;
133 138
             case PRLHRIndicateHardReset:
134
-                state = hardrst_indicate_hard_reset();
139
+                state = hardrst_indicate_hard_reset(cfg);
135 140
                 break;
136 141
             case PRLHRRequestHardReset:
137
-                state = hardrst_request_hard_reset();
142
+                state = hardrst_request_hard_reset(cfg);
138 143
                 break;
139 144
             case PRLHRWaitPHY:
140
-                state = hardrst_wait_phy();
145
+                state = hardrst_wait_phy(cfg);
141 146
                 break;
142 147
             case PRLHRHardResetRequested:
143
-                state = hardrst_hard_reset_requested();
148
+                state = hardrst_hard_reset_requested(cfg);
144 149
                 break;
145 150
             case PRLHRWaitPE:
146
-                state = hardrst_wait_pe();
151
+                state = hardrst_wait_pe(cfg);
147 152
                 break;
148 153
             case PRLHRComplete:
149
-                state = hardrst_complete();
154
+                state = hardrst_complete(cfg);
150 155
                 break;
151 156
             default:
152 157
                 /* This is an error.  It really shouldn't happen.  We might

+ 1
- 1
lib/src/int_n.c Прегледај датотеку

@@ -47,7 +47,7 @@ static THD_FUNCTION(IntNPoll, vcfg) {
47 47
 
48 48
             /* If the I_GCRCSENT flag is set, tell the Protocol RX thread */
49 49
             if (status.interruptb & FUSB_INTERRUPTB_I_GCRCSENT) {
50
-                chEvtSignal(pdb_prlrx_thread, PDB_EVT_PRLRX_I_GCRCSENT);
50
+                chEvtSignal(cfg->prl.rx_thread, PDB_EVT_PRLRX_I_GCRCSENT);
51 51
             }
52 52
 
53 53
             /* If the I_TXSENT or I_RETRYFAIL flag is set, tell the Protocol TX

+ 1
- 3
lib/src/protocol_rx.c Прегледај датотеку

@@ -28,8 +28,6 @@
28 28
 #include "pd.h"
29 29
 
30 30
 
31
-thread_t *pdb_prlrx_thread;
32
-
33 31
 /*
34 32
  * Protocol RX machine states
35 33
  *
@@ -184,6 +182,6 @@ static THD_FUNCTION(ProtocolRX, cfg) {
184 182
 
185 183
 void pdb_prlrx_run(struct pdb_config *cfg)
186 184
 {
187
-    pdb_prlrx_thread = chThdCreateStatic(cfg->prl._rx_wa,
185
+    cfg->prl.rx_thread = chThdCreateStatic(cfg->prl._rx_wa,
188 186
             sizeof(cfg->prl._rx_wa), PDB_PRIO_PRL, ProtocolRX, cfg);
189 187
 }

+ 0
- 3
lib/src/protocol_rx.h Прегледај датотеку

@@ -30,9 +30,6 @@
30 30
 #define PDB_EVT_PRLRX_RESET EVENT_MASK(0)
31 31
 #define PDB_EVT_PRLRX_I_GCRCSENT EVENT_MASK(1)
32 32
 
33
-/* The Protocol RX thread object */
34
-extern thread_t *pdb_prlrx_thread;
35
-
36 33
 /* The last received MessageID */
37 34
 extern int8_t pdb_prlrx_messageid;
38 35
 

+ 27
- 20
lib/src/protocol_tx.c Прегледај датотеку

@@ -60,8 +60,9 @@ int8_t pdb_prltx_messageidcounter = 0;
60 60
 /*
61 61
  * PRL_Tx_PHY_Layer_Reset state
62 62
  */
63
-static enum protocol_tx_state protocol_tx_phy_reset(void)
63
+static enum protocol_tx_state protocol_tx_phy_reset(struct pdb_config *cfg)
64 64
 {
65
+    (void) cfg;
65 66
     /* Reset the PHY */
66 67
     fusb_reset();
67 68
 
@@ -81,8 +82,9 @@ static enum protocol_tx_state protocol_tx_phy_reset(void)
81 82
 /*
82 83
  * PRL_Tx_Wait_for_Message_Request state
83 84
  */
84
-static enum protocol_tx_state protocol_tx_wait_message(void)
85
+static enum protocol_tx_state protocol_tx_wait_message(struct pdb_config *cfg)
85 86
 {
87
+    (void) cfg;
86 88
     /* Wait for an event */
87 89
     eventmask_t evt = chEvtWaitAny(PDB_EVT_PRLTX_RESET | PDB_EVT_PRLTX_DISCARD
88 90
             | PDB_EVT_PRLTX_MSG_TX);
@@ -112,13 +114,13 @@ static enum protocol_tx_state protocol_tx_wait_message(void)
112 114
     return PRLTxDiscardMessage;
113 115
 }
114 116
 
115
-static enum protocol_tx_state protocol_tx_reset(void)
117
+static enum protocol_tx_state protocol_tx_reset(struct pdb_config *cfg)
116 118
 {
117 119
     /* Clear MessageIDCounter */
118 120
     pdb_prltx_messageidcounter = 0;
119 121
 
120 122
     /* Tell the Protocol RX thread to reset */
121
-    chEvtSignal(pdb_prlrx_thread, PDB_EVT_PRLRX_RESET);
123
+    chEvtSignal(cfg->prl.rx_thread, PDB_EVT_PRLRX_RESET);
122 124
     chThdYield();
123 125
 
124 126
     return PRLTxConstructMessage;
@@ -127,8 +129,9 @@ static enum protocol_tx_state protocol_tx_reset(void)
127 129
 /*
128 130
  * PRL_Tx_Construct_Message state
129 131
  */
130
-static enum protocol_tx_state protocol_tx_construct_message(void)
132
+static enum protocol_tx_state protocol_tx_construct_message(struct pdb_config *cfg)
131 133
 {
134
+    (void) cfg;
132 135
     /* Make sure nobody wants us to reset */
133 136
     eventmask_t evt = chEvtGetAndClearEvents(PDB_EVT_PRLTX_RESET | PDB_EVT_PRLTX_DISCARD);
134 137
 
@@ -152,8 +155,9 @@ static enum protocol_tx_state protocol_tx_construct_message(void)
152 155
 /*
153 156
  * PRL_Tx_Wait_for_PHY_Response state
154 157
  */
155
-static enum protocol_tx_state protocol_tx_wait_response(void)
158
+static enum protocol_tx_state protocol_tx_wait_response(struct pdb_config *cfg)
156 159
 {
160
+    (void) cfg;
157 161
     /* Wait for an event.  There is no need to run CRCReceiveTimer, since the
158 162
      * FUSB302B handles that as part of its retry mechanism. */
159 163
     eventmask_t evt = chEvtWaitAny(PDB_EVT_PRLTX_RESET | PDB_EVT_PRLTX_DISCARD
@@ -182,8 +186,9 @@ static enum protocol_tx_state protocol_tx_wait_response(void)
182 186
 /*
183 187
  * PRL_Tx_Match_MessageID state
184 188
  */
185
-static enum protocol_tx_state protocol_tx_match_messageid(void)
189
+static enum protocol_tx_state protocol_tx_match_messageid(struct pdb_config *cfg)
186 190
 {
191
+    (void) cfg;
187 192
     union pd_msg goodcrc;
188 193
 
189 194
     /* Read the GoodCRC */
@@ -199,8 +204,9 @@ static enum protocol_tx_state protocol_tx_match_messageid(void)
199 204
     }
200 205
 }
201 206
 
202
-static enum protocol_tx_state protocol_tx_transmission_error(void)
207
+static enum protocol_tx_state protocol_tx_transmission_error(struct pdb_config *cfg)
203 208
 {
209
+    (void) cfg;
204 210
     /* Increment MessageIDCounter */
205 211
     pdb_prltx_messageidcounter = (pdb_prltx_messageidcounter + 1) % 8;
206 212
 
@@ -211,8 +217,9 @@ static enum protocol_tx_state protocol_tx_transmission_error(void)
211 217
     return PRLTxWaitMessage;
212 218
 }
213 219
 
214
-static enum protocol_tx_state protocol_tx_message_sent(void)
220
+static enum protocol_tx_state protocol_tx_message_sent(struct pdb_config *cfg)
215 221
 {
222
+    (void) cfg;
216 223
     /* Increment MessageIDCounter */
217 224
     pdb_prltx_messageidcounter = (pdb_prltx_messageidcounter + 1) % 8;
218 225
 
@@ -223,8 +230,9 @@ static enum protocol_tx_state protocol_tx_message_sent(void)
223 230
     return PRLTxWaitMessage;
224 231
 }
225 232
 
226
-static enum protocol_tx_state protocol_tx_discard_message(void)
233
+static enum protocol_tx_state protocol_tx_discard_message(struct pdb_config *cfg)
227 234
 {
235
+    (void) cfg;
228 236
     /* If we were working on sending a message, increment MessageIDCounter */
229 237
     if (protocol_tx_message != NULL) {
230 238
         pdb_prltx_messageidcounter = (pdb_prltx_messageidcounter + 1) % 8;
@@ -237,7 +245,6 @@ static enum protocol_tx_state protocol_tx_discard_message(void)
237 245
  * Protocol layer TX state machine thread
238 246
  */
239 247
 static THD_FUNCTION(ProtocolTX, cfg) {
240
-    (void) cfg;
241 248
 
242 249
     enum protocol_tx_state state = PRLTxPHYReset;
243 250
 
@@ -247,31 +254,31 @@ static THD_FUNCTION(ProtocolTX, cfg) {
247 254
     while (true) {
248 255
         switch (state) {
249 256
             case PRLTxPHYReset:
250
-                state = protocol_tx_phy_reset();
257
+                state = protocol_tx_phy_reset(cfg);
251 258
                 break;
252 259
             case PRLTxWaitMessage:
253
-                state = protocol_tx_wait_message();
260
+                state = protocol_tx_wait_message(cfg);
254 261
                 break;
255 262
             case PRLTxReset:
256
-                state = protocol_tx_reset();
263
+                state = protocol_tx_reset(cfg);
257 264
                 break;
258 265
             case PRLTxConstructMessage:
259
-                state = protocol_tx_construct_message();
266
+                state = protocol_tx_construct_message(cfg);
260 267
                 break;
261 268
             case PRLTxWaitResponse:
262
-                state = protocol_tx_wait_response();
269
+                state = protocol_tx_wait_response(cfg);
263 270
                 break;
264 271
             case PRLTxMatchMessageID:
265
-                state = protocol_tx_match_messageid();
272
+                state = protocol_tx_match_messageid(cfg);
266 273
                 break;
267 274
             case PRLTxTransmissionError:
268
-                state = protocol_tx_transmission_error();
275
+                state = protocol_tx_transmission_error(cfg);
269 276
                 break;
270 277
             case PRLTxMessageSent:
271
-                state = protocol_tx_message_sent();
278
+                state = protocol_tx_message_sent(cfg);
272 279
                 break;
273 280
             case PRLTxDiscardMessage:
274
-                state = protocol_tx_discard_message();
281
+                state = protocol_tx_discard_message(cfg);
275 282
                 break;
276 283
             default:
277 284
                 /* This is an error.  It really shouldn't happen.  We might

Loading…
Откажи
Сачувај