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

📄 smbusdlg.cpp

📁 使用winio通过intel 南桥smbus controller对 IDT/silego clock 进行操作为例
💻 CPP
字号:
// smbusDlg.cpp : implementation file
//

#include "stdafx.h"
#include "smbus.h"
#include "smbusDlg.h"

#include "WinIo.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSmbusDlg dialog

CSmbusDlg::CSmbusDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSmbusDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSmbusDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CSmbusDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSmbusDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CSmbusDlg, CDialog)
	//{{AFX_MSG_MAP(CSmbusDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSmbusDlg message handlers

BOOL CSmbusDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CSmbusDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CSmbusDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CSmbusDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CSmbusDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
	#define  IO_SC 0x0cf8 //config  space  control  address
    #define  IO_DA 0x0cfc //config  space  data  address
 char ch[10];
 
 DWORD dataddr=0x8000fb20;  //for intel 
 DWORD dwPortVal,baseddr;
    //  Call  InitializeWinIo  to  initialize  the  WinIo  library.
  BOOL bResult = InitializeWinIo();

    if(bResult)
{
    //Get  SMBus  base  address
    SetPortVal(IO_SC,dataddr,4);
    GetPortVal(IO_DA,&dwPortVal,4);
    baseddr=dwPortVal&0xfffffff0;

 //  itoa(baseddr,ch,10);
 
 //    MessageBox(ch);

   DWORD  RetVal=0;
   SetPortVal(baseddr,0xfe,1);      //清除smbus controller的中断标志位
    //output  Base+04,  (DeviceID+1)
   SetPortVal(baseddr+0x04,0xd2,1); //写发送地址。
    //out  Base+03,  offset
   SetPortVal(baseddr+0x03,0x02,1);  //写发送命令,一般就是器件地址偏移量。
    //out  Base+02,  48H
   SetPortVal(baseddr+0x05,0x03,1);  //写发送数据。
   SetPortVal(baseddr+0x02,0x48,1);  //开始smbus传输。
   
  
  while(1)
{
   
 GetPortVal(baseddr,&RetVal,1);
 if(RetVal==0x42)
	 break;

  }         //等待smbus传输完成。

 GetPortVal(baseddr+0x05,&RetVal,1);
 itoa(RetVal,ch,10);
 MessageBox("呵呵!屏幕花了吧!");

	
}
    ShutdownWinIo();
}

void CSmbusDlg::OnButton2() 
{
	// TODO: Add your control notification handler code here
	#define  IO_SC 0x0cf8 //config  space  control  address
    #define  IO_DA 0x0cfc //config  space  data  address
 char ch[10];
 
 DWORD dataddr=0x8000fb20;  //for intel 
 DWORD dwPortVal,baseddr;
    //  Call  InitializeWinIo  to  initialize  the  WinIo  library.
  BOOL bResult = InitializeWinIo();

    if(bResult)
{
    //Get  SMBus  base  address
    SetPortVal(IO_SC,dataddr,4);
    GetPortVal(IO_DA,&dwPortVal,4);
    baseddr=dwPortVal&0xfffffff0;

 //  itoa(baseddr,ch,10);
 
 //    MessageBox(ch);

   DWORD  RetVal=0;
   SetPortVal(baseddr,0xfe,1);      //清除smbus controller的中断标志位
    //output  Base+04,  (DeviceID+1)
   SetPortVal(baseddr+0x04,0xd2,1); //写发送地址。
    //out  Base+03,  offset
   SetPortVal(baseddr+0x03,0x02,1);  //写发送命令,一般就是器件地址偏移量。
    //out  Base+02,  48H
   SetPortVal(baseddr+0x05,0x83,1);  //写发送数据。
   SetPortVal(baseddr+0x02,0x48,1);  //开始smbus传输。
   
  
  while(1)
{
   
 GetPortVal(baseddr,&RetVal,1);
 if(RetVal==0x42)
	 break;

  }         //等待smbus传输完成。

 GetPortVal(baseddr+0x05,&RetVal,1);
 itoa(RetVal,ch,10);
 MessageBox("呵呵!又好了吧。");

	
}
    ShutdownWinIo();	
}

⌨️ 快捷键说明

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