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

📄 ad6650.c

📁 这是单板上DPRAM的驱动程序
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <psos.h>
#include "board.h"
#include "sdev.h"
#include "AD6650.h"

/* AD6650 Base Address */
const char *AD6650_BASE=(char*)0x40000000;
int INI_STATUS_6650;
void AD6650WriteReg( unsigned short Address, ULONG Data );
ULONG AD6650ReadReg( unsigned short Address);
void AD6650HardReset(void);

/* rd */
int AD6650Read ( void *pDataBuf, void *pBuf, int MaxLen )
{
    ULONG AD_ReadBack;
    AD6650MemValue* pMemBuf = (AD6650MemValue*)pBuf;

    if(MaxLen!=sizeof(AD6650MemValue)||(pMemBuf->MemAdd>0x6f))
        return SDE_INVALID_ARG;
    AD_ReadBack=AD6650ReadReg((unsigned short)(pMemBuf->MemAdd));
    if(AD_ReadBack!=AD6650_ADR_ERR)
    {
    	pMemBuf->MemDat=AD_ReadBack;
    	return SDE_OK;
    }
    else
    	return SDE_INVALID_ARG;
}  				    				   				   				  				  				   				    				  				   				 				     				    			   			   			


/* Internal Function */
void AD6650WriteReg( unsigned short Address, ULONG Data )
{
    unsigned char d[3] = {0};

    *(unsigned char *)(AD6650_BASE+AD6650_ACR) = 0x0;
    *(unsigned char *)(AD6650_BASE+AD6650_CAR) = (unsigned char)Address;

    if(Address<0x40)
    {
	    switch(Address)
    	{
    		case 0x0:
	    	case 0x17:	d[0] = (unsigned char)(Data&0x00000001);
	    				break;
	    	case 0x1:
	    	case 0x2:
	    	case 0x3:
			case 0x4:	d[2] = (unsigned char)((Data&0x003F0000)>>16);
        				*(unsigned char *)(AD6650_BASE+AD6650_DATA2) = d[2];
        				d[1] = (unsigned char)((Data&0x0000FF00)>>8);   
        				*(unsigned char *)(AD6650_BASE+AD6650_DATA1) = d[1];
						d[0] = (unsigned char)(Data&0x000000FF);
	    				break; 
	   		case 0x1c:
	   		case 0x9:	d[0] = (unsigned char)(Data&0x00000003);
	    				break; 
	    	case 0x6:	
	    	case 0x7:
	    	case 0x8:	d[0] = (unsigned char)(Data&0x000000FF);
	    				break;
	    				
	    	case 0x0b:	/*d[0] = (unsigned char)(Data&0x000FFFFF);
	    				break;*/
	    			d[2] = (unsigned char)((Data&0x000F0000)>>16);
        			*(unsigned char *)(AD6650_BASE+AD6650_DATA2) = d[2];
        			d[1] = (unsigned char)((Data&0x0000FF00)>>8);   
        			*(unsigned char *)(AD6650_BASE+AD6650_DATA1) = d[1];
				d[0] = (unsigned char)(Data&0x000000FF);
				break; 	

	    	case 0x0e:
	    	case 0x11:			
	   		case 0x14:	d[1] = (unsigned char)((Data&0x0000FF00)>>8);   
        				*(unsigned char *)(AD6650_BASE+AD6650_DATA1) = d[1];
						d[0] = (unsigned char)(Data&0x000000FF);
	    				break;  
	    	case 0x0a:
	    	        d[0] = (unsigned char)(Data&0x0000000F);
	    	    		break; 
 	
	   	case 0x0c:	
	    	case 0x22:	d[0] = (unsigned char)(Data&0x0000000F);
	    	    		break; 
	   		case 0x0d:	d[1] = (unsigned char)((Data&0x00000100)>>8);   
        				*(unsigned char *)(AD6650_BASE+AD6650_DATA1) = d[1];
						d[0] = (unsigned char)(Data&0x000000FF);
	    				break;  
	   		case 0x0f:	d[1] = (unsigned char)((Data&0x00000700)>>8);   
        				*(unsigned char *)(AD6650_BASE+AD6650_DATA1) = d[1];
						d[0] = (unsigned char)(Data&0x000000FF);
	    				break;
	   		case 0x10:	d[1] = (unsigned char)((Data&0x00001F00)>>8);   
        				*(unsigned char *)(AD6650_BASE+AD6650_DATA1) = d[1];
						d[0] = (unsigned char)(Data&0x000000FF);
	    				break; 
	  		case 0x12:	d[0] = (unsigned char)(Data&0x0000007F);
	    				break;  
	   		case 0x13:
	   		case 0x21:	d[1] = (unsigned char)((Data&0x00000100)>>8);   
        				*(unsigned char *)(AD6650_BASE+AD6650_DATA1) = d[1];
						d[0] = (unsigned char)(Data&0x000000FF);
	    				break;  
	   		case 0x15:	d[0] = (unsigned char)(Data&0x0000001F);
	    				break; 
	   		case 0x16:	d[0] = (unsigned char)(Data&0x0000000F);
	    				break; 
	   		case 0x18:
	   		case 0x19:	d[0] = (unsigned char)(Data&0x00000007);
	    				break;
	   		case 0x5:
	   		case 0x1a:
	   		case 0x1b:	d[0] = (unsigned char)(Data&0x0000003F);
	    				break;
	    	default:	break;
	    }
	}
	else
	{
		d[2] = (unsigned char)((Data&0x000F0000)>>16);
        *(unsigned char *)(AD6650_BASE+AD6650_DATA2) = d[2];		
		d[1] = (unsigned char)((Data&0x0000FF00)>>8);   
        *(unsigned char *)(AD6650_BASE+AD6650_DATA1) = d[1];
		d[0] = (unsigned char)(Data&0x000000FF);
    }
    *(unsigned char *)(AD6650_BASE+AD6650_DATA0) = d[0];
}

/* Internal Function */
ULONG AD6650ReadReg( unsigned short Address)
{
    char d[3] = {0};

    if(Address>0x6f)
        return AD6650_ADR_ERR;
   
    *(unsigned char *)(AD6650_BASE+AD6650_CAR) = (unsigned char)Address;
    *(unsigned char *)(AD6650_BASE+AD6650_ACR) = 0x0;
    
    d[0] = (*(char *)(AD6650_BASE+AD6650_DATA0))&0x0FF;
    if(Address<0x40)
    {
	    switch(Address)
    	{
    		case 0x0:
	    	case 0x17:	return (ULONG)(d[0]&0x01);
	    				break;
	    	case 0x1:
	    	case 0x2:
	    	case 0x3:
			case 0x4:	d[1] = (*(char *)(0x40000000+AD6650_DATA1))&0x0FF;
	            		d[2] = (*(char *)(0x40000000+AD6650_DATA2))&0x03F;
						return (ULONG)((d[0]|(d[1]<<8)|(d[2]<<16))&0x3FFFFF); 
	    	case 0x6:	
	    	case 0x7:
	    	case 0x8:	return (ULONG)(d[0]&0x0FF);
	   		case 0x9:
	   		case 0x1c:	return (ULONG)(d[0]&0x03);
	    	case 0x0e:
	    	case 0x11:			
	   		case 0x14:	d[1] = (*(char *)(0x40000000+AD6650_DATA1))&0x0FF;
	   					return (ULONG)((d[0]|(d[1]<<8))&0x0FFFF);  
	   		case 0x0c:	return (ULONG)(d[0]&0x0f); 
	   		case 0x0d:	d[1] = (*(char *)(0x40000000+AD6650_DATA1))&0x01;
	   					return (ULONG)((d[0]|(d[1]<<8))&0x1ff);
	   		case 0x0f:	d[1] = (*(char *)(0x40000000+AD6650_DATA1))&0x07;
	   					return (ULONG)((d[0]|(d[1]<<8))&0x7ff);
	   		case 0x10:	d[1] = (*(char *)(0x40000000+AD6650_DATA1))&0x1f;
	   					return (ULONG)((d[0]|(d[1]<<8))&0x1fff);
	  		case 0x12:	return (ULONG)(d[0]&0x7f); 
	   		case 0x13:
	   		case 0x21:	d[1] = (*(char *)(0x40000000+AD6650_DATA1))&0x1;
	   					return (ULONG)((d[0]|(d[1]<<8))&0x1ff); 
	   		case 0x15:	return (ULONG)(d[0]&0x1f);
	    	case 0x0a:
	    	case 0x22:	   		
	   		case 0x16:	return (ULONG)(d[0]&0x0f);
	   		case 0x18:
	   		case 0x19:	return (ULONG)(d[0]&0x07);
	   		case 0x1a:
	   		case 0x5:	   		
	   		case 0x1b:	return (ULONG)(d[0]&0x03f);
	    	case 0x0b:  d[1] = (*(char *)(0x40000000+AD6650_DATA1))&0x0FF;
	            		d[2] = (*(char *)(0x40000000+AD6650_DATA2))&0x0F;
						return (ULONG)((d[0]|(d[1]<<8)|(d[2]<<16))&0x0FFFFF); 	   		
	    	default:	return 	AD6650_ADR_ERR;
	    }
	}
	else
	{
		d[1] = (*(char *)(0x40000000+AD6650_DATA1))&0x0FF;
        d[2] = (*(char *)(0x40000000+AD6650_DATA2))&0x0F;	
    	return (ULONG)((d[0]|(d[1]<<8)|(d[2]<<16))&0x0FFFFF);	
    }
}

void AD6650HardReset()
{
    int i;
    volatile float temp;
    SET_PC_BIT(4,0);/* Hard Reset */
    for(i=0;i<200;i++)
        temp = temp*1.19;
    SET_PC_BIT(4,1);/* Hard Reset Over */
 
    
}

ULONG CheckRegVal(unsigned short RegAddress,ULONG ConfData)
{
	if(AD6650ReadReg(RegAddress)!=ConfData)
		return REGDATAERR;
	else
		return REGDATAOK;
}
void AD6650Init(void *pDataBuf, AD6650CfgStruct *cfg )
{
    unsigned char d[5] = {0};
    ULONG temp_value;
    ULONG i;
    
    AD6650CfgStruct* pCfg = (AD6650CfgStruct *)(pDataBuf);
/*-------------------------<< Initial data >>-------------------------------*/
    memmove(pCfg,cfg,sizeof(AD6650CfgStruct));
    
    AD6650HardReset();
    #ifdef _AD6620_H      
    AD6620WriteReg(AD6650_MODE_REG,(ULONG)0x01);  /* Soft_Reset */
    #endif
    
    /* Init Coefficient RAM ,Address Increment Auto */
    *(unsigned char *)(AD6650_BASE+AD6650_CAR) = (unsigned char)(AD6650_CO_MEM);
    *(unsigned char *)(AD6650_BASE+AD6650_ACR) = (unsigned char)0x80;  
    /*for(i=0x40;i<0x6f;i++)*/
    for(i=0x0;i<48;i++)
    {
    /*	*(unsigned char *)(AD6650_BASE+AD6650_CAR) = (unsigned char)i;*/
        d[2] = (unsigned char)((pCfg->Coefficient[i]&0x000F0000)>>16);
        *(unsigned char *)(AD6650_BASE+AD6650_DATA2) = d[2];
        d[1] = (unsigned char)((pCfg->Coefficient[i]&0x0000FF00)>>8);
        *(unsigned char *)(AD6650_BASE+AD6650_DATA1) = d[1];

⌨️ 快捷键说明

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