📄 usrlib.c
字号:
for (i = 0; help_msg [i] != NULL; i++) { if ((i+1) % 20 == 0) { printf ("\nType <CR> to continue, Q<CR> to stop: "); fioRdString (STD_IN, &ch, 1); if (ch == 'q' || ch == 'Q') break; else printf ("\n"); } printf ("%s\n", help_msg [i]); } printf ("\n"); }/********************************************************************************* bootChange - change the boot line** This command changes the boot line used in the boot ROMs. This is useful* during a remote login session. After changing the boot parameters, you* can reboot the target with the reboot() command, and then terminate your* login ( ~. ) and remotely log in again. As soon as the system has* rebooted, you will be logged in again.** This command stores the new boot line in non-volatile RAM, if the target* has it.** RETURNS: N/A** SEE ALSO:* windsh,* .tG "Shell"*/void bootChange (void) { bootParamsPrompt (sysBootLine); (void)sysNvRamSet (sysBootLine, strlen (sysBootLine) + 1, 0); }/********************************************************************************* periodRun - call a function periodically** This command repeatedly calls a specified function, with up to eight of its* arguments, delaying the specified number of seconds between calls.** Normally, this routine is called only by period(), which spawns* it as a task.** RETURNS: N/A** SEE ALSO: period(),* .pG "Target Shell"*/void periodRun ( int secs, /* no. of seconds to delay between calls */ FUNCPTR func, /* function to call repeatedly */ int arg1, /* first of eight args to pass to func */ int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8 ) {#if ((CPU_FAMILY == ARM) && ARM_THUMB) func = (FUNCPTR)((UINT32)func | 1); /* force Thumb state */#endif FOREVER { (* func) (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); taskDelay (secs * sysClkRateGet ()); } }/********************************************************************************* period - spawn a task to call a function periodically** This command spawns a task that repeatedly calls a specified function,* with up to eight of its arguments, delaying the specified number of* seconds between calls.** For example, to have i() display task information every 5 seconds,* just type:* .CS* -> period 5, i* .CE* NOTE* The task is spawned using the sp() routine. See the description* of sp() for details about priority, options, stack size, and task ID.** RETURNS: A task ID, or ERROR if the task cannot be spawned.** SEE ALSO: periodRun(), sp(),* .pG "Target Shell,"* windsh,* .tG "Shell"*/int period ( int secs, /* period in seconds */ FUNCPTR func, /* function to call repeatedly */ int arg1, /* first of eight args to pass to func */ int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8 ) { return (sp ((FUNCPTR)periodRun, secs, (int)func, arg1, arg2, arg3, arg4, arg5, arg6, arg7)); }/********************************************************************************* repeatRun - call a function repeatedly** This command calls a specified function <n> times, with up to eight of its* arguments. If <n> is 0, the routine is called endlessly.** Normally, this routine is called only by repeat(), which spawns it as a* task.** RETURNS: N/A** SEE ALSO: repeat(),* .pG "Target Shell"*/void repeatRun ( FAST int n, /* no. of times to call func (0=forever) */ FAST FUNCPTR func, /* function to call repeatedly */ int arg1, /* first of eight args to pass to func */ int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8 ) { FAST BOOL infinite = (n == 0);#if ((CPU_FAMILY == ARM) && ARM_THUMB) func = (FUNCPTR)((UINT32)func | 1); /* force Thumb state */#endif while (infinite || (--n >= 0)) (* func) (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); }/********************************************************************************* repeat - spawn a task to call a function repeatedly** This command spawns a task that calls a specified function <n> times, with* up to eight of its arguments. If <n> is 0, the routine is called* endlessly, or until the spawned task is deleted.** NOTE* The task is spawned using sp(). See the description of sp() for details* about priority, options, stack size, and task ID.** RETURNS: A task ID, or ERROR if the task cannot be spawned.** SEE ALSO: repeatRun(), sp(),* .pG "Target Shell,"* windsh,* .tG "Shell"*/int repeat ( FAST int n, /* no. of times to call func (0=forever) */ FAST FUNCPTR func, /* function to call repeatedly */ int arg1, /* first of eight args to pass to func */ int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8 ) { return (sp ((FUNCPTR)repeatRun, n, (int)func, arg1, arg2, arg3, arg4, arg5, arg6, arg7)); }/********************************************************************************* sp - spawn a task with default parameters** This command spawns a specified function as a task with the following* defaults:* .IP "priority:" 15* 100* .IP "stack size:"* 20,000 bytes* .IP "task ID:"* highest not currently used* .IP "task options:"* VX_FP_TASK - execute with floating-point coprocessor support.* .IP "task name:"* A name of the form `tN' where N is an integer which increments as new tasks* are spawned, e.g., `t1', `t2', `t3', etc.* .LP* * The task ID is displayed after the task is spawned.** This command is a short form of the underlying taskSpawn() routine,* convenient for spawning tasks in which the default parameters* are satisfactory. If the default parameters are unacceptable, taskSpawn()* should be called directly.** RETURNS: A task ID, or ERROR if the task cannot be spawned.** SEE ALSO: taskLib, taskSpawn(),* .pG "Target Shell,"* windsh,* .tG "Shell"** VARARGS1*/int sp ( FUNCPTR func, /* function to call */ int arg1, /* first of nine args to pass to spawned task */ int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9 ) { int id; if (func == (FUNCPTR)0) { printf ("sorry, won't spawn task at PC = 0.\n"); return (ERROR); } /* spawn task, let taskSpawn pick the task ID, report success or failure */ id = taskSpawn ((char *) NULL, spTaskPriority, spTaskOptions, spTaskStackSize, func, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, 0); if (id == ERROR) { printf ("not able to spawn task.\n"); return (ERROR); } else { printf ("task spawned: id = %#x, name = %s\n", id, taskName (id)); return (id); } }/******************************************************************************** taskIdFigure - translate a task name or ID to a task ID** Many routines in usrLib take a task ID (an integer) or a task name. This* routine determines whether the parameter is a task name or a task ID and* returns the task ID. If <taskNameOrId> is omitted or 0, the current task* is used.** RETURNS: A task ID (an integer), or ERROR.** SEE ALSO: taskNameToId(), taskLib** NOMANUAL*/int taskIdFigure ( int taskNameOrId /* task name or task ID */ ) { char name [10]; /* number to name */ int tid; /* task ID */ int bb; /* bit bucket */ if (taskNameOrId == 0) /* default task ID */ return (taskIdDefault (0)); else if (taskIdVerify (taskNameOrId) == OK) /* try explicit ID */ return (taskNameOrId); sprintf (name, "%x", taskNameOrId); if ((tid = taskNameToId (name)) != ERROR) return (tid); /* name is a number */ else if (vxMemProbe ((char *)taskNameOrId, O_RDONLY, 4, (char *)&bb) == OK) return (taskNameToId ((char *) taskNameOrId)); /* name is a string */ else return (ERROR); /* unreasonable name, bus error! */ }/********************************************************************************* checkStack - print a summary of each task's stack usage** This command displays a summary of stack usage for a specified task, or* for all tasks if no argument is given. The summary includes the total* stack size (SIZE), the current number of stack bytes used (CUR), the* maximum number of stack bytes used (HIGH), and the number of bytes never* used at the top of the stack (MARGIN = SIZE - HIGH).* For example:* .CS* -> checkStack tShell** NAME ENTRY TID SIZE CUR HIGH MARGIN* ------------ ------------ -------- ----- ----- ----- ------* tShell _shell 23e1c78 9208 832 3632 5576* .CE** The maximum stack usage is determined by scanning down from the top of the* stack for the first byte whose value is not 0xee. In VxWorks, when a task* is spawned, all bytes of a task's stack are initialized to 0xee.** DEFICIENCIES* It is possible for a task to write beyond the end of its stack, but* not write into the last part of its stack. This will not be detected* by checkStack().** RETURNS: N/A** SEE ALSO: taskSpawn(),* .pG "Target Shell,"* windsh,* .tG "Shell"*/void checkStack ( int taskNameOrId /* task name or task ID; 0 = summarize all */ ) { FAST int nTasks; /* number of task */ FAST int ix; /* index */ FAST char *pIntStackHigh; /* high interrupt stack usage */ int tid; /* task ID */ TASK_DESC td; /* task info structure */ int idList [MAX_DSP_TASKS]; /* list of active IDs */ static char checkStackHdr [] = "\ NAME ENTRY TID SIZE CUR HIGH MARGIN\n\------------ ------------ -------- ----- ----- ----- ------\n";#if (CPU_FAMILY == ARM) char *intStackBase; char *intStackEnd;#else /* (CPU_FAMILY == ARM) */# if (CPU != MC68060) /* we dont currently use this for MC68060 */ IMPORT char *vxIntStackBase;# endif /* CPU != MC68060 */ IMPORT char *vxIntStackEnd;# if (CPU != MC68060) /* we dont currently use this for MC68060 */ char *intStackBase = vxIntStackBase;# endif /* CPU != MC68060 */ char *intStackEnd = vxIntStackEnd;#endif /* CPU_FAMILY == ARM */ if (taskNameOrId != 0) { /* do specified task */ tid = taskIdFigure (taskNameOrId); if ((tid == ERROR) || (taskInfoGet (tid, &td) != OK)) printErr ("Task not found.\n"); else { printf (checkStackHdr); printStackSummary (&td); } } else { /* do all tasks */ printf (checkStackHdr); nTasks = taskIdListGet (idList, NELEMENTS (idList)); taskIdListSort (idList, nTasks); for (ix = 0; ix < nTasks; ++ix) if (taskInfoGet (idList [ix], &td) == OK) printStackSummary (&td); /* find int stack high usage */#if (CPU_FAMILY != AM29XXX) && (CPU_FAMILY != ARM)#if (_STACK_DIR == _STACK_GROWS_DOWN) for (pIntStackHigh = intStackEnd; * (UINT8 *)pIntStackHigh == 0xee; pIntStackHigh ++) ;#else /* _STACK_DIR == _STACK_GROWS_DOWN) */ for (pIntStackHigh = intStackEnd - 1; * (UINT8 *)pIntStackHigh == 0xee;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -