Browse Source

Reference the PRLTX thread by the new struct

Clara Hobbs 7 years ago
parent
commit
fc5c6780a8
6 changed files with 21 additions and 25 deletions
  1. 1
    1
      lib/src/hard_reset.c
  2. 1
    1
      lib/src/int_n.c
  3. 6
    6
      lib/src/policy_engine.c
  4. 12
    11
      lib/src/protocol_rx.c
  5. 1
    3
      lib/src/protocol_tx.c
  6. 0
    3
      lib/src/protocol_tx.h

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

57
     chThdYield();
57
     chThdYield();
58
 
58
 
59
     /* Reset the Protocol TX machine */
59
     /* Reset the Protocol TX machine */
60
-    chEvtSignal(pdb_prltx_thread, PDB_EVT_PRLTX_RESET);
60
+    chEvtSignal(cfg->prl.tx_thread, PDB_EVT_PRLTX_RESET);
61
     chThdYield();
61
     chThdYield();
62
 
62
 
63
     /* Continue the process based on what event started the reset. */
63
     /* Continue the process based on what event started the reset. */

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

59
             if (status.interrupta & FUSB_INTERRUPTA_I_TXSENT) {
59
             if (status.interrupta & FUSB_INTERRUPTA_I_TXSENT) {
60
                 events |= PDB_EVT_PRLTX_I_TXSENT;
60
                 events |= PDB_EVT_PRLTX_I_TXSENT;
61
             }
61
             }
62
-            chEvtSignal(pdb_prltx_thread, events);
62
+            chEvtSignal(cfg->prl.tx_thread, events);
63
 
63
 
64
             /* If the I_HARDRST or I_HARDSENT flag is set, tell the Hard Reset
64
             /* If the I_HARDRST or I_HARDSENT flag is set, tell the Hard Reset
65
              * thread */
65
              * thread */

+ 6
- 6
lib/src/policy_engine.c View File

154
 {
154
 {
155
     /* Transmit the request */
155
     /* Transmit the request */
156
     chMBPost(&pdb_prltx_mailbox, (msg_t) last_dpm_request, TIME_IMMEDIATE);
156
     chMBPost(&pdb_prltx_mailbox, (msg_t) last_dpm_request, TIME_IMMEDIATE);
157
-    chEvtSignal(pdb_prltx_thread, PDB_EVT_PRLTX_MSG_TX);
157
+    chEvtSignal(cfg->prl.tx_thread, PDB_EVT_PRLTX_MSG_TX);
158
     eventmask_t evt = chEvtWaitAny(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR
158
     eventmask_t evt = chEvtWaitAny(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR
159
             | PDB_EVT_PE_RESET);
159
             | PDB_EVT_PE_RESET);
160
     /* Don't free the request; we might need it again */
160
     /* Don't free the request; we might need it again */
428
         | PD_SPECREV_2_0 | PD_POWERROLE_SINK | PD_NUMOBJ(0);
428
         | PD_SPECREV_2_0 | PD_POWERROLE_SINK | PD_NUMOBJ(0);
429
     /* Transmit the Get_Source_Cap */
429
     /* Transmit the Get_Source_Cap */
430
     chMBPost(&pdb_prltx_mailbox, (msg_t) get_source_cap, TIME_IMMEDIATE);
430
     chMBPost(&pdb_prltx_mailbox, (msg_t) get_source_cap, TIME_IMMEDIATE);
431
-    chEvtSignal(pdb_prltx_thread, PDB_EVT_PRLTX_MSG_TX);
431
+    chEvtSignal(cfg->prl.tx_thread, PDB_EVT_PRLTX_MSG_TX);
432
     eventmask_t evt = chEvtWaitAny(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR
432
     eventmask_t evt = chEvtWaitAny(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR
433
             | PDB_EVT_PE_RESET);
433
             | PDB_EVT_PE_RESET);
434
     /* Free the sent message */
434
     /* Free the sent message */
455
 
455
 
456
     /* Transmit our capabilities */
456
     /* Transmit our capabilities */
457
     chMBPost(&pdb_prltx_mailbox, (msg_t) snk_cap, TIME_IMMEDIATE);
457
     chMBPost(&pdb_prltx_mailbox, (msg_t) snk_cap, TIME_IMMEDIATE);
458
-    chEvtSignal(pdb_prltx_thread, PDB_EVT_PRLTX_MSG_TX);
458
+    chEvtSignal(cfg->prl.tx_thread, PDB_EVT_PRLTX_MSG_TX);
459
     eventmask_t evt = chEvtWaitAny(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR
459
     eventmask_t evt = chEvtWaitAny(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR
460
             | PDB_EVT_PE_RESET);
460
             | PDB_EVT_PE_RESET);
461
 
461
 
522
         | PD_POWERROLE_SINK | PD_NUMOBJ(0);
522
         | PD_POWERROLE_SINK | PD_NUMOBJ(0);
523
     /* Transmit the Accept */
523
     /* Transmit the Accept */
524
     chMBPost(&pdb_prltx_mailbox, (msg_t) accept, TIME_IMMEDIATE);
524
     chMBPost(&pdb_prltx_mailbox, (msg_t) accept, TIME_IMMEDIATE);
525
-    chEvtSignal(pdb_prltx_thread, PDB_EVT_PRLTX_MSG_TX);
525
+    chEvtSignal(cfg->prl.tx_thread, PDB_EVT_PRLTX_MSG_TX);
526
     eventmask_t evt = chEvtWaitAny(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR
526
     eventmask_t evt = chEvtWaitAny(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR
527
             | PDB_EVT_PE_RESET);
527
             | PDB_EVT_PE_RESET);
528
     /* Free the sent message */
528
     /* Free the sent message */
552
         | PD_POWERROLE_SINK | PD_NUMOBJ(0);
552
         | PD_POWERROLE_SINK | PD_NUMOBJ(0);
553
     /* Transmit the soft reset */
553
     /* Transmit the soft reset */
554
     chMBPost(&pdb_prltx_mailbox, (msg_t) softrst, TIME_IMMEDIATE);
554
     chMBPost(&pdb_prltx_mailbox, (msg_t) softrst, TIME_IMMEDIATE);
555
-    chEvtSignal(pdb_prltx_thread, PDB_EVT_PRLTX_MSG_TX);
555
+    chEvtSignal(cfg->prl.tx_thread, PDB_EVT_PRLTX_MSG_TX);
556
     eventmask_t evt = chEvtWaitAny(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR
556
     eventmask_t evt = chEvtWaitAny(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR
557
             | PDB_EVT_PE_RESET);
557
             | PDB_EVT_PE_RESET);
558
     /* Free the sent message */
558
     /* Free the sent message */
613
 
613
 
614
     /* Transmit the message */
614
     /* Transmit the message */
615
     chMBPost(&pdb_prltx_mailbox, (msg_t) reject, TIME_IMMEDIATE);
615
     chMBPost(&pdb_prltx_mailbox, (msg_t) reject, TIME_IMMEDIATE);
616
-    chEvtSignal(pdb_prltx_thread, PDB_EVT_PRLTX_MSG_TX);
616
+    chEvtSignal(cfg->prl.tx_thread, PDB_EVT_PRLTX_MSG_TX);
617
     eventmask_t evt = chEvtWaitAny(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR
617
     eventmask_t evt = chEvtWaitAny(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR
618
             | PDB_EVT_PE_RESET);
618
             | PDB_EVT_PE_RESET);
619
 
619
 

+ 12
- 11
lib/src/protocol_rx.c View File

49
 /*
49
 /*
50
  * PRL_Rx_Wait_for_PHY_Message state
50
  * PRL_Rx_Wait_for_PHY_Message state
51
  */
51
  */
52
-static enum protocol_rx_state protocol_rx_wait_phy(void)
52
+static enum protocol_rx_state protocol_rx_wait_phy(struct pdb_config *cfg)
53
 {
53
 {
54
+    (void) cfg;
54
     /* Wait for an event */
55
     /* Wait for an event */
55
     eventmask_t evt = chEvtWaitAny(ALL_EVENTS);
56
     eventmask_t evt = chEvtWaitAny(ALL_EVENTS);
56
 
57
 
82
 /*
83
 /*
83
  * PRL_Rx_Layer_Reset_for_Receive state
84
  * PRL_Rx_Layer_Reset_for_Receive state
84
  */
85
  */
85
-static enum protocol_rx_state protocol_rx_reset(void)
86
+static enum protocol_rx_state protocol_rx_reset(struct pdb_config *cfg)
86
 {
87
 {
87
     /* Reset MessageIDCounter */
88
     /* Reset MessageIDCounter */
88
     pdb_prltx_messageidcounter = 0;
89
     pdb_prltx_messageidcounter = 0;
91
     pdb_prlrx_messageid = -1;
92
     pdb_prlrx_messageid = -1;
92
 
93
 
93
     /* TX transitions to its reset state */
94
     /* TX transitions to its reset state */
94
-    chEvtSignal(pdb_prltx_thread, PDB_EVT_PRLTX_RESET);
95
+    chEvtSignal(cfg->prl.tx_thread, PDB_EVT_PRLTX_RESET);
95
     chThdYield();
96
     chThdYield();
96
 
97
 
97
     /* If we got a RESET signal, reset the machine */
98
     /* If we got a RESET signal, reset the machine */
108
 /*
109
 /*
109
  * PRL_Rx_Check_MessageID state
110
  * PRL_Rx_Check_MessageID state
110
  */
111
  */
111
-static enum protocol_rx_state protocol_rx_check_messageid(void)
112
+static enum protocol_rx_state protocol_rx_check_messageid(struct pdb_config *cfg)
112
 {
113
 {
114
+    (void) cfg;
113
     /* If we got a RESET signal, reset the machine */
115
     /* If we got a RESET signal, reset the machine */
114
     if (chEvtGetAndClearEvents(PDB_EVT_PRLRX_RESET) != 0) {
116
     if (chEvtGetAndClearEvents(PDB_EVT_PRLRX_RESET) != 0) {
115
         chPoolFree(&pdb_msg_pool, protocol_rx_message);
117
         chPoolFree(&pdb_msg_pool, protocol_rx_message);
133
 /*
135
 /*
134
  * PRL_Rx_Store_MessageID state
136
  * PRL_Rx_Store_MessageID state
135
  */
137
  */
136
-static enum protocol_rx_state protocol_rx_store_messageid(void)
138
+static enum protocol_rx_state protocol_rx_store_messageid(struct pdb_config *cfg)
137
 {
139
 {
138
     /* Tell ProtocolTX to discard the message being transmitted */
140
     /* Tell ProtocolTX to discard the message being transmitted */
139
-    chEvtSignal(pdb_prltx_thread, PDB_EVT_PRLTX_DISCARD);
141
+    chEvtSignal(cfg->prl.tx_thread, PDB_EVT_PRLTX_DISCARD);
140
     chThdYield();
142
     chThdYield();
141
 
143
 
142
     /* Update the stored MessageID */
144
     /* Update the stored MessageID */
155
  * Protocol layer RX state machine thread
157
  * Protocol layer RX state machine thread
156
  */
158
  */
157
 static THD_FUNCTION(ProtocolRX, cfg) {
159
 static THD_FUNCTION(ProtocolRX, cfg) {
158
-    (void) cfg;
159
     enum protocol_rx_state state = PRLRxWaitPHY;
160
     enum protocol_rx_state state = PRLRxWaitPHY;
160
 
161
 
161
     while (true) {
162
     while (true) {
162
         switch (state) {
163
         switch (state) {
163
             case PRLRxWaitPHY:
164
             case PRLRxWaitPHY:
164
-                state = protocol_rx_wait_phy();
165
+                state = protocol_rx_wait_phy(cfg);
165
                 break;
166
                 break;
166
             case PRLRxReset:
167
             case PRLRxReset:
167
-                state = protocol_rx_reset();
168
+                state = protocol_rx_reset(cfg);
168
                 break;
169
                 break;
169
             case PRLRxCheckMessageID:
170
             case PRLRxCheckMessageID:
170
-                state = protocol_rx_check_messageid();
171
+                state = protocol_rx_check_messageid(cfg);
171
                 break;
172
                 break;
172
             case PRLRxStoreMessageID:
173
             case PRLRxStoreMessageID:
173
-                state = protocol_rx_store_messageid();
174
+                state = protocol_rx_store_messageid(cfg);
174
                 break;
175
                 break;
175
             default:
176
             default:
176
                 /* This is an error.  It really shouldn't happen.  We might
177
                 /* This is an error.  It really shouldn't happen.  We might

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

26
 #include "pd.h"
26
 #include "pd.h"
27
 
27
 
28
 
28
 
29
-thread_t *pdb_prltx_thread;
30
-
31
 /* Protocol layer TX thread mailbox */
29
 /* Protocol layer TX thread mailbox */
32
 static msg_t pdb_prltx_mailbox_queue[PDB_MSG_POOL_SIZE];
30
 static msg_t pdb_prltx_mailbox_queue[PDB_MSG_POOL_SIZE];
33
 mailbox_t pdb_prltx_mailbox;
31
 mailbox_t pdb_prltx_mailbox;
290
 
288
 
291
 void pdb_prltx_run(struct pdb_config *cfg)
289
 void pdb_prltx_run(struct pdb_config *cfg)
292
 {
290
 {
293
-    pdb_prltx_thread = chThdCreateStatic(cfg->prl._tx_wa,
291
+    cfg->prl.tx_thread = chThdCreateStatic(cfg->prl._tx_wa,
294
             sizeof(cfg->prl._tx_wa), PDB_PRIO_PRL, ProtocolTX, cfg);
292
             sizeof(cfg->prl._tx_wa), PDB_PRIO_PRL, ProtocolTX, cfg);
295
 }
293
 }

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

33
 #define PDB_EVT_PRLTX_DISCARD EVENT_MASK(3)
33
 #define PDB_EVT_PRLTX_DISCARD EVENT_MASK(3)
34
 #define PDB_EVT_PRLTX_MSG_TX EVENT_MASK(4)
34
 #define PDB_EVT_PRLTX_MSG_TX EVENT_MASK(4)
35
 
35
 
36
-/* The Protocol TX thread object */
37
-extern thread_t *pdb_prltx_thread;
38
-
39
 /* Protocol layer TX thread mailbox */
36
 /* Protocol layer TX thread mailbox */
40
 extern mailbox_t pdb_prltx_mailbox;
37
 extern mailbox_t pdb_prltx_mailbox;
41
 
38
 

Loading…
Cancel
Save