110 lines
2.8 KiB
C
110 lines
2.8 KiB
C
/*!
|
|
Copyright 2017 ÀÎ "ÍÈÈÝÒ" è ÎÎÎ "ÍÏÔ ÂÅÊÒÎÐ"
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
|
|
\file SMCmdLogic.c
|
|
\brief Îáðàáîòêà êîìàíä è çàäàíèé, ïîñòóïàþùèõ èç ðàçëè÷íûõ èñòî÷íèêîâ. (ñì. TSM_CmdLogic)
|
|
\author ÎÎÎ "ÍÏÔ Âåêòîð". http://motorcontrol.ru
|
|
\version v 2.0 25/03/2016
|
|
|
|
\addtogroup SMCmdLogic
|
|
@{*/
|
|
|
|
#include "DSP.h"
|
|
#include "V_IQmath.h"
|
|
#include "main.h"
|
|
|
|
//!Èíèöèàëèçàöèÿ
|
|
|
|
//!Âñÿêèå îáíóëåíèÿ...
|
|
//! \memberof TSM_CmdLogic
|
|
void SM_CmdLogicInit(TSM_CmdLogic *p) {
|
|
p->state = 0;
|
|
p->state_prev = 0xFF;
|
|
cmd.all = 0;
|
|
|
|
}
|
|
|
|
//!Ìåäëåííûé ðàñ÷åò
|
|
|
|
//! \memberof TSM_CmdLogic
|
|
void SM_CmdLogicSlow_Calc(TSM_CmdLogic *p) {
|
|
|
|
}
|
|
|
|
//!1êÃö ðàñ÷åò
|
|
|
|
//!Îáðàáîòêà ðàçëè÷íûõ èñòî÷íèêîâ êîìàíä è ðàñ÷åò ÄÀ,
|
|
//!êîòîðûé ïåðåêëþ÷àåò ãëîáàëüíî ðåæèìû ÐÀÁÎÒÀ è ÎÑÒÀÍÎÂ.
|
|
//! \memberof TSM_CmdLogic
|
|
void SM_CmdLogicms_Calc(TSM_CmdLogic *p) {
|
|
|
|
//Ñòàíäàðòíàÿ îáðàáîòêà äèñêðåòíîãî àâòîìàòà
|
|
if (p->state_prev != p->state)
|
|
p->E = 1;
|
|
else
|
|
p->E = 0;
|
|
p->state_prev = p->state;
|
|
|
|
|
|
//îïðåäåëÿåì ðåæèì ðàáîòû
|
|
switch (p->state) {
|
|
case CMD_LOGIC_TURNED_OFF: { //ñîñòîÿíèå 0- ÎÒÊËÞ×ÅÍ
|
|
if (p->E == 1) {
|
|
/*ENTRY*/
|
|
sm_ctrl.state = CTRL_STOP;
|
|
drv_status.bit.ready = 1;
|
|
drv_status.bit.running = 0;
|
|
}
|
|
|
|
if (sm_prot.state == PROT_ON_OK) {//åñëè ÄÀ çàùèò âêëþ÷èëñÿ, îáðàáàòûâàåì êîìàíäû âêëþ÷åíèÿ
|
|
if ((cmd.bit.start == 1) && (sm_sys.state == SYS_READY))//åñòü áèòîâàÿ êîìàíäà ñòàðòà
|
|
p->state = CMD_LOGIC_TURNED_ON; //ïîåõàëè
|
|
}
|
|
|
|
//äèñêðåòíûé àâòîìàò ñî ñòðóêòóðàìè óïðàâëåíèÿ â ÑÒÎÏå âñåãäà òîæå ïðèíóäèòåëüíî ïåðåâîäèì â ñòîï
|
|
sm_ctrl.state = CTRL_STOP;
|
|
//âñåãäà ñáðàñûâàåì áèòîâûå êîìàíäû óïðàâëåíèÿ
|
|
cmd.bit.stop = 0;
|
|
cmd.bit.start = 0;
|
|
break;
|
|
}
|
|
|
|
case CMD_LOGIC_TURNED_ON: { //ñîñòîÿíèå - ÐÀÁÎÒÀ
|
|
if (p->E == 1) {
|
|
/*ENTRY*/
|
|
drv_status.bit.ready = 1;
|
|
drv_status.bit.running = 1;
|
|
sm_ctrl.state = CTRL_RUN;//ïîåõàëè
|
|
}
|
|
//åñëè ÀÂÀÐÈÿ èëè ÊÎÌÀÍÄÀ ÑÒÎÏ òî ñîñòîÿíèå ñòîï
|
|
if ((sm_prot.state == PROT_FAIL) || (cmd.bit.stop == 1)
|
|
|| (sm_ctrl.state == CTRL_STOP)){
|
|
p->state = CMD_LOGIC_TURNED_OFF;
|
|
}
|
|
|
|
//âñåãäà ñáðàñûâàåì êîìàíäó óïðàâëåíèÿ
|
|
cmd.bit.stop = 0;
|
|
cmd.bit.start = 0;
|
|
break;
|
|
}
|
|
|
|
default:
|
|
break;
|
|
|
|
} // êîíåö switch(p->state)
|
|
}
|
|
|
|
/*@}*/
|