Skip to content

Commit

Permalink
add HAL command "setexact_for_test_suite_only" which acts as though t…
Browse files Browse the repository at this point in the history
…he exact

requested base period was obtained.

Additional printf-format warning fixes
VS: ----------------------------------------------------------------------
  • Loading branch information
jepler committed Oct 6, 2006
1 parent 9c3c0b4 commit e62e512
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
7 changes: 6 additions & 1 deletion src/hal/hal_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1560,7 +1560,11 @@ int hal_create_thread(char *name, unsigned long period_nsec, int uses_fp)
"HAL_LIB: ERROR: clock period too long: %ld\n", curr_period);
return HAL_FAIL;
}
hal_data->base_period = curr_period;
if(hal_data->exact_base_period) {
hal_data->base_period = period_nsec;
} else {
hal_data->base_period = curr_period;
}
/* reserve the highest priority (maybe for a watchdog?) */
prev_priority = rtapi_prio_highest();
} else {
Expand Down Expand Up @@ -2478,6 +2482,7 @@ static int init_hal_data(void)
hal_data->constructor_prefix[0] = 0;
list_init_entry(&(hal_data->funct_entry_free));
hal_data->thread_free_ptr = 0;
hal_data->exact_base_period = 0;
/* set up for shmalloc_xx() */
hal_data->shmem_bot = sizeof(hal_data_t);
hal_data->shmem_top = HAL_SIZE;
Expand Down
4 changes: 3 additions & 1 deletion src/hal/hal_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ typedef struct {
int funct_free_ptr; /* list of free function structs */
hal_list_t funct_entry_free; /* list of free funct entry structs */
int thread_free_ptr; /* list of free thread structs */
int exact_base_period; /* if set, pretend that rtapi satisfied our
period request exactly */
unsigned char lock; /* hal locking, can be one of the HAL_LOCK_* types */
} hal_data_t;

Expand Down Expand Up @@ -299,7 +301,7 @@ typedef struct {
*/

#define HAL_KEY 0x48414C32 /* key used to open HAL shared memory */
#define HAL_VER 0x00000005 /* version code */
#define HAL_VER 0x00000006 /* version code */
#define HAL_SIZE 131000

/* These pointers are set by hal_init() to point to the shmem block
Expand Down
34 changes: 28 additions & 6 deletions src/hal/utils/halcmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ static char *data_arrow2(int dir);
static char *data_value(int type, void *valptr);
static char *data_value2(int type, void *valptr);
static int do_save_cmd(char *type, char *filename);
static int do_setexact_cmd(void);
static void save_comps(FILE *dst);
static void save_signals(FILE *dst);
static void save_links(FILE *dst, int arrows);
Expand Down Expand Up @@ -896,6 +897,8 @@ static int parse_cmd(char *tokens[])
/* print success message */
rtapi_print_msg(RTAPI_MSG_INFO, "Realtime threads stopped\n");
}
} else if (strcmp(tokens[0], "setexact_for_test_suite_only") == 0) {
retval = do_setexact_cmd();
} else {
rtapi_print_msg(RTAPI_MSG_ERR, "HAL:%d: Unknown command '%s'\n", linenumber, tokens[0]);
retval = -1;
Expand Down Expand Up @@ -2248,16 +2251,16 @@ static void print_funct_info(char *pattern)
if ( match(pattern, fptr->name) ) {
comp = SHMPTR(fptr->owner_ptr);
if (scriptmode == 0) {
rtapi_print(" %02d %08p %08p %s %3d %s\n",
rtapi_print(" %02d %08lx %08lx %s %3d %s\n",
comp->comp_id,
fptr->funct,
fptr->arg, (fptr->uses_fp ? "YES" : "NO "),
(long)fptr->funct,
(long)fptr->arg, (fptr->uses_fp ? "YES" : "NO "),
fptr->users, fptr->name);
} else {
rtapi_print("%s %08p %08p %s %3d %s\n",
rtapi_print("%s %08lx %08lx %s %3d %s\n",
comp->name,
fptr->funct,
fptr->arg, (fptr->uses_fp ? "YES" : "NO "),
(long)fptr->funct,
(long)fptr->arg, (fptr->uses_fp ? "YES" : "NO "),
fptr->users, fptr->name);
}
}
Expand Down Expand Up @@ -2918,6 +2921,25 @@ static void save_threads(FILE *dst)
rtapi_mutex_give(&(hal_data->mutex));
}

static int do_setexact_cmd() {
int retval = HAL_SUCCESS;
rtapi_mutex_get(&(hal_data->mutex));
if(hal_data->base_period) {
rtapi_print_msg(RTAPI_MSG_ERR,
"HAL_LIB: ERROR: Cannot run 'setexact'"
" after a thread has been created\n");
retval = HAL_FAIL;
} else {
rtapi_print_msg(RTAPI_MSG_INFO,
"HAL_LIB: HAL will pretend that the exact"
" base period requested is possible.\n"
"This mode is not suitable for running real hardware.");
hal_data->exact_base_period = 1;
}
rtapi_mutex_give(&(hal_data->mutex));
return retval;
}

static int do_help_cmd(char *command)
{

Expand Down

0 comments on commit e62e512

Please sign in to comment.