Browse Source

Use a template for PD message headers

The new tempate variable sets the data role, power role, and
specification revision in one fell swoop.  It's used by the PE and DPM
alike for creating messages, and in the future it may have a part in
determining if we're doing PD 2.0 or 3.0.
Clara Hobbs 7 years ago
parent
commit
6ba7bfdbf3
3 changed files with 14 additions and 14 deletions
  1. 2
    0
      lib/include/pdb_pe.h
  2. 7
    8
      lib/src/policy_engine.c
  3. 5
    6
      src/device_policy_manager.c

+ 2
- 0
lib/include/pdb_pe.h View File

45
 
45
 
46
     /* PE mailbox for received PD messages */
46
     /* PE mailbox for received PD messages */
47
     mailbox_t mailbox;
47
     mailbox_t mailbox;
48
+    /* PD message header template */
49
+    uint16_t hdr_template;
48
 
50
 
49
     /* The received message we're currently working with */
51
     /* The received message we're currently working with */
50
     union pd_msg *_message;
52
     union pd_msg *_message;

+ 7
- 8
lib/src/policy_engine.c View File

409
     /* Get a message object */
409
     /* Get a message object */
410
     union pd_msg *get_source_cap = chPoolAlloc(&pdb_msg_pool);
410
     union pd_msg *get_source_cap = chPoolAlloc(&pdb_msg_pool);
411
     /* Make a Get_Source_Cap message */
411
     /* Make a Get_Source_Cap message */
412
-    get_source_cap->hdr = PD_MSGTYPE_GET_SOURCE_CAP | PD_DATAROLE_UFP
413
-        | PD_SPECREV_2_0 | PD_POWERROLE_SINK | PD_NUMOBJ(0);
412
+    get_source_cap->hdr = cfg->pe.hdr_template | PD_MSGTYPE_GET_SOURCE_CAP
413
+        | PD_NUMOBJ(0);
414
     /* Transmit the Get_Source_Cap */
414
     /* Transmit the Get_Source_Cap */
415
     chMBPost(&cfg->prl.tx_mailbox, (msg_t) get_source_cap, TIME_IMMEDIATE);
415
     chMBPost(&cfg->prl.tx_mailbox, (msg_t) get_source_cap, TIME_IMMEDIATE);
416
     chEvtSignal(cfg->prl.tx_thread, PDB_EVT_PRLTX_MSG_TX);
416
     chEvtSignal(cfg->prl.tx_thread, PDB_EVT_PRLTX_MSG_TX);
503
     /* Get a message object */
503
     /* Get a message object */
504
     union pd_msg *accept = chPoolAlloc(&pdb_msg_pool);
504
     union pd_msg *accept = chPoolAlloc(&pdb_msg_pool);
505
     /* Make an Accept message */
505
     /* Make an Accept message */
506
-    accept->hdr = PD_MSGTYPE_ACCEPT | PD_DATAROLE_UFP | PD_SPECREV_2_0
507
-        | PD_POWERROLE_SINK | PD_NUMOBJ(0);
506
+    accept->hdr = cfg->pe.hdr_template | PD_MSGTYPE_ACCEPT | PD_NUMOBJ(0);
508
     /* Transmit the Accept */
507
     /* Transmit the Accept */
509
     chMBPost(&cfg->prl.tx_mailbox, (msg_t) accept, TIME_IMMEDIATE);
508
     chMBPost(&cfg->prl.tx_mailbox, (msg_t) accept, TIME_IMMEDIATE);
510
     chEvtSignal(cfg->prl.tx_thread, PDB_EVT_PRLTX_MSG_TX);
509
     chEvtSignal(cfg->prl.tx_thread, PDB_EVT_PRLTX_MSG_TX);
533
     /* Get a message object */
532
     /* Get a message object */
534
     union pd_msg *softrst = chPoolAlloc(&pdb_msg_pool);
533
     union pd_msg *softrst = chPoolAlloc(&pdb_msg_pool);
535
     /* Make a Soft_Reset message */
534
     /* Make a Soft_Reset message */
536
-    softrst->hdr = PD_MSGTYPE_SOFT_RESET | PD_DATAROLE_UFP | PD_SPECREV_2_0
537
-        | PD_POWERROLE_SINK | PD_NUMOBJ(0);
535
+    softrst->hdr = cfg->pe.hdr_template | PD_MSGTYPE_SOFT_RESET | PD_NUMOBJ(0);
538
     /* Transmit the soft reset */
536
     /* Transmit the soft reset */
539
     chMBPost(&cfg->prl.tx_mailbox, (msg_t) softrst, TIME_IMMEDIATE);
537
     chMBPost(&cfg->prl.tx_mailbox, (msg_t) softrst, TIME_IMMEDIATE);
540
     chEvtSignal(cfg->prl.tx_thread, PDB_EVT_PRLTX_MSG_TX);
538
     chEvtSignal(cfg->prl.tx_thread, PDB_EVT_PRLTX_MSG_TX);
593
     /* Get a message object */
591
     /* Get a message object */
594
     union pd_msg *reject = chPoolAlloc(&pdb_msg_pool);
592
     union pd_msg *reject = chPoolAlloc(&pdb_msg_pool);
595
     /* Make a Reject message */
593
     /* Make a Reject message */
596
-    reject->hdr = PD_MSGTYPE_REJECT | PD_DATAROLE_UFP | PD_SPECREV_2_0
597
-        | PD_POWERROLE_SINK | PD_NUMOBJ(0);
594
+    reject->hdr = cfg->pe.hdr_template | PD_MSGTYPE_REJECT | PD_NUMOBJ(0);
598
 
595
 
599
     /* Transmit the message */
596
     /* Transmit the message */
600
     chMBPost(&cfg->prl.tx_mailbox, (msg_t) reject, TIME_IMMEDIATE);
597
     chMBPost(&cfg->prl.tx_mailbox, (msg_t) reject, TIME_IMMEDIATE);
655
     chMBObjectInit(&cfg->pe.mailbox, cfg->pe._mailbox_queue, PDB_MSG_POOL_SIZE);
652
     chMBObjectInit(&cfg->pe.mailbox, cfg->pe._mailbox_queue, PDB_MSG_POOL_SIZE);
656
     /* Initialize the old_tcc_match */
653
     /* Initialize the old_tcc_match */
657
     cfg->pe._old_tcc_match = -1;
654
     cfg->pe._old_tcc_match = -1;
655
+    /* Initialize the PD message header template */
656
+    cfg->pe.hdr_template = PD_DATAROLE_UFP | PD_SPECREV_2_0 | PD_POWERROLE_SINK;
658
 
657
 
659
     while (true) {
658
     while (true) {
660
         switch (state) {
659
         switch (state) {

+ 5
- 6
src/device_policy_manager.c View File

75
             if (PD_PDO_SRC_FIXED_VOLTAGE_GET(capabilities, i) == scfg->v
75
             if (PD_PDO_SRC_FIXED_VOLTAGE_GET(capabilities, i) == scfg->v
76
                     && PD_PDO_SRC_FIXED_CURRENT_GET(capabilities, i) >= scfg->i) {
76
                     && PD_PDO_SRC_FIXED_CURRENT_GET(capabilities, i) >= scfg->i) {
77
                 /* We got what we wanted, so build a request for that */
77
                 /* We got what we wanted, so build a request for that */
78
-                request->hdr = PD_MSGTYPE_REQUEST | PD_DATAROLE_UFP |
79
-                    PD_SPECREV_2_0 | PD_POWERROLE_SINK | PD_NUMOBJ(1);
78
+                request->hdr = cfg->pe.hdr_template | PD_MSGTYPE_REQUEST
79
+                    | PD_NUMOBJ(1);
80
                 if (scfg->flags & PDBS_CONFIG_FLAGS_GIVEBACK) {
80
                 if (scfg->flags & PDBS_CONFIG_FLAGS_GIVEBACK) {
81
                     /* GiveBack enabled */
81
                     /* GiveBack enabled */
82
                     request->obj[0] = PD_RDO_FV_MIN_CURRENT_SET(DPM_MIN_CURRENT)
82
                     request->obj[0] = PD_RDO_FV_MIN_CURRENT_SET(DPM_MIN_CURRENT)
102
         }
102
         }
103
     }
103
     }
104
     /* Nothing matched (or no configuration), so get 5 V at low current */
104
     /* Nothing matched (or no configuration), so get 5 V at low current */
105
-    request->hdr = PD_MSGTYPE_REQUEST | PD_DATAROLE_UFP |
106
-        PD_SPECREV_2_0 | PD_POWERROLE_SINK | PD_NUMOBJ(1);
105
+    request->hdr = cfg->pe.hdr_template | PD_MSGTYPE_REQUEST | PD_NUMOBJ(1);
107
     request->obj[0] = PD_RDO_FV_MAX_CURRENT_SET(DPM_MIN_CURRENT)
106
     request->obj[0] = PD_RDO_FV_MAX_CURRENT_SET(DPM_MIN_CURRENT)
108
         | PD_RDO_FV_CURRENT_SET(DPM_MIN_CURRENT)
107
         | PD_RDO_FV_CURRENT_SET(DPM_MIN_CURRENT)
109
         | PD_RDO_NO_USB_SUSPEND
108
         | PD_RDO_NO_USB_SUSPEND
166
     }
165
     }
167
 
166
 
168
     /* Set the Sink_Capabilities message header */
167
     /* Set the Sink_Capabilities message header */
169
-    cap->hdr = PD_MSGTYPE_SINK_CAPABILITIES | PD_DATAROLE_UFP | PD_SPECREV_2_0
170
-        | PD_POWERROLE_SINK | PD_NUMOBJ(numobj);
168
+    cap->hdr = cfg->pe.hdr_template | PD_MSGTYPE_SINK_CAPABILITIES
169
+        | PD_NUMOBJ(numobj);
171
 }
170
 }
172
 
171
 
173
 bool pdbs_dpm_giveback_enabled(struct pdb_config *cfg)
172
 bool pdbs_dpm_giveback_enabled(struct pdb_config *cfg)

Loading…
Cancel
Save