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