KM3NeT CLB  2.0
KM3NeT CLB v2 Embedded Software
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
shell_opt.c
1 /*
2  * KM3NeT CLB v2 Firmware
3  * ----------------------
4  *
5  * Copyright 2013 KM3NeT Collaboration
6  *
7  * All Rights Reserved.
8  *
9  *
10  * File : shell_tests.c
11  * Created : 14 mrt. 2013
12  * Author : Vincent van Beveren
13  */
14 
15 #include <stdbool.h>
16 #include <stdio.h>
17 
18 #include <stdlib.h>
19 
20 #include "pv/vars.h"
21 #include "drv/i2c/promis.h"
22 #include "drv/wb/tdc.h"
23 #include "kernel/scheduler.h"
24 #include "subsys/sub_opt.h"
25 
26 const char cmd_opt_help[] = "Control and monitor optics";
27 
28 void cmd_opt_status()
29 {
30  int i;
31 
32  if (!optUpdate()) {
33  errPrint(true);
34  puts("*** Error/warnings values may not be correct ***");
35  }
36 
37  puts("Ch BRD BCH ID HV as V TH as mV ENA ERROR / WARN");
38  puts("-- --- --- -------- --- ----- --- ----- --- ---------------");
39 
40 
41 
42 
43  for (i = 0; i < 31; ++i)
44  {
45 
46  uint8_t sts = opt.chan_status[i];
47  printf("%2d %s %3d %08x %2x %5d %2x %5d %s %s%s%s%s\n" ,
48  i,
49  _OCT_BRD(i) == 0 ? "SML" : "LRG",
50  _OCT_CH(i),
51  opt.pmt_id[i],
52  opt.pmt_highvolt[i],
54  opt.pmt_threshold[i],
56  opt.chan_enable & BIT(i) ? "yes" : "no ",
57  sts & OPT_STS_WARN_HRVETO ? "hv_veto " : "",
58  sts & OPT_STS_ERR_COMM ? "i2c " : "",
59  sts & OPT_STS_ERR_OVERCUR ? "over_cur " : "",
60  sts & OPT_STS_WARN_ID ? "pmt_id" : "");
61  }
63  puts("High-Voltage disabled");
64  } else {
65  puts("High-Voltage ENABLED");
66  }
67 }
68 
69 
70 void stopBlast() {
71  puts("Stopping da blast!");
73 }
74 
75 bool cmd_opt_exec(int argc, const char *args[])
76 {
77  if (argc == 0 || (argc == 1 && strcmp(args[0], "help") == 0)) {
78  puts("Usage: opt [command [args]] ");
79  puts("Where command may be:");
80  puts(" status Gives a list of all channels with there configuration and state");
81  puts(" set +|-<no> ... Enable / Disable channels, e.g. +3 enable channel 3, \n"
82  " -5 disable channel 5. Multiple values possible");
83  puts(" cfg <no..> <h> <t> Sets the threshold and high voltage for a specific channel.");
84  puts(" no: One or more channel numbers (max 4).");
85  puts(" h : high voltage is in range of -700 to -1500 in Volts.");
86  puts(" t : threshold is in range of 800 to 2400 in milliVolts");
87  puts(" note: values are rounded to DAC values, and may differ.");
88  puts(" hv on|off turns the high voltage on or off. Default is off.");
89  puts(" note: should be enabled before configuring");
90  puts(" blast <t> <ch>.. Blasts the TDC fifos full");
91  puts(" t: Time to blast in ms, ch: Channel list, 0 based");
92  puts(" veto [<v>|on|off] v : Sets high rate veto value. ");
93  puts(" on : Turns veto on on all channels");
94  puts(" off : Turns veto off on all channels");
95  puts(" Leave empty to query the configuration");
96  return true;
97  } else if (argc == 1 && strcmp(args[0], "status") == 0)
98  {
99  cmd_opt_status();
100  return true;
101  } else if (argc >= 2 && strcmp(args[0], "set") == 0) {
102 
103  int i;
104  for (i = 1; i < argc; i++) {
105  int c = atoi(args[i] + 1);
106  if (args[i][0] == '+') {
107  opt.chan_enable |= BIT(c);
108  } else {
109  opt.chan_enable &= ~BIT(c);
110  }
111  }
112 
113 
114  return true;
115  } else if (argc >= 3 && strcmp(args[0], "blast") == 0) {
116 
117  puts(" _____ __ __");
118  puts("|_ _|| \\ / _|");
119  puts(" | | | | || |_ B L A S T E R");
120  puts(" |_| |__/ \\__| 0.1");
121 
122 
123  uint32_t mask = 0;
124  int i;
125  for (i = 2; i < argc; i++) {
126  int c = atoi(args[i]);
127  mask |= BIT(c);
128  }
129 
130  static int myId = TASK_ID_NONE;
131 
132  if (myId == TASK_ID_NONE)
133  {
134  // schedule high prio, else we'll never get to run
135  if (!schdRegister(stopBlast, true, &myId)) return false;
136  }
137 
138  schdRunDelay(myId, atoi(args[1]));
139 
140  tdcDbgSetBlastFull(mask);
141 
142  return true;
143  } else if (argc == 2 && strcmp(args[0], "hv") == 0)
144  {
145  if (strcmp(args[1], "on") == 0) {
147  } else {
149  }
150  return true;
151  } else if (argc >= 1 && strcmp(args[0], "veto") == 0)
152  {
153  if (argc == 1)
154  {
155  printf("Limit: %d, Enabled Ch Bitmask: %08x\n",
157  return true;
158  }
159  if (strcmp(args[1], "on") == 0) {
160  opt.hr_veto_ena_ch = 0x7fffffff;
161  return true;
162  } else if (strcmp(args[1], "off") == 0) {
163  opt.hr_veto_ena_ch = 0x00000000;
164  return true;
165  }
166  uint32_t v = atoi(args[1]);
167  if (v == 0) return false;
168 
169  opt.hr_veto_thres = v;
170 
171  return true;
172 
173  } else if (argc >= 4 && strcmp(args[0], "cfg") == 0)
174  {
175  int i;
176  int thrs = PRMS_THRS_MV2DAC(atoi(args[argc - 1]));
177  thrs = COERCE(thrs, 0, 255);
178  int hv = PRMS_HV_V2DAC(atoi(args[argc - 2]));
179  hv = COERCE(hv, 0, 255);
180  printf("Setting voltages high-voltage=%d V and threshold=%d mV\n",
181  PRMS_HV_DAC2V(hv), PRMS_THRS_DAC2MV(thrs));
182  for (i = 1; i < argc - 2; ++i) {
183  int ch = atoi(args[i]);
184  opt.pmt_highvolt[ch] = hv;
185  opt.pmt_threshold[ch] = thrs;
186  }
187  return true;
188  }
189  return false;
190 
191 }
192 
193 
uint32_t chan_enable
Channel enable, bit per channel.
Definition: vars.h:338
uint32_t hr_veto_ena_ch
High-rate veto enable, bit per channel.
Definition: vars.h:341
Provides access to all variables of the various subsystems.
#define BIT(N)
Makes a value with the specified bit set.
Definition: macro.h:108
bool schdRegister(SchdTaskF task, bool priority, int *taskId)
Register a task with the scheduler.
Definition: scheduler.c:95
#define OPT_STS_ERR_OVERCUR
Over current.
Definition: sub_opt.h:44
#define SYS_SYS_DISABLE_HV
Bit which disables High Voltage.
Definition: vars.h:85
Simple task scheduler for tasks.
#define OPT_STS_WARN_ID
ID is inconsistent.
Definition: sub_opt.h:46
void tdcDbgSetBlastFull(uint32_t channels)
Blast full FIFOs bitmask for debugging.
Definition: tdc.c:75
uint8_t pmt_highvolt[31]
High voltage settings per channel, 0=PMT at location 0, 31=PMT at location 31 Scaling: 0: -700V...
Definition: vars.h:372
uint8_t chan_status[31]
Channel status, 0=PMT at location 0, 31=PMT at location 31.
Definition: vars.h:368
#define PRMS_HV_V2DAC(V)
Converts the high voltage value into the high voltage DAC byte value.
Definition: promis.h:65
void schdRunDelay(int taskId, int interval)
Schedule a task to run after a delay.
Definition: scheduler.c:201
sys_t sys
Provides access to all process variables of subsystem System.
Definition: vars.c:8
#define OPT_STS_WARN_HRVETO
High rate veto active.
Definition: sub_opt.h:45
uint32_t hr_veto_thres
High-rate veto (hits per timeslice)
Definition: vars.h:335
uint8_t sys_disable
Disable parts of the system.
Definition: vars.h:146
void errPrint(bool clear)
Prints the last error.
Definition: err.c:79
TDC Driver.
bool optUpdate()
Updates the status of the optics.
Definition: sub_opt.c:170
Optics subsystem.
opt_t opt
Provides access to all process variables of subsystem Optics.
Definition: vars.c:144
#define PRMS_THRS_DAC2MV(BYTE)
Converts the threshold DAC byte value into milliVolts.
Definition: promis.h:54
This driver interfaces with the PROMiS PMT ASIC.
#define PRMS_THRS_MV2DAC(MV)
Converts a threshold value in milliVolts to the DAC value.
Definition: promis.h:45
#define PRMS_HV_DAC2V(V)
Converts the high voltage DAC byte value into volts.
Definition: promis.h:74
uint32_t pmt_id[31]
All PMT ID&#39;s, 0=PMT at location 0, 31=PMT at location 31.
Definition: vars.h:332
uint8_t pmt_threshold[31]
Threshold settings per channel, 0=PMT at location 0, 31=PMT at location 31 Scaling: 0: 800mV...
Definition: vars.h:376
#define OPT_STS_ERR_COMM
I2C communication error.
Definition: sub_opt.h:43