]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * This file is part of the libsigrok project. | |
3 | * | |
4 | * Copyright (C) 2014 Matthias Heidbrink <m-sigrok@heidbrink.biz> | |
5 | * Copyright (C) 2014 Bert Vermeulen <bert@biot.com> (code from atten-pps3xxx) | |
6 | * | |
7 | * This program is free software: you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation, either version 3 of the License, or | |
10 | * (at your option) any later version. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | */ | |
20 | ||
21 | /** @file | |
22 | * <em>Motech LPS-30x series</em> power supply driver | |
23 | * @internal | |
24 | */ | |
25 | ||
26 | #ifndef LIBSIGROK_HARDWARE_MOTECH_LPS_30X_PROTOCOL_H | |
27 | #define LIBSIGROK_HARDWARE_MOTECH_LPS_30X_PROTOCOL_H | |
28 | ||
29 | #include <stdint.h> | |
30 | #include <glib.h> | |
31 | #include <libsigrok/libsigrok.h> | |
32 | #include "libsigrok-internal.h" | |
33 | ||
34 | SR_PRIV int lps_process_status(struct sr_dev_inst *sdi, int stat); | |
35 | SR_PRIV int lps_send_req(struct sr_serial_dev_inst *serial, const char *fmt, ...); | |
36 | ||
37 | #define LOG_PREFIX "motech-lps-30x" | |
38 | ||
39 | #define LINELEN_MAX 50 /**< Max. line length for requests */ | |
40 | ||
41 | #define REQ_TIMEOUT_MS 250 /**< Timeout [ms] for single request. */ | |
42 | ||
43 | #define MAX_CHANNELS 3 | |
44 | ||
45 | typedef enum { | |
46 | LPS_UNKNOWN = 0,/**< Unknown model (used during detection process) */ | |
47 | LPS_301, /**< Motech/Amrel LPS-301, 1 output */ | |
48 | LPS_302, /**< Motech/Amrel LPS-302, 1 output */ | |
49 | LPS_303, /**< Motech/Amrel LPS-303, 1 output */ | |
50 | LPS_304, /**< Motech/Amrel LPS-304, 3 outputs */ | |
51 | LPS_305, /**< Motech/Amrel LPS-305, 3 outputs */ | |
52 | } lps_modelid; | |
53 | ||
54 | /** Channel specification */ | |
55 | struct channel_spec { | |
56 | /* Min, max, step. */ | |
57 | gdouble voltage[3]; | |
58 | gdouble current[3]; | |
59 | }; | |
60 | ||
61 | /** Model properties specification */ | |
62 | struct lps_modelspec { | |
63 | lps_modelid modelid; | |
64 | const char *modelstr; | |
65 | uint8_t num_channels; | |
66 | struct channel_spec channels[3]; | |
67 | }; | |
68 | ||
69 | /** Used to implement a little state machine to query all required values in a row. */ | |
70 | typedef enum { | |
71 | AQ_NONE, | |
72 | AQ_U1, | |
73 | AQ_I1, | |
74 | AQ_I2, | |
75 | AQ_U2, | |
76 | AQ_STATUS, | |
77 | } acquisition_req; | |
78 | ||
79 | /** Status of a single channel. */ | |
80 | struct channel_status { | |
81 | /* Channel information (struct channel_info*). data (struct) owned by sdi, just a reference to address a single channel. */ | |
82 | GSList *info; | |
83 | /* Received from device. */ | |
84 | gdouble output_voltage_last; | |
85 | gdouble output_current_last; | |
86 | gboolean output_enabled; /**< Also used when set. */ | |
87 | gboolean cc_mode; /**< Constant current mode. If false, constant voltage mode. */ | |
88 | /* Set by frontend. */ | |
89 | gdouble output_voltage_max; | |
90 | gdouble output_current_max; | |
91 | }; | |
92 | ||
93 | /** Private, per-device-instance driver context. */ | |
94 | struct dev_context { | |
95 | /* Model-specific information */ | |
96 | const struct lps_modelspec *model; | |
97 | ||
98 | /* Acquisition status */ | |
99 | gboolean acq_running; /**< Acquisition is running. */ | |
100 | uint64_t limit_samples; /**< Target number of samples */ | |
101 | uint64_t limit_msec; /**< Target sampling time */ | |
102 | acquisition_req acq_req; /**< Current request. */ | |
103 | uint8_t acq_req_pending; /**< Request pending. 0=none, 1=reply, 2=OK */ | |
104 | ||
105 | /* Operational state */ | |
106 | struct channel_status channel_status[MAX_CHANNELS]; | |
107 | guint8 tracking_mode; /**< 0=off, 1=Tracking from CH1, 2=Tracking from CH2. */ | |
108 | ||
109 | /* Temporary state across callbacks */ | |
110 | int64_t req_sent_at; /**< Request sent. */ | |
111 | uint64_t num_samples; /**< Current #samples for limit_samples */ | |
112 | GTimer *elapsed_msec; /**< Used for sampling with limit_msec */ | |
113 | gchar buf[LINELEN_MAX]; /**< Buffer for read callback */ | |
114 | int buflen; /**< Data len in buf */ | |
115 | }; | |
116 | ||
117 | SR_PRIV int motech_lps_30x_receive_data(int fd, int revents, void *cb_data); | |
118 | ||
119 | #endif |