From 358f6b291f8718883a4368088dc8ee4d56975c28 Mon Sep 17 00:00:00 2001 From: Pavel Pisa Date: Tue, 28 Apr 2015 22:25:04 +0200 Subject: [PATCH] RPi PXMC Test: SPIMC specific command and initial data capture test. Signed-off-by: Pavel Pisa --- src/app/rpi-pmsm-test1/Makefile.omk | 3 + src/app/rpi-pmsm-test1/appl_cmdproc.c | 2 +- src/app/rpi-pmsm-test1/appl_pxmccmds.c | 155 +++++++++++++++++++++++++ 3 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 src/app/rpi-pmsm-test1/appl_pxmccmds.c diff --git a/src/app/rpi-pmsm-test1/Makefile.omk b/src/app/rpi-pmsm-test1/Makefile.omk index a9b20d1..3bc65c2 100644 --- a/src/app/rpi-pmsm-test1/Makefile.omk +++ b/src/app/rpi-pmsm-test1/Makefile.omk @@ -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) diff --git a/src/app/rpi-pmsm-test1/appl_cmdproc.c b/src/app/rpi-pmsm-test1/appl_cmdproc.c index f446620..d03a0a1 100644 --- a/src/app/rpi-pmsm-test1/appl_cmdproc.c +++ b/src/app/rpi-pmsm-test1/appl_cmdproc.c @@ -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 index 0000000..7348848 --- /dev/null +++ b/src/app/rpi-pmsm-test1/appl_pxmccmds.c @@ -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 +#include +#include +#include + +#include +#include +#include +#include + +#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 +}; -- 2.39.2