⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filesystemmain.c

📁 epson usb2.0 控制芯片 S1R72V05 固件程序。
💻 C
📖 第 1 页 / 共 3 页
字号:

			if (fr == 0) {
				memset(bmsgstr, 0x00, sizeof(bmsgstr));
				sprintf((char *)bmsgstr, "Error: Cannot open \"%s\".\n\r", arg[1]);
				FlowStrPrint(bmsgstr, FLOW_LV);

			} else {
				seek_size = atol((char *)arg[2]);
				seek_pos = atoi((char *)arg[3]);

				if (fatFseek(fr, seek_size, seek_pos) != TEST_SUCCESS) {
					memset(bmsgstr, 0x00, sizeof(bmsgstr));
					sprintf((char *)bmsgstr, "Error: Cannot seek \"%s\".\n\r", arg[1]);
					FlowStrPrint(bmsgstr, FLOW_LV);
				}
			}

			fatFclose(fr);

		// (20)Direct copy
		} else if (strcmp((char *)arg[0], "direct") == 0) {
			if (fatDrtCopy((char *)arg[1], (char *)arg[2]) != TEST_SUCCESS) {
				memset(bmsgstr, 0x00, sizeof(bmsgstr));
				sprintf((char *)bmsgstr, "Error: Cannot direct copy \"%s\" - \"%s\".\n\r", arg[1], arg[2]);
				FlowStrPrint(bmsgstr, FLOW_LV);
			}
		// (21)End
		} else if (strcmp((char *)arg[0], "exit") == 0) {
			break;

		// (22)Running test
		} else if (strcmp((char *)arg[0], "running") == 0) {

			total_running_cnt = running_cnt = atol((char *)arg[3]);
			if( running_cnt == 0 ){
				total_running_cnt = running_cnt = 1;
			}

			for( ; running_cnt > 0; running_cnt-- ){
				FlowValPrint( PRINT_DECIMAL_MODE, DBG_STORE_DWORD, ((total_running_cnt - running_cnt) + 1), FLOW_LV);
				FlowStrPrint("Try.\n\r", FLOW_LV);
				if( total_running_cnt != running_cnt ){
					FlowStrPrint("Written deletion of file.\n\r", FLOW_LV);
					if (fatRemove((char *)arg[2], (unsigned long)NULL) != TEST_SUCCESS) {
						memset(bmsgstr, 0x00, sizeof(bmsgstr));
						sprintf((char *)bmsgstr, "Error: Cannot delete \"%s\".\n\r", arg[1]);
						FlowStrPrint(bmsgstr, FLOW_LV);
						break;
					}
				}

				fr = fatFopen((char *)arg[1], "rb");

				if (fr == 0) {
					memset(bmsgstr, 0x00, sizeof(bmsgstr));
					sprintf((char *)bmsgstr, "Error: Cannot open \"%s\".\n\r", arg[1]);
					FlowStrPrint(bmsgstr, FLOW_LV);
					fatFclose(fr);
					break;

				} else {
					// The file name needs to be specified in the second argument (receiving side), for the specification of the command
					// It is also OK to miss it for MS-DOS(The file name is the same )
					// Improve the following processing so that MS-DOS may conform
					fw = fatFopen((char *)arg[2], "wb");

					if (fw == 0) {
						memset(bmsgstr, 0x00, sizeof(bmsgstr));
						sprintf((char *)bmsgstr, "Error: Cannot open \"%s\".\n\r", arg[2]);
						FlowStrPrint(bmsgstr, FLOW_LV);
						fatFclose(fr);
						fatFclose(fw);
						break;

					} else {

						FlowStrPrint("File copy.\n\r", FLOW_LV);
						do {
							size = fatFread(buf, 1, BUF_COUNT * BUF_SIZE, fr);
							fatFwrite(buf, 1, size, fw);
						} while (fatFeof(fr) == 0);

						fatFclose(fw);
						fatFclose(fr);
					}

				}

				fr = fatFopen((char *)arg[1], "rb");

				if (fr == 0) {
					memset(bmsgstr, 0x00, sizeof(bmsgstr));
					sprintf((char *)bmsgstr, "Error: Cannot open \"%s\".\n\r", arg[1]);
					FlowStrPrint(bmsgstr, FLOW_LV);
					fatFclose(fr);
					break;

				} else {
					// The file name needs to be specified in the second argument (receiving side), for the specification of the command
					// It is also OK to miss it for MS-DOS(The file name is the same )
					// Improve the following processing so that MS-DOS may conform
					cmp_fr = fatFopen((char *)arg[2], "rb");

					if (cmp_fr == 0) {
						memset(bmsgstr, 0x00, sizeof(bmsgstr));
						sprintf((char *)bmsgstr, "Error: Cannot open \"%s\".\n\r", arg[2]);
						FlowStrPrint(bmsgstr, FLOW_LV);
						fatFclose(fr);
						fatFclose(cmp_fr);
						break;

					} else {

						FlowStrPrint("File compare.\n\r", FLOW_LV);
						running_error = 0;
						do {
							size = fatFread(buf, 1, (BUF_SIZE * BUF_COUNT / 2), fr);
							cmp_size = fatFread(&buf[(BUF_SIZE * BUF_COUNT / 2)], 1, (BUF_SIZE * BUF_COUNT / 2), cmp_fr);
							if( size != cmp_size ){
								FlowStrPrint("File size error!\n\r", FLOW_LV);
								running_error = 1;
								break;
							}

							/* Countermeasure against problem of miss address access caused by optimization */
							if( memcmp(buf, &buf[BUF_SIZE * BUF_COUNT / 2], size) != 0 ){
								FlowStrPrint("File compare error!\n\r", FLOW_LV);
								running_error = 1;
								break;
							}

						} while (fatFeof(fr) == 0);

						fatFclose(cmp_fr);
						fatFclose(fr);
						if( running_error == 1 ){
							break;
						}
					}
				}
			}

			FlowStrPrint("Execution frequency : ", FLOW_LV);
			FlowValPrint( PRINT_DECIMAL_MODE, DBG_STORE_DWORD, (total_running_cnt - running_cnt), FLOW_LV);
			FlowStrPrint(" / ", FLOW_LV);
			FlowValPrint( PRINT_DECIMAL_MODE, DBG_STORE_DWORD, total_running_cnt, FLOW_LV);
			FlowStrPrint("\n\r", FLOW_LV);

		// (23)File read test
		} else if (strcmp((char *)arg[0], "readtest") == 0) {
			total_running_cnt = running_cnt = atol((char *)arg[2]);
			if( running_cnt == 0 ){
				total_running_cnt = running_cnt = 1;
			}

			for( ; running_cnt > 0; running_cnt-- ){
				FlowValPrint( PRINT_DECIMAL_MODE, DBG_STORE_DWORD, ((total_running_cnt - running_cnt) + 1), FLOW_LV);
				FlowStrPrint("Try.\n\r", FLOW_LV);

				fr = fatFopen((char *)arg[1], "rb");

				if (fr == 0) {
					memset(bmsgstr, 0x00, sizeof(bmsgstr));
					sprintf((char *)bmsgstr, "Error: Cannot open \"%s\".\n\r", arg[1]);
					FlowStrPrint(bmsgstr, FLOW_LV);
					fatFclose(fr);
					break;

				} else {
					FlowStrPrint("File read\n\r", FLOW_LV);
					do {
						size = fatFread(buf, 1, BUF_COUNT * BUF_SIZE, fr);
					} while (fatFeof(fr) == 0);
					fatFclose(fr);
				}

			}

			FlowStrPrint("Execution frequency : ", FLOW_LV);
			FlowValPrint( PRINT_DECIMAL_MODE, DBG_STORE_DWORD, (total_running_cnt - running_cnt), FLOW_LV);
			FlowStrPrint(" / ", FLOW_LV);
			FlowValPrint( PRINT_DECIMAL_MODE, DBG_STORE_DWORD, total_running_cnt, FLOW_LV);
			FlowStrPrint("\n\r", FLOW_LV);

#ifdef WRITETEST
		// (24)File write test
		} else if (strcmp((char *)arg[0], "writetest") == 0) {
			total_running_cnt = running_cnt = atol((char *)arg[3]);
			if( running_cnt == 0 ){
				total_running_cnt = running_cnt = 1;
			}

			for( ; running_cnt > 0; running_cnt-- ){
				FlowValPrint( PRINT_DECIMAL_MODE, DBG_STORE_DWORD, ((total_running_cnt - running_cnt) + 1), FLOW_LV);
				FlowStrPrint("Try.\n\r", FLOW_LV);

				fr = fatFopen((char *)arg[1], "rb");
				if (fr == 0) {
					memset(bmsgstr, 0x00, sizeof(bmsgstr));
					sprintf((char *)bmsgstr, "Error: Cannot open \"%s\".\n\r", arg[1]);
					FlowStrPrint(bmsgstr, FLOW_LV);
					fatFclose(fr);
					break;

				} else {
					fatFread(pReadFileData, 1, DAMERICA_SIZE, fr);
					FlowStrPrint("Writing file Read completion.\n\r", FLOW_LV);

					fw = fatFopen((char *)arg[2], "wb");
					if (fw == 0) {
						memset(bmsgstr, 0x00, sizeof(bmsgstr));
						sprintf((char *)bmsgstr, "Error: Cannot open \"%s\".\n\r", arg[2]);
						FlowStrPrint(bmsgstr, FLOW_LV);
						fatFclose(fr);
						fatFclose(fw);
					}
					else {

						FlowStrPrint("File write.\n\r", FLOW_LV);
						fatFwrite(pReadFileData, 1, DAMERICA_SIZE, fw);
					}

					fatFclose(fr);
					fatFclose(fw);
				}

			}

			FlowStrPrint("Execution frequency : ", FLOW_LV);
			FlowValPrint( PRINT_DECIMAL_MODE, DBG_STORE_DWORD, (total_running_cnt - running_cnt), FLOW_LV);
			FlowStrPrint(" / ", FLOW_LV);
			FlowValPrint( PRINT_DECIMAL_MODE, DBG_STORE_DWORD, total_running_cnt, FLOW_LV);
			FlowStrPrint("\n\r", FLOW_LV);
#endif
		} else if (strcmp((char *)arg[0], "readwrite") == 0) {
			LONG	result;
			ULONG   i, sector;
			UCHAR	cnt;

			/* Running command for which filesystem is not used */
			total_running_cnt = running_cnt = atol((char *)arg[1]);
			if( running_cnt == 0 ){
				total_running_cnt = running_cnt = 1;
			}

			sector = cnt = 0;
			for( ; running_cnt > 0; running_cnt-- ){
				FlowValPrint( PRINT_DECIMAL_MODE, DBG_STORE_DWORD, ((total_running_cnt - running_cnt) + 1), FLOW_LV);
				FlowStrPrint("Try.\n\r", FLOW_LV);
#if 0
				FlowStrPrint("  file write.....", FLOW_LV);
				result = TestReadWrite( 1, 0, 1, cnt, sector );		/* DMA use */
				if (result != 0) {
					memset(bmsgstr, 0x00, sizeof(bmsgstr));
					sprintf((char *)bmsgstr, "Error!");
					FlowStrPrint(bmsgstr, FLOW_LV);
				}
				FlowStrPrint("...OK\n\r", FLOW_LV);
#endif
				memcpy(buf, (unsigned char *)LDRV_SECTOR_BUF_ADDRESS, 0x200);
				FlowStrPrint("  file read.....", FLOW_LV);
				result = TestReadWrite( 1, 0, 0, cnt++, sector++ );		/* DMA use */
				if (result != 0) {
					memset(bmsgstr, 0x00, sizeof(bmsgstr));
					sprintf((char *)bmsgstr, "Error!");
					FlowStrPrint(bmsgstr, FLOW_LV);
				} else {
					FlowStrPrint("...OK\n\r", FLOW_LV);
				}
#if 0
				FlowStrPrint("  file compare...", FLOW_LV);
				if( memcmp(buf, (unsigned char *)LDRV_SECTOR_BUF_ADDRESS, 0x200) != 0 ){
					FlowStrPrint("  file compare err!\n\r", FLOW_LV);
					running_error = 1;
				}
				FlowStrPrint("...OK\n\r", FLOW_LV);
#endif
			}

			FlowStrPrint("Execution frequency : ", FLOW_LV);
			FlowValPrint( PRINT_DECIMAL_MODE, DBG_STORE_DWORD, (total_running_cnt - running_cnt), FLOW_LV);
			FlowStrPrint(" / ", FLOW_LV);
			FlowValPrint( PRINT_DECIMAL_MODE, DBG_STORE_DWORD, total_running_cnt, FLOW_LV);
			FlowStrPrint("\n\r", FLOW_LV);

		// Invalid API command of X
		} else {
			memset(bmsgstr, 0x00, sizeof(bmsgstr));
			sprintf((char *)bmsgstr, "Error: Invalid API command \"%s\".\n\r", arg[0]);
			FlowStrPrint(bmsgstr, FLOW_LV);
		}
	}

	// File system demonstration program end
	return TEST_SUCCESS;
}

/************************************************************************
 *	GetCommandStr
 *		Type	 : void
 *		Ret val  : None
 *		Argument : None
 *		Function : Acquisition of the API command character sequence by user's key input
 ************************************************************************/
void GetCommandStr( void )
{
	unsigned short	rcvlength;

	memset(bCommandStr, 0x00, sizeof(bCommandStr));

	FileSytemFlowGetStr(bCommandStr, &rcvlength, 0);			/* Receive the inputted command character string */

	// For debug display
	FlowStrPrint("\n\r", FLOW_LV);
	FlowStrPrint("---- For debug ----\n\r", FLOW_LV);
	FlowStrPrint((CHAR *)bCommandStr, FLOW_LV);
	FlowStrPrint("\n\n\n\r", FLOW_LV);

	return;
}

/************************************************************************
 *	EndingMessage
 *		Type	 : void
 *		Ret val  : None
 *		Argument : None
 *		Function : filesystem ending message
 ************************************************************************/
void EndingMessage( void )
{
	FlowStrPrint("\n\rS1R72V05 USB HS-HOST The filesystem demonstration program is ended. \n\n\r", FLOW_LV);	/* Transfer Ending */
}

/*
//=============================================================================
// Function_Name: FileSytemFlowGetStr
// description	: Wait until the string specified by pString inputted
// argument		: const UCHAR *pString
//				: USHORT dataSize
//				: OS_TMP tmout (Waiting until be inputted, in setting of 0)
// return		: LONG
//=============================================================================
*/
LONG FileSytemFlowGetStr( UCHAR* pString, USHORT* pDataSize, OS_TMO tmout )
{
#ifndef ECHO_OFF
	unsigned char temp;
	unsigned short rcvdSize = 0;
	unsigned char ctrlCh = 0;

	while(1){
		temp = '\n';
		UART_FuncReceiveData( 1, 1, &temp );
		if( ctrlCh > 0 ){
			ctrlCh--;
			continue;
		}
		if( temp == '\r' || temp == '\n' ){
			pString[rcvdSize] = 0;		// Set NULL
			break;
		}else if( temp == '\b' ){
			if( rcvdSize > 0 ){
				UART_FuncSendText( 1, (unsigned char *)("\b \b") );
				rcvdSize--;
				pString[rcvdSize] = 0;		// The reception character string is deleted by 0
			}else{
				// The back space is ignored at the 0th byte
			}
		}else if( iscntrl(temp) == 0 ){
			UART_FuncSendData( 1, 1, &temp );
			pString[rcvdSize] = temp;
			rcvdSize++;
		}else{
			if( temp != '\t' ){
				// Ignore the control character
				if( temp == 0x1b ){
					ctrlCh = 2;		// 0x05 is code of 3 byte(arrow etc.)
				}else{
					ctrlCh = 1;		// It is code of 2 bytes except the above
				}
			}
		}
	}
	*pDataSize = rcvdSize;

#else	// ECHO_ON
	UART_FuncReceiveText( 1, 80, pString, pDataSize);
#endif // ECHO_OFF
	return DBG_STATUS_SUCCESS;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -