Пример #1
0
/* pollConsole():
 * Common function used to query the console port with a message.
 * If after about a 2-second period (or the time specified by POLLTIMEOUT),
 * there is no response from the console, then return 0; else return
 * the character that was received.
 */
int
pollConsole(char *msg)
{
	char	*env;
	int		pollval, msec;
	struct elapsed_tmr tmr;

	env = getenv("POLLTIMEOUT");
	if (env)
		msec = strtol(env,0,0);
	else
		msec = 2000;

	pollval = 0;
	printf("%s",msg);
	startElapsedTimer(&tmr,msec);
	while(!msecElapsed(&tmr)) {
		if (gotachar()) {
			while(gotachar())
				pollval = getchar();
			break;
		}
		pollethernet();
	}
	putstr("\r\n");
	
	if (ELAPSED_TIMEOUT(&tmr))
		return(0);

	return(pollval);
}
Пример #2
0
int
getbytes_t(char *buf,int cnt,int timeout)
{
	int	i;
	struct elapsed_tmr tmr;
	volatile char *bp;
	char c;

	bp = (volatile char *)buf;

	for(i=0;i<cnt;i++) {
		if (!gotachar()) {
			startElapsedTimer(&tmr,timeout);
			while(!gotachar() && !msecElapsed(&tmr));
			if (!gotachar())
				break;
		}
		c = (char)getchar();
		*bp = c;
		if (*bp != c)
			break;
		bp++;
	}
	return(i);
}
Пример #3
0
int
getbytes(char *buf,int cnt,int block)
{
	int	i;
	volatile char *bp;
	char c;

	bp = (volatile char *)buf;

	for(i=0;i<cnt;i++) {
		if (!block && !gotachar())
			break;
		c = (char)getchar();
		*bp = c;
		if (*bp != c)
			break;
		bp++;
	}
	return(i);
}
Пример #4
0
int
Bootp(int argc,char *argv[])
{
	if (!enetInitialized())
		return(CMD_FAILURE);

	startElapsedTimer(&dhcpTmr,RetransmitDelay(DELAY_INIT_DHCP)*1000);

	DHCPState = BOOTPSTATE_INITIALIZE;
	BOOTPStartup(0);

	while(DHCPState != BOOTPSTATE_COMPLETE) {
		pollethernet();
		if (gotachar()) {
			DHCPState = BOOTPSTATE_COMPLETE;
			break;
		}
	}
	return(CMD_SUCCESS);
}
Пример #5
0
int 
getchar(void)
{
	/* If the remotegetchar function pointer is non-zero, then we
	 * assume that the default getchar function has been overridden
	 * by some overlaying application using mon_com(CHARFUNC_GETCHAR,),
	 * so we use that redefined function instead...
	 */
    if (remotegetchar)
        return(remotegetchar());
    
	while(!gotachar()) {
		/* While waiting for an incoming character, call pollethernet()
		 * to process any incoming packets.  Note that if INCLUDE_ETHERNET
		 * is 0 in config.h, then this function is NULL (see ether.h).
		 */
		WATCHDOG_MACRO;
    	pollethernet();
	}

	return(target_getchar());
}
Пример #6
0
int sed_tst(int argc,char *argv[])
{
	volatile ushort wr16, rd16, temp16;
	int i, x, opt;
	int no_wait = 0;
	int init_only = 0;
	char c;

	sed135x_tst = 1;
	sed135x_off();

    while ((opt=getopt(argc,argv,"clnsid:")) != -1) {
        switch(opt) {
	        case 'l':   // Override sed_disp_mode_crt, Run Test in LCD Mode
				sed_disp_mode_crt = 0;
				printf("Forcing LCD Mode!\n");
			break;
	        case 'c':   // Override sed_disp_mode_crt, Run Test in CRT Mode
				sed_disp_mode_crt = 1;
				printf("Forcing CRT Mode!\n");
			break;
			case 'd':	// set the color depth
                switch(*optarg) {
            	    case '4':
	        	        sed_color_depth = 4;
						printf("Forcing 4bpp Mode!\n");
        	            break;
    	            case '8':
            	        sed_color_depth = 8;
						printf("Forcing 8bpp Mode!\n");
                    	break;
    	            case '1':
	                    sed_color_depth = 16;
						printf("Forcing 16bpp Mode!\n");
        	            break;
	                default:	// test with current depth
						break;
                }
	            break;
	        case 'n':   // no waiting for keypress - fastest operation
				no_wait = 1;
				printf("No Keypress Mode, Must Reset System to Stop!\n");
				break;
	        case 'i':   // init only 
				no_wait = 1;
				printf("Initializing SED, Skipping tests!\n");
				init_only = 1;
				break;
	        case 's':   // Scope loop
				no_wait = 1;
				printf("Scope Loop, press any key to Stop!\n");
				while(1){
					SED1356_REG_REV_and_MISC = 0;
					temp16 = SED1356_REG_REV_and_MISC;
					if (gotachar()) break;
				}
				break;
			default:	// test with current mode
				break;
		}
	}
	sed135x_init();
	if (sed135x_ok == 0) return -1;

	sed135x_on();

	if (init_only)
	{
		sed135x_tst = 0;
		return 0;
	}

	printf("Frame Buffer R/W...");
	// do an address=data read/write test on the frame buffer
	// PIXELS_PER_COL * PIXELS_PER_ROW is the highest pixel.  
	// Multiply by bits_per_pixel (sed_color_depth), then
	// divide by 8 to get the actual byte count.
	for (i = 0; i < SED_FB_SIZE(sed_color_depth); i += 4){	
		WR_FB16(i, (i & 0xffff));
		RD_FB16(i, rd16);
		if(rd16 != (i & 0xffff)){
			printf("Fail at 0x%08lx, WR 0x%08x, RD 0x%04x!\n",
				(long)(SED_MEM_BASE + i), i, rd16);
//			return -1;
		}
	} 

	printf("OK!\n");

	printf("Frame Buffer Start: 0x%08lx, End 0x%08lx\n",(long)SED_MEM_BASE,
		(long)(SED_MEM_BASE + SED_FB_SIZE(sed_color_depth)));
	if (no_wait)
	{
		printf("Begin Full Screen Color Test.\n");
		while(1){
			// fill the frame buffer with incrementing color values
			for (x = 0; x < 16; x++){
				switch (sed_color_depth){
					case 4:  wr16 = x | x << 4 | x << 8 | x << 12; break;
					case 8:  wr16 = x | x << 8; break;
					default: wr16 = vga_lookup[x]; break;	// 16-bits bypasses the lookup table
				}
				for (i = 0; i < SED_FB_SIZE(sed_color_depth); i += 2){	
					WR_FB16(i, wr16);
				}
			} // for x
		} // while
	} // no_wait
	else
	{
		printf("Begin Full Screen Color Test, Press any key to go to next color, \'x\' to end.\n");
		while(1){
			// fill the frame buffer with incrementing color values
			for (x = 0; x < 16; x++){
				switch (sed_color_depth){
					case 4:  wr16 = x | x << 4 | x << 8 | x << 12; break;
					case 8:  wr16 = x | x << 8; break;
					default: wr16 = vga_lookup[x]; break;	// 16-bits bypasses the lookup table
				}
				for (i = 0; i < SED_FB_SIZE(sed_color_depth); i += 2){	
					WR_FB16(i, wr16);
				}
				if (no_wait == 0){
					c = getchar();
					if (c == 'x') goto sed_tst_next;
				}
			} // for x
		} // while
	} // else no keycheck test

	sed_tst_next:

	sed135x_off();
	sed135x_init();
	sed135x_on();
	return 0;
}
Пример #7
0
int
If(int argc, char *argv[])
{
	int		opt, arg, true, if_else, offset, verbose;
	void	(*iffunc)(char *), (*elsefunc)(char *);
	long	var1, var2;
	char	*testtype, *arg1, *arg2, *iftag, *elsetag;

	verbose = 0;
	testtype = 0;
	while((opt=getopt(argc,argv,"vt:")) != -1) {
		switch(opt) {
		case 'v':
			verbose = 1;
			break;
		case 't':
			testtype = optarg;
			break;
		default:
			return(CMD_PARAM_ERROR);
		}
	}

	elsetag = 0;
	elsefunc = 0;
	offset = true = if_else = 0;

	/* First see if there is an 'else' present... */
	for (arg=optind;arg<argc;arg++) {
		if (!strcmp(argv[arg],"else")) {
			if_else = 1;
			break;
		}
	}

	if (if_else) {
		elsetag = argv[argc-1];
		if (!strcmp(argv[argc-1],"exit")) {
			offset = 2;
			elsefunc = exitscript;
		}
		else if (!strcmp(argv[argc-1],"return")) {
			offset = 2;
			elsefunc = gosubret;
		}
		else if (!strcmp(argv[argc-2],"goto")) {
			offset = 3;
			elsefunc = gototag;
		}
		else if (!strcmp(argv[argc-2],"gosub")) {
			offset = 3;
			elsefunc = gosubtag;
		}
		else
			return(CMD_PARAM_ERROR);
	}
	
	iftag = argv[argc-offset-1];
	if (!strcmp(argv[argc-offset-1],"exit"))
		iffunc = exitscript;
	else if (!strcmp(argv[argc-offset-1],"return"))
		iffunc = gosubret;
	else if (!strcmp(argv[argc-offset-2],"goto"))
		iffunc = gototag;
	else if (!strcmp(argv[argc-offset-2],"gosub"))
		iffunc = gosubtag;
	else
		return(CMD_PARAM_ERROR);

	if (testtype) {
		if (!strcmp(testtype,"gc")) {
			if (gotachar())
				true=1;
		}
		else if (!strcmp(testtype,"ngc")) {
			if (!gotachar())
				true=1;
		}
		else
			return(CMD_PARAM_ERROR);
	}
	else {
		arg1 = argv[optind];
		testtype = argv[optind+1];
		arg2 = argv[optind+2];

		var1 = strtoul(arg1,(char **)0,0);
		var2 = strtoul(arg2,(char **)0,0);

		if (!strcmp(testtype,"gt")) {
			if (var1 > var2)
				true = 1;
		}
		else if (!strcmp(testtype,"lt")) {
			if (var1 < var2)
				true = 1;
		}
		else if (!strcmp(testtype,"le")) {
			if (var1 <= var2)
				true = 1;
		}
		else if (!strcmp(testtype,"ge")) {
			if (var1 >= var2)
				true = 1;
		}
		else if (!strcmp(testtype,"eq")) {
			if (var1 == var2)
				true = 1;
		}
		else if (!strcmp(testtype,"ne")) {
			if (var1 != var2)
				true = 1;
		}
		else if (!strcmp(testtype,"and")) {
			if (var1 & var2)
				true = 1;
		}
		else if (!strcmp(testtype,"xor")) {
			if (var1 ^ var2)
				true = 1;
		}
		else if (!strcmp(testtype,"or")) {
			if (var1 | var2)
				true = 1;
		}
		else if (!strcmp(testtype,"sec")) {
			if (!strcasecmp(arg1,arg2))
				true = 1;
		}
		else if (!strcmp(testtype,"seq")) {
			if (!strcmp(arg1,arg2))
				true = 1;
		}
		else if (!strcmp(testtype,"sin")) {
			if (strstr(arg2,arg1))
				true = 1;
		}
		else if (!strcmp(testtype,"sne")) {
			if (strcmp(arg1,arg2))
				true = 1;
		}
		else
			return(CMD_PARAM_ERROR);
	}
	
	/* If the true flag is set, call the 'if' function.
	 * If the true flag is clear, and "else" was found on the command
	 * line, then call the 'else' function...
	 */
	if (true) {
		if (verbose)
			printf("TRUE\n");
		iffunc(iftag);
	}
	else {
		if (verbose)
			printf("FALSE\n");
		if (if_else)
			elsefunc(elsetag);
	}

	return(CMD_SUCCESS);
}
Пример #8
0
/* getfullline():
 * Basic line retrieval; but with a few options...
 * This function is accessed through the getline_xx functions
 * below.
 * Args...
 *	buf:	 pointer to buffer to be used to place the incoming characters.
 *  max:	 size of the buffer.
 *  ledit:	 if set, then allow the line-editor to be used if ESC is input.
 *  timeout: if positive, then after 'timeout' number of seconds waiting
 *                per character, giveup.
 *           if negative, then after 'timeout' number of seconds waiting
 *                total, giveup.
 *           if zero, then wait forever.
 *  prefill: if set, prefill the buffer with that string and show the user.
 *  echo:    if set, characters are echoed as they are entered.
 */
int
getfullline(char *buf,int max,int ledit, int timeout,char *prefill, int echo)
{
	char	*base;
	struct	elapsed_tmr tmr;
	static	unsigned char  crlf;
	int		tot, idx, cumulativetimeout;

	cumulativetimeout = 0;
	tot = idx = 0;
	base = buf;
	max -= 1;		/* Make sure there is space for the null terminator. */

	if (prefill) {
		strcpy(base,prefill);
		tot = strlen(prefill);
		putstr(prefill);
		buf += tot;
		idx = tot;
	}

	/* If the timeout parameter is negative, then assume that this is
	 * to be run with a cumulative timeout rather than a timeout that
	 * is re-started after each character...
	 */
	if (timeout < 0) { 
		cumulativetimeout = 1;
		timeout = abs(timeout);
	}

	for(;idx<max;idx++) {
		if (timeout > 0) {
			startElapsedTimer(&tmr,timeout);
			while(!msecElapsed(&tmr)) {
				if (gotachar())
					break;
				pollethernet();
			}
			if (cumulativetimeout)
				timeout = msecRemaining(&tmr);

			if (ELAPSED_TIMEOUT(&tmr)) {
				*buf = 0;
				return(-1);	/* Return negative to indicate timeout */
			}
		}
		if (cumulativetimeout && timeout == 0) {
			*buf = 0;
			return(-1);
		}

		*buf = (char)getchar();
		if (!*buf) {
			idx--;
			continue;
		}
#if INCLUDE_LINEEDIT
		if ((*buf == 0x1b) && (ledit)) {
			(void)line_edit(base);
			break;
		}
		else
#endif
		{
			if ((*buf == '\r') || (*buf == '\n')) {
				if ((crlf) && (*buf != crlf)) {
					crlf = 0;
					continue;
				}
				#if UMON_TARGET == UMON_TARGET_XT || UMON_TARGET == UMON_TARGET_ARM	// use CR/LF
				puts("\r");
				#else
				putchar('\n');
				#endif
				crlf = *buf;
				*buf = 0;
				break;
			}
			if (*buf == '\b') {
				if (tot) {
					idx -= 2;
					buf--; 
					tot--;
					if (echo)
						putstr("\b \b");
				}
			}
			else if (*buf == CTLC) {
				puts("^C");
				*base = 0;
				return(0);
			}
			else {
				if (echo)
					putchar(*buf);
				tot++; 
				buf++;
			}
			crlf = 0;
		}
	}
	if (idx == max) {
		printf((char *)"\007\nInput too long (exceeds %d bytes).\n",max);
		*buf = 0;
		return(0);
	}
#if INCLUDE_LINEEDIT
	if (ledit)
		historylog(base);
#endif
	return(strlen(base));
}
Пример #9
0
/* flush_console_in(void):
 * While there is input queued up from the console, 
 * flush it to the bit bucket...
 */
void
flush_console_in(void)
{
	while(gotachar())
		getchar();
}