Просмотр исходного кода

Use the struct pdb_config for all PRLRX variables

Clara Hobbs 7 лет назад
Родитель
Сommit
468c21ea71
3 измененных файлов: 17 добавлений и 25 удалений
  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 Просмотреть файл

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

+ 16
- 21
lib/src/protocol_rx.c Просмотреть файл

@@ -41,17 +41,11 @@ enum protocol_rx_state {
41 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 45
  * PRL_Rx_Wait_for_PHY_Message state
51 46
  */
52 47
 static enum protocol_rx_state protocol_rx_wait_phy(struct pdb_config *cfg)
53 48
 {
54
-    (void) cfg;
55 49
     /* Wait for an event */
56 50
     eventmask_t evt = chEvtWaitAny(ALL_EVENTS);
57 51
 
@@ -63,12 +57,12 @@ static enum protocol_rx_state protocol_rx_wait_phy(struct pdb_config *cfg)
63 57
     if (evt & PDB_EVT_PRLRX_I_GCRCSENT) {
64 58
         /* Get a buffer to read the message into.  Guaranteed to not fail
65 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 61
         /* Read the message */
68
-        fusb_read_message(protocol_rx_message);
62
+        fusb_read_message(cfg->prl._rx_message);
69 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 66
             return PRLRxReset;
73 67
         /* Otherwise, check the message ID */
74 68
         } else {
@@ -89,7 +83,7 @@ static enum protocol_rx_state protocol_rx_reset(struct pdb_config *cfg)
89 83
     pdb_prltx_messageidcounter = 0;
90 84
 
91 85
     /* Clear stored MessageID */
92
-    pdb_prlrx_messageid = -1;
86
+    cfg->prl._rx_messageid = -1;
93 87
 
94 88
     /* TX transitions to its reset state */
95 89
     chEvtSignal(cfg->prl.tx_thread, PDB_EVT_PRLTX_RESET);
@@ -97,8 +91,8 @@ static enum protocol_rx_state protocol_rx_reset(struct pdb_config *cfg)
97 91
 
98 92
     /* If we got a RESET signal, reset the machine */
99 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 96
         return PRLRxWaitPHY;
103 97
     }
104 98
 
@@ -111,19 +105,18 @@ static enum protocol_rx_state protocol_rx_reset(struct pdb_config *cfg)
111 105
  */
112 106
 static enum protocol_rx_state protocol_rx_check_messageid(struct pdb_config *cfg)
113 107
 {
114
-    (void) cfg;
115 108
     /* If we got a RESET signal, reset the machine */
116 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 112
         return PRLRxWaitPHY;
120 113
     }
121 114
 
122 115
     /* If the message has the stored ID, we've seen this message before.  Free
123 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 120
         return PRLRxWaitPHY;
128 121
     /* Otherwise, there's either no stored ID or this message has an ID we
129 122
      * haven't just seen.  Transition to the Store_MessageID state. */
@@ -142,10 +135,10 @@ static enum protocol_rx_state protocol_rx_store_messageid(struct pdb_config *cfg
142 135
     chThdYield();
143 136
 
144 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 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 142
     chEvtSignal(pdb_pe_thread, PDB_EVT_PE_MSG_RX);
150 143
 
151 144
     /* Don't check if we got a RESET because we'd do nothing different. */
@@ -183,6 +176,8 @@ static THD_FUNCTION(ProtocolRX, cfg) {
183 176
 
184 177
 void pdb_prlrx_run(struct pdb_config *cfg)
185 178
 {
179
+    cfg->prl._rx_messageid = -1;
180
+
186 181
     cfg->prl.rx_thread = chThdCreateStatic(cfg->prl._rx_wa,
187 182
             sizeof(cfg->prl._rx_wa), PDB_PRIO_PRL, ProtocolRX, cfg);
188 183
 }

+ 0
- 3
lib/src/protocol_rx.h Просмотреть файл

@@ -30,9 +30,6 @@
30 30
 #define PDB_EVT_PRLRX_RESET EVENT_MASK(0)
31 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 34
  * Start the Protocol RX thread
38 35
  */

Загрузка…
Отмена
Сохранить