📄 usrlib.c
字号:
* 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==ARM7TDMI_T) 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==ARM7TDMI_T) 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; pIntStackHigh --) ;#endif /* _STACK_DIR == _STACK_GROWS_DOWN) */#if (CPU != MC68060) printf ("%-12.12s %-12.12s", "INTERRUPT", ""); printf (" %8s %5d %5d %5d %6d %s\n", "", /* task name */ (int)((intStackEnd - intStackBase) *_STACK_DIR), /* stack size */ 0, /* current */ (int)((pIntStackHigh - intStackBase) *_STACK_DIR), /* high stack usage */ (int)((intStackEnd - pIntStackHigh) * _STACK_DIR), /* margin */ (pIntStackHigh == intStackEnd) && /* overflow ? */ (intStackEnd != intStackBase != 0) ? /* no interrupt stack ? */ "OVERFLOW" : "");#endif #else#if CPU_FAMILY == AM29XXX /* * Since the Am29k family uses 3 interrupt stacks (Exception Stack * Frame, handler register stack and memory stack), we must compute * each stack usage inside the global stack area allocated at each * interrupt. The ESF takes 1/5 of the global area, the register stack * takes also 1/5 of the global area, and the memory stack takes the * remainder (3/5). See kernelInit(). */ for (pIntStackHigh = vxRegIntStackBase; * (UINT8 *)pIntStackHigh == 0xee; pIntStackHigh ++); printf ("%-12.12s %-12.12s", "INTERRUPT", ""); printf (" %8s %5d %5d %5d %6d %s\n", "", /* task name */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -