Esempio n. 1
0
int FGETC(FILE *f)
{
	if ((stdout == f) || (stderr == f))
	{
		return 0;
	}
	else if (stdin == f)
	{
		if (!appio_dummy)
		{
			uint32_t size;
			do
			{
				usb_protocol_poll();
				size = vsf_fifo_get_data_length(&shell_stream.stream_tx.fifo);
			} while (!size);
			return vsf_fifo_pop8(&shell_stream.stream_tx.fifo);
		}
	}
	else
	{
		struct appio_file_t *file = appio_file_byfn(f);
		if (file != NULL)
		{
			return file->pos >= file->size ? EOF : file->addr[file->pos++];
		}
	}
	return 0;
}
Esempio n. 2
0
int FFLUSH(FILE *f)
{
	if ((stdout == f) || (stderr == f))
	{
		if (!appio_dummy)
		{
			app_io_out_sync();
		}
		return 0;
	}
	else if (stdin == f)
	{
		if (!appio_dummy)
		{
			uint32_t i, size = vsf_fifo_get_data_length(&shell_stream.stream_tx.fifo);
			for (i = 0; i < size; i++)
			{
				vsf_fifo_pop8(&shell_stream.stream_tx.fifo);
			}
		}
		return 0;
	}
	else
	{
		struct appio_file_t *file = appio_file_byfn(f);
		if (file != NULL)
		{
			// TODO: flush appio_file
		}
	}
	return 0;
}
Esempio n. 3
0
int32_t comm_flush_usbtocomm(void)
{
	if (!usbtocomm_open)
	{
		return -1;
	}
	
	while (vsf_fifo_get_data_length(&usart_stream_p0.stream_tx.fifo) > 0)
	{
		usart_stream_poll(&usart_stream_p0);
	}
	while (vsf_fifo_get_data_length(&usart_stream_p0.stream_rx.fifo) > 0)
	{
		vsf_fifo_pop8(&usart_stream_p0.stream_rx.fifo);
		usart_stream_poll(&usart_stream_p0);
	}
	return 0;
}
Esempio n. 4
0
char* FGETS(char *buf, int count, FILE *f)
{
	char cur_char, *result = buf;
	int size = 0, cur_size, pos;
	
	if ((NULL == buf) || (NULL == f) || (stdout == f) || (stderr == f))
	{
		return NULL;
	}
	
	if (stdin == f)
	{
		if (!appio_dummy)
		{
#if HW_HAS_LCM
			char vsprog_ui_buf[2];
#endif
			pos = 0;
			cur_char = '\0';
			while ((size < count) && (cur_char != '\r'))
			{
				usb_protocol_poll();
				cur_size = vsf_fifo_get_data_length(&shell_stream.stream_tx.fifo);
				
				while (cur_size && (size < count) && (cur_char != '\r'))
				{
					cur_char = (char)vsf_fifo_pop8(&shell_stream.stream_tx.fifo);
					if ('\r' == cur_char)
					{
						vsf_fifo_push8(&shell_stream.stream_rx.fifo, '\n');
#if HW_HAS_LCM
						vsprog_ui_print("\n\0");
#endif
					}
					else if ('\b' == cur_char)
					{
						if (pos)
						{
							vsf_fifo_push8(&shell_stream.stream_rx.fifo, '\b');
							vsf_fifo_push8(&shell_stream.stream_rx.fifo, ' ');
							vsf_fifo_push8(&shell_stream.stream_rx.fifo, '\b');
#if HW_HAS_LCM
							vsprog_ui_print("\b \b\0");
#endif
							pos--;
						}
						cur_size--;
						continue;
					}
					else if (!((cur_char >= ' ') && (cur_char <= '~')))
					{
						cur_size--;
						continue;
					}
					vsf_fifo_push8(&shell_stream.stream_rx.fifo, (uint8_t)cur_char);
#if HW_HAS_LCM
					vsprog_ui_buf[0] = cur_char;
					vsprog_ui_buf[1] = '\0';
					vsprog_ui_print(vsprog_ui_buf);
#endif
					buf[pos++] = cur_char;
					size++;
					cur_size--;
				}
			}
			buf[pos] = '\0';
			app_io_out_sync();
		}
		else
		{
			return NULL;
		}
	}
	else
	{
		struct appio_file_t *file = appio_file_byfn(f);
		if (file != NULL)
		{
			if (count < 3)
			{
				return NULL;
			}
			count -= 3;
			
			while ((file->addr[file->pos] != '\0') &&
					(file->addr[file->pos] != 0xFF) &&
					(file->pos < file->size) &&
					((file->addr[file->pos] == '\n') ||
						(file->addr[file->pos] == '\r')))
			{
				file->pos++;
			}
			while (count-- && 
					(file->pos < file->size) &&
					(file->addr[file->pos] != '\0') &&
					(file->addr[file->pos] != '\n') &&
					(file->addr[file->pos] != '\r') &&
					(file->addr[file->pos] != 0xFF))
			{
				*buf++ = file->addr[file->pos++];
			}
			if (result == buf)
			{
				return NULL;
			}
			*buf++ = '\n';
			*buf++ = '\r';
			*buf++ = '\0';
		}
	}
	return result;
}