Selaa lähdekoodia

Improve the whole messages.h situation

This commit splits the old messages.h file into two, one private
(messages.h) and one public (pdb_msg.h).  This new arrangement keeps the
old model of one message pool for all the PD Buddy firmware library, but
moves the macro for the number of objects it contains into a new file,
pdb_conf.h, placed at the project root.  The pool itself is kept in the
new pdb_msg.h file, since the DPM may need to access it.

The new configuration file also contains the stack sizes for the PD
Buddy threads (some will be moved back to secrecy in the future once the
needed sizes are known, but the PE's stack size should be kept in
pdb_conf.h since user code needs that stack).
Clara Hobbs 7 vuotta sitten
vanhempi
commit
2cbb40c6f7

+ 1
- 1
lib/include/fusb302b.h Näytä tiedosto

@@ -23,7 +23,7 @@
23 23
 
24 24
 #include <pdb_fusb.h>
25 25
 
26
-#include "messages.h"
26
+#include <pdb_msg.h>
27 27
 
28 28
 
29 29
 /* I2C addresses of the FUSB302B chips */

+ 1
- 0
lib/include/pdb.h Näytä tiedosto

@@ -24,6 +24,7 @@
24 24
 #include <pdb_pe.h>
25 25
 #include <pdb_prl.h>
26 26
 #include <pdb_int_n.h>
27
+#include <pdb_msg.h>
27 28
 
28 29
 
29 30
 /*

+ 2
- 2
lib/include/pdb_dpm.h Näytä tiedosto

@@ -21,9 +21,9 @@
21 21
 
22 22
 #include <stdbool.h>
23 23
 
24
-/* TODO: improve these includes */
24
+#include <pdb_msg.h>
25
+/* TODO: improve this include */
25 26
 #include "fusb302b.h"
26
-#include "messages.h"
27 27
 
28 28
 
29 29
 /* Forward declaration of struct pdb_config */

+ 3
- 1
lib/include/pdb_int_n.h Näytä tiedosto

@@ -21,9 +21,11 @@
21 21
 
22 22
 #include <ch.h>
23 23
 
24
+#include "pdb_conf.h"
25
+
24 26
 
25 27
 struct pdb_int_n {
26
-    THD_WORKING_AREA(_wa, 128);
28
+    THD_WORKING_AREA(_wa, PDB_INT_N_WA_SIZE);
27 29
     thread_t *thread;
28 30
 };
29 31
 

lib/include/messages.h → lib/include/pdb_msg.h Näytä tiedosto

@@ -16,8 +16,8 @@
16 16
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 17
  */
18 18
 
19
-#ifndef PDB_MESSAGES_H
20
-#define PDB_MESSAGES_H
19
+#ifndef PDB_MSG_H
20
+#define PDB_MSG_H
21 21
 
22 22
 #include <stdint.h>
23 23
 
@@ -46,15 +46,10 @@ union pd_msg {
46 46
     } __attribute__((packed));
47 47
 };
48 48
 
49
-/* Available messages */
50
-#define PDB_MSG_POOL_SIZE 4
51
-
52
-extern memory_pool_t pdb_msg_pool;
53
-
54 49
 /*
55
- * Initialize the msg_pool
50
+ * The pool of messages used by the library
56 51
  */
57
-void pdb_msg_pool_init(void);
52
+extern memory_pool_t pdb_msg_pool;
58 53
 
59 54
 
60
-#endif /* PDB_MESSAGES_H */
55
+#endif /* PDB_MSG_H */

+ 3
- 1
lib/include/pdb_pe.h Näytä tiedosto

@@ -24,6 +24,8 @@
24 24
 
25 25
 #include <ch.h>
26 26
 
27
+#include "pdb_conf.h"
28
+
27 29
 /*
28 30
  * Events for the Policy Engine thread, sent by user code
29 31
  */
@@ -37,7 +39,7 @@
37 39
  * Structure for Policy Engine thread and variables
38 40
  */
39 41
 struct pdb_pe {
40
-    THD_WORKING_AREA(_wa, 256);
42
+    THD_WORKING_AREA(_wa, PDB_PE_WA_SIZE);
41 43
     thread_t *thread;
42 44
 
43 45
     /* PE mailbox for received PD messages */

+ 5
- 3
lib/include/pdb_prl.h Näytä tiedosto

@@ -23,13 +23,15 @@
23 23
 
24 24
 #include <ch.h>
25 25
 
26
+#include "pdb_conf.h"
27
+
26 28
 
27 29
 struct pdb_prl {
28
-    THD_WORKING_AREA(_rx_wa, 256);
30
+    THD_WORKING_AREA(_rx_wa, PDB_PRLRX_WA_SIZE);
29 31
     thread_t *rx_thread;
30
-    THD_WORKING_AREA(_tx_wa, 256);
32
+    THD_WORKING_AREA(_tx_wa, PDB_PRLTX_WA_SIZE);
31 33
     thread_t *tx_thread;
32
-    THD_WORKING_AREA(_hardrst_wa, 256);
34
+    THD_WORKING_AREA(_hardrst_wa, PDB_HARDRST_WA_SIZE);
33 35
     thread_t *hardrst_thread;
34 36
 
35 37
     mailbox_t tx_mailbox;

+ 4
- 0
lib/src/messages.c Näytä tiedosto

@@ -18,6 +18,10 @@
18 18
 
19 19
 #include "messages.h"
20 20
 
21
+#include <pdb_msg.h>
22
+
23
+#include "pdb_conf.h"
24
+
21 25
 
22 26
 /* The messages that will be available for threads to pass each other */
23 27
 static union pd_msg pd_messages[PDB_MSG_POOL_SIZE] __attribute__((aligned(sizeof(stkalign_t))));

+ 29
- 0
lib/src/messages.h Näytä tiedosto

@@ -0,0 +1,29 @@
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_MESSAGES_H
20
+#define PDB_MESSAGES_H
21
+
22
+
23
+/*
24
+ * Initialize the pdb_msg_pool
25
+ */
26
+void pdb_msg_pool_init(void);
27
+
28
+
29
+#endif /* PDB_MESSAGES_H */

+ 1
- 1
lib/src/pdb.c Näytä tiedosto

@@ -29,7 +29,7 @@
29 29
 void pdb_init(struct pdb_config *cfg)
30 30
 {
31 31
     /* Initialize the empty message pool */
32
-    pdb_msg_pool_init(/*TODO cfg*/);
32
+    pdb_msg_pool_init();
33 33
 
34 34
     /* Initialize the FUSB302B */
35 35
     fusb_setup(&cfg->fusb);

+ 0
- 1
lib/src/policy_engine.c Näytä tiedosto

@@ -20,7 +20,6 @@
20 20
 
21 21
 #include <stdbool.h>
22 22
 
23
-#include "messages.h"
24 23
 #include "priorities.h"
25 24
 #include "protocol_tx.h"
26 25
 #include "hard_reset.h"

+ 0
- 1
lib/src/protocol_rx.c Näytä tiedosto

@@ -24,7 +24,6 @@
24 24
 #include "policy_engine.h"
25 25
 #include "protocol_tx.h"
26 26
 #include "fusb302b.h"
27
-#include "messages.h"
28 27
 #include "pd.h"
29 28
 
30 29
 

+ 0
- 1
lib/src/protocol_tx.c Näytä tiedosto

@@ -22,7 +22,6 @@
22 22
 #include "policy_engine.h"
23 23
 #include "protocol_rx.h"
24 24
 #include "fusb302b.h"
25
-#include "messages.h"
26 25
 #include "pd.h"
27 26
 
28 27
 

+ 42
- 0
lib/templates/pdb_conf.h Näytä tiedosto

@@ -0,0 +1,42 @@
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_CONF_H
20
+#define PDB_CONF_H
21
+
22
+
23
+/* Number of messages in the message pool */
24
+#define PDB_MSG_POOL_SIZE 4
25
+
26
+/* Size of the Policy Engine thread's working area */
27
+#define PDB_PE_WA_SIZE 256
28
+
29
+/* Size of the protocol layer RX thread's working area */
30
+#define PDB_PRLRX_WA_SIZE 256
31
+
32
+/* Size of the protocol layer TX thread's working area */
33
+#define PDB_PRLTX_WA_SIZE 256
34
+
35
+/* Size of the protocol layer hard reset thread's working area */
36
+#define PDB_HARDRST_WA_SIZE 256
37
+
38
+/* Size of the INT_N thread's working area */
39
+#define PDB_INT_N_WA_SIZE 128
40
+
41
+
42
+#endif /* PDB_CONF_H */

+ 42
- 0
pdb_conf.h Näytä tiedosto

@@ -0,0 +1,42 @@
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_CONF_H
20
+#define PDB_CONF_H
21
+
22
+
23
+/* Number of messages in the message pool */
24
+#define PDB_MSG_POOL_SIZE 4
25
+
26
+/* Size of the Policy Engine thread's working area */
27
+#define PDB_PE_WA_SIZE 256
28
+
29
+/* Size of the protocol layer RX thread's working area */
30
+#define PDB_PRLRX_WA_SIZE 256
31
+
32
+/* Size of the protocol layer TX thread's working area */
33
+#define PDB_PRLTX_WA_SIZE 256
34
+
35
+/* Size of the protocol layer hard reset thread's working area */
36
+#define PDB_HARDRST_WA_SIZE 256
37
+
38
+/* Size of the INT_N thread's working area */
39
+#define PDB_INT_N_WA_SIZE 128
40
+
41
+
42
+#endif /* PDB_CONF_H */

+ 0
- 1
src/device_policy_manager.h Näytä tiedosto

@@ -23,7 +23,6 @@
23 23
 
24 24
 #include <pdb.h>
25 25
 #include "fusb302b.h"
26
-#include "messages.h"
27 26
 
28 27
 
29 28
 struct pdbs_dpm_data {

Loading…
Peruuta
Tallenna