KM3NeT CLB  2.0
KM3NeT CLB v2 Embedded Software
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
shell_dbg.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 #include <stdlib.h>
18 
19 #include <util/convert.h>
20 
21 
22 static const CnvParams _hex = CNV_DEFAULT_HEX;
23 
24 const char cmd_busrd_help[] = "Read one or more bus addresses: busrd <addr> [<count>]";
25 
26 bool cmd_busrd_exec(int argc, const char *args[])
27 {
28  int count;
29  int i;
30  uint32_t addr = 0;
31  if (argc < 1) {
32  puts("busrd <addr> <count>, addresses in hex (without '0x'), count in integer");
33  return false;
34  }
35 
36  count = argc == 1 ? 1 : atoi(args[1]);
37  if (count == 0) {
38  puts("Failed to read count");
39  return false;
40  }
41 
42  if (cnvParseU(args[0], &addr, _hex) == 0) {
43  puts("Failed to read hex address");
44  return false;
45  }
46 
47  // just in case, cut of the last 2 bits
48  addr = addr & ~0x3;
49  // count is now in words
50  count <<= 2;
51 
52  for (i = 0; i < count; i += 4) {
53  printf("%08x: %08x\n", addr + i, *((uint32_t *)(addr + i )));
54  }
55 
56  return true;
57 }
58 
59 
60 
int cnvParseU(const char *input, uint32_t *output, CnvParams params)
Parse an unsigned integer.
Definition: convert.c:61
This structure provides information about formatting and parsing.
Definition: convert.h:37
This module implements parsing and formating of strings and integers.