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

📄 app.c

📁 此文件是硬盘自伺服刻录代码
💻 C
📖 第 1 页 / 共 3 页
字号:
#include "os_cpu.h"
#include "includes.h"
#include "define.h"


INT32U serial_num;
INT32U countdown;
INT32U countup1;
INT32U flag = 0;
//////////////////////////
// ssw varibal
/////////////////////////
INT8U EnterINT;
INT32U WriteSecCunt;
INT8U SectorNum,OldSectorNum;
INT8U StartNewStep; 
INT8U ArraySubscript = 0,LosingSecNum[100];
INT8S LosingSecCunt;
INT16U OldBurst;
INT8U StopWrite;
INT16U ttt,bbb;
extern INT16U BurstA,BurstB,BurstC,BurstD,Burst,Big_Burst;
extern INT16U CaculateMAXBst();	
//INT8U WriteLosingSec;
/////////////////////////////////
#define GC_MASK 0x00FFFF80;
//unsigned BurstA,BurstB,BurstC,BurstD;
long GC_RAW;
unsigned GC;
unsigned wcs_addr;
unsigned wcs_value;
unsigned wcs_count;
unsigned SSMF_FLAG;
unsigned SIM_SAM_FLAG;
void SetupCPU(void)
{
	// warm reset
	//CPU_WARM_RST = 0x5540;
	//CPU_WARM_RST = 0x0000;
	// interrupt mask
	INT_CTL = 0x0010;				// disable IRQ, soft IR; enable servo FIQ
}

// ******************************
// setup WCS RAM
// ******************************
void SetupWCS(void)
{
	// write
	int i;
    unsigned * tmp = (unsigned *)WCS_BASE;
	for (i=0;i<32;i++)
	{
		* tmp &= 0x00000000;
		* tmp |= RAMData[i];	// set	
		tmp ++;
	}
}

// ******************************
// setup chip power management
// ******************************
void PwrCtl(void)
{
	// disable standby, sleep, enable servo clk(11), enable BM and HBI clk, enable DM, DF, SAIL, ECU
	PWR_CTL = 0x083f;
	// set sys and cpu frequency
//	CLK_DVD0 = 0x46a4; can't debug/////////////////////////////
	// sel servo clk from osc, 20MHz
	SRV_CLK_SEL &= 0xffff0000;
	SRV_CLK_SEL |= 0x0000a424;
	// channel power control, disable sleep and PD and PPD
 	*(volatile unsigned char *)0x10002488 = 0x00;
 	// analog front end pwr ctl, disable write
 	*(volatile unsigned char *)0x1000248a = 0x17;
 	*(volatile unsigned char *)0x1000248a = 0x00;
}

// ******************************
// channel clk frequency setup
// ******************************
void ChnlInit(void)
{
// refer to read channel appendix A
	// program TBG1 to 600M
	// set 1Ch for FS_NF for 2M ref 
	// ??????? Fref = 2MHz ?????????
	// parameter for setting f_TBG=100MHz
	// should *4?
	SFG_NS = 0x66;		// 
	SFG_NF = 0x87;		// 
	FS_NF = 0xF0;		// 
	// set active state, ignored
	// reset servo sequencer only
	SG_EXT_EN =0x80;	// 1-0
	SG_EXT_EN =0x00;	// 0-1
	// analog calibration,ignored
	/* 
	LFG_N&=0xE0;
	LFG_N|=0x06;
	ACAL|=0x80;
	*/
	// delay 300ms
	// TGG CAL
	// setup other channel reg
}

// ******************************
// WCS init
// ******************************
void WCSInit(void)
{
	// init output
	*(volatile unsigned *)0x10002688 = 0x2000; 
 	// read current value
 	wcs_value = WCS_VALUE&0x0000FFFF;
 	// index time out
 	SRV_SYNC_TO &= 0xffff0000;
 	SRV_SYNC_TO |= 0x00000100;
}

// ******************************
// setup servo pattern
// ******************************
void SetupPattern(void)
{
	// encoding format
	ENC_FMT=0x00;
	// gray code length
	GC_LEN_CNL=0x1F;
	// SIM/SAM format
	SIM=0x14;
	SAM=0x27;
	// setup burst
	BG_N=0x03;
	BG_GAP=0x43;
	BG_GAP_EN=0x40;
	// RRO & GCAL
	S_CFG1=0x01;
}

// ******************************
// channel servo state machine
// ******************************
void SetupPatternTiming(void)
{
	S_ACQ_DLY = 0x04;
	S_ACQ1 = 0x09;
	S_ACQ2 = 0x10;
	S_ACQ3 = 0x00;
	S_SMDTMO = 0x30;
	BG_DLY1 =0x11;
	BG_DLY2 = 0x10;
	BG_INTEGRATION = 0x37;
	SG_EXT_TMO = 0x05;
}

// ******************************
// channel-servo interface
// ******************************
void SetupTxFmt(void)
{
	// NRZ mode
	SRV_CFG0=0x08;
	SRV_CFG1=0x01;
	// Quality bits
	SRV_CFG2=0x70;
	SRV_CFG3=0x9E;
	SRV_CFG4=0x00;
	SRV_CFG5=0x50;
	SRV_CFG6=0x00;
	SRV_CFG7=0x10;
	// PES Tx Format
	PES_TX_MODE=0x00;
	// PES shift
	PES_Shift=0x00;
}

// ******************************
// servo controller data config
// ******************************
void SetupSrvctlFmt(void)
{
	// servo controller data configuration
	SRV_DATA_CFG&=0xFFFF0000;
	SRV_DATA_CFG|=0x0000DE01;
}

// ******************************
// enable test out pins
// ******************************
void EnTest(void)
{
	// enable test output
	TO_EN = 0xffff;
	// output FIQ, SG, and so forth for test
	TST&=0xFFFFFF00;
}

// ******************************
// read servo status
// ******************************
void ServoStatus(void)
{
	wcs_addr=WCS_ADDR&0x000000FF;
	wcs_count=WCS_COUNT&0x0000FFFF;
	wcs_value=WCS_VALUE&0x000000FF;
	SSMF_FLAG = SSM & 0x80;
	SIM_SAM_FLAG = SSM & 0x40;
}





void CpuInit(void)
{

//===========================================
// CLOCK SETTINGS
// bit 0x800 of 1000A804 can not be set, it never turns on
//===========================================
//*(volatile unsigned *) (0x1000A628) = 0;
*(volatile unsigned *) 0x1000A814 &=0xFFFF0000;
*(volatile unsigned *) 0x1000A814 |=0x000000B0;	//SIF freq = Osc/4
*(volatile unsigned *) 0x1000A810 &=0x0000ffff;	
*(volatile unsigned *) 0x1000A810 |=0x88040000;	//V_CLK = Osc/2, SPDL_CLK = Osc/2, P_CLK = 120
*(volatile unsigned *) 0x10008100 &=0x0000ffff;
*(volatile unsigned *) 0x10008100 |=0x00800000;	//enable manteca, parallel mode (Set bit 3 [PD_EN] = 0)
*(volatile unsigned *) 0x1000A80A &=0xFFFF0000;
*(volatile unsigned *) 0x1000A80A |=0x00000001;	//normal 120Mhz



//*(volatile unsigned *) 0x1000A804=0xA424;	//ATA_freq = 40Mhz, ATA=div, USB=osc, MR=div, SRAM=div
*(volatile unsigned *) 0x10002804 &=0x0000ffff;
*(volatile unsigned *) 0x10002804 |=0x007F0000;	//reset all HDC blocks
*(volatile unsigned *) 0x10002804 &=0x0000ffff;
*(volatile unsigned *) 0x10002804 |=0x00000000;

*(volatile unsigned *) 0x1000A804 &=0x0000ffff;
*(volatile unsigned *) 0x1000A804 |=0x003F0000;	// Enable clock to BM and HBI
*(volatile unsigned *) 0x1000A80C &=0xFFFF0000;
*(volatile unsigned *) 0x1000A80C |=0x00000AA0;	// 40MHz

*(volatile unsigned *) 0x1000A808 &=0x0000ffff;
*(volatile unsigned *) 0x1000A808 |=0x33800000;	//HDCclk=1, SYSclk=1, MFClk=1, UARTclk=1, SIFclk=1
*(volatile unsigned *) 0x1000A814 &=0x0000ffff;
*(volatile unsigned *) 0x1000A814 |=0x00000000;  //823xiugai!
//*(volatile unsigned *) 0x1000A814 |=0x00010000;	//enable timer0 (below)

//===========================================
// TIMERS (COUNTERS) SETTINGS
// Timer0 creates tick of 10 milliseconds
//===========================================

//*(volatile unsigned *) 0x1000A200 &=0x0000ffff;823xiugai
//*(volatile unsigned *) 0x1000A200 |=0x14040000;823xiugai	

//*(volatile unsigned *) 0x1000A206 = 0x3897;	//timer0 count to 10000
//*(volatile unsigned *) 0x1000A200 &=0x0000ffff;
//*(volatile unsigned *) 0x1000A200 |=0x14010000;	

//===========================================
// INTERRUPT SETTING
/*
*(volatile unsigned *) 0x10008000 &=0xFFFF0000;
*(volatile unsigned *) 0x10008000 |=0x0000FFFF;//显示所有的中断状态位,中断发生时,需要处理	                        // Clear all cpu interrupts
*(volatile unsigned *) 0x10008004 &=0x0000ffff;
*(volatile unsigned *) 0x10008004 |=0x0d100000;
*(volatile unsigned *) 0x10008000 &=0x0000ffff;
*(volatile unsigned *) 0x10008002 |=0x2B240000;//2B24(4)
*/
//============================================
// Basic serial port setting
//============================================

*(volatile unsigned *) 0x1000A624 &=0xffff0000;
*(volatile unsigned *) 0x1000A624 |=0x00007654;   // enable RX/TX
*(volatile unsigned *) 0x1000A624 &=0x0000ffff;
*(volatile unsigned *) 0x1000A624 |=0xfd230000;   // 
*(volatile unsigned *) 0x1000A628 &=0xffff0000; 
*(volatile unsigned *) 0x1000A628 |=0x1EFE0000;   //
*(volatile unsigned *) 0x1000A62C &=0xffff0000; 
*(volatile unsigned *) 0x1000A62C |=0x0000081A;   // baud rate: 115.2

*(volatile unsigned *) 0x1000A620 &=0x00000000;
*(volatile unsigned *) 0x1000A620 |=0x00002340;
//*(volatile unsigned *) 0=0xFFFF;		//end marker


serial_num = *(volatile unsigned *)0x1000a624; 

//OS_ENTER_CRITICAL(); 
}

void eventTickInit (INT32U msec)
{
/* ----------------------------------------------------------------------
 *
 * Initalize the Tick hardware on the Samsung part.
 *
 * ----------------------------------------------------------------------
 */

*(volatile unsigned *) 0x1000A200 &=0x0000ffff;
*(volatile unsigned *) 0x1000A200 |=0x14040000;	
*(volatile unsigned *) 0x10008000 &=0x0000ffff;	

//*TMOD = 0;
//*INTPND = 0x00000000; 

// Clear pending interrupts .............

/* ----------------------------------------------------------------------
 *
 * Set the countdown value depending on msec.
 *
 * ----------------------------------------------------------------------
 */

  switch (msec)
  {
  case 2: /* fast ... */
  //countdown = 0x000ffff0;
  countdown = 0xffffffff;
  break;
  default: /* slow ... */
  countdown = 0x00effff0;
  break;	  
  }
}

void eventTickStart(void)
{	 

*(volatile unsigned *) 0x1000A204 =countdown;
//*(volatile unsigned *) 0x1000A204 |=0x0000bbbb;	//timer0 count to 10000 o
//*(volatile unsigned *) 0x1000A204 = countdown;
//countup1 = *(volatile unsigned *)0x1000a204;
*(volatile unsigned *) 0x1000A200 &=0x0000ffff;
//*(volatile unsigned *) 0x1000A200 |=0x14010000;	  
*(volatile unsigned *) 0x1000A200 |=0x14050000;	
countup1 =*(volatile unsigned *)0x1000a204;
  
/* -- unmask the interrupt source.. */ 
*(volatile unsigned *) 0x10008000 &=0x0000ffff; 
*(volatile unsigned *) 0x10008000 |=0x60100000; 	
//*(volatile int*)INTMSK &= ~((1 << INT_GLOBAL) | (1<<10) | (1<<0));  
//countup1 = (*(volatile unsigned *)0x1000a204);   
}


void DataChan_Reg(void)
{
//The Interface setting  
	/*
	SerInface_0     = 0x80;  //r2400
	SerInface_1     = 0x00;
	SerInface_2     = 0x00;
	SerInface_3     = 0x00;
	*/
//The Error Recovery setting
	ErroRecovery    = 0x00;  //r2408
//Time Base Generator Calibration
 	TimeBaseGC      = 0x1a;  //r240a
 	TimeBaseGSD     = 0x6c;
	TimeBaseGFD     = 0x98;
//The Channel Statistics Measurement Part
	ChanStatisMeasure_0  = 0x4b; //r2410
	ChanStatisMeasure_1  = 0x00;
	ChanStatisMeasure_2  = 0x00;
	ChanStatisMeasure_3  = 0x00;
	ChanStatisMeasure_4  = 0x44;
	ChanStatisMeasure_5  = 0x00;
	//ChanStatisMeasure_6 = 0x39;
	//ChanStatisMeasure_7 = 0x5c;
	ChanStatisMeasure_8  = 0x00;
	ChanStatisMeasure_9  = 0x00;
	ChanStatisMeasure_10&= 0x80;
//The VGA Registor Setting
	VGARegistor_0   = 0x48;  //r2426
	VGARegistor_1   = 0x4a;
	VGARegistor_2   = 0x81;
	VGARegistor_3   = 0x80;
	//VGARegistor_4   = 0xf4;
//Define Asemmetry Correction control
	AsemmetryCoren_0= 0x30;  //r2430
	AsemmetryCoren_1= 0x3d;
	//AsemmetryCoren_2= 0x9d;
//Data Mode CTF controller
 	DataCTFControl_0 = 0x40;  //r2436
 	DataCTFControl_1&= 0x03;
 	DataCTFControl_1|= 0xa0;
 	DataCTFControl_2 = 0x04;
 	DataCTFControl_3 = 0xb8;
 	DataCTFControl_4 = 0x00;
//Data Mode FIR coef setting
	DataFIRCoef_0   = 0xfb;  //r2440
	DataFIRCoef_1   = 0x01;
	DataFIRCoef_2	= 0xef;
	DataFIRCoef_3   = 0x12;
	DataFIRCoef_4   = 0x38;
	DataFIRCoef_5   = 0xfc;
	DataFIRCoef_6   = 0x11;
	DataFIRCoef_7   = 0xf7;
	DataFIRCoef_8   = 0x07;
	DataFIRCoef_9   = 0xfd;
	DataFIRCoef_10  = 0xcc;
	DataFIRCoef_11  = 0x0a;
//Data Timing Loop control
    /*
    DataTimingLoop_0= 0x96;  //r2458
    DataTimingLoop_1= 0x35;
    DataTimingLoop_2= 0x66;
    DataTimingLoop_3= 0x00;
    */
//Sync Detect Status Byte on NRZ

⌨️ 快捷键说明

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