Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of LGstaandart by
host/Source/App/commandset.c
- Committer:
- Kovalev_D
- Date:
- 2016-02-03
- Revision:
- 23:12e6183f04d4
File content as of revision 23:12e6183f04d4:
#include <string.h>
#include "commandset.h"
#include "el_lin.h"
#include "CyclesSync.h"
#include "CntrlGLD.h"
#include "InputOutput.h"
#include "Parameters.h"
#define COMMAND_DEBUG
//++++++++++++++++debug++++++++++++++++
extern uint32_t In_Flag;
unsigned char BuffTemp1[100];
//e. +++++++++++++++++++ variables +++++++++++++++++++++++++++++++++++++++++++ //r. +++++++++++++++++++ ïåðåìåííûå +++++++++++++++++++++++++++++++++++++++++++
uint32_t CMD_Mode = 0; //e. operation mode of the device //r. ðåæèì ðàáîòû óñòðîéñòâà
uint32_t CMD_Code; //e. full code of the last recieved command //r. ïîëíûé êîä ïîñëåäíåé ïðèíÿòîé êîìàíäû
uint32_t wrk_period; //e. run period in cycles //r. ðàáî÷èé ïåðèîä â öèêëàõ
uint32_t blt_in_test;
int32_t ScopeMode; //e. mode of display for a control point of an scope //r. ðåæèì îòîáðàæåíèÿ äëÿ êîíòðîëüíîé òî÷êè îñöèëëîãðàôà
void SetSpeedPeriod(void) //e.============ procedure of set of rate and periodicity of answer ======== //r.============ ïðîöåäóðà óñòàíîâêè ñêîðîñòè è ïåðèîäè÷íîñòè îòâåòà ========
{
if ((rcv_buf[3] & 0x0080) != 0) //e. is periodic data transmission needed? //r. ïåðèîäè÷åñêàÿ ïåðåäà÷à òðóáóåòñÿ?
{
trm_cycl = 1; //e. yes, set present flag //r. äà, óñòàíîâèòü äàííûé ôëàã
}
else
{
trm_cycl = 0; //e. no, reset present flag //r. íåò, ñáðîñèòü äàííûé ôëàã
}
SRgR &= 0xffcf; //e. clear the bit of transfer rate //r. î÷èñòêà áèò ñêîðîñòè ïåðåäà÷è
trm_rate = (rcv_buf[3] >> 1) & 0x0030;
SRgR |= trm_rate; //e. set present transfer rate //r. óñòàíîâèòü äàííóþ ñêîðîñòü ïåðåäà÷è
} // SetSpeedPeriod
void B_Delta_BINS(void) //r.===ïðîöåäóðà âûäà÷è íàêîïëåííûõ ðàçíîñòåé ñ÷åò÷èêîâ èìïóëüñîâ â ÈÍÑ â ôîðìàòå 14.18
{
Valid_Data = 0; // reset all bits of status word
num_of_par = 2; //e. 2 parameters output //r. âûâîäèòü 2 ïàðàìåòðà
addr_param[0] = &Output.Str.BINS_dif; //e. set the first parameter address //r. çàäàòü àäðåñ ïåðâîãî ïàðàìåòðà
addr_param[1] = &Valid_Data; //e. set the second paremeter address //r. çàäàòü àäðåñ âòîðîãî ïàðàìåòðà
size_param[0] = 4; //e. the length of the 1st parameter is 4 bytes //r. ïàðàìåòð 1 èìåeò äëèíó 4 áàéòà
size_param[1] = 1; //e. the length of the 2nd parameter is 1 byte (!! - the high byte, instead of low is transmitted) //r. ïàðàìåòð 2 èìååò äëèíó 1 áàéò (!!! ïåðåäàåòñÿ ñòàðøèé áàéò, à íå ìëàäøèé)
trm_ena = 1; //e. allow operation of the transmitter //r. ðàçðåøèòü ðàáîòó ïåðåäàò÷èêà
} // B_Delta_BINS
void B_Delta_SF(void) //r.=== ïðîöåäóðà äëÿ èçìåðåíèÿ ìàñøòàáíîãî ìíîæèòåëÿ
{
//e. time for data transfer has come, we work only with dither counters //r. ïðèøëî âðåìÿ ïåðåäàâàòü äàííûå, ðàáîòàåì òîëüêî ñ âèáðî-ñ÷åò÷èêàìè
RgConB = RATE_VIBRO_1; //e. set in the additional register of device control the mode of work with dither counters and the filter of moving average //r. óñòàíàâëèâàåì â äîïîëíèòåëüíîì ðåãèñòðå óïðàâëåíèÿ ðåæèì ðàáîòû ñ âèáðîñ÷åò÷èêàìè è ôèëüòðîì ñêîëüçÿùåãî ñðåäíåãî
Valid_Data = 0; // reset all bits of status word
num_of_par = 5;//8; //e. 8 parameters output //r. âûâîäèòü 8 ïàðàìåòðà
addr_param[0] = &Output.Str.SF_dif; //e. set the first parameter address //r. çàäàòü àäðåñ ïåðâîãî ïàðàìåòðà
addr_param[1] = &Out_main_cycle_latch; //e. set the second paremeter address //r. çàäàòü àäðåñ âòîðîãî ïàðàìåòðà
addr_param[2] = &Out_T_latch;//F_ras;
addr_param[3] = &Output.Str.WP_reg;
addr_param[4] = &Output.Str.Tmp_Out;
size_param[0] = 8; //e. the length of the 1st parameter is 4 bytes //r. ïàðàìåòð 1 èìåeò äëèíó 4 áàéòà
size_param[1] = 4; //e. the length of the 2nd parameter is 1 byte (!! - the high byte, instead of low is transmitted) //r. ïàðàìåòð 2 èìååò äëèíó 1 áàéò (!!! ïåðåäàåòñÿ ñòàðøèé áàéò, à íå ìëàäøèé)
size_param[2] = 2;
size_param[3] = 2;
size_param[4] = 12;
trm_ena = 1; //e. allow operation of the transmitter //r. ðàçðåøèòü ðàáîòó ïåðåäàò÷èêà
} // B_Delta_SF
void B_Delta_PS_execution(void)
{
static void * paramTable[11] = {&(Output.Str.F_ras) , &(Output.Str.HF_reg), &(Output.Str.T_Vibro), &(Output.Str.L_Vibro), &(Output.Str.WP_reg), &(Output.Str.Tmp_Out[0]), &(Output.Str.Tmp_Out[1]), &(Output.Str.Tmp_Out[2]), &(Output.Str.Tmp_Out[3]), &(Output.Str.Tmp_Out[4]), &(Output.Str.Tmp_Out[5])};
static uint32_t val, paramTmpWord;
static uint32_t * ptr;
static uint32_t index = 0;
if ((index & 1) == 0) // high byte
{
ptr = (uint32_t*)paramTable[index >> 1];
val = *ptr;
paramTmpWord = val >> 8; // move it to low byte of word
}
else
{
paramTmpWord = val;
}
paramTmpWord &= 0xFF;
paramTmpWord |= index << 8;
Valid_Data = 0; // reset all bits of status word
num_of_par = 2; //e. 2 parameters output //r. âûâîäèòü 2 ïàðàìåòðà
addr_param[0] = &Output.Str.PS_dif; //e. set the first parameter address //r. çàäàòü àäðåñ ïåðâîãî ïàðàìåòðà
addr_param[1] = ¶mTmpWord;
size_param[0] = 2; //e. the 1st parameter has 2 bytes length //r. ïàðàìåòð 1 èìåeò äëèíó 2 áàéò
size_param[1] = 2; //e. the 2nd and 3rd parameters have 1 bytes length//r. ïàðàìåòðû 2,3 èìåþò äëèíó 1 áàéò
trm_ena = 1; //e. allow operation of the transmitter //r. ðàçðåøèòü ðàáîòó ïåðåäàò÷èêà
index++;
if (index > 21)
{
index = 0;
}
} // B_Delta_PS_execution
void M_Mirror(void) //e.---------------- prepare to transmission of the copy of receiving buffer ------------- //r.---------------- ïîäãîòîâêà ïåðåäà÷è êîïèè ïðèåìíîãî áóôåðà -------------
{
num_of_par = 1; //e. 1 parameter output //r. âûâîäèòü 1 ïàðàìåòð
addr_param[0] = &rcv_copy; //e. set the address of the receiving buffer //r. óñòàíîâêà àäðåñà ïðèåìíîãî áóôåðà
//e. multiply the number of copied words on 2, since each //r. óìíîæèòü ÷èñëî ñêîïèðîâàííûõ ñëîâ íà 2, ò.ê. êàæäîå
//e. will be trasferred in two steps: first zero, and then //r. áóäåò ïåðåäàâàòüñ÷ â äâà ïðèåìà: ñíà÷àëà íóëåâîé, à çàòåì
size_param[0] = rcv_byt_copy << 1; // multiplay by 2
if (size_param[0] >= 64)
{
size_param[0] = 64; //e. maximal amount - no more than double length of the copy buffer //r. ìàêñèìàëüíîå êîëè÷åñòâî - íå áîëåå äâîéíîé äëèíû áóôåðà-êîïèè
}
trm_rate = 0; //e. set the transfer rate to the 38400 bauds //r. óñòàíîâèòü ñêîðîñòü ïåðåäà÷è 38400 áîä
trm_cycl = 0; //e. forbid cyclic transmission of the parameter //r. çàïðåòèòü ïåðåäà÷ó ïàðàìåòðà â öèêëå
trm_ena = 1; //e. allow operation of the transmitter //r. ðàçðåøèòü ðàáîòó ïåðåäàò÷èêà
} // M_Mirror
void Mk_Ask1(void) //r.----------------- prepare of the standart answer 1 ---------------------- //r.----------------- ïîäãîòîâêà ñòàíäàðòíîãî îòâåòà 1 ----------------------
{
CMD_Code &= 0xff00; //e. clear bits of errors //r. î÷èñòèòü â íåì ïîëå îøèáîê
num_of_par = 1; //e. total amount parameters in aswer - 1 //r. âñåãî ïàðàìåòðîâ â îòâåòå - 1
addr_param[0] = &CMD_Code; //e. and this parameter - returnable command code //r. è ýòîò ïàðàìåòð - âîçâðàùàåìûé êîä êîìàíäû
size_param[0] = 2; //e. and both its bytes //r. ïðè÷åì îáà åãî áàéòà
trm_ena = 1; //e. allow operation of the transmitter of the device //r. ðàçðåøèòü ðàáîòó ïåðåäàò÷èêà óñòðîéñòâà
} // Mk_Ask1
void Mk_AskDev(void) //r.----------------- answer on a command for device mode set ------------ //r.----------------- Îòâåò íà êîìàíäó óñòàíîâêè ðåæèìà ïðèáîðà ------------
{
num_of_par = 2; //e. 2 parameters output //r. âûâîäèòü äâà ïàðàìåòðà
addr_param[0] = &Device_Mode; //e. address of the counter mode register (intenal latch, external latch, etc.) //r. àäðåñ ðåãèñòðà ðåæèìà ñ÷åò÷èêîâ (âíóòð., âíåøíÿÿ çàùåëêà è ò.ä.)
addr_param[1] = &SRgR; //e. address of the mode register of the processor card //r. àäðåñ ðåãèñòðà ðåæèìà ïëàòû ïðîöåññîðà
size_param[0] = 2; //e. size of the counter mode register - 2 bytes //r. ðàçìåð ðåãèñòðà ðåæèìà ñ÷åò÷èêîâ - 2 áàéòà
size_param[1] = 2; //e. size of the mode register of the processor card //r. ðàçìåð ðåãèñòðà ðåæèìà ïëàòû ïðîöåññîðà
trm_cycl = 0; //e. forbid cyclic transmission of the parameter //r. çàïðåòèòü ïåðåäà÷ó ïàðàìåòðà â öèêëå
trm_ena = 1; //e. allow operation of the transmitter //r. ðàçðåøèòü ðàáîòó ïåðåäàò÷èêà
} // Mk_AskDev
void GLD_Output(void) //e. ----------- Output modes --------- //r. --------- Ðåæèìû âûâîäà ---------
{
if (Latch_Rdy) //latch appeared
{
if (trm_cycl)
trm_ena = 1; //enable packet generation
switch (CMD_Mode)
{
case 1: //e. Delta _PS mode
B_Delta_PS_execution();
break;
case 5:
CMD_Code &= 0xff1f; //e. reset bits of current command code settings of periodicity and transfer rate //r. ñáðîñèòü â òåêóùåì êîäå êîìàíäû áèòû óñòàíîâêè ïåðèîäè÷íîñòè è ñêîðîñòè ïåðåäà÷è
if (CMD_Code == 0xdd02) //e. is it the Rate2 mode? //r. ýòî ðåæèì Rate2?
{
if (data_Rdy & WHOLE_PERIOD)
{
trm_ena = 1;
}
else
trm_ena = 0;
}
break;
}
}
} // GLD_Delta
///// -------- commands -------------------------------------------------------------
//e. set main device operation modes: //r. Óñòàíîâêà îñíîâíûõ ðåæèìîâ ðàáîòû ïðèáîðà:
//e. 1. acions with counters (internal latch, external latch with request over line, //r. 1. ðàáîòà ñî ñ÷åò÷èêàìè (âíóòðåííÿÿ çàùåëêà, âíåøíÿÿ çàùåëêè ñ çàïðîñîì ïî ëèíèè,
//e. external latch without request over line (instant answer after receiving of external latch pulse)) //r. âíåøíÿÿ çàùåëêà áåç çàïðîñà ïî ëèíèè (îòâåò ñðàçó ïîñëå ïðèõîäà èìïóëüñà âíåøí. çàùåëêè))
//e. 2. line receiving/transmission rate //r. 2. ñêîðîñòü ïðèåìà/ïåðåäà÷è ïî ëèíèè
void B_Dev_Mode(void)
{
Device_Mode = rcv_buf[3] & 0x00ff; //e. read the byte of command parameter from the receiver buffer //r. ñ÷èòàòü èç áóôåðà ïðèåìíèêà áàéò ïàðàìåòðà êîìàíäû
//e. and write it to the counter mode register //r. è çàïèñûâàåì â ðåãèñòð ðåæèìà ñ÷åò÷èêîâ
trm_cycl = 0; //e. periodic data transmission is not needed //r. ïåðèîäè÷åñêàÿ ïåðåäà÷à îòâåòà íå òðåáóåòñÿ
Mk_AskDev();
} // B_Dev_Mode
void B_BIT_Mode(void)
{
uint8_t temp;
temp = rcv_buf[3] & 0x000f & (~((rcv_buf[3] & 0x00f0) >> 4));
if (temp == 1) // 1 - const test
{
Is_BIT = 1;
BIT_number = (long)(rcv_buf[4] & 0x00FF) << 24;
BIT_number |= (long)(rcv_buf[5] & 0x00FF) << 16;
BIT_number |= (long)(rcv_buf[6] & 0x00FF) << 8;
BIT_number |= (long)(rcv_buf[7] & 0x00FF);
}
else
{
Is_BIT = 0;
}
trm_cycl = 0; //e. periodic data transmission is not needed //r. ïåðèîäè÷åñêàÿ ïåðåäà÷à îòâåòà íå òðåáóåòñÿ
Mk_AskDev();
} // B_BIT_Mode
void M_Stimul(void) //e. === procedure of output of analog (DAC) and digital (flags) stimuluses //r. === ïðîöåäóðà âûâîäà àíàëîãîâûõ (ÖÀÏ) è äèñêðåòíûõ (ôëàãè) ñòèìóëîâ
{
uint32_t chan;
ScopeMode = 4; //e. WP_PHASE_DETECTOR allocate a mode of display for a control point of an scope //r. WP_PHASE_DETECTOR íàçíà÷èòü ðåæèì îòîáðàæåíèÿ äëÿ êîíòðîëüíîé òî÷êè îñöèëëîãðàôà
chan = CMD_Code & 0x0007; //e. extracting the number of stimulus //r. âûäåëåíèå íîìåðà ñòèìóëà
Output.ArrayOut[chan] = (((int)rcv_buf[4] << 8) | (int)rcv_buf[5])-0x8000;
if ((CMD_Code & (1 << 7)) == 0) //e. to estimate: whether the answer is required //r. îöåíèòü: òðåáóåòñÿ ëè îòâåò
{
return; //e. if no - return //r. åñëè íåò - âîçâðàò
}
Mk_Ask1(); //e. otherwise - answer output //r. èíà÷å - âûäàòü îòâåò
} // M_Stymul
void M_Status(void) //e. === procedure of initialization of transmission of the device status //r. === ïðîöåäóðà èíèöèàëèçàöèè ïåðåäà÷è ñòàòóñà óñòðîéñòâà
{
SetSpeedPeriod(); //e. and set the answer transfer rate and its periodicity //r. è óñòàíîâèòü ñêîðîñòü ïåðåäà÷è îòâåòà è åãî ïåðèîäè÷íîñòü
num_of_par = 2; //e. 2 parameters output //r. âûâîäèòü äâà ïàðàìåòðà
addr_param[0] = &blt_in_test; //e. the register address of the self-testing result //r. àäðåñ ðåãèñòðà ðåçóëüòàòà ñàìîòåñòèðîâàíèÿ
addr_param[1] = &ser_num; //e. address of the register of errors of line //r. àäðåñ ðåãèñòðà îøèáîê ëèíèè
size_param[0] = 2; //e. size of the self-test register - 2 bytes //r. ðàçìåð ðåãèñòðà ñàìîòåñòèðîâàíèÿ - 2 áàéòà
size_param[1] = 2; //e. size of the register of errors of line //r. ðàçìåð ðåãèñòðà îøèáîê ëèíèè
trm_rate = 0; //e. set the transfer rate to the 38400 bauds //r. óñòàíîâèòü ñêîðîñòü ïåðåäà÷è 38400 áîä
trm_cycl = 0; //e. forbid cyclic transmission of the parameter //r. çàïðåòèòü ïåðåäà÷ó ïàðàìåòðà â öèêëå
trm_ena = 1; //e. allow operation of the transmitter //r. ðàçðåøèòü ðàáîòó ïåðåäàò÷èêà
} // M_Status
void M_Clear(void) //e.---------------- cleaning of the register of errors of line -------------------------- //r.---------------- î÷èñòêà ðåãèñòðà îøèáîê ëèíèè --------------------------
{
line_err = 0;
} // M_Clear
void M_Tmp_W(void) //e.----------------- write the command to the AD7714 IC ------------------------- //r.----------------- çàïèñü êîìàíäû â ñõåìû AD7714 -------------------------
{
Mk_Ask1();
}
void M_Tmp_R(void) //e.----------------- read the data from the AD7714 IC -------------------------- //r.----------------- ÷òåíèå äàííûõ èç ñõåì AD7714 --------------------------
{
} // M_Tmp_R
void M_ADC_R(void) //e.----------------- read the data from the ADCs ADS1250, ADS8321 --------- //r.----------------- ÷òåíèå äàííûõ èç êàíàëîâ ÀÖÏ ADS1250, ADS8321 ---------
{
SetSpeedPeriod(); //e. set the answer transfer rate and its periodicity //r. óñòàíîâèòü ñêîðîñòü ïåðåäà÷è îòâåòà è åãî ïåðèîäè÷íîñòü
UART_SwitchSpeed(trm_rate);
num_of_par = 4; //e. 4 parameters output //r. âûâîäèòü ÷åòûðå ïàðàìåòðà
addr_param[0] = 0; //e. //r. <!-- èñïîëüçîâàëèñü äëÿ ÄÓÏ, òåïåðü íå èñïîëüçóþòñÿ
addr_param[1] = 0; //e. //r. -->
addr_param[2] = 0;
addr_param[3] = &(Input.StrIn.HF_out); //e. set the 4th parameter address _HF_out //r. çàäàòü àäðåñ ÷åòâåðòîãî ïàðàìåòðà _HF_out
size_param[0] = 2; //e. size of the parameters - 2 bytes //r. ðàçìåð ïàðàìåòðîâ - 2 áàéòà
size_param[1] = 2;
size_param[2] = 2;
size_param[3] = 2;
trm_ena = 1; //e. allow operation of the transmitter //r. ðàçðåøèòü ðàáîòó ïåðåäàò÷èêà
} // M_ADC_R
void M_Cnt_R(void) //r.----------------- read the counters of the Elio5 card -------------------------- //r.----------------- ÷òåíèå ñ÷åò÷èêîâ ïëàòû Elio5 --------------------------
{
SetSpeedPeriod(); //e. set the answer transfer rate and its periodicity //r. óñòàíîâèòü ñêîðîñòü ïåðåäà÷è îòâåòà è åãî ïåðèîäè÷íîñòü
UART_SwitchSpeed(trm_rate);
num_of_par = 2; //e. 2 parameters output //r. âûâîäèòü äâà ïàðàìåòðà
addr_param[0] = &(Output.Str.Cnt_Pls); //e. set the first parameter address //r. çàäàòü àäðåñ ïåðâîãî ïàðàìåòðà
addr_param[1] = &(Output.Str.Cnt_Mns); //e. set the second paremeter address //r. çàäàòü àäðåñ âòîðîãî ïàðàìåòðà
size_param[0] = 2; //e. size of the parameters - 2 bytes //r. ðàçìåð ïàðàìåòðîâ - 2 áàéòà
size_param[1] = 2;
trm_ena = 1; //e. allow operation of the transmitter //r. ðàçðåøèòü ðàáîòó ïåðåäàò÷èêà
} // M_Cnt_R
/*void M_e5r_W(void) //r.----------------- write to the mode register of the Elio5 card ------------------ //r.----------------- çàïèñü â ðåãèñòð ðåæèìà ïëàòû Elio5 ------------------
{
//e. read the byte of command parameter from the receiver buffer //r. ñ÷èòàòü èç áóôåðà ïðèåìíèêà áàéò ïàðàìåòðà êîìàíäû
//e. and write it to the card mode register and its copy //r. è çàïèñàòü åãî â ðåãèñòð ðåæèìà ïëàòû è â åãî êîïèþ
#if !defined COMMAND_DEBUG
Copy_e5_RgR = rcv_buf[3];
io_space_write(E5_RGR, Copy_e5_RgR);
#endif
trm_cycl = 0; //e. periodic data transmission is not needed //r. ïåðèîäè÷åñêàÿ ïåðåäà÷à îòâåòà íå òðåáóåòñÿ
Mk_Ask1();
} // M_e5r_W */
/*
void M_e5rA_W(void) //e.----- write to the 1st additional mode register of the Elio5 card ---------- //r.----- çàïèñü â 1-ûé äîïîëíèòåëüíûé ðåãèñòð ðåæèìà ïëàòû Elio5 ----------
{
//e. this command is used for switching a signal on which data counters are latched: //r. ýòà êîìàíäà èñïîëüçóåòñÿ äëÿ ïåðåêëþ÷åíèÿ ñèãíàëà, ïî êîòîðîìó çàùåëêèâàþòñÿ
//e. on the Reper signal or on Sign Meander //r. èíôîðìàöèîííûå ñ÷åò÷èêè: ëèáî ïî Reper`ó ëèáî ïî RefMeandr`ó
//e. read the byte of command parameter from the receiver buffer //r. ñ÷èòàòü èç áóôåðà ïðèåìíèêà áàéò ïàðàìåòðà êîìàíäû
//e. and write it to the card mode register and its copy //r. è çàïèñàòü åãî â ðåãèñòð ðåæèìà ïëàòû è â åãî êîïèþ
Copy_e5_RgRA = rcv_buf[3];
//??? Device_Mode = Copy_e5_RgRA; //e. and write it to the counter mode register //r. è çàïèñûâàåì â ðåãèñòð ðåæèìà ñ÷åò÷èêîâ
#if !defined COMMAND_DEBUG
io_space_write(E5_RGRA, Copy_e5_RgRA);
#endif
trm_cycl = 0; //e. periodic data transmission is not needed //r. ïåðèîäè÷åñêàÿ ïåðåäà÷à îòâåòà íå òðåáóåòñÿ
Mk_Ask1();
} // M_e5rA_W */
void M_Ctl_R(void) //r.----------------- reading the control register of the device ----------------- //r.----------------- ÷òåíèå ðåãèñòðà óïðàâëåíèÿ óñòðîéñòâà -----------------
{
num_of_par = 2; //e. 2 parameters transfer //r. ïåðåäàâàòü 2 ïàðàìåòðà
addr_param[0] = &CMD_Code; //e. the first parameter in answer - returned command code //r. ïåðâûé ïàðàìåòð â îòâåòå - âîçâðàùàåìûé êîä êîìàíäû
size_param[0] = 2;
size_param[1] = 2; //e. two bytes also have control registers //r. äâà áàéòà èìåþò òàêæå è ðåãèñòðû óïðàâëåíèÿ
if ((rcv_buf[3] & (1 << 4)) == 0) //e. is main control register needed? //r. òðåáóåòñÿ îñíîâíîé ðåãèñòð óïðàâëåíèÿ?
{
addr_param[1] = &RgConA; //e. yes //r. äà
}
else
{
addr_param[1] = &RgConB; //e. otherwise - load the address of the addititonal register //r. èíà÷å - çàãðóçèòü àäðåñ äîïîëíèòåëüíîãî ðåãèñòðà
}
CMD_Code &= 0xff10; //e. clear in it bit of errors and byte number //r. ñáðîñèòü â íåì ïîëÿ îøèáîê è íîìåðà áèòà
trm_ena = 1; //e. allow operation of the transmitter of line //r. ðàçðåøèòü ðàáîòó ïåðåäàò÷èêà ëèíèè
} // M_Ctl_R
void M_Ctl_M(void) //r.----------------- modification of the control register of the device ------------ //r.----------------- ìîäèôèêàöèÿ ðåãèñòðà óïðàâëåíèÿ óñòðîéñòâà ------------
{
uint32_t * ptr;
uint32_t bit_numb;
num_of_par = 2; //e. 2 parameters transfer //r. ïåðåäàâàòü 2 ïàðàìåòðà
addr_param[0] = &CMD_Code; //e. the first parameter in answer - returned command code //r. ïåðâûé ïàðàìåòð â îòâåòå - âîçâðàùàåìûé êîä êîìàíäû
size_param[0] = 2;
size_param[1] = 2; //e. two bytes also have control registers //r. äâà áàéòà èìåþò òàêæå è ðåãèñòðû óïðàâëåíèÿ
if ((CMD_Code & (1 << 4)) == 0) //e. is main control register needed? //r. òðåáóåòñÿ îñíîâíîé ðåãèñòð óïðàâëåíèÿ?
{
ptr = &RgConA; //e. yes //r. äà
}
else
{
ptr = &RgConB; //e. otherwise - load the address of the addititonal register //r. èíà÷å - çàãðóçèòü àäðåñ äîïîëíèòåëüíîãî ðåãèñòðà
}
addr_param[1] = ptr; //e. the second parameter in answer - modified register //r. âòîðîé ïàðàìåòð â îòâåòå - ìîäèôèöèðîâàííûé ðåãèñòð
bit_numb = CMD_Code & 0x000f; //e. extract the number of the changeable bit //r. âûäåëèòü íîìåð èçìåíÿåìîãî áèòà
if ((CMD_Code & (1 << 7)) == 0) // Is clear bit
{
*ptr &= ~(1 << bit_numb); // yes, clear bit
}
else
{
*ptr |= 1 << bit_numb; // no, set bit
}
CMD_Code &= 0xff10; //e. clear in command bit of errors and byte number //r. ñáðîñèòü â êîìàíäå ïîëÿ îøèáîê è íîìåðà áèòà
trm_cycl = 0; //e. forbid cyclic transmission of the parameter //r. çàïðåòèòü ïåðåäà÷ó ïàðàìåòðà â öèêëå
trm_ena = 1; //e. allow operation of the transmitter of line //r. ðàçðåøèòü ðàáîòó ïåðåäàò÷èêà ëèíèè
} // M_Ctl_M
void M_Flg_R(void) //e.------------ reading the register of input flags --------------------------- //r.------------ ÷òåíèå ðåãèñòðà âõîäíûõ ôëàãîâ ---------------------------
{
num_of_par = 1; //e. 1 parameter output //r. âûâîäèòü îäèí ïàðàìåòð
addr_param[0] = &In_Flag; //e. the address of the flag register copy //r. àäðåñ êîïèè ðåãèñòðà ôëàãîâ
size_param[0] = 2; //e. size of the buffer - 2 bytes //r. ðàçìåð áóôåðà - 2 áàéòà
trm_ena = 1; //e. allow operation of the transmitter //r. ðàçðåøèòü ðàáîòó ïåðåäàò÷èêà
} // M_Flg_R
void M_Vib_W(void) //r.------------ set the oscillation period of the dither drive ----------------- //r.------------ óñòàíîâêà ïåðèîäà êîëåáàíèé âèáðîïðèâîäà -----------------
{
ScopeMode = 1; //e. VB_PHASE_DETECTOR allocate a mode of display for a control point of an scope //r. VB_PHASE_DETECTOR íàçíà÷èòü ðåæèì îòîáðàæåíèÿ äëÿ êîíòðîëüíîé òî÷êè îñöèëëîãðàôà
Output.Str.T_Vibro = (rcv_buf[4] << 8) | (rcv_buf[5] & 0xFF); //e. new variable of the period //r. íîâàÿ ïåðåìåííàÿ ïåðèîäà
/* sprintf(BuffTemp1, "\n\r F = %d ", Output.Str.T_Vibro);
SendToBuff(BuffTemp1,15);*/
Output.Str.L_Vibro= (rcv_buf[6] << 8) | (rcv_buf[7] & 0xFF); //e. new variable of the pulse width //r. íîâàÿ ïåðåìåííàÿ äëèòåëüíîñòè èìïóëüñîâ
/*sprintf(BuffTemp1, "\n\r L = %d ", Output.Str.L_Vibro);
SendToBuff(BuffTemp1,15);*/
VibroDither_Set(); //e. and output its value to period registers on card //r. âûâåñòè åå çíà÷åíèå â ðåãèñòðû ïåðèîäà íà ïëàòå
trm_cycl = 0; //e. periodic data transmission is not needed //r. ïåðèîäè÷åñêàÿ ïåðåäà÷à îòâåòà íå òðåáóåòñÿ
Mk_Ask1();
} // M_Vib_W
void M_Gph_W(void) //e.------------ set the gain factor of photodetector channels ------------------- //r.------------ óñòàíîâêà óñèëåíèÿ êàíàëîâ ôîòîïðèåìíèêà -------------------
{
Device_blk.Str.Gain_Ph_A = rcv_buf[4]; //e. read from the receiver buffer the value of the gain factor of the A channel //r. ñ÷èòàòü èç áóôåðà ïðèåìíèêà çíà÷åíèå óñèëåíèÿ êàíàëà À
Device_blk.Str.Gain_Ph_B = rcv_buf[5]; //e. read from the receiver buffer the value of the gain factor of the B channel //r. ñ÷èòàòü èç áóôåðà ïðèåìíèêà çíà÷åíèå óñèëåíèÿ êàíàëà Â
Out_G_photo(Device_blk.Str.Gain_Ph_A, Device_blk.Str.Gain_Ph_B); //e. display these values to digital potentiometers //r. âûâåñòè ýòè çíà÷åíèÿ â öèôðîâûå ïîòåíöèîìåòðû
trm_cycl = 0; //e. periodic data transmission is not needed //r. ïåðèîäè÷åñêàÿ ïåðåäà÷à îòâåòà íå òðåáóåòñÿ
Mk_Ask1();
} // M_Gph_W
void M_Rate(void) //e.------------ start of transfer of the M_Rate parameters stack ------------------- //r.------------ çàïóñê ïåðåäà÷è íàáîðà ïàðàìåòðîâ M_Rate -------------------
{
uint8_t mode;
SetSpeedPeriod(); //e. set the answer transfer rate and its periodicity //r. óñòàíîâèòü ñêîðîñòü ïåðåäà÷è îòâåòà è åãî ïåðèîäè÷íîñòü
UART_SwitchSpeed(trm_rate);
mode = rcv_buf[3] & 0x001f; //e. extract number of the parameters stack in the command //r. âûäåëèòü íîìåð íàáîðà ïàðàìåòðîâ â êîìàíäå
switch (mode) {
case 1: //e. it is the Rate stack //r. ýòî íàáîð Rate
RgConB = RATE_REPER_OR_REFMEANDR; //e. counter latch every vibro period
SwitchRefMeandInt(RATE_REPER_OR_REFMEANDR); //e. enable reference meander interrupt
wrk_period = 12500000; //e. load needed length of working period 1 ñ.//r. çàãðóçèòü òðåáóåìóþ äëèòåëüíîñòü ðàáî÷åãî ïåðèîäà 1 ñ.
num_of_par = 14; //e. 9 parameters or groups of parameters output //r. âûâîäèòü 9 ïàðàìåòðîâ èëè ãðóïï ïàðàìåòðîâ
Valid_Data = 0; // reset all bits of status word
addr_param[0] = &(Output.Str.Cnt_Pls); //e. set the address of the 1st parameter in the 1st group //r. çàäàòü àäðåñ ïåðâîãî ïàðàìåòðà â 1-îé ãðóïïå
addr_param[1] = &(Output.Str.Cnt_Mns); //e. set the address of the 1st parameter in the 2nd group //r. çàäàòü àäðåñ ïåðâîãî ïàðàìåòðà â 2-îé ãðóïïå
addr_param[2] = &(Output.Str.Cnt_Dif); //e. set the address of the 1st parameter in the 3rd group //r. çàäàòü àäðåñ ïåðâîãî ïàðàìåòðà â 3-îé ãðóïïå
addr_param[3] = &(Output.Str.F_ras); //e. set the address of the _F_ras parameter in the 4th group //r. çàäàòü àäðåñ ïàðàìåòðà _F_ras âî 4-îé ãðóïïå
addr_param[4] = &(Output.Str.HF_reg); //e. set the address of the _HF_reg parameter in the 5th group //r. çàäàòü àäðåñ ïàðàìåòðà _HF_reg â 5-åé ãðóïïå
addr_param[5] = &(Output.Str.HF_dif); //e. set the address of the _HF_dif parameter in the 6th group //r. çàäàòü àäðåñ ïàðàìåòðà _HF_dif â 6-îé ãðóïïå
addr_param[6] = &(Output.Str.T_Vibro); //e. parameter _T_Vibro //r. ïàðàìåòð _T_Vibro
addr_param[7] = &(Output.Str.T_VB_pll); //e. parameter _T_VB_pll //r.ïàðàìåòðâ _T_VB_pll
addr_param[8] = &(Output.Str.L_Vibro); //e. parameter _L_Vibro //r. ïàðàìåòð _L_Vibro
addr_param[9] = &(Input.StrIn.HF_out); //e. set the address of the _RI_reg parameter in the 8th group //r. çàäàòü àäðåñ ïàðàìåòðà _RI_reg â 8-îé ãðóïïå
addr_param[10] = &(Output.Str.WP_reg); //e. parameters: _WP_reg, _WP_pll //r. ïàðàìåòðîâ _WP_reg, _WP_pll
addr_param[11] = &(Output.Str.WP_pll); //e. parameters: _WP_reg, _WP_pll //r. ïàðàìåòðîâ _WP_reg, _WP_pll
addr_param[12] = &(Output.Str.Tmp_Out); //e. set the address of the temperature sensors array //r. çàäàòü àäðåñ ìàññèâà äàò÷èêîâ òåìïåðàòóðû
addr_param[13] = &(Output.Str.WP_scope1); //e. reserved //r. çàðåçåðâèðîâàíî äëÿ äàëüíåéøèõ ïðèìåíåíèé
size_param[0] = 2; //e. groups 1-6, 8-10 consists of one parameter ... //r. ãðóïïû 1-6, 8-10 ñîäåðæàò ïî îäíîìó ïàðàìåòðó
size_param[1] = 2; //e. and have 2 bytes length each //r. è èìåþò äëèíó 2 áàéòà êàæäàÿ
size_param[2] = 2;
size_param[3] = 2;
size_param[4] = 2;
size_param[5] = 2;
size_param[6] = 2;
size_param[7] = 2;
size_param[8] = 2;
size_param[9] = 2;
size_param[10] = 2;
size_param[11] = 2;
size_param[13] = 4; //e. the 11th group parameters has length of 4 bytes //r. 11-z ãðóïïà ïàðàìåòðîâ èìååò äëèíó 4 áàéòà
size_param[12] = 12; //e. format o the GLD array of temperatures - 12 bytes //r. ôîðìàò ìàññèâà òåìïåðàòóð ÃËÄ - 12 áàéò
trm_ena = 1; //e. allow operation of the transmitter //r. ðàçðåøèòü ðàáîòó ïåðåäàò÷èêà
break;
case 2: //e. it is the Rate2 stack //r. ýòî íàáîð Rate2
RgConB = RATE_REPER_OR_REFMEANDR;
SwitchRefMeandInt(RATE_REPER_OR_REFMEANDR); //e. enable interrupt from ref. meander
wrk_period = 0; //e. frequency of output = fvibro //r. ÷àñòîòà âûâîäà ðàâíà ÷àñòîòå ÂÏ
num_of_par = 2; //e. 2 parameters output //r. âûâîäèòü 2 ïàðàìåòðà
addr_param[0] = &(Output.Str.Cnt_Pls); //e. set the first parameter address //r. çàäàòü àäðåñ ïåðâîãî ïàðàìåòðà
addr_param[1] = &(Output.Str.Cnt_Mns); //e. and the 2nd //r. è âòîðîãî
size_param[0] = 2; //e. parameters has 2 bytes length //r. ïàðàìåòðû èìååò äëèíó 2 áàéòà
size_param[1] = 2;
trm_ena = 1; //e. allow operation of the transmitter //r. ðàçðåøèòü ðàáîòó ïåðåäàò÷èêà
break;
case 3: //e. it is the Rate3 stack //r. ýòî íàáîð Rate3
wrk_period = 2500; //e. frequency of output = 10000 Hz //r. n=1, ÷àñòîòà âûâîäà = 10000 Hz
num_of_par = 2; //e. 2 parameters output //r. âûâîäèòü 2 ïàðàìåòðà
addr_param[0] = &(Output.Str.WP_scope1); //e. set the addresses of output parameters //r. çàäàòü àäðåñà âûâîäèìûõ ïàðàìåòðîâ
addr_param[1] = &(Output.Str.WP_scope2);
size_param[0] = 2; //e. all parameters has 2 bytes length //r. âñå ïàðàìåòðû èìåþò äëèíó 2 áàéòà
size_param[1] = 2;
trm_ena = 1; //e. allow operation of the transmitter //r. ðàçðåøèòü ðàáîòó ïåðåäàò÷èêà
break;
case 4: //e. it is the Rate4 stack //r. ýòî íàáîð Rate4
wrk_period = 20000; //e. correspond to output frequency 1.25 kHz //r. ñîîòâåñòâóåò ÷àñòîòå âûâîäà 1.25 kHz
num_of_par = 4; //e. 4 parameters output //r. âûâîäèòü 4 ïàðàìåòðà
//e. set the addresses of output parameters //r. çàäàòü àäðåñà âûâîäèìûõ ïàðàìåòðîâ
// --- raw data array of numbers ---
// addr_param[0] = &Dif_Curr_Array;
// --- filtered array of numbers ---
// addr_param[1] = &Dif_Filt_Array;
// ---------------------------------
addr_param[2] = &(Output.Str.HF_reg); //e. HFO regulator //r. íàïðÿæåíèå ÃÂ×
addr_param[3] = &(Output.Str.WP_reg); //e. CPLC heater regulator //r. íàïðÿæåíèå íàãðåâàòåëÿ
size_param[0] = 16;
size_param[1] = 32;
size_param[2] = 2;
size_param[3] = 2;
trm_ena = 1; //e. allow operation of the transmitter //r. ðàçðåøèòü ðàáîòó ïåðåäàò÷èêà
break;
case 7:
wrk_period = 20000; //e. correspond to output frequency 1250 Hz //r. ñîîòâåñòâóåò ÷àñòîòå âûâîäà 1.25 kHz
num_of_par = 5; //e. 4 parameters output //r. âûâîäèòü 5 ïàðàìåòðà
//e. set the addresses of output parameters //r. çàäàòü àäðåñà âûâîäèìûõ ïàðàìåòðîâ
// --- raw data array of PLC phase ---
addr_param[0] = &(Output.Str.WP_Phase_Det_Array);
// --- filtered array of reference sin---
addr_param[1] = &(Output.Str.WP_sin_Array);
// ---------------------------------
addr_param[2] = &(Output.Str.WP_reg); //e. CPLC heater regulator //r. íàïðÿæåíèå íàãðåâàòåëÿ
addr_param[3] = &(Output.Str.WP_pll); //e. CPLC phase //r. ôàçà
addr_param[4] = &(Output.Str.HF_reg); //e. set the address of the _HF_reg parameter in the 5th group //r. çàäàòü àäðåñ ïàðàìåòðà _HF_reg â 5-åé ãðóïïå
size_param[0] = 16;
size_param[1] = 16;
size_param[2] = 2;
size_param[3] = 2;
size_param[4] = 2;
trm_ena = 1; //e. allow operation of the transmitter //r. ðàçðåøèòü ðàáîòó ïåðåäàò÷èêà
break;
}
SetIntLatch(wrk_period);
} // M_Rate
void M_Reset(void)
{
while(1);
} // will not achieve
void M_Param_R(void) //e. ------------ read the parameter of the GLD from the data memory ---------------------- //r.------------ ÷òåíèå ïàðàìåòðà GLD èç ïàìÿòè äàííûõ ----------------------
{
num_of_par = 1; //e. 1 parameter output //r. âûâîäèòü îäèí ïàðàìåòð
addr_param[0] = (void *)(&Device_blk.Str.My_Addres + rcv_buf[3]); //e. address of the needed parameter in the block //r. àäðåñ òðåáóåìîãî ïàðàìåòðà â áëîêå
size_param[0] = 2; //e. size of the buffer - 2 bytes //r. ðàçìåð áóôåðà - 2 áàéòà
trm_ena = 1; //e. allow operation of the transmitter //r. ðàçðåøèòü ðàáîòó ïåðåäàò÷èêà
} // M_Param_R
void M_Param_W(void) //e.------------ write the parameter of the GLD from the data memory ----------------------- //r.------------ çàïèñü ïàðàìåòðà GLD â ïàìÿòü äàííûõ -----------------------
{
int * ptr;
ScopeMode = 0; //e. VB_DELAY_MEANDER allocate a mode of display for a control point of an scope //r. VB_DELAY_MEANDER íàçíà÷èòü ðåæèì îòîáðàæåíèÿ äëÿ êîíòðîëüíîé òî÷êè îñöèëëîãðàôà
ptr = (int *)&Device_blk.Str.My_Addres; // pointer to Parameters block
ptr += rcv_buf[3]; // calculate offset
*ptr = (rcv_buf[4] << 8) | (rcv_buf[5] & 0xFF); // write new parameter value
trm_cycl = 0; //e. periodic data transmission is not needed //r. ïåðèîäè÷åñêàÿ ïåðåäà÷à îòâåòà íå òðåáóåòñÿ
Mk_Ask1();
} // M_Param_W
void M_LdPar_F() //e.============ procedure for load the GLD parameters from the flash-memory =========== //r.============ ïðîöåäóðà çàãðóçêè ïàðàìåòðîâ ÃËÄ èç ôëýø-ïàìÿòè ===========
{
LoadFlashParam(FromFLASH); //e. load the GLD parameters from the flash-memory //r. çàãðóçèòü ïàðàìåòðû ÃËÄ èç ôäýø-ïàìÿòè
blt_in_test = ((uint32_t)FIRMWARE_VER << 8) | (Device_blk.Str.Device_SerialNumber & 0x00FF);
// Init_software();
trm_cycl = 0; //e. periodic data transmission is not needed //r. ïåðèîäè÷åñêàÿ ïåðåäà÷à îòâåòà íå òðåáóåòñÿ
Mk_Ask1();
} // M_LdPar_F
void M_LdPar_D(void) //e.============ procedure for set parameters of the GLD by default ============ //r.============ ïðîöåäóðà óñòàíîâêè ïàðàìåòðîâ ÃËÄ ïî óìîë÷àíèþ ============
{
#if !defined COMMAND_DEBUG
LoadFlashParam(ByDefault); //e. define parameters of the GLD by default //r. îïðåäåëèòü ïàðàìåòðû ÃËÄ ïî óìîë÷àíèþ (default)
Init_software();
#endif
trm_cycl = 0; //e. periodic data transmission is not needed //r. ïåðèîäè÷åñêàÿ ïåðåäà÷à îòâåòà íå òðåáóåòñÿ
Mk_Ask1();
} // M_LdPar_D
void M_Start(void) //e.============ initialization of the GLD switch on ================================= //r.============ èíèöèàëèçàöèÿ çàïóñêà ÃËÄ =================================
{
start_Rq = 1; //e. set the flag of the GLD switch on request //r. óñòàíîâèòü ôëàã çàïðîñà ñòàðòà ÃËÄ
trm_cycl = 0; //e. periodic data transmission is not needed //r. ïåðèîäè÷åñêàÿ ïåðåäà÷à îòâåòà íå òðåáóåòñÿ
Mk_Ask1();
} // M_Start
void M_Stop(void) //e.============ initialization of the GLD switch off ============================== //r.============ èíèöèàëèçàöèÿ âûêëþ÷åíèÿ ÃËÄ ==============================
{
stop_Rq = 1; //e. set the flag of the GLD switch off request //r. óñòàíîâèòü ôëàã çàïðîñà âûêëþ÷åíèÿ ÃËÄ
trm_cycl = 0; //e. periodic data transmission is not needed //r. ïåðèîäè÷åñêàÿ ïåðåäà÷à îòâåòà íå òðåáóåòñÿ
Mk_Ask1();
} // M_Stop
void M_Pulse(void) //e.============ generetion of the light-up pulse ========================= //r.============ ãåíåðàöèÿ èìïóëüñà çàïóñêà ëàçåðà =========================
{
pulse_Rq = 1; //e. set the flag of the GLD switch on request //r. óñòàíîâèòü ôëàã çàïðîñà ñòàðòà ÃËÄ
trm_cycl = 0; //e. periodic data transmission is not needed //r. ïåðèîäè÷åñêàÿ ïåðåäà÷à îòâåòà íå òðåáóåòñÿ
Mk_Ask1();
} // M_Pulse
void B_Rate(void) //e. === procedure of device operation in a mode of continuous output of raw data //r. === ïðîöåäóðà ðàáîòû ïðèáîðà â ðåæèìå íåïðåðûâíîé âûäà÷è "ñûðûõ" äàííûõ
{
} // B_Rate
void B_Delta(void) //e. === procedure not used //r. === ïðîöåäóðà íå èñïîëüçóåòñÿ
{
} // B_Delta
void D_Period_W(void) //e. === set the period of the angle increase output //r. === óñòàíîâêà ïåðèîäà âûäà÷è ïðèðàùåíèÿ óãëà
{
} // D_Period_W
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void exec_CMD(void) //e. === the final decoding and command execution procedure //r. === ïðîöåäóðà îêîí÷àòåëüíîé äåøèôðàöèè è èñïîëíåíèÿ êîìàíäû
{
uint32_t wcode;
rx_buf_copy = 1; //e. initialization of the flag of copying of receiving buffer //r. ïðåäóñòàíîâ ôëàãà êîïèðîâàíèÿ ïðèåìíîãî áóôåðà
wcode = (rcv_buf[2] & 0xFF) << 8;
CMD_Code = wcode | (rcv_buf[3] & 0xFF); //e. save it in the memory for echo-transmission //r. ñîõðàíèòü åãî â ïàìÿòè äëÿ îáðàòíîé ïåðåäà÷è
if (wcode == CMD_RATE) //e. is it Rate command? //r. ýòî êîìàíäà Rate?
{
B_Rate();
return;
}
else if (wcode == CMD_DEV_MODE) //e. is it the Device_Mode command? //r. ýòî êîìàíäà óñòàíîâêè ðåæèìà ïðèáîðà?
{
CMD_Mode = 3;
B_Dev_Mode();
return;
}
else if (wcode == CMD_DELTA_BINS) //e. is it the B_DeltaBINS command (command of request for data transfer to the navigation system)? //r. ýòî êîìàíäà çàïðîñà ïåðåäà÷è äàííûõ â íàâèã.ñèñòåìó?
{
RgConB = RATE_VIBRO_1; //e. set in the additional register of device control the mode of work with dither counters and the filter of moving average //r. óñòàíàâëèâàåì â äîïîëíèòåëüíîì ðåãèñòðå óïðàâëåíèÿ ðåæèì ðàáîòû ñ âèáðîñ÷åò÷èêàìè è ôèëüòðîì ñêîëüçÿùåãî ñðåäíåãî
SetSpeedPeriod();
UART_SwitchSpeed(trm_rate);
CMD_Mode = 4;
B_Delta_BINS();
return;
}
else if (wcode == CMD_DELTA_PS) //e. is it the B_DeltaPS command (command of request for data transfer to the uPC)? //r. ýòî êîìàíäà çàïðîñà ïåðåäà÷è äàííûõ â MkPC?
{
SetSpeedPeriod(); //e. and set the answer transfer rate and its periodicity //r. è óñòàíîâèòü ñêîðîñòü ïåðåäà÷è îòâåòà è åãî ïåðèîäè÷íîñòü (_trm_cycl)
UART_SwitchSpeed(trm_rate);
if (Device_Mode < 4) //e. work with internal latch
Device_Mode = DM_INT_LATCH_DELTA_PS;
else
Device_Mode = DM_EXT_LATCH_DELTA_PS_PULSE;
CMD_Mode = 1;
// B_Delta_PS();
return;
}
else if (wcode == CMD_DELTA_SF) // is it the B_DeltaSF command?
{
SetSpeedPeriod(); //e. and set the answer transfer rate and its periodicity //r. è óñòàíîâèòü ñêîðîñòü ïåðåäà÷è îòâåòà è åãî ïåðèîäè÷íîñòü (_trm_cycl)
CMD_Mode = 7;
if ((rcv_buf[3] & 0x0001) != 0) //e.reset of accumulated number is disabled //r. ñáðîñ íàêîïëåííîãî ìåæäó çàùåëêàìè ÷èñëà çàïðåùåí
Ext_Latch_ResetEnable = 0;
else
Ext_Latch_ResetEnable = 1;
B_Delta_SF();
return;
}
else if (wcode == CMD_BIT_MODE) //e. is this the BIT mode command? //r. ýòî êîìàíäà òåñòèðîâàíèÿ?
{
CMD_Mode = 6; //e. set the value of the Delta mode//r. óñòàíîâèòü çíà÷åíèå ðåæèìà Delta
B_BIT_Mode();
return;
}
else if (wcode == CMD_DELTA) //e. is this the B_Delta command? //r. ýòî êîìàíäà B_Delta?
{
CMD_Mode = 2; //e. set the value of the Delta mode//r. óñòàíîâèòü çíà÷åíèå ðåæèìà Delta
B_Delta(); //e. output calculated value of angle increase //r. âûâîäèòü âû÷èñëåííîå çíà÷åíèå ïðèðàùåíèÿ óãëà
return;
}
else if (CMD_Code == CMD_MAINT) //e. is this the Maintenance mode command? //r. ýòî êîìàíäà Maintenance mode?
{
if (!RgConB)
{
RgConB = RATE_VIBRO_1;
SwitchRefMeandInt(RATE_VIBRO_1); //e. disable interrupt from referense meander
}
CMD_Mode = 5; //e. yes, switch on present mode //r. äà, âêëþ÷èòü äàííûé ðåæèì
M_Status(); //e. output the status stack of registers //r. âûâåñòè ñòàòóñíûé íàáîð ðåãèñòðîâ
if (Device_Mode != DM_INT_10KHZ_LATCH) //e. mode of internal latch 10 kHz //r. ðåæèì âíóòðåííåé çàùåëêè 10 êÃö
{
Device_Mode = DM_INT_10KHZ_LATCH;
trm_ena = 0;
}
else
UART_SwitchSpeed(trm_rate);
return;
}
else if (wcode == SUBCMD_M_RESET) //e. is this subcommand for modification of the device control register? //r. ýòî ïîäêîìàíäà ìîäèôèêàöèè ðåãèñòðà óïðàâëåíèÿ ó-âà?
{
// Mk_AskDev();
M_Reset();
return;
}
else // subcommand analyse
{
if (CMD_Mode == 2) //e. is this the 2(Delta) mode? //r. ýòî ðåæèì 2? (Delta)
{
if (CMD_Code == CMD_D_PERIOD_W) //e. the Delta mode, check the subcommand ... //r. ðåæèì DElta, ïðîâåðèòü ïîäêîìàíäó çàãðóçêè ïåðèîäà
{
D_Period_W(); //e. otherwise - set the data transfer period //r. èíà÷å óñòàíîâèòèü ïåðèîä âûäà÷è äàííûõ
return;
}
else
{
line_sts = line_sts | CODE_ERR; // invalid command code
return;
}
}
else if (CMD_Mode == 5) //e. check the 5 mode (Maintenance) //r. ïðîâåðêà ðåæèìà 5 (Maintenance)
{
if (CMD_Code == SUBCMD_M_CLEAR) //e. is this subcommand of cleaning of the error register? //r. ýòî ïîäêîìàíäà î÷èñòêè ðåãèñòðà îøèáîê ëèíèè?
{
M_Clear(); //e. yes, cleaning the error register //r. äà, î÷èñòêà ðåãèñòðà îøèáîê
M_Status(); //e. preparing for trabsfer of the device status //r. ïîäãîòîâêà ïåðåäà÷è ñòàòóñà óñòðîéñòâà
UART_SwitchSpeed(trm_rate);
return;
}
else if (CMD_Code == SUBCMD_M_MIRR) //e. is this subcommand of return of previous command? //r. ýòî ïîäêîìàíäà âîçâðàòà ïðåäûäóùåé êîìàíäû?
{
rx_buf_copy = 0; //e. yes, forbid copying of command on saving previous //r. äà, çàïðåòèòü êîïèðîâàíèå êîìàíäû äëÿ ñîõðàíåíèÿ ïðåäûäóùåé
M_Mirror(); //e. prepare transfer of the receiving buffer copy //r. ïîäãîòîâèòü ïåðåäà÷ó êîïèè ïðèåìíîãî áóôåðà
return;
}
/* else if (wcode == SUBCMD_M_TMP_W) //e. is this subcommand for writing instructions to the AD7714? //r. ýòî ïîäêîìàíäà çàïèñè èíñòðóêöèé â AD7714?
{
// M_Tmp_W(); //e. yes, procedure call of write of the command //r. äà, âûçîâ ïðîöåäóðû çàïèñè êîìàíäû
return;
} */
else if (wcode == SUBCMD_M_TMP_R) //e. is this subcommand for data read from the AD7714? //r. ýòî ïîäêîìàíäà ÷òåíèÿ äàííûõ èç AD7714?
{
M_Tmp_R(); //r. yes, call the procedure for data read //e. äà, âûçîâ ïðîöåäóðû ÷òåíèÿ äàííûõ
return;
}
/* else if (wcode == SUBCMD_M_E5R_W) //e. is this subcommand for write to the mode register? //r. ýòî ïîäêîìàíäà çàïèñè â ðåãèñòð ðåæèìà?
{
M_e5r_W(); //e. yes, write data to the mode register of the Elio5 card //r. äà, çàïèñàòü äàííûå â ðåãèñòð ðåæèìà ïëàòû Elio5
return;
}
else if (wcode == SUBCMD_M_E5RA_W) //e. is this subcommand for write to the mode register? //r. ýòî ïîäêîìàíäà çàïèñè â ðåãèñòð ðåæèìà?
{
M_e5rA_W(); //e. yes, write data to the mode register of the Elio5 card //r. äà, çàïèñàòü äàííûå â ðåãèñòð ðåæèìà ïëàòû Elio5
return;
} */
else if (wcode == SUBCMD_M_ADC_R) //e. is t the subcommand for data read from ADCs ADS1250 and ADS8321 ? //r. ýòî ïîäêîìàíäà ÷òåíèÿ äàííûõ èç ÀÖÏ ADS1250 è ADS8321?
{
M_ADC_R(); //e. read of ADC channels //r. ÷òåíèå êàíàëîâ ÀÖÏ
return;
}
else if (wcode == SUBCMD_M_CNT_R) //e. is this subcommand of data read from pulse counters? //r. ýòî ïîäêîìàíäà ÷òåíèÿ äàííûõ èç ñ÷åò÷èêîâ èìïóëüñîâ?
{
M_Cnt_R(); //e. read of counters //r. ÷òåíèå ñ÷åò÷èêîâ
return;
}
else if (wcode == SUBCMD_M_FLG_R) //e. is it the command of data read about input flags? //r. ýòî ïîäêîìàíäà ÷òåíèÿ äàííûõ î âõîäíûõ ôëàãàõ?
{
M_Flg_R(); //e. read the input flags //r. ÷èòàòü âõîäíûå ôëàãè
return;
}
else if (wcode == SUBCMD_M_VIB_W) //e. is this subcommand for load the dither drive period? //r. ýòî ïîäêîìàíäà çàãðóçêè ïåðèîäà âèáðîïðèâîäà?
{
M_Vib_W(); //e. set the new value of the period //r. óñòàíîâèòü íîâîå çíà÷åíèå ïåðèîäà
return;
}
else if (wcode == SUBCMD_M_GPH_W) //e. is this subcommand for set the gain factor of photodetector channels? //r. ýòî ïîäêîìàíäà óñòàíîâêè óñèëåíèÿ êàíàëîâ ôîòîïðèåìíèêà ?
{
M_Gph_W(); //e. set the new values of gain factor //r. óñòàíîâèòü íîâûå çíà÷åíèÿ óñèëåíèÿ
return;
}
else if (wcode == SUBCMD_M_STIMUL) //e. is this subcommand for set the values of the DACs and flags? //r. ýòî ïîäêîìàíäà óñòàíîâêè çíà÷åíèÿ ÖÀÏîâ è ôäàãîâ ?
{
M_Stimul(); //e. set the new values //r. óñòàíîâèòü íîâûå çíà÷åíèÿ
return;
}
else if (wcode == SUBCMD_M_RATE) //e. is this subcommand for set the M_Rate output stack //r. ýòî ïîäêîìàíäà óñòàíîâêè âûäà÷è íàáîðà M_Rate ?
{
M_Rate(); //e. switch on the M_Rate data transfer //r. âêëþ÷èòü ïåðåäà÷ó äàííûõ M_Rate
return;
}
else if (wcode == SUBCMD_M_PARAM_W) //e. is this subcommand for write the new value of the GLD parameter ... //r. ýòî ïîäêîìàíäà çàïèñè íîâîãî çíà÷åíèÿ ïàðàìåòðà GLD
{
M_Param_W(); //e. write the new value of the parameter //r. çàïèñàòü íîâîå çíà÷åíèå ïàðàìåòðà
return;
}
else if (wcode == SUBCMD_M_PARAM_R) //e. is this subcommand for read the value of the GLD parameter? //r. ýòî ïîäêîìàíäà ÷òåíèÿ çíà÷åíèÿ ïàðàìåòðà GLD?
{
M_Param_R(); //e. read the value from the data memory //r. ñ÷èòàòü çíà÷åíèå ïàðàìåòðà èç ïàìÿòè äàíûõ
return;
}
else if (CMD_Code == SUBCMD_M_LDPAR_F) //e. is this subcommand for load GLD parameters ... //r. ýòî ïîäêîìàíäà çàãðóçêè ïàðàìåòðîâ GLD
{
M_LdPar_F(); //e. start the loading of parameters //r. çàïóñòèòü çàãðóçêó ïàðàìåòðîâ
return;
}
else if (CMD_Code == SUBCMD_M_LDPAR_D) //e. is this subcommand for direct setting of the GLD parameters ... //r. ýòî ïîäêîìàíäà ïðÿìîãî íàçíà÷åíèÿ ïàðàìåòðîâ GLD
{
M_LdPar_D(); //e. read the value of the parameter from the data memory //r. ñ÷èòàòü çíà÷åíèå ïàðàìåòðà èç ïàìÿòè äàíûõ
return;
}
else if (CMD_Code == SUBCMD_M_START) //e. is this subcommand for GLD starting? //r. ýòî ïîäêîìàíäà çàïóñêà GLD?
{
M_Start(); //e. call the procedure of start //r. çàïóñòèòü ïðîöåäóðó ñòàðòà
return;
}
else if (CMD_Code == SUBCMD_M_PULSE) //e. is this subcommand for GLD starting? //r. ýòî ïîäêîìàíäà çàïóñêà GLD?
{
M_Pulse(); //e. call light-up function //r. âûäàòü èìïóëüñ ïîäæèãà
return;
}
else if (CMD_Code == SUBCMD_M_STOP) //e. is this subcommand for GLD switch off? //r. ýòî ïîäêîìàíäà âûêëþ÷åíèÿ GLD?
{
M_Stop(); //e. otherwise- switch off all regulators and stop device //r. âûêëþ÷èòü âñå êîíòóðû è îñòàíîâèòü ïðèáîð
return;
}
else if (wcode == SUBCMD_M_CTL_R) //e. is this subcommand for read the device control register? //r. ýòî ïîäêîìàíäà ÷òåíèÿ ðåãèñòðà óïðàâëåíèÿ ó-âà?
{
M_Ctl_R();
return;
}
else if (wcode == SUBCMD_M_CTL_M) //e. is this subcommand for modification of the device control register? //r. ýòî ïîäêîìàíäà ìîäèôèêàöèè ðåãèñòðà óïðàâëåíèÿ ó-âà?
{
M_Ctl_M();
return;
}
/* else if (wcode == SUBCMD_M_RESET) //e. is this subcommand for modification of the device control register? //r. ýòî ïîäêîìàíäà ìîäèôèêàöèè ðåãèñòðà óïðàâëåíèÿ ó-âà?
{
M_Reset();
return;
}*/
else
{
line_sts = line_sts | MODE_ERR; // mode error
return;
}
}
}
} // exec_CMD
void decode_CMD(void)
{
int size;
if (!rcv_Rdy) //e. is data in receive buffer? //r. â ïðèåìíîì áóôåðå åñòü èíôîðìàöèÿ?
{
return; //e. if no, stop processing //r. åñëè íåò, çàêîí÷èòü îáðàáîòêó
}
if (!line_sts) //e. Whether there were errors of receiving of start-bit? //r. áûëè ëè îøèáêè ïðèåìà ñòàðò-áèòà ?
{
//e. there were not errors of receiving of bytes, check the device address //r. îøèáîê ïðèåìà áàéòîâ íå áûëî, ïðîâåðèòü àäðåñ îáðàùåíèÿ
//Is_Brodcast_Req = 0; //e. reset the flag of broadcasting request //r. ñáðîñèòü ôëàã øèðîêîâåùàòåëüíîãî çàïðîñà
if (rcv_buf[1] != Device_blk.Str.My_Addres)
{
if (rcv_buf[1] != BROADCAST_ADDRESS)
{
goto end;
}
}
if (rcv_buf[0] == COMMAND_PREFIX)
{ //e. there is new command in the receiver buffer, stop the transfer //r. â áóôåðå ïðèåìíèêà åñòü íîâàÿ êîìàíäà, ïðåêðàòèòü ïåðåäà÷ó
trm_ena = 0; //e. reset the flag of transmission allowing //r. ñáðîñèòü ôëàã ðàçðåøåíèÿ ïåðåäà÷è
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
exec_CMD(); // øåé êîìàíäû
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//e. check up presence of errors in operation of this procedure //r. ïðîâåðèòü, íàëè÷èå îøèáîê â ðàáîòå äàííîé ïîöåäóðû
//e. did is the "unknown code of a command" or "parameters were set incorrectly" error? //r. áûëà îøèáêà "íåèçâåñòíûé êîä êîìàíäû" èëè "íåâåðíî çàäàííûå ïàðàìåòðû"?
if ( ((line_sts & CODE_ERR) == CODE_ERR) || ((line_sts & PARAM_ERR) == PARAM_ERR) )
{
line_err = line_sts; //e. set error bits in the error register of the line //r. óñòàíîâèòü áèòû îøèáîê â ðåãèñòðå îøèáîê ëèíèè
}
}
else
{
line_err = line_sts | NO_CMD_ERR; // äîáàâëåíèå îøèáêè â ðåãèñòð îøèáîê
}
}
else
{
line_err = line_sts;
}
end:
if (rx_buf_copy) //e. is copying of present received packet needed? //r. òðåáóåòñÿ êîïèðîâàíèå äàííîãî ïðèíÿòîãî ïàêåòà?
{
size = rcv_num_byt;
rcv_byt_copy = rcv_num_byt; //e. save the size of copy //r. çàïîìíèòü ðàçìåð êîïèè
if (rcv_num_byt > sizeof(rcv_buf)) //e. compare the size of receiving buffer with amount of received bytes //r. êîïèðîâàíèå òðåáóåòñÿ, ñðàâíèòü ðàçìåð ïðèåìíîãî áóôåðà ñ ÷èñëîì ïðèíÿòûõ áàéò
{
size = sizeof(rcv_buf);
}
memcpy(rcv_copy, rcv_buf, size); //e. copy of received amount of bytes, but no more than buffer size //r. êîïèðîâàòü ïðèíÿòîå ÷èñëî áàéò, íî íå áîëåå ðàçìåðà áóôåðà
}
rx_buf_copy = 0; //e. reset the flag of necessity of copying of receiving buffer //r. ñáðîñèòü ôëàã íåîáõîäèìîñòè êîïèðîâàíèÿ ïðèåìíîãî áóôåðà
do
rcv_buf[--rcv_num_byt] = 0;
while(rcv_num_byt);
rcv_num_byt_old = rcv_num_byt;
line_sts = 0; //e. reset the line status register //r. ñáðîñèòü ðåãèñòð ñòàòóñà ëèíèè
rcv_Rdy = 0; //e. allow further data reception //r. ðàçðåøèòü äàëüíåéøèé ïðèåì äàííûõ
} // decode_CMD
