www.pudn.com > IEC104_codeamaterial.rar > sys.h, change:2011-02-19,size:3090b


/*------------------------------------------------------------------------ 
 Module:		sys.h 
 Author:		solar 
 Project:		 
 Creation Date: 2009-10-22 
 Description:	 
------------------------------------------------------------------------*/ 
/*------------------------------------------------------------------------ 
 $Log: $ 
------------------------------------------------------------------------*/ 
 
#ifndef _SYS_H 
#define _SYS_H 
 
#include "syscfg.h" 
#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 
#include "bsp.h" 
#include "os.h" 
#include "comm.h" 
#include "db.h" 
#include "para.h" 
//#include "extio.h" 
//#include "myio.h" 
#include "cmd.h" 
 
/* MAX_TASK_NUM  define in os.h*/ 
 
#define BUS_CAN_ID    0    /*总线任务在最前面 for gSoeRp 效率*/ 
#define BUS_485_ID    1     
#define SHELL_ID      2 
#define SELF_DIO_ID   3 
#define COMM_ID       4 
#define WATCHDOG_ID   5 
 
#define SYS_ERR_SYS         0x00000001   /*系统错误,如资源短缺,任务异常退出等*/ 
#define SYS_ERR_ADDR        0x00000002   /*地址有冲突*/ 
#define SYS_ERR_CFG         0x00000004   /*参数错误*/ 
#define SYS_ERR_OBJ         0x00000008   /*动态库错误*/ 
#define SYS_ERR_COMM        0x00000010   /*通信错误*/ 
#define SYS_ERR_GAIN        0x00000020   /*交采整定文件错误*/ 
#define SYS_ERR_LOGIN       0x00000040   /*板卡型号与上级参数不一致,登录失败*/ 
 
#define RUNF_NOLOGIN         0x00000001 
#define RUNF_DIF             0x00000002 
#define RUNF_YXF             0x00000004 
#define RUNF_DICOSF          0x00000008 
#define RUNF_YXCOSF          0x00000010 
#define RUNF_DISOEF          0x00000020 
#define RUNF_YXSOEF          0x00000040 
 
#define RUNF_CFGSYNC_MASK    0xFF000000 
#define RUNF_CFGSYNC_DI      0x01000000 
 
struct VSysInfo{ 
	struct VPExtIoAddr AddrInfo; 
 
	DWORD dwErrCode; 
	DWORD dwRunFlag; 
};	 
 
extern struct VSysInfo g_Sys; 
 
__inline__  void SysSetErr(DWORD errcode) 
{ 
	g_Sys.dwErrCode |= errcode; 
	faultLight_turn(g_Sys.dwErrCode); 
} 
 
__inline__  void SysClearErr(DWORD errcode) 
{ 
	g_Sys.dwErrCode &= (~errcode); 
	faultLight_turn(g_Sys.dwErrCode); 
} 
 
__inline__ int CheckAddr(void) 
{ 
    int addr; 
	DWORD cnt; 
 
	//读出一个稳定的地址,说明插件已插好 
	addr = readAddr(); 
	cnt = GetMsCnt(); 
	for (;;) 
	{ 
        if (GetMsCnt()-cnt > 1000) 
        { 
			if (addr == readAddr()) 
				break; 
			addr = readAddr(); 
			cnt = GetMsCnt(); 
        }			 
	} 
		 
	g_Sys.AddrInfo.dwType = GetAppDioType(EXT_TYPE_DIO_INPUT); 
 
	g_Sys.AddrInfo.wAddr = readAddr(); 
	if ((g_Sys.AddrInfo.wAddr == 0x1F) || (g_Sys.AddrInfo.wAddr == 0x0) || (g_Sys.AddrInfo.wAddr == 0x1)) 
	{ 
		SysSetErr(SYS_ERR_ADDR); 
		return ERROR; 
	} 
	else 
		return OK; 
} 
 
__inline__ void SetRunFlag(DWORD runflag) 
{ 
    g_Sys.dwRunFlag |= runflag; 
} 
 
__inline__ void ClearRunFlag(DWORD runflag) 
{ 
    g_Sys.dwRunFlag &= (~runflag); 
} 
 
__inline__ BOOL TestRunFlag(DWORD runflag) 
{ 
    if (g_Sys.dwRunFlag & runflag) return(TRUE); 
	else return(FALSE); 
} 
 
void WriteWarnEvent(struct VCalClock *ptm, WORD errcode, const char *fmt, ... ); 
 
#endif