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

📄 mem-ffs.c

📁 mmc_sd_memory_card_driver_sample_project_files.zip spi接口的sd card driver 示例
💻 C
📖 第 1 页 / 共 5 页
字号:
	//---------------------------------------------------------------------------------------------------------------------------
	## (#############>#####.####.############## == #)
	{
		//READ IS NOT PERMITTED
		#############>#####.####.############ = #;
		######(#######);
	}


	//---------------------------------
	//----- CHECK FOR END OF FILE -----
	//---------------------------------
	####### = #############>########################;
	## (#############>#####.####.#######################)
		#######++;

	## (####### >= #############>#########)
	{
		//TRYING TO READ PAST END OF FILE
		#############>#####.####.########### = #;
		######(#######);
	}


	//-----------------------------------------------------------------------
	//----- CHECK FOR NEED TO MOVE TO NEXT BYTE POSITION BEFORE READING -----
	//-----------------------------------------------------------------------
	## (#############>#####.####.#######################)
	{
		//----- INCREMENT BYTE COUNT -----
		#############>########################++;

		#############>############++;
		
		## (#############>############ >= ####################)
		{
			//----- MOVE TO NEXT SECTOR -----
			#############>############ = #;

			#############>##############++;

			## (#############>############## >= ###################)
			{
				//----- MOVE TO NEXT CLUSTER -----
				#############>############## = #;

				//Get the next cluster number
				####### = #######################(#############>###############);

				## (##############)
				{
					//FAT32
					## (####### >= ##########)
					{
						//There is no next cluster - all of file has been read
						###### = #;
						#############>#####.####.########### = #;
						######(#######);
					}
				}
				####
				{
					//FAT16
					## (####### >= ######)
					{
						//There is no next cluster - all of file has been read
						###### = #;
						#############>#####.####.########### = #;
						######(#######);
					}
				}

				#############>############### = #######;

			}
		}

		#############>#####.####.####################### = #;
	}


	//-------------------------------------------------------------
	//----- CHECK FOR NEED TO LOAD CURRENT SECTOR INTO BUFFER -----
	//-------------------------------------------------------------
	####### = (
				((#############>############### # #) * ###################) +
				(#####)#############>############## +
				######################
				);
	## (####################### != #######)
	{
		#########################(#######);
	}


	//------------------------
	//----- GET THE BYTE -----
	//------------------------
	############## = &##############################[#] + #############>############;
	#### = (###)*##############;



	//------------------------------------------------------------------------
	//----- FLAG THAT WE NEED TO MOVE ON 1 BYTE NEXT TIME ACCESS IS MADE -----
	//------------------------------------------------------------------------
	//(we do this instead of incrementing now in case we have just doen the last byte of the file)
	#############>#####.####.####################### = #;

	//--------------------------------------------
	//----- EXIT WITH THE BYTE THAT WAS READ -----
	//--------------------------------------------
	######((###)####);
}






//******************************************
//******************************************
//********** WRITE STRING TO FILE **********
//******************************************
//******************************************
//Writes string to file until the null termination is reached.  The null termination is not written to the
//file.  If a new line character (\n) is required it should be included at the end of the string
//
//Returns
//	Non-negative value if successful
//	EOF if errored
int ffs_fputs (const char *string, FFS_FILE *file_pointer)
{
	#### *##############;
	### ############;


	//----- WRITE THE STRING -----
	############## = ######;
	
	##### (*############## != ####)
	{
		############ = ######### ((###)*##############++, ############);

		## (############ == #######)
			######(#######);
	}

	######(#);
}

//THIS IS A NON ANSI VARIENT OF THIS FUNCTION FOR USE WHEN WRITING A STRING FROM RAM WITH COMPILERS THAT WON'T
//DEAL WITH CONVERTING THE RAM STRING TO A CONSTANT STRING.
int ffs_fputs_char (char *string, FFS_FILE *file_pointer)
{
	#### *##############;
	### ############;


	//----- WRITE THE STRING -----
	############## = ######;
	
	##### (*############## != ####)
	{
		############ = ######### ((###)*##############++, ############);

		## (############ == #######)
			######(#######);
	}

	######(#);
}





//*******************************************
//*******************************************
//********** READ STRING FROM FILE **********
//*******************************************
//*******************************************
//Reads characters from file and stores them into the specified buffer until a newline (\n) or EOF character is read or
//(length - 1) characters have been read.
//A newline character (\n) is not discarded.  A null termination is added to the string
//
//Returns
//	Pointer to the buffer if successful
//	Null pointer if end-of-file or error (use ffs_ferror or ffs_feof to check what happened)
char* ffs_fgets (char *string, int length, FFS_FILE *file_pointer)
{
	#### *##############;
	### ############;
	
	//----- READ THE STRING -----
	############## = ######;

	############ = #########(############);
	##### ((############ != #######) && (###### > #))
	{
		*##############++ = (####)############;
		
		########;

		## (############ == (###)'\#')
			#####;

		############ = #########(############);
	}

	//----- STORE THE TERMINATING NULL -----
	*##############++ = ####;

	## (############ == #######)
		######(####);
	####
		######(######);

}





//**********************************************
//**********************************************
//********** WRITE DATA BLOCK TO FILE **********
//**********************************************
//**********************************************
//Writes count number of items, each one with a size of size bytes, from the specified buffer
//No translation occurs for files opened in text mode
//The total number of bytes to be written is (size x count).
//
//Returns
//	Number of full items (not bytes) successfully written. This may be less than the requested number if an error occurred.
 
int ffs_fwrite (const void *buffer, int size, int count, FFS_FILE *file_pointer)
{
	### ##########;
	#### *##############;
	### ####################### = #;


	############## = (####*)######;

	//STORE ALL OF THE ITEMS
	##### (#####)
	{
		//STORE EACH ITEM
		### (########## = #; ########## < ####; ##########++)
		{

			## (#########((###)*##############++, ############) == #######)
			{
				######(#######################);
			}
		}
		#######################++;
		#######;
	}

	######(#######################);
}




//***********************************************
//***********************************************
//********** READ DATA BLOCK FROM FILE **********
//***********************************************
//***********************************************
//Read count number of items each one with a size of size bytes from the file to the specified buffer.
//Total amount of bytes read is (size x count)
//
//Returns
//	Number of items (not bytes) read is returned.  If this number differs from the requested amount (count) an error has
//	occurred or End Of File has been reached (use ffs_ferror or ffs_feof to check what happened)
int ffs_fread (void *buffer, int size, int count, FFS_FILE *file_pointer)
{
	### ##########;
	### ############;
	#### *##############;
	### ####################### = #;


	############## = (####*)######;

	//READ ALL OF THE ITEMS
	##### (#####)
	{
		//STORE EACH ITEM
		### (########## = #; ########## < ####; ##########++)
		{

			############ = #########(############);

			## (############ == #######)
				######(#######################);
			
			*##############++ = (####)############;
		}
		#######################++;
		#######;
	}

	######(#######################);
}






//**********************************************************
//**********************************************************
//********** STORE ANY UNWRITTEN DATA TO THE CARD **********
//**********************************************************
//**********************************************************
//Write any data that is currently held in microcontroller / processor ram that is waiting to be
//written to the card.  Update the file filesize value if it has changed.
//Returns
//	0 if successful, 1 otherwise
int ffs_fflush (FFS_FILE *file_pointer)
{
	#### *##############;


	//----- EXIT IF THIS FILE ISN'T ACTUALLY OPEN -----
	## (#############>#####.####.############ == #)
		######(#);


	//If the data buffer contains data that is waiting to be written then write it
	//(We just store any unwritten data regardless of what file this funciton is called with as there is only 1 buffer)
	## (################################)
	{
		## (####################### != ##########)			//This should not be possible but check is made just in case!
			############################(#######################);

		################################ = #;
	}

	## (#############>#####.####.#####################)
	{
		//----- STORE THE NEW FILE SIZE IN THE FILES DIRECTORY ENTRY -----
		######################### (#############>######################);

		//Offset to the start of the entry
		############## = &##############################[#] + ((####)#############>############################# << #) + ##;			//Start of the file size is 28 bytes into the entry

		*##############++ = (####)(#############>######### & ##########);
		*##############++ = (####)((#############>######### & ##########) >> #);
		*##############++ = (####)((#############>######### & ##########) >> ##);
		*##############++ = (####)((#############>######### & ##########) >> ##);

		############################(#############>######################);

		#############>#####.####.##################### = #;
	}


	###### = #;										//De-select the card

	######(#);
}




//********************************
//********************************
//********** CLOSE FILE **********
//********************************
//********************************
//Return value
//	0 = file successfully closed
//	1 = error
int ffs_fclose (FFS_FILE *file_pointer)
{
	//----- EXIT IF THIS FILE ISN'T ACTUALLY OPEN -----
	## (#############>#####.####.############ == #)
		######(#);

	//----- ENSURE ANY UNWRITTEN DATA AND ANY CHANGE IN FILE SIZE IS STORED -----
	##########(############);

	//----- FLAG THAT THE FILE IS NO LOGER OPEN AND THIS FILE HANDLER IS AVAILABLE AGAIN -----
	#############>#####.####.############ = #;

	######(#);
}




//*********************************
//*********************************
//********** DELETE FILE **********
//*********************************
//*********************************
//Return value
// 0 = file is succesfully deleted

⌨️ 快捷键说明

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