From 94b32ec8d6cd5d80bee4dec498ab85181ab3f33f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Sat, 5 Dec 2015 00:30:41 +0100 Subject: [PATCH] rudimentary status register definitions, TODO: use registers, funcs for setting and clearing, defualt commands for status regs --- scpi.pro | 6 ++-- scpi.pro.user | 2 +- scpi_parser.c | 10 +++---- scpi_status.c | 8 +++++ scpi_status.h | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 101 insertions(+), 8 deletions(-) create mode 100644 scpi_status.c create mode 100644 scpi_status.h diff --git a/scpi.pro b/scpi.pro index b99da06..517b15a 100644 --- a/scpi.pro +++ b/scpi.pro @@ -6,7 +6,8 @@ CONFIG -= qt SOURCES += \ scpi_parser.c \ main.c \ - scpi_errors.c + scpi_errors.c \ + scpi_status.c DISTFILES += \ style.astylerc \ @@ -17,4 +18,5 @@ DISTFILES += \ HEADERS += \ scpi_parser.h \ - scpi_errors.h + scpi_errors.h \ + scpi_status.h diff --git a/scpi.pro.user b/scpi.pro.user index f59e021..62d90a4 100644 --- a/scpi.pro.user +++ b/scpi.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/scpi_parser.c b/scpi_parser.c index 816ed75..8c1bdc2 100644 --- a/scpi_parser.c +++ b/scpi_parser.c @@ -127,7 +127,7 @@ static void builtin_cb_FOO(const SCPI_argval_t *args) } -const SCPI_command_t scpi_commands_builtin[] = { +static const SCPI_command_t scpi_commands_builtin[] = { { .levels = {"FOO"}, .params = {}, @@ -656,13 +656,13 @@ static bool match_cmd(bool partial) strcpy(dest, pst.charbuf); - // First try builtin commands - if (match_any_cmd_from_array(scpi_commands_builtin, partial)) { + // User commands are checked first, can override builtin commands + if (match_any_cmd_from_array(scpi_commands, partial)) { return true; } - // User commands - return match_any_cmd_from_array(scpi_commands, partial); + // Try the built-in commands + return match_any_cmd_from_array(scpi_commands_builtin, partial); } diff --git a/scpi_status.c b/scpi_status.c new file mode 100644 index 0000000..2dbec5b --- /dev/null +++ b/scpi_status.c @@ -0,0 +1,8 @@ +#include +#include + +#include "scpi_status.h" + +struct SCPI_SR_QUEST_struct SCPI_SR_QUEST; +struct SCPI_SR_OPER_struct SCPI_SR_OPER; +struct SCPI_SR_SESR_struct SCPI_SR_SESR; diff --git a/scpi_status.h b/scpi_status.h new file mode 100644 index 0000000..74153fc --- /dev/null +++ b/scpi_status.h @@ -0,0 +1,83 @@ +#pragma once +#include +#include + +struct __attribute__((packed)) SCPI_SR_QUEST_struct { + bool VOLT: 1; + bool CURR: 1; + bool TIME: 1; + bool POWER: 1; + bool TEMP: 1; + bool FREQ: 1; + bool PHASE: 1; + bool MODUL: 1; + bool CALIB: 1; + bool BIT_9: 1; // user defined + bool BIT_10: 1; + bool BIT_11: 1; + bool BIT_12: 1; + bool INSTR_SUM: 1; // instrument summary + bool COMMAND_WARNING: 1; // command warning + bool RESERVED: 1; +}; + + +struct __attribute__((packed)) SCPI_SR_OPER_struct { + bool CALIB: 1; + bool SETTING: 1; + bool RANGING: 1; + bool SWEEP: 1; + bool MEAS: 1; + bool WAIT_TRIG: 1; // waiting for trigger + bool WAIT_ARM: 1; // waiting for ARM + bool CORRECTING: 1; + bool BIT_8: 1; // user defined + bool BIT_9: 1; + bool BIT_10: 1; + bool BIT_11: 1; + bool BIT_12: 1; + bool INSTR_SUM: 1; // instrument summary + bool PROG_RUN: 1; // program running + bool RESERVED: 1; +}; + + +struct __attribute__((packed)) SCPI_SR_SESR_struct { + bool OP_COMPLETE: 1; + bool REQ_CONTROL: 1; + bool QUERY_ERROR: 1; + bool DEV_ERROR: 1; + bool EXE_ERROR: 1; + bool CMD_ERROR: 1; + bool USER_REQUEST: 1; + bool POWER_ON: 1; +}; + + +struct __attribute__((packed)) SCPI_SR_STB_struct { + bool BIT_0: 1; + bool BIT_1: 1; + bool ERROR_QUEUE: 1; + bool QUEST: 1; + bool MSG_AVAIL: 1; + bool SESR: 1; + bool RQS: 1; // request service + bool OPER: 1; +}; + + +// QUESTionable register +extern struct SCPI_SR_QUEST_struct SCPI_SR_QUEST; +extern struct SCPI_SR_QUEST_struct SCPI_SR_QUEST_EN; // picks what to use for the STB bit + +// OPERation status register +extern struct SCPI_SR_OPER_struct SCPI_SR_OPER; +extern struct SCPI_SR_OPER_struct SCPI_SR_OPER_EN; // picks what to use for the STB bit + +// Standard Event Status register +extern struct SCPI_SR_SESR_struct SCPI_SR_SESR; +extern struct SCPI_SR_SESR_struct SCPI_SR_SESR_EN; // ESE + +// Status byte +extern struct SCPI_SR_STB_struct SCPI_SR_STB; +extern struct SCPI_SR_STB_struct SCPI_SR_STB_EN; // SRE