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-def.c
wuliqunyy 0:be95bfb06686 31 * @date Thu Nov 15 10:58:45 UTC 2012
wuliqunyy 0:be95bfb06686 32 *
wuliqunyy 0:be95bfb06686 33 * @brief SCPI parser test
wuliqunyy 0:be95bfb06686 34 *
wuliqunyy 0:be95bfb06686 35 *
wuliqunyy 0:be95bfb06686 36 */
wuliqunyy 0:be95bfb06686 37
wuliqunyy 0:be95bfb06686 38 #include <stdio.h>
wuliqunyy 0:be95bfb06686 39 #include <stdlib.h>
wuliqunyy 0:be95bfb06686 40 #include <string.h>
wuliqunyy 0:be95bfb06686 41 #include "types.h"
wuliqunyy 0:be95bfb06686 42 #include "uart_mbed.h"
wuliqunyy 0:be95bfb06686 43 #include "main_init.h"
wuliqunyy 0:be95bfb06686 44 #include "i2c_mbed_fpga.h"
wuliqunyy 0:be95bfb06686 45 #include "scpi/scpi.h"
wuliqunyy 0:be95bfb06686 46 #include "scpi/parser.h"
wuliqunyy 0:be95bfb06686 47 #include "scpi-def.h"
wuliqunyy 0:be95bfb06686 48 #include "i2c_ram_defines.h"
wuliqunyy 0:be95bfb06686 49 #include "nv_bitfield_map.h"
wuliqunyy 0:be95bfb06686 50 //#include "test_vector.h"
wuliqunyy 0:be95bfb06686 51 #include "test_fg.h"
wuliqunyy 0:be95bfb06686 52 #include "test_ehp_reg.h"
wuliqunyy 0:be95bfb06686 53 #include "mbed.h"
wuliqunyy 0:be95bfb06686 54
wuliqunyy 0:be95bfb06686 55 extern i2c_mbed_fpga i2c;
wuliqunyy 0:be95bfb06686 56 LocalFileSystem local("local");
wuliqunyy 0:be95bfb06686 57
wuliqunyy 0:be95bfb06686 58 static void reprogram_for_server()
wuliqunyy 0:be95bfb06686 59 {
wuliqunyy 0:be95bfb06686 60 i2c.i2c_word_write_simple((0x1018-0x1000)/2, 0x2080 );
wuliqunyy 0:be95bfb06686 61 i2c.i2c_word_write_simple((0x101A-0x1000)/2, 0xfc13);
wuliqunyy 0:be95bfb06686 62 i2c.i2c_word_write_simple((0x101C-0x1000)/2, 0x7eb );
wuliqunyy 0:be95bfb06686 63 i2c.i2c_word_write_simple((0x1022-0x1000)/2, 0x2073);
wuliqunyy 0:be95bfb06686 64 i2c.i2c_word_write_simple((0x1024-0x1000)/2, 0x1ff);
wuliqunyy 0:be95bfb06686 65 i2c.i2c_word_write_simple((0x1026-0x1000)/2, 0xc);
wuliqunyy 0:be95bfb06686 66 i2c.i2c_word_write_simple((0x1028-0x1000)/2, 0x800);
wuliqunyy 0:be95bfb06686 67 i2c.i2c_word_write_simple((0x103A-0x1000)/2, 0xfff);
wuliqunyy 0:be95bfb06686 68 i2c.i2c_word_write_simple((0x103C-0x1000)/2, 0x1);
wuliqunyy 0:be95bfb06686 69 i2c.i2c_word_write_simple((0x003E)/2, 0x1);
wuliqunyy 0:be95bfb06686 70 i2c.i2c_word_write_simple((0x1040-0x1000)/2, 0x0);
wuliqunyy 0:be95bfb06686 71 i2c.i2c_word_write_simple((0x1042-0x1000)/2, 0x0);
wuliqunyy 0:be95bfb06686 72 i2c.i2c_word_write_simple((0x1044-0x1000)/2, 0x7f);
wuliqunyy 0:be95bfb06686 73 i2c.i2c_word_write_simple((0x1046-0x1000)/2, 0x7f7f);
wuliqunyy 0:be95bfb06686 74 i2c.i2c_word_write_simple((0x1050-0x1000)/2, 0x700);
wuliqunyy 0:be95bfb06686 75 }
wuliqunyy 0:be95bfb06686 76
wuliqunyy 0:be95bfb06686 77 static uint16_t word_read_helper(uint16_t address)
wuliqunyy 0:be95bfb06686 78 {
wuliqunyy 0:be95bfb06686 79 uint16_t value;
wuliqunyy 0:be95bfb06686 80 if((address >= 0x1000) && (address < 0x1200)) {
wuliqunyy 0:be95bfb06686 81 address = (address - 0x1000) / 2;
wuliqunyy 0:be95bfb06686 82 i2c.i2c_word_read_simple(address, &value);
wuliqunyy 0:be95bfb06686 83 } else {
wuliqunyy 0:be95bfb06686 84 i2c.i2c_word_read_interpreter(address, &value);
wuliqunyy 0:be95bfb06686 85 }
wuliqunyy 0:be95bfb06686 86 return value;
wuliqunyy 0:be95bfb06686 87 }
wuliqunyy 0:be95bfb06686 88
wuliqunyy 0:be95bfb06686 89 static scpi_result_t set_duty(scpi_t * context) {
wuliqunyy 0:be95bfb06686 90 float input = 0;
wuliqunyy 0:be95bfb06686 91 int32_t duty_cycle_scaled = 0;
wuliqunyy 0:be95bfb06686 92
wuliqunyy 0:be95bfb06686 93 /* read first parameter if present */
wuliqunyy 0:be95bfb06686 94 if (!SCPI_ParamFloat(context, &input, TRUE)) {
wuliqunyy 0:be95bfb06686 95 return SCPI_RES_ERR;
wuliqunyy 0:be95bfb06686 96 }
wuliqunyy 0:be95bfb06686 97 duty_cycle_scaled = ((int)(input * 65535.0)) / 100u;
wuliqunyy 0:be95bfb06686 98 i2c.i2c_set_open_loop_duty(duty_cycle_scaled);
wuliqunyy 0:be95bfb06686 99 return SCPI_RES_OK;
wuliqunyy 0:be95bfb06686 100 }
wuliqunyy 0:be95bfb06686 101
wuliqunyy 0:be95bfb06686 102 scpi_result_t get_duty(scpi_t* context)
wuliqunyy 0:be95bfb06686 103 {
wuliqunyy 0:be95bfb06686 104 float duty_percentage;
wuliqunyy 0:be95bfb06686 105 uint16_t duty_cycle;
wuliqunyy 0:be95bfb06686 106 i2c.i2c_word_read_simple(I2C_SPEED_DUTY, &duty_cycle);
wuliqunyy 0:be95bfb06686 107 duty_percentage = ((float)duty_cycle)/655.35;
wuliqunyy 0:be95bfb06686 108 SCPI_ResultFloat(context, duty_percentage);
wuliqunyy 0:be95bfb06686 109 return SCPI_RES_OK;
wuliqunyy 0:be95bfb06686 110 }
wuliqunyy 0:be95bfb06686 111
wuliqunyy 0:be95bfb06686 112
wuliqunyy 0:be95bfb06686 113 const scpi_choice_def_t led_selects[] = {
wuliqunyy 0:be95bfb06686 114 { "OFF", 0 },
wuliqunyy 0:be95bfb06686 115 { "ON", 1 },
wuliqunyy 0:be95bfb06686 116 SCPI_CHOICE_LIST_END
wuliqunyy 0:be95bfb06686 117 };
wuliqunyy 0:be95bfb06686 118 static scpi_result_t set_led1(scpi_t * context) {
wuliqunyy 0:be95bfb06686 119 int32_t input = 0;
wuliqunyy 0:be95bfb06686 120
wuliqunyy 0:be95bfb06686 121 if (!SCPI_ParamChoice(context, led_selects, &input, TRUE))
wuliqunyy 0:be95bfb06686 122 return SCPI_RES_ERR;
wuliqunyy 0:be95bfb06686 123
wuliqunyy 0:be95bfb06686 124 led1 = input;
wuliqunyy 0:be95bfb06686 125 return SCPI_RES_OK;
wuliqunyy 0:be95bfb06686 126 }
wuliqunyy 0:be95bfb06686 127
wuliqunyy 0:be95bfb06686 128 scpi_result_t get_led1(scpi_t* context)
wuliqunyy 0:be95bfb06686 129 {
wuliqunyy 0:be95bfb06686 130 int led_value = led1;
wuliqunyy 0:be95bfb06686 131 SCPI_ResultText(context, led_selects[led_value].name);
wuliqunyy 0:be95bfb06686 132 return SCPI_RES_OK;
wuliqunyy 0:be95bfb06686 133 }
wuliqunyy 0:be95bfb06686 134
wuliqunyy 0:be95bfb06686 135
wuliqunyy 0:be95bfb06686 136 scpi_result_t read_word(scpi_t* context)
wuliqunyy 0:be95bfb06686 137 {
wuliqunyy 0:be95bfb06686 138 uint32_t address = 0;
wuliqunyy 0:be95bfb06686 139 uint16_t value;
wuliqunyy 0:be95bfb06686 140
wuliqunyy 0:be95bfb06686 141 /* read first parameter if present */
wuliqunyy 0:be95bfb06686 142 if (!SCPI_ParamUInt32(context, &address, TRUE)) {
wuliqunyy 0:be95bfb06686 143 return SCPI_RES_ERR;
wuliqunyy 0:be95bfb06686 144 }
wuliqunyy 0:be95bfb06686 145 value = word_read_helper((uint16_t)address);
wuliqunyy 0:be95bfb06686 146
wuliqunyy 0:be95bfb06686 147 SCPI_ResultUInt16Base(context, value, 16);
wuliqunyy 0:be95bfb06686 148 return SCPI_RES_OK;
wuliqunyy 0:be95bfb06686 149 }
wuliqunyy 0:be95bfb06686 150
wuliqunyy 0:be95bfb06686 151 scpi_result_t write_word(scpi_t* context)
wuliqunyy 0:be95bfb06686 152 {
wuliqunyy 0:be95bfb06686 153 int32_t address = 0;
wuliqunyy 0:be95bfb06686 154 int32_t value = 0;
wuliqunyy 0:be95bfb06686 155
wuliqunyy 0:be95bfb06686 156 /* read first parameter: address */
wuliqunyy 0:be95bfb06686 157 if (!SCPI_ParamInt(context, &address, TRUE)) {
wuliqunyy 0:be95bfb06686 158 return SCPI_RES_ERR;
wuliqunyy 0:be95bfb06686 159 }
wuliqunyy 0:be95bfb06686 160
wuliqunyy 0:be95bfb06686 161 /* read first parameter: address */
wuliqunyy 0:be95bfb06686 162 if (!SCPI_ParamInt(context, &value, TRUE)) {
wuliqunyy 0:be95bfb06686 163 return SCPI_RES_ERR;
wuliqunyy 0:be95bfb06686 164 }
wuliqunyy 0:be95bfb06686 165
wuliqunyy 0:be95bfb06686 166 if((address >= 0x1000) && (address < 0x1200)) {
wuliqunyy 0:be95bfb06686 167 address = (address - 0x1000) / 2;
wuliqunyy 0:be95bfb06686 168 if(address == 15){ /* Special if-case for the windmilling debugging, writing the default registers */
wuliqunyy 0:be95bfb06686 169 i2c.i2c_word_write_simple(address, value);
wuliqunyy 0:be95bfb06686 170 reprogram_for_server();
wuliqunyy 0:be95bfb06686 171 }
wuliqunyy 0:be95bfb06686 172 else { /* Normal write operation */
wuliqunyy 0:be95bfb06686 173 i2c.i2c_word_write_simple(address, value);
wuliqunyy 0:be95bfb06686 174 }
wuliqunyy 0:be95bfb06686 175 } else {
wuliqunyy 0:be95bfb06686 176 i2c.i2c_word_write_interpreter(address, value);
wuliqunyy 0:be95bfb06686 177 }
wuliqunyy 0:be95bfb06686 178 return SCPI_RES_OK;
wuliqunyy 0:be95bfb06686 179 }
wuliqunyy 0:be95bfb06686 180
wuliqunyy 0:be95bfb06686 181 scpi_result_t read_array(scpi_t* context)
wuliqunyy 0:be95bfb06686 182 {
wuliqunyy 0:be95bfb06686 183 uint32_t start_address = 0;
wuliqunyy 0:be95bfb06686 184 uint32_t size = 0;
wuliqunyy 0:be95bfb06686 185
wuliqunyy 0:be95bfb06686 186 /* read first parameter: start address */
wuliqunyy 0:be95bfb06686 187 if (!SCPI_ParamUInt32(context, &start_address, TRUE)) {
wuliqunyy 0:be95bfb06686 188 return SCPI_RES_ERR;
wuliqunyy 0:be95bfb06686 189 }
wuliqunyy 0:be95bfb06686 190
wuliqunyy 0:be95bfb06686 191 /* read second parameter: size */
wuliqunyy 0:be95bfb06686 192 if (!SCPI_ParamUInt32(context, &size, TRUE)) {
wuliqunyy 0:be95bfb06686 193 return SCPI_RES_ERR;
wuliqunyy 0:be95bfb06686 194 }
wuliqunyy 0:be95bfb06686 195
wuliqunyy 0:be95bfb06686 196 if(((size % 2) != 0u) || (size == 0)) {
wuliqunyy 0:be95bfb06686 197 SCPI_ErrorPush(context,SCPI_ERROR_ILLEGAL_PARAMETER_VALUE);
wuliqunyy 0:be95bfb06686 198 return SCPI_RES_ERR;
wuliqunyy 0:be95bfb06686 199 }
wuliqunyy 0:be95bfb06686 200
wuliqunyy 0:be95bfb06686 201 uint16_t array[(size/2)]; // uint16_t* array = (uint16_t*)malloc(size);
wuliqunyy 0:be95bfb06686 202 uint16_t index = 0;
wuliqunyy 0:be95bfb06686 203 for(index = 0u; index < (size/2); index++) {
wuliqunyy 0:be95bfb06686 204 array[index] = word_read_helper(start_address + (index * 2));
wuliqunyy 0:be95bfb06686 205 }
wuliqunyy 0:be95bfb06686 206
wuliqunyy 0:be95bfb06686 207 SCPI_ResultArrayUInt16(context, array, (sizeof(array) / sizeof(*array)), SCPI_FORMAT_ASCII);
wuliqunyy 0:be95bfb06686 208 return SCPI_RES_OK;
wuliqunyy 0:be95bfb06686 209 }
wuliqunyy 0:be95bfb06686 210
wuliqunyy 0:be95bfb06686 211 scpi_result_t repeat_read(scpi_t* context)
wuliqunyy 0:be95bfb06686 212 {
wuliqunyy 0:be95bfb06686 213 uint32_t interval_us;
wuliqunyy 0:be95bfb06686 214 uint32_t first_address;
wuliqunyy 0:be95bfb06686 215 uint32_t second_address;
wuliqunyy 0:be95bfb06686 216 uint32_t samples;
wuliqunyy 0:be95bfb06686 217
wuliqunyy 0:be95bfb06686 218 /* read first parameter: size */
wuliqunyy 0:be95bfb06686 219 if (!SCPI_ParamUInt32(context, &samples, TRUE)) {
wuliqunyy 0:be95bfb06686 220 return SCPI_RES_ERR;
wuliqunyy 0:be95bfb06686 221 }
wuliqunyy 0:be95bfb06686 222
wuliqunyy 0:be95bfb06686 223 if (!SCPI_ParamUInt32( context, &interval_us, TRUE)) {
wuliqunyy 0:be95bfb06686 224 return SCPI_RES_ERR;
wuliqunyy 0:be95bfb06686 225 }
wuliqunyy 0:be95bfb06686 226
wuliqunyy 0:be95bfb06686 227 /* The first address. This is mandatory */
wuliqunyy 0:be95bfb06686 228 if (!SCPI_ParamUInt32(context, &first_address, TRUE)) {
wuliqunyy 0:be95bfb06686 229 return SCPI_RES_ERR;
wuliqunyy 0:be95bfb06686 230 }
wuliqunyy 0:be95bfb06686 231 /* A potential second address. Optional */
wuliqunyy 0:be95bfb06686 232 if (!SCPI_ParamUInt32(context, &second_address, FALSE)) {
wuliqunyy 0:be95bfb06686 233 second_address = 0;
wuliqunyy 0:be95bfb06686 234 }
wuliqunyy 0:be95bfb06686 235
wuliqunyy 0:be95bfb06686 236 if(second_address != 0) {
wuliqunyy 0:be95bfb06686 237 uint16_t array[samples*2]; // uint16_t* array = (uint16_t*)malloc(size);
wuliqunyy 0:be95bfb06686 238
wuliqunyy 0:be95bfb06686 239 for(uint32_t index = 0u; index < samples*2; index=index+2) {
wuliqunyy 0:be95bfb06686 240 array[index] = word_read_helper(first_address);
wuliqunyy 0:be95bfb06686 241 array[index+1] = word_read_helper(second_address);
wuliqunyy 0:be95bfb06686 242 wait_us(interval_us);
wuliqunyy 0:be95bfb06686 243 }
wuliqunyy 0:be95bfb06686 244 SCPI_ResultArrayUInt16(context, array, (sizeof(array) / sizeof(*array)), SCPI_FORMAT_ASCII);
wuliqunyy 0:be95bfb06686 245 } else {
wuliqunyy 0:be95bfb06686 246 uint16_t array[samples]; // uint16_t* array = (uint16_t*)malloc(size);
wuliqunyy 0:be95bfb06686 247
wuliqunyy 0:be95bfb06686 248 for(uint32_t index = 0u; index < samples; index++) {
wuliqunyy 0:be95bfb06686 249 array[index] = word_read_helper(first_address);
wuliqunyy 0:be95bfb06686 250 wait_us(interval_us);
wuliqunyy 0:be95bfb06686 251 }
wuliqunyy 0:be95bfb06686 252 SCPI_ResultArrayUInt16(context, array, (sizeof(array) / sizeof(*array)), SCPI_FORMAT_ASCII);
wuliqunyy 0:be95bfb06686 253 }
wuliqunyy 0:be95bfb06686 254
wuliqunyy 0:be95bfb06686 255 return SCPI_RES_OK;
wuliqunyy 0:be95bfb06686 256 }
wuliqunyy 0:be95bfb06686 257
wuliqunyy 0:be95bfb06686 258 scpi_result_t dump_ram(scpi_t* context)
wuliqunyy 0:be95bfb06686 259 {
wuliqunyy 0:be95bfb06686 260 uint16_t start_address = 0x1000;
wuliqunyy 0:be95bfb06686 261 uint16_t end_address = 0x1096;
wuliqunyy 0:be95bfb06686 262 uint16_t data;
wuliqunyy 0:be95bfb06686 263
wuliqunyy 0:be95bfb06686 264
wuliqunyy 0:be95bfb06686 265 FILE *RAMdump = fopen("/local/RAMdump.csv", "w"); // Open "RAMdump.csv" on the local file system (on the mbed) for writing
wuliqunyy 0:be95bfb06686 266 led4 = !led4;
wuliqunyy 0:be95bfb06686 267 wait_us(500000);
wuliqunyy 0:be95bfb06686 268 for (uint16_t address=start_address ; address<=end_address-2; address=address+2)
wuliqunyy 0:be95bfb06686 269 {
wuliqunyy 0:be95bfb06686 270 data = word_read_helper((uint16_t)address);
wuliqunyy 0:be95bfb06686 271 fprintf(RAMdump, "0x%.4X,0x%.4X\r\n", address, data); // Write each address and read data of the complete RAM to the external file
wuliqunyy 0:be95bfb06686 272 }
wuliqunyy 0:be95bfb06686 273 fclose(RAMdump);
wuliqunyy 0:be95bfb06686 274 led4 = !led4;
wuliqunyy 0:be95bfb06686 275 return SCPI_RES_OK;
wuliqunyy 0:be95bfb06686 276 }
wuliqunyy 0:be95bfb06686 277
wuliqunyy 0:be95bfb06686 278 scpi_result_t reset_config_mode(scpi_t* context)
wuliqunyy 0:be95bfb06686 279 {
wuliqunyy 0:be95bfb06686 280 main_init();
wuliqunyy 0:be95bfb06686 281 //wait_us(2000000); /* keep FPGA in reset for 2s, to let motor stop */
wuliqunyy 0:be95bfb06686 282 wait_us(100); /* reset the IO-pin for minimum few us */
wuliqunyy 0:be95bfb06686 283 enable_fpga(); /* enable FPGA */
wuliqunyy 0:be95bfb06686 284 i2c.wait_for_idle_state(); /* wait for FPGA responsive */
wuliqunyy 0:be95bfb06686 285 //wait_us(1000);
wuliqunyy 0:be95bfb06686 286 wait_us(100);
wuliqunyy 0:be95bfb06686 287 i2c.i2c_config_mode_entry();/* enter configuration mode */
wuliqunyy 0:be95bfb06686 288 return SCPI_RES_OK;
wuliqunyy 0:be95bfb06686 289 }
wuliqunyy 0:be95bfb06686 290
wuliqunyy 0:be95bfb06686 291 scpi_result_t reset_htol_mode(scpi_t* context)
wuliqunyy 0:be95bfb06686 292 {
wuliqunyy 0:be95bfb06686 293 i2c.i2c_soft_reset();
wuliqunyy 0:be95bfb06686 294 i2c.wait_for_idle_state(); /* wait for FPGA responsive */
wuliqunyy 0:be95bfb06686 295 //wait_us(1000);
wuliqunyy 0:be95bfb06686 296 wait_us(100);
wuliqunyy 0:be95bfb06686 297 i2c.i2c_mlx_mode_entry(); /* Enter melexis mode */
wuliqunyy 0:be95bfb06686 298 wait_us(100);
wuliqunyy 0:be95bfb06686 299 i2c.i2c_htol_mode_entry(); /* Enter HTOL mode */
wuliqunyy 0:be95bfb06686 300 return SCPI_RES_OK;
wuliqunyy 0:be95bfb06686 301 }
wuliqunyy 0:be95bfb06686 302
wuliqunyy 0:be95bfb06686 303
wuliqunyy 0:be95bfb06686 304 const scpi_choice_def_t mlxmode_selects[] = {
wuliqunyy 0:be95bfb06686 305 { "OFF", 0 },
wuliqunyy 0:be95bfb06686 306 { "ON", 1 },
wuliqunyy 0:be95bfb06686 307 SCPI_CHOICE_LIST_END
wuliqunyy 0:be95bfb06686 308 };
wuliqunyy 0:be95bfb06686 309 scpi_result_t reset_application_mode(scpi_t* context)
wuliqunyy 0:be95bfb06686 310 {
wuliqunyy 0:be95bfb06686 311 int32_t mlxmode = 0;
wuliqunyy 0:be95bfb06686 312 if (!SCPI_ParamChoice(context, mlxmode_selects, &mlxmode, FALSE))
wuliqunyy 0:be95bfb06686 313 mlxmode = 0;
wuliqunyy 0:be95bfb06686 314 main_init();
wuliqunyy 0:be95bfb06686 315 wait_us(2000000); /* keep FPGA in reset for 5s, to let motor stop*/
wuliqunyy 0:be95bfb06686 316 enable_fpga(); /* enable FPGA */
wuliqunyy 0:be95bfb06686 317 if(mlxmode == 1) {
wuliqunyy 0:be95bfb06686 318 i2c.wait_for_idle_state();
wuliqunyy 0:be95bfb06686 319 wait_us(1000);
wuliqunyy 0:be95bfb06686 320 i2c.i2c_mlx_mode_entry();
wuliqunyy 0:be95bfb06686 321 }
wuliqunyy 0:be95bfb06686 322 i2c.wait_for_application_state();
wuliqunyy 0:be95bfb06686 323 wait_us(1000);
wuliqunyy 0:be95bfb06686 324 return SCPI_RES_OK;
wuliqunyy 0:be95bfb06686 325 }
wuliqunyy 0:be95bfb06686 326
wuliqunyy 0:be95bfb06686 327 scpi_result_t soft_reset_application_mode(scpi_t* context)
wuliqunyy 0:be95bfb06686 328 {
wuliqunyy 0:be95bfb06686 329 int32_t mlxmode = 0;
wuliqunyy 0:be95bfb06686 330 if (!SCPI_ParamChoice(context, mlxmode_selects, &mlxmode, FALSE))
wuliqunyy 0:be95bfb06686 331 mlxmode = 0;
wuliqunyy 0:be95bfb06686 332 i2c.i2c_soft_reset();
wuliqunyy 0:be95bfb06686 333 if(mlxmode == 1) {
wuliqunyy 0:be95bfb06686 334 i2c.wait_for_idle_state();
wuliqunyy 0:be95bfb06686 335 wait_us(100);
wuliqunyy 0:be95bfb06686 336 i2c.i2c_mlx_mode_entry();
wuliqunyy 0:be95bfb06686 337 i2c.wait_for_application_state();
wuliqunyy 0:be95bfb06686 338 }
wuliqunyy 0:be95bfb06686 339 wait_us(100);
wuliqunyy 0:be95bfb06686 340 return SCPI_RES_OK;
wuliqunyy 0:be95bfb06686 341 }
wuliqunyy 0:be95bfb06686 342
wuliqunyy 0:be95bfb06686 343 /*
wuliqunyy 0:be95bfb06686 344 * self-test routines
wuliqunyy 0:be95bfb06686 345 */
wuliqunyy 0:be95bfb06686 346
wuliqunyy 0:be95bfb06686 347 scpi_result_t test_capture_position_timing(scpi_t* context)
wuliqunyy 0:be95bfb06686 348 {
wuliqunyy 0:be95bfb06686 349 /*to be added*/
wuliqunyy 0:be95bfb06686 350 reset_fpga(); /*finish*/
wuliqunyy 0:be95bfb06686 351 return SCPI_RES_OK;
wuliqunyy 0:be95bfb06686 352 }
wuliqunyy 0:be95bfb06686 353
wuliqunyy 0:be95bfb06686 354 scpi_result_t test_ehp_reg_vector(scpi_t* context)
wuliqunyy 0:be95bfb06686 355 {
wuliqunyy 0:be95bfb06686 356
wuliqunyy 0:be95bfb06686 357 /*vector start, use template later: TBD*/
wuliqunyy 0:be95bfb06686 358 led3=1;
wuliqunyy 0:be95bfb06686 359 test_ehp_reg test(p15,p16);
wuliqunyy 0:be95bfb06686 360 test.configure();
wuliqunyy 0:be95bfb06686 361 test.run();
wuliqunyy 0:be95bfb06686 362 test.stop();
wuliqunyy 0:be95bfb06686 363 SCPI_ResultArrayUInt32(context, test.getResult(), test.getBufferSize(), SCPI_FORMAT_ASCII);
wuliqunyy 0:be95bfb06686 364 SCPI_ResultText(context, test.getResultStatus() );
wuliqunyy 0:be95bfb06686 365 test.release();
wuliqunyy 0:be95bfb06686 366
wuliqunyy 0:be95bfb06686 367 /*
wuliqunyy 0:be95bfb06686 368 test_vector* t;
wuliqunyy 0:be95bfb06686 369 test_ehp_reg test(p15,p16); //p15 to capture timer -> non_flat. p16 to trigger ADC sample
wuliqunyy 0:be95bfb06686 370 t = &test;
wuliqunyy 0:be95bfb06686 371 t->configure();
wuliqunyy 0:be95bfb06686 372 t->run();
wuliqunyy 0:be95bfb06686 373 t->stop();
wuliqunyy 0:be95bfb06686 374 SCPI_ResultArrayUInt32(context, t->getResult(), t->getBufferSize(), SCPI_FORMAT_ASCII);
wuliqunyy 0:be95bfb06686 375 SCPI_ResultText(context, t->getResultStatus() );
wuliqunyy 0:be95bfb06686 376 t->release();
wuliqunyy 0:be95bfb06686 377 */
wuliqunyy 0:be95bfb06686 378 led3=0;
wuliqunyy 0:be95bfb06686 379 return SCPI_RES_OK;
wuliqunyy 0:be95bfb06686 380 }
wuliqunyy 0:be95bfb06686 381
wuliqunyy 0:be95bfb06686 382 scpi_result_t test_fg_vector(scpi_t* context)
wuliqunyy 0:be95bfb06686 383 {
wuliqunyy 0:be95bfb06686 384 /*vector start, use template later: TBD*/
wuliqunyy 0:be95bfb06686 385 led3=1;
wuliqunyy 0:be95bfb06686 386 test_fg test(p15);
wuliqunyy 0:be95bfb06686 387 test.configure();
wuliqunyy 0:be95bfb06686 388 test.run();
wuliqunyy 0:be95bfb06686 389 test.stop();
wuliqunyy 0:be95bfb06686 390 SCPI_ResultArrayUInt32(context, test.getResult(), test.getBufferSize(), SCPI_FORMAT_ASCII);
wuliqunyy 0:be95bfb06686 391 SCPI_ResultText(context, test.getResultStatus() );
wuliqunyy 0:be95bfb06686 392 test.release();
wuliqunyy 0:be95bfb06686 393 /*
wuliqunyy 0:be95bfb06686 394 test_vector* t;
wuliqunyy 0:be95bfb06686 395 test_fg test(p15); //only two option to capture: p15 is CAP3.0 or p16 is CAP3.1
wuliqunyy 0:be95bfb06686 396 t = &test;
wuliqunyy 0:be95bfb06686 397 t->configure();
wuliqunyy 0:be95bfb06686 398 t->run();
wuliqunyy 0:be95bfb06686 399 t->stop();
wuliqunyy 0:be95bfb06686 400 SCPI_ResultArrayUInt32(context, t->getResult(), t->getBufferSize(), SCPI_FORMAT_ASCII);
wuliqunyy 0:be95bfb06686 401 SCPI_ResultText(context, t->getResultStatus() );
wuliqunyy 0:be95bfb06686 402 t->release();
wuliqunyy 0:be95bfb06686 403 */
wuliqunyy 0:be95bfb06686 404 led3=0;
wuliqunyy 0:be95bfb06686 405 return SCPI_RES_OK;
wuliqunyy 0:be95bfb06686 406 }
wuliqunyy 0:be95bfb06686 407
wuliqunyy 0:be95bfb06686 408 /**
wuliqunyy 0:be95bfb06686 409 * Reimplement IEEE488.2 *TST?
wuliqunyy 0:be95bfb06686 410 *
wuliqunyy 0:be95bfb06686 411 * Result should be 0 if everything is ok
wuliqunyy 0:be95bfb06686 412 * Result should be 1 if something goes wrong
wuliqunyy 0:be95bfb06686 413 *
wuliqunyy 0:be95bfb06686 414 * Return SCPI_RES_OK
wuliqunyy 0:be95bfb06686 415 */
wuliqunyy 0:be95bfb06686 416 static scpi_result_t My_CoreTstQ(scpi_t * context) {
wuliqunyy 0:be95bfb06686 417
wuliqunyy 0:be95bfb06686 418 SCPI_ResultInt(context, 0);
wuliqunyy 0:be95bfb06686 419
wuliqunyy 0:be95bfb06686 420
wuliqunyy 0:be95bfb06686 421 return SCPI_RES_OK;
wuliqunyy 0:be95bfb06686 422 }
wuliqunyy 0:be95bfb06686 423
wuliqunyy 0:be95bfb06686 424 void configure_scpi(void)
wuliqunyy 0:be95bfb06686 425 {
wuliqunyy 0:be95bfb06686 426 /* user_context will be pointer to socket */
wuliqunyy 0:be95bfb06686 427 SCPI_Init(&scpi_context,
wuliqunyy 0:be95bfb06686 428 scpi_commands,
wuliqunyy 0:be95bfb06686 429 &scpi_interface,
wuliqunyy 0:be95bfb06686 430 scpi_units_def,
wuliqunyy 0:be95bfb06686 431 "Melexis", "MLX90418", NULL, "0",
wuliqunyy 0:be95bfb06686 432 scpi_input_buffer, SCPI_INPUT_BUFFER_LENGTH,
wuliqunyy 0:be95bfb06686 433 scpi_error_queue_data, SCPI_ERROR_QUEUE_SIZE);
wuliqunyy 0:be95bfb06686 434 }
wuliqunyy 0:be95bfb06686 435
wuliqunyy 0:be95bfb06686 436
wuliqunyy 0:be95bfb06686 437 const scpi_command_t scpi_commands[] = {
wuliqunyy 0:be95bfb06686 438 /* IEEE Mandated Commands (SCPI std V1999.0 4.1.1) */
wuliqunyy 0:be95bfb06686 439 {"*CLS", SCPI_CoreCls, 0},
wuliqunyy 0:be95bfb06686 440 {"*ESE", SCPI_CoreEse, 0},
wuliqunyy 0:be95bfb06686 441 {"*ESE?", SCPI_CoreEseQ, 0},
wuliqunyy 0:be95bfb06686 442 {"*ESR?", SCPI_CoreEsrQ, 0},
wuliqunyy 0:be95bfb06686 443 {"*IDN?", SCPI_CoreIdnQ, 0},
wuliqunyy 0:be95bfb06686 444 {"*OPC", SCPI_CoreOpc, 0},
wuliqunyy 0:be95bfb06686 445 {"*OPC?", SCPI_CoreOpcQ, 0},
wuliqunyy 0:be95bfb06686 446 {"*RST", SCPI_CoreRst, 0},
wuliqunyy 0:be95bfb06686 447 {"*SRE", SCPI_CoreSre, 0},
wuliqunyy 0:be95bfb06686 448 {"*SRE?", SCPI_CoreSreQ, 0},
wuliqunyy 0:be95bfb06686 449 {"*STB?", SCPI_CoreStbQ, 0},
wuliqunyy 0:be95bfb06686 450 {"*TST?", My_CoreTstQ, 0},
wuliqunyy 0:be95bfb06686 451 {"*WAI", SCPI_CoreWai, 0},
wuliqunyy 0:be95bfb06686 452
wuliqunyy 0:be95bfb06686 453 /* Required SCPI commands (SCPI std V1999.0 4.2.1) */
wuliqunyy 0:be95bfb06686 454 {"SYSTem:ERRor[:NEXT]?", SCPI_SystemErrorNextQ, 0},
wuliqunyy 0:be95bfb06686 455 {"SYSTem:ERRor:COUNt?", SCPI_SystemErrorCountQ, 0},
wuliqunyy 0:be95bfb06686 456 {"SYSTem:VERSion?", SCPI_SystemVersionQ, 0},
wuliqunyy 0:be95bfb06686 457
wuliqunyy 0:be95bfb06686 458 //{"STATus:OPERation?", scpi_stub_callback, 0},
wuliqunyy 0:be95bfb06686 459 //{"STATus:OPERation:EVENt?", scpi_stub_callback, 0},
wuliqunyy 0:be95bfb06686 460 //{"STATus:OPERation:CONDition?", scpi_stub_callback, 0},
wuliqunyy 0:be95bfb06686 461 //{"STATus:OPERation:ENABle", scpi_stub_callback, 0},
wuliqunyy 0:be95bfb06686 462 //{"STATus:OPERation:ENABle?", scpi_stub_callback, 0},
wuliqunyy 0:be95bfb06686 463
wuliqunyy 0:be95bfb06686 464 {"STATus:QUEStionable[:EVENt]?", SCPI_StatusQuestionableEventQ, 0},
wuliqunyy 0:be95bfb06686 465 //{"STATus:QUEStionable:CONDition?", scpi_stub_callback, 0},
wuliqunyy 0:be95bfb06686 466 {"STATus:QUEStionable:ENABle", SCPI_StatusQuestionableEnable, 0},
wuliqunyy 0:be95bfb06686 467 {"STATus:QUEStionable:ENABle?", SCPI_StatusQuestionableEnableQ, 0},
wuliqunyy 0:be95bfb06686 468
wuliqunyy 0:be95bfb06686 469 {"STATus:PRESet", SCPI_StatusPreset, 0},
wuliqunyy 0:be95bfb06686 470
wuliqunyy 0:be95bfb06686 471 /* DMM */
wuliqunyy 0:be95bfb06686 472 {"TARGet:DUTYcycle", set_duty, 0},
wuliqunyy 0:be95bfb06686 473 {"TARGet:DUTYcycle?", get_duty, 0},
wuliqunyy 0:be95bfb06686 474 {"TARGet:SPEED", set_duty, 0},
wuliqunyy 0:be95bfb06686 475 {"TARGet:SPEED?", get_duty, 0},
wuliqunyy 0:be95bfb06686 476 {"LED1", set_led1, 0},
wuliqunyy 0:be95bfb06686 477 {"LED1?", get_led1, 0},
wuliqunyy 0:be95bfb06686 478 {"MEMory:WORD?", read_word, 0},
wuliqunyy 0:be95bfb06686 479 {"MEMory:WORD", write_word, 0},
wuliqunyy 0:be95bfb06686 480 {"MEMory:ARRAY?", read_array, 0},
wuliqunyy 0:be95bfb06686 481 {"MEMory:REPEAT?", repeat_read, 0},
wuliqunyy 0:be95bfb06686 482 {"MEMory:DUMPRAM", dump_ram, 0},
wuliqunyy 0:be95bfb06686 483 {"SYSTem:RESET[:APPLImode]", reset_application_mode, 0},
wuliqunyy 0:be95bfb06686 484 {"SYSTem:SOFTRESET[:APPLImode]", soft_reset_application_mode, 0},
wuliqunyy 0:be95bfb06686 485 {"SYSTem:RESET:CONFIGmode", reset_config_mode, 0},
wuliqunyy 0:be95bfb06686 486 {"SYSTem:RESET:HTOLmode", reset_htol_mode, 0},
wuliqunyy 0:be95bfb06686 487 {"TEST:POSItion", test_capture_position_timing, 0},
wuliqunyy 0:be95bfb06686 488 {"TEST:TESTfg", test_fg_vector, 0},
wuliqunyy 0:be95bfb06686 489 {"TEST:TESTehpreg", test_ehp_reg_vector, 0},
wuliqunyy 0:be95bfb06686 490
wuliqunyy 0:be95bfb06686 491 SCPI_CMD_LIST_END
wuliqunyy 0:be95bfb06686 492 };
wuliqunyy 0:be95bfb06686 493
wuliqunyy 0:be95bfb06686 494 scpi_interface_t scpi_interface = {
wuliqunyy 0:be95bfb06686 495 /*.error = */ SCPI_Error,
wuliqunyy 0:be95bfb06686 496 /*.write = */ SCPI_Write,
wuliqunyy 0:be95bfb06686 497 /*.control = */ SCPI_Control,
wuliqunyy 0:be95bfb06686 498 /*.flush = */ SCPI_Flush,
wuliqunyy 0:be95bfb06686 499 /*.reset = */ SCPI_Reset,
wuliqunyy 0:be95bfb06686 500 };
wuliqunyy 0:be95bfb06686 501
wuliqunyy 0:be95bfb06686 502 char scpi_input_buffer[SCPI_INPUT_BUFFER_LENGTH];
wuliqunyy 0:be95bfb06686 503 scpi_error_t scpi_error_queue_data[SCPI_ERROR_QUEUE_SIZE];
wuliqunyy 0:be95bfb06686 504 scpi_t scpi_context;