/*=============================================================
* Copyright (c) 2008~2010, CPIT. All Rights Reserved.
*
* MODULE: i2c 驱动
*
* FILENAME: i2cDrv8548.c
*
* DESCRIPTION:i2c 驱动程序代码
*
*
* HISTORY:
*
* Date CR No Person Description
* ---------- ------------ ------ -------------
* 2008-11-27 litao created.
*
=============================================================*/
#include "vxWorks.h"
#include "sysLib.h"
#include "stdio.h"
#include "semLib.h"
#include "taskLib.h"
#include "../../comm_drv/nbDrvDef.h"
#include"../../comm_drv/nbdrvcommintf.h"
#include "../../Driver/I2C8548/8548_I2C/inc/i2cDrv8548.h"
#include "../inc/cpb40DrvApi.h"
#include "../inc/cpb8548Drv.h"
UINT8 gDdConfigWords[] =
{
0xAA,0x55,0xAA,
0xFF,0xFF,0xFF,0x00,0x2F,0x0C,0x00,
0xFF,0xFF,0xFF,0x44,0xEC,0x00,0x18,
0x01,
0x00,0x2F,0x0C,0x00,0x04,0xEC,0x00,0x28,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
STATUS cpb_reset_8144(void)
{
*(UINT8 *)CPB_CPLD_RESET_8144_REG=0x05;
taskDelay(sysClkRateGet());
return OK;
}
SYS_STATUS cpb_cfg_8144()
{
UINT32 cfg_len = 0;
UINT32 cfg_addr = 0x0;
/*write 8144 config*/
/*8144 reset status*/
cpb_reset_8144();
cfg_len = sizeof(gDdConfigWords);
if(NB_DRV_OK != mpc8548_i2c_write(1,0x50,0x00,cfg_len,(UINT8 *)&gDdConfigWords[0]))
{
printf("\r\n8144 config failed.");
return ERROR;
}
/*8144 reset status cleared*/
cpb_reset_8144();
return NB_DRV_OK;
}
/*------------------------------------------------------------------------------
*
* Function Name: fpga_download
*
* Input(s):
* UINT8* pdata:加载数据
* UINT32 len:加载数据长度
*
* Output(s):
* <none>
*
* Returns:
* DRV_OK: 成功
* DRV_ERR:失败
* DRV_API_ERR_INPUT_PARA:输入参数错误
*
* Description:
*GPIO 的管脚定义:
*GPOUT12 FPGA异步全片复位PROGRAM_B
*GPOUT13 FPGA配置时钟CCLK0
*GPOUT14 FPGA配置读写信号RDWR_B
*GPIN9 FPGA配置完成标志DONE
*GPIN10 FPGA配置校验标志INIT_B
*GPIN11 FPGA配置忙标志BUSY
*GPOUT0 FPGA配置数据D7
*GPOUT1 FPGA配置数据D6
*GPOUT2 FPGA配置数据D5
*GPOUT3 FPGA配置数据D4
*GPOUT4 FPGA配置数据D3
*GPOUT5 FPGA配置数据D2
*GPOUT6 FPGA配置数据D1
*GPOUT7 FPGA配置数据D0
*
------------------------------------------------------------------------------*/
SYS_STATUS cpb_fpga_download (UINT8 fpga_id, UINT8* str_ptr, UINT32 str_len)
{
UINT32 i;
UINT32 code = 0;
UINT8 *file_ptr = NULL;
UINT8 val;
UINT8 orderval;
UINT8 tempnum;
UINT32 tempval = 0;
UINT32 immr_val = /*(vxImmrGet() && 0xff000000)*/0x80000000;
if ((NULL == str_ptr ) || (0 == str_len) || (fpga_id>1))
{
return CPB_PARA_ERROR;
}
file_ptr = str_ptr;
*M85XX_GPIOCR(immr_val) |= (TX2OUT | RX2IN | PCIOUT |PCIIN|GPOUT);
*M85XX_DEVDISR(immr_val) |= ETSEC2_DISABLE;
*M85XX_DEVDISR(immr_val) |= (PCI2_DISABLE|PCI1_DISABLE);
if(0 == fpga_id)
{
/*prepare download, pulse PROGRAM pin down.*/
*M85XX_GPOUTDR(immr_val) &= (~FPGA1_PROG);
/*INIT_B*/
/* *M85XX_GPINDR(immr_val) &= (~FPGA1_INIT);*/
while(((*M85XX_GPINDR(immr_val) ) & (FPGA1_INIT)));
taskDelay(3) ;
*M85XX_GPOUTDR(immr_val) |= FPGA1_PROG;/* release */
/*taskDelay(3) ;*/
/* *M85XX_GPINDR(immr_val) |= FPGA1_INIT;*//* release */
while(!((*M85XX_GPINDR(immr_val) ) & (FPGA1_INIT)));
/*set CS*/
*M85XX_GPOUTDR(immr_val) |=FPGA2_CS;
*M85XX_GPOUTDR(immr_val) &=(~FPGA1_CS);
/**M85XX_GPOUTDR(immr_val) &=(~FPGA1_RDWR);*//*write fpga input*/
taskDelay(50) ; /* wait until FPGA finished internal memory clear */
/*check done pin, must be low*/
#if 0
if ((*M85XX_GPINDR(immr_val) & FPGA_DONE ))
{
printf("\r\nfpga_download:fpga busy.....");
return DRV_API_ERR_FPGA_BUSY ;
}
#endif
/*put data onto the FPGA*/
while ( code < str_len )
{
val = file_ptr[code++];
orderval = 0;
for(i = 0; i < 4; i++)
{
tempnum = (val>>(7 - i*2)) &((UINT8)0x80 >>(7 - i));
orderval |= tempnum;
tempnum = (val<<(7 - i*2)) &((UINT8)0x01 <<(7 - i));
orderval |= tempnum;
}
*M85XX_GPOUTDR(immr_val) &= (~FPGA1_CCLK); /* set CCLK lo */
tempval = *M85XX_GPOUTDR(immr_val);
*M85XX_GPOUTDR(immr_val) = (orderval |(tempval & (~FPGA_DATA_MASK)));/* put byte onto FPGA */
*M85XX_GPOUTDR(immr_val) |= FPGA1_CCLK; /* set CCLK hi */
}
/* send the bits of the last double word */
for (i = 0; i < 120; i++)
{
*M85XX_GPOUTDR(immr_val) &= (~FPGA1_CCLK); /* set CCLK lo */
*M85XX_GPOUTDR(immr_val) |= FPGA1_CCLK; /* set CCLK hi */
}
taskDelay(10);
if (!(*M85XX_GPINDR(immr_val) & FPGA1_DONE ))
{
printf("\r\nfpga_download:fpga is not done.....");
*M85XX_GPOUTDR(immr_val) |=FPGA2_CS;
*M85XX_GPOUTDR(immr_val) |=FPGA1_CS;
return ERROR ;
}
/*set CS*/
*M85XX_GPOUTDR(immr_val) |=FPGA2_CS;
*M85XX_GPOUTDR(immr_val) |=FPGA1_CS;
/*reset_fpga1*/
}
else
{
/*prepare download, pulse PROGRAM pin down.*/
*M85XX_GPOUTDR(immr_val) &= (~FPGA2_PROG);
/*INIT_B*/
*M85XX_GPINDR(immr_val) &= (~FPGA2_INIT);
taskDelay(3) ;
*M85XX_GPOUTDR(immr_val) |= FPGA2_PROG;/* release */
评论0