#ifndef __FUNSTATE_H
#define __FUNSTATE_H

#include <stdint.h>
#include "f28x_project.h"

#define PRECHARFETIMEOUT 50000//10s 5MS 计数周期运行一次，时间就是1000

//母线输入时间判断
#define VBUSDELAY  1000   //   5MS 计数周期运行一次
#define VBUSTIME   1000    //时间就是1000
#define VBUSJUG    900     //时间就是1000



enum
{
	init=0,       //1、系统初始化 2、下发关机或者故障之后，就是进入初始化
	PreFun,   //接收到了开机指令
	PreFunRelay,   //充电状态
	PreFunGPIO,   //充电状态
	softer,   // 预充
	charge_softer,   // 预充
	charge_on,   // 预充
};
//系统控制指令
//0-不使能 	1-使能
struct	SystemCommand
{
    Uint32  shutdown:1;                 // 0  关机
	Uint32	standby:1;				// 1  正向充电DCDC使能
	Uint32	CharDcdcOn:1;				// 2  正向PFC整流
	Uint32	ReCharDcdcOn:1;				// 3  反向放电DCDC使能
	Uint32	fault:1;				// 4  反向放电逆变使能
	Uint32	updata:1;				    // 5 充电使能
	Uint32	openTest:1;				// 6  测试发波

	Uint32	rsvd:25;					    // 7~31 预留
};

union SYSTEM_COMMAND {
    Uint32              	all;
    struct SystemCommand	bit;
};

//运行状态指令
struct	LLCRUNSTABITS
{
	Uint32	init:1;				        // 0 初始化状态，故障态
	Uint32	PreFun:1;				    // 1 预处理
	Uint32	PreFunRelay:1;			    // 2 预处理继电器相关
	Uint32	PreFunGPIO:1;
	Uint32	softer:1;				    // 4 唤起
	Uint32	charge_softer:1;
	Uint32	charge_on:1;				// 6 正常充电
	Uint32	rsvd:25;					    // 7~31 预留
};

union LLCRUNSTA
{
    Uint32              	all;
    struct LLCRUNSTABITS	bit;
};



struct	LLCRUNTIM
{
	Uint16 PreFunTime;
	Uint16 PreFunTime_Jud;
	Uint16 PreFunTime_del;

	Uint16 PreRelTim;
	Uint16 PreRelTim_Jud;
	Uint16 PreRelTim_del;	

	Uint16 PreGpio_del;
	Uint16 uFreSofter_tim;
};

struct	RUNSTATUS
{
	union LLCRUNSTA LLCRunSta;				

	struct	LLCRUNTIM LLCRunTim;
	
	Uint16 uFaultFlag;
	Uint16 uStart_Time;
	Uint16 RunStaFlag;

	Uint16 uOpenTestTim;
};

extern	union 	SYSTEM_COMMAND	SysCmd;
extern struct	RUNSTATUS	RunState;

void Fun_Status_RUN(void);
void Fun_Status_init(void);


#endif

/*********************************************END OF FILE**********************/
