158 lines
6.0 KiB
C
158 lines
6.0 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
|
|
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
|
|
|
|
//ëîããåð ñîáûòèé:
|
|
// ðàçìåð áóôåðà: 50
|
|
// ñòàðòîâûé àäðåñ â SPI: 3000
|
|
FaultLog.init(&FaultLog, 50, 3000, (Uint32*)&RTCclock.packed_time);//íèæå óêàçàòåëü íà âðåìÿ ìîæåò áûòü ïåðåîïðåäåëåí â çàâèñèìîñòè îò ðàáîòû ÷àñîâ
|
|
|
|
|
|
////Ðàáîòà ñ CANopen ÷åðåç UART (ïàðàëëåëüíî ñ CAN, íåò êîíôëèêòà)
|
|
CANtoRS.nodeID = (Uint16*)&co1_vars.co_nodeID; //Íîìåð óçëà èç CANopen
|
|
CANtoRS.callback = Z_co_receiveSDOrequest;//Óêàçàòåëü íà ôóíêöèþ îáðàòíîãî âûçîâà èç äðàéâåðà CANopen ïî ïðèõîäó SDO ñîîáùåíèÿ
|
|
CANtoRS.init(&CANtoRS);
|
|
}
|
|
|
|
//!Ìåäëåííûé ðàñ÷åò.
|
|
|
|
//! Ïðèñâîåíèå ìàñøòàáèðóþùèõ êîýôôèöèåíòîâ, ôîíîâûé ðàñ÷åò íåêîòîðûõ ìîäóëåé.
|
|
|
|
//! \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;
|
|
|
|
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 ôîíîâûé
|
|
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;
|
|
//ôóíêöèÿ ëèñòàíèÿ àâàðèé äëÿ ïóëüòà (UniCON)
|
|
pult_faults_lister.calc(&pult_faults_lister);
|
|
sm_prot.Main_ErrorCode = 0xFF & pult_faults_lister.output;
|
|
|
|
co_1ms_calc(&co1_vars); //Ðàñ÷åò äðàéâåðà CANOpen
|
|
CANtoRS.calc(&CANtoRS);
|
|
|
|
}
|
|
|
|
void SM_Net_fast_Calc(TSM_Net *p) {
|
|
|
|
#ifdef MODBUS_ENA
|
|
ModBus.Execute(&ModBus);
|
|
#endif
|
|
}
|
|
|
|
/*@}*/
|