Browse Source

Reference the PRLRX thread by the new struct

Clara Hobbs 6 years ago
parent
commit
22ead74015
5 changed files with 50 additions and 43 deletions
  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 View File

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

+ 1
- 1
lib/src/int_n.c View File

47
 
47
 
48
             /* If the I_GCRCSENT flag is set, tell the Protocol RX thread */
48
             /* If the I_GCRCSENT flag is set, tell the Protocol RX thread */
49
             if (status.interruptb & FUSB_INTERRUPTB_I_GCRCSENT) {
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
             /* If the I_TXSENT or I_RETRYFAIL flag is set, tell the Protocol TX
53
             /* If the I_TXSENT or I_RETRYFAIL flag is set, tell the Protocol TX

+ 1
- 3
lib/src/protocol_rx.c View File

28
 #include "pd.h"
28
 #include "pd.h"
29
 
29
 
30
 
30
 
31
-thread_t *pdb_prlrx_thread;
32
-
33
 /*
31
 /*
34
  * Protocol RX machine states
32
  * Protocol RX machine states
35
  *
33
  *
184
 
182
 
185
 void pdb_prlrx_run(struct pdb_config *cfg)
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
             sizeof(cfg->prl._rx_wa), PDB_PRIO_PRL, ProtocolRX, cfg);
186
             sizeof(cfg->prl._rx_wa), PDB_PRIO_PRL, ProtocolRX, cfg);
189
 }
187
 }

+ 0
- 3
lib/src/protocol_rx.h View File

30
 #define PDB_EVT_PRLRX_RESET EVENT_MASK(0)
30
 #define PDB_EVT_PRLRX_RESET EVENT_MASK(0)
31
 #define PDB_EVT_PRLRX_I_GCRCSENT EVENT_MASK(1)
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
 /* The last received MessageID */
33
 /* The last received MessageID */
37
 extern int8_t pdb_prlrx_messageid;
34
 extern int8_t pdb_prlrx_messageid;
38
 
35
 

+ 27
- 20
lib/src/protocol_tx.c View File

60
 /*
60
 /*
61
  * PRL_Tx_PHY_Layer_Reset state
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
     /* Reset the PHY */
66
     /* Reset the PHY */
66
     fusb_reset();
67
     fusb_reset();
67
 
68
 
81
 /*
82
 /*
82
  * PRL_Tx_Wait_for_Message_Request state
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
     /* Wait for an event */
88
     /* Wait for an event */
87
     eventmask_t evt = chEvtWaitAny(PDB_EVT_PRLTX_RESET | PDB_EVT_PRLTX_DISCARD
89
     eventmask_t evt = chEvtWaitAny(PDB_EVT_PRLTX_RESET | PDB_EVT_PRLTX_DISCARD
88
             | PDB_EVT_PRLTX_MSG_TX);
90
             | PDB_EVT_PRLTX_MSG_TX);
112
     return PRLTxDiscardMessage;
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
     /* Clear MessageIDCounter */
119
     /* Clear MessageIDCounter */
118
     pdb_prltx_messageidcounter = 0;
120
     pdb_prltx_messageidcounter = 0;
119
 
121
 
120
     /* Tell the Protocol RX thread to reset */
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
     chThdYield();
124
     chThdYield();
123
 
125
 
124
     return PRLTxConstructMessage;
126
     return PRLTxConstructMessage;
127
 /*
129
 /*
128
  * PRL_Tx_Construct_Message state
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
     /* Make sure nobody wants us to reset */
135
     /* Make sure nobody wants us to reset */
133
     eventmask_t evt = chEvtGetAndClearEvents(PDB_EVT_PRLTX_RESET | PDB_EVT_PRLTX_DISCARD);
136
     eventmask_t evt = chEvtGetAndClearEvents(PDB_EVT_PRLTX_RESET | PDB_EVT_PRLTX_DISCARD);
134
 
137
 
152
 /*
155
 /*
153
  * PRL_Tx_Wait_for_PHY_Response state
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
     /* Wait for an event.  There is no need to run CRCReceiveTimer, since the
161
     /* Wait for an event.  There is no need to run CRCReceiveTimer, since the
158
      * FUSB302B handles that as part of its retry mechanism. */
162
      * FUSB302B handles that as part of its retry mechanism. */
159
     eventmask_t evt = chEvtWaitAny(PDB_EVT_PRLTX_RESET | PDB_EVT_PRLTX_DISCARD
163
     eventmask_t evt = chEvtWaitAny(PDB_EVT_PRLTX_RESET | PDB_EVT_PRLTX_DISCARD
182
 /*
186
 /*
183
  * PRL_Tx_Match_MessageID state
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
     union pd_msg goodcrc;
192
     union pd_msg goodcrc;
188
 
193
 
189
     /* Read the GoodCRC */
194
     /* Read the GoodCRC */
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
     /* Increment MessageIDCounter */
210
     /* Increment MessageIDCounter */
205
     pdb_prltx_messageidcounter = (pdb_prltx_messageidcounter + 1) % 8;
211
     pdb_prltx_messageidcounter = (pdb_prltx_messageidcounter + 1) % 8;
206
 
212
 
211
     return PRLTxWaitMessage;
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
     /* Increment MessageIDCounter */
223
     /* Increment MessageIDCounter */
217
     pdb_prltx_messageidcounter = (pdb_prltx_messageidcounter + 1) % 8;
224
     pdb_prltx_messageidcounter = (pdb_prltx_messageidcounter + 1) % 8;
218
 
225
 
223
     return PRLTxWaitMessage;
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
     /* If we were working on sending a message, increment MessageIDCounter */
236
     /* If we were working on sending a message, increment MessageIDCounter */
229
     if (protocol_tx_message != NULL) {
237
     if (protocol_tx_message != NULL) {
230
         pdb_prltx_messageidcounter = (pdb_prltx_messageidcounter + 1) % 8;
238
         pdb_prltx_messageidcounter = (pdb_prltx_messageidcounter + 1) % 8;
237
  * Protocol layer TX state machine thread
245
  * Protocol layer TX state machine thread
238
  */
246
  */
239
 static THD_FUNCTION(ProtocolTX, cfg) {
247
 static THD_FUNCTION(ProtocolTX, cfg) {
240
-    (void) cfg;
241
 
248
 
242
     enum protocol_tx_state state = PRLTxPHYReset;
249
     enum protocol_tx_state state = PRLTxPHYReset;
243
 
250
 
247
     while (true) {
254
     while (true) {
248
         switch (state) {
255
         switch (state) {
249
             case PRLTxPHYReset:
256
             case PRLTxPHYReset:
250
-                state = protocol_tx_phy_reset();
257
+                state = protocol_tx_phy_reset(cfg);
251
                 break;
258
                 break;
252
             case PRLTxWaitMessage:
259
             case PRLTxWaitMessage:
253
-                state = protocol_tx_wait_message();
260
+                state = protocol_tx_wait_message(cfg);
254
                 break;
261
                 break;
255
             case PRLTxReset:
262
             case PRLTxReset:
256
-                state = protocol_tx_reset();
263
+                state = protocol_tx_reset(cfg);
257
                 break;
264
                 break;
258
             case PRLTxConstructMessage:
265
             case PRLTxConstructMessage:
259
-                state = protocol_tx_construct_message();
266
+                state = protocol_tx_construct_message(cfg);
260
                 break;
267
                 break;
261
             case PRLTxWaitResponse:
268
             case PRLTxWaitResponse:
262
-                state = protocol_tx_wait_response();
269
+                state = protocol_tx_wait_response(cfg);
263
                 break;
270
                 break;
264
             case PRLTxMatchMessageID:
271
             case PRLTxMatchMessageID:
265
-                state = protocol_tx_match_messageid();
272
+                state = protocol_tx_match_messageid(cfg);
266
                 break;
273
                 break;
267
             case PRLTxTransmissionError:
274
             case PRLTxTransmissionError:
268
-                state = protocol_tx_transmission_error();
275
+                state = protocol_tx_transmission_error(cfg);
269
                 break;
276
                 break;
270
             case PRLTxMessageSent:
277
             case PRLTxMessageSent:
271
-                state = protocol_tx_message_sent();
278
+                state = protocol_tx_message_sent(cfg);
272
                 break;
279
                 break;
273
             case PRLTxDiscardMessage:
280
             case PRLTxDiscardMessage:
274
-                state = protocol_tx_discard_message();
281
+                state = protocol_tx_discard_message(cfg);
275
                 break;
282
                 break;
276
             default:
283
             default:
277
                 /* This is an error.  It really shouldn't happen.  We might
284
                 /* This is an error.  It really shouldn't happen.  We might

Loading…
Cancel
Save