Harald Welte has uploaded this change for review. ( 
https://gerrit.osmocom.org/13037


Change subject: add 'sim-status' debug command
......................................................................

add 'sim-status' debug command

Change-Id: Id6131be60d37cba769c79952fa44f3ec6c976a38
---
M sysmoOCTSIM/main.c
M sysmoOCTSIM/ncn8025.c
M sysmoOCTSIM/ncn8025.h
3 files changed, 50 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-ccid-firmware 
refs/changes/37/13037/1

diff --git a/sysmoOCTSIM/main.c b/sysmoOCTSIM/main.c
index ef87162..41bf73a 100644
--- a/sysmoOCTSIM/main.c
+++ b/sysmoOCTSIM/main.c
@@ -16,6 +16,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
USA.
 */

+#include <stdlib.h>
+#include <stdio.h>
 #include <parts.h>
 #include <hal_cache.h>
 #include <hri_port_e54.h>
@@ -55,6 +57,25 @@
        printf("Hello World!\r\n");
 }

+DEFUN(sim_status, cmd_sim_status, "sim-status", "Get state of specified 
NCN8025")
+{
+       struct ncn8025_settings settings;
+       int slotnr;
+       if (argc < 2) {
+               printf("You have to specify the slot number (0..7)\r\n");
+               return;
+       }
+       slotnr = atoi(argv[1]);
+       if (slotnr < 0 || slotnr > 7) {
+               printf("You have to specify the slot number (0..7)\r\n");
+               return;
+       }
+       ncn8025_get(slotnr, &settings);
+       printf("SIM%d: ", slotnr);
+       ncn8025_dump(&settings);
+       printf("\r\n");
+}
+
 int main(void)
 {
        atmel_start_init();
@@ -66,6 +87,7 @@
        board_init();
        command_init("sysmoOCTSIM> ");
        command_register(&cmd_hello);
+       command_register(&cmd_sim_status);

        printf("\r\n\r\nsysmocom sysmoOCTSIM\r\n");
        while (true) { // main loop
diff --git a/sysmoOCTSIM/ncn8025.c b/sysmoOCTSIM/ncn8025.c
index 99b93b8..5f9b03d 100644
--- a/sysmoOCTSIM/ncn8025.c
+++ b/sysmoOCTSIM/ncn8025.c
@@ -8,6 +8,7 @@

 #include <stdint.h>
 #include <string.h>
+#include <stdio.h>
 #include <utils_assert.h>
 #include <utils.h>
 #include "octsim_i2c.h"
@@ -134,3 +135,29 @@
                return rc;
        return ncn8025_set(slot, &def_settings);
 }
+
+static const char *volt_str[] = {
+       [SIM_VOLT_3V0] = "3.0",
+       [SIM_VOLT_5V0] = "5.0",
+       [SIM_VOLT_1V8] = "1.8",
+};
+
+static const unsigned int div_val[] = {
+       [SIM_CLKDIV_1] = 1,
+       [SIM_CLKDIV_2] = 2,
+       [SIM_CLKDIV_4] = 4,
+       [SIM_CLKDIV_8] = 8,
+};
+
+void ncn8025_dump(const struct ncn8025_settings *set)
+{
+       printf("VOLT=%s, CLKDIV=%u", volt_str[set->vsel], div_val[set->clkdiv]);
+       if (set->rstin)
+               printf(", RST");
+       if (set->cmdvcc)
+               printf(", VCC");
+       if (set->simpres)
+               printf(", SIMPRES");
+       if (set->led)
+               printf(", LED");
+}
diff --git a/sysmoOCTSIM/ncn8025.h b/sysmoOCTSIM/ncn8025.h
index a392c5d..79e8b60 100644
--- a/sysmoOCTSIM/ncn8025.h
+++ b/sysmoOCTSIM/ncn8025.h
@@ -26,3 +26,4 @@
 int ncn8025_set(uint8_t slot, const struct ncn8025_settings *set);
 int ncn8025_get(uint8_t slot, struct ncn8025_settings *set);
 int ncn8025_init(unsigned int slot);
+void ncn8025_dump(const struct ncn8025_settings *set);

--
To view, visit https://gerrit.osmocom.org/13037
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-ccid-firmware
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id6131be60d37cba769c79952fa44f3ec6c976a38
Gerrit-Change-Number: 13037
Gerrit-PatchSet: 1
Gerrit-Owner: Harald Welte <lafo...@gnumonks.org>

Reply via email to