#include <sys/stat.h>
#include <string.h>
+#include <errno.h>
+#include <getopt.h>
-#include <termios.h>
+#include <termios.h> /* for serial config */
#include <ctype.h>
-#include <errno.h>
-#include <getopt.h> /* for getopt */
+#include "isp_utils.h"
#define PROG_NAME "LPC11xx ISP"
#define VERSION "0.01"
#define SERIAL_BUFSIZE 128
-#define SYNCHRO_START '?'
+#define SYNCHRO_START "?"
#define SYNCHRO "Synchronized"
#define SERIAL_BAUD B115200
return 0;
}
-int serial_write(const char* buf, int buf_size)
+int serial_write(const char* buf, unsigned int buf_size)
{
int nb = 0;
if (trace_on) {
printf("Sending %d :\n", buf_size);
- /* FIXME : display data as in hexdump -C */
+ isp_dump((unsigned char*)buf, buf_size);
}
nb = write(serial_fd, buf, buf_size);
if (nb <= 0) {
return 0;
}
-int serial_read(char* buf, int buf_size)
+int serial_read(char* buf, unsigned int buf_size)
{
int nb = 0;
}
if (trace_on) {
printf("Received : %d octets\n", nb);
- /* FIXME : display data as in hexdump -C */
+ isp_dump((unsigned char*)buf, nb);
}
return nb;
}
char buf[SERIAL_BUFSIZE];
/* Send synchronize request */
- serial_write("?", 1);
+ serial_write(SYNCHRO_START, 1);
/* Wait for answer */
serial_read(buf, SERIAL_BUFSIZE);
#include <errno.h>
+/* display data as in hexdump -C :
+ 00000000 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 |.ELF............|
+ */
+void isp_dump(const unsigned char* buf, unsigned int buf_size)
+{
+ unsigned int count = 0;
+ char pass = 0;
+ while ((count < buf_size) || (pass == 0)) {
+ if (count == buf_size) {
+ while (count & 0x0F) {
+ printf(" ");
+ count++;
+ }
+ pass = 1;
+ count -= 0x10;
+ }
+ if ((count % 0x10) == 0) {
+ if (pass == 0) {
+ printf(" %08x ", count);
+ } else {
+ printf(" |");
+ }
+ }
+ if (pass == 0) {
+ printf("%02x ", buf[count]);
+ } else {
+ if (isgraph((int)buf[count])) {
+ printf("%c", buf[count]);
+ } else {
+ printf(".");
+ }
+ }
+ count++;
+ if ((count % 0x10) == 0) {
+ if (pass == 0) {
+ count -= 0x10;
+ } else {
+ printf("|\n");
+ }
+ pass = !pass;
+ }
+ }
+ printf("|\n");
+}
+
+
/* FIXME : This is a place-holder forr uuencode and uudecode functions !!! */
int uu_encode(unsigned char* dest, unsigned char* src, int orig_size)
{