wdt_test case

这是一个watch dog test case的代码,可以用来测试watchdog的功能:

#include <stdio.h>   
#include <stdlib.h>
#include <string.h>   
#include <sys/types.h>   
#include <sys/stat.h>   
#include <unistd.h>   
#include <fcntl.h>   
#include <sys/ioctl.h>   
#include <errno.h>   
#include <sys/time.h>   
#include <unistd.h>   
#include <time.h>   
#include <getopt.h>   
#include <sys/signal.h>   
#include "watchdog.h"   
#define  OPTION_REBOOT		0
#define  OPTION_BASIC		1

#define  REBOOT		"reboot"

int zsleep(int millisecond)   
{   
	unsigned long usec;   
	usec=1000*millisecond;   
	usleep(usec);   
}
/*      
void keep_alive(void)
{
    int dummy;

    ioctl(fd, WDIOC_KEEPALIVE, &dummy);
}

void wdt_getstatus(int *arg)
{
    ioctl(fd, WDIOC_KEEPALIVE, *arg);
}

void keep_getbootstatus(int *arg)
{
    ioctl(fd, WDIOC_KEEPALIVE, *arg);
}
*/
int Init()   
{
	int fd;
	//open device file
	fd = open("/dev/watchdog",O_RDWR);
	if(fd < 0)
	{
	    printf("device open fail\n");
	    return -1;
	}
	else
	    printf("enable watchdog\n");

	return fd;
}

int main(int argc,char **argv)   
{
        int fd,ch;
        int i,j,k=1,option,timeout;
	char *arg;
        struct watchdog_info wi;
        fd=Init();
	if(argv[1]!=NULL){
		if(strcmp(argv[1],REBOOT)==0){
			printf("reboot mode\n");
			arg = argv[2];
			i = strtoul(arg,&arg,10);
			option = OPTION_REBOOT;
		}
		else{
			printf("invalid option arguments,only do the basic action\n");
			option = OPTION_BASIC;
		}	
	}
	else{
		printf("only basic action\n");
		option = OPTION_BASIC;
	}
	if(option == OPTION_BASIC){
        	//read watchdog information
        	ioctl(fd,WDIOC_GETSUPPORT,&wi); 
        	printf("%d,%s\n",wi.options,wi.identity);

        	//set watchdog timeout   
        	//set the timeout is 10s,if success return 0,else return -1   
        	i=5;
		j=ioctl(fd,WDIOC_SETTIMEOUT,&i);
		if(j==0)
            		printf("Set watchdog timeout success!\nSet watchdog timeout: %ds\n",i*2);
		else
	    		printf("Set watchdog timeout failed!\n");

        	//read watchdog timeout
		j=ioctl(fd,WDIOC_GETTIMEOUT,&i);
		if(j==0)
            		printf("Read watchdog timeout success!\nRead watchdog timeout: %ds\n",i*2);
		else
	    		printf("Read watchdog timeout failed!\n");

        	//disable watchdog
        	close(fd);
		printf("disable watchdog\n");
	}
	else{
 		//read watchdog information
                ioctl(fd,WDIOC_GETSUPPORT,&wi);
                printf("%d,%s\n",wi.options,wi.identity);

                //set watchdog timeout   
                //set the timeout is 10s,if success return 0,else return -1   
                timeout = i/2;
                j=ioctl(fd,WDIOC_SETTIMEOUT,&timeout);
                if(j==0)
                        printf("Set watchdog timeout success!\nSet watchdog timeout: %ds\n",timeout*2);
                else
                        printf("Set watchdog timeout failed!\n");

                //read watchdog timeout
                j=ioctl(fd,WDIOC_GETTIMEOUT,&timeout);
                if(j==0)
                        printf("Read watchdog timeout success!\nRead watchdog timeout: %ds\n",timeout*2);
                else
                        printf("Read watchdog timeout failed!\n");

                timeout = timeout*2;
                while(1){
                        printf("I 'll do the reboot after %d seconds\n",timeout--);
			sleep(1);
                }
                //disable watchdog
                close(fd);
                printf("disable watchdog\n");
	}
        return 0;
}

watchdog.h 代码如下

/*
 *	Generic watchdog defines. Derived from..
 *
 * Berkshire PC Watchdog Defines
 * by Ken Hollis <khollis@bitgate.com>
 *
 */

#ifndef _LINUX_WATCHDOG_H
#define _LINUX_WATCHDOG_H

#include <linux/ioctl.h>

#define	WATCHDOG_IOCTL_BASE	'W'

struct watchdog_info {
	unsigned int options;		/* Options the card/driver supports */
	unsigned int firmware_version;	/* Firmware version of the card */
	unsigned char identity[32];	/* Identity of the board */
};

#define	WDIOC_GETSUPPORT	_IOR(WATCHDOG_IOCTL_BASE, 0, struct watchdog_info)
#define	WDIOC_GETSTATUS		_IOR(WATCHDOG_IOCTL_BASE, 1, int)
#define	WDIOC_GETBOOTSTATUS	_IOR(WATCHDOG_IOCTL_BASE, 2, int)
#define	WDIOC_GETTEMP		_IOR(WATCHDOG_IOCTL_BASE, 3, int)
#define	WDIOC_SETOPTIONS	_IOR(WATCHDOG_IOCTL_BASE, 4, int)
#define	WDIOC_KEEPALIVE		_IOR(WATCHDOG_IOCTL_BASE, 5, int)
#define	WDIOC_SETTIMEOUT        _IOWR(WATCHDOG_IOCTL_BASE, 6, int)
#define	WDIOC_GETTIMEOUT        _IOR(WATCHDOG_IOCTL_BASE, 7, int)

#define	WDIOF_UNKNOWN		-1	/* Unknown flag error */
#define	WDIOS_UNKNOWN		-1	/* Unknown status error */

#define	WDIOF_OVERHEAT		0x0001	/* Reset due to CPU overheat */
#define	WDIOF_FANFAULT		0x0002	/* Fan failed */
#define	WDIOF_EXTERN1		0x0004	/* External relay 1 */
#define	WDIOF_EXTERN2		0x0008	/* External relay 2 */
#define	WDIOF_POWERUNDER	0x0010	/* Power bad/power fault */
#define	WDIOF_CARDRESET		0x0020	/* Card previously reset the CPU */
#define WDIOF_POWEROVER		0x0040	/* Power over voltage */
#define WDIOF_SETTIMEOUT	0x0080	/* Set timeout (in seconds) */
#define WDIOF_MAGICCLOSE	0x0100	/* Supports magic close char */
#define	WDIOF_KEEPALIVEPING	0x8000	/* Keep alive ping reply */

#define	WDIOS_DISABLECARD	0x0001	/* Turn off the watchdog timer */
#define	WDIOS_ENABLECARD	0x0002	/* Turn on the watchdog timer */
#define	WDIOS_TEMPPANIC		0x0004	/* Kernel panic on temperature trip */

#endif  /* ifndef _LINUX_WATCHDOG_H */




资源下载链接为: https://pan.quark.cn/s/0c983733fad2 本文主要回顾了2021年之前及2021年中国科学技术大学软件学院(简称“中科大软院”)高级软件工程(MN)专业的考试情况,重点聚焦于编程题。编程题在考试中的占比不断提高,因此考生需要深入理解这些题目及其解题方法。 中科大软院的高级软件工程专业致力于培养具备深厚理论基础和强大实践能力的高级软件人才。课程设计注重理论与实践相结合,以满足软件行业对高素质工程师的需求。考试内容通常涵盖计算机基础知识、软件工程理论、编程语言、数据结构与算法、操作系统、数据库系统等多个领域。2021年的考试中,编程题的比重进一步提升,这体现了学院对学生实际编程能力和问题解决能力的重视。 编程题通常涉及常见的编程问题,例如字符串处理、数组操作、递归算法、图论问题等,也可能包括网络编程、数据库查询或系统设计等特定领域的应用。考生需要熟练掌握至少一种编程语言,如C++、Java、Python等,并具备较强的算法分析和实现能力。在解题过程中,考生需要注意以下几点:一是准确理解题目要求,避免因误解而导致错误;二是合理选择并设计算法,考虑时间复杂度和空间复杂度,追求高效性;三是遵循良好的编程规范,注重代码的可读性和可维护性;四是考虑边界条件和异常情况,编写健壮的代码;五是编写测试用例,对代码进行充分测试,及时发现并修复问题。 对于备考的同学,建议多做历年试题,尤其是编程题,以熟悉题型和解题思路。同时,可以参加编程竞赛或在在线编程平台(如LeetCode、HackerRank)进行实战训练,提升编程和问题解决能力。此外,关注PPT中的编程代码也很关键,因为这些代码可能是老师给出的示例或解题思路,能够帮助学生更好地理解和掌握编程题的解法。因此,考生需要深入学习PPT内容,理解代码逻辑,并学会将其应用到实际编程题目中。 总之,对于
WDT_RTC_test 是一种测试芯片中WDT(Watchdog Timer)和RTC(Real-Time Clock)的测试项目,主要用于验证芯片中的WDT和RTC是否能够正常工作,并能够保证芯片在正常工作时的稳定性和可靠性。 WDT是一种硬件计时器,用于监控芯片的运行状态,并在出现故障时进行复位。RTC是一种硬件时钟,用于提供芯片的实时时钟信号。在芯片测试中,WDT和RTC是非常重要的测试项目,它们可以确保芯片在出现故障时能够及时进行自我恢复,同时还能保证芯片的实时时钟信号的准确性和稳定性。 WDT_RTC_test 测试方法主要包括以下步骤: 1. 准备测试环境:测试人员需要准备适当的测试工具和设备,以测试芯片中的WDT和RTC。测试人员需要通过测试工具和设备,对芯片中的WDT和RTC进行测试。 2. 测试WDT:测试人员需要测试芯片中的WDT是否能够正常工作,并能够在出现故障时进行复位。测试人员需要测试WDT在不同的工作模式下的性能和稳定性,并对测试结果进行分析和记录。 3. 测试RTC:测试人员需要测试芯片中的RTC是否能够正常工作,并能够提供准确的实时时钟信号。测试人员需要测试RTC在不同的工作模式下的性能和稳定性,并对测试结果进行分析和记录。 4. 输出测试结果:测试人员会根据测试结果,判断芯片中的WDT和RTC是否正常工作,并输出相应的测试报告。测试报告应该包括测试过程中所使用的测试工具和设备,以及测试结果和结论。 通过 WDT_RTC_test 测试,可以验证芯片中的WDT和RTC是否能够正常工作,并能够保证芯片在正常工作时的稳定性和可靠性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值