Chipscope 仿真VmodCAM IIC程序:
目的:熟悉EDK中建立chipscope
注意:zedboard使用digilent USB下载时,chipscope不能和SDK同时使用,否则芯片会死机。要用仿真器烧写程序。
1:搭建硬件平台
2:编写SDK软件
0x30,0x00,0x00,0x00, // Chip version. Default 0x1580 !! only for read !! 0x33,0x86,0x05,0x01, // MCU Reset 0x32,0x90,0x00,0x01, // test pattern 0x32,0x92,0x00,0x00, // R pattern 0x32,0x94,0x00,0xff, // G pattern 0x32,0x96,0x00,0x00, // B pattern 0x33,0x86,0x05,0x00, // MCU Release from reset 0x32,0x14,0x0D,0x85, // Slew rate control, PCLK 5, D 5 0x34,0x1E,0x8F,0x09, // PLL control; bypassed, powered down 0x34,0x1C,0x02,0x30, // PLL dividers; M=80,N=2,fMCLK=fCLKIN*M/(N+1)/8=24MHz 0x34,0x1E,0x8F,0x09, // PLL control; Power-up PLL; wait 1ms after this! 0x34,0x1E,0x8F,0x08, // PLL control; Turn off bypass 0x32,0x02,0x00,0x08, // Standby control; Wake up
0x33,0x8C,0x27,0x97, // Output format; Context B shadow 0x33,0x90,0x00,0x20, // RGB with BT656 codes
0x33,0x8C,0x27,0x2F, // Sensor Row Start Context B 0x33,0x90,0x00,0x04, // 4 0x33,0x8C,0x27,0x33, // Sensor Row End Context B 0x33,0x90,0x04,0xBB, // 1211 0x33,0x8C,0x27,0x31, // Sensor Column Start Context B 0x33,0x90,0x00,0x04, // 4
0x33,0x8C,0x27,0x35, // Sensor Column End Context B 0x33,0x90,0x06,0x4B, // 1611 0x33,0x8C,0x27,0x07, // Output width; Context B 0x33,0x90,0x02,0x80, // 640 0x33,0x8C,0x27,0x09, // Output height; Context B 0x33,0x90,0x01,0xE0, // 480
0x33,0x8C,0x27,0x5F, // Crop X0; Context B 0x33,0x90,0x00,0x00, // 0 0x33,0x8C,0x27,0x63, // Crop Y0; Context B 0x33,0x90,0x00,0x00, // 0 0x33,0x8C,0x27,0x61, // Crop X1; Context B 0x33,0x90,0x06,0x40, // 1600 0x33,0x8C,0x27,0x65, // Crop Y1; Context B 0x33,0x90,0x04,0xB0, // 1200
0x33,0x8C,0x27,0x41, // Sensor_Fine_IT_min B 0x33,0x90,0x01,0x69, // 361 0x33,0x8C,0xA1,0x20, // Capture mode options 0x33,0x90,0x00,0xF2, // Turn on AWB, AE, HG, Video 0x33,0x8C,0xA1,0x03, // Refresh Sequencer Mode 0x33,0x90,0x00,0x02, // Capture 0x33,0x90,0x00,0x00, // Read until sequencer in mode 0 (run) 0x30,0x1A,0x02,0xCC, // reset/output control; parallel enable, drive pins, start streaming
/*****************************************************************************/
/**
* This function is initial the iic_0.
*
* @param	None.
*
* @return	The number of bytes sent.
*
* @note		None.
*
****************************************************************************/
int  IIC_Initial( XIic *IicInstance, u16 DeviceId)
{
			 XIic_Config *IICConfigPtr;	/* Pointer to configuration data */
			 Xil_AssertNonvoid(IicInstance != NULL);
	 	 	 /*
		     * Initialize the IIC driver so that it is ready to use.
		     */
		    IICConfigPtr = XIic_LookupConfig(DeviceId);
			if (IICConfigPtr == (XIic_Config *) NULL) {
				IicInstance->IsReady = 0;
				return (XST_DEVICE_NOT_FOUND);
			}
			return XIic_CfgInitialize(IicInstance, IICConfigPtr,IICConfigPtr->BaseAddress);
}int Vmod_CameraA_IIC_Config()
{
	unsigned ByteCount=0;
	int i = 0;
	u8 ReadCamera_ChipVersion_Add[2] = {0x30,0x00};
	u8 ReadCamera_ChipVersion_Rdata[2];
	u16 Chip_Version = 0;
	printf("Here we go\n");
	printf("Config the Camera\n");
	read_camera_config(XPAR_CAMER_IIC_A_BASEADDR,ReadCamera_ChipVersion_Add,ReadCamera_ChipVersion_Rdata);
	Chip_Version = (ReadCamera_ChipVersion_Rdata[0] << 8) | ReadCamera_ChipVersion_Rdata[1];
	printf("Read Chip Version is:0x%x\n",Chip_Version);
	for(i=0;i<MT9D112_CONFIG_BUFFER_ROWS;i++)
	{
		ByteCount += XIic_Send(XPAR_CAMER_IIC_A_BASEADDR,CAMERA_ADDRESS_ID,MT9D112_CONFIG_BUFFER[i],4,XIIC_STOP);
	}
	if(MT9D112_CONFIG_BUFFER_ROWS*4 == ByteCount)
	{
		printf("Camera Initialize success\n");
		printf("Camera Initialize ByteCount is:%d\n",ByteCount);
		return ByteCount;
	}
	else printf("Camera Initialize fail\n");
}
void read_camera_config (u32 BaseAddress, u8 *sub_addr, u8 *RdData)
{
	u8 sent_byte_count;
	u8 received_byte_count;
	RdData[0] = 0;
	RdData[1] = 0;
	xil_printf("Read\t");
	sent_byte_count = XIic_Send(BaseAddress, 0x78>>1, sub_addr, 2, XIIC_STOP); //write sub-address
	if (sent_byte_count != 2)
		xil_printf("Sent %d bytes\t", sent_byte_count);
	received_byte_count = XIic_Recv(BaseAddress, 0x79>>1, RdData, 2, XIIC_STOP); //read 2 byte datas
	if (received_byte_count != 2)
		xil_printf("Received %d bytes\r\n", received_byte_count);
	else
		xil_printf("0x%02x 0x%02x\r\n", RdData[0], RdData[1]);
}3:ChipScope 调试
4 VmodCAM
硬件写地址0x78 读地址0x79
访问方式:
1、通过直接的硬件寄存器访问
2、通过驱动变量进行配置,这种配置都是靠R[0X338C]与R[0X3390]两个硬件寄存器间接访问,R[0X338C]是选择驱动变量的寄存器,R[0X3390]则是设置对应驱动变量的值。
图 1 驱动变量地址
供电与复位:
配置操作:
寄存器上电的初始值
首先就可以读取摄像头的ID 地址是R[0X3000],读取的ID应该是0X1580.
然后复位MCU
PLL 时钟配置:
PLL配置包括R[0X341C]用于PLL输出(PCLK)频率设置。PCLK = MCLK*M/((N+1)/8), R[0X341E]用于设置PLL工作与否 还有旁路有否。如果想要旁路掉PLL那么R[0X341E]【0】必须设置为1,如果有功耗要求,可以将R[0X341E]【1】设置为1来关闭PLL 。如果要打开PLL,那么以上两位必须设置为0.在默认情况下,都是关闭和旁路掉PLL的。
Any changes to PLL settings must be done with PLL bypassed (R0x341E[0]=1). (当需要修改PLL的参数时必须保持PLL在旁路状态)
PLL programming and power-up sequence is as follows:
1. Program PLL frequency settings, R0x341C (pll_m, pll_n) (master clock frequency is
equal to fVCO_pll/8). With default settings master clock frequency of 80 MHz is
obtained with fCLKIN=16MHz.
2. Power up PLL, R0x341E[1] = 0.
3. Wait for PLL settling time > 1ms.
4. Turn off PLL bypass, R0x341E[0] = 0.
 
                    
                     
                    
                 
                    
                 
 
         
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号