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 6 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
 /*
283
 /*
284
  * Send a USB Power Delivery message to the FUSB302B
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
  * Read a USB Power Delivery message from the FUSB302B
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
  * Tell the FUSB302B to send a hard reset signal
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
  * Read the FUSB302B status and interrupt flags into *status
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
  * Read the FUSB302B BC_LVL as an enum fusb_typec_current
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
  * Initialization routine for the FUSB302B
309
  * Initialization routine for the FUSB302B
313
 /*
313
 /*
314
  * Reset the FUSB302B
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
 #endif /* PDB_FUSB302B_H */
319
 #endif /* PDB_FUSB302B_H */

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

67
     i2cMasterTransmit(&I2CD2, FUSB302B_ADDR, txbuf, size + 1, NULL, 0);
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
     /* Token sequences for the FUSB302B */
72
     /* Token sequences for the FUSB302B */
73
     static uint8_t sop_seq[5] = {
73
     static uint8_t sop_seq[5] = {
85
     };
85
     };
86
 
86
 
87
     /* Take the I2C2 mutex now so there can't be a race condition on sop_seq */
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
     /* Get the length of the message: a two-octet header plus NUMOBJ four-octet
90
     /* Get the length of the message: a two-octet header plus NUMOBJ four-octet
91
      * data objects */
91
      * data objects */
99
     fusb_write_buf(FUSB_FIFOS, msg_len, msg->bytes);
99
     fusb_write_buf(FUSB_FIFOS, msg_len, msg->bytes);
100
     fusb_write_buf(FUSB_FIFOS, 4, eop_seq);
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
     uint8_t garbage[4];
107
     uint8_t garbage[4];
108
     uint8_t numobj;
108
     uint8_t numobj;
109
 
109
 
110
-    i2cAcquireBus(&I2CD2);
110
+    i2cAcquireBus(cfg->i2cp);
111
 
111
 
112
     /* If this isn't an SOP message, return error.
112
     /* If this isn't an SOP message, return error.
113
      * Because of our configuration, we should be able to assume this means the
113
      * Because of our configuration, we should be able to assume this means the
128
     /* Throw the CRC32 in the garbage, since the PHY already checked it. */
128
     /* Throw the CRC32 in the garbage, since the PHY already checked it. */
129
     fusb_read_buf(FUSB_FIFOS, 4, garbage);
129
     fusb_read_buf(FUSB_FIFOS, 4, garbage);
130
 
130
 
131
-    i2cReleaseBus(&I2CD2);
131
+    i2cReleaseBus(cfg->i2cp);
132
     return 0;
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
     /* Send a hard reset */
139
     /* Send a hard reset */
140
     fusb_write_byte(FUSB_CONTROL3, 0x07 | FUSB_CONTROL3_SEND_HARD_RESET);
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
 void fusb_setup(struct pdb_fusb_config *cfg)
145
 void fusb_setup(struct pdb_fusb_config *cfg)
189
     i2cReleaseBus(cfg->i2cp);
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
     /* Read the interrupt and status flags into status */
196
     /* Read the interrupt and status flags into status */
197
     fusb_read_buf(FUSB_STATUS0A, 7, status->bytes);
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
     /* Read the BC_LVL into a variable */
206
     /* Read the BC_LVL into a variable */
207
     enum fusb_typec_current bc_lvl = fusb_read_byte(FUSB_STATUS0)
207
     enum fusb_typec_current bc_lvl = fusb_read_byte(FUSB_STATUS0)
208
         & FUSB_STATUS0_BC_LVL;
208
         & FUSB_STATUS0_BC_LVL;
209
 
209
 
210
-    i2cReleaseBus(&I2CD2);
210
+    i2cReleaseBus(cfg->i2cp);
211
 
211
 
212
     return bc_lvl;
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
     /* Flush the TX buffer */
219
     /* Flush the TX buffer */
220
     fusb_write_byte(FUSB_CONTROL0, 0x44);
220
     fusb_write_byte(FUSB_CONTROL0, 0x44);
223
     /* Reset the PD logic */
223
     /* Reset the PD logic */
224
     fusb_write_byte(FUSB_RESET, FUSB_RESET_PD_RESET);
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
 {
82
 {
83
     (void) cfg;
83
     (void) cfg;
84
     /* Tell the PHY to send a hard reset */
84
     /* Tell the PHY to send a hard reset */
85
-    fusb_send_hardrst();
85
+    fusb_send_hardrst(&cfg->fusb);
86
 
86
 
87
     return PRLHRWaitPHY;
87
     return PRLHRWaitPHY;
88
 }
88
 }

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

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

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

621
  */
621
  */
622
 static enum policy_engine_state pe_sink_source_unresponsive(struct pdb_config *cfg)
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
     /* If the last two readings are the same, set the output */
626
     /* If the last two readings are the same, set the output */
627
     if (cfg->pe._old_tcc_match == tcc_match) {
627
     if (cfg->pe._old_tcc_match == tcc_match) {

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

59
          * because we have a big enough pool and are careful. */
59
          * because we have a big enough pool and are careful. */
60
         cfg->prl._rx_message = chPoolAlloc(&pdb_msg_pool);
60
         cfg->prl._rx_message = chPoolAlloc(&pdb_msg_pool);
61
         /* Read the message */
61
         /* Read the message */
62
-        fusb_read_message(cfg->prl._rx_message);
62
+        fusb_read_message(&cfg->fusb, cfg->prl._rx_message);
63
         /* 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 */
64
         if (PD_MSGTYPE_GET(cfg->prl._rx_message) == PD_MSGTYPE_SOFT_RESET
64
         if (PD_MSGTYPE_GET(cfg->prl._rx_message) == PD_MSGTYPE_SOFT_RESET
65
                 && PD_NUMOBJ_GET(cfg->prl._rx_message) == 0) {
65
                 && PD_NUMOBJ_GET(cfg->prl._rx_message) == 0) {

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

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

Loading…
Cancel
Save