cornucopia: bump SRCREV
[openembedded.git] / recipes / i2c / files / DumpMem.c
blobe13e94b0f8bd43a78a2317f2949d82103babf32c
1 /****************************************************************************
3 * Copyright (c) 2006 Dave Hylands <dhylands@gmail.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
10 * license.
12 * See README and COPYING for more details.
14 ****************************************************************************/
15 /**
17 * @file DumpMem.c
19 * @brief Memmory dump routine
21 ****************************************************************************/
23 // ---- Include Files -------------------------------------------------------
25 #include <inttypes.h>
26 #include "DumpMem.h"
27 #include "Log.h"
29 // ---- Public Variables ----------------------------------------------------
30 // ---- Private Constants and Types -----------------------------------------
31 // ---- Private Variables ---------------------------------------------------
32 // ---- Private Function Prototypes -----------------------------------------
33 // ---- Functions -----------------------------------------------------------
35 /**************************************************************************/
36 /**
37 * Dumps a page of output for debugging purposes.
40 void DumpMem( const char *prefix, unsigned address, const void *inData, unsigned numBytes )
42 const uint8_t *data = (const uint8_t *)inData;
43 unsigned byteOffset;
45 if ( numBytes == 0 )
47 Log( "%s: No data\n", prefix );
48 return;
51 #define LINE_WIDTH 16
53 for ( byteOffset = 0; byteOffset < numBytes; byteOffset += LINE_WIDTH )
55 unsigned i;
57 Log( "%s: %04x: ", prefix, address + byteOffset );
59 for ( i = 0; i < LINE_WIDTH; i++ )
61 if (( byteOffset + i ) < numBytes )
63 Log( "%02.2X ", data[ byteOffset + i ] );
65 else
67 Log( " " );
70 for ( i = 0; i < LINE_WIDTH; i++ )
72 if (( byteOffset + i ) < numBytes )
74 unsigned char ch = data[ byteOffset + i ];
75 if (( ch < ' ' ) || ( ch > '~' ))
77 Log( "." );
79 else
81 Log( "%c", ch );
84 else
86 break;
89 Log( "\n" );
92 } // DumpMem