示例#1
0
/* fatfsLs():
 * The incoming string is assumed to be some directory name.
 * If NULL, then it is assumed to be the CF's top-most level.
 */ 
static int
fatfsLs(char *dirname)
{
	int	ftot;
	DIRENT de;
	DIRINFO di;
	char *dir;

	if (dirname)
		dir = dirname;
	else
		dir = "";

	di.scratch = sector;
	if (DFS_OpenDir(&vi, (uint8_t *)dir, &di)) {
		printf("Can't open dir: <%s>\n",dirname);
		return(CMD_FAILURE);
	}

	ftot = 0;
	while (!DFS_GetNext(&vi, &di, &de)) {
		char tmp[32]; 

		if (de.name[0] && ((de.attr & ATTR_LONG_NAME) != ATTR_LONG_NAME)) {
			if ((de.attr & ATTR_VOLUME_ID) > 0) {
				de.name[8] = 0;
				printf("Volume:     %s\n",de.name);
				continue;
            }
			ftot++;

			printf("%02d/%02d/%4d  %02d:%02d   ",
				CREATE_MON(de), CREATE_DAY(de), CREATE_YEAR(de),
				CREATE_HR(de), CREATE_MIN(de));

			if ((de.attr & ATTR_DIRECTORY) > 0) {
				// truncate the extension
				de.name[8] = 0;

				printf("<DIR>            %-8s",de.name);
			}
			else {
				DFS_DirToCanonical((uint8_t *)tmp,de.name);
				printf("       %8d  %-12s",FILESIZE(de), tmp);
			}

			printf("  %c%c%c%c%c\n",
				(( de.attr & ATTR_VOLUME_ID) ? 'V' : ' '),
				(( de.attr & ATTR_READ_ONLY) ? 'R' : ' '),
				(( de.attr & ATTR_ARCHIVE  ) ? 'A' : ' '),
				(( de.attr & ATTR_SYSTEM   ) ? 'S' : ' '),
				(( de.attr & ATTR_HIDDEN   ) ? 'H' : ' '));
		}
	}
	shell_sprintf(FATFS_FTOT_STR,"%d",ftot);
	return(0);
}
示例#2
0
/* ShellVarInit();
 *	Setup the shell_vars pointer appropriately for additional
 *	shell variable assignments that will be made through shell_alloc().
 */
int
ShellVarInit()
{
	char	buf[16];

#if !INCLUDE_MALLOC
	memset((char *)&envSpace,0,sizeof(envSpace));
#endif

	shell_vars = (struct s_shell *)env_alloc(sizeof(struct s_shell));
	if (!shell_vars) {
		printf("No memory for environment initialization\n");
		return(-1);
	}
	shell_vars->next = (struct s_shell *)0;
	shell_vars->name = (char *)0;
	setenv("PROMPT",PROMPT);
	sprintf(buf,"0x%lx",APPLICATION_RAMSTART);
	setenv("APPRAMBASE",buf);
	sprintf(buf,"0x%lx",BOOTROM_BASE);
	setenv("BOOTROMBASE",buf);
	setenv("PLATFORM",PLATFORM_NAME);
	setenv("MONITORBUILT",monBuilt());
	shell_sprintf("MONCOMPTR","0x%lx",(ulong)&moncomptr);
#if INCLUDE_HWTMR
	shell_sprintf("TARGETTIMER","0x%x",target_timer);
	shell_sprintf("TICKSPERMSEC","0x%x",TIMER_TICKS_PER_MSEC);
#endif

	/* Support the ability to have additional target-specific 
	 * shell variables initialized at startup...
	 */
#ifdef TARGET_ENV_SETUP
	TARGET_ENV_SETUP();
#endif

	shell_sprintf("VERSION_MAJ","%d",MAJOR_VERSION);
	shell_sprintf("VERSION_MIN","%d",MINOR_VERSION);
	shell_sprintf("VERSION_TGT","%d",TARGET_VERSION);
	return(0);
}
示例#3
0
int
Sleep(int argc,char *argv[])
{
	int opt, calibrate, count, multiplier;

	multiplier = 1000;
	calibrate = 0;
	while ((opt=getopt(argc,argv,"clmv:")) != -1) {
		switch(opt) {
		case 'c':
			calibrate = 2;
			break;
		case 'l':
			calibrate = 1;
			break;
		case 'm':
			multiplier = 1;
			break;
		case 'v':
			shell_sprintf(optarg,"%d",LoopsPerMillisecond*1000);
			return(CMD_SUCCESS);
		default:
			return(CMD_PARAM_ERROR);
		}
	}

	/* If no args, just print the current LPS value and return... */
	if (argc == 1) {
#if INCLUDE_HWTMR
		printf("Hardware-based timer, LPS not applicable\n");
#else
		printf("Current LPS = %ld\n",LoopsPerMillisecond * 1000);
#endif
		return(CMD_SUCCESS);
	}

	/* For calibration, take in the count on the command line, then use
	 * it to put out 5 dots dot at the rate of the loop to allow the user
	 * to adjust it to be about 1 second.
	 */
	if (calibrate) {
#if INCLUDE_HWTMR
		printf("Hardware-based timer, doesn't calibrate\n");
#else
		long lps;

		if (argc != optind+1)
			return(CMD_PARAM_ERROR);

		printf("Current LPS: %ld\n",LoopsPerMillisecond * 1000);
		lps = strtol(argv[optind],0,0);
		LoopsPerMillisecond = lps/1000;
		printf("New LPS: %ld%s\n",LoopsPerMillisecond * 1000,
			lps % 1000 ? " (truncated by 1000)" : "");

		if (calibrate == 2) {
			count = 10;
			while(count-- > 0) {
				monDelay(1000);
				putstr(".\007");
			}
			putchar('\n');
		}
#endif
		return(CMD_SUCCESS);
	}

	if (argc == optind)
		count = 1;
	else
		count = strtol(argv[optind],(char **)0,0);

	monDelay(count * multiplier);
	return(CMD_SUCCESS);
}
示例#4
0
int
Set(int argc,char *argv[])
{
	char	*file, *envp, buf[CMDLINESIZE];
	int		opt, decimal, setop, i;

	setop = SET_NOOP;
	file = (char *)0;
	envp = (char *)0;
	decimal = 1;
	while((opt=getopt(argc,argv,"ab:cdef:iox")) != -1) {
		switch(opt) {
		case 'a':		/* logical and */
			setop = SET_AND;
			decimal = 0;
			break;
		case 'b':
			ChangeConsoleBaudrate(atoi(optarg));
			return(CMD_SUCCESS);
		case 'c':		/* clear environment */
			clearenv();
			break;
		case 'd':		/* decrement */
			setop = SET_DECR;
			break;
		case 'e':	
			envp = getenvp();
			break;
#if INCLUDE_TFS	
		case 'f':		/* build script from environment */
			envToExec(optarg);
			return(0);
#endif
		case 'i':		/* increment */
			setop = SET_INCR;
			break;
		case 'o':		/* logical or */
			setop = SET_OR;
			decimal = 0;
			break;
		case 'x':
			decimal = 0;
			break;
		default:
			return(CMD_PARAM_ERROR);
		}
	}

	if (!shell_vars) {
		printf("No memory allocated for environment.\n");
		return(CMD_FAILURE);
	}

	if (setop != SET_NOOP) {	/* Do some operation on a shell variable */
		char	*varval;
		unsigned long	value, opval;

		/* For -i & -d, if value is not specified, then assume 1. */
		if (argc == optind+1) {
			if ((setop == SET_INCR) || (setop == SET_DECR))
				opval = 1;
			else
				return(CMD_PARAM_ERROR);
		}
		else if (argc == optind+2)
			opval = strtoul(argv[optind+1],0,0);
		else
			return(CMD_PARAM_ERROR);

		varval = getenv(argv[optind]);
		if (!varval) {
			printf("%s: not found\n", argv[optind]);
			return(CMD_FAILURE);
		}
			
		value = strtoul(varval,(char **)0,0);
		switch(setop) {
			case SET_INCR:
				value += opval;
				break;
			case SET_DECR:
				value -= opval;
				break;
			case SET_AND:
				value &= opval;
				break;
			case SET_OR:
				value |= opval;
				break;
		}
		if (decimal)
			sprintf(buf,"%ld",value);
		else
			sprintf(buf,"0x%lx",value);
		setenv(argv[optind],buf);
	}
	else if (argc == optind) {	/* display all variables */
		shell_print();
	}
	else if (argc == (optind+1)) {	/* run EE or clear one var or set envp */
#if INCLUDE_EE
		switch(setEE(argv[optind])) {
			case 1:
				return(CMD_SUCCESS);
			case -1:
				return(CMD_FAILURE);
		}
#endif
		if (envp) 
			shell_sprintf(argv[optind],"0x%lx",(ulong)envp);
		else
			setenv(argv[optind],0);
	}
	else if (argc >= (optind+2)) {	/* Set a specific variable */
		buf[0] = 0;
		for(i=optind+1;i<argc;i++) {
			if ((strlen(buf) + strlen(argv[i]) + 2) >= sizeof(buf)) {
				printf("String too large\n");
				break;
			}
			strcat(buf,argv[i]);
			if (i != (argc-1))
				strcat(buf," ");
		}
		if (!decimal)
			shell_sprintf(argv[optind],"0x%lx",atoi(buf));
		else
			setenv(argv[optind],buf);
	}
	else 
		return(CMD_PARAM_ERROR);

	return(CMD_SUCCESS);
}
示例#5
0
static int
fatfsQry(char *fatfspath, int verbose)
{
	DIRENT de;
	DIRINFO di;
	char *lastslash, *fname, *dir, pathcopy[80], matchname[80];
	int flen, flen1, fsize, pathlen, match, ftot;

	if (!fatfspath)
		return(-1);

	/* Prior to each 'ls', clear the content of the name and
	 * size shell variables...
	 */
	setenv(FATFS_FNAME_STR,0);
	setenv(FATFS_FSIZE_STR,0);
	setenv(FATFS_FTOT_STR,0);

	pathlen = strlen(fatfspath);
	if (pathlen > sizeof(pathcopy)) {
		printf("path too big\n");
		return(-1);
	}
	strcpy(pathcopy, fatfspath);
	lastslash = strrchr(pathcopy,DIR_SEPARATOR);

	if (lastslash == 0) {
		dir = "";
		fname = pathcopy;
	}
	else {
		*lastslash = 0;
		dir = pathcopy;
		fname = lastslash+1;
	}

	flen = strlen(fname);
	if (verbose > 1)
		printf("Qry opening dir <%s>, fname <%s>...\n",dir,fname);

	di.scratch = sector;
	if (DFS_OpenDir(&vi, (uint8_t *)dir, &di)) {
		printf("error opening subdirectory\n");
		return(CMD_FAILURE);
	}

	match = fsize = ftot = flen1 = 0;
	while (!DFS_GetNext(&vi, &di, &de)) {
		int i;
		char dosname[16];

		memset(dosname,0,sizeof(dosname));
		if (de.name[0] && ((de.attr & ATTR_LONG_NAME) != ATTR_LONG_NAME)) {
			if ((de.attr & ATTR_VOLUME_ID) || (de.attr & ATTR_DIRECTORY)) {
				for(i=0;i<8;i++) {
					if (de.name[i] != ' ') {
						dosname[i] = de.name[i];
					}
					else {
						dosname[i] = 0;
						break;
					}
				}
				dosname[8] = 0;
			}
			else
				DFS_DirToCanonical((uint8_t *)dosname,de.name);
	
			flen1 = strlen(dosname);

			if ((fname[0] == '*') && (fname[flen-1] == '*')) {
				fname[flen-1] = 0;
				if (strstr(dosname,fname+1))
					match = 1;
				fname[flen-1] = '*';
			}
			else if (fname[0] == '*') {
				if (!strcmp(dosname+(flen1-flen+1),fname+1))
					match = 1;
			}
			else if (fname[flen-1] == '*') {
				fname[flen-1] = 0;
				if (!strncmp(dosname,fname,flen-1))
					match = 1;
				fname[flen-1] = '*';
			}
			else if (!strcmp(dosname,fname)) {
				match = 1;
			}
			if (match) {
				strcpy(matchname,dosname);
				fsize = FILESIZE(de);
				ftot++;
				match = 0;
				if (verbose)
					printf("  %s (%d)\n",dosname,fsize);
			}
		}
	}
	shell_sprintf(FATFS_FTOT_STR,"%d",ftot);
	if (ftot) {
		shell_sprintf(FATFS_FSIZE_STR,"%d",fsize);
		setenv(FATFS_FNAME_STR,matchname);
	}
	return(0);
}