www.pudn.com > MP3DIY.rar > userinit.c
//===========================================================
// Project Name(项目名称): SPCA755 rebuild
// File Name(模块名称): userinit.c
// Built Date(创建日期):2004-09-14
// Abstract(模块描述): 用户初始化功能函数模块
// Revision History(版本信息):
// Rev Date Author Comment(修改说明)
// 1.0 2004-09-14 XYQ created
//============================================================
#include "..\userdefine.h"
#include "userinit.h"
#include "user.h"
#include "interrupt.h"
#include "main.h"
//////////////////////////////hst
//extern void LCD501_Clear_ALL2();
//////////////////////////////////
//================================================================================================
code U8 User_Dir[K_USER_DIR_NUM][12] =
{
'D','V','R',0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x10,
};//==================注意:目录名字母必须大写=====================================
#define USER_SETTING_CHECKSUM_LENTH 10
code U8 LogFileName[] =
{
'U','S','E','R','S','E','T',' ','L','O','G'
};
//***************************************** USB DESCRIPTOR ******************************************
//================================================================================================
code U8 K_MSDC_DeviceDescriptor[] =
{
//-------------------------------------------------------------------
//TotalLength = 0x0012 byte
//-------------------------------------------------------------------
//Device (0x12 byte)
0x12, //bLength: 0x12 byte
0x01, //bDescriptorType: DEVICE
0x10, 0x01, //bcdUSB: version 1.10
0x00, //bDeviceClass: independent interfaces
0x00, //bDeviceSubClass: 0
0x00, //bDeviceProtocol: class specific protocols NOT used on device basis
0x40, //bMaxPacketSize0: maximum packet size for endpoint zero
0xFC, 0x04, //idVendor: vendor ID
0x7A, 0x75, //idProduct: product ID (for MSDC)
0x00, 0x01, //bcdDevice: device release number in BCD
0x01, //iManufacturer: index of string
0x02, //iProduct: index of string
0x00, //iSerialNumber: index of string
0x01, //bNumConfigurations: 1 configuration
};
//================================================================================================
code U8 K_ManufacturerString[] =
{
//----------
//0x20 Bytes
//----------
0x20, //bLength
0x03, //bDescriptorType: STRING
'S', 0x00, //bString: Sunplus Co Ltd
'u', 0x00,
'n', 0x00,
'p', 0x00,
'l', 0x00,
'u', 0x00,
's', 0x00,
' ', 0x00,
'C', 0x00,
'o', 0x00,
' ', 0x00,
'L', 0x00,
't', 0x00,
'd', 0x00,
' ', 0x00,
};
//================================================================================================
code U8 K_ProductString[] =
{
//----------
//0x30 Bytes
//----------
0x30, //bLength
0x03, //bDescriptorType: STRING
'S', 0x00, //bString: Sunplus SPCA755/SPCA757
'u', 0x00,
'n', 0x00,
'p', 0x00,
'l', 0x00,
'u', 0x00,
's', 0x00,
' ', 0x00,
'M', 0x00,
'u', 0x00,
'l', 0x00,
't', 0x00,
'i', 0x00,
'M', 0x00,
'e', 0x00,
'd', 0x00,
'i', 0x00,
'a', 0x00,
' ', 0x00,
'd', 0x00,
'i', 0x00,
's', 0x00,
'k', 0x00,
};
//================================================================================================
code U8 K_SerialNumberString[] =
{
//----------
//0x1a Bytes
//----------
//----------
0x12, //bLength
0x03, //bDescriptorType: STRING
'0', 0x00, //bString: 01.00.00
'1', 0x00,
'.', 0x00,
'0', 0x00,
'0', 0x00,
'.', 0x00,
'0', 0x00,
'0', 0x00,
};
//================================================================================================
code U8 K_ScsiVendorInformation[8] =//注意长度不能改动
{
'S', 'u', 'n', 'p', 'l', 'u', 's', 0x20,
};
//================================================================================================
code U8 K_ScsiProductIdentification[16] =//注意长度不能改动
{
'M', 'u', 'l', 't', 'i', 'M', 'e', 'd',
'i', 'a', '-', 'D', 'i', 's', 'k', 0x20,
};
//================================================================================================
code U8 K_ScsiProductRevisionLevel[4] =//注意长度不能改动
{
'1', '.', '0', '0',
};
//-----------------------------------------------------------------------------------
code U8 gc_CustomerID1 = 0x00;
code U8 gc_CustomerID2 = 0x00;
code U8 gc_CustomerID3 = 0x00;
//----------------------------------------------------------------------------------
xdata U32 gdw_USER_DirClus[K_USER_DIR_NUM];
data U8 gc_SystemStateMode;
xdata U8 gc_KeyLockState;
xdata U8 gc_PLAY_DPC;
xdata U8 gc_DSP_Volume;
xdata U8 gc_PlayEQMode;
data U8 gc_UIMode;
xdata U8 G_Current_Contrast;
xdata U16 gw_Code;
xdata U8 gc_UserBacklightLevel;//lyh add
xdata U8 gc_LrcFileName_Exist;
//================================================================================================
void User_initialize(void);
void User_initialize2(void);
//void User_initialize3(void);//lyh add
void L2_ConfigureIO(void);
//===================================================================================================
void User_initialize2()
{
U8 i;
gw_Code = SYS_VersionCode;
gw_Code = USB_VersionCode;
gw_Code = Nand_VersionCode;
gw_Code = DSP_VersionCode;
gw_Code = ID3_VersionCode;
gw_Code = LRC_VersionCode;
gw_Code = Dos_VersionCode;
#ifdef SUPPORT_MLUN
gw_Code = Mlun_VersionCode;
#endif
#ifdef SUPPORT_SELECTIVE_FUNC
gw_Code = Selective_VersionCode;
#endif
// Usb_WriteProtectInitio(DbgP11);
gc_SecondTimer = SECONDTIMER_VALUE;
gc_basetimerx4= BASETIMERX4_VALUE;//lyh add
// gc_CardTotal = K_CARD_TOTAL;
gc_DSP_Volume = 21; // Volume
gc_PlayEQMode = 0; // EQ
gc_PLAY_DPC = 12; // Speed control
G_CurrentHZK = Language_GB2312;
gc_UserBacklightLevel = 0; //lizhn debug
gc_UIMode=0; // UIMode = 0x00 is music file
// UIMode = 0x01 is record file
gc_LrcFileName_Exist = 0;
gc_RECLowBattValue = K_REC_MINBATTERYVALUE;
gc_SystemStateMode = SYSTEM_STATE0_IDLE;//default idle state
gc_DispTime[0] = 0;
gc_DispTime[1] = 0;
gc_DispTime[2] = 0;
MlunSequence[0] = 0;
MlunSequence[1] = 1;
gc_KeyLockState = 0;
gc_KeyValue = 0;
SPLC501_Init();
SPLC501_Disp_MyMP3Logo();
SPLC501_ShowCompanyLogo();
SPLC501_Disp_TASOLogo();
#ifdef SUPPORT_MLUN
// gb_MlunEnable = 1;
#else
// gb_MlunEnable = 0;
#endif
#if (K_CARD_TYPE == 0x03)
SMC_STORAGE_Initialize();
if (gc_DOS_ErrorStatus = SD_STORAGE_Initialize())//try to initialize SD card
#endif
{//if SD card is not exist
gc_DOS_ErrorStatus = SMC_STORAGE_Initialize();//try to initialize SMC
}
if (gc_DOS_ErrorStatus == 0)
{
USER_FindDir(0,gdw_DOS_RootDirClus);//detect DVR dir
}else{
UI_StorageIsError();//hst add
if(!test_nandmem()){
SPLC501_Printf(0x6,0,"nandmem err");
}
ldelay(5);
gc_MenuHZK=0;
gdw_UserRsvSectorNum = 32L * 55;//user reserve sector number
UI_Exe_Format();
}
for(i=0;i<10;i++)
{
USER_DelayDTms(250);
}
if(!USB_PlugDetect())
{
//battery port power
// if(LockPin_Locked)//xyq040210 locked lss 060612
if(0)//xyq040210 locked
{
unsigned char i;
for(i=0;i<12;i++)
{
USER_DelayDTms(250);
}
POWER_CTRL_LOW;//DbgP30=0;//Low for Power Off
while(1);
}
}
//用户可以根据需要编写自己的字库写入程序和检测,去掉下列两个函数
if (gc_CurrentCard == CURRENT_MEDIA_NAND && gc_DOS_ErrorStatus == 0)
{
X_MoveFiletoReserveBLK(RESERVEBLOCK_FILETYPE_USERDATA);//将HZK文件写入保留块 //lss 060613
X_MoveFiletoReserveBLK(RESERVEBLOCK_ISP_FILE);//将ISP文件写入保留块 //lijh 050314
X_DetectHZK();//字库检测
}
USER_LogFile_ReadWrite(0);//read log file for user setting
if (gdw_USER_DirClus[0] != 0)
{//if DVR is exist
gs_File_FCB[1].dw_FDB_StartCluster = gdw_USER_DirClus[0];
gbt_FindFlag = 0;//当要第一次查找或改变查找文件类型时,都需要将该值清0
DOS_Search_File(0x10,1,0x10);
DOS_Search_File(0x12,1,0x10);
}
gs_File_FCB[0].dw_FDB_StartCluster = gdw_DOS_RootDirClus;
gbt_FindFlag = 0;//当要第一次查找或改变查找文件类型时,都需要将该值清0
DOS_Search_File(0,0,0x10);//全盘检索音乐文件
DOS_Search_File(0x01,0,0x10);//向下检索一个音乐文件
if(gw_FileTotalNumber[gc_UIMode])
{
gw_FileIndex[gc_UIMode] = 1;
}
else
{
gw_FileIndex[gc_UIMode] = 0;
}
gc_KeyValue = 0;
gc_ADCOldKey = 0;
}
//===========================================================================================
void User_initialize(void)
{
L2_ConfigureIO();//set GPIO input or output
User_Set_P3Mode(0x3D);
POWER_CTRL_HIGH;//DbgP30=1;//open power control
//用户保留块大小定义,最大不能超过8MB,以扇区为单位
gdw_UserRsvSectorNum = 32L * 55;//user reserve sector number
USER_Set_SYSInformation(SYSI_CREATE_DATE,0x0021);//create file date
USER_Set_SYSInformation(SYSI_CREATE_TIME,0x0021);//create file time
}
//===========================================================================================
//================================================================================================
void User_initialize4_UI(void)
{
gb_LowBatt_State=0; //how to change it? change it in void LCD501_Disp_Battery()
gc_EVENT=0;
gc_SPressingKey = 0;
gc_SKeyState = 0;
ADCOldKey1 = 0;
gc_SKeyHoldCnt = 0;
gc_Busy_Timer=0;
gc_AB_Cnt=0;
gb_PlayPause=FALSE;//signal of pause
gb_Storage_Full=0;//
gb_UIPostError=0;
gc_fileend=TRUE; //...
G_Current_Contrast = 2;//...
G_W_OldTime=0;
G_DISPLAY_TotalSec=0;
gc_Menu_State = 0;
gc_MenuHZK=0;
gb_UIEvent=FALSE;
gc_sts=9;
gc_USR_PowerOffCount = 1;//lyh add
gw_PowerOffTimer=1440;
gc_Battery_Detect_Timer=0;
gc_Battery_Level=5;//how to ....
gc_DVRE_Mode_Selected=0;
gc_PlaySequenceMode = REP_ALL_MODE;
gc_USB_Connect=0;
gb_USB_PowerPlug_Interrupt=0;
gb_LrcGetTimeOrNot=0;
gc_PlayMode=0;//lyh add
gw_DispFileName_ByteOffset=0;
gb_DisplayEvent_Happened=1;
gw_PowerOffTimer=1440;
}
//===========================================================================================
//================================================================================================
void L2_ConfigureIO(void)
{
U8 tc_P3Value;
User_Set_P1Mode(0xFF);
P1 &=0x1F;
User_Set_P3Mode(0x30);
P3 &=0xC7;
//SPCA759
User_Set_MuxPinFunc(IOREG_MUX_PIN_VALUE);
User_Set_GPIOMode(IOREG_GPIOOE_6_0_VALUE);
User_Set_P1Mode(IOREG_P1OESEL_VALUE);
User_Set_P3Mode(IOREG_P3OESEL_VALUE);
tc_P3Value = User_Read_P3Mode();
tc_P3Value|= 0x02;
User_Set_P3Mode(tc_P3Value);
}
//-------------------------------------------------------------------------------
//建议该函数只在开机和关机时使用,开机读取日志文件,关机保存日志文件,不要在其余位置调用
//-------------------------------------------------------------------------------
U8 USER_LogFile_ReadWrite(bit tbt_ReadOrWrite)
{//建议该函数只在开机和关机时使用,开机读取日志文件,关机保存日志文件,不要在其余位置调用
//开机读取日志文件应该在文件检索之前
U8 tc_Status;
U8 tc_CheckSum = 0;
U8 tc_Loop;
bit tbt_SaveFlag;//lijh 050627 add
tbt_SaveFlag = gbt_FindFlag;//lijh 050627 add
gbt_FindFlag = 0;
if ((gdw_USER_DirClus[0] != 0) && (gc_DOS_ErrorStatus == 0))
{//DVR dir is exist
HSTPrint("find DVR\n");//
gs_File_FCB[2].dw_FDB_StartCluster = gdw_USER_DirClus[0];
}
else
{//DVR dir is no exist and not to create log file
HSTPrint("no find DVR\n");
X_Get_DefaultUserValue();
return 1;
}
EXT_NameC[0]=1;
EXT_NameC[1]='L';
EXT_NameC[2]='O';
EXT_NameC[3]='G';
//search user log file in specify dir
tc_Status = DOS_Search_File(0x13,2,0x10);
gbt_FindFlag = tbt_SaveFlag;
HSTPrint("tc_sts=%bx\n",tc_Status);
if (tc_Status == 0x00)
{//find log file
DOS_Open_File(2, 2, 0);//open log file,and get the startcluster
DOS_Read_File(2);
DOS_Close_File(2,0,0);
//detect log file flag
if (gc_PlayRecordDataBuf[510] == 0x55 && gc_PlayRecordDataBuf[511] == 0xaa)
{//"55aa"flag is exist
if (tbt_ReadOrWrite)
{//save(modify) log file
USER_FillSettingInfo();//fill gc_PlayRecordDataBuf[]
//get the checksum of the first 10 byte
for (tc_Loop = 0; tc_Loop < USER_SETTING_CHECKSUM_LENTH; tc_Loop ++)
tc_CheckSum += gc_PlayRecordDataBuf[tc_Loop];
gc_PlayRecordDataBuf[500] = tc_CheckSum;
DOS_Open_File(2, 2, 0);//open log file,and get the startcluster
DOS_Write_File(2);
DOS_Close_File(2,0,0);
}
else
{//read log file
//get the checksum of the first 10 byte
for (tc_Loop = 0; tc_Loop < USER_SETTING_CHECKSUM_LENTH; tc_Loop ++)
tc_CheckSum += gc_PlayRecordDataBuf[tc_Loop];
//detect the check sum
if (tc_CheckSum == gc_PlayRecordDataBuf[500])
{//checksum is ok, get the setting info
USER_GetSettingInfo();
}
else
{
X_Get_DefaultUserValue();//get default value
}
}
}
else
{//have no "55aa"flag,is not real log file
if (tbt_ReadOrWrite)
{//
USER_FillSettingInfo();
//get the checksum of the first 10 byte
for (tc_Loop = 0; tc_Loop < USER_SETTING_CHECKSUM_LENTH; tc_Loop ++)
tc_CheckSum += gc_PlayRecordDataBuf[tc_Loop];
gc_PlayRecordDataBuf[500] = tc_CheckSum;//write checksum byte
gc_PlayRecordDataBuf[510] = 0x55;//mark "0x55"
gc_PlayRecordDataBuf[511] = 0xaa;//mark "0xaa"
DOS_Open_File(2, 2, 0);//open log file,and get the startcluster
DOS_Write_File(2);
DOS_Close_File(2,0,0);
}
else
{
X_Get_DefaultUserValue();//get default value
}
}
}
else if (tbt_ReadOrWrite)
{//when write mode ,no find log file,create log file
//ceate log file in Root Dir
if (DOS_Open_File(2,1,0))
{//disk is full
gc_DOS_ErrorStatus = DOS_ERROR_DISK_FULL;
return 1;
}
USER_FillSettingInfo();//fill gc_PlayRecordDataBuf[]
//get the checksum of the first 10 byte
for (tc_Loop = 0; tc_Loop < USER_SETTING_CHECKSUM_LENTH; tc_Loop ++)
tc_CheckSum += gc_PlayRecordDataBuf[tc_Loop];
gc_PlayRecordDataBuf[500] = tc_CheckSum;//write checksum byte
gc_PlayRecordDataBuf[510] = 0x55;//mark "0x55"
gc_PlayRecordDataBuf[511] = 0xaa;//mark "0xaa"
DOS_Write_File(2);//create log file
DOS_Close_File(2,1,LogFileName);
}
else
X_Get_DefaultUserValue();//get default value
return 0;
}