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

📄 control.c

📁 华恒瑞科公司的S3C44B0开发板音频测试程序
💻 C
字号:
#include "def.h"
#include "44b.h"
#include "option.h"
#include "utils.h"


void PortInit(void)
{
	// PORT A GROUP
	/*  BIT 9	8	7	6	5	4	3	2	1	0	*/
	/*  A24	  A23	A22	A21	A20	A19	A18	A17	A16	A0	*/	      
	/*  1		1	1	1	1	1	1	1	1	1	*/
	rPCONA = 0x3ff;	

	// PORT B GROUP
	/* BIT 10   9    8       7      6        5     4     3     2     1     0    */
	/*     /CS5 /CS4 /CS3    /CS2   /CS1     nWBE3 nWBE2 /SRAS /SCAS SCLS  SCKE	*/
	/*     NC   NC   RTL8019 USBD12 NV_Flash NC    NC    Sdram Sdram Sdram Sdram*/
	/*     1,   1,   1,      1,     1,       0,    0,    1,    1,    1,    1    */
	rPDATB = 0x7cf;
    
	//PORT C GROUP
	//BUSWIDTH=16													*/
	/*  PC15		14		13		12		11		10		9		8	*/
	/*	o		o		RXD1	TXD1	o		o		o		o	*/
	/*	NC		NC		Uart1	Uart1	NC		NC		NC		NC	*/
	/*   01		01		11		11		01		01		01		00	*/

	/*  PC7		6		5		4		3		2		1		0	*/
	/*   o		o		o		o		o		o		o		o	*/
	/*   NC		NC		NC		NC		NFALE 	NFCLE 	NFCE 	NFRB*/
	/*   01		01		01		01		01		01		01		00	*/
#ifdef FS44B0_BOARD
	rPDATC = 0x0100;	//All IO is low, PC8 = 1 LCD-Off, PC9 = 0 BackLight Off
	rPCONC = 0xfff5ff54;	//0->D12SUSPD, 1~3->LED, 4~7->VD7~VD4, 8->DISPON, 9->BACKLIGHT, 10~13->UART1, 14->RTS0, 15->CTS0
	rPUPC  = 0x0000;	//disable all pull-up
#elif defined ST44B0_BOARD
	rPDATC = 0x0300;	//All IO is low, PC8 = 1 LCD-Off, PC9 = 1 BackLight Off
	rPCONC = 0x0005ff00;	//0~3->input, 4~7->VD7~VD4, 8->DISPON, 9->BACKLIGHT, 10~15->input
	rPUPC  = 0x0000;	//disable all pull-up
#else
	rPDATC = 0x0100;	//All IO is low, PC8 = 1 LCD-Off, PC9 = 0 BackLight Off
	rPCONC = 0xfff5ff54;	//0->D12SUSPD, 1~3->LED, 4~7->VD7~VD4, 8->DISPON, 9->BACKLIGHT, 10~13->UART1, 14->RTS0, 15->CTS0
	rPUPC  = 0x0000;	//disable all pull-up
#endif	

	//PORT D GROUP
	/*  PORT D GROUP(I/O OR LCD)										*/
	/*  BIT7		6		5		4		3		2		1		0	*/
	/*      VF		VM		VLINE	VCLK	VD3		VD2		VD1		VD0	*/
	/*	   10		10		10		10		10		10		10		10	*/
	rPCOND= 0xaaaa;	
	rPUPD = 0x00;
	//These pins must be set only after CPU's internal LCD controller is enable
	
	//PORT E GROUP 
	/*  Bit 8		7		6		5		4		3		2		1		0		*/
	/*		ENDLAN	LED3	LED2	LED1	LED0	BEEP	RXD0	TXD0	CLKOUT	*/ 
	/*      10		01		01		01		01		01		10		10		11		*/
#ifdef FS44B0_BOARD
	rPCONE	= 0x20828;	//0->input, 1 2->TXD0 RXD0, 3 4 6 7->input, 5->beep, 8->CODECLK
	rPUPE	= 0x000;	//disable all pull-up
#elif defined ST44B0_BOARD
	rPDATE	= 0x70;
	rPCONE	= 0x15ab;	//0->FOUT, 1 2->TXD0 RXD0, 3->beep, 4~6->LED, 7->input, 8->ENDIAN
	rPUPE	= 0x000;	//disable all pull-up
#else
	rPCONE	= 0x26568;	//0->input, 1 2->TXD0 RXD0, 3 4->input, 5->led, 6->buzzer, 7->led, 8->CODECLK
	rPDATE	= 0x70;
	rPUPE	= 0x000;	//disable all pull-up
#endif	
	
	//PORT F GROUP
	/*  Bit8		7		6		5		 4		3		2		1		0		*/   
	/*  IISCLK	IISDI	IISDO	IISLRCK	Input	Input	Input	IICSDA	IICSCL	*/
	/*	100		100		100		100		00		01		01		10		10		*/
#ifdef 	FS44B0_BOARD
	rPCONF = 0x24900a;	//0 1->IICSCL IICSDA, 2~4->input 5~8->IIS PORT
	rPUPF  = 0x000;		//disable all pull-up
#elif defined ST44B0_BOARD
	rPCONF = 0x24000;	//0~5->input, 6 7->TXD1 RXD1, 8->input
	rPUPF  = 0x000;		//disable all pull-up
#else
	rPCONF = 0x24900a;	//0 1->IICSCL IICSDA, 2~4->input 5~8->IIS PORT
	rPUPF  = 0x000;		//disable all pull-up
#endif

	//PORT G GROUP
	/*  BIT7		6		5		4		3		2		1		0	 */
	/*	INT7		INT6		INT5		INT4		INT3		INT2		INT1		INT0	*/
	/*    S3		S4		S5		S6		NIC		EXT		IDE		USB	*/
	/*      11      11      11      11      11      11      11      11       */
	rPCONG = 0xff3c;	//eint1 is eth interrupt in FS44B0, eint2 for ide
	rPUPG  = 0x00;		//disable all pull-up
	
//	rSPUCR = 0x7;  //D15-D0 pull-up disable
	rSPUCR = 0x6;  //D15-D0 pull-up enable

	/*所有的外部硬件中断为低电平触发*/
	//rEXTINT = 0x0;
// need for uClinux	
//	rEXTINT = 0x42;				//所有的外部硬件中断为低电平触发, extint0 为下降沿,extint1为上升沿	
	rEXTINT = (4<<16)|(4<<8)|(4<<4);	//EINT1上升沿,EINT2上升沿,EINT4上升沿中断
//	rINTCON = 5;				// non vector mode, irq enable
//	rINTMOD = 0;				//all are irq mode
}

void Beep(U32 freq, U32 ms)
{
#ifdef FS44B0_BOARD
	rPCONE &= ~(3<<10);
	rPCONE |= (2<<10);
	
	rTCON  	&= ~0xf000;				// clear manual update bit, stop Timer2
	rTCFG0 	&= ~0xff00;				// set Timer 2&3 prescaler 0
	rTCFG1 	&= ~0xf00;				// set Timer 2 MUX 1/16
	rTCFG1  |= 0x300;	
	rTCNTB2	 = GetCpuClock()/(2100*16);		//if set inverter off, when TCNT2<=TCMP2, TOUT is high, TCNT2>TCMP2, TOUT is low
	rTCMPB2  = rTCNTB2>>1;			//if set inverter on,  when TCNT2<=TCMP2, TOUT is low,  TCNT2>TCMP2, TOUT is high
	rTCON	|= 0x2000;				// manual update
	rTCON	&= ~0x2000;				// clear manal update bit
	rTCON   |= 0xd000;				// auto reload, inverter on, start Timer 2	
	
	Delay(ms);
	
	rTCON &= ~0x1000;
	
	rPCONE &= ~(3<<10);
	rPCONE |= 1<<10;
	rPDATE &= ~(1<<5);
	
#elif defined ST44B0_BOARD

	rTCON  	&= ~0x1f;				// clear manual update bit, stop Timer0
	rTCFG0 	&= ~0xff;				// set Timer 0&1 prescaler 0
	rTCFG1 	&= ~0xf;				// set Timer 0 MUX 1/16
	rTCFG1  |= 3;	
	rTCNTB0	 = GetCpuClock()/(2100*16);
	rTCMPB0  = rTCNTB0>>1;				
	rTCON   |= 2;
	rTCON   &= ~2;
	rTCON	|= 0xd;					//auto-reload, inverter off, manual update, start timer	

	Delay(ms);
	
	rTCON &= ~1;					//stop
#else

	rTCON  	&= ~0xf0000;			// clear manual update bit, stop Timer3
	rTCFG0 	&= ~0xff00;				// set Timer 2&3 prescaler 0
	rTCFG1 	&= ~0xf000;				// set Timer 3 MUX 1/16
	rTCFG1  |= 0x3000;
	rTCNTB3	 = GetCpuClock()/(2100*16);		//if set inverter off, when TCNT2<=TCMP2, TOUT is high, TCNT2>TCMP2, TOUT is low
	rTCMPB3  = rTCNTB3>>1;			//if set inverter on,  when TCNT2<=TCMP2, TOUT is low,  TCNT2>TCMP2, TOUT is high
	rTCON	|= 0x20000;				// manual update
	rTCON	&= ~0x20000;			// clear manal update bit
	rTCON   |= 0xd0000;				// auto reload, inverter on, start Timer 2	
	
	Delay(ms);
	
	rTCON &= ~0x10000;
	
#endif

}

#ifdef	FS44B0_BOARD
#define	LED1_ON()
#define	LED2_ON()	(rPDATC |= 2)
#define	LED3_ON()	(rPDATC |= 4)
#define	LED4_ON()	(rPDATC |= 8)
#define	LED1_OFF()	
#define	LED2_OFF()	(rPDATC &= ~2)
#define	LED3_OFF()	(rPDATC &= ~4)
#define	LED4_OFF()	(rPDATC &= ~8)
#elif defined ST44B0_BOARD
#define	LED1_ON()
#define	LED2_ON()	(rPDATE |= 0x10)
#define	LED3_ON()	(rPDATE |= 0x20)
#define	LED4_ON()	(rPDATE |= 0x40)
#define	LED1_OFF()
#define	LED2_OFF()	(rPDATE &= ~0x10)
#define	LED3_OFF()	(rPDATE &= ~0x20)
#define	LED4_OFF()	(rPDATE &= ~0x40)
#else
#define	LED1_ON()	(rPDATE |= 0x20)
#define	LED2_ON()	(rPDATC |= 2)
#define	LED3_ON()	(rPDATC |= 4)
#define	LED4_ON()	(rPDATC |= 8)
#define	LED1_OFF()	(rPDATE &= ~0x20)
#define	LED2_OFF()	(rPDATC &= ~2)
#define	LED3_OFF()	(rPDATC &= ~4)
#define	LED4_OFF()	(rPDATC &= ~8)
#endif

void LedSet(U32 LedStatus)
{
	if(LedStatus&1)
		LED1_ON();
	else
		LED1_OFF();
	
	if(LedStatus&2)
		LED2_ON();
	else
		LED2_OFF();
		
	if(LedStatus&4)
		LED3_ON();
	else
		LED3_OFF();
		
	if(LedStatus&8)
		LED4_ON();
	else
		LED4_OFF();
}

void MemCfgInit(void)
{
	rNCACHBE0 = ((unsigned int)(Non_Cache_End>>12)<<16)|(Non_Cache_Start>>12);
	rNCACHBE1 = (0xf000U<<16)|(0xe000);
#ifdef FS44B0_BOARD			//0 for FS44B0 BACK-LIGHT ON
	rBWSCON &= ~0xf000;		//8bits for RTL8019 in FS44B0 BOARD
#endif
}

void BoardInitStart(void)
{
}

void BoardInitEnd(void)
{
}

void CacheDisable(void)
{
	rSYSCFG = SYSCFG_0KB;
}

void CacheEnable(void)
{
	rSYSCFG = SYSCFG_8KB;
}

void CacheFlush(void)
{
	int i, saveSyscfg;
    
    saveSyscfg = rSYSCFG;

    rSYSCFG = SYSCFG_0KB;
    for(i = 0x10004000; i<0x10004800; i+=16)
		*((int *)i) = 0x0;
    rSYSCFG = saveSyscfg;
}

U16 GetKeyStatus(void)
{
	return (rPDATG>>4);
}

//nand flash operation
#define	SEL_SMART_MEDIA_CARD

#ifdef	SEL_SMART_MEDIA_CARD
#define	NAND_DAT	0x0e000000
#define	NAND_ALE	0x0e000004
#define	NAND_CLE	0x0e000002
#else
#define	NAND_DAT	0x02000000
#define	NAND_ALE	0x02000004
#define	NAND_CLE	0x02000002
#endif

void NFChipSel(U32 sel)
{
	if(sel)
		rPDATC &= ~(1<<9);
	else
		rPDATC |= 1<<9;
}

int NFIsReady(void)
{
	return rPDATC&(1<<8);
}

void NFWrCmd(int cmd)
{
	*(volatile U8 *)NAND_CLE = cmd;
}

void NFWrAddr(int addr)
{
	*(volatile U8 *)NAND_ALE = addr;
}

void NFWrDat(int dat)
{
	*(volatile U8 *)NAND_DAT = dat;
}

U8 NFRdDat(void)
{
	return *(volatile U8 *)NAND_DAT;
}

⌨️ 快捷键说明

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