PS_Fgen_FW  4da88f4073c1cc65ea45c3a652a2751e495e50db
Firmware for an Power Supply and Function Generator build from an ATX power supply
Loading...
Searching...
No Matches
types.h
1/*-
2 * BSD 2-Clause License
3 *
4 * Copyright (c) 2012-2018, Jan Breuer, Richard.hmm
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * * Redistributions of source code must retain the above copyright notice, this
11 * list of conditions and the following disclaimer.
12 *
13 * * Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
37
38#ifndef SCPI_TYPES_H
39#define SCPI_TYPES_H
40
41#include <stddef.h>
42#include <stdint.h>
44
45#if HAVE_STDBOOL
46#include <stdbool.h>
47#endif
48
49#ifdef __cplusplus
50extern "C" {
51#endif
52
53#if !HAVE_STDBOOL
54 typedef unsigned char bool;
55#endif
56
57#ifndef FALSE
58#define FALSE 0
59#endif
60#ifndef TRUE
61#define TRUE (!FALSE)
62#endif
63
64 /* basic data types */
65 typedef bool scpi_bool_t;
66 /* typedef enum { FALSE = 0, TRUE } scpi_bool_t; */
67
68 /* IEEE 488.2 registers */
69 enum _scpi_reg_name_t {
70 SCPI_REG_STB = 0, /* Status Byte */
71 SCPI_REG_SRE, /* Service Request Enable Register */
72 SCPI_REG_ESR, /* Standard Event Status Register (ESR, SESR) */
73 SCPI_REG_ESE, /* Event Status Enable Register */
74 SCPI_REG_OPER, /* OPERation Status Register */
75 SCPI_REG_OPERE, /* OPERation Status Enable Register */
76 SCPI_REG_OPERC, /* OPERation Status Condition Register */
77 SCPI_REG_QUES, /* QUEStionable status register */
78 SCPI_REG_QUESE, /* QUEStionable status Enable Register */
79 SCPI_REG_QUESC, /* QUEStionable status Condition Register */
80
81 /* last definition - number of registers */
82 SCPI_REG_COUNT
83 };
84 typedef enum _scpi_reg_name_t scpi_reg_name_t;
85
86 enum _scpi_ctrl_name_t {
87 SCPI_CTRL_SRQ = 1, /* service request */
88 SCPI_CTRL_GTL, /* Go to local */
89 SCPI_CTRL_SDC, /* Selected device clear */
90 SCPI_CTRL_PPC, /* Parallel poll configure */
91 SCPI_CTRL_GET, /* Group execute trigger */
92 SCPI_CTRL_TCT, /* Take control */
93 SCPI_CTRL_LLO, /* Device clear */
94 SCPI_CTRL_DCL, /* Local lockout */
95 SCPI_CTRL_PPU, /* Parallel poll unconfigure */
96 SCPI_CTRL_SPE, /* Serial poll enable */
97 SCPI_CTRL_SPD, /* Serial poll disable */
98 SCPI_CTRL_MLA, /* My local address */
99 SCPI_CTRL_UNL, /* Unlisten */
100 SCPI_CTRL_MTA, /* My talk address */
101 SCPI_CTRL_UNT, /* Untalk */
102 SCPI_CTRL_MSA /* My secondary address */
103 };
104 typedef enum _scpi_ctrl_name_t scpi_ctrl_name_t;
105
106 typedef uint16_t scpi_reg_val_t;
107
108 /* scpi commands */
109 enum _scpi_result_t {
110 SCPI_RES_OK = 1,
111 SCPI_RES_ERR = -1
112 };
113 typedef enum _scpi_result_t scpi_result_t;
114
115 typedef struct _scpi_command_t scpi_command_t;
116
117#if USE_COMMAND_TAGS
118 #define SCPI_CMD_LIST_END {NULL, NULL, 0}
119#else
120 #define SCPI_CMD_LIST_END {NULL, NULL}
121#endif
122
123
124 /* scpi interface */
125 typedef struct _scpi_t scpi_t;
126 typedef struct _scpi_interface_t scpi_interface_t;
127
129 size_t length;
130 size_t position;
131 char * data;
132 };
133 typedef struct _scpi_buffer_t scpi_buffer_t;
134
136 size_t length;
137 size_t position;
138 const char * data;
139 };
140 typedef struct _scpi_const_buffer_t scpi_const_buffer_t;
141
142 typedef size_t(*scpi_write_t)(scpi_t * context, const char * data, size_t len);
143 typedef scpi_result_t(*scpi_write_control_t)(scpi_t * context, scpi_ctrl_name_t ctrl, scpi_reg_val_t val);
144 typedef int (*scpi_error_callback_t)(scpi_t * context, int_fast16_t error);
145
146 /* scpi lexer */
147 enum _scpi_token_type_t {
148 SCPI_TOKEN_COMMA,
149 SCPI_TOKEN_SEMICOLON,
150 SCPI_TOKEN_COLON,
151 SCPI_TOKEN_SPECIFIC_CHARACTER,
152 SCPI_TOKEN_QUESTION,
153 SCPI_TOKEN_NL,
154 SCPI_TOKEN_HEXNUM,
155 SCPI_TOKEN_OCTNUM,
156 SCPI_TOKEN_BINNUM,
157 SCPI_TOKEN_PROGRAM_MNEMONIC,
158 SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA,
159 SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA_WITH_SUFFIX,
160 SCPI_TOKEN_SUFFIX_PROGRAM_DATA,
161 SCPI_TOKEN_ARBITRARY_BLOCK_PROGRAM_DATA,
162 SCPI_TOKEN_SINGLE_QUOTE_PROGRAM_DATA,
163 SCPI_TOKEN_DOUBLE_QUOTE_PROGRAM_DATA,
164 SCPI_TOKEN_PROGRAM_EXPRESSION,
165 SCPI_TOKEN_COMPOUND_PROGRAM_HEADER,
166 SCPI_TOKEN_INCOMPLETE_COMPOUND_PROGRAM_HEADER,
167 SCPI_TOKEN_COMMON_PROGRAM_HEADER,
168 SCPI_TOKEN_INCOMPLETE_COMMON_PROGRAM_HEADER,
169 SCPI_TOKEN_COMPOUND_QUERY_PROGRAM_HEADER,
170 SCPI_TOKEN_COMMON_QUERY_PROGRAM_HEADER,
171 SCPI_TOKEN_WS,
172 SCPI_TOKEN_ALL_PROGRAM_DATA,
173 SCPI_TOKEN_INVALID,
174 SCPI_TOKEN_UNKNOWN,
175 };
176 typedef enum _scpi_token_type_t scpi_token_type_t;
177
179 scpi_token_type_t type;
180 char * ptr;
181 int len;
182 };
183 typedef struct _scpi_token_t scpi_token_t;
184
186 char * buffer;
187 char * pos;
188 int len;
189 };
190 typedef struct _lex_state_t lex_state_t;
191
192 /* scpi parser */
193 enum _message_termination_t {
194 SCPI_MESSAGE_TERMINATION_NONE,
195 SCPI_MESSAGE_TERMINATION_NL,
196 SCPI_MESSAGE_TERMINATION_SEMICOLON,
197 };
198 typedef enum _message_termination_t message_termination_t;
199
201 scpi_token_t programHeader;
202 scpi_token_t programData;
203 int numberOfParameters;
204 message_termination_t termination;
205 };
206 typedef struct _scpi_parser_state_t scpi_parser_state_t;
207
208 typedef scpi_result_t(*scpi_command_callback_t)(scpi_t *);
209
211 size_t wr;
212 /* size_t rd; */
213 size_t count;
214 size_t size;
215 char * data;
216 };
217 typedef struct _scpi_error_info_heap_t scpi_error_info_heap_t;
218
220 int16_t error_code;
221#if USE_DEVICE_DEPENDENT_ERROR_INFORMATION
222 char * device_dependent_info;
223#endif
224 };
225 typedef struct _scpi_error_t scpi_error_t;
226
228 int16_t wr;
229 int16_t rd;
230 int16_t count;
231 int16_t size;
232 scpi_error_t * data;
233 };
234 typedef struct _scpi_fifo_t scpi_fifo_t;
235
236 /* scpi units */
237 enum _scpi_unit_t {
238 SCPI_UNIT_NONE,
239 SCPI_UNIT_VOLT,
240 SCPI_UNIT_AMPER,
241 SCPI_UNIT_OHM,
242 SCPI_UNIT_HERTZ,
243 SCPI_UNIT_CELSIUS,
244 SCPI_UNIT_SECOND,
245 SCPI_UNIT_METER,
246 SCPI_UNIT_GRAY,
247 SCPI_UNIT_BECQUEREL,
248 SCPI_UNIT_MOLE,
249 SCPI_UNIT_DEGREE,
250 SCPI_UNIT_GRADE,
251 SCPI_UNIT_RADIAN,
252 SCPI_UNIT_REVOLUTION,
253 SCPI_UNIT_STERADIAN,
254 SCPI_UNIT_SIEVERT,
255 SCPI_UNIT_FARAD,
256 SCPI_UNIT_COULOMB,
257 SCPI_UNIT_SIEMENS,
258 SCPI_UNIT_ELECTRONVOLT,
259 SCPI_UNIT_JOULE,
260 SCPI_UNIT_NEWTON,
261 SCPI_UNIT_LUX,
262 SCPI_UNIT_HENRY,
263 SCPI_UNIT_ASTRONOMIC_UNIT,
264 SCPI_UNIT_INCH,
265 SCPI_UNIT_FOOT,
266 SCPI_UNIT_PARSEC,
267 SCPI_UNIT_MILE,
268 SCPI_UNIT_NAUTICAL_MILE,
269 SCPI_UNIT_LUMEN,
270 SCPI_UNIT_CANDELA,
271 SCPI_UNIT_WEBER,
272 SCPI_UNIT_TESLA,
273 SCPI_UNIT_ATOMIC_MASS,
274 SCPI_UNIT_KILOGRAM,
275 SCPI_UNIT_WATT,
276 SCPI_UNIT_DBM,
277 SCPI_UNIT_ATMOSPHERE,
278 SCPI_UNIT_INCH_OF_MERCURY,
279 SCPI_UNIT_MM_OF_MERCURY,
280 SCPI_UNIT_PASCAL,
281 SCPI_UNIT_TORT,
282 SCPI_UNIT_BAR,
283 SCPI_UNIT_DECIBEL,
284 SCPI_UNIT_UNITLESS,
285 SCPI_UNIT_FAHRENHEIT,
286 SCPI_UNIT_KELVIN,
287 SCPI_UNIT_DAY,
288 SCPI_UNIT_YEAR,
289 SCPI_UNIT_STROKES,
290 SCPI_UNIT_POISE,
291 SCPI_UNIT_LITER
292 };
293 typedef enum _scpi_unit_t scpi_unit_t;
294
296 const char * name;
297 scpi_unit_t unit;
298 double mult;
299 };
300#define SCPI_UNITS_LIST_END {NULL, SCPI_UNIT_NONE, 0}
301 typedef struct _scpi_unit_def_t scpi_unit_def_t;
302
303 enum _scpi_special_number_t {
304 SCPI_NUM_NUMBER,
305 SCPI_NUM_MIN,
306 SCPI_NUM_MAX,
307 SCPI_NUM_DEF,
308 SCPI_NUM_UP,
309 SCPI_NUM_DOWN,
310 SCPI_NUM_NAN,
311 SCPI_NUM_INF,
312 SCPI_NUM_NINF,
313 SCPI_NUM_AUTO
314 };
315 typedef enum _scpi_special_number_t scpi_special_number_t;
316
318 const char * name;
319 int32_t tag;
320 };
321#define SCPI_CHOICE_LIST_END {NULL, -1}
322 typedef struct _scpi_choice_def_t scpi_choice_def_t;
323
325 const scpi_command_t * cmd;
326 lex_state_t lex_state;
327 scpi_const_buffer_t cmd_raw;
328 };
329 typedef struct _scpi_param_list_t scpi_param_list_t;
330
332 scpi_bool_t special;
333
334 union {
335 double value;
336 int32_t tag;
337 } content;
338 scpi_unit_t unit;
339 int8_t base;
340 };
341 typedef struct _scpi_number_parameter_t scpi_number_t;
342
344 const char * ptr;
345 int32_t len;
346 };
347 typedef struct _scpi_data_parameter_t scpi_data_parameter_t;
348
349 typedef scpi_token_t scpi_parameter_t;
350
352 const char * pattern;
353 scpi_command_callback_t callback;
354#if USE_COMMAND_TAGS
355 int32_t tag;
356#endif /* USE_COMMAND_TAGS */
357 };
358
360 scpi_error_callback_t error;
361 scpi_write_t write;
362 scpi_write_control_t control;
363 scpi_command_callback_t flush;
364 scpi_command_callback_t reset;
365 };
366
367 struct _scpi_t {
368 const scpi_command_t * cmdlist;
369 scpi_buffer_t buffer;
370 scpi_param_list_t param_list;
371 scpi_interface_t * interface;
372 int_fast16_t output_count;
373 int_fast16_t input_count;
374 scpi_bool_t cmd_error;
375 scpi_fifo_t error_queue;
376#if USE_DEVICE_DEPENDENT_ERROR_INFORMATION && !USE_MEMORY_ALLOCATION_FREE
377 scpi_error_info_heap_t error_info_heap;
378#endif
379 scpi_reg_val_t registers[SCPI_REG_COUNT];
380 const scpi_unit_def_t * units;
381 void * user_context;
382 scpi_parser_state_t parser_state;
383 const char * idn[4];
384 size_t arbitrary_reminding;
385 };
386
387 enum _scpi_array_format_t {
388 SCPI_FORMAT_ASCII = 0,
389 SCPI_FORMAT_NORMAL = 1,
390 SCPI_FORMAT_SWAPPED = 2,
391 SCPI_FORMAT_BIGENDIAN = SCPI_FORMAT_NORMAL,
392 SCPI_FORMAT_LITTLEENDIAN = SCPI_FORMAT_SWAPPED,
393 };
394 typedef enum _scpi_array_format_t scpi_array_format_t;
395
396#ifdef __cplusplus
397}
398#endif
399
400#endif /* SCPI_TYPES_H */
401
SCPI Configuration.
Definition types.h:185
Definition types.h:128
Definition types.h:317
Definition types.h:351
Definition types.h:135
Definition types.h:343
Definition types.h:210
Definition types.h:219
Definition types.h:227
Definition types.h:359
Definition types.h:331
Definition types.h:324
Definition types.h:200
Definition types.h:367
Definition types.h:178
Definition types.h:295