Browse Source

Add struct pdb_fusb_config *cfg to fusb functions

Now the user-visible FUSB302B functions all take a struct
pdb_fusb_config * as a parameter.  The static functions don't use it
yet, but at least the public API of this code is in its finished state.
Clara Hobbs 7 years ago
parent
commit
735edb3444
7 changed files with 31 additions and 31 deletions
  1. 6
    6
      lib/include/fusb302b.h
  2. 18
    18
      lib/src/fusb302b.c
  3. 1
    1
      lib/src/hard_reset.c
  4. 1
    1
      lib/src/int_n.c
  5. 1
    1
      lib/src/policy_engine.c
  6. 1
    1
      lib/src/protocol_rx.c
  7. 3
    3
      lib/src/protocol_tx.c

+ 6
- 6
lib/include/fusb302b.h View File

@@ -283,27 +283,27 @@ enum fusb_typec_current {
283 283
 /*
284 284
  * Send a USB Power Delivery message to the FUSB302B
285 285
  */
286
-void fusb_send_message(const union pd_msg *msg);
286
+void fusb_send_message(struct pdb_fusb_config *cfg, const union pd_msg *msg);
287 287
 
288 288
 /*
289 289
  * Read a USB Power Delivery message from the FUSB302B
290 290
  */
291
-uint8_t fusb_read_message(union pd_msg *msg);
291
+uint8_t fusb_read_message(struct pdb_fusb_config *cfg, union pd_msg *msg);
292 292
 
293 293
 /*
294 294
  * Tell the FUSB302B to send a hard reset signal
295 295
  */
296
-void fusb_send_hardrst(void);
296
+void fusb_send_hardrst(struct pdb_fusb_config *cfg);
297 297
 
298 298
 /*
299 299
  * Read the FUSB302B status and interrupt flags into *status
300 300
  */
301
-void fusb_get_status(union fusb_status *status);
301
+void fusb_get_status(struct pdb_fusb_config *cfg, union fusb_status *status);
302 302
 
303 303
 /*
304 304
  * Read the FUSB302B BC_LVL as an enum fusb_typec_current
305 305
  */
306
-enum fusb_typec_current fusb_get_typec_current(void);
306
+enum fusb_typec_current fusb_get_typec_current(struct pdb_fusb_config *cfg);
307 307
 
308 308
 /*
309 309
  * Initialization routine for the FUSB302B
@@ -313,7 +313,7 @@ void fusb_setup(struct pdb_fusb_config *);
313 313
 /*
314 314
  * Reset the FUSB302B
315 315
  */
316
-void fusb_reset(void);
316
+void fusb_reset(struct pdb_fusb_config *cfg);
317 317
 
318 318
 
319 319
 #endif /* PDB_FUSB302B_H */

+ 18
- 18
lib/src/fusb302b.c View File

@@ -67,7 +67,7 @@ static void fusb_write_buf(uint8_t addr, uint8_t size, const uint8_t *buf)
67 67
     i2cMasterTransmit(&I2CD2, FUSB302B_ADDR, txbuf, size + 1, NULL, 0);
68 68
 }
69 69
 
70
-void fusb_send_message(const union pd_msg *msg)
70
+void fusb_send_message(struct pdb_fusb_config *cfg, const union pd_msg *msg)
71 71
 {
72 72
     /* Token sequences for the FUSB302B */
73 73
     static uint8_t sop_seq[5] = {
@@ -85,7 +85,7 @@ void fusb_send_message(const union pd_msg *msg)
85 85
     };
86 86
 
87 87
     /* Take the I2C2 mutex now so there can't be a race condition on sop_seq */
88
-    i2cAcquireBus(&I2CD2);
88
+    i2cAcquireBus(cfg->i2cp);
89 89
 
90 90
     /* Get the length of the message: a two-octet header plus NUMOBJ four-octet
91 91
      * data objects */
@@ -99,15 +99,15 @@ void fusb_send_message(const union pd_msg *msg)
99 99
     fusb_write_buf(FUSB_FIFOS, msg_len, msg->bytes);
100 100
     fusb_write_buf(FUSB_FIFOS, 4, eop_seq);
101 101
 
102
-    i2cReleaseBus(&I2CD2);
102
+    i2cReleaseBus(cfg->i2cp);
103 103
 }
104 104
 
105
-uint8_t fusb_read_message(union pd_msg *msg)
105
+uint8_t fusb_read_message(struct pdb_fusb_config *cfg, union pd_msg *msg)
106 106
 {
107 107
     uint8_t garbage[4];
108 108
     uint8_t numobj;
109 109
 
110
-    i2cAcquireBus(&I2CD2);
110
+    i2cAcquireBus(cfg->i2cp);
111 111
 
112 112
     /* If this isn't an SOP message, return error.
113 113
      * Because of our configuration, we should be able to assume this means the
@@ -128,18 +128,18 @@ uint8_t fusb_read_message(union pd_msg *msg)
128 128
     /* Throw the CRC32 in the garbage, since the PHY already checked it. */
129 129
     fusb_read_buf(FUSB_FIFOS, 4, garbage);
130 130
 
131
-    i2cReleaseBus(&I2CD2);
131
+    i2cReleaseBus(cfg->i2cp);
132 132
     return 0;
133 133
 }
134 134
 
135
-void fusb_send_hardrst(void)
135
+void fusb_send_hardrst(struct pdb_fusb_config *cfg)
136 136
 {
137
-    i2cAcquireBus(&I2CD2);
137
+    i2cAcquireBus(cfg->i2cp);
138 138
 
139 139
     /* Send a hard reset */
140 140
     fusb_write_byte(FUSB_CONTROL3, 0x07 | FUSB_CONTROL3_SEND_HARD_RESET);
141 141
 
142
-    i2cReleaseBus(&I2CD2);
142
+    i2cReleaseBus(cfg->i2cp);
143 143
 }
144 144
 
145 145
 void fusb_setup(struct pdb_fusb_config *cfg)
@@ -189,32 +189,32 @@ void fusb_setup(struct pdb_fusb_config *cfg)
189 189
     i2cReleaseBus(cfg->i2cp);
190 190
 }
191 191
 
192
-void fusb_get_status(union fusb_status *status)
192
+void fusb_get_status(struct pdb_fusb_config *cfg, union fusb_status *status)
193 193
 {
194
-    i2cAcquireBus(&I2CD2);
194
+    i2cAcquireBus(cfg->i2cp);
195 195
 
196 196
     /* Read the interrupt and status flags into status */
197 197
     fusb_read_buf(FUSB_STATUS0A, 7, status->bytes);
198 198
 
199
-    i2cReleaseBus(&I2CD2);
199
+    i2cReleaseBus(cfg->i2cp);
200 200
 }
201 201
 
202
-enum fusb_typec_current fusb_get_typec_current(void)
202
+enum fusb_typec_current fusb_get_typec_current(struct pdb_fusb_config *cfg)
203 203
 {
204
-    i2cAcquireBus(&I2CD2);
204
+    i2cAcquireBus(cfg->i2cp);
205 205
 
206 206
     /* Read the BC_LVL into a variable */
207 207
     enum fusb_typec_current bc_lvl = fusb_read_byte(FUSB_STATUS0)
208 208
         & FUSB_STATUS0_BC_LVL;
209 209
 
210
-    i2cReleaseBus(&I2CD2);
210
+    i2cReleaseBus(cfg->i2cp);
211 211
 
212 212
     return bc_lvl;
213 213
 }
214 214
 
215
-void fusb_reset(void)
215
+void fusb_reset(struct pdb_fusb_config *cfg)
216 216
 {
217
-    i2cAcquireBus(&I2CD2);
217
+    i2cAcquireBus(cfg->i2cp);
218 218
 
219 219
     /* Flush the TX buffer */
220 220
     fusb_write_byte(FUSB_CONTROL0, 0x44);
@@ -223,5 +223,5 @@ void fusb_reset(void)
223 223
     /* Reset the PD logic */
224 224
     fusb_write_byte(FUSB_RESET, FUSB_RESET_PD_RESET);
225 225
 
226
-    i2cReleaseBus(&I2CD2);
226
+    i2cReleaseBus(cfg->i2cp);
227 227
 }

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

@@ -82,7 +82,7 @@ static enum hardrst_state hardrst_request_hard_reset(struct pdb_config *cfg)
82 82
 {
83 83
     (void) cfg;
84 84
     /* Tell the PHY to send a hard reset */
85
-    fusb_send_hardrst();
85
+    fusb_send_hardrst(&cfg->fusb);
86 86
 
87 87
     return PRLHRWaitPHY;
88 88
 }

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

@@ -43,7 +43,7 @@ static THD_FUNCTION(IntNPoll, vcfg) {
43 43
         /* If the INT_N line is low */
44 44
         if (palReadLine(LINE_INT_N) == PAL_LOW) {
45 45
             /* Read the FUSB302B status and interrupt registers */
46
-            fusb_get_status(&status);
46
+            fusb_get_status(&cfg->fusb, &status);
47 47
 
48 48
             /* If the I_GCRCSENT flag is set, tell the Protocol RX thread */
49 49
             if (status.interruptb & FUSB_INTERRUPTB_I_GCRCSENT) {

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

@@ -621,7 +621,7 @@ static enum policy_engine_state pe_sink_send_reject(struct pdb_config *cfg)
621 621
  */
622 622
 static enum policy_engine_state pe_sink_source_unresponsive(struct pdb_config *cfg)
623 623
 {
624
-    int tcc_match = cfg->dpm.evaluate_typec_current(cfg, fusb_get_typec_current());
624
+    int tcc_match = cfg->dpm.evaluate_typec_current(cfg, fusb_get_typec_current(&cfg->fusb));
625 625
 
626 626
     /* If the last two readings are the same, set the output */
627 627
     if (cfg->pe._old_tcc_match == tcc_match) {

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

@@ -59,7 +59,7 @@ static enum protocol_rx_state protocol_rx_wait_phy(struct pdb_config *cfg)
59 59
          * because we have a big enough pool and are careful. */
60 60
         cfg->prl._rx_message = chPoolAlloc(&pdb_msg_pool);
61 61
         /* Read the message */
62
-        fusb_read_message(cfg->prl._rx_message);
62
+        fusb_read_message(&cfg->fusb, cfg->prl._rx_message);
63 63
         /* If it's a Soft_Reset, go to the soft reset state */
64 64
         if (PD_MSGTYPE_GET(cfg->prl._rx_message) == PD_MSGTYPE_SOFT_RESET
65 65
                 && PD_NUMOBJ_GET(cfg->prl._rx_message) == 0) {

+ 3
- 3
lib/src/protocol_tx.c View File

@@ -52,7 +52,7 @@ enum protocol_tx_state {
52 52
 static enum protocol_tx_state protocol_tx_phy_reset(struct pdb_config *cfg)
53 53
 {
54 54
     /* Reset the PHY */
55
-    fusb_reset();
55
+    fusb_reset(&cfg->fusb);
56 56
 
57 57
     /* If a message was pending when we got here, tell the policy engine that
58 58
      * we failed to send it */
@@ -133,7 +133,7 @@ static enum protocol_tx_state protocol_tx_construct_message(struct pdb_config *c
133 133
     cfg->prl._tx_message->hdr |= (cfg->prl._tx_messageidcounter % 8) << PD_HDR_MESSAGEID_SHIFT;
134 134
 
135 135
     /* Send the message to the PHY */
136
-    fusb_send_message(cfg->prl._tx_message);
136
+    fusb_send_message(&cfg->fusb, cfg->prl._tx_message);
137 137
 
138 138
     return PRLTxWaitResponse;
139 139
 }
@@ -177,7 +177,7 @@ static enum protocol_tx_state protocol_tx_match_messageid(struct pdb_config *cfg
177 177
     union pd_msg goodcrc;
178 178
 
179 179
     /* Read the GoodCRC */
180
-    fusb_read_message(&goodcrc);
180
+    fusb_read_message(&cfg->fusb, &goodcrc);
181 181
 
182 182
     /* Check that the message is correct */
183 183
     if (PD_MSGTYPE_GET(&goodcrc) == PD_MSGTYPE_GOODCRC

Loading…
Cancel
Save