]>
Commit | Line | Data |
---|---|---|
0549416e JC |
1 | /* |
2 | * This file is part of the libsigrok project. | |
3 | * | |
4 | * Copyright (C) 2018 James Churchill <pelrun@gmail.com> | |
7c0891b0 | 5 | * Copyright (C) 2019 Frank Stettner <frank-stettner@gmx.net> |
d7a4dad8 | 6 | * Copyright (C) 2021 Gerhard Sittig <gerhard.sittig@gmx.net> |
0549416e JC |
7 | * |
8 | * This program is free software: you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation, either version 3 of the License, or | |
11 | * (at your option) any later version. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 | */ | |
21 | ||
22 | #ifndef LIBSIGROK_HARDWARE_RDTECH_DPS_PROTOCOL_H | |
23 | #define LIBSIGROK_HARDWARE_RDTECH_DPS_PROTOCOL_H | |
24 | ||
5352598f | 25 | #include "config.h" |
d7a4dad8 | 26 | |
0549416e JC |
27 | #include <glib.h> |
28 | #include <libsigrok/libsigrok.h> | |
d7a4dad8 GS |
29 | #include <stdint.h> |
30 | ||
0549416e JC |
31 | #include "libsigrok-internal.h" |
32 | ||
33 | #define LOG_PREFIX "rdtech-dps" | |
34 | ||
884ae8c0 GS |
35 | enum rdtech_dps_model_type { |
36 | MODEL_NONE, | |
37 | MODEL_DPS, | |
38 | MODEL_RD, | |
39 | }; | |
40 | ||
02a4f485 MD |
41 | struct rdtech_dps_range { |
42 | const char *range_str; | |
69b05583 JC |
43 | unsigned int max_current; |
44 | unsigned int max_voltage; | |
45 | unsigned int max_power; | |
cce6a8a1 FS |
46 | unsigned int current_digits; |
47 | unsigned int voltage_digits; | |
69b05583 JC |
48 | }; |
49 | ||
02a4f485 MD |
50 | struct rdtech_dps_model { |
51 | enum rdtech_dps_model_type model_type; | |
52 | unsigned int id; | |
53 | const char *name; | |
1ac04e6d GS |
54 | const struct rdtech_dps_range *ranges; |
55 | size_t n_ranges; | |
02a4f485 MD |
56 | }; |
57 | ||
0549416e | 58 | struct dev_context { |
69b05583 | 59 | const struct rdtech_dps_model *model; |
cce6a8a1 FS |
60 | double current_multiplier; |
61 | double voltage_multiplier; | |
d7a4dad8 GS |
62 | struct sr_sw_limits limits; |
63 | GMutex rw_mutex; | |
64 | gboolean curr_ovp_state; | |
65 | gboolean curr_ocp_state; | |
66 | gboolean curr_cc_state; | |
67 | gboolean curr_out_state; | |
1ac04e6d | 68 | size_t curr_range; |
02a4f485 | 69 | gboolean acquisition_started; |
0549416e JC |
70 | }; |
71 | ||
d7a4dad8 GS |
72 | /* Container to get and set parameter values. */ |
73 | struct rdtech_dps_state { | |
74 | enum rdtech_dps_state_mask { | |
75 | STATE_LOCK = 1 << 0, | |
76 | STATE_OUTPUT_ENABLED = 1 << 1, | |
77 | STATE_REGULATION_CC = 1 << 2, | |
78 | STATE_PROTECT_OVP = 1 << 3, | |
79 | STATE_PROTECT_OCP = 1 << 4, | |
80 | STATE_PROTECT_ENABLED = 1 << 5, | |
81 | STATE_VOLTAGE_TARGET = 1 << 6, | |
82 | STATE_CURRENT_LIMIT = 1 << 7, | |
83 | STATE_OVP_THRESHOLD = 1 << 8, | |
84 | STATE_OCP_THRESHOLD = 1 << 9, | |
85 | STATE_VOLTAGE = 1 << 10, | |
86 | STATE_CURRENT = 1 << 11, | |
87 | STATE_POWER = 1 << 12, | |
02a4f485 | 88 | STATE_RANGE = 1 << 13, |
d7a4dad8 GS |
89 | } mask; |
90 | gboolean lock; | |
91 | gboolean output_enabled, regulation_cc; | |
92 | gboolean protect_ovp, protect_ocp, protect_enabled; | |
93 | float voltage_target, current_limit; | |
94 | float ovp_threshold, ocp_threshold; | |
95 | float voltage, current, power; | |
1ac04e6d | 96 | size_t range; |
69b05583 JC |
97 | }; |
98 | ||
7a78fd56 GS |
99 | enum rdtech_dps_state_context { |
100 | ST_CTX_NONE, | |
101 | ST_CTX_CONFIG, | |
102 | ST_CTX_PRE_ACQ, | |
103 | ST_CTX_IN_ACQ, | |
104 | }; | |
d7a4dad8 | 105 | SR_PRIV int rdtech_dps_get_state(const struct sr_dev_inst *sdi, |
7a78fd56 | 106 | struct rdtech_dps_state *state, enum rdtech_dps_state_context reason); |
d7a4dad8 GS |
107 | SR_PRIV int rdtech_dps_set_state(const struct sr_dev_inst *sdi, |
108 | struct rdtech_dps_state *state); | |
69b05583 JC |
109 | |
110 | SR_PRIV int rdtech_dps_get_model_version(struct sr_modbus_dev_inst *modbus, | |
884ae8c0 GS |
111 | enum rdtech_dps_model_type model_type, |
112 | uint16_t *model, uint16_t *version, uint32_t *serno); | |
02a4f485 MD |
113 | SR_PRIV void rdtech_dps_update_multipliers(const struct sr_dev_inst *sdi); |
114 | SR_PRIV int rdtech_dps_update_range(const struct sr_dev_inst *sdi); | |
d7a4dad8 | 115 | SR_PRIV int rdtech_dps_seed_receive(const struct sr_dev_inst *sdi); |
0549416e JC |
116 | SR_PRIV int rdtech_dps_receive_data(int fd, int revents, void *cb_data); |
117 | ||
118 | #endif |