From b4e7e23b7abe02ffbed2d8dfe25ad2e159a1dedf Mon Sep 17 00:00:00 2001 From: Jan Breuer <jan.breuer@jaybee.cz> Date: 周三, 13 3月 2013 01:56:42 +0800 Subject: [PATCH] Add next example command CONF:VOLT:DC --- libscpi/src/ieee488.c | 73 ++++++++++++++++++++++++------------ 1 files changed, 48 insertions(+), 25 deletions(-) diff --git a/libscpi/src/ieee488.c b/libscpi/src/ieee488.c index e493a93..6b4e62e 100644 --- a/libscpi/src/ieee488.c +++ b/libscpi/src/ieee488.c @@ -39,12 +39,30 @@ #include "scpi/error.h" #include "scpi/constants.h" +#include <stdio.h> + /** * Update register value + * @param context * @param name - register name */ -static void SCPI_RegUpdate(scpi_t * context, scpi_reg_name_t name) { +static void regUpdate(scpi_t * context, scpi_reg_name_t name) { SCPI_RegSet(context, name, SCPI_RegGet(context, name)); +} + +/** + * Update STB register according to value and its mask register + * @param context + * @param val value of register + * @param mask name of mask register (enable register) + * @param stbBits bits to clear or set in STB + */ +static void regUpdateSTB(scpi_t * context, scpi_reg_val_t val, scpi_reg_name_t mask, scpi_reg_val_t stbBits) { + if (val & SCPI_RegGet(context, mask)) { + SCPI_RegSetBits(context, SCPI_REG_STB, stbBits); + } else { + SCPI_RegClearBits(context, SCPI_REG_STB, stbBits); + } } /** @@ -55,6 +73,20 @@ scpi_reg_val_t SCPI_RegGet(scpi_t * context, scpi_reg_name_t name) { if ((name < SCPI_REG_COUNT) && (context->registers != NULL)) { return context->registers[name]; + } else { + return 0; + } +} + +/** + * Wrapper function to control interface from context + * @param context + * @param ctrl number of controll message + * @param value value of related register + */ +static size_t writeControl(scpi_t * context, int ctrl, scpi_reg_val_t val) { + if (context && context->interface && context->interface->control) { + return context->interface->control(context, ctrl, val); } else { return 0; } @@ -74,9 +106,10 @@ } - // set register value + /* set register value */ context->registers[name] = val; + /** @TODO: remove recutsion */ switch (name) { case SCPI_REG_STB: mask = SCPI_RegGet(context, SCPI_REG_SRE); @@ -89,37 +122,25 @@ } break; case SCPI_REG_SRE: - SCPI_RegUpdate(context, SCPI_REG_STB); + regUpdate(context, SCPI_REG_STB); break; case SCPI_REG_ESR: - if (val & SCPI_RegGet(context, SCPI_REG_ESE)) { - SCPI_RegSetBits(context, SCPI_REG_STB, STB_ESR); - } else { - SCPI_RegClearBits(context, SCPI_REG_STB, STB_ESR); - } + regUpdateSTB(context, val, SCPI_REG_ESE, STB_ESR); break; case SCPI_REG_ESE: - SCPI_RegUpdate(context, SCPI_REG_ESR); + regUpdate(context, SCPI_REG_ESR); break; case SCPI_REG_QUES: - if (val & SCPI_RegGet(context, SCPI_REG_QUESE)) { - SCPI_RegSetBits(context, SCPI_REG_STB, STB_QES); - } else { - SCPI_RegClearBits(context, SCPI_REG_STB, STB_QES); - } + regUpdateSTB(context, val, SCPI_REG_QUESE, STB_QES); break; case SCPI_REG_QUESE: - SCPI_RegUpdate(context, SCPI_REG_QUES); + regUpdate(context, SCPI_REG_QUES); break; case SCPI_REG_OPER: - if (val & SCPI_RegGet(context, SCPI_REG_OPERE)) { - SCPI_RegSetBits(context, SCPI_REG_STB, STB_OPS); - } else { - SCPI_RegClearBits(context, SCPI_REG_STB, STB_OPS); - } + regUpdateSTB(context, val, SCPI_REG_OPERE, STB_OPS); break; case SCPI_REG_OPERE: - SCPI_RegUpdate(context, SCPI_REG_OPER); + regUpdate(context, SCPI_REG_OPER); break; @@ -131,8 +152,8 @@ // set updated register value context->registers[name] = val; - if (srq && context->interface && context->interface->srq) { - context->interface->srq(context); + if (srq) { + writeControl(context, SCPI_CTRL_SRQ, SCPI_RegGet(context, SCPI_REG_STB)); } } @@ -154,8 +175,10 @@ SCPI_RegSet(context, name, SCPI_RegGet(context, name) & ~bits); } -/* ============ */ - +/** + * Clear event register + * @param context + */ void SCPI_EventClear(scpi_t * context) { // TODO SCPI_RegSet(context, SCPI_REG_ESR, 0); -- Gitblit v1.9.1