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

📄 iic_test.c

📁 s3c6400 ADS下官方测试程序
💻 C
字号:
/**************************************************************************************
* 
*	Project Name : S3C6400 Validation
*
*	Copyright 2006 by Samsung Electronics, Inc.
*	All rights reserved.
*
*	Project Description :
*		This software is only for validating functions of the S3C6400.
*		Anybody can use this software without our permission.
*  
*--------------------------------------------------------------------------------------
* 
*	File Name : iic_test.c
*  
*	File Description : This file implements the API functons for IIC test.
*
*	Author : Woojin.Kim
*	Dept. : AP Development Team
*	Created Date : 2006/01/11
*	Version : 0.1 
* 
*	History
*	- Created(Woojin.Kim 2006/01/11)
*  
**************************************************************************************/


/* Include Files */

#include <string.h>
#include <stdio.h>
#include <stdlib.h>

#include "iic.h"
#include "def.h"
#include "option.h"
#include "library.h"
#include "sfr6400.h"
#include "system.h"
#include "sysc.h"
#include "intc.h"

void IIC_BTest(void);
void SFR_Test(void);
void IIC_MasterTxP(void);
void IIC_SlaveRxP(void);
void IIC_MasterRxP(void);
void IIC_SlaveTxP(void);
void IIC_SlaveTxInt(void);
void IIC_SlaveRxInt(void);


extern u8 g_uSlaveAddr;


const testFuncMenu g_aIICTestFunc[] =
{	
	SFR_Test,				"SFR R/W test    ",
	IIC_BTest,					"IIC Basic test (MasterTx/Rx from EEPROM)",
	IIC_MasterTxP,				"IIC Master Tx (B'd to B'd) by Polling",
	IIC_SlaveRxP,					"IIC Slave Rx (B'd to B'd) by Polling",
	IIC_MasterRxP,				"IIC Master Rx(B'd to B'd) by Polling",
	IIC_SlaveTxP,					"IIC Slave Tx(B'd to B'd) by Polling",
	IIC_SlaveTxInt,					"IIC Slave Tx(B'd to B'd) by Interrupt",	
	IIC_SlaveRxInt,					"IIC Slave Rx (B'd to B'd) by Interrupt",
	0,0
};


void IIC_Test(void)
{
	u32 uCountFunc=0;
	s32 iSel=0;

	printf("\n\n================== Timer Function Test =====================\n\n");


	
	while(1)
	{
		for (uCountFunc=0; (u32)(g_aIICTestFunc[uCountFunc].desc)!=0; uCountFunc++)
			printf("%2d: %s\n", uCountFunc, g_aIICTestFunc[uCountFunc].desc);

		printf("\nSelect the function to test : ");
		iSel =GetIntNum();
		printf("\n");
		if(iSel == -1) 
			break;

		if (iSel>=0 && iSel<(sizeof(g_aIICTestFunc)/8-1))
			(g_aIICTestFunc[iSel].func) ();
	}
}	




void SFR_Test(void)
{

	TestSFR();

}



//////////
// Function Name : IIC_test
// Function Description : This function tests IIC with 7-bit addresses by write and read out from EEPROM
// Input : NONE
// Output : Print out Data which readed out from EEPROM
// Version : v0.1

void IIC_BTest( void)
{
    u32 uCnt;
    u8 cData;

    printf("[ IIC Test using Serial EEPROM ]\n");

	IIC_Open(10000);

    printf("\nWrite (0xff) and read back from EEPROM\n");

    for(uCnt=0;uCnt<256;uCnt++) {
        cData=0;
	
       IIC_Write(0xa0,uCnt,0xff);		//EEPROM address = 0xa0
       IIC_Read(0xa0,uCnt,&cData);
        printf("%02x ",cData);
        if ((uCnt&0xf)==0xf) printf("\n");
		
    }

    printf("\nWrite (0~255) and read back from EEPROM\n");
    
    for(uCnt=0;uCnt<256;uCnt++) {
        cData=0;
       IIC_Write(0xa0,uCnt,uCnt);
       IIC_Read(0xa0,uCnt,&cData);
        printf("%02x ",cData);
        if ((uCnt&0xf)==0xf) printf("\n");
    }

	IIC_Close();
}


//////////
// Function Name : IIC_MasterTxP
// Function Description : This function tests polling mode of the MasterTx by B'd to B'd
// Input : NONE
// Output : Transmit data to SlaveRx Board
// Version : v0.1
// note) to test this function, SlaveRx should be ready
void IIC_MasterTxP(void)
{
    u32 sCnt;
    u8 cData[100];

    printf("IIC Master Tx Test (Board to Board)\n");
    printf("Connect IIC related signals (IICSCL, IICSDA, and GND) between IIC Master TX Board and IIC Slave RX Board.\n");
    printf("Make sure that IIC Slave Board is read and then Press any key.\n");

	GetIntNum();
    
	IIC_OpenPolling(200000);

	for(sCnt=0;sCnt<100;sCnt++)
		cData[sCnt]=(u8)sCnt;
	
	IIC_MasterWrP((u8)0xd0, cData);


	IIC_Close();

}


//////////
// Function Name : IIC_MasterRxP
// Function Description : This function tests polling mode of the MasterRx by B'd to B'd
// Input : NONE
// Output : Print out Data which readed out from SlaveTx Board
// Version : v0.1
// note ) to test this function , SlaveTx should be ready
void IIC_MasterRxP(void)
{
	s32 cCnt;
	static u8 cData[256];
//	static u8* pSlaveAddr;

	
    printf("IIC Slave Rx Test...\n");
    

	IIC_OpenPolling(200000);

	for(cCnt=0;cCnt<101;cCnt++)
		cData[cCnt]=0;


    printf("IIC Master Rx Test (Board to Board)\n");
    printf("Connect IIC related signals (IICSCL, IICSDA, and GND) between IIC Master RX Board and IIC Slave TX Board.\n");
    printf("At first, SlaveTx should set up before MasterRx. Make sure that SlaveTx is set up and Press any key to get data\n");

	GetIntNum();

	IIC_MasterRdP(0xc0,cData);

//	printf("Received Addr.: 0x%x\n",(u32)cSlaveAddr);
	for(cCnt=1;cCnt<101;cCnt++)
	printf("Received Data : 0x%0d\n",(u32)cData[cCnt]);


	IIC_Close();


}


//////////
// Function Name : IIC_SlaveTxP
// Function Description : This function tests polling mode of the SlaveTx by B'd to B'd
// Input : NONE
// Output : Transmit data to MasterRx Board
// Version : v0.1
void IIC_SlaveTxP(void)
{
    u32 sCnt;
    u8 cData[100];
    static u8 cSlaveAddr;
	
    printf("IIC Slave Tx Test (Board to Board)\n");
    printf("Connect IIC related signals (IICSCL, IICSDA, and GND) between IIC Master RX Board and IIC Slave TX Board.\n");
    
	IIC_OpenPolling(200000);

	for(sCnt=0;sCnt<100;sCnt++)
		cData[sCnt]=(u8)sCnt;
	
	cSlaveAddr = 0xc0;
	
	IIC_SlaveWrP(&cSlaveAddr, cData);


	IIC_Close();



}


//////////
// Function Name : IIC_SlaveRxP
// Function Description : This function tests polling mode of the SlaveRx by B'd to B'd connection
// Input : NONE
// Output : Print out Data which readed out from MasterTx Board
// Version : v0.1
void IIC_SlaveRxP(void)
{
	s32 cCnt;
	static u8 cData[256];
	static u8 cSlaveAddr;
//	static u8* pSlaveAddr;

	
    printf("IIC Slave Rx Test...\n");
    
    
	IIC_OpenPolling(200000);

	   cSlaveAddr = 0xd0;
   
	for(cCnt=0;cCnt<101;cCnt++)
		cData[cCnt]=0;

    printf("IIC Slave Rx Test (Board to Board)\n");
    printf("Connect IIC related signals (IICSCL, IICSDA, and GND) between IIC Master TX Board and IIC Slave RX Board.\n");
    printf("Waiting for Receiving Data\n");
	IIC_SlaveRdP(&cSlaveAddr,cData);

	printf("Received Addr.: 0x%x\n",(u32)cSlaveAddr);
	for(cCnt=1;cCnt<101;cCnt++)
	printf("Received Data : 0x%0d\n",(u32)cData[cCnt]);


	IIC_Close();
	
}


//////////
// Function Name : IIC_SlaveTxInt
// Function Description : This function tests Interrupt mode of the SlaveTx by B'd to B'd
// Input : NONE
// Output : Transmit data to MasterRx Board
// Version : v0.1
void IIC_SlaveTxInt(void)
{
    u32 sCnt;
    u8 cData[100];
    static u8 cSlaveAddr;
	
    printf("IIC Slave Tx Test (Board to Board)\n");
    printf("Connect IIC related signals (IICSCL, IICSDA, and GND) between IIC Master RX(Polling) Board and IIC Slave TX Board.\n");
    
	IIC_Open(200000);					// Interrupt mode

	for(sCnt=0;sCnt<100;sCnt++)
		cData[sCnt]=(u8)sCnt;
	
	cSlaveAddr = 0xc0;
	
	IIC_SlaveWrInt(&cSlaveAddr, cData);


	IIC_Close();



}


//////////
// Function Name : IIC_SlaveRxInt
// Function Description : This function tests Interrupt mode of the SlaveRx by B'd to B'd connection
// Input : NONE
// Output : Print out Data which readed out from MasterTxP Board
// Version : v0.1
void IIC_SlaveRxInt(void)
{

	s32 cCnt;
	static u8 cData[256];
	static u8 cSlaveAddr;
//	static u8* pSlaveAddr;

	
    printf("IIC Slave Rx Test...\n");
    
    
	IIC_Open(200000);					//Interrupt mode
   	cSlaveAddr = 0xd0;
   
	for(cCnt=0;cCnt<101;cCnt++)
		cData[cCnt]=0;

    printf("IIC Slave Rx Test (Board to Board)\n");
    printf("Connect IIC related signals (IICSCL, IICSDA, and GND) between IIC Master TX(Polling) Board and IIC Slave RX Board.\n");
    printf("Waiting for Receiving Data\n");
	IIC_SlaveRdInt(&cSlaveAddr,cData);

	cSlaveAddr = cData[0];

	printf("Received Addr.: 0x%x\n",(u32)cSlaveAddr);
	for(cCnt=1;cCnt<101;cCnt++)
	printf("Received Data : 0x%0d\n",(u32)cData[cCnt]);


	IIC_Close();

}





⌨️ 快捷键说明

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