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

📄 timex20t_old.c

📁 此压缩包为杰得开发得z228的BSP的源代码,可以实现很多功能,尤其是视频解码有很好的效果.
💻 C
📖 第 1 页 / 共 2 页
字号:
/*   The content of this file or document is CONFIDENTIAL and PROPRIETARY
*   to Jade Technologies Co., Ltd.  It is subjected to the terms of a
*   License Agreement between Licensee and Jade Technologies Co., Ltd.
*   restricting among other things, the use, reproduction, distribution
*   and transfer.  Each of the embodiments, including this information 
*   and any derivative work shall retain this copyright notice.
* 
*   Copyright (c) 2004 - 2005 Jade Technologies Co., Ltd. 
*   All rights reserved.
 * ----------------------------------------------------------------
 * File:     timex20t.c,v
 * Revision: 1.0
 * ----------------------------------------------------------------
 * $
 */

#include <windows.h>
#include <nkintr.h>
#include <oalintr.h>

#include "win_plat.h"
#include <oalfuncs.h>
#include <pl031.h>  // RTC
//yz_add
//#include <ceddk.h>
#include "gpiodrv.h"
//#include "Winbase.h"

extern DWORD OEMCount1ms;

DWORD dwReschedIncrement;

unsigned __int64 RealTimeBias = 0;  /* Number of 100-nanosecond intervals since */
                                    /* January 1, 1601.                         */
unsigned __int64 RTCBias = 0;									
//yz_add
typedef unsigned char u8;
typedef unsigned short u16;

#define SCLK_0	pGpio1Regs->Padding1[254]  &= (~0x80)
#define SCLK_1	pGpio1Regs->Padding1[254]  |= 0x80
#define RST_0  	pGpio1Regs->Padding1[254]  &= (~0x40)
#define RST_1  	pGpio1Regs->Padding1[254]  |= 0x40

#define IO_I		pGpio2Regs->GPIODir &= (~0x80)	//gpio6_7 in
#define IO_O		pGpio2Regs->GPIODir |= 0x80	//gpio6_7 out

#define IO_W0   	pGpio2Regs->Padding1[254]  &= (~0x80)
#define IO_W1   	pGpio2Regs->Padding1[254]  |= 0x80
#define IO_R   	pGpio2Regs->Padding1[254] & 0x80

void RTC_Init();
void W1381(u8 cmd, u8 data);
void R1381(u8 cmd, u8 *data);
//yz_end

void HalTimerInit(void)
{
    pvstRTCRegs pRTC = (pvstRTCRegs) VA_RTC_BASE;
    
    pRTC->CR = 1;           /* Set the RTC running */
}

void InitClock(void)
{
    pvstRTCRegs pRTC = (pvstRTCRegs) VA_RTC_BASE;
    
    /* InitClock() is called when a suspend mode is exited.  Be careful that 
     * debug is not included when developing power handling code, as the
     * system will not exit cleanly and it is tricky to debug. 
     */
     
     //yz_add
	RETAILMSG (1, (TEXT("+InitClock\r\n")));
	RTC_Init();
	
    /* Set up timers */
    uHALr_InitTimers();
    
    /* disable RTC interrupts at the RTC */
    pRTC->IMSC = 0;

    /* initialize and start scheduler timer */
    dwReschedIncrement = RESCHED_INCREMENT;
    OEMCount1ms = OEM_COUNT_1MS;

    OEMClockFreq = OEM_CLOCK_FREQ;

    CPUSetSysTimerCount(RESCHED_PERIOD);
    RETAILMSG (1, (TEXT("-InitClock\r\n")));
    return;
}


//yz_add for RTC
void apSleepus(unsigned int usec)
{
	volatile int i;	
    while (usec--) 
    {   
		i=33;
		while(i--);
	}
}

void apSleep(unsigned int msec)
{
    while (msec--)
	    apSleepus(1000);
}


void delay(unsigned int msec)
{
	//apSleep(msec);
	apSleepus(msec*10);
	//Sleep(1);
}

//PGPIO_INFO		pGpioHead = NULL;

volatile PGPIO_REGS pGpio1Regs;
volatile PGPIO_REGS pGpio2Regs;

void Gpio_Init()
{   
    RETAILMSG (1, (TEXT("+GIO_Init\r\n")));
#if 0	
    // Allocate our control structure.
    pGpioHead = (PGPIO_INFO)LocalAlloc(LPTR, sizeof(GPIO_INFO));
    // Check that LocalAlloc did stuff ok too.
    if ( !pGpioHead ) {
        RETAILMSG(1, (TEXT("Error allocating memory for pGpioHead, GIO_Init failed\r\n")));
        return;
    }
#endif
	pGpio1Regs = (PGPIO_REGS) VA_GPIO5_BASE;
	pGpio2Regs = (PGPIO_REGS) VA_GPIO6_BASE;

	pGpio1Regs->GPIODir |= 0xC0;	//gpio5_6, 5_7 out, RST, SCLK
	pGpio2Regs->GPIODir &= (~0x80);	//gpio6_7 in, I/O
	
	pGpio1Regs->Padding1[254] &= (~0xC0);	//gpio5_6, 5_7 low
	RETAILMSG (1, (TEXT("-GIO_Init\r\n")));
	return;
}

void RTC_Init()
{
	u8 temp;
	Gpio_Init();
	R1381(0x81, &temp);
	RETAILMSG(1, (TEXT("+RTC_Init\r\n")));
	RETAILMSG(1, (TEXT("0x81: %x  \r\n"),temp));
	if(temp&0x80)
	{	
		temp &= 0x7F; 
		W1381(0x80, temp);		
	}	
	W1381(0x8e, 0x00);
	//apSleep(100);
#if 0
	R1381(0x81, &temp);
	RETAILMSG(1, (TEXT("sec: %x  "),temp));
	R1381(0x83, &temp);
	RETAILMSG(1, (TEXT("min: %x  "),temp));
	W1381(0x84, 0x10);
	R1381(0x85, &temp);	
	RETAILMSG(1, (TEXT("hour: %x  "),temp));       	
	W1381(0x86, 0x20);
	R1381(0x87, &temp);	
	RETAILMSG(1, (TEXT("date: %x  "),temp));       
	W1381(0x88, 0x11);
	R1381(0x89, &temp);	
	RETAILMSG(1, (TEXT("month: %x  "),temp));       
	W1381(0x8a, 0x6);
	R1381(0x8b, &temp);	
	RETAILMSG(1, (TEXT("day: %x  "),temp));       
	W1381(0x8c, 0x98);
	R1381(0x8d, &temp);	
	RETAILMSG(1, (TEXT("year: %x  "),temp));       	
	RETAILMSG(1, (TEXT("\r\n"))); 
#endif
	RETAILMSG(1, (TEXT("-RTC_Init\r\n")));
	return;
}

void W1381(u8 cmd, u8 data)
{
	int i = 0;
	//u8 temp = 0;
	IO_O;
	
	RST_0;
	SCLK_0;
		
	RST_1;
	delay(1);
	for(i = 0;i < 8; i++)
	{
		if((cmd>>i) & 0x01)
			IO_W1;
		else
			IO_W0;			
			
		SCLK_1;	
		delay(1);
		SCLK_0;	
		delay(1);
	}

	for(i = 0;i < 8; i++)
	{
		if((data>>i) & 0x01)
			IO_W1;
		else
			IO_W0;			
			
		SCLK_1;	
		delay(1);
		SCLK_0;	
		delay(1);
	}	
	RST_0;
	return;
}

void R1381(u8 cmd, u8 *data)
{
	int i = 0;
	//u8 temp = 0;
	*data = 0x0;
	IO_O;
	
	RST_0;
	SCLK_0;
		
	RST_1;
	delay(1);
	for(i = 0;i < 8; i++)
	{
		if((cmd>>i) & 0x01)
			IO_W1;
		else
			IO_W0;			
			
		SCLK_1;	
		delay(1);
		SCLK_0;	
		delay(1);
	}

	IO_I;
	
	for(i = 0;i < 8; i++)
	{		
		if(IO_R)
			*data |= (0x01<<i);			
		SCLK_1;	
		delay(1);

⌨️ 快捷键说明

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