Browse Source

Use the struct pdb_config for all PRLRX variables

Clara Hobbs 7 years ago
parent
commit
468c21ea71
3 changed files with 17 additions and 25 deletions
  1. 1
    1
      lib/src/hard_reset.c
  2. 16
    21
      lib/src/protocol_rx.c
  3. 0
    3
      lib/src/protocol_rx.h

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

49
             | PDB_EVT_HARDRST_I_HARDRST);
49
             | PDB_EVT_HARDRST_I_HARDRST);
50
 
50
 
51
     /* Reset the stored message IDs */
51
     /* Reset the stored message IDs */
52
-    pdb_prlrx_messageid = 0;
52
+    cfg->prl._rx_messageid = 0;
53
     pdb_prltx_messageidcounter = 0;
53
     pdb_prltx_messageidcounter = 0;
54
 
54
 
55
     /* Reset the Protocol RX machine */
55
     /* Reset the Protocol RX machine */

+ 16
- 21
lib/src/protocol_rx.c View File

41
     PRLRxStoreMessageID
41
     PRLRxStoreMessageID
42
 };
42
 };
43
 
43
 
44
-/* The received message we're currently working with */
45
-static union pd_msg *protocol_rx_message = NULL;
46
-/* The ID of the last received message */
47
-int8_t pdb_prlrx_messageid = -1;
48
-
49
 /*
44
 /*
50
  * PRL_Rx_Wait_for_PHY_Message state
45
  * PRL_Rx_Wait_for_PHY_Message state
51
  */
46
  */
52
 static enum protocol_rx_state protocol_rx_wait_phy(struct pdb_config *cfg)
47
 static enum protocol_rx_state protocol_rx_wait_phy(struct pdb_config *cfg)
53
 {
48
 {
54
-    (void) cfg;
55
     /* Wait for an event */
49
     /* Wait for an event */
56
     eventmask_t evt = chEvtWaitAny(ALL_EVENTS);
50
     eventmask_t evt = chEvtWaitAny(ALL_EVENTS);
57
 
51
 
63
     if (evt & PDB_EVT_PRLRX_I_GCRCSENT) {
57
     if (evt & PDB_EVT_PRLRX_I_GCRCSENT) {
64
         /* Get a buffer to read the message into.  Guaranteed to not fail
58
         /* Get a buffer to read the message into.  Guaranteed to not fail
65
          * because we have a big enough pool and are careful. */
59
          * because we have a big enough pool and are careful. */
66
-        protocol_rx_message = chPoolAlloc(&pdb_msg_pool);
60
+        cfg->prl._rx_message = chPoolAlloc(&pdb_msg_pool);
67
         /* Read the message */
61
         /* Read the message */
68
-        fusb_read_message(protocol_rx_message);
62
+        fusb_read_message(cfg->prl._rx_message);
69
         /* If it's a Soft_Reset, go to the soft reset state */
63
         /* If it's a Soft_Reset, go to the soft reset state */
70
-        if (PD_MSGTYPE_GET(protocol_rx_message) == PD_MSGTYPE_SOFT_RESET
71
-                && PD_NUMOBJ_GET(protocol_rx_message) == 0) {
64
+        if (PD_MSGTYPE_GET(cfg->prl._rx_message) == PD_MSGTYPE_SOFT_RESET
65
+                && PD_NUMOBJ_GET(cfg->prl._rx_message) == 0) {
72
             return PRLRxReset;
66
             return PRLRxReset;
73
         /* Otherwise, check the message ID */
67
         /* Otherwise, check the message ID */
74
         } else {
68
         } else {
89
     pdb_prltx_messageidcounter = 0;
83
     pdb_prltx_messageidcounter = 0;
90
 
84
 
91
     /* Clear stored MessageID */
85
     /* Clear stored MessageID */
92
-    pdb_prlrx_messageid = -1;
86
+    cfg->prl._rx_messageid = -1;
93
 
87
 
94
     /* TX transitions to its reset state */
88
     /* TX transitions to its reset state */
95
     chEvtSignal(cfg->prl.tx_thread, PDB_EVT_PRLTX_RESET);
89
     chEvtSignal(cfg->prl.tx_thread, PDB_EVT_PRLTX_RESET);
97
 
91
 
98
     /* If we got a RESET signal, reset the machine */
92
     /* If we got a RESET signal, reset the machine */
99
     if (chEvtGetAndClearEvents(PDB_EVT_PRLRX_RESET) != 0) {
93
     if (chEvtGetAndClearEvents(PDB_EVT_PRLRX_RESET) != 0) {
100
-        chPoolFree(&pdb_msg_pool, protocol_rx_message);
101
-        protocol_rx_message = NULL;
94
+        chPoolFree(&pdb_msg_pool, cfg->prl._rx_message);
95
+        cfg->prl._rx_message = NULL;
102
         return PRLRxWaitPHY;
96
         return PRLRxWaitPHY;
103
     }
97
     }
104
 
98
 
111
  */
105
  */
112
 static enum protocol_rx_state protocol_rx_check_messageid(struct pdb_config *cfg)
106
 static enum protocol_rx_state protocol_rx_check_messageid(struct pdb_config *cfg)
113
 {
107
 {
114
-    (void) cfg;
115
     /* If we got a RESET signal, reset the machine */
108
     /* If we got a RESET signal, reset the machine */
116
     if (chEvtGetAndClearEvents(PDB_EVT_PRLRX_RESET) != 0) {
109
     if (chEvtGetAndClearEvents(PDB_EVT_PRLRX_RESET) != 0) {
117
-        chPoolFree(&pdb_msg_pool, protocol_rx_message);
118
-        protocol_rx_message = NULL;
110
+        chPoolFree(&pdb_msg_pool, cfg->prl._rx_message);
111
+        cfg->prl._rx_message = NULL;
119
         return PRLRxWaitPHY;
112
         return PRLRxWaitPHY;
120
     }
113
     }
121
 
114
 
122
     /* If the message has the stored ID, we've seen this message before.  Free
115
     /* If the message has the stored ID, we've seen this message before.  Free
123
      * it and don't pass it to the policy engine. */
116
      * it and don't pass it to the policy engine. */
124
-    if (PD_MESSAGEID_GET(protocol_rx_message) == pdb_prlrx_messageid) {
125
-        chPoolFree(&pdb_msg_pool, protocol_rx_message);
126
-        protocol_rx_message = NULL;
117
+    if (PD_MESSAGEID_GET(cfg->prl._rx_message) == cfg->prl._rx_messageid) {
118
+        chPoolFree(&pdb_msg_pool, cfg->prl._rx_message);
119
+        cfg->prl._rx_message = NULL;
127
         return PRLRxWaitPHY;
120
         return PRLRxWaitPHY;
128
     /* Otherwise, there's either no stored ID or this message has an ID we
121
     /* Otherwise, there's either no stored ID or this message has an ID we
129
      * haven't just seen.  Transition to the Store_MessageID state. */
122
      * haven't just seen.  Transition to the Store_MessageID state. */
142
     chThdYield();
135
     chThdYield();
143
 
136
 
144
     /* Update the stored MessageID */
137
     /* Update the stored MessageID */
145
-    pdb_prlrx_messageid = PD_MESSAGEID_GET(protocol_rx_message);
138
+    cfg->prl._rx_messageid = PD_MESSAGEID_GET(cfg->prl._rx_message);
146
 
139
 
147
     /* Pass the message to the policy engine. */
140
     /* Pass the message to the policy engine. */
148
-    chMBPost(&pdb_pe_mailbox, (msg_t) protocol_rx_message, TIME_IMMEDIATE);
141
+    chMBPost(&pdb_pe_mailbox, (msg_t) cfg->prl._rx_message, TIME_IMMEDIATE);
149
     chEvtSignal(pdb_pe_thread, PDB_EVT_PE_MSG_RX);
142
     chEvtSignal(pdb_pe_thread, PDB_EVT_PE_MSG_RX);
150
 
143
 
151
     /* Don't check if we got a RESET because we'd do nothing different. */
144
     /* Don't check if we got a RESET because we'd do nothing different. */
183
 
176
 
184
 void pdb_prlrx_run(struct pdb_config *cfg)
177
 void pdb_prlrx_run(struct pdb_config *cfg)
185
 {
178
 {
179
+    cfg->prl._rx_messageid = -1;
180
+
186
     cfg->prl.rx_thread = chThdCreateStatic(cfg->prl._rx_wa,
181
     cfg->prl.rx_thread = chThdCreateStatic(cfg->prl._rx_wa,
187
             sizeof(cfg->prl._rx_wa), PDB_PRIO_PRL, ProtocolRX, cfg);
182
             sizeof(cfg->prl._rx_wa), PDB_PRIO_PRL, ProtocolRX, cfg);
188
 }
183
 }

+ 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 last received MessageID */
34
-extern int8_t pdb_prlrx_messageid;
35
-
36
 /*
33
 /*
37
  * Start the Protocol RX thread
34
  * Start the Protocol RX thread
38
  */
35
  */

Loading…
Cancel
Save