![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
forkd
Fork of LG2 by
host/Source/App/CntrlGLD.c
- Committer:
- Kovalev_D
- Date:
- 2016-02-03
- Revision:
- 23:12e6183f04d4
File content as of revision 23:12e6183f04d4:
#include "commandset.h" #include "CntrlGLD.h" #include "Cyclessync.h" #include "dspfns.h" #include "SIP.h" #include "el_lin.h" #define COMMAND_DEBUG uint32_t SRgR; //r. ñèñòåìíûé ðåãèñòð ðåæèìà ïëàòû ADSP uint32_t RgConA; //r. îñíîâíîé ðåãèñòð óïðàâëåíèÿ óñòðîéñòâà uint32_t RgConB; //r. äîïîëíèòåëüíûé ðåãèñòð óïðàâëåíèÿ //uint32_t Copy_e5_RgR; //r. êîïèÿ ðåãèñòðà ðåæèìà ïëàòû E5 //uint32_t Copy_e5_RgRA; //r. êîïèÿ äîïîëíèòåëüíîãî ðåãèñòðà ðåæèìà E5 uint32_t Valid_Data; //r. áàéò-ïðèçíàê äîñòîâåðíûõ äàííûõ, íàêàïëèâàþùèé îøèáêè îò çàïðîñà äî çàïðîñà TDEVICE_BLK Device_blk; //e. union for device constants uint32_t ser_num; //e. device serial number int Device_Mode = DM_INT_10KHZ_LATCH; //r. ðåæèì ðàáîòû ïðèáîðà (âíóòð.çàùåëêà, çíàêîâûé ìåàíäð èëè âíåøíÿÿ çàùåëêà) void Sts_Pulse(void); void Sts_Pause(void); void Sts_Polling(void); //r. òàáëèöà ñîñòîÿíèé ïðîöåäóðû çàïóñêà ïðèáîðà void (* Tab_Gld_Start[3])(void) = {Sts_Pulse, Sts_Pause, Sts_Polling}; //r. òàáëèöà ñîñòîÿíèé ïðîöåäóðû ïîäæèãà ëàçåðà void (* Tab_Gld_Pulse[1])(void) = {Sts_Pulse}; //e. stack of states of the procedure of starting //r. ñòåê ïàðàìåòðîâ ñîñòîÿíèé ïðîöåäóðû çàïóñêà uint32_t Stk_Gld_Start[3] = {LIGHT_UP_PULSE_WDTH, LIGHT_UP_PAUSE, LIGHT_UP_POLLING}; uint32_t gyro_Sts = 0; //r. ðåãèñòð ñîñòîÿíèÿ ïðèáîðà uint32_t start_Rq = 1; //r. çàïðîñ íà çàïóñê ïðèáîðà uint32_t start_Go = 0; //r. ïðîöåäóðà çàïóñêà àêòèâíà uint32_t stop_Rq = 0; //r. çàïðîñ íà îñòàíîâ ïðèáîðà uint32_t pulse_Rq = 0; //r. çàïðîñ íà ïîäæèã ëàçåðà uint32_t pulse_Go = 0; //r. ïðîöåññ ïîäæèãà àêòèâåí uint32_t state_index; //r. èíäåêñ ñîñòîÿíèÿ ïðîöåäóðû (ñòàðòà) uint32_t sts_work; //r. 1 - òåêóùåå ñîñòîÿíèå - â ðàáî÷åé ôàçå, 0 - èíèöèàëèçàöèè uint32_t sts_time; //r. ñ÷åò÷èê âðåìåíè òåêóùåãî ñîñòîÿíèÿ uint32_t attempt_Str; //r. ñ÷åò÷èê ïîïûòîê çàïóñêà ïðèáîðà uint32_t BIT_number; uint32_t Is_BIT = 0; void GLD_Stop(void) //e.---------- procedure of GLD stopping -------------------------------------- //r.---------- ïðîöåäóðà îñòàíîâà ÃËÄ -------------------------------------- { if (!stop_Rq) //r. ïðîâåðèòü çàïðîñ íà âûêëþ÷åíèå ïðèáîðà { return; //r. åñëè íåò, âîçâðàò } //r. ñáðîñèòü ôëàãè start_Rq = 0; //r. çàïðîñà âêëþ÷åíèÿ, start_Go = 0; //r. àêòèâíîñòè ïðîöåññà çàïóñêà ïðèáîðà, stop_Rq = 0; //r. çàïðîñà îñòàíîâà open_all_loops(); //r. âûêëþ÷èòü âñå êîíòóðà ðåãóëèðîâàíèÿ gyro_Sts = 0; //r. ñáðîñ ðåãèñòðà ñîñòîÿíèÿ àïïàðàòóðû ÃËÄ //r. óñòàíîâêà çíà÷åíèé ïîêîÿ âûõîäíûõ ïàðàìåòðîâ ðåãóëÿòîðîâ #if !defined COMMAND_DEBUG disable_DACs(); #endif } // GLD_Stop void GLD_Status(void) //r.---------- äîïóñêîâûé êîíòðîëü ïàðàìåòðîâ ÃËÄ -------------------------- { static uint32_t Device_Mode_Old = DM_INT_10KHZ_LATCH/*DM_EXT_LATCH_DELTA_SF_PULSE*/; if ( loop_is_closed(GLD_ON) == 0 ) { open_all_loops(); GLD_Stop(); } if (Device_Mode_Old != Device_Mode) //deviñe mode has been changed { if (SwitchMode()) //e. mode is changed successful { Device_Mode_Old = Device_Mode; //e. save current mode name if (Device_Mode_Old == DM_INT_10KHZ_LATCH) trm_ena = 1; //e. enable answer } } } // GLD_Status void Sts_Pause(void) //r.------- ïðîöåäóðà ñîñòîÿíèÿ ïàóçû -------------------------------------- { if (sts_work) //r. ñîñòîÿíèå â àêòèâíîé ôàçå? { sts_time--; //r. äåêðåìåíò ñ÷åò÷èêà âðåìåíè ñîñòîÿíèÿ if (sts_time > 0) { return; //r. ïðîäîëæàòü ðàáîòó, ïîêà ñ÷åò÷èê ïîëîæèòåëåí } //r. âðåìÿ ñîñòîÿíèÿ êîí÷èëîñü sts_work = 0; //r. ñáðîñèòü ôëàã àêòèâíîñòè state_index++; //r. ïåðåäâèíóòü óêàçàòåëü íà ñëåäóþùåå ñîñòîÿíèå } else { sts_time = Stk_Gld_Start[state_index]; //r. âðåìÿ äàííîãî ñîñòîÿíèÿ sts_work = 1; //r. óñòàíîâèòü ôëàã àêòèâíîé ôàçû } } // Sts_Pause void Sts_Pulse() //r. ------- ïðîöåäóðà ñîñòîÿíèÿ èìïóëüñà ïîäæèãà -------------------------- { if (sts_work) //r. ñîñòîÿíèå â àêòèâíîé ôàçå? { sts_time--; //r. äåêðåìåíò ñ÷åò÷èêà âðåìåíè ñîñòîÿíèÿ if (sts_time > 0) { return; //r. ïðîäîëæàòü ðàáîòó, ïîêà ñ÷åò÷èê ïîëîæèòåëåí } //r. âðåìÿ ñîñòîÿíèÿ êîí÷èëîñü sts_work = 0; //r. ñáðîñèòü ôëàã àêòèâíîñòè state_index++; //r. ïåðåäâèíóòü óêàçàòåëü íà ñëåäóþùåå ñîñòîÿíèå Set_LightUp; //r. ñíÿòü ñèãíàë ïîäæèãà ëàçåðà } else { sts_time = Stk_Gld_Start[state_index]; //r. âðåìÿ äàííîãî ñîñòîÿíèÿ sts_work = 1; //r. óñòàíîâèòü ôëàã àêòèâíîé ôàçû Reset_LightUp; //r. àêòèâèðîâàòü ñèãíàë ïîäæèãà ëàçåðà } } // Sts_Pulse void Sts_Polling(void) //r.========== ïðîöåäóðà ñîñòîÿíèÿ èçìåðåíèÿ è ïðèíÿòèÿ ðåøåíèÿ î çàïóñêå { static int32_t Sum_F_ras = 0; //r. èíòåãðàëüíàÿ ñóììà ðàñùåïëåíèÿ äëÿ ïðîöåäóðû ñòàðòà if (sts_work) //r. ñîñòîÿíèå â àêòèâíîé ôàçå? { if (Dif_Curr_Vib >0) Sum_F_ras = L_add(Sum_F_ras, Dif_Curr_Vib); else Sum_F_ras = L_sub(Sum_F_ras, Dif_Curr_Vib); //r. íåò, ïðîïóñòèòü íàêîïëåíèå ñóììû ðàñùåïëåíèÿ sts_time--; //r. äåêðåìåíò ñ÷åò÷èêà âðåìåíè ñîñòîÿíèÿ if (sts_time > 0) { return; //r. ïðîäîëæàòü ðàáîòó, ïîêà ñ÷åò÷èê ïîëîæèòåëåí } //r. âðåìÿ ñîñòîÿíèÿ êîí÷èëîñü sts_work = 0; //r. ñáðîñèòü ôëàã àêòèâíîñòè state_index++; //r. ïåðåäâèíóòü óêàçàòåëü íà ñëåäóþùåå ñîñòîÿíèå //r. ïðîâåðèòü íàëè÷èå ãåíåðàöèè if ( Sum_F_ras >= F_RAS_MIN) //e. //r. F_RAS_MIN = 10000 ??? ÷òî ýòî çà åäèíèöû??? { gyro_Sts |= LASER_ON; //r. èíà÷å ñòàðò ñîñòîÿëñÿ, îòìåòèòü â ðåãèñòðå ñîñòîÿíèÿ return; //r. ïðèáîðà è çàâåðøàòü ïðîöåññ } //r. åñëè îíà ìåíüøå, ãåíåðàöèè íåò attempt_Str--; //r. äåêðåìåíò ñ÷åò÷èêà ïîïûòîê çàïóñêà ëàçåðà if (attempt_Str <= 0) { return; //r. åñëè ïîïûòêè çàêîí÷åíû, çàâåðøèòü ïðîöåññ } //r. èíà÷å óñòàíîâèòü óêàçàòåëü ñîñòîÿíèé íà state_index = 0; //r. íà÷àëî ïðîöåññà çàïóñêà äëÿ ïîâòîðíîé ïîïûòêè } else { sts_time = Stk_Gld_Start[state_index]; //r. âðåìÿ äàííîãî ñîñòîÿíèÿ sts_work = 1; //r. óñòàíîâèòü ôëàã àêòèâíîé ôàçû Sum_F_ras = 0; //r. ïðåäñáðîñ èíòåãðàëüíîé ñóììû ðàñùåïëåíèÿ } } // Sts_Polling //r.---------- ïðîöåññ çàïóñêà ïðèáîðà ------------------------------------- void GLD_Start(void) { if (!start_Rq) //r. ïðîâåðèòü ñîñòîÿíèå çàïðîñà íà çàïóñê ïðèáîðà { return; //r. çàïðîñà íåò, âîçâðàò } if (!start_Go) //r. ïðîöåññ çàïóñêà åùå íå áûë àêòèâåí? { //r. ýòî íà÷àëî çàïóñêà attempt_Str = N_START_MAX; //r. óñòàíîâèòü ìàêñèìàëüíîå ÷èñëî ïîïûòîê çàïóñêà //r. ðàçîìêíóòü êîíòóðà ðåãóëÿòîðîâ //open_loop(VB_FREQ_ON | VB_TAU_ON | WP_REG_ON | HF_REG_ON); // 0xff95 //close_all_loops(); sts_work = 0; //r. ñáðîñèòü ôëàã àêòèâíîé ôàçû ñîñòîÿíèÿ state_index= 0; //r. óñòàíîâèòü óêàçàòåëü ñîñòîÿíèé â íà÷àëüíîå ïîëîæåíèå start_Go = 1; //r. ïðîöåññ ñòàðòà íà÷àëñÿ } ( *Tab_Gld_Start[state_index] )(); //r. âûçîâ ïðîöåäóðû ñîñòîÿíèÿ ïî íîìåðó â ìàññèâå if (sts_work) //r. òåêóùåå ñîñòîÿíèå îêîí÷åíî? { return; //r. ïðîäîëæàòü îæèäàíèå } //r. ñîñòîÿíèå çàêîí÷èëîñü ïðîâåðèòü óêàçàòåëü ñîñòîÿíèé if ( state_index >= 3 ) { //r. îêîí÷àíèå ïðîöåññà //r. ñáðîñèòü ôëàãè start_Rq = 0; //r. çàïðîñà start_Go = 0; //r. è àêòèâíîñòè ïðîöåññà #if !defined COMMAND_DEBUG Out_G_photo(Device_blk.Str.Gain_Ph_A, Device_blk.Str.Gain_Ph_B); //r. ïîâòîðíî èíèöèàëèçèðîâàòü êîýô-òû ïåðåäà÷è ôîòîïðèåìíèêîâ #endif // close_all_loops(); } } // GLD_Start void GLD_Pulse(void) //r.---------- ïðîöåññ ïîäæèãà ëàçåðà -------------------------------------- { if (!pulse_Rq) //r. ïðîâåðèòü ñîñòîÿíèå çàïðîñà íà ïîäæèã ëàçåðà { return; //r. çàïðîñà íåò, âîçâðàò } if (!pulse_Go) //r. ïðîöåññ ïîäæèãà åùå íå áûë àêòèâåí? { sts_work = 0; //r. ñáðîñèòü ôëàã àêòèâíîé ôàçû ñîñòîÿíèÿ state_index = 0; //r. óñòàíîâèòü óêàçàòåëü ñîñòîÿíèé â íà÷àëüíîå ïîëîæåíèå pulse_Go = 1; //r. ïðîöåññ ñòàðòà íà÷àëñÿ } ( *Tab_Gld_Pulse[state_index] )(); //r. âûçîâ ïðîöåäóðû ñîñòîÿíèÿ ïî íîìåðó â ìàññèâå if (sts_work) //r. òåêóùåå ñîñòîÿíèå îêîí÷åíî? { return; //r. ïðîäîëæàòü îæèäàíèå } if ( state_index >= 1 ) { //r. ñáðîñèòü ôëàãè pulse_Rq = 0; //r. çàïðîñà pulse_Go = 0; //r. è àêòèâíîñòè ïðîöåññà } } // GLD_Pulse void contrl_GLD(void) //r.========== ïðîöåäóðà óïðàâëåíèÿ ïðèáîðîì =============================== { GLD_Start(); //r. çàïóñòèòü ïðèáîð, åñëè åñòü çàïðîñ GLD_Status(); //r. ïðîâåðêà ñîñòîÿíèÿ ïðèáîðà GLD_Stop(); //r. îñòàíîâèòü ïðèáîð, åñëè íåîáõîäèìî GLD_Pulse(); //r. ãåíåðàöèÿ èìïóëüñà ïîäæèãà ïðè íàëè÷èè çàïðîñà GLD_Output(); //r. ðåæèìû âûäà÷è äàííûõ èç ãèðîñêîïà } // contrl_GLD