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

📄 demo.c

📁 中芯微camera 图像处理芯片演示
💻 C
字号:
/*************************************************************************/
/*                                                                       */
/*               Copyright Mentor Graphics Corporation 2002              */
/*                         All Rights Reserved.                          */
/*                                                                       */
/* THIS WORK CONTAINS TRADE SECRET AND PROPRIETARY INFORMATION WHICH IS  */
/* THE PROPERTY OF MENTOR GRAPHICS CORPORATION OR ITS LICENSORS AND IS   */
/* SUBJECT TO LICENSE TERMS.                                             */
/*                                                                       */
/*************************************************************************/
#include <string.h>
#include <stdlib.h>
#include "../inc/nucleus.h"
#include "../inc/nu_sd.h"
#include "../inc/44b.h"
#include "../inc/Keyboard.h"
#include "../inc/Key.h"

#include "../inc/NandFlash.h"
#include "../inc/MassStorage.h"

#include "../inc/thin_usr.h"
#include "../inc/High_Api.h"
#include "../inc/stor.h"

#include "MMI.h"
#include "../inc/panel.h"


int g_UDiskExit=1;
#define SOFTWARE_KEY 1

#define Uart_Printf // Hua,

//#define	SYSMEM_SIZE		1 * 1024 * 1024		//For System
//#define	USER_SIZE		4 * 1024 * 1024		//For User
//#define	FILESYSTEM_SIZE		512 * 1024		//For File System

#define	SYSMEM_SIZE		512 * 1024		//For System
#define	USER_SIZE			512 * 1024		//For User
#define	FILESYSTEM_SIZE	512 * 1024		//For File System

/*
void Config_968CS(void)
{
//((B3_Tacs<<13)+(B3_Tcos<<11)+(B3_Tacc<<8)+(B3_Tcoh<<6)+(B3_Tah<<4)+(B3_Tacp<<2)+(B3_PMC))	
	//int csconfig=((0x3<<13)+(0x3<<11)+(0x2<<8)+(0x3<<6)+(0x3<<4)+(0x3<<2)+(0));

	int csconfig=((0x1<<13)+(0x1<<11)+(0x5<<8)+(0x1<<6)+(0x1<<4)+(0x3<<2)+(0));

	rBANKCON3=csconfig;
}
*/
/* Define Application data structures.  */

NU_TASK		Task_0;
NU_TASK		Task_1;
NU_TASK		Task_2;
//NU_TASK		Task_868;

NU_MEMORY_POOL	_NU_sysMemory;
NU_MEMORY_POOL	User_Memory;
NU_MEMORY_POOL	FileSystem_Memory;

NU_SERIAL_PORT  port;               /* Serial IO being used */

int g_mpeg4Sign;

//NU_MAILBOX mailbox_868demo1;

extern  int ERC_System_Error(int);
extern  UNSIGNED TMD_System_Clock;



/* Function Prototypes */
CHAR *DEMO_Ultoa(unsigned long, char *, int);
VOID task_0(UNSIGNED argc, VOID *argv);
VOID task_1(UNSIGNED argc, VOID *argv);
VOID task_2(UNSIGNED argc, VOID *argv);
//extern VOID task_868demo(UNSIGNED argc, VOID *argv);

VOID	(*old_lisr)(INT);

UINT32	func_id;

extern int g_mclk;
#if 0

void CallBack(void)
{
	//VPlr_Unload(func_id);
	//VPlr_Close();
	//VPlr_Destory();
}    

void CLock_Init(UINT32 clck)
{
	int mid, pid, sid;
//8MHZ in
	switch(clck)
	{
		case 24000000:
			mid = 0x40;
			pid = 0x1;
			sid = 0x3;
			break;
		case 32000000:
			mid = 0x58;
			pid = 0x1;
			sid = 0x3;
			break;
		case 40000000:
			mid = 0x48;
			pid = 0x2;
			sid = 0x2;
			break;
		case 48000000:
			mid = 0x40;
			pid = 0x1;
			sid = 0x2;
			break;	
		case 64000000:
			mid = 0x58;
			pid = 0x1;
			sid = 0x2;
			break;
		default:
			clck=40000000,
			mid = 0x48;
			pid = 0x2;
			sid = 0x2;
			break;			
	}
	rPLLCON=(mid<<12)|(pid<<4)|sid;
	g_mclk = clck;
}
#endif
#define TIMER0_CLK_DIVISOR_8	(2 << 0)
#define TIMER0_LOAD			(1 << 1)
#define TIMER0_RUN			(1 << 0)
#define TIMER0_INTERVAL			(1 << 3)
void 	InitTimer0()
{
	UINT32 Freq, Tcount;

	rTCFG0 = 0xa;
	rTCFG1 = TIMER0_CLK_DIVISOR_8;
	Freq = 	g_mclk/8/(0xa+1)	;	// Timer0_clock (in Hz)
        							// Timer0_clock=MCLK_FREQ/(prescale+1)/Divisor

	Tcount = (10*Freq)/1000;    //10ms timer
	rTCNTB0 = Tcount;

	rTCON |= TIMER0_LOAD;
	rTCON &= (~TIMER0_LOAD);	
	rTCON |= TIMER0_RUN | TIMER0_INTERVAL;	

//	Enable_Intr(nINT_TIMER0);

}





UINT8 taskbuf0[200000];
//UINT8 taskbuf1[2000];
UINT8 taskbuf2[2000];
//UINT8 taskbuf3[8000];

void Application_Initialize(void *first_available_memory)
{
	//VOID	*pointer;
	STATUS	status;
	
	//CLock_Init(64000000);
	CLock_Init(40000000);
	Port_Init();
	InitTimer0();
	status = NU_Create_Memory_Pool (&_NU_sysMemory, "SysMem", first_available_memory, SYSMEM_SIZE, 50, NU_FIFO);
	if (status != NU_SUCCESS)
	{
		ERC_System_Error(status);
	}

	// Create a user memory pool that will be used to allocate task stacks, queue areas, etc.
	status = NU_Create_Memory_Pool(&User_Memory, "SYSMEM", first_available_memory, USER_SIZE, 50, NU_FIFO);
	if (status != NU_SUCCESS)
	{
		ERC_System_Error(status);
	}

	// Create a file system memory pool that will be used to allocate file system information.
	status = NU_Create_Memory_Pool(&FileSystem_Memory, "SYSMEM", first_available_memory, FILESYSTEM_SIZE, 50, NU_FIFO);
	if (status != NU_SUCCESS)
	{
		ERC_System_Error(status);
	}

	/* Create each task in the system.  */

	/* Create task 0.  */
	//NU_Allocate_Memory(&User_Memory, &pointer, 200000, NU_NO_SUSPEND);
	//status = NU_Create_Task(&Task_0, "TASK 0", task_0, 0, NU_NULL, pointer, 200000, 1, 20, NU_PREEMPT, NU_START);
	status = NU_Create_Task(&Task_0, "TASK 0", task_0, 0, NU_NULL, taskbuf0, 200000, 1, 20, NU_PREEMPT, NU_START);	
	if (status != NU_SUCCESS)
	{
		ERC_System_Error(status);
	}

#if 0
	/* Create task 1.  */
	//NU_Allocate_Memory(&User_Memory, &pointer, 2000, NU_NO_SUSPEND);
	//status = NU_Create_Task(&Task_1, "TASK 1", task_1, 0, NU_NULL, pointer, 2000, 10, 5, NU_PREEMPT, NU_START);
	status = NU_Create_Task(&Task_1, "TASK 1", task_1, 0, NU_NULL, taskbuf1, 2000, 10, 5, NU_PREEMPT, NU_START);	
	if (status != NU_SUCCESS)
	{
		ERC_System_Error(status);
	}

#endif
	/* Create task 2.  */
#if 1
	//NU_Allocate_Memory(&User_Memory, &pointer, 2000, NU_NO_SUSPEND);
	//status = NU_Create_Task(&Task_2, "TASK 2", task_2, 0, NU_NULL, pointer, 2000, 10, 5, NU_PREEMPT, NU_START);
	status = NU_Create_Task(&Task_2, "TASK 2", task_2, 0, NU_NULL, taskbuf2, 2000, 10, 5, NU_PREEMPT, NU_START);	
	if (status != NU_SUCCESS)
	{
		ERC_System_Error(status);
	}
#endif
	/* Create task 868 demo.  */
	//NU_Allocate_Memory(&User_Memory, &pointer, 8000, NU_NO_SUSPEND);
	//status = NU_Create_Task(&Task_868, "task 868demo", task_868demo, 0, NU_NULL, pointer, 8000, 15, 5, NU_PREEMPT, NU_START);	
//	status = NU_Create_Task(&Task_868, "task 868demo", task_868demo, 0, NU_NULL, taskbuf3, 8000, 15, 5, NU_PREEMPT, NU_START);		
	if (status != NU_SUCCESS)
	{
		ERC_System_Error(status);
	}
//	/* create mailbox for 868 demo*/
//	status=NU_Create_Mailbox(&mailbox_868demo1, "mailbox_868demo1", NU_FIFO);	
	if (status != NU_SUCCESS)
	{
		ERC_System_Error(status);
	}
}

#if 1
void f_GetNowFileName(const char *Dir) 
{
	F_FIND FindFile;
	Uart_Printf("\n %s",Dir);
		f_chdir(Dir);
		if (!f_findfirst("*.*",&FindFile)) {
		do {
			Uart_Printf ("filename:%s",FindFile.filename);
				if (FindFile.attr&F_ATTR_DIR) {
			Uart_Printf ("directory\n");
		}
		else {
			Uart_Printf ("size %d\n",FindFile.filesize);
		}
		} while (!f_findnext(&FindFile));
		}	
}



#endif
void   task_0(UNSIGNED argc, VOID *argv)
{
//	UINT8		flag;
	STATUS		status;
	UNSIGNED		total_memory_pool;

	/* Init the serial port. */
	port.com_port   = DEFAULT_UART_PORT;
	port.baud_rate  = DEFAULT_UART_BAUD;
	port.data_bits  = DEFAULT_UART_DATA;
	port.stop_bits  = DEFAULT_UART_STOP;
	port.parity     = DEFAULT_UART_PARITY;
	port.data_mode  = DEFAULT_UART_MODE;
	port.communication_mode = SERIAL_MODE;
	port.sd_buffer_size   =   DEFAULT_UART_BUFFER;

	status = NU_SD_Init_Port (&port);

	if (status != NU_SUCCESS)
	{
		ERC_System_Error(status);
	}



	/* Access argc and argv just to avoid compilation warnings.  */
	status =  (STATUS) argc + (STATUS) argv;

	total_memory_pool = NU_Established_Memory_Pools();
#if 0// filesystem
			rPLLCON=(0x40<<12)|(0x1<<4)|0x3;
			g_mclk = 24000000;

			rPCONB |= (1<<10);

			rPCONC &= ~(0xff);
			rPCONC |= 0x54;
			rPDATC |= 0x0e;
			MassStorage_Init();
#endif 
	//P9555_Init(Key_Machine);
	//V858_Init();

	//FATFileSystemInit();
	InitVc0578();
#if 0
	//rPLLCON=(0x40<<12)|(0x1<<4)|0x3;
	//g_mclk = 24000000;

	rPCONB |= (1<<10);

	rPCONC &= ~(0xff);
	rPCONC |= 0x54;
	rPDATC |= 0x0e;
	g_UDiskExit=0;
	MassStorage_Init();
#endif
	//if(!testFat())
		//NU_SD_Put_String("FatSystem test false!\r\n", &port);
		
	//MassStorage_Init();

	//P9555_Init(Key_Machine);

	Init_GUI();

	while(1)
	{

		NU_Sleep(100);
    
	}


}


/*
   Define the queue sending task.  Note that the only things that cause
   this task to suspend are queue full conditions and the time slice
   specified in the configuration file.  

   Use this task to test 568 driver.
*/
//UINT8 JpegBuf[0x30000];
//UINT32 Jpeg_Length=0;
// void RdZLG7290(UINT8 addr, UINT8 *data, UINT32 num);

void RdP9555(UINT8 addr, UINT8 *data, UINT32 num);

void Led_Disp(int LedStatus)
{
	int val;

	LedStatus &= 0xf;
	val =rPDATE;// ReadMemory(REG_PDATE);
	val &= ~(0xf0);
	val |= LedStatus << 4;
	//WriteMemory(REG_PDATE, val);
	rPDATE=val;
}
extern int g_vKey ;
//char VideoBuf[2048000];



//=======
#define KBYTE (1024)
#define VIDEO_BUF_LEN	(1*KBYTE)
char VideoBuf[VIDEO_BUF_LEN];
unsigned int gVideoLen = 0;
int g_VideoSize;

extern UINT8 gbEncode; // Hua,
extern UINT8 gbPlayingRecode; // Hua,
extern UINT8 gbVideoGUIClose; // Hua,
extern UINT8 gbPlayVIMP4;

void task_1(UNSIGNED argc, VOID *argv)
{
#if 1
	char key;

///////////////////////////////////////////////////////
#if (SOFTWARE_KEY==1)
while(1)
{
key=SDC_Get_Char (&port);
			if(key)
			{
				switch(key)
				{
					case '8':
						g_vKey=11;//KEY_UP;
						break;
					case '2':
						g_vKey=5;//KEY_DOWN;
						break;
					case '4':
						g_vKey=8;//KEY_LEFT;
						break;
					case '6':
						g_vKey=10;//KEY_RIGHT;
						break;	
					case '5':
						g_vKey=4;//KEY_OK;
						break;
					case '0':
						g_vKey=6;//KEY_CANCEL;
						break;	
					case 2:
						g_vKey=2;//DELETE
					default:
						g_vKey=0;
						break;				
				}
				if(g_vKey) g_vKey+=49;

			}

/* keyBoad poll has been moved to KBD_Poll(void) in kbd_tc.c
//jsguo modified 2005.11.1
RdZLG7290(0x1, rdata, 2);
RdP9555(0x1, rdata, 2);
if(rdata[0])
{
	g_vKey=49+rdata[0];
	Vmac_Open(VM_MODE_BBPLAY);
	Vmac_PlayKeyEffect(1, 2, 60, 60);	
	Vmac_Close();
	NU_Sleep(50);
}*/
	NU_Sleep(100);
}
#endif

//////////////////////////////////////////////////////
		#if (SOFTWARE_KEY==0)	
		NU_Sleep(100);
		#endif
#endif
}


/* Define the queue receiving task.  Note that the only things that cause
   this task to suspend are queue empty conditions and the time slice
   specified in the configuration file.   */
extern UINT8 g_UAudioStop;

void task_2(UNSIGNED argc, VOID *argv)
{
#if 1
	char *filename;
	STATUS         status; 

	/* Access argc and argv just to avoid compilation warnings.  */
	status =  (STATUS) argc + (STATUS) argv;
    
	while(1)
	{
#if 1	
		if(g_UDiskExit==0)
		{
			rPCONB |= (1<<10);

			rPCONC &= ~(0xff);
			rPCONC |= 0x54;
			rPDATC |= 0x0e;
			MassStorage_Init();
		}
		else
		{
			//Init_Key();
		}
#endif 
		if (g_UAudioStop == 0)
		{
			PostMessage(GetActiveWindow(),WM_PAINT,0,1);
			filename = MMI_GetFileListSelectItem_Name();
			//PlaybackAudioFile(1, filename, 0, 0, 0, 0);
			//PlaybackAudioFile(1, 1, 0, 0, 0, 0);
			g_UAudioStop = 1;
		}
	
		NU_Sleep(100);
        
	}
#endif
}








⌨️ 快捷键说明

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