Fork

Dependencies:   mbed libscpi

Files at this revision

API Documentation at this revision

Comitter:
bavovanachte
Date:
Thu Jun 10 13:29:48 2021 +0000
Parent:
30:b463e1f3cae3
Commit message:
Implemented; - Word write; - SPEED aliases

Changed in this revision

i2c_mbed_fpga.cpp Show annotated file Show diff for this revision Revisions of this file
i2c_mbed_fpga.h Show annotated file Show diff for this revision Revisions of this file
scpi-def.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r b463e1f3cae3 -r 0475756cede6 i2c_mbed_fpga.cpp
--- a/i2c_mbed_fpga.cpp	Thu Jun 10 12:45:11 2021 +0000
+++ b/i2c_mbed_fpga.cpp	Thu Jun 10 13:29:48 2021 +0000
@@ -120,6 +120,29 @@
     return ack;
 }
 
+int i2c_mbed_fpga::i2c_word_write_interpreter(int address, int value){
+    int read_value;
+    int busy;
+    int ack = 0;
+    while(i2c_check_busy_flag()) {
+        /* Wait for the busy flag to clear */
+    }
+    ack += this->i2c_word_write_simple(I2C_CMD_INTERPRETER_DATA, value);
+    ack += this->i2c_word_write_simple(I2C_CMD_INTERPRETER_ADDRESS, (address & 0xFFFE)); /* Write the address with the LSB set to 0 to indicate a write operation */
+    /* Check if the command is finished by polling the LSB of CMD_INTERPRETER_ADDRESS */
+    do {
+        ack += this->i2c_word_read_simple(I2C_CMD_INTERPRETER_ADDRESS, &read_value);
+        if((read_value & 0x1) == 0u) {
+            busy = true;
+        } else {
+            busy = false;
+        }
+        wait_us(100); 
+    }
+    while(busy == true);
+    return (ack == 0) ? 0 : 1; 
+}
+
 
 
 /** i2c enter key to open I2C window (for old releases)
diff -r b463e1f3cae3 -r 0475756cede6 i2c_mbed_fpga.h
--- a/i2c_mbed_fpga.h	Thu Jun 10 12:45:11 2021 +0000
+++ b/i2c_mbed_fpga.h	Thu Jun 10 13:29:48 2021 +0000
@@ -42,6 +42,7 @@
     int i2c_word_read_interpreter(int address, int* return_value);
     int i2c_word_write(char *word);
     int i2c_word_write_simple(char address, int value);
+    int i2c_word_write_interpreter(int address, int value);
 
     //int i2c_window_open();
     //int i2c_motor_start();
diff -r b463e1f3cae3 -r 0475756cede6 scpi-def.cpp
--- a/scpi-def.cpp	Thu Jun 10 12:45:11 2021 +0000
+++ b/scpi-def.cpp	Thu Jun 10 13:29:48 2021 +0000
@@ -113,6 +113,30 @@
     return SCPI_RES_OK;
 }
 
+scpi_result_t write_word(scpi_t* context)
+{
+    int address = 0;
+    int value = 0;
+  
+    /* read first parameter: address */
+    if (!SCPI_ParamInt(context, &address, TRUE)) {
+        return SCPI_RES_ERR;
+    }
+    
+    /* read first parameter: address */
+    if (!SCPI_ParamInt(context, &value, TRUE)) {
+        return SCPI_RES_ERR;
+    }
+    
+    if((address >= 0x1000) && (address < 0x1200)) {
+        address = (address - 0x1000) / 2;
+        i2c.i2c_word_write_simple(address, value);
+    } else {
+        i2c.i2c_word_write_interpreter(address, value);
+    }   
+    return SCPI_RES_OK;
+}
+
 
 /**
  * Reimplement IEEE488.2 *TST?
@@ -166,9 +190,12 @@
     /* DMM */
     {"TARGet:DUTYcycle", set_duty, 0},
     {"TARGet:DUTYcycle?", get_duty, 0},
+    {"TARGet:SPEED", set_duty, 0},
+    {"TARGet:SPEED?", get_duty, 0},
     {"LED1", set_led1, 0},
     {"LED1?", get_led1, 0},
     {"MEMory:WORD?", read_word, 0},
+    {"MEMory:WORD", write_word, 0},
     
 
     SCPI_CMD_LIST_END