KM3NeT CLB  2.0
KM3NeT CLB v2 Embedded Software
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
shell_sfp.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 "drv/wb/wrx.h"
21 #include "modules/wltune.h"
22 
23 const char cmd_sfp_help[] = "SFP utils sfp [tune up|tune down]";
24 
25 int smartParse(const char * value)
26 {
27 
28  int base;
29  int len = strlen(value);
30  if (strlen(value) > 3 && value[1] == 'x') {
31  base = 16;
32  len -= 2;
33  value = &value[2];
34  }
35  else
36  {
37  base = 10;
38  }
39  return strtol(value, value+len, base);
40 }
41 
42 // WRX_TUNE_PROC_NONE = 0,
43 // WRX_TUNE_PROC_EOPTOLINK,
44 // WRX_TUNE_PROC_OESOLUTIONS
45 
46 bool cmd_sfp_exec(int argc, const char *args[])
47 {
48 
49  if (argc >= 2) {
50 
51  if (strcmp(args[0], "tune") == 0) {
52  wltune_update_info();
53 
54  if (wlTuneInfo.tuneword == 65535) {
55  puts("Tune word error");
56  return false;
57  }
58 
59  if (strcmp(args[1], "up") == 0) {
60  wltune_set_word(wlTuneInfo.tuneword + 1);
61  }
62  else if (strcmp(args[1], "down") == 0)
63  {
64  wltune_set_word(wlTuneInfo.tuneword - 1);
65  }
66  else if (strcmp(args[1], "set") == 0)
67  {
68  if (argc == 3) {
69  int32_t v = atoi(args[2]);
70  wltune_set_word(v);
71  } else return false;
72  }
73  else if (strcmp(args[1], "ack") == 0)
74  {
75  wltune_ack();
76  }
77  wltune_update_info();
78  wltune_show_info();
79  } else if (strcmp(args[0], "i2c") == 0) {
80 
81  uint8_t buf[4];
82  uint8_t reg;
83  uint8_t addr;
84  uint8_t len;
85 
86  if (strcmp(args[1], "rd") == 0)
87  {
88  if (argc == 5)
89  {
90 
91  addr = smartParse(args[2]);
92  reg = smartParse(args[3]);
93  len = smartParse(args[4]);
94  if (!wrxModI2cRead(addr, reg, len, &buf[0])) {
95  puts("exit");
96  return false;
97  }
98  printf("i2c rd addr=%02x reg=%02x (%u):", addr, reg, reg, len);
99  for (int i = 0; i < len; ++i)
100  {
101  printf(" %02x", buf[i]);
102  }
103  puts("");
104  } else
105  {
106  return false;
107  }
108 
109  }
110  else if (strcmp(args[1], "wr") == 0)
111  {
112  if (argc >= 5)
113  {
114  addr = smartParse(args[2]);
115  reg = smartParse(args[3]);
116  len = 0;
117  for (int i = 4; i < argc; ++i)
118  {
119  buf[len++] = args[i];
120  }
121 
122  if (!wrxModI2cWrite(addr, reg, len, buf)) return false;
123 
124  puts("i2c write succesful");
125  } else
126  {
127  return false;
128  }
129  }
130 
131  }
132 
133  } else {
134  puts(
135  "sfp <cmd> [<options/subcommand>]\n"
136  " when <cmd> is 'tune', subcommand::\n"
137  " up - single dac value up\n"
138  " down - single dac value down\n"
139  " set [#] - set specific dac value (use with care!)\n"
140  " ack - acknowledge dac value [otherwise will be set back]\n"
141  " when <cmd> is 'i2c'\n"
142  " rd <addr> <reg> <len> - Read len bytes (max 4)\n"
143  " wr <addr> <reg> <byte> [<byte>...] - Write bytes (max 4)\n"
144  );
145 
146  }
147 
148  return true;
149 }
150 
bool wrxModI2cWrite(uint8_t addr, uint8_t reg, uint8_t len, uint8_t *buf)
Write SFP I2C bus (raw)
Definition: wrx.c:185
bool wrxModI2cRead(uint8_t addr, uint8_t reg, uint8_t len, uint8_t *buf)
Read SFP I2C bus (raw)
Definition: wrx.c:169
WhiteRabbit exchange exchanges information between the 2nd LM32 and WhiteRabbit though a small client...