![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
n
Fork of LG by
Command.c@0:8ad47e2b6f00, 2016-01-30 (annotated)
- Committer:
- igor_v
- Date:
- Sat Jan 30 13:00:39 2016 +0000
- Revision:
- 0:8ad47e2b6f00
- Child:
- 17:44b2801ac94b
- Child:
- 21:bc8c1cec3da6
2016_01_30;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
igor_v | 0:8ad47e2b6f00 | 1 | #include "stdlib.h" |
igor_v | 0:8ad47e2b6f00 | 2 | #include "LPC17xx.h" |
igor_v | 0:8ad47e2b6f00 | 3 | #include "Command.h" |
igor_v | 0:8ad47e2b6f00 | 4 | #include "el_lin.h" |
igor_v | 0:8ad47e2b6f00 | 5 | #include "vibro.h" |
igor_v | 0:8ad47e2b6f00 | 6 | #include "Global.h" |
igor_v | 0:8ad47e2b6f00 | 7 | #include "uart_m.h" |
igor_v | 0:8ad47e2b6f00 | 8 | #include "CntrlGLD.h" |
igor_v | 0:8ad47e2b6f00 | 9 | #include "QEI.h" |
igor_v | 0:8ad47e2b6f00 | 10 | #include "InputOutput.h" |
igor_v | 0:8ad47e2b6f00 | 11 | #include "SPI.h" |
igor_v | 0:8ad47e2b6f00 | 12 | unsigned int Rate_Flag; |
igor_v | 0:8ad47e2b6f00 | 13 | unsigned int PC_Comand; |
igor_v | 0:8ad47e2b6f00 | 14 | unsigned int n; |
igor_v | 0:8ad47e2b6f00 | 15 | unsigned int CountBuFFIn; |
igor_v | 0:8ad47e2b6f00 | 16 | unsigned int ParamIn; |
igor_v | 0:8ad47e2b6f00 | 17 | unsigned int Err; |
igor_v | 0:8ad47e2b6f00 | 18 | unsigned int N=0,CRC_N; |
igor_v | 0:8ad47e2b6f00 | 19 | unsigned int Param1=0; |
igor_v | 0:8ad47e2b6f00 | 20 | unsigned int Param2=0; |
igor_v | 0:8ad47e2b6f00 | 21 | unsigned int Param3=0; |
igor_v | 0:8ad47e2b6f00 | 22 | unsigned int Param4=0; |
igor_v | 0:8ad47e2b6f00 | 23 | |
igor_v | 0:8ad47e2b6f00 | 24 | /* |
igor_v | 0:8ad47e2b6f00 | 25 | void exec_CMD(void) //r. === ��������� ������������� ���������� � ���������� ������� |
igor_v | 0:8ad47e2b6f00 | 26 | { |
igor_v | 0:8ad47e2b6f00 | 27 | unsigned int Comand_code; |
igor_v | 0:8ad47e2b6f00 | 28 | |
igor_v | 0:8ad47e2b6f00 | 29 | //rx_buf_copy = 1; //r. ����������� ����� ����������� ��������� ������ |
igor_v | 0:8ad47e2b6f00 | 30 | |
igor_v | 0:8ad47e2b6f00 | 31 | Comand_code = (rcv_buf[2] & 0xFF) << 8; |
igor_v | 0:8ad47e2b6f00 | 32 | PC_Comand = Comand_code | (rcv_buf[3] & 0xFF); //e. save it in the memory for echo-transmission //r. ��������� ��� � ������ ��� �������� �������� |
igor_v | 0:8ad47e2b6f00 | 33 | }*/ |
igor_v | 0:8ad47e2b6f00 | 34 | void CMD_Maintenance(void) |
igor_v | 0:8ad47e2b6f00 | 35 | { |
igor_v | 0:8ad47e2b6f00 | 36 | BuffTemp[0] = Main.SOC_Out; |
igor_v | 0:8ad47e2b6f00 | 37 | BuffTemp[1] = Main.My_Addres; |
igor_v | 0:8ad47e2b6f00 | 38 | BuffTemp[2] = Main.Firmware_Version; |
igor_v | 0:8ad47e2b6f00 | 39 | BuffTemp[3] = Main.GLD_Serial; |
igor_v | 0:8ad47e2b6f00 | 40 | BuffTemp[4]=0x00; |
igor_v | 0:8ad47e2b6f00 | 41 | BuffTemp[5]=0x00; |
igor_v | 0:8ad47e2b6f00 | 42 | Check(BuffTemp, 8); |
igor_v | 0:8ad47e2b6f00 | 43 | WriteConN (BuffTemp,8); |
igor_v | 0:8ad47e2b6f00 | 44 | } |
igor_v | 0:8ad47e2b6f00 | 45 | |
igor_v | 0:8ad47e2b6f00 | 46 | void CMD_Rate(void) |
igor_v | 0:8ad47e2b6f00 | 47 | { |
igor_v | 0:8ad47e2b6f00 | 48 | |
igor_v | 0:8ad47e2b6f00 | 49 | unsigned int T_VibH , T_VibL; // ������� ������������. |
igor_v | 0:8ad47e2b6f00 | 50 | unsigned int Cnt_PlsL , Cnt_PlsH; // ������� +. |
igor_v | 0:8ad47e2b6f00 | 51 | unsigned int Cnt_MnsL , Cnt_MnsH; // ������� -. |
igor_v | 0:8ad47e2b6f00 | 52 | unsigned int Cnt_DifL , Cnt_DifH; // �������� ���������. |
igor_v | 0:8ad47e2b6f00 | 53 | unsigned int F_rasL , F_rasH; // ������� �����������. |
igor_v | 0:8ad47e2b6f00 | 54 | |
igor_v | 0:8ad47e2b6f00 | 55 | unsigned int HF_regL , HF_regH; // ����� ���������� ���. �� ������� |
igor_v | 0:8ad47e2b6f00 | 56 | unsigned int HF_difL , HF_difH; // ������ ������ ����������� ���. �� ������� |
igor_v | 0:8ad47e2b6f00 | 57 | |
igor_v | 0:8ad47e2b6f00 | 58 | unsigned int WP_regL , WP_regH; |
igor_v | 0:8ad47e2b6f00 | 59 | |
igor_v | 0:8ad47e2b6f00 | 60 | unsigned int ADC1L, ADC2L, ADC3L, ADC4L, ADC5L; |
igor_v | 0:8ad47e2b6f00 | 61 | unsigned int ADC1H, ADC2H, ADC3H, ADC4H, ADC5H; |
igor_v | 0:8ad47e2b6f00 | 62 | |
igor_v | 0:8ad47e2b6f00 | 63 | |
igor_v | 0:8ad47e2b6f00 | 64 | LoopOn |
igor_v | 0:8ad47e2b6f00 | 65 | // Main.T_Vib=(unsigned int)((7680000*16/Main.Frq)*4096); |
igor_v | 0:8ad47e2b6f00 | 66 | Main.T_Vib=(unsigned int)((7680000*16/(Main.Frq>>12))); |
igor_v | 0:8ad47e2b6f00 | 67 | Main.Firmware_Version=0xff; /// ������������� ������� |
igor_v | 0:8ad47e2b6f00 | 68 | |
igor_v | 0:8ad47e2b6f00 | 69 | T_VibH = ( Main.T_Vib>>8 ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 70 | T_VibL = ( Main.T_Vib ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 71 | |
igor_v | 0:8ad47e2b6f00 | 72 | Cnt_PlsH = ( Main.Cnt_Pls>>8) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 73 | Cnt_PlsL = ( Main.Cnt_Pls ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 74 | |
igor_v | 0:8ad47e2b6f00 | 75 | Cnt_MnsH = ( Main.Cnt_Mns>>8) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 76 | Cnt_MnsL = ( Main.Cnt_Mns ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 77 | |
igor_v | 0:8ad47e2b6f00 | 78 | Cnt_DifH = ( Main.Cnt_Dif>>8) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 79 | Cnt_DifL = ( Main.Cnt_Dif ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 80 | |
igor_v | 0:8ad47e2b6f00 | 81 | F_rasH = ( Main.F_ras>>8 ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 82 | F_rasL = ( Main.F_ras ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 83 | |
igor_v | 0:8ad47e2b6f00 | 84 | ADC1H = ( Spi.ADC1>>8 ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 85 | ADC1L = ( Spi.ADC1 ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 86 | |
igor_v | 0:8ad47e2b6f00 | 87 | ADC2H = ( Spi.ADC2>>8 ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 88 | ADC2L = ( Spi.ADC2 ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 89 | |
igor_v | 0:8ad47e2b6f00 | 90 | ADC3H = ( Spi.ADC3>>8 ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 91 | ADC3L = ( Spi.ADC3 ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 92 | |
igor_v | 0:8ad47e2b6f00 | 93 | ADC4H = ( Spi.ADC4>>8 ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 94 | ADC4L = ( Spi.ADC4 ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 95 | |
igor_v | 0:8ad47e2b6f00 | 96 | ADC5H = ( Spi.ADC5>>8 ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 97 | ADC5L = ( Spi.ADC5 ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 98 | |
igor_v | 0:8ad47e2b6f00 | 99 | WP_regH = ( Spi.DAC_B>>8 ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 100 | WP_regL = ( Spi.DAC_B ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 101 | |
igor_v | 0:8ad47e2b6f00 | 102 | HF_regH=0xff; |
igor_v | 0:8ad47e2b6f00 | 103 | HF_regL=0xff; |
igor_v | 0:8ad47e2b6f00 | 104 | |
igor_v | 0:8ad47e2b6f00 | 105 | HF_difH=0xff; |
igor_v | 0:8ad47e2b6f00 | 106 | HF_difL=0xff; |
igor_v | 0:8ad47e2b6f00 | 107 | |
igor_v | 0:8ad47e2b6f00 | 108 | |
igor_v | 0:8ad47e2b6f00 | 109 | BuffTemp[ 0] = Main.SOC_Out; |
igor_v | 0:8ad47e2b6f00 | 110 | BuffTemp[ 1] = Main.My_Addres; |
igor_v | 0:8ad47e2b6f00 | 111 | |
igor_v | 0:8ad47e2b6f00 | 112 | BuffTemp[ 2] = Cnt_PlsH;//������� ���� �������� +. |
igor_v | 0:8ad47e2b6f00 | 113 | BuffTemp[ 3] = Cnt_PlsL;//������� ���� �������� +. |
igor_v | 0:8ad47e2b6f00 | 114 | |
igor_v | 0:8ad47e2b6f00 | 115 | BuffTemp[ 4] = Cnt_MnsH;//������� ���� �������� -. |
igor_v | 0:8ad47e2b6f00 | 116 | BuffTemp[ 5] = Cnt_MnsL;//������� ���� �������� -. |
igor_v | 0:8ad47e2b6f00 | 117 | |
igor_v | 0:8ad47e2b6f00 | 118 | BuffTemp[ 6] = Cnt_DifH;//������� ���� �������� ��������� |
igor_v | 0:8ad47e2b6f00 | 119 | BuffTemp[ 7] = Cnt_DifL;//������� ���� �������� ��������� |
igor_v | 0:8ad47e2b6f00 | 120 | |
igor_v | 0:8ad47e2b6f00 | 121 | BuffTemp[ 8] = F_rasH; |
igor_v | 0:8ad47e2b6f00 | 122 | BuffTemp[ 9] = F_rasL; |
igor_v | 0:8ad47e2b6f00 | 123 | |
igor_v | 0:8ad47e2b6f00 | 124 | BuffTemp[10] = HF_regH; |
igor_v | 0:8ad47e2b6f00 | 125 | BuffTemp[11] = HF_regL; |
igor_v | 0:8ad47e2b6f00 | 126 | |
igor_v | 0:8ad47e2b6f00 | 127 | BuffTemp[12] = HF_difH; |
igor_v | 0:8ad47e2b6f00 | 128 | BuffTemp[13] = HF_difL; |
igor_v | 0:8ad47e2b6f00 | 129 | |
igor_v | 0:8ad47e2b6f00 | 130 | BuffTemp[14] = T_VibH ;// |
igor_v | 0:8ad47e2b6f00 | 131 | BuffTemp[15] = T_VibL; //? |
igor_v | 0:8ad47e2b6f00 | 132 | |
igor_v | 0:8ad47e2b6f00 | 133 | BuffTemp[16] = Main.Firmware_Version;//�� |
igor_v | 0:8ad47e2b6f00 | 134 | BuffTemp[17] = Main.Firmware_Version;//�� |
igor_v | 0:8ad47e2b6f00 | 135 | |
igor_v | 0:8ad47e2b6f00 | 136 | BuffTemp[18] = T_VibH>>1; |
igor_v | 0:8ad47e2b6f00 | 137 | BuffTemp[19] = T_VibL; |
igor_v | 0:8ad47e2b6f00 | 138 | |
igor_v | 0:8ad47e2b6f00 | 139 | BuffTemp[20] = Main.Firmware_Version;//�� |
igor_v | 0:8ad47e2b6f00 | 140 | BuffTemp[21] = Main.Firmware_Version;//�� |
igor_v | 0:8ad47e2b6f00 | 141 | |
igor_v | 0:8ad47e2b6f00 | 142 | BuffTemp[22] = WP_regH; //��� Spi.DAC_B |
igor_v | 0:8ad47e2b6f00 | 143 | BuffTemp[23] = WP_regL; //��� |
igor_v | 0:8ad47e2b6f00 | 144 | |
igor_v | 0:8ad47e2b6f00 | 145 | BuffTemp[24] = Main.Firmware_Version;// �� |
igor_v | 0:8ad47e2b6f00 | 146 | BuffTemp[25] = Main.Firmware_Version;// �� |
igor_v | 0:8ad47e2b6f00 | 147 | |
igor_v | 0:8ad47e2b6f00 | 148 | BuffTemp[26] = ADC1H; |
igor_v | 0:8ad47e2b6f00 | 149 | BuffTemp[27] = ADC1L; |
igor_v | 0:8ad47e2b6f00 | 150 | |
igor_v | 0:8ad47e2b6f00 | 151 | BuffTemp[28] = ADC1H; |
igor_v | 0:8ad47e2b6f00 | 152 | BuffTemp[29] = ADC1L; |
igor_v | 0:8ad47e2b6f00 | 153 | |
igor_v | 0:8ad47e2b6f00 | 154 | BuffTemp[30] = ADC1H; |
igor_v | 0:8ad47e2b6f00 | 155 | BuffTemp[31] = ADC1L; |
igor_v | 0:8ad47e2b6f00 | 156 | |
igor_v | 0:8ad47e2b6f00 | 157 | BuffTemp[32] = ADC1H; |
igor_v | 0:8ad47e2b6f00 | 158 | BuffTemp[33] = ADC1L; |
igor_v | 0:8ad47e2b6f00 | 159 | |
igor_v | 0:8ad47e2b6f00 | 160 | BuffTemp[34] = ADC1H; |
igor_v | 0:8ad47e2b6f00 | 161 | BuffTemp[35] = ADC1L; |
igor_v | 0:8ad47e2b6f00 | 162 | |
igor_v | 0:8ad47e2b6f00 | 163 | BuffTemp[36] = 0x00;//ADC6 |
igor_v | 0:8ad47e2b6f00 | 164 | BuffTemp[37] = 0x00;//ADC6 |
igor_v | 0:8ad47e2b6f00 | 165 | |
igor_v | 0:8ad47e2b6f00 | 166 | BuffTemp[38] = Main.Firmware_Version; |
igor_v | 0:8ad47e2b6f00 | 167 | BuffTemp[39] = Main.Firmware_Version; |
igor_v | 0:8ad47e2b6f00 | 168 | BuffTemp[40] = Main.Firmware_Version; |
igor_v | 0:8ad47e2b6f00 | 169 | BuffTemp[41] = Main.Firmware_Version; |
igor_v | 0:8ad47e2b6f00 | 170 | |
igor_v | 0:8ad47e2b6f00 | 171 | |
igor_v | 0:8ad47e2b6f00 | 172 | Check(BuffTemp, 44); |
igor_v | 0:8ad47e2b6f00 | 173 | WriteConN (BuffTemp,44); |
igor_v | 0:8ad47e2b6f00 | 174 | LoopOff |
igor_v | 0:8ad47e2b6f00 | 175 | } |
igor_v | 0:8ad47e2b6f00 | 176 | |
igor_v | 0:8ad47e2b6f00 | 177 | void CMD_M_Control_D8()///���������\����� ��������� ���������� |
igor_v | 0:8ad47e2b6f00 | 178 | { |
igor_v | 0:8ad47e2b6f00 | 179 | int bit,NReg; |
igor_v | 0:8ad47e2b6f00 | 180 | BuffTemp[0] = Main.SOC_Out; //DD |
igor_v | 0:8ad47e2b6f00 | 181 | BuffTemp[1] = Main.My_Addres; //00 |
igor_v | 0:8ad47e2b6f00 | 182 | BuffTemp[2] = Main.CMD_In; //D8 |
igor_v | 0:8ad47e2b6f00 | 183 | //10? |
igor_v | 0:8ad47e2b6f00 | 184 | if((Param1&0x80)) |
igor_v | 0:8ad47e2b6f00 | 185 | { |
igor_v | 0:8ad47e2b6f00 | 186 | bit=1; |
igor_v | 0:8ad47e2b6f00 | 187 | } |
igor_v | 0:8ad47e2b6f00 | 188 | else |
igor_v | 0:8ad47e2b6f00 | 189 | { |
igor_v | 0:8ad47e2b6f00 | 190 | bit=0; |
igor_v | 0:8ad47e2b6f00 | 191 | } |
igor_v | 0:8ad47e2b6f00 | 192 | |
igor_v | 0:8ad47e2b6f00 | 193 | if ((Param1 & 0x10) == 0) |
igor_v | 0:8ad47e2b6f00 | 194 | { |
igor_v | 0:8ad47e2b6f00 | 195 | NReg=0; |
igor_v | 0:8ad47e2b6f00 | 196 | switch(Param1&0xf) // Main.RgConA |
igor_v | 0:8ad47e2b6f00 | 197 | { |
igor_v | 0:8ad47e2b6f00 | 198 | case 0x0: |
igor_v | 0:8ad47e2b6f00 | 199 | Main.RgConA|=bit; |
igor_v | 0:8ad47e2b6f00 | 200 | break; |
igor_v | 0:8ad47e2b6f00 | 201 | |
igor_v | 0:8ad47e2b6f00 | 202 | case 0x1: |
igor_v | 0:8ad47e2b6f00 | 203 | Main.RgConA|=bit<<0x1; |
igor_v | 0:8ad47e2b6f00 | 204 | break; |
igor_v | 0:8ad47e2b6f00 | 205 | |
igor_v | 0:8ad47e2b6f00 | 206 | case 0x2: |
igor_v | 0:8ad47e2b6f00 | 207 | Main.RgConA|=bit<<0x2; |
igor_v | 0:8ad47e2b6f00 | 208 | break; |
igor_v | 0:8ad47e2b6f00 | 209 | |
igor_v | 0:8ad47e2b6f00 | 210 | case 0x3: |
igor_v | 0:8ad47e2b6f00 | 211 | Main.RgConA|=bit<<0x3; |
igor_v | 0:8ad47e2b6f00 | 212 | break; |
igor_v | 0:8ad47e2b6f00 | 213 | |
igor_v | 0:8ad47e2b6f00 | 214 | case 0x4: |
igor_v | 0:8ad47e2b6f00 | 215 | Main.RgConA|=bit<<0x4; |
igor_v | 0:8ad47e2b6f00 | 216 | break; |
igor_v | 0:8ad47e2b6f00 | 217 | |
igor_v | 0:8ad47e2b6f00 | 218 | case 0x5: |
igor_v | 0:8ad47e2b6f00 | 219 | Main.RgConA|=bit<<0x5; |
igor_v | 0:8ad47e2b6f00 | 220 | break; |
igor_v | 0:8ad47e2b6f00 | 221 | |
igor_v | 0:8ad47e2b6f00 | 222 | case 0x6: |
igor_v | 0:8ad47e2b6f00 | 223 | Main.RgConA|=bit<<0x6; |
igor_v | 0:8ad47e2b6f00 | 224 | break; |
igor_v | 0:8ad47e2b6f00 | 225 | |
igor_v | 0:8ad47e2b6f00 | 226 | case 0x7: |
igor_v | 0:8ad47e2b6f00 | 227 | Main.RgConA|=bit<<0x7; |
igor_v | 0:8ad47e2b6f00 | 228 | break; |
igor_v | 0:8ad47e2b6f00 | 229 | } |
igor_v | 0:8ad47e2b6f00 | 230 | BuffTemp[3] = NReg<<4; |
igor_v | 0:8ad47e2b6f00 | 231 | BuffTemp[4] = (Main.RgConA>>8 )& 0xff; |
igor_v | 0:8ad47e2b6f00 | 232 | BuffTemp[5] = Main.RgConA & 0xff; |
igor_v | 0:8ad47e2b6f00 | 233 | } |
igor_v | 0:8ad47e2b6f00 | 234 | else |
igor_v | 0:8ad47e2b6f00 | 235 | { |
igor_v | 0:8ad47e2b6f00 | 236 | NReg=1; // Main.RgConB |
igor_v | 0:8ad47e2b6f00 | 237 | switch(Param1&0xf) // Main.RgConB |
igor_v | 0:8ad47e2b6f00 | 238 | { |
igor_v | 0:8ad47e2b6f00 | 239 | case 0x0: |
igor_v | 0:8ad47e2b6f00 | 240 | Main.RgConB|=bit; |
igor_v | 0:8ad47e2b6f00 | 241 | break; |
igor_v | 0:8ad47e2b6f00 | 242 | case 0x1: |
igor_v | 0:8ad47e2b6f00 | 243 | Main.RgConB|=bit<1; |
igor_v | 0:8ad47e2b6f00 | 244 | break; |
igor_v | 0:8ad47e2b6f00 | 245 | case 0x2: |
igor_v | 0:8ad47e2b6f00 | 246 | Main.RgConB|=bit<2; |
igor_v | 0:8ad47e2b6f00 | 247 | break; |
igor_v | 0:8ad47e2b6f00 | 248 | } |
igor_v | 0:8ad47e2b6f00 | 249 | BuffTemp[3] = NReg<<4; |
igor_v | 0:8ad47e2b6f00 | 250 | BuffTemp[4] = (Main.RgConB>>8 ) & 0xff; |
igor_v | 0:8ad47e2b6f00 | 251 | BuffTemp[5] = Main.RgConB & 0xff; |
igor_v | 0:8ad47e2b6f00 | 252 | } |
igor_v | 0:8ad47e2b6f00 | 253 | |
igor_v | 0:8ad47e2b6f00 | 254 | Check(BuffTemp, CRC_N); |
igor_v | 0:8ad47e2b6f00 | 255 | WriteConN (BuffTemp,CRC_N); |
igor_v | 0:8ad47e2b6f00 | 256 | } |
igor_v | 0:8ad47e2b6f00 | 257 | |
igor_v | 0:8ad47e2b6f00 | 258 | void CMD_M_Control_D9()///������ ��������� ���������� |
igor_v | 0:8ad47e2b6f00 | 259 | { |
igor_v | 0:8ad47e2b6f00 | 260 | int bit,NReg; |
igor_v | 0:8ad47e2b6f00 | 261 | BuffTemp[0] = Main.SOC_Out; //DD |
igor_v | 0:8ad47e2b6f00 | 262 | BuffTemp[1] = Main.My_Addres; //00 |
igor_v | 0:8ad47e2b6f00 | 263 | BuffTemp[2] = Main.CMD_In; //D9 |
igor_v | 0:8ad47e2b6f00 | 264 | if ((Param1 & 0x10) == 0) |
igor_v | 0:8ad47e2b6f00 | 265 | { |
igor_v | 0:8ad47e2b6f00 | 266 | BuffTemp[3]=0<<4; |
igor_v | 0:8ad47e2b6f00 | 267 | BuffTemp[4] = (Main.RgConA>>8 )& 0xff; |
igor_v | 0:8ad47e2b6f00 | 268 | BuffTemp[5] = Main.RgConA & 0xff; |
igor_v | 0:8ad47e2b6f00 | 269 | } |
igor_v | 0:8ad47e2b6f00 | 270 | else |
igor_v | 0:8ad47e2b6f00 | 271 | { |
igor_v | 0:8ad47e2b6f00 | 272 | BuffTemp[3]=1<<4; |
igor_v | 0:8ad47e2b6f00 | 273 | BuffTemp[4] = (Main.RgConB>>8 ) & 0xff; |
igor_v | 0:8ad47e2b6f00 | 274 | BuffTemp[5] = Main.RgConB & 0xff; |
igor_v | 0:8ad47e2b6f00 | 275 | } |
igor_v | 0:8ad47e2b6f00 | 276 | Check(BuffTemp, CRC_N); |
igor_v | 0:8ad47e2b6f00 | 277 | WriteConN (BuffTemp,CRC_N); |
igor_v | 0:8ad47e2b6f00 | 278 | } |
igor_v | 0:8ad47e2b6f00 | 279 | // (����� (���) ���� 0...3, ������� ���� ���������� ����, ������� ���� ���� ����) |
igor_v | 0:8ad47e2b6f00 | 280 | void CMD_M_Stymul() |
igor_v | 0:8ad47e2b6f00 | 281 | { |
igor_v | 0:8ad47e2b6f00 | 282 | int temp; |
igor_v | 0:8ad47e2b6f00 | 283 | temp =((BuffTemp[4]<<8) | BuffTemp[5]); |
igor_v | 0:8ad47e2b6f00 | 284 | // temp=0; |
igor_v | 0:8ad47e2b6f00 | 285 | temp=temp&0xFFFF; |
igor_v | 0:8ad47e2b6f00 | 286 | DACF =(temp*K_DAC)+deltaDAC; |
igor_v | 0:8ad47e2b6f00 | 287 | Spi.DAC_B =(unsigned int)(DACF) /*(unsigned int)(temp*K_DAC+deltaDAC)*/; // K_DAC); |
igor_v | 0:8ad47e2b6f00 | 288 | |
igor_v | 0:8ad47e2b6f00 | 289 | //int temp; |
igor_v | 0:8ad47e2b6f00 | 290 | // temp =((BuffTemp[4]<<8) | BuffTemp[5]); |
igor_v | 0:8ad47e2b6f00 | 291 | //temp = 65535 - temp; |
igor_v | 0:8ad47e2b6f00 | 292 | /*if(temp<1000) |
igor_v | 0:8ad47e2b6f00 | 293 | { |
igor_v | 0:8ad47e2b6f00 | 294 | temp=0; |
igor_v | 0:8ad47e2b6f00 | 295 | } |
igor_v | 0:8ad47e2b6f00 | 296 | else if(temp>60000) |
igor_v | 0:8ad47e2b6f00 | 297 | { |
igor_v | 0:8ad47e2b6f00 | 298 | temp=65535; |
igor_v | 0:8ad47e2b6f00 | 299 | }*/ |
igor_v | 0:8ad47e2b6f00 | 300 | //Spi.DAC_B =(((BuffTemp[4]<<8) | BuffTemp[5])*K_DAC+deltaDAC);/*((BuffTemp[4]<<8) | BuffTemp[5])-0xFFFF*///; //((rcv_buf[4] << 8) | (int)rcv_buf[5]);K_DAC+deltaDAC |
igor_v | 0:8ad47e2b6f00 | 301 | //BuffTemp[0] = temp; //DD |
igor_v | 0:8ad47e2b6f00 | 302 | //WriteConN (BuffTemp,1); |
igor_v | 0:8ad47e2b6f00 | 303 | } |
igor_v | 0:8ad47e2b6f00 | 304 | |
igor_v | 0:8ad47e2b6f00 | 305 | unsigned int Check(char *c, unsigned int Count) |
igor_v | 0:8ad47e2b6f00 | 306 | { |
igor_v | 0:8ad47e2b6f00 | 307 | int i=1; |
igor_v | 0:8ad47e2b6f00 | 308 | unsigned int temp,CRC; |
igor_v | 0:8ad47e2b6f00 | 309 | |
igor_v | 0:8ad47e2b6f00 | 310 | |
igor_v | 0:8ad47e2b6f00 | 311 | temp=1; |
igor_v | 0:8ad47e2b6f00 | 312 | CRC=0; |
igor_v | 0:8ad47e2b6f00 | 313 | |
igor_v | 0:8ad47e2b6f00 | 314 | |
igor_v | 0:8ad47e2b6f00 | 315 | for(;i<Count-2;i++) |
igor_v | 0:8ad47e2b6f00 | 316 | { |
igor_v | 0:8ad47e2b6f00 | 317 | CRC+=c[i]; |
igor_v | 0:8ad47e2b6f00 | 318 | } |
igor_v | 0:8ad47e2b6f00 | 319 | |
igor_v | 0:8ad47e2b6f00 | 320 | if(c[Count-2]!=((CRC>>8)&0xFF)) |
igor_v | 0:8ad47e2b6f00 | 321 | { |
igor_v | 0:8ad47e2b6f00 | 322 | temp=0; |
igor_v | 0:8ad47e2b6f00 | 323 | Main.RsErrLine = (Main.RsErrLine)&=0x2; |
igor_v | 0:8ad47e2b6f00 | 324 | } |
igor_v | 0:8ad47e2b6f00 | 325 | |
igor_v | 0:8ad47e2b6f00 | 326 | if(c[Count-1]!=((CRC>>0)&0xFF)) |
igor_v | 0:8ad47e2b6f00 | 327 | { |
igor_v | 0:8ad47e2b6f00 | 328 | temp=0; |
igor_v | 0:8ad47e2b6f00 | 329 | // Main.RsErrLine= (Main.RsErrLine)=0x2; |
igor_v | 0:8ad47e2b6f00 | 330 | } |
igor_v | 0:8ad47e2b6f00 | 331 | |
igor_v | 0:8ad47e2b6f00 | 332 | c[Count-2]=(CRC>>8)&0xFF; |
igor_v | 0:8ad47e2b6f00 | 333 | c[Count-1]=(CRC>>0)&0xFF; |
igor_v | 0:8ad47e2b6f00 | 334 | |
igor_v | 0:8ad47e2b6f00 | 335 | |
igor_v | 0:8ad47e2b6f00 | 336 | |
igor_v | 0:8ad47e2b6f00 | 337 | return temp; |
igor_v | 0:8ad47e2b6f00 | 338 | } |
igor_v | 0:8ad47e2b6f00 | 339 | |
igor_v | 0:8ad47e2b6f00 | 340 | int Getlengf(void) |
igor_v | 0:8ad47e2b6f00 | 341 | { |
igor_v | 0:8ad47e2b6f00 | 342 | unsigned int lengf=0; |
igor_v | 0:8ad47e2b6f00 | 343 | switch(Main.CMD_In) |
igor_v | 0:8ad47e2b6f00 | 344 | { |
igor_v | 0:8ad47e2b6f00 | 345 | case 0x99://maintainance |
igor_v | 0:8ad47e2b6f00 | 346 | lengf=6; |
igor_v | 0:8ad47e2b6f00 | 347 | CRC_N=8; |
igor_v | 0:8ad47e2b6f00 | 348 | break; |
igor_v | 0:8ad47e2b6f00 | 349 | |
igor_v | 0:8ad47e2b6f00 | 350 | case 0x0A: //m_stymul |
igor_v | 0:8ad47e2b6f00 | 351 | lengf=8; |
igor_v | 0:8ad47e2b6f00 | 352 | break; |
igor_v | 0:8ad47e2b6f00 | 353 | |
igor_v | 0:8ad47e2b6f00 | 354 | case 0xA5://DeviceMode |
igor_v | 0:8ad47e2b6f00 | 355 | |
igor_v | 0:8ad47e2b6f00 | 356 | lengf=6; |
igor_v | 0:8ad47e2b6f00 | 357 | CRC_N=8; |
igor_v | 0:8ad47e2b6f00 | 358 | break; |
igor_v | 0:8ad47e2b6f00 | 359 | |
igor_v | 0:8ad47e2b6f00 | 360 | case 0xDD://m_rate |
igor_v | 0:8ad47e2b6f00 | 361 | |
igor_v | 0:8ad47e2b6f00 | 362 | lengf=6; |
igor_v | 0:8ad47e2b6f00 | 363 | CRC_N=44; |
igor_v | 0:8ad47e2b6f00 | 364 | break; |
igor_v | 0:8ad47e2b6f00 | 365 | |
igor_v | 0:8ad47e2b6f00 | 366 | case 0xB0://DeviceMode |
igor_v | 0:8ad47e2b6f00 | 367 | |
igor_v | 0:8ad47e2b6f00 | 368 | lengf=6; |
igor_v | 0:8ad47e2b6f00 | 369 | CRC_N=8; |
igor_v | 0:8ad47e2b6f00 | 370 | break; |
igor_v | 0:8ad47e2b6f00 | 371 | |
igor_v | 0:8ad47e2b6f00 | 372 | case 0xD8://m_control |
igor_v | 0:8ad47e2b6f00 | 373 | |
igor_v | 0:8ad47e2b6f00 | 374 | lengf=6; |
igor_v | 0:8ad47e2b6f00 | 375 | CRC_N=8; |
igor_v | 0:8ad47e2b6f00 | 376 | break; |
igor_v | 0:8ad47e2b6f00 | 377 | |
igor_v | 0:8ad47e2b6f00 | 378 | case 0xD9://m_control |
igor_v | 0:8ad47e2b6f00 | 379 | |
igor_v | 0:8ad47e2b6f00 | 380 | lengf=6; |
igor_v | 0:8ad47e2b6f00 | 381 | CRC_N=8; |
igor_v | 0:8ad47e2b6f00 | 382 | break; |
igor_v | 0:8ad47e2b6f00 | 383 | } |
igor_v | 0:8ad47e2b6f00 | 384 | return lengf; |
igor_v | 0:8ad47e2b6f00 | 385 | } |
igor_v | 0:8ad47e2b6f00 | 386 | |
igor_v | 0:8ad47e2b6f00 | 387 | void Read_CMD(void) |
igor_v | 0:8ad47e2b6f00 | 388 | { |
igor_v | 0:8ad47e2b6f00 | 389 | Main.SOC_Out=0xDD; |
igor_v | 0:8ad47e2b6f00 | 390 | Main.RsErrLine = (Main.RsErrLine)& 0xffff; |
igor_v | 0:8ad47e2b6f00 | 391 | |
igor_v | 0:8ad47e2b6f00 | 392 | |
igor_v | 0:8ad47e2b6f00 | 393 | CountBuFFIn=ReadChekCon(BuffTemp); |
igor_v | 0:8ad47e2b6f00 | 394 | if(CountBuFFIn==1) |
igor_v | 0:8ad47e2b6f00 | 395 | { |
igor_v | 0:8ad47e2b6f00 | 396 | if (BuffTemp[0] != SOC_In) |
igor_v | 0:8ad47e2b6f00 | 397 | { |
igor_v | 0:8ad47e2b6f00 | 398 | ReadCon(BuffTemp); |
igor_v | 0:8ad47e2b6f00 | 399 | Main.RsErrLine += 0x100;//WriteCon("\n\r ...Error.... "); |
igor_v | 0:8ad47e2b6f00 | 400 | BuffTemp[99]=Main.RsErrLine; |
igor_v | 0:8ad47e2b6f00 | 401 | } |
igor_v | 0:8ad47e2b6f00 | 402 | } |
igor_v | 0:8ad47e2b6f00 | 403 | else if(CountBuFFIn==2) |
igor_v | 0:8ad47e2b6f00 | 404 | { |
igor_v | 0:8ad47e2b6f00 | 405 | if (BuffTemp[1] != Main.My_Addres) |
igor_v | 0:8ad47e2b6f00 | 406 | { |
igor_v | 0:8ad47e2b6f00 | 407 | ReadCon(BuffTemp); |
igor_v | 0:8ad47e2b6f00 | 408 | Main.RsErrLine += 0x1;//WriteCon("\n\r ...Error_ADDRES.... "); |
igor_v | 0:8ad47e2b6f00 | 409 | } |
igor_v | 0:8ad47e2b6f00 | 410 | } |
igor_v | 0:8ad47e2b6f00 | 411 | else if(CountBuFFIn==3) |
igor_v | 0:8ad47e2b6f00 | 412 | { |
igor_v | 0:8ad47e2b6f00 | 413 | Main.CMD_In=BuffTemp[2]; |
igor_v | 0:8ad47e2b6f00 | 414 | N=Getlengf(); |
igor_v | 0:8ad47e2b6f00 | 415 | } |
igor_v | 0:8ad47e2b6f00 | 416 | |
igor_v | 0:8ad47e2b6f00 | 417 | else if(CountBuFFIn==4 && N==6) |
igor_v | 0:8ad47e2b6f00 | 418 | { |
igor_v | 0:8ad47e2b6f00 | 419 | Param1=BuffTemp[3]; |
igor_v | 0:8ad47e2b6f00 | 420 | } |
igor_v | 0:8ad47e2b6f00 | 421 | else if((CountBuFFIn==5)&&(N==7)) |
igor_v | 0:8ad47e2b6f00 | 422 | { |
igor_v | 0:8ad47e2b6f00 | 423 | //LoopOn |
igor_v | 0:8ad47e2b6f00 | 424 | Param1=BuffTemp[3]; |
igor_v | 0:8ad47e2b6f00 | 425 | Param2=BuffTemp[4]; |
igor_v | 0:8ad47e2b6f00 | 426 | |
igor_v | 0:8ad47e2b6f00 | 427 | } |
igor_v | 0:8ad47e2b6f00 | 428 | else if((CountBuFFIn==6)&&(N==8)) |
igor_v | 0:8ad47e2b6f00 | 429 | { |
igor_v | 0:8ad47e2b6f00 | 430 | Param1=BuffTemp[3]; |
igor_v | 0:8ad47e2b6f00 | 431 | Param2=BuffTemp[4]; |
igor_v | 0:8ad47e2b6f00 | 432 | Param3=BuffTemp[5]; |
igor_v | 0:8ad47e2b6f00 | 433 | } |
igor_v | 0:8ad47e2b6f00 | 434 | else if(CountBuFFIn > (N-1)) |
igor_v | 0:8ad47e2b6f00 | 435 | { |
igor_v | 0:8ad47e2b6f00 | 436 | ReadCon(BuffTemp); |
igor_v | 0:8ad47e2b6f00 | 437 | if(Check(BuffTemp, CountBuFFIn)) |
igor_v | 0:8ad47e2b6f00 | 438 | { |
igor_v | 0:8ad47e2b6f00 | 439 | switch(Main.CMD_In) |
igor_v | 0:8ad47e2b6f00 | 440 | { |
igor_v | 0:8ad47e2b6f00 | 441 | case CMD_MAINT: |
igor_v | 0:8ad47e2b6f00 | 442 | CMD_Maintenance(); |
igor_v | 0:8ad47e2b6f00 | 443 | break; |
igor_v | 0:8ad47e2b6f00 | 444 | case 0xD8: |
igor_v | 0:8ad47e2b6f00 | 445 | CMD_M_Control_D8(); |
igor_v | 0:8ad47e2b6f00 | 446 | case 0xD9: |
igor_v | 0:8ad47e2b6f00 | 447 | CMD_M_Control_D9(); |
igor_v | 0:8ad47e2b6f00 | 448 | break; |
igor_v | 0:8ad47e2b6f00 | 449 | case 0x0A: |
igor_v | 0:8ad47e2b6f00 | 450 | CMD_M_Stymul(Param1,Param2,Param3); |
igor_v | 0:8ad47e2b6f00 | 451 | break; |
igor_v | 0:8ad47e2b6f00 | 452 | case 0xDD: |
igor_v | 0:8ad47e2b6f00 | 453 | Rate_Flag=1; |
igor_v | 0:8ad47e2b6f00 | 454 | break; |
igor_v | 0:8ad47e2b6f00 | 455 | Main.RsErrLine = 0; |
igor_v | 0:8ad47e2b6f00 | 456 | } |
igor_v | 0:8ad47e2b6f00 | 457 | |
igor_v | 0:8ad47e2b6f00 | 458 | } |
igor_v | 0:8ad47e2b6f00 | 459 | } |
igor_v | 0:8ad47e2b6f00 | 460 | } |
igor_v | 0:8ad47e2b6f00 | 461 | |
igor_v | 0:8ad47e2b6f00 | 462 |