motorcontroldemo_028/Vinclude/SM_Protect.h

145 lines
4.5 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 SMProtect.h
\brief Ìîäóëü çàùèò. (ñì. TSM_Protect)
\author ÎÎÎ "ÍÏÔ Âåêòîð". http://motorcontrol.ru
\version v 2.0 25/03/2016
\defgroup SMProtect Ìîäóëü çàùèò. (ñì. TSM_Protect)
@{
*/
#ifndef SM_Protect_H
#define SM_Protect_H
#ifdef __cplusplus
extern "C"
{
#endif
#include "build.h"
//! Ìîäóëü àùèò âûêëþ÷åí
#define PROT_OFF 0
//! Ìîäóëü çàùèò âêëþ÷åí
#define PROT_ON_OK 1
//! Ìîäóëü çàùèò â ñîñòîÿíèè àâàðèè (ñðàáîòàëà çàùèòà)
#define PROT_FAIL 2
//Ìàêðîñû ïðèåìà (åñëè íîëü, òî àâàðèÿ) è ñáðîñà (åñëè 1, òî ñáðîñ) àïïàðàòíûõ àâàðèé
#if defined (HW_MCB3)
#define DRV_FAULT (GPIOB->DATA & (1 << 3)) //Ïðèåì îáùåé àâàðèè
#define DRV_FAULT1 (GPIOB->DATA & (1 << 4)) //Àâàðèÿ êëþ÷à A0
#define DRV_FAULT2 (GPIOB->DATA & (1 << 5)) //Àâàðèÿ êëþ÷à A1
#define DRV_FAULT3 (GPIOD->DATA & (1 << 4)) //Àâàðèÿ êëþ÷à A2
#define DRV_FAULT4 (GPIOD->DATA & (1 << 5)) //Àâàðèÿ êëþ÷à B0 èëè B1 èëè B2
//Äëÿ ñáðîñà àïïàðàòíîé àâàðèè â äàííîì êîíòðîëëåðå èñïîëüçóååòñÿ âíåøíèé äèñêðåòíûé ïîðò ââîäà
#define RESET_FAULT_BUTTON (dio.in_bit.n2) //Äèñêðåòíûé âõîä äëÿ êíîïêè ñáðîñà àâàðèè
#elif defined (HW_MCB3_SIMULATOR)
#define DRV_FAULT 0
#define DRV_FAULT1 0
#define DRV_FAULT2 0
#define DRV_FAULT3 0
#define DRV_FAULT4 0
#define RESET_FAULT_BUTTON 0
#endif
/*! \class TSM_Protect
\brief Ìîäóëü çàùèò.
Êëàññ \a TSM_Protect, îñíîâàííûé íà ñòðóêòóðå SSMProtect,
îáðàáàòûâàåò âñå âîçìîæíûå àâàðèéíûå ñèòóàöèè è âîçâîäèò ñîîòâåòñòâóþùèé ýòîé
àâàðèè áèò â îäíîì èç ñëîâ bit_fault 1-2. äàëåå ïðîèñõîäèò îáðàáîòêà ýòèõ ñëîâ, è,
åñëè ýòà àâàðèÿ íå çàìàñêèðîâàíà, ïðîèñõîäèò îñòàíîâ ïðèâîäà.
*/
//! ñì. TSM_Protect
struct SSM_Protect
{
Uint16 state;//!< Ñîñòîÿíèå
Uint16 state_prev;//!< Ñîñòîÿíèå ïðåäûäóùåå
Uint16 readDrvSts; //!<Ôëàã çàïðîñà ÷òåíèÿ ñòàòóñà drv8301
Uint16 clearDrvFault; //!<Ôëàã çàïðîñà ñáðîñà àâàðèè drv8301
Uint16 bit_fault1;//!<Ñëîâî àâàðèé 1
Uint16 bit_fault2;//!<Ñëîâî àâàðèé 2
Uint16 masked_bit_fault1;//!<Ñëîâî àâàðèé ïîñëå ìàñêèðîâàíèÿ
Uint16 masked_bit_fault2;//!<Ñëîâî àâàðèé ïîñëå ìàñêèðîâàíèÿ
Uint16 mask_fault1;//!<Ìàñêà àâàðèé 1
Uint16 mask_fault2;//!<Ìàñêà àâàðèé 2
Uint16 bit_fault_written1;
Uint16 bit_fault_written2;
long Imax_protect; //!<Óñòàâêà ìàêñèìàëüíî-òîêîâîé çàùèòû
long Umax_protect; //!<Óñòàâêà çàùèòû max íàïðÿæåíèÿ íà ÇÏÒ
long Umin_protect; //!<Óñòàâêà çàùèòû min íàïðÿæåíèÿ íà ÇÏÒ
long speed_max; //!<Óñòàâêà ìàêñèìàëüíîé ñêîðîñòè
long T_max; //!<Óñòàâêà ìàêñèìàëüíîé òåìïåðàòóðû
int E;//!<Ôëàã ïåðâîãî âõîæäåíèÿ
Uint16 Main_ErrorCode;//!< //ëèñòàþùèéñÿ êîä àâàðèè
Uint32 Main_Flags;//!< //Ôëàã àâàðèéíîé áëîêèðîâêè áëîêà
Uint16 powered_okCounter;//!< Ñ÷åò÷èê äëÿ îæèäàíèÿ âêëþ÷åíÿ ìîäóëÿ çàùèò ïîñëå èíåöèàëèçàöèè
void (*init)(struct SSM_Protect*); /* Pointer to the init funcion */
void (*slow_calc)(struct SSM_Protect*); /* Pointer to the calc funtion */
void (*fast_calc)(struct SSM_Protect*); /* Pointer to the calc funtion */
void (*ms_calc)(struct SSM_Protect*); /* Pointer to the calc funtion */
} ;
typedef struct SSM_Protect TSM_Protect;
//!Èíèöèàëèçàòîð ïî óìîë÷àíèþ
#define SM_PROTECT_DEFAULTS {0,0,\
0,0,\
0,0,\
0,0,\
0,0,\
0,0,\
0,0,0,0,0,\
0,0,0,0,\
SM_Protect_Init,\
SM_Protect_Slow_Calc,\
SM_Protect_Fast_Calc,\
SM_Protect_ms_Calc,\
}
//! \memberof TSM_Protect
void SM_Protect_Init(TSM_Protect*);
//! \memberof TSM_Protect
void SM_Protect_Slow_Calc(TSM_Protect*);
//! \memberof TSM_Protect
void SM_Protect_Fast_Calc(TSM_Protect*);
//! \memberof TSM_Protect
void SM_Protect_ms_Calc(TSM_Protect*);
#ifdef __cplusplus
}
#endif
#endif
/*@}*/