查看: 2918|回复: 0

[Wince技术] 实现看门狗功能的应用程序3

[复制链接]
  • TA的每日心情

    2014-4-10 13:56
  • 签到天数: 5 天

    连续签到: 1 天

    [LV.2]偶尔看看I

    发表于 2014-1-23 09:07:53 | 显示全部楼层 |阅读模式
    分享到:
    本帖最后由 forlinx2013 于 2014-1-24 09:16 编辑

    欢迎大家来到飞凌爱板网专区,对嵌入式技术感兴趣的朋友不妨多多关注一下,我们提供了公司所有开发板的所有资料,也会更新大量技术文章,欢迎大家一块学习提高!!!

    看门狗测试应用程序

    硬件平台:飞凌OK6410-A
    操作系统:飞凌光盘中的BSPWINCE6.0
    编译工具:VS2005 + WINCE6.0 + BSP
    打开VS2005,新建一个工程为watchdog_test
    // watchdog_testDlg.cpp : 实现文件
    //

    #include "stdafx.h"
    #include "watchdog_test.h"
    #include "watchdog_testDlg.h"
    #include <ceddk.h>
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #endif

    #define IOCTL_wdg_wdg1_OPEN                                  0x04002060
    #define IOCTL_wdg_wdg1_CLOSE                                0x04002061

    BOOL flag_wdg = 1;
    HANDLE hwdg;
    HANDLE hThread;
    DWORD convalue = 4;
    CString str;
    //int i;
    DWORD WINAPI wdgThread (PVOID);

    // Cwatchdog_testDlg 对话框

    Cwatchdog_testDlg::Cwatchdog_testDlg(CWnd* pParent /*=NULL*/)
            : CDialog(Cwatchdog_testDlg::IDD, pParent)
            , value_wdg(_T(""))
    {
            m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    }

    void Cwatchdog_testDlg:oDataExchange(CDataExchange* pDX)
    {
            CDialog:oDataExchange(pDX);
            DDX_Control(pDX, IDC_start_wdg, m_ctrl_start);
            DDX_Text(pDX, IDC_EDIT1, value_wdg);
    }

    BEGIN_MESSAGE_MAP(Cwatchdog_testDlg, CDialog)
    #if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
            ON_WM_SIZE()
    #endif
            //}}AFX_MSG_MAP
            ON_BN_CLICKED(IDC_start_wdg, &Cwatchdog_testDlg::OnBnClickedstartwdg)
            ON_WM_TIMER()
    END_MESSAGE_MAP()


    // Cwatchdog_testDlg 消息处理程序

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

            // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
            //  执行此操作
            SetIcon(m_hIcon, TRUE);                        // 设置大图标
            SetIcon(m_hIcon, FALSE);                // 设置小图标

            // TODO: 在此添加额外的初始化代码
            hwdg = CreateFile(TEXT("wdg1:"),GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
            if (hwdg == INVALID_HANDLE_VALUE)
            {
                    printf ("can't open wdg1\r\n");
            }
            else
            {
                    printf ("Open wdg1\r\n");
            }
            SetTimer(1,1000,NULL);
            hThread = CreateThread (NULL, 0, wdgThread, NULL, 0, NULL);

            return TRUE;  // 除非将焦点设置到控件,否则返回 TRUE
    }

    #if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
    void Cwatchdog_testDlg::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/)
    {
            if (AfxIsDRAEnabled())
            {
                    DRA::RelayoutDialog(
                            AfxGetResourceHandle(),
                            this->m_hWnd,
                            DRA::GetDisplayMode() != DRA:ortrait ?
                            MAKEINTRESOURCE(IDD_WATCHDOG_TEST_DIALOG_WIDE) :
                            MAKEINTRESOURCE(IDD_WATCHDOG_TEST_DIALOG));
            }
    }
    #endif

    DWORD WINAPI wdgThread (PVOID hdcMain)
    {

            Cwatchdog_testDlg *pdlg =(Cwatchdog_testDlg*)(AfxGetApp()->m_pMainWnd);

            while (1)
            {
                    str.Format(_T("%d"),convalue);

                    pdlg->SetDlgItemTextW(IDC_EDIT1,str);
            }

    return 0;

    }
    void Cwatchdog_testDlg::OnBnClickedstartwdg()
    {
            // TODO: Add your control notification handler code here
            if (flag_wdg)
            {
                    m_ctrl_start.SetWindowText( TEXT("FEED" ) );
                    //flag_wdg =0;
                    convalue =4;
                    DeviceIoControl(hwdg,IOCTL_wdg_wdg1_OPEN,NULL,
                            sizeof(DWORD),
                            NULL,
                            0,
                            0,
                            NULL);
            }
    }
    void Cwatchdog_testDlg::OnTimer(UINT nIDEvent)
    {
            convalue--;
    }


    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /3 下一条



    手机版|小黑屋|与非网

    GMT+8, 2024-5-16 15:18 , Processed in 0.119584 second(s), 15 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.