Blame view

RIOT/sys/include/od.h 4.77 KB
fb11e647   vrobic   reseau statique a...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
  /*
   * Copyright (C) 2014 Martine Lenders <mlenders@inf.fu-berlin.de>
   *
   * This file is subject to the terms and conditions of the GNU Lesser
   * General Public License v2.1. See the file LICENSE in the top level
   * directory for more details.
   */
  
  /**
   * @defgroup sys_od Object dump
   * @ingroup  sys
   * @brief   Allows to print out data dumps of memory regions in a similar fashion
   *          to the UNIX's
   *          <a href="http://pubs.opengroup.org/onlinepubs/9699919799/utilities/od.html">
   *              od
   *          </a> tool
   *
   * @see <a href="http://pubs.opengroup.org/onlinepubs/9699919799/utilities/od.html">
   *          od(1)
   *      </a>
   * @{
   *
   * @file
   *
   * @author  Martine Lenders <mlenders@inf.fu-berlin.de>
   */
  #ifndef OD_H
  #define OD_H
  
  #ifdef __cplusplus
  extern "C" {
  #endif
  
  #include <stdint.h>
  
  /**
   * @brief Bit-mask to extract address offset format settings from flags
   */
  #define OD_FLAGS_ADDRESS_MASK   (0xc000)
  
  /**
   * @brief Bit-mask to extract byte format settings from flags
   */
  #define OD_FLAGS_BYTES_MASK     (0x3e00)
  
  /**
   * @brief Bit-mask to extract length information for byte format from flags
   */
  #define OD_FLAGS_LENGTH_MASK    (0x00f7)
  
  /**
   * @anchor od_flags_address
   * @name Address offset format flags
   * @brief Flags to define format of the address offset
   * @{
   */
  #define OD_FLAGS_ADDRESS_OCTAL      (0x0000)    /**< octal address offset */
  #define OD_FLAGS_ADDRESS_HEX        (0x4000)    /**< hexadecimal address offset */
  #define OD_FLAGS_ADDRESS_DECIMAL    (0x8000)    /**< decimal address offset */
  #define OD_FLAGS_ADDRESS_NONE       (0xc000)    /**< no address offset */
  /** @} */
  
  /**
   * @anchor od_flags_bytes
   * @name Bytes format flags
   * @brief Flags to define format of the byte output
   * @{
   */
  /**
   * @brief Print `LENGTH` bytes as `LENGTH`-wide octal integer (`LENGTH` is defined
   *        in the lower significant byte of the flags)
   */
  #define OD_FLAGS_BYTES_OCTAL    (0x0000)
  
  /**
   * @brief Print bytes as their represented character in ASCII
   */
  #define OD_FLAGS_BYTES_CHAR     (0x2000)
  
  /**
   * @brief Print `LENGTH` bytes as `LENGTH`-wide decimal integer (`LENGTH` is
   *        defined in the lower significant byte of the flags)
   */
  #define OD_FLAGS_BYTES_INT      (0x1000)
  
  /**
   * @brief Alias for @ref OD_FLAGS_BYTES_INT
   */
  #define OD_FLAGS_BYTES_DECIMAL  (OD_FLAGS_BYTES_INT)
  
  /* XXX: No float support for now, but reserved 0x0800 for this */
  
  /**
   * @brief Print `LENGTH` bytes as `LENGTH`-wide decimal unsigned integer
   *        (`LENGTH` is defined in the lower significant byte of the flags)
   */
  #define OD_FLAGS_BYTES_UINT     (0x0400)
  
  /**
   * @brief Print `LENGTH` bytes as `LENGTH`-wide hexadecimal integer
   *        (`LENGTH` is defined in the lower significant byte of the flags)
   */
  #define OD_FLAGS_BYTES_HEX      (0x0200)
  
  /** @} */
  
  
  /**
   * @anchor od_flags_length
   * @name Bytes format length flags
   * @brief Flags to define format length of the byte output
   * @{
   */
  #define OD_FLAGS_LENGTH_1       (0x0010)    /**< 1 byte */
  #define OD_FLAGS_LENGTH_2       (0x0020)    /**< 2 byte */
  #define OD_FLAGS_LENGTH_4       (0x0000)    /**< 4 byte and default */
  /**
   * @brief   8 byte
   *
   * @warning not working with newlib-nano
   */
  #define OD_FLAGS_LENGTH_8       (0x0080)
  #define OD_FLAGS_LENGTH_CHAR    (OD_FLAGS_LENGTH_1)    /**< alias for OD_FLAGS_LENGTH_1 */
  #define OD_FLAGS_LENGTH_SHORT   (0x0002)    /**< sizeof(short) byte */
  #define OD_FLAGS_LENGTH_LONG    (0x0004)    /**< sizeof(long) byte */
  /** @} */
  
  /**
   * @brief   Default value for parameter *width* of @ref od()
   */
  #define OD_WIDTH_DEFAULT    (16)
  
  /**
   * @brief Dumps memory stored at *data* up to *data_len* in octal, decimal, or
   *        hexadecimal representation to stdout
   *
   * @param[in] data      Data to dump.
   * @param[in] data_len  Length in bytes of *data* to output.
   * @param[in] width     Number of bytes per line. If *width* is 0,
   *                      @ref OD_WIDTH_DEFAULT is assumed as a default value.
   * @param[in] flags     Flags as defined in @ref od_flags_address and
   *                      @ref od_flags_bytes
   */
  void od(const void *data, size_t data_len, uint8_t width, uint16_t flags);
  
  /**
   * @brief Dumps memory stored at *data* up to *data_len* in octal, decimal, or
   *        hexadecimal representation to stdout with
   *        `flags == OD_FLAGS_ADDRESS_HEX | OD_FLAGS_BYTES_HEX | OD_FLAGS_LENGTH_1`.
   *
   * @param[in] data      Data to dump.
   * @param[in] data_len  Length in bytes of *data* to output.
   * @param[in] width     Number of bytes per line. If *width* is 0,
   *                      @ref OD_WIDTH_DEFAULT is assumed as a default value.
   */
  static inline void od_hex_dump(const void *data, size_t data_len, uint8_t width)
  {
      od(data, data_len, width, OD_FLAGS_ADDRESS_HEX | OD_FLAGS_BYTES_HEX | OD_FLAGS_LENGTH_1);
  }
  
  #ifdef __cplusplus
  }
  #endif
  
  #endif /* OD_H */
  /** @} */