matlab_23550/Inu/main.c
2024-12-27 10:50:32 +03:00

145 lines
3.1 KiB
C

/**************************************************************************
Description: Ïðîãðàììà óïðàâëåíèÿ INU.
Âûçûâàåò ï/ï èíèöèàëèçàöèè ïðîöåññîðà è ï/ï îáìåíà.
Àâòîð: Óëèòîâñêèé Ä.È.
Äàòà ïîñëåäíåãî îáíîâëåíèÿ: 2021.10.05
**************************************************************************/
#include "def.h"
#include "main.h"
void control_processor_led(void);
void talk_with_desk(void);
void talk_with_mst(void);
void write_eeprom(void);
extern void detcoeff(void);
extern void init28335(void);
#ifndef ML
void main(void) {
// disable the watchdog
EALLOW;
SysCtrlRegs.WDCR = 0x0068;
EDIS;
// èíèöèàëèçàöèÿ ïðîöåññîðà
init28335();
// èíèöèàëèçàöèÿ ïðîãðàììû
detcoeff();
// re-enable the watchdog
EALLOW;
SysCtrlRegs.WDCR = 0x00A8;
// ... clear the WD counter
SysCtrlRegs.WDKEY = 0x55;
SysCtrlRegs.WDKEY = 0xAA;
EDIS;
// clear Interrupt Flag ADC Sequencer 1
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;
// clear PIEIFR1 register
PieCtrlRegs.PIEIFR1.all = 0;
// before we can start we have to enable interrupt mask in the PIE unit
PieCtrlRegs.PIEIER1.bit.INTx6 = 1;
// core line 1 (INT1)
IER |= M_INT1;
// enable global interrupts and higher priority real-time debug events
EINT;
ERTM;
// çàïóñêàåì òàéìåðû (up-down-count mode)
EPwm1Regs.TBCTL.bit.CTRMODE = 2;
EPwm2Regs.TBCTL.bit.CTRMODE = 2;
EPwm3Regs.TBCTL.bit.CTRMODE = 2;
EPwm4Regs.TBCTL.bit.CTRMODE = 2;
EPwm5Regs.TBCTL.bit.CTRMODE = 2;
EPwm6Regs.TBCTL.bit.CTRMODE = 2;
#ifdef ML
EPwm7Regs.TBCTL.bit.CTRMODE = 2;
EPwm8Regs.TBCTL.bit.CTRMODE = 2;
EPwm9Regs.TBCTL.bit.CTRMODE = 2;
EPwm10Regs.TBCTL.bit.CTRMODE = 2;
EPwm11Regs.TBCTL.bit.CTRMODE = 2;
EPwm12Regs.TBCTL.bit.CTRMODE = 2;
#endif
// loop forever
while(1) {
// îáìåí ñ ÂÓ
// ( -> mst)
talk_with_mst();
// îáìåí ñ ÏÓ
// ( -> param[], eprom.writeRequestNumber)
talk_with_desk();
// çàïèñü â EEPROM
// (param[], eprom.writeRequestNumber -> eprom.writeRequestNumber)
if ( eprom.writeRequestNumber > 0 ) {
write_eeprom();
}
// óïðàâëÿåì ñâåòîäèîäàìè íà ïðîöåññîðíîé ïëàòå
control_processor_led();
} //while(1)
} //void main(void)
// Óïðàâëÿåò ñâåòîäèîäàìè íà ïðîöåññîðíîé ïëàòå
void control_processor_led(void) {
static unsigned short Tled = (unsigned short)(0.5/TY);
static unsigned short tLed = 0;
if ( tLed < Tled ) {
tLed++;
}
else {
tLed = 1;
// â àâàðèéíîì ðåæ. ìîðãàåì êðàñíûì ñâåòîäèîäîì
if ( state == STATE_SHUTDOWN ) {
LED_GREEN1_OFF;
LED_GREEN2_OFF;
LED_RED_TOGGLE;
}
// â ðåæ. îñòàíîâêè ìîðãàåì ïåðâûì çåë¸íûì ñâåòîäèîäîì
else if ( state == STATE_STOP ) {
LED_GREEN1_TOGGLE;
LED_GREEN2_OFF;
LED_RED_OFF;
}
// â ðàáî÷åì ðåæ. ìîðãàåì âòîðûì çåë¸íûì ñâåòîäèîäîì
else {
LED_GREEN1_OFF;
LED_GREEN2_TOGGLE;
LED_RED_OFF;
}
}
} //void control_processor_led(void)
// Ïîëó÷àåò ïàðàìåòðû ñ ÏÓ
// ( -> param[], eprom.writeRequestNumber)
void talk_with_desk(void) {
}
// Ïîëó÷àåò êîìàíäû ñ ÂÓ
// ( -> mst)
void talk_with_mst(void) {
}
// Çàïèñûâàåò ïàðàìåòðû â EEPROM
// (param[], eprom.writeRequestNumber -> eprom.writeRequestNumber)
void write_eeprom(void) {
}
#endif //ML