Bläddra i källkod

Added more library headers

These new headers define structs for configuring the library.  They're
currently unused, and some function prototypes no longer match.
Clara Hobbs 7 år sedan
förälder
incheckning
92a7620c1e
7 ändrade filer med 276 tillägg och 8 borttagningar
  1. 29
    1
      lib/include/pdb.h
  2. 84
    0
      lib/include/pdb_dpm.h
  3. 36
    0
      lib/include/pdb_fusb.h
  4. 31
    0
      lib/include/pdb_int_n.h
  5. 44
    0
      lib/include/pdb_pe.h
  6. 45
    0
      lib/include/pdb_prl.h
  7. 7
    7
      lib/src/pdb.c

+ 29
- 1
lib/include/pdb.h Visa fil

@@ -19,11 +19,39 @@
19 19
 #ifndef PDB_H
20 20
 #define PDB_H
21 21
 
22
+#include <pdb_fusb.h>
23
+#include <pdb_dpm.h>
24
+#include <pdb_pe.h>
25
+#include <pdb_prl.h>
26
+#include <pdb_int_n.h>
27
+
28
+
29
+/*
30
+ * Structure for PD Buddy firmware library configuration
31
+ *
32
+ * Contains working areas for statically allocated threads, and therefore must
33
+ * be statically allocated!
34
+ */
35
+struct pdb_config {
36
+    /* Configuration information for the FUSB302B* chip */
37
+    struct pdb_fusb_config fusb_config;
38
+    /* DPM callbacks */
39
+    struct pdb_dpm_callbacks dpm;
40
+    /* Pointer to port-specific DPM data */
41
+    void *dpm_data;
42
+    /* Policy Engine thread and related variables */
43
+    struct pdb_pe pe;
44
+    /* Protocol layer threads and related variables */
45
+    struct pdb_prl prl;
46
+    /* INT_N pin thread and related variables */
47
+    struct pdb_int_n int_n;
48
+};
49
+
22 50
 
23 51
 /*
24 52
  * Initialize the PD Buddy firmware library, starting all its threads
25 53
  */
26
-void pdb_init(void);
54
+void pdb_init(struct pdb_config *);
27 55
 
28 56
 
29 57
 #endif /* PDB_H */

+ 84
- 0
lib/include/pdb_dpm.h Visa fil

@@ -0,0 +1,84 @@
1
+/*
2
+ * PD Buddy - USB Power Delivery for everyone
3
+ * Copyright (C) 2017 Clayton G. Hobbs <clay@lakeserv.net>
4
+ *
5
+ * This program is free software: you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License as published by
7
+ * the Free Software Foundation, either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
+ * GNU General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU General Public License
16
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+
19
+#ifndef PDB_DPM_H
20
+#define PDB_DPM_H
21
+
22
+#include <stdbool.h>
23
+
24
+/* TODO: improve these includes */
25
+#include "fusb302b.h"
26
+#include "messages.h"
27
+
28
+
29
+/* Forward declaration of struct pdb_config */
30
+struct pdb_config;
31
+
32
+/* DPM callback typedefs */
33
+typedef void (*pdb_dpm_func)(struct pdb_config *);
34
+typedef bool (*pdb_dpm_eval_cap_func)(struct pdb_config *,
35
+        const union pd_msg *, union pd_msg *);
36
+typedef void (*pdb_dpm_get_sink_cap_func)(struct pdb_config *, union pd_msg *);
37
+typedef void (*pdb_dpm_tcc_func)(struct pdb_config *, enum fusb_typec_current);
38
+
39
+/*
40
+ * PD Buddy firmware library device policy manager callback structure
41
+ *
42
+ * Optional functions may be set to NULL if the associated functionality is not
43
+ * required.
44
+ */
45
+struct pdb_dpm_callbacks {
46
+    pdb_dpm_eval_cap_func evaluate_capability;
47
+    pdb_dpm_get_sink_cap_func get_sink_capability;
48
+    pdb_dpm_func giveback_enabled;
49
+    pdb_dpm_tcc_func evaluate_typec_current; /* Optional */
50
+    pdb_dpm_func pd_start; /* Optional */
51
+    /* dpm_sink_standby is called in PE_SNK_Select_Capability to ensure power
52
+     * consumption is less than 2.5 W.
53
+     *   - dpm_transition_standby()
54
+     */
55
+    /* dpm_output_set is called in five places:
56
+     *   - PS_RDY received → transition sink power supply to our request
57
+     *     - This could mean what we wanted, or what we had to settle for, so
58
+     *       we have to remember.
59
+     *     - dpm_transition_requested()
60
+     *   - Protocol error in PE_SNK_Transition_Sink
61
+     *     - Unnecessary?  If we really want to be defensive here, just go to
62
+     *       default output, right?  That's what we'll do shortly afterwards
63
+     *       anyway.
64
+     *     - dpm_transition_default()
65
+     *   - GotoMin received and giveback → transition sink to min power
66
+     *     - dpm_transition_min()
67
+     *   - Transition sink power supply to match Type-C Current advertisement
68
+     *     - dpm_transition_typec() (if I don't like it I can change it)
69
+     *   - Part of dpm_output_default
70
+     *     - Obsolete (see below)
71
+     */
72
+    /* dpm_output_default is only called in PE_SNK_Transition_to_Default.
73
+     * Should probably be part of new improved replacement for dpm_output_set.
74
+     *   - dpm_transition_default()
75
+     */
76
+    pdb_dpm_func transition_default;
77
+    pdb_dpm_func transition_min; /* Optional if no GiveBack */
78
+    pdb_dpm_func transition_standby;
79
+    pdb_dpm_func transition_requested;
80
+    pdb_dpm_func transition_typec; /* Optional */
81
+};
82
+
83
+
84
+#endif /* PDB_DPM_H */

+ 36
- 0
lib/include/pdb_fusb.h Visa fil

@@ -0,0 +1,36 @@
1
+/*
2
+ * PD Buddy - USB Power Delivery for everyone
3
+ * Copyright (C) 2017 Clayton G. Hobbs <clay@lakeserv.net>
4
+ *
5
+ * This program is free software: you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License as published by
7
+ * the Free Software Foundation, either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
+ * GNU General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU General Public License
16
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+
19
+#ifndef PDB_FUSB_H
20
+#define PDB_FUSB_H
21
+
22
+#include <hal.h>
23
+
24
+
25
+/*
26
+ * Configuration for the FUSB302B chip
27
+ */
28
+struct pdb_fusb_config {
29
+    /* The I2C bus that the chip is connected to */
30
+    I2CDriver *i2cp;
31
+    /* The I2C address of the chip */
32
+    i2caddr_t addr;
33
+};
34
+
35
+
36
+#endif /* PDB_FUSB_H */

+ 31
- 0
lib/include/pdb_int_n.h Visa fil

@@ -0,0 +1,31 @@
1
+/*
2
+ * PD Buddy - USB Power Delivery for everyone
3
+ * Copyright (C) 2017 Clayton G. Hobbs <clay@lakeserv.net>
4
+ *
5
+ * This program is free software: you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License as published by
7
+ * the Free Software Foundation, either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
+ * GNU General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU General Public License
16
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+
19
+#ifndef PDB_INT_N_H
20
+#define PDB_INT_N_H
21
+
22
+#include <ch.h>
23
+
24
+
25
+struct pdb_int_n {
26
+    THD_WORKING_AREA(_wa, 128);
27
+    thread_t *thread;
28
+};
29
+
30
+
31
+#endif /* PDB_INT_N_H */

+ 44
- 0
lib/include/pdb_pe.h Visa fil

@@ -0,0 +1,44 @@
1
+/*
2
+ * PD Buddy - USB Power Delivery for everyone
3
+ * Copyright (C) 2017 Clayton G. Hobbs <clay@lakeserv.net>
4
+ *
5
+ * This program is free software: you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License as published by
7
+ * the Free Software Foundation, either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
+ * GNU General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU General Public License
16
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+
19
+#ifndef PDB_PE_H
20
+#define PDB_PE_H
21
+
22
+#include <stdbool.h>
23
+#include <stdint.h>
24
+
25
+#include <ch.h>
26
+
27
+
28
+struct pdb_pe {
29
+    THD_WORKING_AREA(_wa, 128);
30
+    thread_t *thread;
31
+
32
+    mailbox_t mailbox;
33
+
34
+    union pd_msg *_policy_engine_message;
35
+    union pd_msg *_last_dpm_request;
36
+    bool _capability_match;
37
+    bool _explicit_contract;
38
+    bool _min_power;
39
+    int8_t _hard_reset_counter;
40
+    msg_t _mailbox_queue[PDB_MSG_POOL_SIZE];
41
+};
42
+
43
+
44
+#endif /* PDB_PE_H */

+ 45
- 0
lib/include/pdb_prl.h Visa fil

@@ -0,0 +1,45 @@
1
+/*
2
+ * PD Buddy - USB Power Delivery for everyone
3
+ * Copyright (C) 2017 Clayton G. Hobbs <clay@lakeserv.net>
4
+ *
5
+ * This program is free software: you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License as published by
7
+ * the Free Software Foundation, either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
+ * GNU General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU General Public License
16
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+
19
+#ifndef PDB_PRL_H
20
+#define PDB_PRL_H
21
+
22
+#include <stdint.h>
23
+
24
+#include <ch.h>
25
+
26
+
27
+struct pdb_prl {
28
+    THD_WORKING_AREA(_rx_wa, 128);
29
+    thread_t *rx_thread;
30
+    THD_WORKING_AREA(_tx_wa, 128);
31
+    thread_t *tx_thread;
32
+    THD_WORKING_AREA(_hardrst_wa, 128);
33
+    thread_t *hardrst_thread;
34
+
35
+    mailbox_t tx_mailbox;
36
+
37
+    int8_t _rx_messageid;
38
+    union pd_msg *_rx_message;
39
+
40
+    int8_t _tx_messageidcounter;
41
+    msg_t _tx_mailbox_queue[PDB_MSG_POOL_SIZE];
42
+};
43
+
44
+
45
+#endif /* PDB_PRL_H */

+ 7
- 7
lib/src/pdb.c Visa fil

@@ -25,19 +25,19 @@
25 25
 #include "fusb302b.h"
26 26
 
27 27
 
28
-void pdb_init(void)
28
+void pdb_init(struct pdb_config *cfg)
29 29
 {
30 30
     /* Initialize the FUSB302B */
31
-    fusb_setup();
31
+    fusb_setup(cfg);
32 32
 
33 33
     /* Create the policy engine thread. */
34
-    pdb_pe_run();
34
+    pdb_pe_run(cfg);
35 35
 
36 36
     /* Create the protocol layer threads. */
37
-    pdb_prlrx_run();
38
-    pdb_prltx_run();
39
-    pdb_hardrst_run();
37
+    pdb_prlrx_run(cfg);
38
+    pdb_prltx_run(cfg);
39
+    pdb_hardrst_run(cfg);
40 40
 
41 41
     /* Create the INT_N thread. */
42
-    pdb_int_n_run();
42
+    pdb_int_n_run(cfg);
43 43
 }

Laddar…
Avbryt
Spara