Browse Source

Do PD communications in Setup mode

A good first step towards the upcoming 1.1 release, this commit runs the
Power Delivery threads in Setup mode.  This required a slight change to
the shell to make it non-blocking, as otherwise the PD threads would
never get to run.

There's still a lot to do!  The shell and the PD threads fight over
control of the LED in Setup mode.  There's no way to make the PD threads
re-negotiate the required power.  There's also no way to turn the output
on or off from the shell.  None of these changes should be too major,
but together they'll be pretty cool when they're all done.
Clara Hobbs 6 years ago
parent
commit
5e853f098f
2 changed files with 32 additions and 18 deletions
  1. 28
    16
      src/main.c
  2. 4
    2
      src/shell.c

+ 28
- 16
src/main.c View File

@@ -61,11 +61,37 @@ static const I2CConfig i2c2config = {
61 61
     0
62 62
 };
63 63
 
64
+/*
65
+ * Start the USB Power Delivery threads
66
+ */
67
+static void start_pd(void)
68
+{
69
+    /* Start I2C2 to make communication with the PHY possible */
70
+    i2cStart(&I2CD2, &i2c2config);
71
+
72
+    /* Initialize the FUSB302B */
73
+    fusb_setup();
74
+
75
+    /* Create the policy engine thread. */
76
+    pdb_pe_run();
77
+
78
+    /* Create the protocol layer threads. */
79
+    pdb_prlrx_run();
80
+    pdb_prltx_run();
81
+    pdb_hardrst_run();
82
+
83
+    /* Create the INT_N thread. */
84
+    pdb_int_n_run();
85
+}
86
+
64 87
 /*
65 88
  * Enter setup mode
66 89
  */
67 90
 static void setup(void)
68 91
 {
92
+    /* Start the USB Power Delivery threads */
93
+    start_pd();
94
+
69 95
     /* Indicate that we're in setup mode */
70 96
     chEvtSignal(pdb_led_thread, PDB_EVT_LED_CONFIG);
71 97
 
@@ -90,22 +116,8 @@ static void setup(void)
90 116
  */
91 117
 static void sink(void)
92 118
 {
93
-    /* Start I2C2 to make communication with the PHY possible */
94
-    i2cStart(&I2CD2, &i2c2config);
95
-
96
-    /* Initialize the FUSB302B */
97
-    fusb_setup();
98
-
99
-    /* Create the policy engine thread. */
100
-    pdb_pe_run();
101
-
102
-    /* Create the protocol layer threads. */
103
-    pdb_prlrx_run();
104
-    pdb_prltx_run();
105
-    pdb_hardrst_run();
106
-
107
-    /* Create the INT_N thread. */
108
-    pdb_int_n_run();
119
+    /* Start the USB Power Delivery threads */
120
+    start_pd();
109 121
 
110 122
     /* Wait, letting all the other threads do their work. */
111 123
     while (true) {

+ 4
- 2
src/shell.c View File

@@ -393,8 +393,10 @@ bool shellGetLine(BaseSequentialStream *chp, char *line, unsigned size)
393 393
         char c;
394 394
 
395 395
         /* Read a character */
396
-        if (chSequentialStreamRead(chp, (uint8_t *)&c, 1) == 0)
397
-            return true;
396
+        /* The cast to BaseAsynchronousChannel * is safe because we know that
397
+         * chp is always really of that type. */
398
+        while (chnReadTimeout((BaseAsynchronousChannel *) chp, (uint8_t *)&c, 1, TIME_IMMEDIATE) == 0)
399
+            chThdSleepMilliseconds(2);
398 400
         /* Abort if ^D is received */
399 401
         if (c == '\x04') {
400 402
             chprintf(chp, "^D");

Loading…
Cancel
Save