Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ti-connected-launchpad
lm4tools_public
Commits
79b32d37
Commit
79b32d37
authored
Oct 25, 2012
by
Fabio Utzig
Browse files
pretty print refactoring
parent
61f691f0
Changes
1
Show whitespace changes
Inline
Side-by-side
lm4flash/lm4flash.c
View file @
79b32d37
...
@@ -105,31 +105,47 @@ static int do_verify = 0;
...
@@ -105,31 +105,47 @@ static int do_verify = 0;
#define cpu_to_le32 le32_to_cpu
#define cpu_to_le32 le32_to_cpu
#ifdef DEBUG
static
void
pretty_print_buf
(
uint8_t
*
b
,
int
size
)
{
#define PP_LINESIZE 80
#define PP_NUM_P_LINE 16
#define PP_HEX_COL 7
#define PP_ASC_COL 56
int
i
,
pos
;
char
linebuf
[
PP_LINESIZE
];
memset
(
linebuf
,
' '
,
sizeof
linebuf
);
linebuf
[
PP_ASC_COL
+
PP_NUM_P_LINE
]
=
0
;
for
(
i
=
0
;
i
<
size
;
i
++
)
{
if
(((
i
%
PP_NUM_P_LINE
)
==
0
))
{
if
(
i
)
{
printf
(
"%s
\n
"
,
linebuf
);
memset
(
linebuf
,
' '
,
sizeof
linebuf
);
linebuf
[
PP_ASC_COL
+
PP_NUM_P_LINE
]
=
0
;
}
sprintf
(
linebuf
,
"%04x : "
,
i
);
linebuf
[
PP_ASC_COL
]
=
' '
;
linebuf
[
PP_HEX_COL
]
=
' '
;
}
pos
=
PP_HEX_COL
+
((
i
%
PP_NUM_P_LINE
)
*
3
);
sprintf
(
linebuf
+
pos
,
"%02x"
,
b
[
i
]);
linebuf
[
pos
+
2
]
=
' '
;
linebuf
[(
i
%
PP_NUM_P_LINE
)
+
PP_ASC_COL
]
=
isprint
(
b
[
i
])
?
b
[
i
]
:
'.'
;
}
printf
(
"%s
\n
"
,
linebuf
);
}
#endif
static
int
send_command
(
libusb_device_handle
*
handle
,
int
size
)
static
int
send_command
(
libusb_device_handle
*
handle
,
int
size
)
{
{
int
transferred
=
0
;
int
transferred
=
0
;
int
retval
;
int
retval
;
#ifdef DEBUG
#ifdef DEBUG
{
printf
(
">>> sending %d bytes
\n
"
,
size
);
int
i
,
col
;
pretty_print_buf
(
buf
.
u8
,
size
);
char
ascbuf
[
32
];
printf
(
"send_command: size=%d
\n
"
,
size
);
printf
(
"buffer:
\n
"
);
memset
(
ascbuf
,
0
,
sizeof
(
ascbuf
));
for
(
i
=
0
,
col
=
1
;
i
<
size
;
i
++
,
col
++
)
{
printf
(
"%02x "
,
buf
.
u8
[
i
]);
ascbuf
[
i
%
16
]
=
isprint
(
buf
.
u8
[
i
])
?
buf
.
u8
[
i
]
:
'.'
;
if
(
col
==
16
)
{
col
=
0
;
printf
(
"%s
\n
"
,
ascbuf
);
memset
(
ascbuf
,
0
,
sizeof
ascbuf
);
}
}
while
(
col
++
<
17
)
{
printf
(
" "
);
}
printf
(
"%s
\n
"
,
ascbuf
);
}
#endif
#endif
retval
=
libusb_bulk_transfer
(
handle
,
ENDPOINT_OUT
,
buf
.
u8
,
size
,
&
transferred
,
0
);
retval
=
libusb_bulk_transfer
(
handle
,
ENDPOINT_OUT
,
buf
.
u8
,
size
,
&
transferred
,
0
);
...
@@ -150,18 +166,8 @@ static int wait_response(libusb_device_handle *handle, int *size)
...
@@ -150,18 +166,8 @@ static int wait_response(libusb_device_handle *handle, int *size)
}
}
#ifdef DEBUG
#ifdef DEBUG
{
printf
(
"<<< received %d bytes
\n
"
,
*
size
);
int
i
;
pretty_print_buf
(
buf
.
u8
,
*
size
);
printf
(
"wait_response: size=%d
\n
"
,
*
size
);
printf
(
"buffer: "
);
for
(
i
=
0
;
i
<
*
size
;
i
++
)
printf
(
"0x%02x "
,
buf
.
u8
[
i
]);
putchar
(
'\''
);
for
(
i
=
0
;
i
<
*
size
;
i
++
)
putchar
(
isprint
(
buf
.
u8
[
i
])
?
buf
.
u8
[
i
]
:
'.'
);
printf
(
"'
\n
"
);
}
#endif
#endif
return
retval
;
return
retval
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment