Kaynağa Gözat

Changed PDO getters to take just the PDO

Previously, the PDO attribute getter macros took a capabilities message
and the PDO index.  This worked in a lot of cases, but not in some I
need now, and there was little advantage to them working they way they
did anyway.  Now they take just the PDO itself, which is more intuitive
and more useful.
Clara Hobbs 6 yıl önce
ebeveyn
işleme
61992f5088
2 değiştirilmiş dosya ile 30 ekleme ve 30 silme
  1. 5
    5
      lib/include/pd.h
  2. 25
    25
      src/device_policy_manager.c

+ 5
- 5
lib/include/pd.h Dosyayı Görüntüle

@@ -172,10 +172,10 @@
172 172
 #define PD_PDO_SRC_FIXED_CURRENT (0x3FF << PD_PDO_SRC_FIXED_CURRENT_SHIFT)
173 173
 
174 174
 /* PD Source Fixed PDO current */
175
-#define PD_PDO_SRC_FIXED_CURRENT_GET(msg, i) (((msg)->obj[(i)] & PD_PDO_SRC_FIXED_CURRENT) >> PD_PDO_SRC_FIXED_CURRENT_SHIFT)
175
+#define PD_PDO_SRC_FIXED_CURRENT_GET(pdo) (((pdo) & PD_PDO_SRC_FIXED_CURRENT) >> PD_PDO_SRC_FIXED_CURRENT_SHIFT)
176 176
 
177 177
 /* PD Source Fixed PDO voltage */
178
-#define PD_PDO_SRC_FIXED_VOLTAGE_GET(msg, i) (((msg)->obj[(i)] & PD_PDO_SRC_FIXED_VOLTAGE) >> PD_PDO_SRC_FIXED_VOLTAGE_SHIFT)
178
+#define PD_PDO_SRC_FIXED_VOLTAGE_GET(pdo) (((pdo) & PD_PDO_SRC_FIXED_VOLTAGE) >> PD_PDO_SRC_FIXED_VOLTAGE_SHIFT)
179 179
 
180 180
 /* PD Programmable Power Supply APDO */
181 181
 #define PD_APDO_PPS_MAX_VOLTAGE_SHIFT 17
@@ -186,14 +186,14 @@
186 186
 #define PD_APDO_PPS_CURRENT (0x7F << PD_APDO_PPS_CURRENT_SHIFT)
187 187
 
188 188
 /* PD Programmable Power Supply APDO voltages */
189
-#define PD_APDO_PPS_MAX_VOLTAGE_GET(msg, i) (((msg)->obj[(i)] & PD_APDO_PPS_MAX_VOLTAGE) >> PD_APDO_PPS_MAX_VOLTAGE_SHIFT)
190
-#define PD_APDO_PPS_MIN_VOLTAGE_GET(msg, i) (((msg)->obj[(i)] & PD_APDO_PPS_MIN_VOLTAGE) >> PD_APDO_PPS_MIN_VOLTAGE_SHIFT)
189
+#define PD_APDO_PPS_MAX_VOLTAGE_GET(pdo) (((pdo) & PD_APDO_PPS_MAX_VOLTAGE) >> PD_APDO_PPS_MAX_VOLTAGE_SHIFT)
190
+#define PD_APDO_PPS_MIN_VOLTAGE_GET(pdo) (((pdo) & PD_APDO_PPS_MIN_VOLTAGE) >> PD_APDO_PPS_MIN_VOLTAGE_SHIFT)
191 191
 
192 192
 #define PD_APDO_PPS_MAX_VOLTAGE_SET(v) (((v) << PD_APDO_PPS_MAX_VOLTAGE_SHIFT) & PD_APDO_PPS_MAX_VOLTAGE)
193 193
 #define PD_APDO_PPS_MIN_VOLTAGE_SET(v) (((v) << PD_APDO_PPS_MIN_VOLTAGE_SHIFT) & PD_APDO_PPS_MIN_VOLTAGE)
194 194
 
195 195
 /* PD Programmable Power Supply APDO current */
196
-#define PD_APDO_PPS_CURRENT_GET(msg, i) (((msg)->obj[(i)] & PD_APDO_PPS_CURRENT) >> PD_APDO_PPS_CURRENT_SHIFT)
196
+#define PD_APDO_PPS_CURRENT_GET(pdo) (((pdo) & PD_APDO_PPS_CURRENT) >> PD_APDO_PPS_CURRENT_SHIFT)
197 197
 
198 198
 #define PD_APDO_PPS_CURRENT_SET(i) (((i) << PD_APDO_PPS_CURRENT_SHIFT) & PD_APDO_PPS_CURRENT)
199 199
 

+ 25
- 25
src/device_policy_manager.c Dosyayı Görüntüle

@@ -38,11 +38,11 @@
38 38
  *
39 39
  * If there is no such PDO, returns -1 instead.
40 40
  */
41
-static int8_t dpm_get_range_fixed_pdo_index(const union pd_msg *capabilities,
41
+static int8_t dpm_get_range_fixed_pdo_index(const union pd_msg *caps,
42 42
         struct pdbs_config *scfg)
43 43
 {
44 44
     /* Get the number of PDOs */
45
-    uint8_t numobj = PD_NUMOBJ_GET(capabilities);
45
+    uint8_t numobj = PD_NUMOBJ_GET(caps);
46 46
 
47 47
     /* Get ready to iterate over the PDOs */
48 48
     int8_t i;
@@ -59,10 +59,10 @@ static int8_t dpm_get_range_fixed_pdo_index(const union pd_msg *capabilities,
59 59
     while (0 <= i && i < numobj) {
60 60
         /* If we have a fixed PDO, its V is within our range, and its I is at
61 61
          * least our desired I */
62
-        if ((capabilities->obj[i] & PD_PDO_TYPE) == PD_PDO_TYPE_FIXED
63
-                && PD_PDO_SRC_FIXED_CURRENT_GET(capabilities, i) >= scfg->i
64
-                && PD_PDO_SRC_FIXED_VOLTAGE_GET(capabilities, i) >= PD_MV2PDV(scfg->vmin)
65
-                && PD_PDO_SRC_FIXED_VOLTAGE_GET(capabilities, i) <= PD_MV2PDV(scfg->vmax)) {
62
+        if ((caps->obj[i] & PD_PDO_TYPE) == PD_PDO_TYPE_FIXED
63
+                && PD_PDO_SRC_FIXED_CURRENT_GET(caps->obj[i]) >= scfg->i
64
+                && PD_PDO_SRC_FIXED_VOLTAGE_GET(caps->obj[i]) >= PD_MV2PDV(scfg->vmin)
65
+                && PD_PDO_SRC_FIXED_VOLTAGE_GET(caps->obj[i]) <= PD_MV2PDV(scfg->vmax)) {
66 66
             return i;
67 67
         }
68 68
         i += step;
@@ -71,26 +71,26 @@ static int8_t dpm_get_range_fixed_pdo_index(const union pd_msg *capabilities,
71 71
 }
72 72
 
73 73
 bool pdbs_dpm_evaluate_capability(struct pdb_config *cfg,
74
-        const union pd_msg *capabilities, union pd_msg *request)
74
+        const union pd_msg *caps, union pd_msg *request)
75 75
 {
76 76
     /* Cast the dpm_data to the right type */
77 77
     struct pdbs_dpm_data *dpm_data = cfg->dpm_data;
78 78
 
79 79
     /* Update the stored Source_Capabilities */
80
-    if (capabilities != NULL) {
80
+    if (caps != NULL) {
81 81
         if (dpm_data->capabilities != NULL) {
82 82
             chPoolFree(&pdb_msg_pool, (union pd_msg *) dpm_data->capabilities);
83 83
         }
84
-        dpm_data->capabilities = capabilities;
84
+        dpm_data->capabilities = caps;
85 85
     } else {
86 86
         /* No new capabilities; use a shorter name for the stored ones. */
87
-        capabilities = dpm_data->capabilities;
87
+        caps = dpm_data->capabilities;
88 88
     }
89 89
 
90 90
     /* Get the current configuration */
91 91
     struct pdbs_config *scfg = pdbs_config_flash_read();
92 92
     /* Get the number of PDOs */
93
-    uint8_t numobj = PD_NUMOBJ_GET(capabilities);
93
+    uint8_t numobj = PD_NUMOBJ_GET(caps);
94 94
 
95 95
     /* Make the LED blink to indicate ongoing power negotiations */
96 96
     if (dpm_data->led_pd_status) {
@@ -98,7 +98,7 @@ bool pdbs_dpm_evaluate_capability(struct pdb_config *cfg,
98 98
     }
99 99
 
100 100
     /* Get whether or not the power supply is constrained */
101
-    dpm_data->_unconstrained_power = capabilities->obj[0] & PD_PDO_SRC_FIXED_UNCONSTRAINED;
101
+    dpm_data->_unconstrained_power = caps->obj[0] & PD_PDO_SRC_FIXED_UNCONSTRAINED;
102 102
 
103 103
     /* Make sure we have configuration */
104 104
     if (scfg != NULL && dpm_data->output_enabled) {
@@ -106,9 +106,9 @@ bool pdbs_dpm_evaluate_capability(struct pdb_config *cfg,
106 106
         for (uint8_t i = 0; i < numobj; i++) {
107 107
             /* If we have a fixed PDO, its V equals our desired V, and its I is
108 108
              * at least our desired I */
109
-            if ((capabilities->obj[i] & PD_PDO_TYPE) == PD_PDO_TYPE_FIXED
110
-                    && PD_PDO_SRC_FIXED_VOLTAGE_GET(capabilities, i) == PD_MV2PDV(scfg->v)
111
-                    && PD_PDO_SRC_FIXED_CURRENT_GET(capabilities, i) >= scfg->i) {
109
+            if ((caps->obj[i] & PD_PDO_TYPE) == PD_PDO_TYPE_FIXED
110
+                    && PD_PDO_SRC_FIXED_VOLTAGE_GET(caps->obj[i]) == PD_MV2PDV(scfg->v)
111
+                    && PD_PDO_SRC_FIXED_CURRENT_GET(caps->obj[i]) >= scfg->i) {
112 112
                 /* We got what we wanted, so build a request for that */
113 113
                 request->hdr = cfg->pe.hdr_template | PD_MSGTYPE_REQUEST
114 114
                     | PD_NUMOBJ(1);
@@ -136,11 +136,11 @@ bool pdbs_dpm_evaluate_capability(struct pdb_config *cfg,
136 136
             }
137 137
             /* If we have a PPS APDO, our desired V lies within its range, and
138 138
              * its I is at least our desired I */
139
-            if ((capabilities->obj[i] & PD_PDO_TYPE) == PD_PDO_TYPE_AUGMENTED
140
-                    && (capabilities->obj[i] & PD_APDO_TYPE) == PD_APDO_TYPE_PPS
141
-                    && PD_APDO_PPS_MAX_VOLTAGE_GET(capabilities, i) >= PD_MV2PAV(scfg->v)
142
-                    && PD_APDO_PPS_MIN_VOLTAGE_GET(capabilities, i) <= PD_MV2PAV(scfg->v)
143
-                    && PD_APDO_PPS_CURRENT_GET(capabilities, i) >= PD_CA2PAI(scfg->i)) {
139
+            if ((caps->obj[i] & PD_PDO_TYPE) == PD_PDO_TYPE_AUGMENTED
140
+                    && (caps->obj[i] & PD_APDO_TYPE) == PD_APDO_TYPE_PPS
141
+                    && PD_APDO_PPS_MAX_VOLTAGE_GET(caps->obj[i]) >= PD_MV2PAV(scfg->v)
142
+                    && PD_APDO_PPS_MIN_VOLTAGE_GET(caps->obj[i]) <= PD_MV2PAV(scfg->v)
143
+                    && PD_APDO_PPS_CURRENT_GET(caps->obj[i]) >= PD_CA2PAI(scfg->i)) {
144 144
                 /* We got what we wanted, so build a request for that */
145 145
                 request->hdr = cfg->pe.hdr_template | PD_MSGTYPE_REQUEST
146 146
                     | PD_NUMOBJ(1);
@@ -161,7 +161,7 @@ bool pdbs_dpm_evaluate_capability(struct pdb_config *cfg,
161 161
             }
162 162
         }
163 163
         /* If there's a PDO in the voltage range, use it */
164
-        int8_t i = dpm_get_range_fixed_pdo_index(capabilities, scfg);
164
+        int8_t i = dpm_get_range_fixed_pdo_index(caps, scfg);
165 165
         if (i >= 0) {
166 166
             /* We got what we wanted, so build a request for that */
167 167
             request->hdr = cfg->pe.hdr_template | PD_MSGTYPE_REQUEST
@@ -183,7 +183,7 @@ bool pdbs_dpm_evaluate_capability(struct pdb_config *cfg,
183 183
             }
184 184
 
185 185
             /* Update requested voltage */
186
-            dpm_data->_requested_voltage = PD_PDV2MV(PD_PDO_SRC_FIXED_VOLTAGE_GET(capabilities, i));
186
+            dpm_data->_requested_voltage = PD_PDV2MV(PD_PDO_SRC_FIXED_VOLTAGE_GET(caps->obj[i]));
187 187
 
188 188
             dpm_data->_capability_match = true;
189 189
             return true;
@@ -252,10 +252,10 @@ void pdbs_dpm_get_sink_capability(struct pdb_config *cfg, union pd_msg *cap)
252 252
 
253 253
             /* If the range PDO is a different voltage than the preferred
254 254
              * voltage, add it to the array. */
255
-            if (i > 0 && PD_PDO_SRC_FIXED_VOLTAGE_GET(dpm_data->capabilities, i) != PD_MV2PDV(scfg->v)) {
255
+            if (i > 0 && PD_PDO_SRC_FIXED_VOLTAGE_GET(dpm_data->capabilities->obj[i]) != PD_MV2PDV(scfg->v)) {
256 256
                 cap->obj[numobj++] = PD_PDO_TYPE_FIXED
257
-                    | PD_PDO_SNK_FIXED_VOLTAGE_SET(PD_PDO_SRC_FIXED_VOLTAGE_GET(dpm_data->capabilities, i))
258
-                    | PD_PDO_SNK_FIXED_CURRENT_SET(PD_PDO_SRC_FIXED_CURRENT_GET(dpm_data->capabilities, i));
257
+                    | PD_PDO_SNK_FIXED_VOLTAGE_SET(PD_PDO_SRC_FIXED_VOLTAGE_GET(dpm_data->capabilities->obj[i]))
258
+                    | PD_PDO_SNK_FIXED_CURRENT_SET(PD_PDO_SRC_FIXED_CURRENT_GET(dpm_data->capabilities->obj[i]));
259 259
             }
260 260
 
261 261
             /* If we have three PDOs at this point, make sure the last two are

Loading…
İptal
Kaydet