Browse Source

Move protocol_tx_message to the new struct

Clara Hobbs 7 years ago
parent
commit
3fd0cb3a8f
2 changed files with 12 additions and 14 deletions
  1. 1
    0
      lib/include/pdb_prl.h
  2. 11
    14
      lib/src/protocol_tx.c

+ 1
- 0
lib/include/pdb_prl.h View File

@@ -38,6 +38,7 @@ struct pdb_prl {
38 38
     union pd_msg *_rx_message;
39 39
 
40 40
     int8_t _tx_messageidcounter;
41
+    union pd_msg *_tx_message;
41 42
     msg_t _tx_mailbox_queue[PDB_MSG_POOL_SIZE];
42 43
 };
43 44
 

+ 11
- 14
lib/src/protocol_tx.c View File

@@ -45,9 +45,6 @@ enum protocol_tx_state {
45 45
     PRLTxDiscardMessage
46 46
 };
47 47
 
48
-/* The message we're currently working on transmitting */
49
-static union pd_msg *protocol_tx_message = NULL;
50
-
51 48
 
52 49
 /*
53 50
  * PRL_Tx_PHY_Layer_Reset state
@@ -60,11 +57,11 @@ static enum protocol_tx_state protocol_tx_phy_reset(struct pdb_config *cfg)
60 57
 
61 58
     /* If a message was pending when we got here, tell the policy engine that
62 59
      * we failed to send it */
63
-    if (protocol_tx_message != NULL) {
60
+    if (cfg->prl._tx_message != NULL) {
64 61
         /* Tell the policy engine that we failed */
65 62
         chEvtSignal(pdb_pe_thread, PDB_EVT_PE_TX_ERR);
66 63
         /* Finish failing to send the message */
67
-        protocol_tx_message = NULL;
64
+        cfg->prl._tx_message = NULL;
68 65
     }
69 66
 
70 67
     /* Wait for a message request */
@@ -90,10 +87,10 @@ static enum protocol_tx_state protocol_tx_wait_message(struct pdb_config *cfg)
90 87
     /* If the policy engine is trying to send a message */
91 88
     if (evt & PDB_EVT_PRLTX_MSG_TX) {
92 89
         /* Get the message */
93
-        chMBFetch(&cfg->prl.tx_mailbox, (msg_t *) &protocol_tx_message, TIME_IMMEDIATE);
90
+        chMBFetch(&cfg->prl.tx_mailbox, (msg_t *) &cfg->prl._tx_message, TIME_IMMEDIATE);
94 91
         /* If it's a Soft_Reset, reset the TX layer first */
95
-        if (PD_MSGTYPE_GET(protocol_tx_message) == PD_MSGTYPE_SOFT_RESET
96
-                && PD_NUMOBJ_GET(protocol_tx_message) == 0) {
92
+        if (PD_MSGTYPE_GET(cfg->prl._tx_message) == PD_MSGTYPE_SOFT_RESET
93
+                && PD_NUMOBJ_GET(cfg->prl._tx_message) == 0) {
97 94
             return PRLTxReset;
98 95
         /* Otherwise, just send the message */
99 96
         } else {
@@ -134,11 +131,11 @@ static enum protocol_tx_state protocol_tx_construct_message(struct pdb_config *c
134 131
     }
135 132
 
136 133
     /* Set the correct MessageID in the message */
137
-    protocol_tx_message->hdr &= ~PD_HDR_MESSAGEID;
138
-    protocol_tx_message->hdr |= (cfg->prl._tx_messageidcounter % 8) << PD_HDR_MESSAGEID_SHIFT;
134
+    cfg->prl._tx_message->hdr &= ~PD_HDR_MESSAGEID;
135
+    cfg->prl._tx_message->hdr |= (cfg->prl._tx_messageidcounter % 8) << PD_HDR_MESSAGEID_SHIFT;
139 136
 
140 137
     /* Send the message to the PHY */
141
-    fusb_send_message(protocol_tx_message);
138
+    fusb_send_message(cfg->prl._tx_message);
142 139
 
143 140
     return PRLTxWaitResponse;
144 141
 }
@@ -204,7 +201,7 @@ static enum protocol_tx_state protocol_tx_transmission_error(struct pdb_config *
204 201
     /* Tell the policy engine that we failed */
205 202
     chEvtSignal(pdb_pe_thread, PDB_EVT_PE_TX_ERR);
206 203
 
207
-    protocol_tx_message = NULL;
204
+    cfg->prl._tx_message = NULL;
208 205
     return PRLTxWaitMessage;
209 206
 }
210 207
 
@@ -217,7 +214,7 @@ static enum protocol_tx_state protocol_tx_message_sent(struct pdb_config *cfg)
217 214
     /* Tell the policy engine that we succeeded */
218 215
     chEvtSignal(pdb_pe_thread, PDB_EVT_PE_TX_DONE);
219 216
 
220
-    protocol_tx_message = NULL;
217
+    cfg->prl._tx_message = NULL;
221 218
     return PRLTxWaitMessage;
222 219
 }
223 220
 
@@ -225,7 +222,7 @@ static enum protocol_tx_state protocol_tx_discard_message(struct pdb_config *cfg
225 222
 {
226 223
     (void) cfg;
227 224
     /* If we were working on sending a message, increment MessageIDCounter */
228
-    if (protocol_tx_message != NULL) {
225
+    if (cfg->prl._tx_message != NULL) {
229 226
         cfg->prl._tx_messageidcounter = (cfg->prl._tx_messageidcounter + 1) % 8;
230 227
     }
231 228
 

Loading…
Cancel
Save