From da207f10d452dcba43c0c7cbfb8ab55fbe6c481d Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Thu, 18 Aug 2005 15:36:00 +0000 Subject: [PATCH] An attemt to make writing to ram working properly. It stil doesn't work :( darcs-hash:20050818153630-f2ef6-495e320d9cd5843cac7dd14b1e46f1d608d2e56c.gz --- arch/arm/mach-lpc2106/tools/tolpc/tolpc_fn.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/arch/arm/mach-lpc2106/tools/tolpc/tolpc_fn.c b/arch/arm/mach-lpc2106/tools/tolpc/tolpc_fn.c index d006844..892ecb2 100644 --- a/arch/arm/mach-lpc2106/tools/tolpc/tolpc_fn.c +++ b/arch/arm/mach-lpc2106/tools/tolpc/tolpc_fn.c @@ -21,8 +21,7 @@ int tolpc_debug_level = 0; -#define SENT_BUFFER_SIZE 1000 -char sent_buffer[SENT_BUFFER_SIZE]; //buffer for storing all sended data. Used for removing echoed characters from response +char sent_buffer[10000]; //buffer for storing all sended data. Used for removing echoed characters from response #ifdef WITHOUT_CFSETSPEED @@ -360,7 +359,7 @@ int tolpc_readline(struct tolpc_env *env, char *dest, int size) int ret; char *nl, *cr; - ret = tolpc_test_read(env, 0/*1000&MSEC*/); + ret = tolpc_test_read(env, 0); if (ret == 0 && tail == buffer) break; //timeout if (ret > 0) { @@ -379,7 +378,10 @@ int tolpc_readline(struct tolpc_env *env, char *dest, int size) nl = strchr(buffer, '\n'); cr = strchr(buffer, '\r'); - nl = MIN(nl, cr); + if (cr != NULL && nl != NULL) + nl = MIN(nl, cr); + if (cr != NULL && nl == NULL) + nl = cr; if (nl == NULL) continue; // wait for next part(s) of line to arrive *nl = '\0'; @@ -423,6 +425,7 @@ int tolpc_readline_to(struct tolpc_env *env, char *dest, int size) void get_sent_command(char *dest, size_t n) { char *cmd_end, *next_cmd; + int len; cmd_end = strchr(sent_buffer, '\n'); if (cmd_end == NULL) { @@ -435,7 +438,8 @@ void get_sent_command(char *dest, size_t n) dest[n - 1] = '\0'; // move the rest of the buffer at the beggning next_cmd = cmd_end+1; - memmove(sent_buffer, next_cmd, strlen(next_cmd)+1); + len = strlen(next_cmd)+1; // move also trailing \0 + memmove(sent_buffer, next_cmd, len); } /** @@ -446,7 +450,7 @@ void get_sent_command(char *dest, size_t n) int echoed_command(char *string) { char cmd[100]; - get_sent_command(cmd, 100); + get_sent_command(cmd, sizeof(cmd)); return strcmp(string, cmd); } @@ -507,7 +511,7 @@ static int tolpc_sendline_va(struct tolpc_env *env, const char *fmt, va_list ap) } // Store a sent line for removing it from response (due to echoing) - strncat(sent_buffer, line, SENT_BUFFER_SIZE - 1); + strncat(sent_buffer, line, sizeof(sent_buffer) - 1); return 0; } @@ -687,7 +691,7 @@ int tolpc_write_ram(struct tolpc_env *env, unsigned int start, int length, unsig unsigned char *block_beg; ret = tolpc_send_cmd(env, "W %u %d", start, length); - + if (ret) return ret; i = 0; lines = 0; checksum = 0; -- 2.11.4.GIT