Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
libscpi/src/ieee488.c@0:be95bfb06686, 2022-01-17 (annotated)
- Committer:
- wuliqunyy
- Date:
- Mon Jan 17 13:20:09 2022 +0000
- Revision:
- 0:be95bfb06686
a working non_flat + adc_didt for ehp regulation version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wuliqunyy | 0:be95bfb06686 | 1 | /*- |
wuliqunyy | 0:be95bfb06686 | 2 | * BSD 2-Clause License |
wuliqunyy | 0:be95bfb06686 | 3 | * |
wuliqunyy | 0:be95bfb06686 | 4 | * Copyright (c) 2012-2018, Jan Breuer |
wuliqunyy | 0:be95bfb06686 | 5 | * All rights reserved. |
wuliqunyy | 0:be95bfb06686 | 6 | * |
wuliqunyy | 0:be95bfb06686 | 7 | * Redistribution and use in source and binary forms, with or without |
wuliqunyy | 0:be95bfb06686 | 8 | * modification, are permitted provided that the following conditions are met: |
wuliqunyy | 0:be95bfb06686 | 9 | * |
wuliqunyy | 0:be95bfb06686 | 10 | * * Redistributions of source code must retain the above copyright notice, this |
wuliqunyy | 0:be95bfb06686 | 11 | * list of conditions and the following disclaimer. |
wuliqunyy | 0:be95bfb06686 | 12 | * |
wuliqunyy | 0:be95bfb06686 | 13 | * * Redistributions in binary form must reproduce the above copyright notice, |
wuliqunyy | 0:be95bfb06686 | 14 | * this list of conditions and the following disclaimer in the documentation |
wuliqunyy | 0:be95bfb06686 | 15 | * and/or other materials provided with the distribution. |
wuliqunyy | 0:be95bfb06686 | 16 | * |
wuliqunyy | 0:be95bfb06686 | 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
wuliqunyy | 0:be95bfb06686 | 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
wuliqunyy | 0:be95bfb06686 | 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
wuliqunyy | 0:be95bfb06686 | 20 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
wuliqunyy | 0:be95bfb06686 | 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
wuliqunyy | 0:be95bfb06686 | 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
wuliqunyy | 0:be95bfb06686 | 23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
wuliqunyy | 0:be95bfb06686 | 24 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
wuliqunyy | 0:be95bfb06686 | 25 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
wuliqunyy | 0:be95bfb06686 | 26 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
wuliqunyy | 0:be95bfb06686 | 27 | */ |
wuliqunyy | 0:be95bfb06686 | 28 | |
wuliqunyy | 0:be95bfb06686 | 29 | /** |
wuliqunyy | 0:be95bfb06686 | 30 | * @file scpi_ieee488.c |
wuliqunyy | 0:be95bfb06686 | 31 | * @date Thu Nov 15 10:58:45 UTC 2012 |
wuliqunyy | 0:be95bfb06686 | 32 | * |
wuliqunyy | 0:be95bfb06686 | 33 | * @brief Implementation of IEEE488.2 commands and state model |
wuliqunyy | 0:be95bfb06686 | 34 | * |
wuliqunyy | 0:be95bfb06686 | 35 | * |
wuliqunyy | 0:be95bfb06686 | 36 | */ |
wuliqunyy | 0:be95bfb06686 | 37 | |
wuliqunyy | 0:be95bfb06686 | 38 | #include "scpi/parser.h" |
wuliqunyy | 0:be95bfb06686 | 39 | #include "scpi/ieee488.h" |
wuliqunyy | 0:be95bfb06686 | 40 | #include "scpi/error.h" |
wuliqunyy | 0:be95bfb06686 | 41 | #include "scpi/constants.h" |
wuliqunyy | 0:be95bfb06686 | 42 | |
wuliqunyy | 0:be95bfb06686 | 43 | #include <stdio.h> |
wuliqunyy | 0:be95bfb06686 | 44 | |
wuliqunyy | 0:be95bfb06686 | 45 | /** |
wuliqunyy | 0:be95bfb06686 | 46 | * Update register value |
wuliqunyy | 0:be95bfb06686 | 47 | * @param context |
wuliqunyy | 0:be95bfb06686 | 48 | * @param name - register name |
wuliqunyy | 0:be95bfb06686 | 49 | */ |
wuliqunyy | 0:be95bfb06686 | 50 | static void regUpdate(scpi_t * context, scpi_reg_name_t name) { |
wuliqunyy | 0:be95bfb06686 | 51 | SCPI_RegSet(context, name, SCPI_RegGet(context, name)); |
wuliqunyy | 0:be95bfb06686 | 52 | } |
wuliqunyy | 0:be95bfb06686 | 53 | |
wuliqunyy | 0:be95bfb06686 | 54 | /** |
wuliqunyy | 0:be95bfb06686 | 55 | * Update latching event register value based on bit transitions from 0 -> 1 |
wuliqunyy | 0:be95bfb06686 | 56 | * in the condition register |
wuliqunyy | 0:be95bfb06686 | 57 | * @param context |
wuliqunyy | 0:be95bfb06686 | 58 | * @param condReg - condition register name |
wuliqunyy | 0:be95bfb06686 | 59 | * @param eventReg - event register name |
wuliqunyy | 0:be95bfb06686 | 60 | */ |
wuliqunyy | 0:be95bfb06686 | 61 | static void regUpdateEvent(scpi_t * context, scpi_reg_val_t oldCondVal, scpi_reg_val_t newCondVal, scpi_reg_name_t eventReg) { |
wuliqunyy | 0:be95bfb06686 | 62 | SCPI_RegSet(context, eventReg, ((oldCondVal ^ newCondVal) & newCondVal) | SCPI_RegGet(context, eventReg)); |
wuliqunyy | 0:be95bfb06686 | 63 | } |
wuliqunyy | 0:be95bfb06686 | 64 | |
wuliqunyy | 0:be95bfb06686 | 65 | /** |
wuliqunyy | 0:be95bfb06686 | 66 | * Update STB register according to value and its mask register |
wuliqunyy | 0:be95bfb06686 | 67 | * @param context |
wuliqunyy | 0:be95bfb06686 | 68 | * @param val value of register |
wuliqunyy | 0:be95bfb06686 | 69 | * @param mask name of mask register (enable register) |
wuliqunyy | 0:be95bfb06686 | 70 | * @param stbBits bits to clear or set in STB |
wuliqunyy | 0:be95bfb06686 | 71 | */ |
wuliqunyy | 0:be95bfb06686 | 72 | static void regUpdateSTB(scpi_t * context, scpi_reg_val_t val, scpi_reg_name_t mask, scpi_reg_val_t stbBits) { |
wuliqunyy | 0:be95bfb06686 | 73 | if (val & SCPI_RegGet(context, mask)) { |
wuliqunyy | 0:be95bfb06686 | 74 | SCPI_RegSetBits(context, SCPI_REG_STB, stbBits); |
wuliqunyy | 0:be95bfb06686 | 75 | } else { |
wuliqunyy | 0:be95bfb06686 | 76 | SCPI_RegClearBits(context, SCPI_REG_STB, stbBits); |
wuliqunyy | 0:be95bfb06686 | 77 | } |
wuliqunyy | 0:be95bfb06686 | 78 | } |
wuliqunyy | 0:be95bfb06686 | 79 | |
wuliqunyy | 0:be95bfb06686 | 80 | /** |
wuliqunyy | 0:be95bfb06686 | 81 | * Get register value |
wuliqunyy | 0:be95bfb06686 | 82 | * @param name - register name |
wuliqunyy | 0:be95bfb06686 | 83 | * @return register value |
wuliqunyy | 0:be95bfb06686 | 84 | */ |
wuliqunyy | 0:be95bfb06686 | 85 | scpi_reg_val_t SCPI_RegGet(scpi_t * context, scpi_reg_name_t name) { |
wuliqunyy | 0:be95bfb06686 | 86 | if ((name < SCPI_REG_COUNT) && context) { |
wuliqunyy | 0:be95bfb06686 | 87 | return context->registers[name]; |
wuliqunyy | 0:be95bfb06686 | 88 | } else { |
wuliqunyy | 0:be95bfb06686 | 89 | return 0; |
wuliqunyy | 0:be95bfb06686 | 90 | } |
wuliqunyy | 0:be95bfb06686 | 91 | } |
wuliqunyy | 0:be95bfb06686 | 92 | |
wuliqunyy | 0:be95bfb06686 | 93 | /** |
wuliqunyy | 0:be95bfb06686 | 94 | * Wrapper function to control interface from context |
wuliqunyy | 0:be95bfb06686 | 95 | * @param context |
wuliqunyy | 0:be95bfb06686 | 96 | * @param ctrl number of controll message |
wuliqunyy | 0:be95bfb06686 | 97 | * @param value value of related register |
wuliqunyy | 0:be95bfb06686 | 98 | */ |
wuliqunyy | 0:be95bfb06686 | 99 | static size_t writeControl(scpi_t * context, scpi_ctrl_name_t ctrl, scpi_reg_val_t val) { |
wuliqunyy | 0:be95bfb06686 | 100 | if (context && context->interface && context->interface->control) { |
wuliqunyy | 0:be95bfb06686 | 101 | return context->interface->control(context, ctrl, val); |
wuliqunyy | 0:be95bfb06686 | 102 | } else { |
wuliqunyy | 0:be95bfb06686 | 103 | return 0; |
wuliqunyy | 0:be95bfb06686 | 104 | } |
wuliqunyy | 0:be95bfb06686 | 105 | } |
wuliqunyy | 0:be95bfb06686 | 106 | |
wuliqunyy | 0:be95bfb06686 | 107 | /** |
wuliqunyy | 0:be95bfb06686 | 108 | * Set register value |
wuliqunyy | 0:be95bfb06686 | 109 | * @param name - register name |
wuliqunyy | 0:be95bfb06686 | 110 | * @param val - new value |
wuliqunyy | 0:be95bfb06686 | 111 | */ |
wuliqunyy | 0:be95bfb06686 | 112 | void SCPI_RegSet(scpi_t * context, scpi_reg_name_t name, scpi_reg_val_t val) { |
wuliqunyy | 0:be95bfb06686 | 113 | scpi_bool_t srq = FALSE; |
wuliqunyy | 0:be95bfb06686 | 114 | scpi_reg_val_t mask; |
wuliqunyy | 0:be95bfb06686 | 115 | scpi_reg_val_t old_val; |
wuliqunyy | 0:be95bfb06686 | 116 | |
wuliqunyy | 0:be95bfb06686 | 117 | if ((name >= SCPI_REG_COUNT) || (context == NULL)) { |
wuliqunyy | 0:be95bfb06686 | 118 | return; |
wuliqunyy | 0:be95bfb06686 | 119 | } |
wuliqunyy | 0:be95bfb06686 | 120 | |
wuliqunyy | 0:be95bfb06686 | 121 | /* store old register value */ |
wuliqunyy | 0:be95bfb06686 | 122 | old_val = context->registers[name]; |
wuliqunyy | 0:be95bfb06686 | 123 | |
wuliqunyy | 0:be95bfb06686 | 124 | /* set register value */ |
wuliqunyy | 0:be95bfb06686 | 125 | context->registers[name] = val; |
wuliqunyy | 0:be95bfb06686 | 126 | |
wuliqunyy | 0:be95bfb06686 | 127 | /** @TODO: remove recutsion */ |
wuliqunyy | 0:be95bfb06686 | 128 | switch (name) { |
wuliqunyy | 0:be95bfb06686 | 129 | case SCPI_REG_STB: |
wuliqunyy | 0:be95bfb06686 | 130 | mask = SCPI_RegGet(context, SCPI_REG_SRE); |
wuliqunyy | 0:be95bfb06686 | 131 | mask &= ~STB_SRQ; |
wuliqunyy | 0:be95bfb06686 | 132 | if (val & mask) { |
wuliqunyy | 0:be95bfb06686 | 133 | val |= STB_SRQ; |
wuliqunyy | 0:be95bfb06686 | 134 | /* avoid sending SRQ if nothing has changed */ |
wuliqunyy | 0:be95bfb06686 | 135 | if (old_val != val) { |
wuliqunyy | 0:be95bfb06686 | 136 | srq = TRUE; |
wuliqunyy | 0:be95bfb06686 | 137 | } |
wuliqunyy | 0:be95bfb06686 | 138 | } else { |
wuliqunyy | 0:be95bfb06686 | 139 | val &= ~STB_SRQ; |
wuliqunyy | 0:be95bfb06686 | 140 | } |
wuliqunyy | 0:be95bfb06686 | 141 | break; |
wuliqunyy | 0:be95bfb06686 | 142 | case SCPI_REG_SRE: |
wuliqunyy | 0:be95bfb06686 | 143 | regUpdate(context, SCPI_REG_STB); |
wuliqunyy | 0:be95bfb06686 | 144 | break; |
wuliqunyy | 0:be95bfb06686 | 145 | case SCPI_REG_ESR: |
wuliqunyy | 0:be95bfb06686 | 146 | regUpdateSTB(context, val, SCPI_REG_ESE, STB_ESR); |
wuliqunyy | 0:be95bfb06686 | 147 | break; |
wuliqunyy | 0:be95bfb06686 | 148 | case SCPI_REG_ESE: |
wuliqunyy | 0:be95bfb06686 | 149 | regUpdate(context, SCPI_REG_ESR); |
wuliqunyy | 0:be95bfb06686 | 150 | break; |
wuliqunyy | 0:be95bfb06686 | 151 | case SCPI_REG_QUES: |
wuliqunyy | 0:be95bfb06686 | 152 | regUpdateSTB(context, val, SCPI_REG_QUESE, STB_QES); |
wuliqunyy | 0:be95bfb06686 | 153 | break; |
wuliqunyy | 0:be95bfb06686 | 154 | case SCPI_REG_QUESE: |
wuliqunyy | 0:be95bfb06686 | 155 | regUpdate(context, SCPI_REG_QUES); |
wuliqunyy | 0:be95bfb06686 | 156 | break; |
wuliqunyy | 0:be95bfb06686 | 157 | case SCPI_REG_QUESC: |
wuliqunyy | 0:be95bfb06686 | 158 | regUpdateEvent(context, old_val, val, SCPI_REG_QUES); |
wuliqunyy | 0:be95bfb06686 | 159 | break; |
wuliqunyy | 0:be95bfb06686 | 160 | case SCPI_REG_OPER: |
wuliqunyy | 0:be95bfb06686 | 161 | regUpdateSTB(context, val, SCPI_REG_OPERE, STB_OPS); |
wuliqunyy | 0:be95bfb06686 | 162 | break; |
wuliqunyy | 0:be95bfb06686 | 163 | case SCPI_REG_OPERE: |
wuliqunyy | 0:be95bfb06686 | 164 | regUpdate(context, SCPI_REG_OPER); |
wuliqunyy | 0:be95bfb06686 | 165 | break; |
wuliqunyy | 0:be95bfb06686 | 166 | case SCPI_REG_OPERC: |
wuliqunyy | 0:be95bfb06686 | 167 | regUpdateEvent(context, old_val, val, SCPI_REG_OPER); |
wuliqunyy | 0:be95bfb06686 | 168 | break; |
wuliqunyy | 0:be95bfb06686 | 169 | |
wuliqunyy | 0:be95bfb06686 | 170 | |
wuliqunyy | 0:be95bfb06686 | 171 | case SCPI_REG_COUNT: |
wuliqunyy | 0:be95bfb06686 | 172 | /* nothing to do */ |
wuliqunyy | 0:be95bfb06686 | 173 | break; |
wuliqunyy | 0:be95bfb06686 | 174 | } |
wuliqunyy | 0:be95bfb06686 | 175 | |
wuliqunyy | 0:be95bfb06686 | 176 | /* set updated register value */ |
wuliqunyy | 0:be95bfb06686 | 177 | context->registers[name] = val; |
wuliqunyy | 0:be95bfb06686 | 178 | |
wuliqunyy | 0:be95bfb06686 | 179 | if (srq) { |
wuliqunyy | 0:be95bfb06686 | 180 | writeControl(context, SCPI_CTRL_SRQ, SCPI_RegGet(context, SCPI_REG_STB)); |
wuliqunyy | 0:be95bfb06686 | 181 | } |
wuliqunyy | 0:be95bfb06686 | 182 | } |
wuliqunyy | 0:be95bfb06686 | 183 | |
wuliqunyy | 0:be95bfb06686 | 184 | /** |
wuliqunyy | 0:be95bfb06686 | 185 | * Set register bits |
wuliqunyy | 0:be95bfb06686 | 186 | * @param name - register name |
wuliqunyy | 0:be95bfb06686 | 187 | * @param bits bit mask |
wuliqunyy | 0:be95bfb06686 | 188 | */ |
wuliqunyy | 0:be95bfb06686 | 189 | void SCPI_RegSetBits(scpi_t * context, scpi_reg_name_t name, scpi_reg_val_t bits) { |
wuliqunyy | 0:be95bfb06686 | 190 | SCPI_RegSet(context, name, SCPI_RegGet(context, name) | bits); |
wuliqunyy | 0:be95bfb06686 | 191 | } |
wuliqunyy | 0:be95bfb06686 | 192 | |
wuliqunyy | 0:be95bfb06686 | 193 | /** |
wuliqunyy | 0:be95bfb06686 | 194 | * Clear register bits |
wuliqunyy | 0:be95bfb06686 | 195 | * @param name - register name |
wuliqunyy | 0:be95bfb06686 | 196 | * @param bits bit mask |
wuliqunyy | 0:be95bfb06686 | 197 | */ |
wuliqunyy | 0:be95bfb06686 | 198 | void SCPI_RegClearBits(scpi_t * context, scpi_reg_name_t name, scpi_reg_val_t bits) { |
wuliqunyy | 0:be95bfb06686 | 199 | SCPI_RegSet(context, name, SCPI_RegGet(context, name) & ~bits); |
wuliqunyy | 0:be95bfb06686 | 200 | } |
wuliqunyy | 0:be95bfb06686 | 201 | |
wuliqunyy | 0:be95bfb06686 | 202 | /** |
wuliqunyy | 0:be95bfb06686 | 203 | * Clear event register |
wuliqunyy | 0:be95bfb06686 | 204 | * @param context |
wuliqunyy | 0:be95bfb06686 | 205 | */ |
wuliqunyy | 0:be95bfb06686 | 206 | void SCPI_EventClear(scpi_t * context) { |
wuliqunyy | 0:be95bfb06686 | 207 | /* TODO */ |
wuliqunyy | 0:be95bfb06686 | 208 | SCPI_RegSet(context, SCPI_REG_ESR, 0); |
wuliqunyy | 0:be95bfb06686 | 209 | } |
wuliqunyy | 0:be95bfb06686 | 210 | |
wuliqunyy | 0:be95bfb06686 | 211 | /** |
wuliqunyy | 0:be95bfb06686 | 212 | * *CLS - This command clears all status data structures in a device. |
wuliqunyy | 0:be95bfb06686 | 213 | * For a device which minimally complies with SCPI. (SCPI std 4.1.3.2) |
wuliqunyy | 0:be95bfb06686 | 214 | * @param context |
wuliqunyy | 0:be95bfb06686 | 215 | * @return |
wuliqunyy | 0:be95bfb06686 | 216 | */ |
wuliqunyy | 0:be95bfb06686 | 217 | scpi_result_t SCPI_CoreCls(scpi_t * context) { |
wuliqunyy | 0:be95bfb06686 | 218 | SCPI_EventClear(context); |
wuliqunyy | 0:be95bfb06686 | 219 | SCPI_ErrorClear(context); |
wuliqunyy | 0:be95bfb06686 | 220 | SCPI_RegSet(context, SCPI_REG_OPER, 0); |
wuliqunyy | 0:be95bfb06686 | 221 | SCPI_RegSet(context, SCPI_REG_QUES, 0); |
wuliqunyy | 0:be95bfb06686 | 222 | return SCPI_RES_OK; |
wuliqunyy | 0:be95bfb06686 | 223 | } |
wuliqunyy | 0:be95bfb06686 | 224 | |
wuliqunyy | 0:be95bfb06686 | 225 | /** |
wuliqunyy | 0:be95bfb06686 | 226 | * *ESE |
wuliqunyy | 0:be95bfb06686 | 227 | * @param context |
wuliqunyy | 0:be95bfb06686 | 228 | * @return |
wuliqunyy | 0:be95bfb06686 | 229 | */ |
wuliqunyy | 0:be95bfb06686 | 230 | scpi_result_t SCPI_CoreEse(scpi_t * context) { |
wuliqunyy | 0:be95bfb06686 | 231 | int32_t new_ESE; |
wuliqunyy | 0:be95bfb06686 | 232 | if (SCPI_ParamInt32(context, &new_ESE, TRUE)) { |
wuliqunyy | 0:be95bfb06686 | 233 | SCPI_RegSet(context, SCPI_REG_ESE, (scpi_reg_val_t) new_ESE); |
wuliqunyy | 0:be95bfb06686 | 234 | return SCPI_RES_OK; |
wuliqunyy | 0:be95bfb06686 | 235 | } |
wuliqunyy | 0:be95bfb06686 | 236 | return SCPI_RES_ERR; |
wuliqunyy | 0:be95bfb06686 | 237 | } |
wuliqunyy | 0:be95bfb06686 | 238 | |
wuliqunyy | 0:be95bfb06686 | 239 | /** |
wuliqunyy | 0:be95bfb06686 | 240 | * *ESE? |
wuliqunyy | 0:be95bfb06686 | 241 | * @param context |
wuliqunyy | 0:be95bfb06686 | 242 | * @return |
wuliqunyy | 0:be95bfb06686 | 243 | */ |
wuliqunyy | 0:be95bfb06686 | 244 | scpi_result_t SCPI_CoreEseQ(scpi_t * context) { |
wuliqunyy | 0:be95bfb06686 | 245 | SCPI_ResultInt32(context, SCPI_RegGet(context, SCPI_REG_ESE)); |
wuliqunyy | 0:be95bfb06686 | 246 | return SCPI_RES_OK; |
wuliqunyy | 0:be95bfb06686 | 247 | } |
wuliqunyy | 0:be95bfb06686 | 248 | |
wuliqunyy | 0:be95bfb06686 | 249 | /** |
wuliqunyy | 0:be95bfb06686 | 250 | * *ESR? |
wuliqunyy | 0:be95bfb06686 | 251 | * @param context |
wuliqunyy | 0:be95bfb06686 | 252 | * @return |
wuliqunyy | 0:be95bfb06686 | 253 | */ |
wuliqunyy | 0:be95bfb06686 | 254 | scpi_result_t SCPI_CoreEsrQ(scpi_t * context) { |
wuliqunyy | 0:be95bfb06686 | 255 | SCPI_ResultInt32(context, SCPI_RegGet(context, SCPI_REG_ESR)); |
wuliqunyy | 0:be95bfb06686 | 256 | SCPI_RegSet(context, SCPI_REG_ESR, 0); |
wuliqunyy | 0:be95bfb06686 | 257 | return SCPI_RES_OK; |
wuliqunyy | 0:be95bfb06686 | 258 | } |
wuliqunyy | 0:be95bfb06686 | 259 | |
wuliqunyy | 0:be95bfb06686 | 260 | /** |
wuliqunyy | 0:be95bfb06686 | 261 | * *IDN? |
wuliqunyy | 0:be95bfb06686 | 262 | * |
wuliqunyy | 0:be95bfb06686 | 263 | * field1: MANUFACTURE |
wuliqunyy | 0:be95bfb06686 | 264 | * field2: MODEL |
wuliqunyy | 0:be95bfb06686 | 265 | * field4: SUBSYSTEMS REVISIONS |
wuliqunyy | 0:be95bfb06686 | 266 | * |
wuliqunyy | 0:be95bfb06686 | 267 | * example: MANUFACTURE,MODEL,0,01-02-01 |
wuliqunyy | 0:be95bfb06686 | 268 | * @param context |
wuliqunyy | 0:be95bfb06686 | 269 | * @return |
wuliqunyy | 0:be95bfb06686 | 270 | */ |
wuliqunyy | 0:be95bfb06686 | 271 | scpi_result_t SCPI_CoreIdnQ(scpi_t * context) { |
wuliqunyy | 0:be95bfb06686 | 272 | int i; |
wuliqunyy | 0:be95bfb06686 | 273 | for (i = 0; i < 4; i++) { |
wuliqunyy | 0:be95bfb06686 | 274 | if (context->idn[i]) { |
wuliqunyy | 0:be95bfb06686 | 275 | SCPI_ResultMnemonic(context, context->idn[i]); |
wuliqunyy | 0:be95bfb06686 | 276 | } else { |
wuliqunyy | 0:be95bfb06686 | 277 | SCPI_ResultMnemonic(context, "0"); |
wuliqunyy | 0:be95bfb06686 | 278 | } |
wuliqunyy | 0:be95bfb06686 | 279 | } |
wuliqunyy | 0:be95bfb06686 | 280 | return SCPI_RES_OK; |
wuliqunyy | 0:be95bfb06686 | 281 | } |
wuliqunyy | 0:be95bfb06686 | 282 | |
wuliqunyy | 0:be95bfb06686 | 283 | /** |
wuliqunyy | 0:be95bfb06686 | 284 | * *OPC |
wuliqunyy | 0:be95bfb06686 | 285 | * @param context |
wuliqunyy | 0:be95bfb06686 | 286 | * @return |
wuliqunyy | 0:be95bfb06686 | 287 | */ |
wuliqunyy | 0:be95bfb06686 | 288 | scpi_result_t SCPI_CoreOpc(scpi_t * context) { |
wuliqunyy | 0:be95bfb06686 | 289 | SCPI_RegSetBits(context, SCPI_REG_ESR, ESR_OPC); |
wuliqunyy | 0:be95bfb06686 | 290 | return SCPI_RES_OK; |
wuliqunyy | 0:be95bfb06686 | 291 | } |
wuliqunyy | 0:be95bfb06686 | 292 | |
wuliqunyy | 0:be95bfb06686 | 293 | /** |
wuliqunyy | 0:be95bfb06686 | 294 | * *OPC? |
wuliqunyy | 0:be95bfb06686 | 295 | * @param context |
wuliqunyy | 0:be95bfb06686 | 296 | * @return |
wuliqunyy | 0:be95bfb06686 | 297 | */ |
wuliqunyy | 0:be95bfb06686 | 298 | scpi_result_t SCPI_CoreOpcQ(scpi_t * context) { |
wuliqunyy | 0:be95bfb06686 | 299 | /* Operation is always completed */ |
wuliqunyy | 0:be95bfb06686 | 300 | SCPI_ResultInt32(context, 1); |
wuliqunyy | 0:be95bfb06686 | 301 | return SCPI_RES_OK; |
wuliqunyy | 0:be95bfb06686 | 302 | } |
wuliqunyy | 0:be95bfb06686 | 303 | |
wuliqunyy | 0:be95bfb06686 | 304 | /** |
wuliqunyy | 0:be95bfb06686 | 305 | * *RST |
wuliqunyy | 0:be95bfb06686 | 306 | * @param context |
wuliqunyy | 0:be95bfb06686 | 307 | * @return |
wuliqunyy | 0:be95bfb06686 | 308 | */ |
wuliqunyy | 0:be95bfb06686 | 309 | scpi_result_t SCPI_CoreRst(scpi_t * context) { |
wuliqunyy | 0:be95bfb06686 | 310 | if (context && context->interface && context->interface->reset) { |
wuliqunyy | 0:be95bfb06686 | 311 | return context->interface->reset(context); |
wuliqunyy | 0:be95bfb06686 | 312 | } |
wuliqunyy | 0:be95bfb06686 | 313 | return SCPI_RES_OK; |
wuliqunyy | 0:be95bfb06686 | 314 | } |
wuliqunyy | 0:be95bfb06686 | 315 | |
wuliqunyy | 0:be95bfb06686 | 316 | /** |
wuliqunyy | 0:be95bfb06686 | 317 | * *SRE |
wuliqunyy | 0:be95bfb06686 | 318 | * @param context |
wuliqunyy | 0:be95bfb06686 | 319 | * @return |
wuliqunyy | 0:be95bfb06686 | 320 | */ |
wuliqunyy | 0:be95bfb06686 | 321 | scpi_result_t SCPI_CoreSre(scpi_t * context) { |
wuliqunyy | 0:be95bfb06686 | 322 | int32_t new_SRE; |
wuliqunyy | 0:be95bfb06686 | 323 | if (SCPI_ParamInt32(context, &new_SRE, TRUE)) { |
wuliqunyy | 0:be95bfb06686 | 324 | SCPI_RegSet(context, SCPI_REG_SRE, (scpi_reg_val_t) new_SRE); |
wuliqunyy | 0:be95bfb06686 | 325 | return SCPI_RES_OK; |
wuliqunyy | 0:be95bfb06686 | 326 | } |
wuliqunyy | 0:be95bfb06686 | 327 | return SCPI_RES_ERR; |
wuliqunyy | 0:be95bfb06686 | 328 | } |
wuliqunyy | 0:be95bfb06686 | 329 | |
wuliqunyy | 0:be95bfb06686 | 330 | /** |
wuliqunyy | 0:be95bfb06686 | 331 | * *SRE? |
wuliqunyy | 0:be95bfb06686 | 332 | * @param context |
wuliqunyy | 0:be95bfb06686 | 333 | * @return |
wuliqunyy | 0:be95bfb06686 | 334 | */ |
wuliqunyy | 0:be95bfb06686 | 335 | scpi_result_t SCPI_CoreSreQ(scpi_t * context) { |
wuliqunyy | 0:be95bfb06686 | 336 | SCPI_ResultInt32(context, SCPI_RegGet(context, SCPI_REG_SRE)); |
wuliqunyy | 0:be95bfb06686 | 337 | return SCPI_RES_OK; |
wuliqunyy | 0:be95bfb06686 | 338 | } |
wuliqunyy | 0:be95bfb06686 | 339 | |
wuliqunyy | 0:be95bfb06686 | 340 | /** |
wuliqunyy | 0:be95bfb06686 | 341 | * *STB? |
wuliqunyy | 0:be95bfb06686 | 342 | * @param context |
wuliqunyy | 0:be95bfb06686 | 343 | * @return |
wuliqunyy | 0:be95bfb06686 | 344 | */ |
wuliqunyy | 0:be95bfb06686 | 345 | scpi_result_t SCPI_CoreStbQ(scpi_t * context) { |
wuliqunyy | 0:be95bfb06686 | 346 | SCPI_ResultInt32(context, SCPI_RegGet(context, SCPI_REG_STB)); |
wuliqunyy | 0:be95bfb06686 | 347 | return SCPI_RES_OK; |
wuliqunyy | 0:be95bfb06686 | 348 | } |
wuliqunyy | 0:be95bfb06686 | 349 | |
wuliqunyy | 0:be95bfb06686 | 350 | /** |
wuliqunyy | 0:be95bfb06686 | 351 | * *TST? |
wuliqunyy | 0:be95bfb06686 | 352 | * @param context |
wuliqunyy | 0:be95bfb06686 | 353 | * @return |
wuliqunyy | 0:be95bfb06686 | 354 | */ |
wuliqunyy | 0:be95bfb06686 | 355 | scpi_result_t SCPI_CoreTstQ(scpi_t * context) { |
wuliqunyy | 0:be95bfb06686 | 356 | (void) context; |
wuliqunyy | 0:be95bfb06686 | 357 | SCPI_ResultInt32(context, 0); |
wuliqunyy | 0:be95bfb06686 | 358 | return SCPI_RES_OK; |
wuliqunyy | 0:be95bfb06686 | 359 | } |
wuliqunyy | 0:be95bfb06686 | 360 | |
wuliqunyy | 0:be95bfb06686 | 361 | /** |
wuliqunyy | 0:be95bfb06686 | 362 | * *WAI |
wuliqunyy | 0:be95bfb06686 | 363 | * @param context |
wuliqunyy | 0:be95bfb06686 | 364 | * @return |
wuliqunyy | 0:be95bfb06686 | 365 | */ |
wuliqunyy | 0:be95bfb06686 | 366 | scpi_result_t SCPI_CoreWai(scpi_t * context) { |
wuliqunyy | 0:be95bfb06686 | 367 | (void) context; |
wuliqunyy | 0:be95bfb06686 | 368 | /* NOP */ |
wuliqunyy | 0:be95bfb06686 | 369 | return SCPI_RES_OK; |
wuliqunyy | 0:be95bfb06686 | 370 | } |
wuliqunyy | 0:be95bfb06686 | 371 | |
wuliqunyy | 0:be95bfb06686 | 372 |