226 lines
9.1 KiB
C
226 lines
9.1 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 SMNet.c
|
|
\brief Ìîäóëü îáùåãî íàçíà÷åíèÿ äëÿ ðàáîòû ñ ñåòüþ. (ñì. TSM_Net)
|
|
\author ÎÎÎ "ÍÏÔ Âåêòîð". http://motorcontrol.ru
|
|
\version v 2.0 25/03/2016
|
|
|
|
*/
|
|
|
|
/** \addtogroup SMNet */
|
|
/*@{*/
|
|
|
|
#include "DSP.h"
|
|
#include "V_IQmath.h"
|
|
#include "main.h"
|
|
|
|
//!Èíèöèàëèçàöèÿ.
|
|
|
|
//!Ïðèñâîåíèå ìàñøòàáèðóþùèõ êîýôôèöèåíòîâ, èíèöèàëèçàöèÿ äðóãèõ ìîäóëåé.
|
|
//! \memberof TSM_Net
|
|
void SM_Net_Init(TSM_Net *p) {
|
|
|
|
p->state = 0;
|
|
p->state_prev = 0xff;
|
|
|
|
//Íàñòðîéêà äðàéâåðà CANOpen
|
|
UserMem.init(&UserMem);
|
|
|
|
co1_vars.settings.LoadParamsFromUserMemory_ena = 1;//Ðàçðåøèòü çàãðóæàòü çíà÷åíèÿ ïàðàìåòðîâ èç ÝÍÎÇÓ
|
|
co1_vars.CAN_REGS = (CAN_TypeDef *)CAN_BASE;//Ïåðåäàåì äðàéâåðó àäðåñ ñòðóêòóðû ðåãèñòðîâ CAN
|
|
co1_vars.settings.CAN_ISR_priority = IRQ_PRIORITY_CAN;//Ïðèñâîåíèå ïðèîðèòåòà ïåðûâàíèÿ CAN (îáðàáîò÷èê âíóòðè áèáëèîòåêè)
|
|
co1_vars.settings.CAN_IRQn = CAN1_IRQn;//Ïåðåäàåì íîìåð ïðåðûâàíèÿ CAN1 èç òàáëèöû ïðåðûâàíèé â äðàéâåð CANOpen
|
|
co1_vars.settings.MultiPDO_ena = 0;//Îòêëþ÷åíèå îáðàáîòêè PDO áåç ó÷åòà íîìåðà óçëà (ñïåö. ôóíêöèÿ)
|
|
co1_vars.settings.RX_PDO_Callback_ena = 0; //Íå âûçûâàòü ôóíêöèè îáðàòíîãî âûçîâà ïðè ïðèåìå PDO
|
|
co1_vars.settings.AutoBusON_ena = 1; //Àâòîìàòè÷åñêè ïåðåçàïóñêàòü CAN ïðè îøèáêàõ íà ëèíèè
|
|
co1_vars.settings.BlockTransfer_ena = 1;//Ðàçðåøèòü áëî÷íóþ ïåðåäà÷ó (íóæíà äëÿ îñöèëëîãðàôà)
|
|
co1_vars.settings.speedCANTablePointer = &canSpeedTable;//Ïåðåäàåì äðàéâåðó ïàðàìåòðû äëÿ íàñòðîéêè ñêîðîñòè CAN
|
|
co1_vars.settings.resetCPU = Watchdog.resetCPU;//Ïåðåäàåì äðàéâåðó àäðåñ ôóíêöèè ðåñåòà ìèêðîêîíòðîëëåðà
|
|
co1_Init(&co1_vars); //Èíèöèàëèçàöèÿ äðàéâåðà CANOpen
|
|
|
|
co2_vars.settings.LoadParamsFromUserMemory_ena = 1;//Ðàçðåøèòü çàãðóæàòü çíà÷åíèÿ ïàðàìåòðîâ èç ÝÍÎÇÓ
|
|
co2_vars.CAN_REGS = (CAN_TypeDef *)CAN_BASE;//Ïåðåäàåì äðàéâåðó àäðåñ ñòðóêòóðû ðåãèñòðîâ CAN
|
|
co2_vars.settings.CAN_ISR_priority = IRQ_PRIORITY_CAN;//Ïðèñâîåíèå ïðèîðèòåòà ïåðûâàíèÿ CAN (îáðàáîò÷èê âíóòðè áèáëèîòåêè)
|
|
co2_vars.settings.CAN_IRQn = CAN2_IRQn;//Ïåðåäàåì íîìåð ïðåðûâàíèÿ CAN2 èç òàáëèöû ïðåðûâàíèé â äðàéâåð CANOpen
|
|
co2_vars.settings.MultiPDO_ena = 0;//Îòêëþ÷åíèå îáðàáîòêè PDO áåç ó÷åòà íîìåðà óçëà (ñïåö. ôóíêöèÿ)
|
|
co2_vars.settings.RX_PDO_Callback_ena = 0; //Íå âûçûâàòü ôóíêöèè îáðàòíîãî âûçîâà ïðè ïðèåìå PDO
|
|
co2_vars.settings.AutoBusON_ena = 1; //Àâòîìàòè÷åñêè ïåðåçàïóñêàòü CAN ïðè îøèáêàõ íà ëèíèè
|
|
co2_vars.settings.BlockTransfer_ena = 1;//Ðàçðåøèòü áëî÷íóþ ïåðåäà÷ó (íóæíà äëÿ îñöèëëîãðàôà)
|
|
co2_vars.settings.speedCANTablePointer = &canSpeedTable;//Ïåðåäàåì äðàéâåðó ïàðàìåòðû äëÿ íàñòðîéêè ñêîðîñòè CAN
|
|
co2_vars.settings.resetCPU = Watchdog.resetCPU;//Ïåðåäàåì äðàéâåðó àäðåñ ôóíêöèè ðåñåòà ìèêðîêîíòðîëëåðà
|
|
co2_Init(&co2_vars); //Èíèöèàëèçàöèÿ äðàéâåðà CANOpen
|
|
|
|
//ëîããåð ñîáûòèé:
|
|
// ðàçìåð áóôåðà: 50
|
|
// ñòàðòîâûé àäðåñ â SPI: 3000
|
|
FaultLog.init((TLogger*)&FaultLog, 50, 3000,(Uint32*) &RTCclock.packed_time);//íèæå óêàçàòåëü íà âðåìÿ ìîæåò áûòü ïåðåîïðåäåëåí â çàâèñèìîñòè îò ðàáîòû ÷àñîâ
|
|
|
|
|
|
|
|
#if (defined(CANTORS_ENA)) || (defined(CANTOUSB_ENA))
|
|
//Ðàáîòà ñ CANopen ÷åðåç UART (ïàðàëëåëüíî ñ CAN, íåò êîíôëèêòà)
|
|
CANtoRS.nodeID = (Uint16*)&co1_vars.co_nodeID; //Íîìåð óçëà èç CANopen
|
|
CANtoRS.callback = Z_co_receiveSDOrequest;//Óêàçàòåëü íà ôóíêöèþ îáðàòíîãî âûçîâà èç äðàéâåðà CANopen ïî ïðèõîäó SDO ñîîáùåíèÿ
|
|
CANtoRS.init(&CANtoRS);
|
|
#endif
|
|
#ifdef MODBUS_ENA
|
|
// Íàñòðàèâàåì MODBUS
|
|
ModBus.ExecutionFreq = 10000;//×àñòîòà âûçîâà ðàñ÷åòà ìîäóëÿ ìîäáàñ â êÃö
|
|
ModBus.Init(&ModBus);
|
|
MBVarsConv.init(&MBVarsConv);
|
|
#endif
|
|
}
|
|
|
|
//!Ìåäëåííûé ðàñ÷åò.
|
|
|
|
//! Ïðèñâîåíèå ìàñøòàáèðóþùèõ êîýôôèöèåíòîâ, ôîíîâûé ðàñ÷åò íåêîòîðûõ ìîäóëåé.
|
|
|
|
//! \memberof TSM_Net
|
|
void SM_Net_Slow_Calc(TSM_Net *p) {
|
|
|
|
co1_vars.co_scaleNum0 = 1; //áåç ìàñøòàáèðîâàíèÿ
|
|
co1_vars.co_scaleNum1 = 100; // %
|
|
co1_vars.co_scaleNum2 = drv_params.freq_nom; //Ãö
|
|
co1_vars.co_scaleNum3 = drv_params.U_nom;//íàïðÿæåíèå ôàçíîå íîìèíàëüíîå àìïëèòóäíîå
|
|
co1_vars.co_scaleNum4 = drv_params.I_nom; //Òîê ôàçíûé áàçîâûé
|
|
co1_vars.co_scaleNum5 = 1;
|
|
co1_vars.co_scaleNum6 = 1;
|
|
co1_vars.co_scaleNum7 = drv_params.Udc_nom; //íàïðÿæåíèå ÇÏÒ áàçîâîå
|
|
co1_vars.co_scaleNum8 = drv_params.power; //18 â ôîðìàòå 9.6 //Ìîùíîñòü
|
|
co1_vars.co_scaleNum9 = 1;
|
|
co1_vars.co_scaleNumA = 20; //òåìïåðàòóðà
|
|
co1_vars.co_scaleNumB = 1;
|
|
co1_vars.co_scaleNumC = 1;
|
|
co1_vars.co_scaleNumD = 1;
|
|
co1_vars.co_scaleNumE = 1;
|
|
co1_vars.co_scaleNumF = 1;
|
|
co1_vars.co_scaleNum10 = 1; //
|
|
co1_vars.co_scaleNum11 = 1; //
|
|
co1_vars.co_scaleNum12 = drv_params.power; //18 â ôîðìàòå 10.6 //Ìîùíîñòü
|
|
co1_vars.co_scaleNum13 = 360; //
|
|
co1_vars.co_scaleNum14 = drv_params.speed_nom; //íîìèíàëüíàÿ ÷àñòîòà âðàùåíèÿ
|
|
co1_vars.co_scaleNum15 = 1; //
|
|
co1_vars.co_scaleNum16 = 1; //
|
|
co1_vars.co_scaleNum17 = ((((long) drv_params.Udc_nom) << 6)
|
|
/ (long) drv_params.I_nom); //Ráàç 10.6
|
|
co1_vars.co_scaleNum18 = 1000;
|
|
co1_vars.co_scaleNum19 = 1;
|
|
co1_vars.co_scaleNum1A = 1;
|
|
co1_vars.co_scaleNum1B = 1;
|
|
co1_vars.co_scaleNum1C = 1;
|
|
co1_vars.co_scaleNum1D = 1;
|
|
co1_vars.co_scaleNum1E = 1;
|
|
co1_vars.co_scaleNum1F = 1;
|
|
|
|
co2_vars.co_scaleNum0 = 1; //áåç ìàñøòàáèðîâàíèÿ
|
|
co2_vars.co_scaleNum1 = 100; // %
|
|
co2_vars.co_scaleNum2 = drv_params.freq_nom; //Ãö
|
|
co2_vars.co_scaleNum3 = drv_params.U_nom;//íàïðÿæåíèå ôàçíîå íîìèíàëüíîå àìïëèòóäíîå
|
|
co2_vars.co_scaleNum4 = drv_params.I_nom; //Òîê ôàçíûé áàçîâûé
|
|
co2_vars.co_scaleNum5 = 1;
|
|
co2_vars.co_scaleNum6 = 1;
|
|
co2_vars.co_scaleNum7 = drv_params.Udc_nom; //íàïðÿæåíèå ÇÏÒ áàçîâîå
|
|
co2_vars.co_scaleNum8 = drv_params.power; //18 â ôîðìàòå 9.6 //Ìîùíîñòü
|
|
co2_vars.co_scaleNum9 = 1;
|
|
co2_vars.co_scaleNumA = 20; //òåìïåðàòóðà
|
|
co2_vars.co_scaleNumB = 1;
|
|
co2_vars.co_scaleNumC = 1;
|
|
co2_vars.co_scaleNumD = 1;
|
|
co2_vars.co_scaleNumE = 1;
|
|
co2_vars.co_scaleNumF = 1;
|
|
co2_vars.co_scaleNum10 = 1; //
|
|
co2_vars.co_scaleNum11 = 1; //
|
|
co2_vars.co_scaleNum12 = drv_params.power; //18 â ôîðìàòå 10.6 //Ìîùíîñòü
|
|
co2_vars.co_scaleNum13 = 360; //
|
|
co2_vars.co_scaleNum14 = drv_params.speed_nom; //íîìèíàëüíàÿ ÷àñòîòà âðàùåíèÿ
|
|
co2_vars.co_scaleNum15 = 1; //
|
|
co2_vars.co_scaleNum16 = 1; //
|
|
co2_vars.co_scaleNum17 = ((((long) drv_params.Udc_nom) << 6)
|
|
/ (long) drv_params.I_nom); //Ráàç 10.6
|
|
co2_vars.co_scaleNum18 = 1000;
|
|
co2_vars.co_scaleNum19 = 1;
|
|
co2_vars.co_scaleNum1A = 1;
|
|
co2_vars.co_scaleNum1B = 1;
|
|
co2_vars.co_scaleNum1C = 1;
|
|
co2_vars.co_scaleNum1D = 1;
|
|
co2_vars.co_scaleNum1E = 1;
|
|
co2_vars.co_scaleNum1F = 1;
|
|
|
|
drv_params.U_nom = 0.5759 * drv_params.Udc_nom;//íîìèíàëüíîå ôàçíîå íàïðÿæåíèå
|
|
drv_params.power = ((long) 300) << 6; //ïðèâåäåì ê ôîðìàòó 10.6
|
|
drv_params.freq_nom = ((float) drv_params.speed_nom * drv_params.p) / 60 + 0.5; //íîìèí ÷àñòîòà
|
|
|
|
co_background_calc(&co1_vars); //Ðàñ÷åò äðàéâåðà CANOpen ôîíîâûé
|
|
co_background_calc(&co2_vars); //Ðàñ÷åò äðàéâåðà CANOpen ôîíîâûé
|
|
drv_interface.calc(&drv_interface);
|
|
FaultLog.background_calc(&FaultLog);
|
|
#ifdef MODBUS_ENA
|
|
MBVarsConv.slow_calc(&MBVarsConv);
|
|
#endif
|
|
|
|
if (RTCclock.ClockOk)//÷àñû ðàáîòàþò?
|
|
FaultLog.time_ptr = (Uint32*) &RTCclock.packed_time; //âðåìÿ äëÿ áàíêà àâàðèé èç ÷àñîâ
|
|
else
|
|
FaultLog.time_ptr = (Uint32*) &global_time.PowerOn_time;//åñëè íå ðàáîòàþò, òî èç ìîäóëÿ ïîäñ÷åòà âðåìåíè íàðàáîòêè
|
|
}
|
|
|
|
//!Áûñòðûé ðàñ÷åò
|
|
|
|
//!Áûñòðûé ðàñ÷åò íåêîòîðûõ ñåòåâûõ ìîäóëåé, âûçîâ ìåòîäîâ "ïðîëèñòûâàíèÿ" êîäîâ àâàðèé è ïðåäóïðåæäåíèé
|
|
//! \memberof TSM_Net
|
|
void SM_Net_ms_Calc(TSM_Net *p) {
|
|
//Ïåðåâîä áèòîâîãî ñîñòîÿíèÿ ñèñòåìû óïðàâëåíèÿ â êîíñòàíòó.
|
|
//Ïî drv_status_code îòîáðàæàåòñÿ ñòàòóñ ïðèâîäà â UniCON
|
|
if (drv_status.bit.ready == 1)
|
|
drv_status_code = DRV_STATUS_READY;
|
|
if (drv_status.bit.running == 1)
|
|
drv_status_code = DRV_STATUS_RUNNING;
|
|
if (drv_status.bit.testing == 1)
|
|
drv_status_code = DRV_STATUS_TESTING;
|
|
if (drv_status.bit.fault == 1)
|
|
drv_status_code = DRV_STATUS_FAULT;
|
|
if (drv_status.bit.alarm == 1)
|
|
drv_status_code |= DRV_STATUS_ALARM;
|
|
else
|
|
drv_status_code &= ~DRV_STATUS_ALARM;
|
|
if (drv_status.bit.overheat == 1)
|
|
drv_status_code = DRV_STATUS_OVERHEAT;
|
|
else
|
|
drv_status_code &= ~DRV_STATUS_OVERHEAT;
|
|
//ôóíêöèÿ ëèñòàíèÿ àâàðèé äëÿ ïóëüòà (UniCON)
|
|
pult_faults_lister.calc(&pult_faults_lister);
|
|
sm_prot.Main_ErrorCode = 0xFF & pult_faults_lister.output;
|
|
|
|
co_1ms_calc(&co1_vars); //Ðàñ÷åò äðàéâåðà CANOpen
|
|
co_1ms_calc(&co2_vars); //Ðàñ÷åò äðàéâåðà CANOpen
|
|
#if (defined(CANTORS_ENA)) || (defined(CANTOUSB_ENA))
|
|
CANtoRS.calc(&CANtoRS);
|
|
#endif
|
|
#ifdef MODBUS_ENA
|
|
MBVarsConv.calc(&MBVarsConv);
|
|
#endif
|
|
|
|
}
|
|
|
|
void SM_Net_fast_Calc(TSM_Net *p) {
|
|
|
|
#ifdef MODBUS_ENA
|
|
ModBus.Execute(&ModBus);
|
|
#endif
|
|
}
|
|
|
|
/*@}*/
|