|
@@ -60,9 +60,6 @@ static bool explicit_contract = false;
|
60
|
60
|
static bool min_power = false;
|
61
|
61
|
/* Keep track of how many hard resets we've sent */
|
62
|
62
|
static int hard_reset_counter = 0;
|
63
|
|
-/* Policy Engine thread mailbox */
|
64
|
|
-static msg_t pdb_pe_mailbox_queue[PDB_MSG_POOL_SIZE];
|
65
|
|
-mailbox_t pdb_pe_mailbox;
|
66
|
63
|
|
67
|
64
|
static enum policy_engine_state pe_sink_startup(struct pdb_config *cfg)
|
68
|
65
|
{
|
|
@@ -110,7 +107,7 @@ static enum policy_engine_state pe_sink_wait_cap(struct pdb_config *cfg)
|
110
|
107
|
/* If we got a message */
|
111
|
108
|
if (evt & PDB_EVT_PE_MSG_RX) {
|
112
|
109
|
/* Get the message */
|
113
|
|
- if (chMBFetch(&pdb_pe_mailbox, (msg_t *) &policy_engine_message, TIME_IMMEDIATE) == MSG_OK) {
|
|
110
|
+ if (chMBFetch(&cfg->pe.mailbox, (msg_t *) &policy_engine_message, TIME_IMMEDIATE) == MSG_OK) {
|
114
|
111
|
/* If we got a Source_Capabilities message, read it. */
|
115
|
112
|
if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_SOURCE_CAPABILITIES
|
116
|
113
|
&& PD_NUMOBJ_GET(policy_engine_message) > 0) {
|
|
@@ -181,7 +178,7 @@ static enum policy_engine_state pe_sink_select_cap(struct pdb_config *cfg)
|
181
|
178
|
}
|
182
|
179
|
|
183
|
180
|
/* Get the response message */
|
184
|
|
- if (chMBFetch(&pdb_pe_mailbox, (msg_t *) &policy_engine_message, TIME_IMMEDIATE) == MSG_OK) {
|
|
181
|
+ if (chMBFetch(&cfg->pe.mailbox, (msg_t *) &policy_engine_message, TIME_IMMEDIATE) == MSG_OK) {
|
185
|
182
|
/* If the source accepted our request, wait for the new power */
|
186
|
183
|
if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_ACCEPT
|
187
|
184
|
&& PD_NUMOBJ_GET(policy_engine_message) == 0) {
|
|
@@ -242,7 +239,7 @@ static enum policy_engine_state pe_sink_transition_sink(struct pdb_config *cfg)
|
242
|
239
|
}
|
243
|
240
|
|
244
|
241
|
/* If we received a message, read it */
|
245
|
|
- if (chMBFetch(&pdb_pe_mailbox, (msg_t *) &policy_engine_message, TIME_IMMEDIATE) == MSG_OK) {
|
|
242
|
+ if (chMBFetch(&cfg->pe.mailbox, (msg_t *) &policy_engine_message, TIME_IMMEDIATE) == MSG_OK) {
|
246
|
243
|
/* If we got a PS_RDY, handle it */
|
247
|
244
|
if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_PS_RDY
|
248
|
245
|
&& PD_NUMOBJ_GET(policy_engine_message) == 0) {
|
|
@@ -324,7 +321,7 @@ static enum policy_engine_state pe_sink_ready(struct pdb_config *cfg)
|
324
|
321
|
|
325
|
322
|
/* If we received a message */
|
326
|
323
|
if (evt & PDB_EVT_PE_MSG_RX) {
|
327
|
|
- if (chMBFetch(&pdb_pe_mailbox, (msg_t *) &policy_engine_message, TIME_IMMEDIATE) == MSG_OK) {
|
|
324
|
+ if (chMBFetch(&cfg->pe.mailbox, (msg_t *) &policy_engine_message, TIME_IMMEDIATE) == MSG_OK) {
|
328
|
325
|
/* Ignore vendor-defined messages */
|
329
|
326
|
if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_VENDOR_DEFINED
|
330
|
327
|
&& PD_NUMOBJ_GET(policy_engine_message) > 0) {
|
|
@@ -581,7 +578,7 @@ static enum policy_engine_state pe_sink_send_soft_reset(struct pdb_config *cfg)
|
581
|
578
|
}
|
582
|
579
|
|
583
|
580
|
/* Get the response message */
|
584
|
|
- if (chMBFetch(&pdb_pe_mailbox, (msg_t *) &policy_engine_message, TIME_IMMEDIATE) == MSG_OK) {
|
|
581
|
+ if (chMBFetch(&cfg->pe.mailbox, (msg_t *) &policy_engine_message, TIME_IMMEDIATE) == MSG_OK) {
|
585
|
582
|
/* If the source accepted our soft reset, wait for capabilities. */
|
586
|
583
|
if (PD_MSGTYPE_GET(policy_engine_message) == PD_MSGTYPE_ACCEPT
|
587
|
584
|
&& PD_NUMOBJ_GET(policy_engine_message) == 0) {
|
|
@@ -659,11 +656,12 @@ static enum policy_engine_state pe_sink_source_unresponsive(struct pdb_config *c
|
659
|
656
|
/*
|
660
|
657
|
* Policy Engine state machine thread
|
661
|
658
|
*/
|
662
|
|
-static THD_FUNCTION(PolicyEngine, cfg) {
|
|
659
|
+static THD_FUNCTION(PolicyEngine, vcfg) {
|
|
660
|
+ struct pdb_config *cfg = vcfg;
|
663
|
661
|
enum policy_engine_state state = PESinkStartup;
|
664
|
662
|
|
665
|
663
|
/* Initialize the mailbox */
|
666
|
|
- chMBObjectInit(&pdb_pe_mailbox, pdb_pe_mailbox_queue, PDB_MSG_POOL_SIZE);
|
|
664
|
+ chMBObjectInit(&cfg->pe.mailbox, cfg->pe._mailbox_queue, PDB_MSG_POOL_SIZE);
|
667
|
665
|
|
668
|
666
|
while (true) {
|
669
|
667
|
switch (state) {
|