📄 main.c
字号:
/*++
Copyright (c) 2001 Sunplus Technology Co., Ltd.
Module Name:
main.c
Abstract:
Module related to main routine
Environment:
Keil C51 Compiler
Revision History:
08/28/2001 Chi-Yeh Tsai created
--*/
//=============================================================================
//Header file
//=============================================================================
#include "general.h"
#include "main.h"
#include "initio.h"
#include "setmode.h"
#include "storage.h"
#include "sensor.h"
#include "timer.h"
#include "ui.h"
#include "isp.h"
#include "bulkout.h"
#include "cardlink.h"
//richie@1211
#include "ctlsetup.h"
#include "doslink.h"
#include "uiflow.h"
//richie@mi 0409
#include "usbmsdc2.h"
UCHAR USBMSDC_ReadWriteData(void);
UCHAR USBMSDC_SendStatus(void);
//richie@si0418
#include "sidcinit.h"
#include "sidcmain.h"
xdata ULONG G_ulExifThumbAddr;
xdata ULONG G_ulExifThumbSize;
//patch4.3@richie@zo
extern xdata USHORT G_usZoomOSDTimer;
//patch4.4@richie@dsi begin
#if ( DOSRAM_OPTION == 1 )
extern xdata ULONG G_ulDRAMSTORFAT1AddrTemp;
#endif
//Joe@2003.2.25 10:09 add begin
#include "JoeToEvb.h"
extern xdata UCHAR G_FlashStatus;
extern code unsigned char *LOW_BATTERY[];
extern xdata int Tidx;
//Joe@2003.2.25 10:09 add end
//=============================================================================
//Symbol
//=============================================================================
//-----------------------------------------------------------------------------
//Constant
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//Variable
//-----------------------------------------------------------------------------
//bit flag
data BIT G_btSoftwareResetFlag = 0;
data BIT G_btStopStream = 0;
//lock fields of USB device request
data UCHAR G_bRequestLock = 0;
data UCHAR G_bRequestLog = 0;
data USHORT G_wIndexLock = 0;
data USHORT G_wValueLock = 0;
//state and error code
xdata UCHAR G_ucState;
xdata UCHAR G_ucState2; //cch@10/15
xdata UCHAR G_ucState3; //cch@10/15
xdata ULONG G_ulErrorCode;
//type of storage used
xdata UCHAR G_ucStorageType;
//command and data buffer of control pipe and bulk in/out pipes
xdata UCHAR G_ucCtrlCommand[K_CtrlCommandSize];
xdata UCHAR G_ucCtrlData[K_CtrlDataSize];
xdata UCHAR G_ucStorCommand[K_StorCommandSize];
#if ( SIMULATE == 1 ) // WWWW
xdata UCHAR G_ucStorData[K_DMA_MaxSize];
#else
xdata UCHAR G_ucStorData[K_DMA_MaxSize] _at_ 0x1c00; //ada@0118
#endif
/*++
xdata UCHAR G_ucStor2Command[K_Stor2CommandSize];
xdata UCHAR G_ucStor2Data[K_Stor2DataSize];
--*/
//pointer to data buffer
UCHAR *G_pucCtrlDataPointer; //for both CODE and DATA area
xdata UCHAR *G_pucStorDataPointer;
/*++
xdata UCHAR *G_pucStor2DataPointer;
--*/
//storage interface N belongs to which USB class
xdata UCHAR G_ucStorIntrf1Class;
xdata UCHAR G_ucStorIntrf2Class;
xdata UCHAR G_ucPktStorIntrf; //current packet belongs to which storage interface
//richie
data BIT G_btBulkIntr;
//patch4.4@richie@usbvd
data BIT G_btEP0Intr;
//richie@ae0305
xdata UCHAR G_ucStrobeCnt;
xdata UCHAR G_ucStrobeRdy;
//patch4.4@richie@flip
xdata UCHAR G_ucFlip;//bit1:H-flip, bit2:V-flip
//------------------------------------------------------------------------------
//L1 Global variables
//------------------------------------------------------------------------------
//ISP
xdata UCHAR G_ISP;
xdata ULONG G_ISPDRAMAddr;
xdata ULONG G_ISPROMAddr;
xdata ULONG G_ISPSecAddr;
xdata USHORT G_ISPSecCnt;
//patch4.3@richie@je0531 begin
data UCHAR G_ucISPCheck1;
data UCHAR G_ucISPCheck2;
//patch4.3@richie@je0531 end
//device component
xdata UCHAR G_SensorID; //TBD by YGLiu
//patch5.0@richie@sdram mapping mark
//xdata UCHAR G_CardType; //TBD by WZH
xdata UCHAR G_AudioModuleType; //0:Buildin audio CODEC, 1: External AC-97 Codec
xdata UCHAR G_DisplayType; //TBD by Prover
//mode setting
xdata UCHAR G_CamMode; //0:Idle, 1:Preview, 2:DSC, 3: VideoClip, 4:PC-camera, 5:Playback
//xdata UCHAR G_QtableIndex; //0: Q50, 1:Q70, 2:Q80, 3:Q85, 4:Q88, 5:Q90, 6:Q92, 7:Q95 //ada@0225
xdata UCHAR G_QtableIndex; //0: Q50, 1:Q70, 2:Q80, 3:Q85, 4:Q88, 5:Q90, 6:Q92, 7:Q95
xdata UCHAR G_DRAMint;
//user interface
xdata USHORT G_ObjectID; //Current object ID
xdata UCHAR G_ObjectType; //Current object type, 0: still image, 1: videoclip with audio, 2: videoclip w/o audio 3: audio file
xdata USHORT G_KeyState; //UI key state, this variable is set by the polling function or sent by the USB vendor command
//component setting
xdata UCHAR G_FrameRate;
xdata USHORT G_Hsize; //Full image width of the sensor
xdata USHORT G_Vsize; //Full imgage height of the sensor
xdata USHORT G_MHSize; //Monitor mode H size
xdata USHORT G_MVSize; //Monitor mode V size
xdata USHORT G_DSPHsize; //Display buffer horizontal size
xdata USHORT G_DSPVsize; //Display buffer vertical size
xdata UCHAR G_3ACount;
xdata UCHAR G_3AFlag;
xdata UCHAR G_PVZFactor; //Current zoom ratio in the preview mode, this ratio is used for later capture
xdata UCHAR G_PBZFactor; //Current zoom ratio in the playback mode.
xdata UCHAR G_PBID; //DSC playback ID
xdata UCHAR G_GOSDID; //Graphic OSD ID
//SDRAM arrangement
xdata ULONG G_AudioAddr; //Audio buffer starting address
xdata ULONG G_FreeAddr; //Fress SDRAM space starting address (this space is used as temprary buffer during camera operation)
xdata ULONG G_RawImageBufAddr; //patch4.2@yichang@0513 for continue snapping
//date/time
xdata UCHAR G_DateStamp; //0: Date stamp function is off, 1: date stamp function is on
xdata struct DATESTC G_DATEINFO;
//USB
xdata UCHAR G_TurnOnBulkInEn;
xdata UCHAR G_TurnOnBulkOutEn;
xdata UCHAR G_TurnOnIntInEn;
xdata UCHAR G_TurnOnBulkIn2En;
xdata UCHAR G_TurnOnBulkOut2En;
xdata UCHAR G_TurnOnIntIn2En;
xdata ULONG G_BulkSize;
xdata ULONG G_BulkOutSize;
xdata ULONG G_BulkDRAMAddr;
xdata UCHAR G_LastBulk;
xdata ULONG G_BulkFlash;
xdata ULONG G_BulkFlashAddr;
xdata ULONG G_BulkSRAMAddr;
//testing
xdata UCHAR G_L1_ModuleID;
xdata UCHAR G_L2_ModuleID;
xdata UCHAR G_L1_FuncID;
xdata UCHAR G_L2_FuncID;
xdata ULONG G_ArgBuf[16];
//For Videoclip
xdata UCHAR G_ABVLCIntFlag;
xdata ULONG G_AVLCSize;
xdata ULONG G_BVLCSize;
//patch4.4@richie@sus
xdata UCHAR G_ucSuspend;
//patch4.5@richie@checksum isp begin
#if (ISPCHECKSUM_OPTION)
xdata USHORT G_usISPCheckSum;
#endif
//patch4.5@richie@checksum isp end
//patch4.5@richie@vender info begin
xdata UCHAR G_ucMSDC_CARD;
xdata UCHAR G_ucMSDC_BUILT_IN;
/*
xdata UCHAR G_ScsiVendorInformation[8] =
{
'S', 'u', 'n', 'p', 'l', 'u', 's', 0x20,
};
xdata UCHAR G_ScsiProductIdentification[16] =
{
'S', 'u', 'n', 'p', 'l', 'u', 's', ' ',
'S', 'P', 'C', 'A', '5', '3', '3', 0x20,
};
xdata UCHAR G_ScsiProductRevisionLevel[4] =
{
'1', '.', '0', '0',
};
*/
//patch4.5@richie@vender info end
//patch3.2@ada@0401 For file system refreshing when back from mass storage
//For system refreshing when back from mass storage
xdata UCHAR G_MassStorage_Mode;
//patch4.2@ada@0527 for key scan
xdata UCHAR G_MainLoopCount;
// wyeo@0521, patch 4.2
#if (NANDF_OPTION == 1 && CARD_OPTION == 1)
// when 1, use 0x5B cammand to test nand reserve block
// sjould 0 to reduce code size
#define K_TEST_RESERVE_BLOCK 0
BYTE TestReserveBlock(void);
#endif
//=============================================================================
//Program
//=============================================================================
//-----------------------------------------------------------------------------
//main
//-----------------------------------------------------------------------------
void main(void) USING_0
/*++
Routine Description:
main routine
Arguments:
none
Return Value:
none
--*/
{
XBYTE[0x2c00] = 0x0f; //SRAM enable, rompage/rampage enable
spca533main();
}
//-----------------------------------------------------------------------------
//spca533main
//-----------------------------------------------------------------------------
void spca533main(void) USING_0
/*++
Routine Description:
main routine
Arguments:
none
Return Value:
none
--*/
{
//ULONG VidFrameTime;
//patch5.0@richie@usbisp begin
XBYTE[0x2C00] &= 0xEF; //shadow disable;
//patch5.0@richie@usbisp end
if (XBYTE[0x2c00] & 0x10)
{
DbgPrint("spca533main: ISP is completed\n");
}
//patch4.3@richie@je0531 begin
G_ucISPCheck1 = 0x55;
G_ucISPCheck2 = 0x00;
//patch4.3@richie@je0531 end
//patch4.5@richie@checksum isp begin
#if (ISPCHECKSUM_OPTION)
G_usISPCheckSum = 0x00;
#endif
//patch4.5@richie@checksum isp end
XBYTE[0x2c00] = 0x0f;
if(L2K_CPUP1 == 1) //P1 USED AS LOW BYTE ADDR ;dlchiou - 2002/10/17 14:14
{
#if(TURNKEY_OPTION == 1)
XBYTE[0x201a] = 0x07;
#else
XBYTE[0x201a] = 0x0f;
#endif
}
EA = 0;
EX0 = 0;
P1 = 0x00;
INITIO_Initialize();
P1 = 0xFF;
//patch4.4@richie@sus begin
//add for suspend resume
//set config change intr enable
G_ucSuspend = 0;
XBYTE[0x25c0] = 0;
XBYTE[0x25d0] |= 0x20;
//resume and suspend intr enable
//XBYTE[0x25d0] |= 0x90;
//patch4.4@richie@sus end
G_btSoftwareResetFlag = 0;
MAIN_LockLoop();
}
//-----------------------------------------------------------------------------
//MAIN_LockLoop
//-----------------------------------------------------------------------------
void MAIN_LockLoop(void) USING_0
/*++
Routine Description:
main lock loop, where bRequest denotes
0x0X register read/write without deferred procedure call
0x1X ISP Related function
0x2X miscellaneous function without deferred procedure call
0x3X miscellaneous function with deferred procedure call
0x4X SDRAM related function
0x5X general storage related function
Arguments:
none
Return Value:
none
--*/
{
BYTE sts; // WWW3
while (G_btSoftwareResetFlag == 0)
{
MAIN_PreDpc();
switch (G_bRequestLock)
{
//---------------------------------------------------
//0x0X - Register Read/Write without Deferred Procedure Call
//---------------------------------------------------
//---------------------------------------------------
//0x1X - ISP Related Function
//---------------------------------------------------
case 0x10:
//-------------------------------------------
//0x10 - update flash ROM code through ISP
//-------------------------------------------
MAIN_EventPreDpc();
MAIN_EventPostDpc();
break;
case 0x11:
//-------------------------------------------
//0x11 - L2 Function Test
//-------------------------------------------
MAIN_EventPreDpc();
MAIN_EventPostDpc();
break;
//---------------------------------------------------
// 0x2X - Miscellaneous Function without Deferred Procedure Call
//---------------------------------------------------
//---------------------------------------------------
// 0x3X - Miscellaneous Function with Deferred Procedure Call
//---------------------------------------------------
case 0x30:
//-------------------------------------------
//0x30 - Software Reset
//-------------------------------------------
MAIN_EventPreDpc();
INITIO_SoftwareReset();
G_btSoftwareResetFlag = 1;
MAIN_EventPostDpc();
break;
case 0x31: //cch@10/18
//-------------------------------------------
//0x31 - Set Idle / PC Camera Mode
// G_wIndexLock = 0 - Idle mode
// 4 - PC Camera
//-------------------------------------------
MAIN_EventPreDpc();
SETMODE_ChangeCameraMode((UCHAR)G_wIndexLock);
INITIO_SetCameraSize(K_MODE_PCCAM);
MAIN_EventPostDpc();
break;
case 0x32:
//-------------------------------------------
//0x32 - Change Camera Mode
// G_wIndexLock = 0 - Idle
// 1 - Preview
// 2 - Digital Still Camera
// 3 - Video Clip
// 4 - PC Camera
// 5 - Playback
// 6 - Upload/Download
//-------------------------------------------
MAIN_EventPreDpc();
SETMODE_ChangeCameraMode((UCHAR)G_wIndexLock);
MAIN_EventPostDpc();
break;
case 0x33: //cch@10/15
//-------------------------------------------
//0x33 - Set Initial Sensor
// G_wIndexLock = 0 - Initial Global
// 1 - Initial CDSP
// 2 - Initial TG
//-------------------------------------------
MAIN_EventPreDpc();
//NotYet!
MAIN_EventPostDpc();
break;
case 0x34: //cch@10/15
//-------------------------------------------
//0x34 - Set GPIO
// G_wIndexLock = 0 - Turn on GPIP power
// 1 - Turn off GPIP power
//-------------------------------------------
MAIN_EventPreDpc();
//NotYet!
MAIN_EventPostDpc();
break;
//---------------------------------------------------
// 0x4X - SDRAM Related Function
//---------------------------------------------------
#if (SDRAM_OPTION == 1)
case 0x40:
//-------------------------------------------
//0x40 - Format
//-------------------------------------------
MAIN_EventPreDpc();
SDRAM_Format();
MAIN_EventPostDpc();
break;
case 0x41:
//-------------------------------------------
//0x41 - Capture Object
// G_wIndexLock = 0 - Capture One Image (JPEG)
// 1 - Capture Audio Stream (WAV)
// 2 - Capture Video Stream (AVI)
// 3 - Capture Audio/Video Stream (AVI)
//-------------------------------------------
MAIN_EventPreDpc();
SENSOR_CaptureAeAwbAf();
SDRAM_CaptureObject(G_wIndexLock);
MAIN_EventPostDpc();
break;
case 0x42:
//-------------------------------------------
//0x42 - Delete Object
// G_wValueLock = 0 - Delete All Object
// otherwise - Delete Object of Index
//-------------------------------------------
MAIN_EventPreDpc();
SDRAM_DeleteObject(G_wValueLock);
MAIN_EventPostDpc();
break;
case 0x43:
//-------------------------------------------
//0x43 - Playback Object
// G_wIndexLock = 0 - Playback Nine Thumbnail
// 1 - Playback Four Thumbnail
// 2 - Playback One Image
// 3 - Playback Image Slide
// 4 - Playback Video
// G_wValueLock = Index of Object
//-------------------------------------------
MAIN_EventPreDpc();
SDRAM_PlaybackObject(G_wIndexLock, G_wValueLock);
MAIN_EventPostDpc();
break;
case 0x44:
//-------------------------------------------
//0x44 - Upload Object
// G_wIndexLock = 0 - Get Object Count
// 1 - Get Object FDBs
// 2 - Upload One Object
// G_wValueLock = Index of Object
//-------------------------------------------
MAIN_EventPreDpc();
if (G_wIndexLock)
SDRAM_UploadObject(G_wIndexLock, G_wValueLock);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -