KM3NeT CLB  2.0
KM3NeT CLB v2 Embedded Software
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
shell_app.c
1 /*
2  * KM3NeT CLB v2 Firmware
3  * ----------------------
4  *
5  * Copyright 2013 KM3NeT Collaboration
6  *
7  * All Rights Reserved.
8  *
9  *
10  * File : shell_app.c
11  * Created : 6 mei 2014
12  * Author : Vincent van Beveren
13  */
14 #include <stdbool.h>
15 
16 
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <stdint.h>
20 #include <string.h>
21 
22 #include "util/float.h"
23 #include "clbstate.h"
24 #include "drv/wb/stmach.h"
25 #include "pv/vars.h"
26 #include "pv/varid.h"
27 #include "pv/access.h"
28 
29 const char cmd_pv_help[] = "Show / Modify process variables";
30 
31 static void listPVs() {
32  int subsys, vars;
33 
34  for (subsys = 0; subsys < SUBSYS_COUNT; ++subsys)
35  {
36  const subsys_info_t * sinfo = &subsys_info[subsys];
37  printf("Subsystem %s (#%d)\n", sinfo->name, subsys);
38 #ifdef PV_META
39  for (vars = 0; vars < sinfo->count; ++vars) {
40  int32_t id = sinfo->ids[vars];
41  if (id == 0) continue;
42  const char * name = sinfo->names[vars];
43  printf(" - %-20s (%08x) - ", name, id);
44  if (vidArrSize(id) > 1) {
45  printf("array of %d elements of ", vidArrSize(id));
46  }
47  printf("type %s\n", vidTypeNames[vidType(id)]);
48  }
49 #endif
50  }
51 }
52 
53 static void printBuffer(void * buf, int id) {
54  switch (vidType(id)) {
55  case VID_SCLTYP_U8: printf("%u (%03x)", *((uint8_t *)buf), *((uint8_t *)buf)); break;
56  case VID_SCLTYP_U16: printf("%u (%04x)", *((uint16_t *)buf), *((uint16_t *)buf)); break;
57  case VID_SCLTYP_U32: printf("%lu (%08x)", *((uint32_t *)buf), *((uint32_t *)buf)); break;
58  case VID_SCLTYP_U64: printf("%llu (%016x)", *((uint64_t *)buf), *((uint64_t *)buf)); break;
59  case VID_SCLTYP_I8: printf("%d", *((int8_t *)buf)); break;
60  case VID_SCLTYP_I16: printf("%d", *((int16_t *)buf)); break;
61  case VID_SCLTYP_I32: printf("%ld", *((int32_t *)buf)); break;
62  case VID_SCLTYP_I64: printf("%lld", *((int64_t *)buf)); break;
63  case VID_SCLTYP_F32: printf("%d.%03u", FLT2DU(*((f32_t *)buf), 3)); break;
64  case VID_SCLTYP_BOOL: printf((*((uint8_t*)buf)) ? "True" : "False"); break;
65  default:
66  printf("Not supported");
67  }
68 }
69 
70 static void showPVByID(const char * name, int id) {
71  printf("%-20s: ", name);
72  int i;
73  uint8_t buf[48];
74 
75  if (!xsRead(id, buf, sizeof(buf))) {
76  errPrint(true);
77  return;
78  }
79 
80  int elements = vidArrSize(id);
81  int size = vidSclSize(id);
82 
83  if (elements > 1) {
84  printf("Array of %d elements:", elements);
85  uint8_t * ptr = buf;
86  for (i = 0; i < elements; ++i) {
87  printf("\n * %3d: ", i);
88  printBuffer(ptr, id);
89  ptr += size;
90 
91  }
92  } else {
93  printBuffer(buf, id);
94  }
95  puts("\n");
96 }
97 
98 #ifdef PV_META
99 
100 static void showPV(const char * search) {
101  int subsys, vars;
102  for (subsys = 0; subsys < SUBSYS_COUNT; ++subsys)
103  {
104  const subsys_info_t * sinfo = &subsys_info[subsys];
105  for (vars = 0; vars < sinfo->count; ++vars) {
106  int32_t id = sinfo->ids[vars];
107 // void * ptr = sinfo->ptrs[vars];
108  if (id == 0) continue;
109  const char * name = sinfo->names[vars];
110 
111  if (strncmp(name, search, strlen(search)) == 0) {
112  showPVByID(name, id);
113  }
114  }
115  }
116 
117 }
118 
119 #endif
120 
121 
122 
123 bool cmd_pv_exec(int argc, const char *args[])
124 {
125 
126  if (argc == 0) {
127 #ifndef PV_META
128  puts("Only summery information available, not build with meta-data (PV_META / DEBUG)");
129 #endif
130  listPVs();
131 #ifdef PV_META
132  puts("use pv [name] to show variable contents");
133  // puts("Note: can append * the name to match the beginning of a variable");
134 #endif
135 #ifdef PV_META
136  } else if (argc == 1) {
137  showPV(args[0]);
138 #endif
139  } else {
140  return false;
141  }
142 
143  return true;
144 }
145 
146 
147 const char cmd_state_help[] = "Control/view high-level state machine";
148 
149 bool cmd_state_exec(int argc, const char *args[])
150 {
151  int i;
152 
153  if (argc == 0) {
154  int errCode;
155  const char * errMsg;
156  for (i = 0; i < CLB_SUB_CNT; ++i)
157  {
158  printf("Subsystem %s: %s", clbSubsystemNames[i], clbStateNames[clbState(i)]);
159  if (clbStateError(i, &errCode, &errMsg)) {
160  printf(" -> %s (%x)\n", errMsg, errCode);
161  } else {
162  puts("");
163  }
164  }
165  puts("Invoke 'state help' for more information");
166  } else if (argc == 1 && strcmp(args[0], "help") == 0)
167  {
168  puts("state [<event>|help|clear]");
169  puts("Without argument, lists all subsystems with there current states");
170  puts("With argument:");
171  puts(" help Show this help");
172  puts(" clear Clear error state on all state machines");
173  puts("Else, emit event, one of:");
174  for (i = 0; i < sizeof(clbEventNames) / sizeof(clbEventNames[0]); ++i) {
175  printf("- %s\n", clbEventNames[i]);
176  }
177  } else if (argc == 1 && strcmp(args[0], "clear") == 0)
178  {
180  } else if (argc == 1) {
181  for (i = 0; i < sizeof(clbEventNames) / sizeof(clbEventNames[0]); ++i) {
182  if (stricmp(clbEventNames[i], args[0]) == 0) {
183  clbEvent(0xFF, (ClbEvent)i);
184  return true;
185  }
186  }
187  printf("Unknown event %s\n", args[0]);
188  return false;
189  }
190 
191 
192  return true;
193 }
194 
195 
196 const char cmd_stmach_help[] = "Configure hardware state machine";
197 
198 bool cmd_stmach_exec(int argc, const char *args[])
199 {
200 
201  if (argc == 0 || (argc == 1 && strcmp(args[0], "help") == 0)) {
202  puts("stmach [option [arg]]");
203  puts("where option ay be:");
204  puts(" tslice <us> Timeslice duration in us.");
205  puts(" psize <bytes> Packet size in bytes");
206  puts(" firq <ch> Generate fake tdc fifo-full IRQ on channel 0..31");
207  puts(" run <runnr> Set the run-number.");
208  puts("\nNote that these values will be set when going to the configured phase\n");
209  printf("Current configuration: tslice=%d us, psize=%d bytes\n",
211  } else if (argc == 2)
212  {
213  int v = atoi(args[1]);
214  if (strcmp(args[0], "tslice") == 0) {
215  sys.time_slice_dur = v;
216  } else if (strcmp(args[0], "psize") == 0) {
217  sys.stmach_pktsize = v;
218  } else if (strcmp(args[0], "firq") == 0) {
219  stmachFakeFull(1 << v);
220  } else if (strcmp(args[0], "run") == 0) {
221  sys.run_number = atoi(args[1]);
222  } else return false;
223  } else return false;
224 
225  return true;
226 }
227 
#define VID_SCLTYP_I8
Signed 8 bit integer.
Definition: varid.h:71
uint16_t stmach_pktsize
Max packet size in bytes as chopped by the HW-StateMachine.
Definition: vars.h:124
const char *const clbEventNames[9]
All state change event names.
Definition: clbstate.c:66
ClbEvent
All state change events.
Definition: clbstate.h:88
State Machine Driver.
uint32_t time_slice_dur
Timeslice duration in microseconds.
Definition: vars.h:115
#define VID_SCLTYP_U16
Unsigned 16 bit integer.
Definition: varid.h:68
Provides access to all variables of the various subsystems.
ClbState clbState(int idx)
Returns the current clbSubState for the specified subsystem.
Definition: clbstate.c:92
#define VID_SCLTYP_F32
32 bit IEEE floating point
Definition: varid.h:77
bool clbEvent(int idx, ClbEvent event)
Request a subsystem to go to a certain state.
Definition: clbstate.c:221
Special library for primitive IEEE 754 floating point handling without dragging all float support alo...
#define VID_SCLTYP_I64
Signed 64 bit integer.
Definition: varid.h:74
void clbClearErrorState(int idx)
Clears the error state of the specific subsystem.
Definition: clbstate.c:241
bool clbStateError(int idx, int *code, const char **message)
Retrieves the error of a subsystem (if any).
Definition: clbstate.c:106
#define VID_SCLTYP_I16
Signed 16 bit integer.
Definition: varid.h:72
#define VID_SCLTYP_BOOL
Boolean, encoded as a byte (0 - false, 1 - true)
Definition: varid.h:76
const char *const clbSubsystemNames[5]
Contains a list of all the subsystems.
Definition: clbstate.c:53
uint32_t run_number
The current run number 20160704 Made run number configurable.
Definition: vars.h:109
#define VID_SCLTYP_U64
Unsigned 64 bit integer.
Definition: varid.h:70
void stmachFakeFull(uint32_t mask)
Debugging stuff, don&#39;t touch!
Definition: stmach.c:155
sys_t sys
Provides access to all process variables of subsystem System.
Definition: vars.c:8
const subsys_info_t subsys_info[6]
array of subsystem meta objects
Definition: vars.c:427
static int vidArrSize(int varID)
Returns the number of elements in the array of this variable.
Definition: varid.h:99
static int vidType(int varID)
Returns the type of the variable.
Definition: varid.h:121
void errPrint(bool clear)
Prints the last error.
Definition: err.c:79
uint32_t f32_t
32 bit representation for float.
Definition: float.h:30
const char *const clbStateNames[6]
Contains list of the state names.
Definition: clbstate.c:61
#define CLB_SUB_ALL
Indicates all subsystems. Can be used in clbStateGoto.
Definition: clbstate.h:111
The CLB stare module tracks is responsible for state management of the various sub-systems on the CLB...
#define VID_SCLTYP_U8
Unsigned 8 bit integer.
Definition: varid.h:67
bool xsRead(int varID, void *target, int size)
Reads variable into target buffer from variable structure.
Definition: access.c:60
#define VID_SCLTYP_U32
Unsigned 32 bit integer.
Definition: varid.h:69
const char *const vidTypeNames[16]
Types names.
Definition: varid.c:17
#define VID_SCLTYP_I32
Signed 32 bit integer.
Definition: varid.h:73
Access provides &#39;introspective&#39; access to process variables.
static int vidSclSize(int varID)
Returns the size of the scalar part of variable in bytes.
Definition: varid.h:110
Defines the variable ID format.