Liqun Wu / Mbed 2 deprecated 90418_mbed_controller

Dependencies:   mbed

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?

UserRevisionLine numberNew 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_minimal.c
wuliqunyy 0:be95bfb06686 31 * @date Thu Nov 15 10:58:45 UTC 2012
wuliqunyy 0:be95bfb06686 32 *
wuliqunyy 0:be95bfb06686 33 * @brief SCPI minimal implementation
wuliqunyy 0:be95bfb06686 34 *
wuliqunyy 0:be95bfb06686 35 *
wuliqunyy 0:be95bfb06686 36 */
wuliqunyy 0:be95bfb06686 37
wuliqunyy 0:be95bfb06686 38
wuliqunyy 0:be95bfb06686 39 #include "scpi/parser.h"
wuliqunyy 0:be95bfb06686 40 #include "scpi/minimal.h"
wuliqunyy 0:be95bfb06686 41 #include "scpi/constants.h"
wuliqunyy 0:be95bfb06686 42 #include "scpi/error.h"
wuliqunyy 0:be95bfb06686 43 #include "scpi/ieee488.h"
wuliqunyy 0:be95bfb06686 44 #include "utils_private.h"
wuliqunyy 0:be95bfb06686 45
wuliqunyy 0:be95bfb06686 46 /**
wuliqunyy 0:be95bfb06686 47 * Command stub function
wuliqunyy 0:be95bfb06686 48 * @param context
wuliqunyy 0:be95bfb06686 49 * @return
wuliqunyy 0:be95bfb06686 50 */
wuliqunyy 0:be95bfb06686 51 scpi_result_t SCPI_Stub(scpi_t * context) {
wuliqunyy 0:be95bfb06686 52 (void) context;
wuliqunyy 0:be95bfb06686 53 return SCPI_RES_OK;
wuliqunyy 0:be95bfb06686 54 }
wuliqunyy 0:be95bfb06686 55
wuliqunyy 0:be95bfb06686 56 /**
wuliqunyy 0:be95bfb06686 57 * Query command stub function
wuliqunyy 0:be95bfb06686 58 * @param context
wuliqunyy 0:be95bfb06686 59 * @return
wuliqunyy 0:be95bfb06686 60 */
wuliqunyy 0:be95bfb06686 61 scpi_result_t SCPI_StubQ(scpi_t * context) {
wuliqunyy 0:be95bfb06686 62 SCPI_ResultInt32(context, 0);
wuliqunyy 0:be95bfb06686 63 return SCPI_RES_OK;
wuliqunyy 0:be95bfb06686 64 }
wuliqunyy 0:be95bfb06686 65
wuliqunyy 0:be95bfb06686 66 /**
wuliqunyy 0:be95bfb06686 67 * SYSTem:VERSion?
wuliqunyy 0:be95bfb06686 68 * @param context
wuliqunyy 0:be95bfb06686 69 * @return
wuliqunyy 0:be95bfb06686 70 */
wuliqunyy 0:be95bfb06686 71 scpi_result_t SCPI_SystemVersionQ(scpi_t * context) {
wuliqunyy 0:be95bfb06686 72 SCPI_ResultMnemonic(context, SCPI_STD_VERSION_REVISION);
wuliqunyy 0:be95bfb06686 73 return SCPI_RES_OK;
wuliqunyy 0:be95bfb06686 74 }
wuliqunyy 0:be95bfb06686 75
wuliqunyy 0:be95bfb06686 76 /**
wuliqunyy 0:be95bfb06686 77 * SYSTem:ERRor[:NEXT]?
wuliqunyy 0:be95bfb06686 78 * @param context
wuliqunyy 0:be95bfb06686 79 * @return
wuliqunyy 0:be95bfb06686 80 */
wuliqunyy 0:be95bfb06686 81 scpi_result_t SCPI_SystemErrorNextQ(scpi_t * context) {
wuliqunyy 0:be95bfb06686 82 scpi_error_t error;
wuliqunyy 0:be95bfb06686 83 SCPI_ErrorPop(context, &error);
wuliqunyy 0:be95bfb06686 84 SCPI_ResultError(context, &error);
wuliqunyy 0:be95bfb06686 85 #if USE_DEVICE_DEPENDENT_ERROR_INFORMATION
wuliqunyy 0:be95bfb06686 86 SCPIDEFINE_free(&context->error_info_heap, error.device_dependent_info, false);
wuliqunyy 0:be95bfb06686 87 #endif
wuliqunyy 0:be95bfb06686 88 return SCPI_RES_OK;
wuliqunyy 0:be95bfb06686 89 }
wuliqunyy 0:be95bfb06686 90
wuliqunyy 0:be95bfb06686 91 /**
wuliqunyy 0:be95bfb06686 92 * SYSTem:ERRor:COUNt?
wuliqunyy 0:be95bfb06686 93 * @param context
wuliqunyy 0:be95bfb06686 94 * @return
wuliqunyy 0:be95bfb06686 95 */
wuliqunyy 0:be95bfb06686 96 scpi_result_t SCPI_SystemErrorCountQ(scpi_t * context) {
wuliqunyy 0:be95bfb06686 97 SCPI_ResultInt32(context, SCPI_ErrorCount(context));
wuliqunyy 0:be95bfb06686 98
wuliqunyy 0:be95bfb06686 99 return SCPI_RES_OK;
wuliqunyy 0:be95bfb06686 100 }
wuliqunyy 0:be95bfb06686 101
wuliqunyy 0:be95bfb06686 102 /**
wuliqunyy 0:be95bfb06686 103 * STATus:QUEStionable:CONDition?
wuliqunyy 0:be95bfb06686 104 * @param context
wuliqunyy 0:be95bfb06686 105 * @return
wuliqunyy 0:be95bfb06686 106 */
wuliqunyy 0:be95bfb06686 107 scpi_result_t SCPI_StatusQuestionableConditionQ(scpi_t * context) {
wuliqunyy 0:be95bfb06686 108 /* return value */
wuliqunyy 0:be95bfb06686 109 SCPI_ResultInt32(context, SCPI_RegGet(context, SCPI_REG_QUESC));
wuliqunyy 0:be95bfb06686 110
wuliqunyy 0:be95bfb06686 111 return SCPI_RES_OK;
wuliqunyy 0:be95bfb06686 112 }
wuliqunyy 0:be95bfb06686 113
wuliqunyy 0:be95bfb06686 114 /**
wuliqunyy 0:be95bfb06686 115 * STATus:QUEStionable[:EVENt]?
wuliqunyy 0:be95bfb06686 116 * @param context
wuliqunyy 0:be95bfb06686 117 * @return
wuliqunyy 0:be95bfb06686 118 */
wuliqunyy 0:be95bfb06686 119 scpi_result_t SCPI_StatusQuestionableEventQ(scpi_t * context) {
wuliqunyy 0:be95bfb06686 120 /* return value */
wuliqunyy 0:be95bfb06686 121 SCPI_ResultInt32(context, SCPI_RegGet(context, SCPI_REG_QUES));
wuliqunyy 0:be95bfb06686 122
wuliqunyy 0:be95bfb06686 123 /* clear register */
wuliqunyy 0:be95bfb06686 124 SCPI_RegSet(context, SCPI_REG_QUES, 0);
wuliqunyy 0:be95bfb06686 125
wuliqunyy 0:be95bfb06686 126 return SCPI_RES_OK;
wuliqunyy 0:be95bfb06686 127 }
wuliqunyy 0:be95bfb06686 128
wuliqunyy 0:be95bfb06686 129 /**
wuliqunyy 0:be95bfb06686 130 * STATus:QUEStionable:ENABle?
wuliqunyy 0:be95bfb06686 131 * @param context
wuliqunyy 0:be95bfb06686 132 * @return
wuliqunyy 0:be95bfb06686 133 */
wuliqunyy 0:be95bfb06686 134 scpi_result_t SCPI_StatusQuestionableEnableQ(scpi_t * context) {
wuliqunyy 0:be95bfb06686 135 /* return value */
wuliqunyy 0:be95bfb06686 136 SCPI_ResultInt32(context, SCPI_RegGet(context, SCPI_REG_QUESE));
wuliqunyy 0:be95bfb06686 137
wuliqunyy 0:be95bfb06686 138 return SCPI_RES_OK;
wuliqunyy 0:be95bfb06686 139 }
wuliqunyy 0:be95bfb06686 140
wuliqunyy 0:be95bfb06686 141 /**
wuliqunyy 0:be95bfb06686 142 * STATus:QUEStionable:ENABle
wuliqunyy 0:be95bfb06686 143 * @param context
wuliqunyy 0:be95bfb06686 144 * @return
wuliqunyy 0:be95bfb06686 145 */
wuliqunyy 0:be95bfb06686 146 scpi_result_t SCPI_StatusQuestionableEnable(scpi_t * context) {
wuliqunyy 0:be95bfb06686 147 int32_t new_QUESE;
wuliqunyy 0:be95bfb06686 148 if (SCPI_ParamInt32(context, &new_QUESE, TRUE)) {
wuliqunyy 0:be95bfb06686 149 SCPI_RegSet(context, SCPI_REG_QUESE, (scpi_reg_val_t) new_QUESE);
wuliqunyy 0:be95bfb06686 150 }
wuliqunyy 0:be95bfb06686 151 return SCPI_RES_OK;
wuliqunyy 0:be95bfb06686 152 }
wuliqunyy 0:be95bfb06686 153
wuliqunyy 0:be95bfb06686 154 /**
wuliqunyy 0:be95bfb06686 155 * STATus:OPERation:CONDition?
wuliqunyy 0:be95bfb06686 156 * @param context
wuliqunyy 0:be95bfb06686 157 * @return
wuliqunyy 0:be95bfb06686 158 */
wuliqunyy 0:be95bfb06686 159 scpi_result_t SCPI_StatusOperationConditionQ(scpi_t * context) {
wuliqunyy 0:be95bfb06686 160 /* return value */
wuliqunyy 0:be95bfb06686 161 SCPI_ResultInt32(context, SCPI_RegGet(context, SCPI_REG_OPERC));
wuliqunyy 0:be95bfb06686 162
wuliqunyy 0:be95bfb06686 163 return SCPI_RES_OK;
wuliqunyy 0:be95bfb06686 164 }
wuliqunyy 0:be95bfb06686 165
wuliqunyy 0:be95bfb06686 166 /**
wuliqunyy 0:be95bfb06686 167 * STATus:OPERation[:EVENt]?
wuliqunyy 0:be95bfb06686 168 * @param context
wuliqunyy 0:be95bfb06686 169 * @return
wuliqunyy 0:be95bfb06686 170 */
wuliqunyy 0:be95bfb06686 171 scpi_result_t SCPI_StatusOperationEventQ(scpi_t * context) {
wuliqunyy 0:be95bfb06686 172 /* return value */
wuliqunyy 0:be95bfb06686 173 SCPI_ResultInt32(context, SCPI_RegGet(context, SCPI_REG_OPER));
wuliqunyy 0:be95bfb06686 174
wuliqunyy 0:be95bfb06686 175 /* clear register */
wuliqunyy 0:be95bfb06686 176 SCPI_RegSet(context, SCPI_REG_OPER, 0);
wuliqunyy 0:be95bfb06686 177
wuliqunyy 0:be95bfb06686 178 return SCPI_RES_OK;
wuliqunyy 0:be95bfb06686 179 }
wuliqunyy 0:be95bfb06686 180
wuliqunyy 0:be95bfb06686 181 /**
wuliqunyy 0:be95bfb06686 182 * STATus:OPERation:ENABle?
wuliqunyy 0:be95bfb06686 183 * @param context
wuliqunyy 0:be95bfb06686 184 * @return
wuliqunyy 0:be95bfb06686 185 */
wuliqunyy 0:be95bfb06686 186 scpi_result_t SCPI_StatusOperationEnableQ(scpi_t * context) {
wuliqunyy 0:be95bfb06686 187 /* return value */
wuliqunyy 0:be95bfb06686 188 SCPI_ResultInt32(context, SCPI_RegGet(context, SCPI_REG_OPERE));
wuliqunyy 0:be95bfb06686 189
wuliqunyy 0:be95bfb06686 190 return SCPI_RES_OK;
wuliqunyy 0:be95bfb06686 191 }
wuliqunyy 0:be95bfb06686 192
wuliqunyy 0:be95bfb06686 193 /**
wuliqunyy 0:be95bfb06686 194 * STATus:OPERation:ENABle
wuliqunyy 0:be95bfb06686 195 * @param context
wuliqunyy 0:be95bfb06686 196 * @return
wuliqunyy 0:be95bfb06686 197 */
wuliqunyy 0:be95bfb06686 198 scpi_result_t SCPI_StatusOperationEnable(scpi_t * context) {
wuliqunyy 0:be95bfb06686 199 int32_t new_OPERE;
wuliqunyy 0:be95bfb06686 200 if (SCPI_ParamInt32(context, &new_OPERE, TRUE)) {
wuliqunyy 0:be95bfb06686 201 SCPI_RegSet(context, SCPI_REG_OPERE, (scpi_reg_val_t) new_OPERE);
wuliqunyy 0:be95bfb06686 202 }
wuliqunyy 0:be95bfb06686 203 return SCPI_RES_OK;
wuliqunyy 0:be95bfb06686 204 }
wuliqunyy 0:be95bfb06686 205
wuliqunyy 0:be95bfb06686 206 /**
wuliqunyy 0:be95bfb06686 207 * STATus:PRESet
wuliqunyy 0:be95bfb06686 208 * @param context
wuliqunyy 0:be95bfb06686 209 * @return
wuliqunyy 0:be95bfb06686 210 */
wuliqunyy 0:be95bfb06686 211 scpi_result_t SCPI_StatusPreset(scpi_t * context) {
wuliqunyy 0:be95bfb06686 212 /* clear STATUS:... */
wuliqunyy 0:be95bfb06686 213 SCPI_RegSet(context, SCPI_REG_QUES, 0);
wuliqunyy 0:be95bfb06686 214 return SCPI_RES_OK;
wuliqunyy 0:be95bfb06686 215 }
wuliqunyy 0:be95bfb06686 216