?? protect.c
字號:
/********************************************************************
** 電動機保護主任務
** FUNCTION:
** Protect_Task(unsigned int, void *)
**
********************************************************************/
#include "nucleus.h"
#include "Fix_Dsp.h"
#include "led.h"
#include "Keyboard_drv.h"
#include "MOTOType.h"
#include "UItype.h"
TJDTimingNode TestTn;
extern Protect_Process(void);
extern NU_HISR PROTECT_TASK;
extern NU_TASK GUI_TASK;
extern U16 prochip[4];
extern int readIndex;
extern int udelaytime;
extern int pdelaytime;
extern void SetLedBuff();
extern void sound();
extern int Voltage_Low_Overtime;
extern int uboottestflag;
extern int Reset_Signal;
extern int sound_flag;
extern int Alarm_flag;
extern int Break_flag;
extern int Start_Signal;
extern int Break_Signal;
extern int Start_Enable_Signal;
unsigned char testing = 1;
unsigned char Task_Suspended = 0;
int keyNum;
unsigned short ledBuff[4];
unsigned short lightBuff = 0xff;
//unsigned short test[10];
int ResetKeyTime = 0;
int StopKeyTime = 0;
void key(void)
{
static unsigned int keyBoardTime = 0;
keyBoardTime++;
if(keyBoardTime == 85)
{
//keyboard
keyNum = key_Finder();
if( keyNum == RESET)
{
ResetKeyTime++;
}
else
{
ResetKeyTime = 0;
}
if(keyNum == STOP)
{
StopKeyTime++;
}
else
{
StopKeyTime= 0;
}
keyBoardTime = 0;
}
}
void led(void)
{
static unsigned char i;
static unsigned int ledTime = 0;
ledTime++;
if(1)
{
sLedout(ledBuff[3-i], i);
i++;
if(i==4) i=0;
ledTime = 0;
}
}
int testLed_old(void)
{
static unsigned int time;
static unsigned int i = 0;
static unsigned int j = 0;
time++;
//sLedout(LedNum[i] + 0xff, j);
ledBuff[0] = LedNum[i] + lightBuff;
ledBuff[1] = LedNum[i] + lightBuff;
ledBuff[2] = LedNum[i] + lightBuff;
ledBuff[3] = LedNum[i] + lightBuff;
j++;
if(j == 4) j = 0;
if(time == 300)
{
time = 0;
i++;
if(i == 10)
{
i = 0;
testing = 0;
ledBuff[0] = LedNum[9] ;
ledBuff[1] = LedNum[5] ;
ledBuff[2] = LedNum[2] ;
ledBuff[3] = LedNum[7] ;
udelaytime = 1;
pdelaytime = updateTime;
sound_flag = 1;
/****************恢復開出量*******/
*(volatile unsigned long *)PORTG_DATA &= ~0x10;
*(volatile unsigned long *)PORTG_DATA &= ~0x4;
*(volatile unsigned long *)PORTG_DATA &= ~0x2;
*(volatile unsigned long *)PORTG_DATA &= ~0x1;
NU_Resume_Task(&GUI_TASK);
}
}
return 0;
}
int testLed(void)
{
static unsigned int time;
static unsigned int i = 0;
static unsigned int j = 0;
time++;
//sLedout(LedNum[i] + 0xff, j);
ledBuff[0] = LedNum[8] + lightBuff;
ledBuff[1] = LedNum[8] + lightBuff;
ledBuff[2] = LedNum[8] + lightBuff;
ledBuff[3] = LedNum[8] + lightBuff;
j++;
if(j == 4) j = 0;
if(time == 300)
{
time = 0;
i++;
if(i == 1)
{
i = 0;
testing = 0;
ledBuff[0] = LedNum[9] ;
ledBuff[1] = LedNum[5] ;
ledBuff[2] = LedNum[2] ;
ledBuff[3] = LedNum[7] ;
udelaytime = 1;
pdelaytime = updateTime;
sound_flag = 1;
/****************恢復開出量*******/
//*(volatile unsigned long *)PORTG_DATA &= ~0x10;
//*(volatile unsigned long *)PORTG_DATA &= ~0x4;
//*(volatile unsigned long *)PORTG_DATA &= ~0x2;
//*(volatile unsigned long *)PORTG_DATA &= ~0x1;
NU_Resume_Task(&GUI_TASK);
}
}
return 0;
}
int testKeyboard(void)
{
static unsigned char i;
static unsigned int Time = 0;
if(keyNum != -1)
{
ledBuff[0] = LedNum[keyNum] + lightBuff;
ledBuff[1] = LedNum[keyNum] + lightBuff;
ledBuff[2] = LedNum[keyNum] + lightBuff;
ledBuff[3] = LedNum[keyNum] + lightBuff;
if(keyNum != ENTER)
{
sound_flag = 1;
Time = 0;
}
else
{
if(Time > 100)
{
*(RP)(PWM2_C) = 0;
sound_flag = 0;
}
else
{
sound_flag = 1;
}
}
}
i++;
if(i==4) i=0;
if(keyNum == ENTER) Time++;
if(Time == 1000)
{
testing = 0;
ledBuff[0] = LedNum[9] ;
ledBuff[1] = LedNum[5] ;
ledBuff[2] = LedNum[2] ;
ledBuff[3] = LedNum[7] ;
udelaytime = 1;
pdelaytime = updateTime;
NU_Resume_Task(&GUI_TASK);
}
}
VOID Protect_Task(UNSIGNED argc, VOID *argv)
{
static int KeyTime = 0;
U32 temp;
int i = 0;
int testuboot = 0;
int stat;
if(0 == testing)
{
/*****************判斷啟動控制信號**************/
// 下面三行寫到Gui.c里
/*
if( Break_flag || (Start_Enable_Signal == -1) )
{
SystemSetting.StartSingal = 0;
}
*/
if(uboottestflag )
{
NorFlash_unlock( 0x200f0000 );
NorFlash_bolckerase( 0x200f0000 );
i=0;
uboottestflag = 0;
do
{
stat = NorFlash_write(0x200f0000 + i * 2, ((U32)&uboottestflag) + i * 2);
i++;
}while(stat && (i < 2));
}
if((SystemSetting.StartSingal == 1) &&(Start_Enable_Signal != -1))
{
if(KG_2_1 || KG_2_2)
{
if(Restart_Permit)
{
Start_Signal = 1;
Break_Signal = 0;
}
}
else
{
Start_Signal = 1;
Break_Signal = 0;
}
}
if(StopKeyTime == 3)
{
Break_Signal = 1;
Start_Signal = 0;
SystemSetting.StartSingal = 0;
}
/*--------------------------------------------------*/
Protect_Process();
DI_DO_Func();
//NU_Resume_Task(&GUI_TASK); //調試添加
SetLedBuff(); //led閃爍
/**************************************************************************
指示燈控制
運行sect7 電源sect4 本地 sect2 通訊 sect5 告警 sect3 預留sect6
*****************************************************************************/
ledBuff[0] |= sect4 ;
ledBuff[1] |= sect4 ;
ledBuff[2] |= sect4 ;
ledBuff[3] |= sect4 ;
if(udelaytime <= 100)
{
ledBuff[0] |= sect2;
ledBuff[1] |= sect2;
ledBuff[2] |= sect2;
ledBuff[3] |= sect2;
}
else
{
ledBuff[0] &= 0xfffa;
ledBuff[1] &= 0xfffa;
ledBuff[2] &= 0xfffa;
ledBuff[3] &= 0xfffa;
}
/*****************************************************************************/
if(Alarm_flag)
{
if(udelaytime <= 100)
{
ledBuff[0] |= sect3;
ledBuff[1] |= sect3;
ledBuff[2] |= sect3;
ledBuff[3] |= sect3;
}
else
{
ledBuff[0] &= 0xfff4;
ledBuff[1] &= 0xfff4;
ledBuff[2] &= 0xfff4;
ledBuff[3] &= 0xfff4;
}
Alarm_Sound();
}
else
{
ledBuff[0] &= 0xfff4;
ledBuff[1] &= 0xfff4;
ledBuff[2] &= 0xfff4;
ledBuff[3] &= 0xfff4;
}
if(Break_flag )
{
ledBuff[0] |= sect3;
ledBuff[1] |= sect3;
ledBuff[2] |= sect3;
ledBuff[3] |= sect3;
Break_Sound();
}
if(Starting)
{
if(udelaytime <= 100)
{
ledBuff[0] |= sect7;
ledBuff[1] |= sect7;
ledBuff[2] |= sect7;
ledBuff[3] |= sect7;
}
else
{
ledBuff[0] &= ~sect7;
ledBuff[1] &= ~sect7;
ledBuff[2] &= ~sect7;
ledBuff[3] &= ~sect7;
}
}
if(Running)
{
ledBuff[0] |= sect7;
ledBuff[1] |= sect7;
ledBuff[2] |= sect7;
ledBuff[3] |= sect7;
}
if(Stop)
{
ledBuff[0] &= ~sect7;
ledBuff[1] &= ~sect7;
ledBuff[2] &= ~sect7;
ledBuff[3] &= ~sect7;
}
if( (ResetKeyTime == 1) || Reset_Signal )
{
Alarm_flag = 0;
Break_flag = 0;
*(RP)(PWM2_C) = 0 ;
ResetKeyTime = 0;
Voltage_Low_Overtime = 0; //清晃電超時標志
}
/************測試添加****************/
/*
if(SystemSetting.ControlWay == 0)
{
TimingNodePulse(&TestTn, Break_flag);
if(TestTn.level)
{
Break_flag = 0;
*(RP)(PWM2_C) = 0 ;
Voltage_Low_Overtime = 0; //清晃電超時標志
}
}
*/
/*----------------------------------------------*/
}
key();
led();
if(sound_flag == 1)
{
sound();
}
/*****************************/
if(testing == 1)
{
testLed();
}
if(testing == 2) testKeyboard();
/*****************************************/
udelaytime = (udelaytime + 1) % 200;
pdelaytime = (pdelaytime + 1) % 500;
Task_Suspended = 1;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -