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

📄 nandfdbg.c

📁 嵌入式系统中文件系统源代码
💻 C
字号:

/*************************************************************
File Name: NANDfdbg.C
Last Modified Date: 2001/03/21
Programmer: MSC
Compiler:
Platform:
Usage:
	NAND Flash File System debug functions

Other Information:
**************************************************************/
#include <sys/syscall.h>
#include <ansi_c/stdio.h>
#include <ansi_c/string.h>
//#include "../../rDebug/include/rdebug.h"	// jason
#include "../include/FFS_NAND.h"
#include "../include/NANDfblk.h"
#include "../include/NANDfdrv.h"
#include "../include/NANDlump.h"

#ifdef NAND_FLASH_DISK_ID
#ifdef NAND_FFS_DEBUG

#include <ansi_c/stdio.h>


char NAND_FFS_DebugString[80];



// FFS_NAND.c
extern int NAND_FFS_SemaphoreID;
extern int NAND_FFS_Init_OK;
extern unsigned long *NAND_FFS_ReadCount;
extern unsigned long *NAND_FFS_EraseCount;
extern unsigned long *NAND_FFS_ProgramCount;
extern unsigned char *NAND_FlashAccessBuffer;
#ifdef NAND_FFS_USE_CACHE
  extern struct NAND_FFS_cacheInfo **NAND_FFS_CacheStatus;
  extern unsigned char **NAND_FFS_BlockCache;
#endif

// NANDfile.c
extern struct NAND_FFS_FILE **NAND_FFS_HandleTable;

// NANDlump.c
extern unsigned long NAND_LumpNum;



/*************************************************************
Function: NAND_FFS_showHandleContent
Description:
	show the file handle content
Input:
	handle - the target file handle
Output:
	0	SUCCESS
	-1	FAILURE
**************************************************************/
int NAND_FFS_showHandleContent(int handle)
{
  struct NAND_FFS_FILE *pfile;

  if (NAND_FFS_Init_OK == FALSE)
  {
	NAND_FFS_Errno = ERROR_FILE_SYSTEM_NOT_INIT;
	return -1;
  }

  if ((handle < 0) || (handle >= MAX_OPEN_FILE) || (NAND_FFS_HandleTable[handle] == NULL))
  {
	NAND_FFS_Errno = ERROR_INVALID_HANDLE;
	return -1;
  }

  NAND_FFS_Errno = 0;

  pfile = NAND_FFS_HandleTable[handle];
  sprintf(NAND_FFS_DebugString, "[Handle %d]:", handle);
  SprintStringLn(NAND_FFS_DebugString);
  sprintf(NAND_FFS_DebugString, "    handle = %d", pfile->handle);
  SprintStringLn(NAND_FFS_DebugString);
  sprintf(NAND_FFS_DebugString, "    headLump = %d", pfile->headLump);
  SprintStringLn(NAND_FFS_DebugString);
  sprintf(NAND_FFS_DebugString, "    currentLump = %d", pfile->currentLump);
  SprintStringLn(NAND_FFS_DebugString);
  sprintf(NAND_FFS_DebugString, "    fpos = %d", pfile->fpos);
  SprintStringLn(NAND_FFS_DebugString);
  sprintf(NAND_FFS_DebugString, "    size = %d", pfile->size);
  SprintStringLn(NAND_FFS_DebugString);
  sprintf(NAND_FFS_DebugString, "    ownerID = %d", pfile->ownerID);
  SprintStringLn(NAND_FFS_DebugString);

  return 0;
}



/*************************************************************
Function: NAND_FFS_showCounts
Description:
	show the erase/read/program counts
Input:
	none
Output:
	none
**************************************************************/
void NAND_FFS_showCounts(void)
{
  int i;

  sprintf(NAND_FFS_DebugString, "Counts:");
  SprintStringLn(NAND_FFS_DebugString);

  for (i = 0; i < NAND_FFS_BLOCK_NUM; i++)
  {
	sprintf(NAND_FFS_DebugString, "    %03d[%04d]: read=%d, erase=%d, program=%d", i, NAND_FFS_START_BLOCK + i, NAND_FFS_ReadCount[i], NAND_FFS_EraseCount[i], NAND_FFS_ProgramCount[i]);
	SprintStringLn(NAND_FFS_DebugString);
  }

  return;
}



/*************************************************************
Function: NAND_FFS_showLumpChain
Description:
	show the lump chain
Input:
	handle - file handle
Output:
	none
**************************************************************/
void NAND_FFS_showLumpChain(int handle)
{
  int lump;
  int index;
  int i;
  char tempStr[20];

  sprintf(NAND_FFS_DebugString, "Lump chain:");
  SprintStringLn(NAND_FFS_DebugString);

  if ((handle < 0) || (handle >= MAX_OPEN_FILE) || (NAND_FFS_HandleTable[handle] == NULL))
  {
	sprintf(NAND_FFS_DebugString, "    Invalid handle = %d", handle);
	SprintStringLn(NAND_FFS_DebugString);
	return;
  }

  if (NAND_FFS_HandleTable[handle]->deviceID != NAND_FLASH_DISK_ID)
  {
	sprintf(NAND_FFS_DebugString, "    Invalid device = %d", NAND_FFS_HandleTable[handle]->deviceID);
	SprintStringLn(NAND_FFS_DebugString);
	return;
  }

  lump = NAND_FFS_HandleTable[handle]->headLump;

  sprintf(NAND_FFS_DebugString, "    ");
  index = 4;

  while (lump != NAND_END_LUMP)
  {
	sprintf(tempStr, "%d->", lump);
	for (i = 0; i < strlen(tempStr); i++)
	{
		NAND_FFS_DebugString[index++] = tempStr[i];
	}

	if (index > 70)
	{
		NAND_FFS_DebugString[index] = '\0';
		SprintStringLn(NAND_FFS_DebugString);
		index = 4;
	}

	lump = NAND_getNextLump(lump);
  }

  sprintf(tempStr, "END", lump);
  for (i = 0; i < strlen(tempStr); i++)
  {
	NAND_FFS_DebugString[index++] = tempStr[i];
  }
  SprintStringLn(NAND_FFS_DebugString);

  return;
}



/*************************************************************
Function: NAND_FFS_showLumpChainStructure
Description:
	show the structures of each lump in the chain
Input:
	handle - file handle
Output:
	none
**************************************************************/
void NAND_FFS_showLumpChainStructure(int handle)
{
  int lump;
  struct NAND_diskLump *lumpPtr;

  sprintf(NAND_FFS_DebugString, "Lump structures in the chain:");
  SprintStringLn(NAND_FFS_DebugString);

  if ((handle < 0) || (handle >= MAX_OPEN_FILE) || (NAND_FFS_HandleTable[handle] == NULL))
  {
	sprintf(NAND_FFS_DebugString, "    Invalid handle = %d", handle);
	SprintStringLn(NAND_FFS_DebugString);
	return;
  }

  if (NAND_FFS_HandleTable[handle]->deviceID != NAND_FLASH_DISK_ID)
  {
	sprintf(NAND_FFS_DebugString, "    Invalid device = %d", NAND_FFS_HandleTable[handle]->deviceID);
	SprintStringLn(NAND_FFS_DebugString);
	return;
  }

  lump = NAND_FFS_HandleTable[handle]->headLump;

  while (lump != NAND_END_LUMP)
  {
	lumpPtr = NAND_readLumpStructure(lump, 0);

	sprintf(NAND_FFS_DebugString, "%06d: t=0x%x, dS=%d, uD=%d, uT=%d, nL=%d", lump, lumpPtr->type, lumpPtr->dataSize, lumpPtr->updateDate, lumpPtr->updateTime, lumpPtr->nextLump);
	SprintStringLn(NAND_FFS_DebugString);

	lump = lumpPtr->nextLump;
  }

  return;
}



#ifdef NAND_FFS_USE_CACHE

/*************************************************************
Function: NAND_FFS_showCacheStatusAddress
Description:
	show the addresses of the cache status
Input:
	none
Output:
	none
**************************************************************/
void NAND_FFS_showCacheStatusAddress(void)
{
  int i;

  sprintf(NAND_FFS_DebugString, "Cache status addresses:");
  SprintStringLn(NAND_FFS_DebugString);

  for (i = 0; i < NAND_FFS_CACHE_BLOCK_NUM; i++)
  {
	sprintf(NAND_FFS_DebugString, "    %03d: address = 0x%x", i, NAND_FFS_CacheStatus[i]);
	SprintStringLn(NAND_FFS_DebugString);
  }

  return;
}



/*************************************************************
Function: NAND_FFS_showCacheAddress
Description:
	show the addresses of the cache
Input:
	none
Output:
	none
**************************************************************/
void NAND_FFS_showCacheAddress(void)
{
  int i;

  sprintf(NAND_FFS_DebugString, "Cache addresses:");
  SprintStringLn(NAND_FFS_DebugString);

  for (i = 0; i < NAND_FFS_CACHE_BLOCK_NUM; i++)
  {
	sprintf(NAND_FFS_DebugString, "    %03d: address = 0x%x", i, NAND_FFS_BlockCache[i]);
	SprintStringLn(NAND_FFS_DebugString);
  }

  return;
}



/*************************************************************
Function: NAND_FFS_showCacheStatus
Description:
	show the cache status
Input:
	none
Output:
	none
**************************************************************/
void NAND_FFS_showCacheStatus(void)
{
  int i;
  struct NAND_FFS_cacheInfo *status;

  sprintf(NAND_FFS_DebugString, "Cache status:");
  SprintStringLn(NAND_FFS_DebugString);

  for (i = 0; i < NAND_FFS_CACHE_BLOCK_NUM; i++)
  {
	status = NAND_FFS_CacheStatus[i];
	sprintf(NAND_FFS_DebugString, "    %03d: addr=0x%x", i, status);
	SprintStringLn(NAND_FFS_DebugString);
	sprintf(NAND_FFS_DebugString, "          block=%d, handle=%d, crc=0x%x, time=%u, flag=%x", status->block, status->handle, status->checksum, status->lastModTime, status->flag);
	SprintStringLn(NAND_FFS_DebugString);
  }

  return;
}



/*************************************************************
Function: NAND_FFS_showCacheStatusN
Description:
	show the cache status
Input:
	cacheNum - the specific cache number
Output:
	none
**************************************************************/
void NAND_FFS_showCacheStatusN(int cacheNum)
{
  struct NAND_FFS_cacheInfo *status;

  status = NAND_FFS_CacheStatus[cacheNum];
  sprintf(NAND_FFS_DebugString, "    %02d: block=%d, handle=%d, crc=0x%x, time=%u, flag=%x", cacheNum, status->block, status->handle, status->checksum, status->lastModTime, status->flag);
  SprintStringLn(NAND_FFS_DebugString);

  return;
}

#endif	// #ifdef NAND_FFS_USE_CACHE


#endif	// #ifdef NAND_FFS_DEBUG
#endif	// #ifdef NAND_FLASH_DISK_ID


⌨️ 快捷键说明

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