]> rtime.felk.cvut.cz Git - fpga/rpi-motor-control-pxmc.git/commitdiff
RPi PXMC Test: SPIMC specific command and initial data capture test.
authorPavel Pisa <pisa@cmp.felk.cvut.cz>
Tue, 28 Apr 2015 20:25:04 +0000 (22:25 +0200)
committerPavel Pisa <pisa@cmp.felk.cvut.cz>
Tue, 28 Apr 2015 20:25:04 +0000 (22:25 +0200)
Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
src/app/rpi-pmsm-test1/Makefile.omk
src/app/rpi-pmsm-test1/appl_cmdproc.c
src/app/rpi-pmsm-test1/appl_pxmccmds.c [new file with mode: 0644]

index a9b20d12ef3deece39ada2539a3cf4b96cb582b9..3bc65c25b73a17262a0e7599ea5d2baf55fe61e0 100644 (file)
@@ -31,6 +31,9 @@ rpi_pmsm_t1_SOURCES += appl_cmdproc.c
 #rpi_pmsm_t1_SOURCES += appl_tests.c
 #rpi_pmsm_t1_SOURCES += appl_dprint.c
 #rpi_pmsm_t1_SOURCES += cmd_uartcon.c
+ifeq ($(CONFIG_PXMC_COORDMV),y)
+rpi_pmsm_t1_SOURCES += appl_pxmccmds.c
+endif
 endif
 
 ifeq ($(CONFIG_PXMC),y)
index f4466204431aed1694d1280511024ac1cdc88d6a..d03a0a1f3ff08f6b4deea53771cfb1d0a8638733 100644 (file)
@@ -105,7 +105,7 @@ cmd_des_t const *cmd_list_main[] =
   &cmd_des_r_all,
   CMD_DES_INCLUDE_SUBLIST(cmd_pxmc_coordmv),
   //CMD_DES_INCLUDE_SUBLIST(cmd_appl_specific),
-  //CMD_DES_INCLUDE_SUBLIST(cmd_appl_pxmc),
+  CMD_DES_INCLUDE_SUBLIST(cmd_appl_pxmc),
   //&cmd_des_dprint,
   NULL
 };
diff --git a/src/app/rpi-pmsm-test1/appl_pxmccmds.c b/src/app/rpi-pmsm-test1/appl_pxmccmds.c
new file mode 100644 (file)
index 0000000..7348848
--- /dev/null
@@ -0,0 +1,155 @@
+/*******************************************************************
+  Motion and Robotic System (MARS) aplication components.
+
+  appl_pxmccmds.c - position controller RoCoN specific commands
+
+  Copyright (C) 2001-2013 by Pavel Pisa - originator
+                          pisa@cmp.felk.cvut.cz
+            (C) 2001-2013 by PiKRON Ltd. - originator
+                    http://www.pikron.com
+
+  This file can be used and copied according to next
+  license alternatives
+   - GPL - GNU Public License
+   - other license provided by project originators
+
+ *******************************************************************/
+
+#include <system_def.h>
+#include <pxmc.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "pxmc_cmds.h"
+
+#include "appl_defs.h"
+#include "appl_pxmc.h"
+#include "pxmc_spimc.h"
+
+#define SPIMC_LOG_CURRENT_SIZE 1024*1024
+
+int32_t *spimc_logcurrent_buff;
+int32_t *spimc_logcurrent_pos;
+
+extern spimc_state_t spimc_state0;
+
+int spimc_logcurrent(struct pxmc_state *mcs)
+{
+  /*pxmc_spimc_state_t *mcsrc = pxmc_state2spimc_state(mcs); */
+  /*mcsrc->spimc_state*/
+  spimc_state_t *spimc = &spimc_state0;
+
+  if ((spimc_logcurrent_buff == NULL) ||
+      (spimc_logcurrent_pos == NULL) ||
+      ((char*)spimc_logcurrent_pos -
+       (char*)spimc_logcurrent_buff + 64 >= SPIMC_LOG_CURRENT_SIZE))
+    return 0;
+
+
+  spimc_logcurrent_pos[0] = mcs->pxms_ptindx;
+
+  spimc_logcurrent_pos[1] = spimc->pwm[0];
+  spimc_logcurrent_pos[2] = spimc->pwm[1];
+  spimc_logcurrent_pos[3] = spimc->pwm[2];
+
+  spimc_logcurrent_pos[4] = spimc->curadc_sqn;
+
+  spimc_logcurrent_pos[5] = spimc->curadc_cumsum[0];
+  spimc_logcurrent_pos[6] = spimc->curadc_cumsum[1];
+  spimc_logcurrent_pos[7] = spimc->curadc_cumsum[2];
+
+  spimc_logcurrent_pos += 8;
+
+  return 0;
+}
+
+int cmd_do_logcurrent(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
+  int fd;
+  size_t log_size;
+
+  if (pxmc_main_list.pxml_cnt < 1)
+    return -1;
+
+  if (pxmc_dbgset(pxmc_main_list.pxml_arr[0], NULL, 0) < 0)
+    return -1;
+
+  if (spimc_logcurrent_buff == NULL) {
+    spimc_logcurrent_buff = malloc(SPIMC_LOG_CURRENT_SIZE);
+    if (spimc_logcurrent_buff == NULL)
+      return -1;
+  }
+
+  if (spimc_logcurrent_pos != NULL) {
+    log_size = (char*)spimc_logcurrent_pos - (char*)spimc_logcurrent_buff;
+    printf("Log size %ld\n", (long)log_size);
+
+    if ((spimc_logcurrent_pos > spimc_logcurrent_buff) &&
+        (log_size < SPIMC_LOG_CURRENT_SIZE)) {
+
+      fd = open("currents.bin", O_WRONLY | O_CREAT | O_TRUNC,
+              S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
+
+      if (fd == -1)
+        return -1;
+
+      write(fd, spimc_logcurrent_buff, log_size);
+
+      close(fd);
+    }
+  }
+
+  spimc_logcurrent_pos = spimc_logcurrent_buff;
+
+  if (pxmc_dbgset(pxmc_main_list.pxml_arr[0], spimc_logcurrent, 1) < 0)
+    return -1;
+
+  return 0;
+}
+
+cmd_des_t const cmd_des_regcurdp={0, CDESM_OPCHR|CDESM_RW,
+                        "REGCURDP?","current controller d component p parameter", cmd_do_reg_short_val,
+                        {(char*)pxmc_spimc_state_offs(cur_d_p),
+                         0}};
+
+cmd_des_t const cmd_des_regcurdi={0, CDESM_OPCHR|CDESM_RW,
+                        "REGCURDI?","current controller d component i parameter", cmd_do_reg_short_val,
+                        {(char*)pxmc_spimc_state_offs(cur_d_i),
+                         0}};
+
+cmd_des_t const cmd_des_regcurqp={0, CDESM_OPCHR|CDESM_RW,
+                        "REGCURQP?","current controller q component p parameter", cmd_do_reg_short_val,
+                        {(char*)pxmc_spimc_state_offs(cur_q_p),
+                         0}};
+
+cmd_des_t const cmd_des_regcurqi={0, CDESM_OPCHR|CDESM_RW,
+                        "REGCURQI?","current controller q component i parameter", cmd_do_reg_short_val,
+                        {(char*)pxmc_spimc_state_offs(cur_q_i),
+                         0}};
+
+cmd_des_t const cmd_des_regcurhold={0, CDESM_OPCHR|CDESM_RW,
+                        "REGCURHOLD?","current steady hold value for stepper", cmd_do_reg_short_val,
+                        {(char*)pxmc_spimc_state_offs(cur_hold),
+                         0}};
+
+cmd_des_t const cmd_des_logcurrent={0, 0,
+                        "logcurrent","log current history", cmd_do_logcurrent,
+                        {(char*)0,
+                         0}};
+
+
+cmd_des_t const *cmd_appl_pxmc[] =
+{
+  &cmd_des_regcurdp,
+  &cmd_des_regcurdi,
+  &cmd_des_regcurqp,
+  &cmd_des_regcurqi,
+  &cmd_des_regcurhold,
+  &cmd_des_logcurrent,
+  NULL
+};