KM3NeT CLB  2.0
KM3NeT CLB v2 Embedded Software
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
shell_xadc.c
1 /*
2  * KM3NeT CLB v2 Firmware
3  * ----------------------
4  *
5  * Copyright 2014 KM3NeT Collaboration
6  *
7  * All Rights Reserved.
8  *
9  *
10  * File : shell_xadc.c
11  * Created : 15 apr. 2014
12  * Author : Riccardo Travaglini
13  */
14 
15 #include <stdbool.h>
16 #include <stdio.h>
17 #include <stdlib.h>
18 
19 #include <util/convert.h>
20 
21 #include <drv/wb/xadc.h>
22 
23 #include "kernel/scheduler.h"
24 #include <errorcode.h>
25 #include <kernel/err.h>
26 
27 
28 
29 
30 static const CnvParams _hex = CNV_DEFAULT_HEX;
31 static const CnvParams _int = CNV_DEFAULT;
32 
33 const char cmd_xadc_help[] = "XADC - Read Temp and Voltages";
34 
35 
36 static int _tconv(int x)
37 {
38  return (x*503975/4096-273150)/10;
39 }
40 
41 static int _vmv(int x)
42 {
43  return (x*3000/4096);
44 }
45 
46 
47 //#define TCONV(X) (X*503975/4096-273150)/10
48 //#define VMV(X) (X*3000/4096)
49 
50 #define TCONV _tconv
51 #define VMV _vmv
52 
53 
54 
55 
56 
57 
58 
59 bool cmd_xadc_exec(int argc, const char *args[])
60 {
61 
62  XadcChan cc;
63  XadcType tt;
64  uint32_t ush;
65 
66 
67  if (argc < 1 || ((argc == 1) && (strcmp(args[0],"help") == 0))) {
68  puts("usage:");
69  puts(" xadc read <what> ;");
70  puts(" <what> = temp, vccint, vccaux, vccbram, all");
71  /* puts(" xadc raw <what> ;");
72  puts(" <what> = temp, vccint, vccaux, vccbram, all");*/
73  puts(" xadc power <what> ;");
74  puts(" <what> = up, down, onlya");
75  puts(" xadc alarm <type> <action>;");
76  puts(" <type> = temp, vccint, vccaux, vccbram, ot ");
77  puts(" <action> = read, flag, enable, disable, set ");
78  puts(" if set -> <min,max> <val> (val in hexadecimal) ");
79  puts(" xadc mode <how> ;");
80  puts(" <how> = def,cont");
81 
82 
83  }
84  else if(argc == 2 && strcmp(args[0],"read") == 0){
85  if( strcmp(args[1],"temp")== 0 || strcmp(args[1],"all")== 0 ){
86 // printf("temperature = 0x%x (curr) -- 0x%x (max) -- 0x%x (min)\n",
87  printf("temp = %d (/100 C)(curr) -- %d (/100 C)(max) -- %d (/100 C)(min)\n",
88  TCONV(xadcGetMeas(xadcChanTemp, xadcTypeCur)),
89  TCONV(xadcGetMeas(xadcChanTemp, xadcTypeMax)),
90  TCONV(xadcGetMeas(xadcChanTemp, xadcTypeMin)));
91  }
92  if( strcmp(args[1],"vccint")== 0|| strcmp(args[1],"all")== 0){
93 // printf("VccInt = 0x%x (curr) -- 0x%x (max) -- 0x%x (min)\n",
94  printf("VccInt = %d mV(curr) -- %d mV(max) -- %d mV(min)\n",
95  VMV(xadcGetMeas(xadcChanVccInt, xadcTypeCur)),
96  VMV(xadcGetMeas(xadcChanVccInt, xadcTypeMax)),
97  VMV(xadcGetMeas(xadcChanVccInt, xadcTypeMin)) );
98  }
99  /* if( strcmp(args[1],"vccaux")== 0|| strcmp(args[1],"all")== 0){
100 // printf("VccAux = 0x%x (curr) -- 0x%x (max) -- 0x%x (min)\n",
101  printf("VccAux = %d mV(curr) -- %d mV(max) -- %d mV(min)\n",
102  VMV(xadcGetMeas(xadcChanVccAux,xadcTypeCur)),
103  VMV(xadcGetMeas(xadcChanVccAux,xadcTypeMax)),
104  VMV(xadcGetMeas(xadcChanVccAux,xadcTypeMin)) );
105  }*/
106  if( strcmp(args[1],"vccbram")== 0|| strcmp(args[1],"all")== 0){
107 // printf("VccBram = 0x%x (curr) -- 0x%x (max) -- 0x%x (min)\n",
108  printf("VccBram = %d mV(curr) -- %d mV(max) -- %d mV(min)\n",
109  VMV(xadcGetMeas(xadcChanVccBRAM,xadcTypeCur)),
110  VMV(xadcGetMeas(xadcChanVccBRAM,xadcTypeMax)),
111  VMV(xadcGetMeas(xadcChanVccBRAM,xadcTypeMin)));
112  }
113 
114 
115 
116 
117  }
118 /* else if(argc == 2 && strcmp(args[0],"raw") == 0 ){
119  if( strcmp(args[1],"temp")== 0 || strcmp(args[1],"all")== 0 ){
120  printf("temp = 0x%x (curr) -- 0x%x (max) -- 0x%x (min)\n",
121  (xadcGetMeas(xadcChanTemp,xadcTypeCur)),
122  (xadcGetMeas(xadcChanTemp,xadcTypeMax)),
123  (xadcGetMeas(xadcChanTemp,xadcTypeMin)));
124  }
125  if( strcmp(args[1],"vccint")== 0|| strcmp(args[1],"all")== 0){
126  printf("VccInt = 0x%x (curr) -- 0x%x (max) -- 0x%x (min)\n",
127  (xadcGetMeas(xadcChanVccInt,xadcTypeCur)),
128  (xadcGetMeas(xadcChanVccInt,xadcTypeMax)),
129  (xadcGetMeas(xadcChanVccInt,xadcTypeMin)) );
130  }
131  if( strcmp(args[1],"vccaux")== 0|| strcmp(args[1],"all")== 0){
132  printf("VccAux = 0x%x (curr) -- 0x%x (max) -- 0x%x (min)\n",
133  (xadcGetMeas(xadcChanVccAux,xadcTypeCur)),
134  (xadcGetMeas(xadcChanVccAux,xadcTypeMax)),
135  (xadcGetMeas(xadcChanVccAux,xadcTypeMin)) );
136  }
137  if( strcmp(args[1],"vccbram")== 0|| strcmp(args[1],"all")== 0){
138  printf("VccBram = 0x%x (curr) -- 0x%x (max) -- 0x%x (min)\n",
139  (xadcGetMeas(xadcChanVccBRAM,xadcTypeCur)),
140  (xadcGetMeas(xadcChanVccBRAM,xadcTypeMax)),
141  (xadcGetMeas(xadcChanVccBRAM,xadcTypeMin)));
142  }
143 
144  }*/
145 /* else if(argc == 2 && strcmp(args[0],"power") == 0){
146  if( strcmp(args[1],"up")== 0){xadcPowerDown(xadcPowerStateUp);}
147  else if( strcmp(args[1],"down")== 0){xadcPowerDown(xadcPowerStateDown);}
148  else if( strcmp(args[1],"onlya")== 0){xadcPowerDown(xadcPowerStateBDown);}
149  else return false;
150  }
151  else if(argc >= 3 && strcmp(args[0],"alarm") == 0){
152  if( strcmp(args[1],"temp")== 0)cc = xadcChanTemp;
153  else if( strcmp(args[1],"vccint")== 0)cc = xadcChanVccInt;
154  else if( strcmp(args[1],"vccaux")== 0)cc = xadcChanVccAux;
155  else if( strcmp(args[1],"vccbram")== 0)cc = xadcChanVccBRAM;
156  else if( strcmp(args[1],"ot")== 0)cc = xadcChanOT;
157  else return false;
158  if(argc == 5 && strcmp(args[2],"set")== 0){
159  if( strcmp(args[3],"min")== 0)tt = xadcTypeMin;
160  else if( strcmp(args[3],"max")== 0)tt = xadcTypeMax;
161  else return false;
162  if (cnvParseU(args[4], &ush, _hex) == 0) {
163  puts("Fail to read hex val");
164  return false;
165  }
166  return xadcSetAlarmValue(cc, tt, (unsigned int short)ush);
167  }
168  else if(argc == 3 && strcmp(args[2],"read")== 0){
169  printf("Alarm val = 0x%x\n", xadcGetAlarm(cc)?0x1:0x0);
170  return true;
171  }
172  else if(argc == 3 && strcmp(args[2],"flag")== 0){
173  //printf("Alarm value = 0x%x\n", XadcGetAlarmFlag(cc,true)?0x1:0x0);
174  printf("Warning: com removed from SW in this revision\n");
175  return true;
176  }
177  else if(argc == 3 && strcmp(args[2],"enable")== 0){
178  xadcEnaAlarm(cc,true);
179  }
180  else if(argc == 3 && strcmp(args[2],"disable")== 0){
181  xadcEnaAlarm(cc,false);
182  }
183  else return false;
184 
185  }
186  else if(argc == 2 && strcmp(args[0],"mode") == 0){
187  if( strcmp(args[1],"def")== 0){xadcSetMode(xadcModeDefault);}
188  else if( strcmp(args[1],"cont")== 0){xadcSetMode(xadcModeAutoSequence);}
189 
190  else return false;
191  }*/
192 
193  else return false;
194  return true;
195 }
XADC Driver.
Simple task scheduler for tasks.
#define CNV_DEFAULT
Default conversion/formatting parameters (base 10).
Definition: convert.h:47
Manages the global system error.
This structure provides information about formatting and parsing.
Definition: convert.h:37
This module is responsible for distributing error codes.
This module implements parsing and formating of strings and integers.