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