fork

Dependencies:   mbed

Fork of LG by igor Apu

Committer:
igor_v
Date:
Sat Jan 30 13:53:19 2016 +0000
Revision:
1:f2adcae3d304
Parent:
0:8ad47e2b6f00
Child:
7:078abbed4565
123

Who changed what in which revision?

UserRevisionLine numberNew contents of line
igor_v 1:f2adcae3d304 1 #include "Global.h"
igor_v 0:8ad47e2b6f00 2
igor_v 0:8ad47e2b6f00 3 #define COMMAND_DEBUG
igor_v 0:8ad47e2b6f00 4
igor_v 0:8ad47e2b6f00 5 uint32_t SRgR; //r. ��������� ������� ������ ����� ADSP
igor_v 0:8ad47e2b6f00 6
igor_v 0:8ad47e2b6f00 7 uint32_t RgConA; //r. �������� ������� ���������� ����������
igor_v 0:8ad47e2b6f00 8 uint32_t RgConB; //r. �������������� ������� ����������
igor_v 0:8ad47e2b6f00 9 //uint32_t Copy_e5_RgR; //r. ����� �������� ������ ����� E5
igor_v 0:8ad47e2b6f00 10 //uint32_t Copy_e5_RgRA; //r. ����� ��������������� �������� ������ E5
igor_v 0:8ad47e2b6f00 11
igor_v 0:8ad47e2b6f00 12 uint32_t Valid_Data; //r. ����-������� ����������� ������, ������������� ������ �� ������� �� �������
igor_v 0:8ad47e2b6f00 13
igor_v 0:8ad47e2b6f00 14 TDEVICE_BLK Device_blk; //e. union for device constants
igor_v 0:8ad47e2b6f00 15 uint32_t ser_num; //e. device serial number
igor_v 0:8ad47e2b6f00 16
igor_v 0:8ad47e2b6f00 17 int Device_Mode = DM_INT_10KHZ_LATCH; //r. ����� ������ ������� (�����.�������, �������� ������ ��� ������� �������)
igor_v 0:8ad47e2b6f00 18
igor_v 0:8ad47e2b6f00 19 void Sts_Pulse(void);
igor_v 0:8ad47e2b6f00 20 void Sts_Pause(void);
igor_v 0:8ad47e2b6f00 21 void Sts_Polling(void);
igor_v 0:8ad47e2b6f00 22
igor_v 0:8ad47e2b6f00 23 //r. ������� ��������� ��������� ������� �������
igor_v 0:8ad47e2b6f00 24 void (* Tab_Gld_Start[3])(void) = {Sts_Pulse, Sts_Pause, Sts_Polling};
igor_v 0:8ad47e2b6f00 25 //r. ������� ��������� ��������� ������� ������
igor_v 0:8ad47e2b6f00 26 void (* Tab_Gld_Pulse[1])(void) = {Sts_Pulse};
igor_v 0:8ad47e2b6f00 27
igor_v 0:8ad47e2b6f00 28 //e. stack of states of the procedure of starting //r. ���� ���������� ��������� ��������� �������
igor_v 0:8ad47e2b6f00 29 uint32_t Stk_Gld_Start[3] = {LIGHT_UP_PULSE_WDTH, LIGHT_UP_PAUSE, LIGHT_UP_POLLING};
igor_v 0:8ad47e2b6f00 30
igor_v 0:8ad47e2b6f00 31 uint32_t gyro_Sts = 0; //r. ������� ��������� �������
igor_v 0:8ad47e2b6f00 32 uint32_t start_Rq = 1; //r. ������ �� ������ �������
igor_v 0:8ad47e2b6f00 33 uint32_t start_Go = 0; //r. ��������� ������� �������
igor_v 0:8ad47e2b6f00 34 uint32_t stop_Rq = 0; //r. ������ �� ������� �������
igor_v 0:8ad47e2b6f00 35 uint32_t pulse_Rq = 0; //r. ������ �� ������ ������
igor_v 0:8ad47e2b6f00 36 uint32_t pulse_Go = 0; //r. ������� ������� �������
igor_v 0:8ad47e2b6f00 37
igor_v 0:8ad47e2b6f00 38 uint32_t state_index; //r. ������ ��������� ��������� (������)
igor_v 0:8ad47e2b6f00 39 uint32_t sts_work; //r. 1 - ������� ��������� - � ������� ����, 0 - �������������
igor_v 0:8ad47e2b6f00 40 uint32_t sts_time; //r. ������� ������� �������� ���������
igor_v 0:8ad47e2b6f00 41 uint32_t attempt_Str; //r. ������� ������� ������� �������
igor_v 0:8ad47e2b6f00 42
igor_v 0:8ad47e2b6f00 43
igor_v 0:8ad47e2b6f00 44 uint32_t BIT_number;
igor_v 0:8ad47e2b6f00 45 uint32_t Is_BIT = 0;
igor_v 0:8ad47e2b6f00 46
igor_v 0:8ad47e2b6f00 47 void GLD_Stop(void) //e.---------- procedure of GLD stopping -------------------------------------- //r.---------- ��������� �������� ��� --------------------------------------
igor_v 0:8ad47e2b6f00 48 {
igor_v 0:8ad47e2b6f00 49 if (!stop_Rq) //r. ��������� ������ �� ���������� �������
igor_v 0:8ad47e2b6f00 50 {
igor_v 0:8ad47e2b6f00 51 return; //r. ���� ���, �������
igor_v 0:8ad47e2b6f00 52 }
igor_v 0:8ad47e2b6f00 53
igor_v 0:8ad47e2b6f00 54 //r. �������� �����
igor_v 0:8ad47e2b6f00 55 start_Rq = 0; //r. ������� ���������,
igor_v 0:8ad47e2b6f00 56 start_Go = 0; //r. ���������� �������� ������� �������,
igor_v 0:8ad47e2b6f00 57 stop_Rq = 0; //r. ������� ��������
igor_v 0:8ad47e2b6f00 58 open_all_loops(); //r. ��������� ��� ������� �������������
igor_v 0:8ad47e2b6f00 59
igor_v 0:8ad47e2b6f00 60 gyro_Sts = 0; //r. ����� �������� ��������� ���������� ���
igor_v 0:8ad47e2b6f00 61
igor_v 0:8ad47e2b6f00 62 //r. ��������� �������� ����� �������� ���������� �����������
igor_v 0:8ad47e2b6f00 63 #if !defined COMMAND_DEBUG
igor_v 0:8ad47e2b6f00 64 disable_DACs();
igor_v 0:8ad47e2b6f00 65 #endif
igor_v 0:8ad47e2b6f00 66 } // GLD_Stop
igor_v 0:8ad47e2b6f00 67
igor_v 1:f2adcae3d304 68
igor_v 0:8ad47e2b6f00 69 void GLD_Status(void) //r.---------- ���������� �������� ���������� ��� --------------------------
igor_v 0:8ad47e2b6f00 70 {
igor_v 0:8ad47e2b6f00 71 static uint32_t Device_Mode_Old = DM_INT_10KHZ_LATCH/*DM_EXT_LATCH_DELTA_SF_PULSE*/;
igor_v 0:8ad47e2b6f00 72 if ( loop_is_closed(GLD_ON) == 0 )
igor_v 0:8ad47e2b6f00 73 {
igor_v 0:8ad47e2b6f00 74 open_all_loops();
igor_v 0:8ad47e2b6f00 75 GLD_Stop();
igor_v 0:8ad47e2b6f00 76 }
igor_v 0:8ad47e2b6f00 77 if (Device_Mode_Old != Device_Mode) //devi�e mode has been changed
igor_v 0:8ad47e2b6f00 78 {
igor_v 0:8ad47e2b6f00 79 if (SwitchMode()) //e. mode is changed successful
igor_v 0:8ad47e2b6f00 80 {
igor_v 0:8ad47e2b6f00 81 Device_Mode_Old = Device_Mode; //e. save current mode name
igor_v 0:8ad47e2b6f00 82 if (Device_Mode_Old == DM_INT_10KHZ_LATCH)
igor_v 0:8ad47e2b6f00 83 trm_ena = 1; //e. enable answer
igor_v 0:8ad47e2b6f00 84 }
igor_v 0:8ad47e2b6f00 85 }
igor_v 0:8ad47e2b6f00 86 } // GLD_Status
igor_v 0:8ad47e2b6f00 87
igor_v 1:f2adcae3d304 88
igor_v 0:8ad47e2b6f00 89 void Sts_Pause(void) //r.------- ��������� ��������� ����� --------------------------------------
igor_v 0:8ad47e2b6f00 90 {
igor_v 0:8ad47e2b6f00 91 if (sts_work) //r. ��������� � �������� ����?
igor_v 0:8ad47e2b6f00 92 {
igor_v 0:8ad47e2b6f00 93 sts_time--; //r. ��������� �������� ������� ���������
igor_v 0:8ad47e2b6f00 94 if (sts_time > 0)
igor_v 0:8ad47e2b6f00 95 {
igor_v 0:8ad47e2b6f00 96 return; //r. ���������� ������, ���� ������� �����������
igor_v 0:8ad47e2b6f00 97 }
igor_v 0:8ad47e2b6f00 98 //r. ����� ��������� ���������
igor_v 0:8ad47e2b6f00 99 sts_work = 0; //r. �������� ���� ����������
igor_v 0:8ad47e2b6f00 100 state_index++; //r. ����������� ��������� �� ��������� ���������
igor_v 0:8ad47e2b6f00 101 }
igor_v 0:8ad47e2b6f00 102 else
igor_v 0:8ad47e2b6f00 103 {
igor_v 0:8ad47e2b6f00 104 sts_time = Stk_Gld_Start[state_index]; //r. ����� ������� ���������
igor_v 0:8ad47e2b6f00 105 sts_work = 1; //r. ���������� ���� �������� ����
igor_v 0:8ad47e2b6f00 106 }
igor_v 0:8ad47e2b6f00 107 } // Sts_Pause
igor_v 0:8ad47e2b6f00 108
igor_v 0:8ad47e2b6f00 109 void Sts_Pulse() //r. ------- ��������� ��������� �������� ������� --------------------------
igor_v 0:8ad47e2b6f00 110 {
igor_v 0:8ad47e2b6f00 111 if (sts_work) //r. ��������� � �������� ����?
igor_v 0:8ad47e2b6f00 112 {
igor_v 0:8ad47e2b6f00 113 sts_time--; //r. ��������� �������� ������� ���������
igor_v 0:8ad47e2b6f00 114 if (sts_time > 0)
igor_v 0:8ad47e2b6f00 115 {
igor_v 0:8ad47e2b6f00 116 return; //r. ���������� ������, ���� ������� �����������
igor_v 0:8ad47e2b6f00 117 }
igor_v 0:8ad47e2b6f00 118 //r. ����� ��������� ���������
igor_v 0:8ad47e2b6f00 119 sts_work = 0; //r. �������� ���� ����������
igor_v 0:8ad47e2b6f00 120 state_index++; //r. ����������� ��������� �� ��������� ���������
igor_v 0:8ad47e2b6f00 121
igor_v 0:8ad47e2b6f00 122 Set_LightUp; //r. ����� ������ ������� ������
igor_v 0:8ad47e2b6f00 123
igor_v 0:8ad47e2b6f00 124 }
igor_v 0:8ad47e2b6f00 125 else
igor_v 0:8ad47e2b6f00 126 {
igor_v 0:8ad47e2b6f00 127 sts_time = Stk_Gld_Start[state_index]; //r. ����� ������� ���������
igor_v 0:8ad47e2b6f00 128 sts_work = 1; //r. ���������� ���� �������� ����
igor_v 0:8ad47e2b6f00 129
igor_v 0:8ad47e2b6f00 130 Reset_LightUp; //r. ������������ ������ ������� ������
igor_v 0:8ad47e2b6f00 131
igor_v 0:8ad47e2b6f00 132 }
igor_v 0:8ad47e2b6f00 133 } // Sts_Pulse
igor_v 0:8ad47e2b6f00 134
igor_v 0:8ad47e2b6f00 135 void Sts_Polling(void) //r.========== ��������� ��������� ��������� � �������� ������� � �������
igor_v 0:8ad47e2b6f00 136 {
igor_v 0:8ad47e2b6f00 137 static int32_t Sum_F_ras = 0; //r. ������������ ����� ����������� ��� ��������� ������
igor_v 0:8ad47e2b6f00 138
igor_v 0:8ad47e2b6f00 139 if (sts_work) //r. ��������� � �������� ����?
igor_v 0:8ad47e2b6f00 140 {
igor_v 0:8ad47e2b6f00 141 if (Dif_Curr_Vib >0)
igor_v 0:8ad47e2b6f00 142 Sum_F_ras = L_add(Sum_F_ras, Dif_Curr_Vib);
igor_v 0:8ad47e2b6f00 143 else
igor_v 0:8ad47e2b6f00 144 Sum_F_ras = L_sub(Sum_F_ras, Dif_Curr_Vib);
igor_v 0:8ad47e2b6f00 145
igor_v 0:8ad47e2b6f00 146 //r. ���, ���������� ���������� ����� �����������
igor_v 0:8ad47e2b6f00 147 sts_time--; //r. ��������� �������� ������� ���������
igor_v 0:8ad47e2b6f00 148 if (sts_time > 0)
igor_v 0:8ad47e2b6f00 149 {
igor_v 0:8ad47e2b6f00 150 return; //r. ���������� ������, ���� ������� �����������
igor_v 0:8ad47e2b6f00 151 }
igor_v 0:8ad47e2b6f00 152 //r. ����� ��������� ���������
igor_v 0:8ad47e2b6f00 153 sts_work = 0; //r. �������� ���� ����������
igor_v 0:8ad47e2b6f00 154 state_index++; //r. ����������� ��������� �� ��������� ���������
igor_v 0:8ad47e2b6f00 155 //r. ��������� ������� ���������
igor_v 0:8ad47e2b6f00 156 if ( Sum_F_ras >= F_RAS_MIN) //e. //r. F_RAS_MIN = 10000 ??? ��� ��� �� �������???
igor_v 0:8ad47e2b6f00 157 {
igor_v 0:8ad47e2b6f00 158 gyro_Sts |= LASER_ON; //r. ����� ����� ���������, �������� � �������� ���������
igor_v 0:8ad47e2b6f00 159 return; //r. ������� � ��������� �������
igor_v 0:8ad47e2b6f00 160 }
igor_v 0:8ad47e2b6f00 161 //r. ���� ��� ������, ��������� ���
igor_v 0:8ad47e2b6f00 162 attempt_Str--; //r. ��������� �������� ������� ������� ������
igor_v 0:8ad47e2b6f00 163 if (attempt_Str <= 0)
igor_v 0:8ad47e2b6f00 164 {
igor_v 0:8ad47e2b6f00 165 return; //r. ���� ������� ���������, ��������� �������
igor_v 0:8ad47e2b6f00 166 }
igor_v 0:8ad47e2b6f00 167 //r. ����� ���������� ��������� ��������� ��
igor_v 0:8ad47e2b6f00 168 state_index = 0; //r. ������ �������� ������� ��� ��������� �������
igor_v 0:8ad47e2b6f00 169 }
igor_v 0:8ad47e2b6f00 170 else
igor_v 0:8ad47e2b6f00 171 {
igor_v 0:8ad47e2b6f00 172 sts_time = Stk_Gld_Start[state_index]; //r. ����� ������� ���������
igor_v 0:8ad47e2b6f00 173 sts_work = 1; //r. ���������� ���� �������� ����
igor_v 0:8ad47e2b6f00 174 Sum_F_ras = 0; //r. ��������� ������������ ����� �����������
igor_v 0:8ad47e2b6f00 175 }
igor_v 0:8ad47e2b6f00 176
igor_v 0:8ad47e2b6f00 177 } // Sts_Polling
igor_v 0:8ad47e2b6f00 178
igor_v 0:8ad47e2b6f00 179
igor_v 0:8ad47e2b6f00 180 //r.---------- ������� ������� ������� -------------------------------------
igor_v 0:8ad47e2b6f00 181 void GLD_Start(void)
igor_v 0:8ad47e2b6f00 182 {
igor_v 0:8ad47e2b6f00 183 if (!start_Rq) //r. ��������� ��������� ������� �� ������ �������
igor_v 0:8ad47e2b6f00 184 {
igor_v 0:8ad47e2b6f00 185 return; //r. ������� ���, �������
igor_v 0:8ad47e2b6f00 186 }
igor_v 0:8ad47e2b6f00 187
igor_v 0:8ad47e2b6f00 188 if (!start_Go) //r. ������� ������� ��� �� ��� �������?
igor_v 0:8ad47e2b6f00 189 {
igor_v 0:8ad47e2b6f00 190 //r. ��� ������ �������
igor_v 0:8ad47e2b6f00 191 attempt_Str = N_START_MAX; //r. ���������� ������������ ����� ������� �������
igor_v 0:8ad47e2b6f00 192 //r. ���������� ������� �����������
igor_v 0:8ad47e2b6f00 193 //open_loop(VB_FREQ_ON | VB_TAU_ON | WP_REG_ON | HF_REG_ON); // 0xff95
igor_v 0:8ad47e2b6f00 194 //close_all_loops();
igor_v 0:8ad47e2b6f00 195
igor_v 0:8ad47e2b6f00 196 sts_work = 0; //r. �������� ���� �������� ���� ���������
igor_v 0:8ad47e2b6f00 197 state_index= 0; //r. ���������� ��������� ��������� � ��������� ���������
igor_v 0:8ad47e2b6f00 198 start_Go = 1; //r. ������� ������ �������
igor_v 0:8ad47e2b6f00 199 }
igor_v 0:8ad47e2b6f00 200
igor_v 0:8ad47e2b6f00 201 ( *Tab_Gld_Start[state_index] )(); //r. ����� ��������� ��������� �� ������ � �������
igor_v 0:8ad47e2b6f00 202
igor_v 0:8ad47e2b6f00 203 if (sts_work) //r. ������� ��������� ��������?
igor_v 0:8ad47e2b6f00 204 {
igor_v 0:8ad47e2b6f00 205 return; //r. ���������� ��������
igor_v 0:8ad47e2b6f00 206 }
igor_v 0:8ad47e2b6f00 207 //r. ��������� ����������� ��������� ��������� ���������
igor_v 0:8ad47e2b6f00 208 if ( state_index >= 3 )
igor_v 0:8ad47e2b6f00 209 {
igor_v 0:8ad47e2b6f00 210 //r. ��������� ��������
igor_v 0:8ad47e2b6f00 211 //r. �������� �����
igor_v 0:8ad47e2b6f00 212 start_Rq = 0; //r. �������
igor_v 0:8ad47e2b6f00 213 start_Go = 0; //r. � ���������� ��������
igor_v 0:8ad47e2b6f00 214 #if !defined COMMAND_DEBUG
igor_v 0:8ad47e2b6f00 215 Out_G_photo(Device_blk.Str.Gain_Ph_A, Device_blk.Str.Gain_Ph_B); //r. �������� ���������������� ����-�� �������� ��������������
igor_v 0:8ad47e2b6f00 216 #endif
igor_v 0:8ad47e2b6f00 217 // close_all_loops();
igor_v 0:8ad47e2b6f00 218
igor_v 0:8ad47e2b6f00 219 }
igor_v 0:8ad47e2b6f00 220
igor_v 0:8ad47e2b6f00 221 } // GLD_Start
igor_v 0:8ad47e2b6f00 222
igor_v 0:8ad47e2b6f00 223 void GLD_Pulse(void) //r.---------- ������� ������� ������ --------------------------------------
igor_v 0:8ad47e2b6f00 224 {
igor_v 0:8ad47e2b6f00 225 if (!pulse_Rq) //r. ��������� ��������� ������� �� ������ ������
igor_v 0:8ad47e2b6f00 226 {
igor_v 0:8ad47e2b6f00 227 return; //r. ������� ���, �������
igor_v 0:8ad47e2b6f00 228 }
igor_v 0:8ad47e2b6f00 229
igor_v 0:8ad47e2b6f00 230 if (!pulse_Go) //r. ������� ������� ��� �� ��� �������?
igor_v 0:8ad47e2b6f00 231 {
igor_v 0:8ad47e2b6f00 232 sts_work = 0; //r. �������� ���� �������� ���� ���������
igor_v 0:8ad47e2b6f00 233 state_index = 0; //r. ���������� ��������� ��������� � ��������� ���������
igor_v 0:8ad47e2b6f00 234 pulse_Go = 1; //r. ������� ������ �������
igor_v 0:8ad47e2b6f00 235 }
igor_v 0:8ad47e2b6f00 236
igor_v 0:8ad47e2b6f00 237 ( *Tab_Gld_Pulse[state_index] )(); //r. ����� ��������� ��������� �� ������ � �������
igor_v 0:8ad47e2b6f00 238
igor_v 0:8ad47e2b6f00 239 if (sts_work) //r. ������� ��������� ��������?
igor_v 0:8ad47e2b6f00 240 {
igor_v 0:8ad47e2b6f00 241 return; //r. ���������� ��������
igor_v 0:8ad47e2b6f00 242 }
igor_v 0:8ad47e2b6f00 243
igor_v 0:8ad47e2b6f00 244 if ( state_index >= 1 )
igor_v 0:8ad47e2b6f00 245 {
igor_v 0:8ad47e2b6f00 246 //r. �������� �����
igor_v 0:8ad47e2b6f00 247 pulse_Rq = 0; //r. �������
igor_v 0:8ad47e2b6f00 248 pulse_Go = 0; //r. � ���������� ��������
igor_v 0:8ad47e2b6f00 249 }
igor_v 0:8ad47e2b6f00 250
igor_v 0:8ad47e2b6f00 251 } // GLD_Pulse
igor_v 0:8ad47e2b6f00 252
igor_v 0:8ad47e2b6f00 253 void contrl_GLD(void) //r.========== ��������� ���������� �������� ===============================
igor_v 0:8ad47e2b6f00 254 {
igor_v 0:8ad47e2b6f00 255 GLD_Start(); //r. ��������� ������, ���� ���� ������
igor_v 0:8ad47e2b6f00 256 GLD_Status(); //r. �������� ��������� �������
igor_v 0:8ad47e2b6f00 257 GLD_Stop(); //r. ���������� ������, ���� ����������
igor_v 0:8ad47e2b6f00 258 GLD_Pulse(); //r. ��������� �������� ������� ��� ������� �������
igor_v 0:8ad47e2b6f00 259 GLD_Output(); //r. ������ ������ ������ �� ���������
igor_v 0:8ad47e2b6f00 260 } // contrl_GLD
igor_v 0:8ad47e2b6f00 261
igor_v 0:8ad47e2b6f00 262