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

📄 i2cstatp.c

📁 用并口模拟的I2C驱动程序
💻 C
字号:
#include "stv0297.h"
#include <analysis.h>
//
#include "def.h"
#define SOURCE I2CSTATUSPANEL
//
#include <cvirte.h>		/* Needed if linking in external compiler; harmless otherwise */
#include <userint.h>
#include "driver.h"
//
#include "DrivMain.H"
#include "i2c.h"
#include "reg0297.h"
//
#define	SDA	0x01
#define	SCL	0x02
#define	ACK	0x04
//
#include "I2cStatP.h"
//
static int fail ;
//
extern struct {
               int Handle; char Title[50] ; int ButtonId; int Activity;
               int Top; int Left; int Height; int Width;
               int Next;int Previous;
               void (*RunPanel)(int); void (*HidePanel)(void);
              }DriverTaskList[50]  ;
//
int I2cStatusTestPPort(void)
{
	PPSTATE result;
	int FieldValue ;
	int ReadValue ;
	//
	FieldValue = FieldGetVal(ID) ;
	if(FieldValue == 0xFF)
	  FieldValue -= 1 ;
	else
	  FieldValue += 1 ;
	RegSetField(ID,FieldValue) ;
	//
	ReadValue =RegGetField(ID) ;
	if(ReadValue == FieldValue)
	  result = OK;
	else if(ReadValue == 0xFF)
	  result = WRONGADR ;
	else
	  result = NOACK ;
	//
	if(FieldValue == 0xFE)
	  FieldValue += 1 ;
	else
	  FieldValue -= 1 ;
	RegSetField(ID,FieldValue) ;
	//
   	return result;
}
//
//
//
int I2cStatusGetStatus(void)
{
	int status;
	int PanelHandle ;
	//
	PanelHandle = DriverTaskList[I2CSTATUSINDEX].Handle ;
	
	//I2cStop() ; <<<<< STEF:: doit poser un probl鑝e si l'on fait un stop alors qu'une autre fen阾re fait un acc閟 I2C  
	
	fail = I2cGetStatus() ;
	if(fail == 0x07)
	{
		SetCtrlVal (PanelHandle, I2CSTATUS_I2CSTATE,0);    
		status = 0 ;
	}
	else
	{
		SetCtrlVal (PanelHandle, I2CSTATUS_I2CSTATE,1);
		status = -1 ;
	}
	
	// SDA test
	if((fail&SDA)==0)
		SetCtrlVal (PanelHandle, I2CSTATUS_SDA, 0);
	else
		SetCtrlVal (PanelHandle, I2CSTATUS_SDA, 1);
	
	//  SCL test
	if((fail&SCL) == 0)
		SetCtrlVal (PanelHandle, I2CSTATUS_SCL, 0);
	else
		SetCtrlVal (PanelHandle, I2CSTATUS_SCL, 1);
	
	// ACK test
	switch(I2cStatusTestPPort())
	{
		case OK:
			fail |= (fail&ACK); 	
		break;
		
		case WRONGADR:
			SetCtrlVal (PanelHandle, I2CSTATUS_I2CSTATE,2);  
		case NOACK:
			fail = 0;
		break;	       
	}
	
	if((fail&ACK) == 0)
		SetCtrlVal (PanelHandle, I2CSTATUS_ACK, 0);
	else
		SetCtrlVal (PanelHandle, I2CSTATUS_ACK, 1);
	
	return (status);
}
//
//
//
void I2cStatusTest(int _MainPanel)
{
	int fail ;
	//
	fail = I2cGetStatus() ;
	if(fail != 0x07)
	{
		if(DriverTaskList[I2CSTATUSINDEX].Activity <= 0)
			I2cStatusRunPanel(_MainPanel) ;
	}
}
//
//**********************************************************************
//
//
void I2cStatusRunPanel(int _MainPanel)
{
	int status ;
	//
	status = I2cStatusGetStatus();
	I2cStatusShowPanel() ;
	//
	return ;
}
//
//
//
void I2cStatusShowPanel(void)
{
	DriverTaskList[I2CSTATUSINDEX].Activity = 1  ;
	DisplayPanel (DriverTaskList[I2CSTATUSINDEX].Handle);
	//
	return;
}
//
//
//
void I2cStatusHidePanel(void)
{
	HidePanel (DriverTaskList[I2CSTATUSINDEX].Handle);
	DriverTaskList[I2CSTATUSINDEX].Activity = 0  ;
	//
	return;
}


int CVICALLBACK I2cControlClbk (int panel, int control, int event,
		void *callbackData, int eventData1, int eventData2)
{
	unsigned int UInt=0;
	
	switch(control)
	{
		case I2CSTATUS_QUIT:
			if(event==EVENT_COMMIT)
				I2cStatusHidePanel(); 
		break;
		
		case I2CSTATUS_SPEED:
			if(event==EVENT_VAL_CHANGED)
			{
				GetCtrlVal (panel, control, &UInt);
				I2cInit(UInt);
				DriverMainTimerUpdate(UInt) ;
			}
		break;
	}
	
	return 0;
}

⌨️ 快捷键说明

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