added busy sleep (for testing purposes)

git-svn-id: svn://svn.berlios.de/openocd/trunk@1033 b42882b7-edfa-0310-969c-e2dbd0fdcd60
This commit is contained in:
oharboe 2008-10-09 08:08:29 +00:00
parent a5806d21d2
commit d798871a99
3 changed files with 93 additions and 63 deletions

View File

@ -669,7 +669,7 @@ command_context_t* command_init()
}
register_command(context, NULL, "sleep", handle_sleep_command,
COMMAND_ANY, "sleep for <n> milliseconds");
COMMAND_ANY, "<n> [busy] - sleep for n milliseconds. \"busy\" means busy wait");
register_command(context, NULL, "fast", handle_fast_command,
COMMAND_ANY, "fast <enable/disable> - place at beginning of config files. Sets defaults to fast and dangerous.");
@ -692,10 +692,28 @@ int command_context_mode(command_context_t *cmd_ctx, enum command_mode mode)
int handle_sleep_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{
unsigned long duration = 0;
int busy = 0;
if (argc==1)
{
} else if (argc==2)
{
if (strcmp(args[1], "busy")!=0)
return ERROR_COMMAND_SYNTAX_ERROR;
busy = 1;
} else
{
return ERROR_COMMAND_SYNTAX_ERROR;
}
duration = strtoul(args[0], NULL, 0);
if (busy)
{
busy_sleep(duration);
} else
{
alive_sleep(duration);
}

View File

@ -412,3 +412,14 @@ void alive_sleep(int ms)
keep_alive();
}
}
void busy_sleep(int ms)
{
long long then;
then=timeval_ms();
while ((timeval_ms()-then)<ms)
{
/* busy wait */
}
}

View File

@ -65,6 +65,7 @@ extern int set_log_output(struct command_context_s *cmd_ctx, FILE *output);
extern void keep_alive(void);
extern void kept_alive(void);
extern void alive_sleep(int ms);
extern void busy_sleep(int ms);
typedef void (*log_callback_fn)(void *priv, const char *file, int line,
const char *function, const char *string);