Browse Source

Use tx_messageidcounter in the new struct

Apparently one of the threads was using too much stack space??  This
will require investigtion later, but for now increasing their stack
space fixed some weird problems I was having with this patch.
Clara Hobbs 7 years ago
parent
commit
ac3fa561ec
5 changed files with 11 additions and 15 deletions
  1. 3
    3
      lib/include/pdb_prl.h
  2. 1
    1
      lib/src/hard_reset.c
  3. 1
    1
      lib/src/protocol_rx.c
  4. 6
    8
      lib/src/protocol_tx.c
  5. 0
    2
      lib/src/protocol_tx.h

+ 3
- 3
lib/include/pdb_prl.h View File

@@ -25,11 +25,11 @@
25 25
 
26 26
 
27 27
 struct pdb_prl {
28
-    THD_WORKING_AREA(_rx_wa, 128);
28
+    THD_WORKING_AREA(_rx_wa, 256);
29 29
     thread_t *rx_thread;
30
-    THD_WORKING_AREA(_tx_wa, 128);
30
+    THD_WORKING_AREA(_tx_wa, 256);
31 31
     thread_t *tx_thread;
32
-    THD_WORKING_AREA(_hardrst_wa, 128);
32
+    THD_WORKING_AREA(_hardrst_wa, 256);
33 33
     thread_t *hardrst_thread;
34 34
 
35 35
     mailbox_t tx_mailbox;

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

@@ -50,7 +50,7 @@ static enum hardrst_state hardrst_reset_layer(struct pdb_config *cfg)
50 50
 
51 51
     /* Reset the stored message IDs */
52 52
     cfg->prl._rx_messageid = 0;
53
-    pdb_prltx_messageidcounter = 0;
53
+    cfg->prl._tx_messageidcounter = 0;
54 54
 
55 55
     /* Reset the Protocol RX machine */
56 56
     chEvtSignal(cfg->prl.rx_thread, PDB_EVT_PRLRX_RESET);

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

@@ -80,7 +80,7 @@ static enum protocol_rx_state protocol_rx_wait_phy(struct pdb_config *cfg)
80 80
 static enum protocol_rx_state protocol_rx_reset(struct pdb_config *cfg)
81 81
 {
82 82
     /* Reset MessageIDCounter */
83
-    pdb_prltx_messageidcounter = 0;
83
+    cfg->prl._tx_messageidcounter = 0;
84 84
 
85 85
     /* Clear stored MessageID */
86 86
     cfg->prl._rx_messageid = -1;

+ 6
- 8
lib/src/protocol_tx.c View File

@@ -47,8 +47,6 @@ enum protocol_tx_state {
47 47
 
48 48
 /* The message we're currently working on transmitting */
49 49
 static union pd_msg *protocol_tx_message = NULL;
50
-/* The ID to be used in transmission */
51
-int8_t pdb_prltx_messageidcounter = 0;
52 50
 
53 51
 
54 52
 /*
@@ -110,7 +108,7 @@ static enum protocol_tx_state protocol_tx_wait_message(struct pdb_config *cfg)
110 108
 static enum protocol_tx_state protocol_tx_reset(struct pdb_config *cfg)
111 109
 {
112 110
     /* Clear MessageIDCounter */
113
-    pdb_prltx_messageidcounter = 0;
111
+    cfg->prl._tx_messageidcounter = 0;
114 112
 
115 113
     /* Tell the Protocol RX thread to reset */
116 114
     chEvtSignal(cfg->prl.rx_thread, PDB_EVT_PRLRX_RESET);
@@ -137,7 +135,7 @@ static enum protocol_tx_state protocol_tx_construct_message(struct pdb_config *c
137 135
 
138 136
     /* Set the correct MessageID in the message */
139 137
     protocol_tx_message->hdr &= ~PD_HDR_MESSAGEID;
140
-    protocol_tx_message->hdr |= pdb_prltx_messageidcounter << PD_HDR_MESSAGEID_SHIFT;
138
+    protocol_tx_message->hdr |= (cfg->prl._tx_messageidcounter % 8) << PD_HDR_MESSAGEID_SHIFT;
141 139
 
142 140
     /* Send the message to the PHY */
143 141
     fusb_send_message(protocol_tx_message);
@@ -190,7 +188,7 @@ static enum protocol_tx_state protocol_tx_match_messageid(struct pdb_config *cfg
190 188
     /* Check that the message is correct */
191 189
     if (PD_MSGTYPE_GET(&goodcrc) == PD_MSGTYPE_GOODCRC
192 190
             && PD_NUMOBJ_GET(&goodcrc) == 0
193
-            && PD_MESSAGEID_GET(&goodcrc) == pdb_prltx_messageidcounter) {
191
+            && PD_MESSAGEID_GET(&goodcrc) == cfg->prl._tx_messageidcounter) {
194 192
         return PRLTxMessageSent;
195 193
     } else {
196 194
         return PRLTxTransmissionError;
@@ -201,7 +199,7 @@ static enum protocol_tx_state protocol_tx_transmission_error(struct pdb_config *
201 199
 {
202 200
     (void) cfg;
203 201
     /* Increment MessageIDCounter */
204
-    pdb_prltx_messageidcounter = (pdb_prltx_messageidcounter + 1) % 8;
202
+    cfg->prl._tx_messageidcounter = (cfg->prl._tx_messageidcounter + 1) % 8;
205 203
 
206 204
     /* Tell the policy engine that we failed */
207 205
     chEvtSignal(pdb_pe_thread, PDB_EVT_PE_TX_ERR);
@@ -214,7 +212,7 @@ static enum protocol_tx_state protocol_tx_message_sent(struct pdb_config *cfg)
214 212
 {
215 213
     (void) cfg;
216 214
     /* Increment MessageIDCounter */
217
-    pdb_prltx_messageidcounter = (pdb_prltx_messageidcounter + 1) % 8;
215
+    cfg->prl._tx_messageidcounter = (cfg->prl._tx_messageidcounter + 1) % 8;
218 216
 
219 217
     /* Tell the policy engine that we succeeded */
220 218
     chEvtSignal(pdb_pe_thread, PDB_EVT_PE_TX_DONE);
@@ -228,7 +226,7 @@ static enum protocol_tx_state protocol_tx_discard_message(struct pdb_config *cfg
228 226
     (void) cfg;
229 227
     /* If we were working on sending a message, increment MessageIDCounter */
230 228
     if (protocol_tx_message != NULL) {
231
-        pdb_prltx_messageidcounter = (pdb_prltx_messageidcounter + 1) % 8;
229
+        cfg->prl._tx_messageidcounter = (cfg->prl._tx_messageidcounter + 1) % 8;
232 230
     }
233 231
 
234 232
     return PRLTxPHYReset;

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

@@ -33,8 +33,6 @@
33 33
 #define PDB_EVT_PRLTX_DISCARD EVENT_MASK(3)
34 34
 #define PDB_EVT_PRLTX_MSG_TX EVENT_MASK(4)
35 35
 
36
-/* The ID to be used in transmission */
37
-extern int8_t pdb_prltx_messageidcounter;
38 36
 
39 37
 /*
40 38
  * Start the Protocol TX thread

Loading…
Cancel
Save