Browse Source

Move protocol_tx_message to the new struct

Clara Hobbs 6 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
     union pd_msg *_rx_message;
38
     union pd_msg *_rx_message;
39
 
39
 
40
     int8_t _tx_messageidcounter;
40
     int8_t _tx_messageidcounter;
41
+    union pd_msg *_tx_message;
41
     msg_t _tx_mailbox_queue[PDB_MSG_POOL_SIZE];
42
     msg_t _tx_mailbox_queue[PDB_MSG_POOL_SIZE];
42
 };
43
 };
43
 
44
 

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

45
     PRLTxDiscardMessage
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
  * PRL_Tx_PHY_Layer_Reset state
50
  * PRL_Tx_PHY_Layer_Reset state
60
 
57
 
61
     /* If a message was pending when we got here, tell the policy engine that
58
     /* If a message was pending when we got here, tell the policy engine that
62
      * we failed to send it */
59
      * we failed to send it */
63
-    if (protocol_tx_message != NULL) {
60
+    if (cfg->prl._tx_message != NULL) {
64
         /* Tell the policy engine that we failed */
61
         /* Tell the policy engine that we failed */
65
         chEvtSignal(pdb_pe_thread, PDB_EVT_PE_TX_ERR);
62
         chEvtSignal(pdb_pe_thread, PDB_EVT_PE_TX_ERR);
66
         /* Finish failing to send the message */
63
         /* Finish failing to send the message */
67
-        protocol_tx_message = NULL;
64
+        cfg->prl._tx_message = NULL;
68
     }
65
     }
69
 
66
 
70
     /* Wait for a message request */
67
     /* Wait for a message request */
90
     /* If the policy engine is trying to send a message */
87
     /* If the policy engine is trying to send a message */
91
     if (evt & PDB_EVT_PRLTX_MSG_TX) {
88
     if (evt & PDB_EVT_PRLTX_MSG_TX) {
92
         /* Get the message */
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
         /* If it's a Soft_Reset, reset the TX layer first */
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
             return PRLTxReset;
94
             return PRLTxReset;
98
         /* Otherwise, just send the message */
95
         /* Otherwise, just send the message */
99
         } else {
96
         } else {
134
     }
131
     }
135
 
132
 
136
     /* Set the correct MessageID in the message */
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
     /* Send the message to the PHY */
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
     return PRLTxWaitResponse;
140
     return PRLTxWaitResponse;
144
 }
141
 }
204
     /* Tell the policy engine that we failed */
201
     /* Tell the policy engine that we failed */
205
     chEvtSignal(pdb_pe_thread, PDB_EVT_PE_TX_ERR);
202
     chEvtSignal(pdb_pe_thread, PDB_EVT_PE_TX_ERR);
206
 
203
 
207
-    protocol_tx_message = NULL;
204
+    cfg->prl._tx_message = NULL;
208
     return PRLTxWaitMessage;
205
     return PRLTxWaitMessage;
209
 }
206
 }
210
 
207
 
217
     /* Tell the policy engine that we succeeded */
214
     /* Tell the policy engine that we succeeded */
218
     chEvtSignal(pdb_pe_thread, PDB_EVT_PE_TX_DONE);
215
     chEvtSignal(pdb_pe_thread, PDB_EVT_PE_TX_DONE);
219
 
216
 
220
-    protocol_tx_message = NULL;
217
+    cfg->prl._tx_message = NULL;
221
     return PRLTxWaitMessage;
218
     return PRLTxWaitMessage;
222
 }
219
 }
223
 
220
 
225
 {
222
 {
226
     (void) cfg;
223
     (void) cfg;
227
     /* If we were working on sending a message, increment MessageIDCounter */
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
         cfg->prl._tx_messageidcounter = (cfg->prl._tx_messageidcounter + 1) % 8;
226
         cfg->prl._tx_messageidcounter = (cfg->prl._tx_messageidcounter + 1) % 8;
230
     }
227
     }
231
 
228
 

Loading…
Cancel
Save