Exemplo n.º 1
0
void console_put_hex(int number)
{
    console_put_char(' '); 
    console_put_char('0'); 
    console_put_char('x'); 
    console_put_char(hex_chars[(number & 0xF0000000) >> 28]); 
    console_put_char(hex_chars[(number & 0x0F000000) >> 24]); 
    console_put_char(hex_chars[(number & 0x00F00000) >> 20]); 
    console_put_char(hex_chars[(number & 0x000F0000) >> 16]); 
    console_put_char(hex_chars[(number & 0x0000F000) >> 12]); 
    console_put_char(hex_chars[(number & 0x00000F00) >> 8]); 
    console_put_char(hex_chars[(number & 0x000000F0) >> 4]); 
    console_put_char(hex_chars[(number & 0x0000000F)]); 
    console_put_char(' '); 
}
Exemplo n.º 2
0
Arquivo: console.c Projeto: wugsh/wgs
/**
*  Reads an hexadecimal number
*
*  \param pvalue  Pointer to the uint32_t variable to contain the input value.
*/
extern uint32_t console_get_hexa_32(uint32_t * pvalue)
{
	uint8_t key;
	uint32_t dw = 0;
	uint32_t value = 0;

	for (dw = 0; dw < 8; dw++) {
		key = console_get_char();
		console_put_char(key);

		if (key >= '0' && key <= '9') {
			value = (value * 16) + (key - '0');
		} else {
			if (key >= 'A' && key <= 'F') {
				value = (value * 16) + (key - 'A' + 10);
			} else {
				if (key >= 'a' && key <= 'f') {
					value = (value * 16) + (key - 'a' + 10);
				} else {
					printf
					    ("\n\rIt is not a hexa character!\n\r");
					return 0;
				}
			}
		}
	}
	printf("\n\r");
	*pvalue = value;
	return 1;
}
Exemplo n.º 3
0
Arquivo: console.c Projeto: wugsh/wgs
/**
*  Reads an integer
*
*  \param pvalue  Pointer to the uint32_t variable to contain the input value.
*/
extern uint32_t console_get_integer(uint32_t * pvalue)
{
	uint8_t key;
	uint8_t nb = 0;
	uint32_t value = 0;

	while (1) {
		key = console_get_char();
		console_put_char(key);

		if (key >= '0' && key <= '9') {
			value = (value * 10) + (key - '0');
			nb++;
		} else {
			if (key == 0x0D || key == ' ') {
				if (nb == 0) {
					printf
					    ("\n\rWrite a number and press ENTER or SPACE!\n\r");
					return 0;
				} else {
					printf("\n\r");
					*pvalue = value;
					return 1;
				}
			} else {
				printf("\n\r'%c' not a number!\n\r", key);
				return 0;
			}
		}
	}
}
Exemplo n.º 4
0
void console_put_string(const char *s) 
{
#if defined BUILD_X86_FD_TARGET || defined BUILD_I386_FD_TARGET 
    Current_Row = 12; 
    Current_Col = 20; 
#endif
    while(*s != '\0') 
    { 
        console_put_char(*s); 
        s++; 
    }
#ifdef BUILD_ARM_BB
    if (*(s-1) == '\n')
    {
        console_put_char('\r'); 
    }
#endif
}
Exemplo n.º 5
0
/* 在线程中运行的函数 */
void k_thread_b(void* arg) {     
   void* addr1 = sys_malloc(256);
   void* addr2 = sys_malloc(255);
   void* addr3 = sys_malloc(254);
   console_put_str(" thread_b malloc addr:0x");
   console_put_int((int)addr1);
   console_put_char(',');
   console_put_int((int)addr2);
   console_put_char(',');
   console_put_int((int)addr3);
   console_put_char('\n');

   int cpu_delay = 100000;
   while(cpu_delay-- > 0);
   sys_free(addr1);
   sys_free(addr2);
   sys_free(addr3);
   while(1);
}
Exemplo n.º 6
0
Arquivo: console.c Projeto: wugsh/wgs
/**
*  Displays the content of the given buffer on the DBGU.
*
*  \param pbuffer  Pointer to the buffer to dump.
*  \param size     Buffer size in bytes.
*  \param address  Start address to display
*/
void console_dump_memory(uint8_t * pbuffer, uint32_t size,
				uint32_t address)
{
	uint32_t i, j;
	uint32_t last_line_start;
	uint8_t *tmp;

	for (i = 0; i < (size / 16); i++) {
		printf("0x%08X: ", (unsigned int)(address + (i * 16)));
		tmp = (uint8_t *) & pbuffer[i * 16];
		for (j = 0; j < 4; j++) {
			printf("%02X%02X%02X%02X ", tmp[0], tmp[1], tmp[2],
			       tmp[3]);
			tmp += 4;
		}
		tmp = (uint8_t *) & pbuffer[i * 16];
		for (j = 0; j < 16; j++) {
			console_put_char(*tmp++);
		}
		printf("\n\r");
	}
	if ((size % 16) != 0) {
		last_line_start = size - (size % 16);
		printf("0x%08X: ", (unsigned int)(address + last_line_start));
		for (j = last_line_start; j < last_line_start + 16; j++) {
			if ((j != last_line_start) && (j % 4 == 0)) {
				printf(" ");
			}
			if (j < size)
				printf("%02X", pbuffer[j]);
			else
				printf("  ");
		}
		printf(" ");
		for (j = last_line_start; j < size; j++) {
			console_put_char(pbuffer[j]);
		}
		printf("\n\r");
	}
}
Exemplo n.º 7
0
Arquivo: console.c Projeto: wugsh/wgs
void console_echo(uint8_t c)
{
	switch (c) {
	case '\r':
	case '\n':
		printf("\r\n");
		break;
	case 0x7F:
		printf("\033[1D\033[K");
		break;
	case '\b':
		printf("\033[1D\033[K");
		break;
	default:
		console_put_char(c);
	}
}
Exemplo n.º 8
0
void console_put_mem(mem_address start_address)
{
    int *mem_ref = (int *) start_address; 
    int i; 
    console_put_string("mem from address: "); 
    console_put_hex(start_address); 
    for (i = 0; i < 15; i++)
    {    
	if (i == 13 || i == 14)
	{
            console_put_string("m"); 
    	    console_put_char((char) (i + '0')); 
   	    console_put_string(": "); 
            console_put_hex(*mem_ref); 
	}
        mem_ref++; 
    }
    console_put_string("\n"); 
}
Exemplo n.º 9
0
int si_comm_read(char message_data[], int message_data_size)
{
#ifdef BUILD_ARM_BB
    int read_status; 
    char c; 
    int pos;
    int n_tries; 
    int max_tries = 100000;  
    int end_found; 
    int stop_reading; 
    int char_found; 

    read_status = console_get_char(&c); 
    // console_put_char(c); 

    if (read_status == -1)
    {
        return SI_COMM_ERROR; 
    }
    if ((int) c < 32)
    {
        return SI_COMM_ERROR; 
    }

    // console_put_char((int) c + 1); 

    // there seems to be some writable characters for us

    // store first character
    message_data[0] = c; 

    // look for the rest
    end_found = 0; 
    stop_reading = 0; 
    pos = 1; 
    while (!end_found && !stop_reading)
    {
        // console_put_string("after a while\n"); 
        n_tries = 0; 
	char_found = 0; 
        while (n_tries < max_tries && !char_found)
        {
            read_status = console_get_char(&c); 
            char_found = read_status != 1 && (int) c >= 32; 
            n_tries++; 
        } 
        // console_put_string("after DO while\n"); 
        // console_put_char(c); 
        if (char_found)
	{
            // console_put_char(c); 
            if (c == '#')
	    {
                end_found = 1; 
                stop_reading = 1; 
	    }
            else
	    {
                message_data[pos] = c; 
                pos++; 
	    }
	}
	else
	{
            console_put_char(c); 
            stop_reading = 1; 
	}
    }
    if (end_found)
    {
        // console_put_string("end found\n"); 
        message_data[pos] = '\0'; 
        return SI_COMM_OK; 
    }
    else
    {
        // console_put_string("end NOT found\n"); 
        return SI_COMM_ERROR; 
    }
#else
    fd_set read_fds; 
    struct timeval waitd; 
    int stat; 
    int n; 

    int return_value; 

    waitd.tv_sec = 0;  
    waitd.tv_usec = 0; 

    FD_ZERO(&read_fds);
    FD_SET(newsockfd, &read_fds); 
    
    stat = select(newsockfd + 1, &read_fds, NULL, NULL, &waitd);

    if (stat < 0)
    {    
        printf("SELECT ERROR\n");
        return SI_COMM_ERROR; 
    }

    if (!(FD_ISSET(newsockfd, &read_fds)))
    {
        /* nothing to read, but otherwise OK */ 
        return SI_COMM_EMPTY; 
    }

    // printf("there seems to be data to be read\n");

    /* read the data */ 
#ifdef BUILD_X86_WIN_HOST
    n = recv(newsockfd,message_data,255,0);
#else
    n = read(newsockfd,message_data,255);
#endif
    if (n < 0) 
    {
        printf("ERROR reading from socket"); 
        return SI_COMM_ERROR; 
    }

    /* now we have data, let's check how many */ 
    if (n > message_data_size-1)
    {
        /* too many */
        message_data[message_data_size-1] = '\0'; 
        return_value = SI_COMM_ERROR; 
    }
    else
    {
        /* everything is ok - we have some data! */ 
        message_data[n-1] = '\0'; 
        return_value = SI_COMM_OK; 
    }           
    // printf("Here is the message: %sSTOP\n", message_data);

    return return_value; 
#endif
}
Exemplo n.º 10
0
/**
 * \brief Get new time, successful value is put in new_date.year, new_date.month, new_date.day, new_date.week.
 */
static int get_new_date(void)
{
	char ucKey;
	int i = 0;

	/* clear setting variable */
	new_date.year = 0xFFFF;
	new_date.month = new_date.day = new_date.week = 0xFF;

	/* use time[] as a format template */
	while (1) {
		ucKey = console_get_char();

		/* end input */
		if (ucKey == 0x0d || ucKey == 0x0a) {
			printf("\r\n");
			break;
		}

		/* DEL or BACKSPACE */
		if (ucKey == 0x7f || ucKey == 0x08) {
			if (i > 0) {
				/* end of date[], index then one more back */
				if (!date[i]) {
					--i;
				}

				printf(pEraseSeq);
				--i;

				/* delimitor '/' for date is uneditable */
				if (!is_digit(date[i]) && i > 0) {
					printf(pEraseSeq);
					--i;
				}
			}
		}

		/* end of time[], no more input except above DEL/BS or enter to end */
		if (!date[i]) {
			continue;
		}

		if (!is_digit(ucKey)) {
			continue;
		}

		console_put_char(ucKey);
		date[i++] = ucKey;

		/* ignore non digit position */
		if (!is_digit(date[i]) && i < 10) {
			console_put_char(date[i]);
			++i;
		}
	}

	if (i == 0) {
		return 0;
	}

	if (i != 0 && date[i] != '\0' && i != 6) {
		return 1;	/* failure input */
	}

	/* MM-DD-YY */
	new_date.month = to_digit(date[0]) * 10 + to_digit(date[1]);
	new_date.day = to_digit(date[3]) * 10 + to_digit(date[4]);
	/* not scenario of getting mm/dd/ only for alarm */
	if (i != 6) {
		new_date.year =
		    to_digit(date[6]) * 1000 + to_digit(date[7]) * 100 +
		    to_digit(date[8]) * 10 + to_digit(date[9]);
		new_date.week = compute_week(new_date.year, new_date.month, new_date.day);
	}

	/* success input. verification of data is left to RTC internal Error Checking */
	return 0;
}
Exemplo n.º 11
0
/**
 * \brief Get new time, successful value is put in new_time.hour, new_time.min, new_time.sec.
 */
static int get_new_time(void)
{
	char ucKey;
	int i = 0;

	/* clear setting variable */
	new_time.hour = new_time.min = new_time.sec = 0xFF;

	/* use time[] as a format template */
	while (1) {
		ucKey = console_get_char();

		/* end input */
		if (ucKey == 0x0d || ucKey == 0x0a) {
			printf("\r\n");
			break;
		}

		/* DEL or BACKSPACE */
		if (ucKey == 0x7f || ucKey == 0x08) {
			if (i > 0) {
				/* end of time[], index then one more back */
				if (!rtc_time[i]) {
					--i;
				}

				printf(pEraseSeq);
				--i;

				/* delimitor ':' for time is uneditable */
				if (!is_digit(rtc_time[i]) && i > 0) {
					printf(pEraseSeq);
					--i;
				}
			}
		}

		/* end of time[], no more input except above DEL/BS or enter to end */
		if (!rtc_time[i]) {
			continue;
		}

		if (!is_digit(ucKey)) {
			continue;
		}

		console_put_char(ucKey);
		rtc_time[i++] = ucKey;

		/* ignore non digit position if not end */
		if (!is_digit(rtc_time[i]) && i < 8) {
			console_put_char(rtc_time[i]);
			++i;
		}
	}

	if (i == 0) {
		return 0;
	}

	if (i != 0 && rtc_time[i] != '\0') {
		return 1;	/* failure input */
	}

	new_time.hour = to_digit(rtc_time[0]) * 10 + to_digit(rtc_time[1]);
	new_time.min = to_digit(rtc_time[3]) * 10 + to_digit(rtc_time[4]);
	new_time.sec = to_digit(rtc_time[6]) * 10 + to_digit(rtc_time[7]);

	/* success input. verification of data is left to RTC internal Error Checking */
	return 0;
}