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

📄 wfunlib.c

📁 在S3C44b0上移植ucos并实现哲学家就餐问题的演示
💻 C
字号:
/**************************************************************************
NAME:WFUNLIB.C
copyright:wzz at Qingdao University  2008
**************************************************************************/

#include "..\inc\WOPTIONS.h"
/**************************************************************************************************/
#if PORT_SELECT==1
void Port_Init(void)//add by eric rong
{
	//CAUTION:Follow the configuration order for setting the ports. 
	// 1) setting value 
	 // 2) setting control register 
	 // 3) configure pull-up resistor.  

	//16bit data bus configuration  

	// PORT A GROUP
	/*  BIT 9		8		7		6		5		4		3		2		1		0            */
	/*  ADDR24	ADDR23	ADDR22	ADDR21	ADDR20	ADDR19	ADDR18	ADDR17	ADDR16	ADDR0   */	      
	/*  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	SCLK	SCKE*/
	/*	rtl8019	(Reserve)(Reserve)FLASH	D12 		Out		Out		Sdram	Sdram	Sdram	Sdram*/
	/*      1,        1,		1,		1,		1,		0,		0,		1,		1,		1,		1*/
	rPDATB = 0x7ff;
	rPCONB = 0x7cf;
    
	//PORT C GROUP
	//BUSWIDTH=16*/
	/*  PC    15		14		13		12		11		10		9		8                       */
	/*          O		O		RXD1	TXD1	O		O		O		O*/
	/*          Nand-CE	UDA-CE	Uart1	Uart1	NandCLE	NandALE	L3DATA	L3CLK*/
	/*          01		01		11		11		01		01		01		01		*/

	/*  PC	7		6		5		4		3		2		1		0*/
	/*		O		O		O		I		IISCLK	IISDI	IISDO	IISLRCK*/
	/*		VD4		VD5		VD6		VD7		[		for UDA1341			]*/
	/*		11		11		11		11		11		11		11		11*/
	rPDATC = 0x3fff;	//All IO is high
	rPCONC = 0x5f55ffff;	
	rPUPC  = 0x3000;	//PULL UP RESISTOR should be enabled to I/O

	//PORT D GROUP for LCD
	/*BIT 7	6	5		4		3		2		1		0*/
	/*      VF	VM	VLINE	VCLK	VD3		VD2		VD1		VD0*/
	/*	  10	10	10		10		10		10		10		10*/
	rPDATD= 0xff;
	rPCOND= 0xaaaa;
	rPUPD = 0x0;
	
	//PORT E GROUP
	/*  Bit	 	8		7		6		5		4		3		2		1		0	*/
	/*		CODECLK	TOUT4	TOUT3	TOUT2	TOUT1	TOUT0	RXD0	TXD0	SMRB(I)	*/
	/*			10		10		10		10		10		10		10		10		00	*/
	rPDATE = 0x1ff;
	rPCONE = 0x2aaa8;
	rPUPE  = 0x106;

	//PORT F GROUP
	/*  Bit	8		7		6		5		4		3		2		1	      0*/
	/*		SIOCLK	SIORxD	7843CS	SIOTxD	[Input(DMA)	]	Output	IICSDA	IICSCL*/
	/*		011		011		001		011		00		00		01		10     	10*/

	rPDATF = 0x1fb;	//GPF2=0
	rPCONF = 0x1B2C1A;	//0x9241A;
	rPUPF  = 0x3;

	//PORT G GROUP
	/*BIT	7		6		5		4		3		2		1		0*/
	/*		INT7		INT6		INT5		INT4		INT3		INT2		INT1		INT0*/
	/*		11		11		00		11		11		11		11		11*/
	//						~tch		~~input for bios
	rPDATG = 0xff;
	rPCONG = 0xf3ff;
	rPUPG  = 0x0;	//should be enabled  

	rSPUCR=0x7;  //D15-D0 pull-up disable

/*定义非Cache区*/
//NCACHBE0=(((unsigned int)Non_Cache_End>>12)<<16)|(Non_Cache_Start>>12); 
/*所有的外部硬件中断为低电平触发*/
//EXTINT=0x0;
}
#endif
/**************************************************************************************************/
#if PORT_SELECT==2
void Port_Init(void)
{    //CAUTION:Follow the configuration order for setting the ports. 
    // 1) setting value 
    // 2) setting control register 
    // 3) configure pull-up resistor.  

    //PORT A GROUP
    //GPA9 ADDR23 ADDR22 ADDR21 ADDR20 ADDR19 ADDR18 ADDR17 ADDR16 ADDR0		      
    //  0,    1,     1,    1,     1,     1,     1,      1,     1,    1
    rPCONA=0x1ff;	
    rPDATA=0x0;
    //PORT B GROUP
    //GPB10  GPB9 nGCS3 nGCS2 nGCS1 GPB5 GPB4 nSRAS nSCAS SCLK SCKE
    //  0,    0,    1,	1,    1,    0,    0,	1,    1,   1,   1	
    rPCONB=0x1Cf;
    
    //PORT C GROUP
    //IISLRCK  IISD0 IISDI IISCLK VD7 VD6 VD5 VD4 nXDACK1 nXDREQ1 GPC10 GPC11 TXD1 RXD1 GPC14 GPC15
    //All input
    //  11      11    11    11    11  11   11  11   11      11     01	01     11   11   01    01
    //rPDATC=0x8400;
    //rPCONC=0x5F5FFFFF;	
    //rPUPC=0x33ff;	//should be enabled	
    rPDATC=0xffff;	//All I/O Is High
    rPCONC=0x0f05ff55;	
    rPUPC=0x30f0;	//PULL UP RESISTOR should be enabled to I/O
    
   
    //PORT D GROUP
    //VFRAME VM VLINE VCLK VD3 VD2 VD1 VD0
    //    10,10,   10,	10, 10,	10, 10,	10  
    rPCOND=0xaaaa;	
    rPUPD=0xff;

	//PORT E GROUP
	//PE0:FOUT, PE1:TxD0, PE2:RxD0, GPE3, GPE4, GPE5,GPE6,GPE7, CODECLK   
	//    10       10,      10,     01  ,  01,    01,   01,   01,   10
	rPCONE=0x2aaa9;//rPCONE=0x2556a;//0x6552a;//0x2B;	
	rPUPE=0x00;	//0xff;	
	rPDATE=rPDATE|(0x03<<6);
    rPDATE=rPDATE&(~(0x01<<4))|(0x01<<3);
	
	//PORT F GROUP
	//  GPF8    GPF7  GPF6 GPF5   nXDREQ0   nXBACK0   nWAIT  IICSDA  IICSCL
	//  100     100   100    100    10       10         10      10      10    
	rPCONF=0x24915a;//rPCONF=0x9256A;//rPCONF=0x242aa;//0x2A;
	rPUPF=0xff;;

    //PORT G GROUP
    //EINT0 EINT1 EINT2 EINT3 GPG4 GPG5 GPG6 GPG7
    //	  0x0
    //  11      11   11     11   11  11   11   11
    rPDATG=0x0;
    rPCONG=0xFFFF;
    rPUPG=0xf;
    
    rSPUCR=0x7;  //pull-up disable
    rEXTINT=0x22222222;  //All EINT[7:0] will be falling edge triggered.
    
}
#endif
/**************************************************************************************************/
#if PORT_SELECT==3

#endif
/**************************************************************************************************/
static int delayLoopCount=400;
//1S=1,000,000 uS
//t_watchdog  = 1/( MCLK / (Prescaler value + 1) / Division_factor )
//Prescaler=MCLK/1000000-1
//t_watchdog=1/1000000/(1/64) s=64 us
void Delay(int time)
// time=0: adjust the Delay function by WatchDog timer.//
// time>0: the number of loop time//
// 100us resolution.//
{
	int i,adjust=0;
	if(time==0)
	{
		time=200;
		adjust=1;
		delayLoopCount=400;
		rWTCON=((MCLK/1000000-1)<<8)|(2<<3);		// 64us,Watch-dog,nRESET,interrupt disable//
		rWTDAT=0xffff;
		rWTCNT=0xffff;	 
		rWTCON=((MCLK/1000000-1)<<8)|(2<<3)|(1<<5); // 64us,Watch-dog enable,nRESET,interrupt disable //
	}
	for(;time>0;time--)
		for(i=0;i<delayLoopCount;i++);
	if(adjust==1)
	{
		rWTCON=((MCLK/1000000-1)<<8)|(2<<3);
		i=0xffff-rWTCNT;				/*aim at 100us*/
		delayLoopCount=8000000/(i*64);	/* (200*400):(64us*i)=(1*delayLoopCount):100us*/
	}									/*delayLoopCount=200*400*100*/
}
/**************************************************************************************************/

⌨️ 快捷键说明

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