]> rtime.felk.cvut.cz Git - fpga/lx-cpu1/lx-rocon.git/blob - sw/app/rocon/appl_cmds.c
RoCoN: Add command to select motor driver type/axis mode at runtime.
[fpga/lx-cpu1/lx-rocon.git] / sw / app / rocon / appl_cmds.c
1 /*******************************************************************
2   Motion and Robotic System (MARS) aplication components
3
4   appl_cmds.c - application specific commands - mainly global
5                 PXMC state manipulation for RoCoN
6
7   Copyright (C) 2001-2014 by Pavel Pisa - originator
8                           pisa@cmp.felk.cvut.cz
9             (C) 2001-2014 by PiKRON Ltd. - originator
10                     http://www.pikron.com
11
12   This file can be used and copied according to next
13   license alternatives
14    - GPL - GNU Public License
15    - other license provided by project originators
16
17  *******************************************************************/
18
19 #include <cpu_def.h>
20 #include <system_def.h>
21 #include <stdlib.h>
22 #include <pxmc.h>
23 #include <pxmc_coordmv.h>
24 #include <cmd_proc.h>
25 #include <pxmc_cmds.h>
26 #include <utils.h>
27
28 #include "appl_defs.h"
29
30 int sqrtll_main(int argc, char *argv[]);
31 int cmd_do_stop_all(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]);
32 int cmd_do_release_all(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]);
33 int cmd_do_status_bsybits(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]);
34 int cmd_do_axst_all(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]);
35 int cmd_do_cer_all(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]);
36 int cmd_do_clr_all(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]);
37
38 unsigned short statchk_power_stop=0;
39 unsigned short statchk_power_off=0;
40
41 int cmd_do_status_all(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
42 {
43   int i;
44   int val;
45   int opchar;
46   pxmc_state_t *mcs;
47
48   if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
49   if(opchar=='?'){
50     val=0;
51     pxmc_for_each_mcs(i, mcs) {
52       if(mcs)
53         val|=mcs->pxms_flg;
54     }
55     if(pxmc_coordmv_checkst(&pxmc_coordmv_state)>=2)
56       val|=PXMS_CQF_m;  /* coordinator coomand queue full */
57     /*if(trap_pc_addr)
58       val|=0x1000000;*/
59     if(statchk_power_stop)
60       val|=0x20000;
61     if(statchk_power_off)
62       val|=0x10000;
63     return cmd_opchar_replong(cmd_io, param, val, 0, 0);
64   }
65   return 0; 
66 }
67
68 int cmd_do_pthalign(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
69 {
70     pxmc_state_t *mcs;
71     int res;
72
73     if((mcs=cmd_opchar_getreg(cmd_io,des,param))==NULL) return -CMDERR_BADREG;
74
75     if(*param[2]=='?') {
76       return cmd_opchar_replong(cmd_io, param, (long)mcs->pxms_ptmark, 0, 0);
77     }
78
79     if(*param[2]!=':') return -CMDERR_OPCHAR;
80
81     res = pxmc_rocon_pthalalign(mcs, 20);
82
83     if(res < 0)
84        return -CMDERR_BADDIO;
85
86     return 0;
87 }
88
89 /**
90  * cmd_do_axis_mode - checks the command format and busy flag validity, calls pxmc_axis_mode
91  *
92  * if pxmc_axis_mode returns -1, cmd_do_axis_mode returns -1.
93  */
94 int cmd_do_axis_mode(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
95 {
96   int val;
97   pxmc_state_t *mcs;
98
99   if((mcs=cmd_opchar_getreg(cmd_io,des,param))==NULL) return -CMDERR_BADREG;
100
101   if(*param[2]=='?') {
102     return cmd_opchar_replong(cmd_io, param, pxmc_axis_rdmode(mcs), 0, 0);
103   }
104
105   if(*param[2]!=':') return -CMDERR_OPCHAR;
106
107   if(mcs->pxms_flg&PXMS_BSY_m) return -CMDERR_BSYREG;
108
109   val=atol(param[3]);
110   val=pxmc_axis_mode(mcs,val);
111   if(val<0)
112     return val;
113
114   return 0;
115 }
116
117 int cmd_do_sqrtll(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
118 {
119   char *ps;
120   ps = param[1];
121   sqrtll_main(!ps?1: !*ps? 1: 2, param);
122   return 0;
123 }
124
125 cmd_des_t const cmd_des_cer_all={0, CDESM_OPCHR,"PURGE","clear error flags and release failded axes",
126                         cmd_do_cer_all,{}};
127 cmd_des_t const cmd_des_clr_all={0, CDESM_OPCHR,
128                         "CLEAR",0,cmd_do_clr_all,{}};
129 cmd_des_t const cmd_des_stop_all={0, CDESM_OPCHR,
130                         "STOP","stop all motions",cmd_do_stop_all,{}};
131 cmd_des_t const cmd_des_release_all={0, CDESM_OPCHR,
132                         "RELEASE","releases all axes closed loop control",cmd_do_release_all,{}};
133 cmd_des_t const cmd_des_status_all={0, CDESM_OPCHR|CDESM_RD,
134                         "ST","system status bits encoded in number",
135                         cmd_do_status_all,{}};
136 cmd_des_t const cmd_des_status_bsybits={0, CDESM_OPCHR|CDESM_RD,
137                         "STBSYBITS","busy bits of all axes in one number",
138                         cmd_do_status_bsybits,{}};
139 cmd_des_t const cmd_des_stamp={0, CDESM_OPCHR,
140                         "STAMP","host communication stamp",
141                         cmd_do_stamp,{}};
142 cmd_des_t const cmd_des_pthalign={0, CDESM_OPCHR|CDESM_RW,"PTHALIGN?","run alignement of phase according to HAL",
143                         cmd_do_pthalign,
144                         {0,0}};
145 cmd_des_t const cmd_des_axis_mode={0, CDESM_OPCHR|CDESM_WR,
146                         "REGMODE?","axis working mode",cmd_do_axis_mode,
147                         {}};
148 cmd_des_t const cmd_des_sqrtll={0, 0,"sqrtll","test 64-bit square root computation",
149                         cmd_do_sqrtll,
150                         {0,0}};
151
152 cmd_des_t const *const cmd_appl_specific[]={
153   &cmd_des_clr_all,
154   &cmd_des_stop_all,
155   &cmd_des_release_all,
156   &cmd_des_status_all,
157   &cmd_des_status_bsybits,
158   &cmd_des_stamp,
159   &cmd_des_pthalign,
160   &cmd_des_axis_mode,
161   &cmd_des_sqrtll,
162   NULL
163 };