📄 mass_common.c
字号:
#include "tcc730.h"
#include "SMC.H"
#include "SMC_FS.H"
#include "SMC_FILE.H"
#if defined(MMC_INCLUDE)
#include "mmc_fs.h"
#include "mmc_io.h"
#endif
#if defined(DEBUG) || defined(MMC_DEBUG)
#include "mmc_debug.h"
#endif
#include "filesystem.h"
#include "mass_common.h"
#include "GENLIB.H"
///////////////////////////////////////////////////////////////////////////////
#if defined(DEBUG) || defined(MMC_DEBUG)
#define STATIC
#else
#define STATIC static
#endif
#ifndef UNREFERENCED_PARAMETER
#define UNREFERENCED_PARAMETER(__param) ((__param) = (__param))
#endif
#if !defined(__MMC_DEBUG_H__)
// defined in "mmc_debug.h"
#define MMC_ASSERT(__expr)
#define MMC_BREAK()
#define MMC_BREAK_EX(__expr)
#endif
#define ENTRY_ATTR_READONLY 0x01
#define ENTRY_ATTR_HIDDEN 0x02
#define ENTRY_ATTR_ARCHIVE 0x20
#pragma packed on
typedef struct __tag_Entry
{
unsigned char szShortName[11];
unsigned char bAttrib;
unsigned char bReserved1;
unsigned char bCreateTimeTenth;
unsigned short int wCreateTime;
unsigned short int wCreateDate;
unsigned short int wLastAccessDate;
unsigned short int wStartClusterHi;
unsigned short int wLastWriteTime;
unsigned short int wLastWriteDate;
unsigned short int wStartClusterLo;
unsigned long int dwFileSize;
} ENTRY_INFO;
#pragma packed off
int ConvertToEntryDate( int nYear, int nMonth, int nDay );
int ConvertToEntryTime( int nHour, int nMinute, int nSecond);
///////////////////////////////////////////////////////////////////////////////
//**********************************************************
//*
//* Global Variables
//*
//**********************************************************
#pragma memory=data_seg(TCC730_INTERNAL)
struct _FAT_Cache mFATCache;
#pragma memory=default
const unsigned MPX_SamplingFreq[9] = {
44100, 48000, 32000, // MPEG1
22050, 24000, 16000, // MPEG2
11025, 12000, 8000}; // MPEG2.5
// short t_bitrate[ID][bitrateIndex] when mpeg 1/2/2.5 layer3
const unsigned short MPX_Bitrate[45] = {
0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, // [V2 L2&L3]
0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, // [V1 L3]
0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384}; // layer2 [V1L2]
unsigned TCC730_FS_Check_Audio_Header(CONST_FAKE void* lpFrame, unsigned char* lpbMpegVer,
unsigned char* lpbLayer,
unsigned* lpnBitrate,
unsigned* lpnSampFreq)
{
CONST_FAKE unsigned char* lpFrame2;
unsigned nMpegVer, nLayer, nBitrate, nSampFreq;
lpFrame2 = (CONST_FAKE unsigned char*)lpFrame;
// MPEG Version, MPEG 1/2/2.5
*lpbMpegVer = nMpegVer = ((lpFrame2[1] & 0x10) >>3) | ((lpFrame2[1] & 0x08) >>3);
// Layer 2/3, MP2/MP3
*lpbLayer = nLayer = (lpFrame2[1] & 0x06) >> 1;
// Bitrate
nBitrate = (lpFrame2[2] & 0xf0) >> 4;
// Sampling Frequency
nSampFreq = *lpnSampFreq = (lpFrame2[2] & 0x0c) >> 2;
///////////////////////////////////////////
//
// Check Invalid Information
if (nMpegVer == 1 || nLayer == 0 || nLayer == 3 ||
nBitrate >= 15 || nBitrate == 0 || nSampFreq >= 3)
{
return FALSE;
}
switch(nMpegVer)
{
case ID_MPEG1:
*lpnSampFreq = MPX_SamplingFreq[0*3 + nSampFreq];
if (nLayer == LAYERIII)
*lpnBitrate = MPX_Bitrate[1*15 + nBitrate];
else if (nLayer == LAYERII)
*lpnBitrate = MPX_Bitrate[2*15 + nBitrate];
else
return FALSE;
break;
case ID_MPEG2:
*lpnSampFreq = MPX_SamplingFreq[1*3 + nSampFreq];
*lpnBitrate = MPX_Bitrate[0*15 + nBitrate];
break;
case ID_MPEG25:
*lpnSampFreq = MPX_SamplingFreq[2*3 + nSampFreq];
*lpnBitrate = MPX_Bitrate[0*15 + nBitrate];
break;
default :
return FALSE;
}
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////
//
//
// FUCNTIONS for Handling Directories
//
//
///////////////////////////////////////////////////////////////////////////////
unsigned long ChangeDirectory( int drive, char* pathname )
{
unsigned long dircluster;
#if defined(MMC_INCLUDE)
int nError;
#endif
switch(drive)
{
#if defined(MMC_INCLUDE)
case DRIVE_MMC :
nError = TCC730_MMC_ChangeDirectory(pathname, gTempBuf);
if (nError != 0)
dircluster = (unsigned long)(-1);
else
dircluster = TCC730_MMC_GetCurrentDirectory(NULL, 0, gTempBuf);
break;
#else
case DRIVE_SMC :
#endif
case DRIVE_NFL :
dircluster = SMC_FILE_ChangeDirectory( drive,
(unsigned char*)pathname,
gTempBuf );
break;
default :
dircluster = (unsigned long)(-1);
}
return dircluster;
}
unsigned long ChangeDirectoryByCode( int drive, code char* code_pathname )
{
unsigned long dircluster;
#if defined(MMC_INCLUDE)
int nError;
#endif
switch(drive)
{
#if defined(MMC_INCLUDE)
case DRIVE_MMC :
nError = TCC730_MMC_ChangeDirectoryByCode(code_pathname, gTempBuf);
if (nError != 0)
dircluster = (unsigned long)(-1);
else
dircluster = TCC730_MMC_GetCurrentDirectory(NULL, 0, gTempBuf);
break;
#else
case DRIVE_SMC :
#endif
case DRIVE_NFL :
dircluster = SMC_FILE_ChangeDirectoryByCode( drive,
(code unsigned char*)code_pathname,
gTempBuf );
break;
default :
dircluster=0xFFFFFFFF;
}
return dircluster;
}
unsigned long ChangeDirectoryByCluster( int drive, unsigned long cluster )
{
unsigned long dircluster;
#if defined(MMC_INCLUDE)
int nError;
#endif
switch(drive)
{
#if defined(MMC_INCLUDE)
case DRIVE_MMC :
nError = TCC730_MMC_ChangeDirectoryByCluster(cluster);
if (nError != 0)
dircluster = (unsigned long)(-1);
else
dircluster = TCC730_MMC_GetCurrentDirectory(NULL, 0, gTempBuf);
break;
#else
case DRIVE_SMC :
#endif
case DRIVE_NFL :
dircluster = SMC_FILE_ChangeDirectoryByCluster( drive,cluster );
break;
default :
dircluster=0xFFFFFFFF;
}
return dircluster;
}
unsigned long MakeDirectory( int drive, char* pathname )
{
unsigned long dircluster;
#if defined(MMC_INCLUDE)
int nError;
#endif
switch( drive )
{
#if defined(MMC_INCLUDE)
case DRIVE_MMC:
nError = TCC730_MMC_MakeDirectory(pathname, &dircluster, gTempBuf);
if (nError != 0)
dircluster = (unsigned long)(-1);
break;
#else
case DRIVE_SMC:
#endif
case DRIVE_NFL:
dircluster = SMC_FILE_MakeDirectory( drive,
(unsigned char*)pathname,
gTempBuf );
break;
default :
dircluster = 0xFFFFFFFF;
}
return dircluster;
}
unsigned long MakeDirectoryByCode( int drive, code char* code_pathname )
{
unsigned long dircluster;
#if defined(MMC_INCLUDE)
int nError;
#endif
switch( drive )
{
#if defined(MMC_INCLUDE)
case DRIVE_MMC:
nError = TCC730_MMC_MakeDirectoryByCode(code_pathname, &dircluster, gTempBuf);
if (nError != 0)
dircluster = (unsigned long)(-1);
break;
#else
case DRIVE_SMC:
#endif
case DRIVE_NFL:
dircluster = SMC_FILE_MakeDirectoryByCode( drive,
(code unsigned char*)code_pathname,
gTempBuf );
break;
default :
dircluster = 0xFFFFFFFF;
}
return dircluster;
}
unsigned long GetCurrentDirectory( int drive, char* pathname, int maxlen )
{
unsigned long dircluster;
switch( drive )
{
#if defined(MMC_INCLUDE)
case DRIVE_MMC:
dircluster = TCC730_MMC_GetCurrentDirectory(pathname, maxlen, gTempBuf);
break;
#else
case DRIVE_SMC:
#endif
case DRIVE_NFL:
dircluster = SMC_FILE_GetCurrentDirectory( drive,
(unsigned char*)pathname,
maxlen,gTempBuf );
break;
default :
dircluster = 0xFFFFFFFF;
}
return dircluster;
}
///////////////////////////////////////////////////////////////////////////////
//
//
// CALLBACK FUCNTIONS for Accessing entries
//
//
///////////////////////////////////////////////////////////////////////////////
//
// unsigned char szShortName[11];
// unsigned char bAttrib; // [ Changeable ]
// unsigned char bReserved1;
// unsigned char bCreateTimeTenth;
// unsigned short int wCreateTime; // [ Changeable ]
// unsigned short int wCreateDate; // [ Changeable ]
// unsigned short int wLastAccessDate; // [ Changeable ]
// unsigned short int wStartClusterHi;
// unsigned short int wLastWriteTime; // [ Changeable ]
// unsigned short int wLastWriteDate; // [ Changeable ]
// unsigned short int wStartClusterLo;
// unsigned long int dwFileSize;
//
// ENTRY_ATTR_READONLY 0x01
// ENTRY_ATTR_HIDDEN 0x02
// ENTRY_ATTR_ARCHIVE 0x20
//
///////////////////////////////////////////////////////////////////////////////
void GetCurrentFileTime(int* lpnYear, int* lpnMonth, int* lpnDay,
int* lpnHour, int* lpnMinute, int* lpnSecond)
{
// Year, Valid range 1980 ~ 2107
// Month, Valid range 1 ~ 12
// Day, Valid range 1 ~ 31
// Hour, Valid range 0 ~ 23
// nMinute, Valid range 0 ~ 59
// nSecond, Valid range 0 ~ 59
*lpnYear = 2002;
*lpnMonth = 12;
*lpnDay = 28;
*lpnHour = 11;
*lpnMinute = 10;
*lpnSecond = 0;
}
// Called at Creating a File
MASS_CALLBACK ChangeEntryofCreateFileAtOpen( void* EntryofFile )
{
ENTRY_INFO* lpEntry;
int nYear, nMonth, nDay;
int nHour, nMinute, nSecond;
lpEntry = EntryofFile;
GetCurrentFileTime(&nYear, &nMonth, &nDay, &nHour, &nMinute, &nSecond);
//lpEntry->bAttrib |= ENTRY_ATTR_ARCHIVE;
lpEntry->wCreateTime = ConvertToEntryTime( nHour, nMinute, nSecond );
lpEntry->wCreateDate = ConvertToEntryDate( nYear, nMonth, nDay );
return 1;
}
// Called at Close a File
MASS_CALLBACK ChangeEntryofCreateFileAtClose( void* EntryofFile )
{
ENTRY_INFO* lpEntry;
int nYear, nMonth, nDay;
int nHour, nMinute, nSecond;
lpEntry = EntryofFile;
GetCurrentFileTime(&nYear, &nMonth, &nDay, &nHour, &nMinute, &nSecond);
lpEntry->wLastAccessDate = ConvertToEntryDate( nYear, nMonth, nDay );
lpEntry->wLastWriteTime = ConvertToEntryTime( nHour, nMinute, nSecond );
lpEntry->wLastWriteDate = ConvertToEntryDate( nYear, nMonth, nDay );
return 1;
}
// Called at Make a Directory
MASS_CALLBACK ChangeEntryofCreateDirectory( void* EntryofDir )
{
ENTRY_INFO* lpEntry;
int nYear, nMonth, nDay;
int nHour, nMinute, nSecond;
lpEntry = EntryofDir;
GetCurrentFileTime(&nYear, &nMonth, &nDay, &nHour, &nMinute, &nSecond);
//lpEntry->bAttrib |= ENTRY_ATTR_ARCHIVE;
lpEntry->wCreateTime = ConvertToEntryTime( nHour, nMonth, nSecond );
lpEntry->wCreateDate = ConvertToEntryDate( nYear, nMonth, nDay );
lpEntry->wLastWriteTime = ConvertToEntryTime( nHour, nMonth, nSecond );
lpEntry->wLastAccessDate = ConvertToEntryDate( nYear, nMonth, nDay );
lpEntry->wLastWriteDate = ConvertToEntryDate( nYear, nMonth, nDay );
return 1;
}
///////////////////////////////////////////////////////////////////////////////
// Miscellaneous function
int ConvertToEntryDate( int nYear, int nMonth, int nDay )
{
int nDate;
// Year, Valid range 1980 ~ 2107
// Month, Valid range 1 ~ 12
// Day, Valid range 1 ~ 31
if ( (nYear<1980)||(nYear>2107) ) return 0;
if ( (nMonth<1)||(nMonth>12) ) return 0;
if ( (nDay<1)||(nDay>31) ) return 0;
nDate = nDay
+ (nMonth << 5)
+ ((nYear - 1980) << 9);
return SWAP16(nDate);
}
int ConvertToEntryTime( int nHour, int nMinute, int nSecond)
{
int nTime;
// Hour, Valid range 0 ~ 23
// nMinute, Valid range 0 ~ 59
// nSecond, Valid range 0 ~ 59
if ( nHour>23 ) return 0;
if ( nMinute>59 ) return 0;
if ( nSecond>59 ) return 0;
nTime = nSecond / 2
+ (nMinute << 5)
+ (nHour << 11);
return SWAP16(nTime);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -