CMD0x22_Request_AnalogChannelSet.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. #include <string.h>
  2. #include "delay.h"
  3. #include "DebugDataDefine.h"
  4. #include "CommandsDefine.h"
  5. #include "AnalogChannelCtrl_Dictionary.h"
  6. #include "ProjectConfig.h"
  7. #include "Probe_MSO7000X_2d5g.h"
  8. #include "AnalogChannelCtrl_2d5g_base.h"
  9. #include "Helper.h"
  10. #include "usart.h"
  11. //////////////////////////////////////////////////////////////////////////////
  12. // 2203/5/X GHz_ljw 合并版,业务逻辑下沉 模拟通道控制
  13. //////////////////////////////////////////////////////////////////////////////
  14. u8 Get4094CtrlWord(struct Paras595 params, u32* ctrlWord)
  15. {
  16. u32 _ctrlWord = 0;
  17. u8 _isHigh = 0;
  18. // 带宽
  19. if(params.bandwidth == 0xFFFF)//FULL
  20. {
  21. _ctrlWord|=bwCtrlWords[0];
  22. }
  23. else if(params.bandwidth == 1000) //1GHz
  24. {
  25. _ctrlWord|=bwCtrlWords[1];
  26. }
  27. else if(params.bandwidth == 500) //500MHz
  28. {
  29. _ctrlWord|=bwCtrlWords[2];
  30. }
  31. else if(params.bandwidth == 20) //20MHz
  32. {
  33. _ctrlWord|=bwCtrlWords[3];
  34. }
  35. else
  36. {
  37. return 0; //error
  38. }
  39. // 阻抗
  40. if(params.coupling == 0 && params.high_low == 1)//DC50
  41. {
  42. _ctrlWord|=coupleCtrl_4094[0];
  43. }
  44. else if(params.coupling == 0 && params.high_low == 0)//DC1M
  45. {
  46. _ctrlWord|=coupleCtrl_4094[1];
  47. _isHigh = 1;
  48. }
  49. else if(params.coupling == 1 && params.high_low == 0)//AC1M
  50. {
  51. _ctrlWord|=coupleCtrl_4094[2];
  52. _isHigh = 1;
  53. }
  54. else
  55. {
  56. return 0; //error
  57. }
  58. //衰减
  59. if(_isHigh)
  60. {
  61. if(params.att==1||params.att==0) //不衰减
  62. {
  63. _ctrlWord|=0;
  64. }
  65. else if(params.att==ATTLV2)
  66. {
  67. _ctrlWord|=impCtrlBit;
  68. }
  69. else if(params.att==ATTLV1)
  70. {
  71. _ctrlWord|=relayCtrlBit2;
  72. }
  73. else if(params.att==ATTLV1*ATTLV2)
  74. {
  75. _ctrlWord|=impCtrlBit|relayCtrlBit2;
  76. }
  77. else
  78. {
  79. return 0; //error
  80. }
  81. }
  82. else
  83. {
  84. if(params.att==1||params.att==0) //不衰减
  85. {
  86. _ctrlWord|=0;
  87. }
  88. else if(params.att==ATTLV1)
  89. {
  90. _ctrlWord|=impCtrlBit;
  91. }
  92. else if(params.att==ATTLV2)
  93. {
  94. _ctrlWord|=impCtrlBit|relayCtrlBit2;
  95. }
  96. else if(params.att==ATTLV1*ATTLV2)
  97. {
  98. _ctrlWord|=impCtrlBit|relayCtrlBit2;
  99. }
  100. else
  101. {
  102. return 0; //error
  103. }
  104. }
  105. ctrlWord[0]=_ctrlWord;
  106. return 1;
  107. }
  108. u8 AnalogChannelSet_Check_Len(u16 dataLen)
  109. {
  110. if(dataLen<PACKAGE_CHANNELSET_DATA_BYTES+PACKAGE_CHANNELSET_INDEX_BYTES+PACKAGE_CHANNELSET_CHECK_AREA_BYTES+PACKAGE_CHANNELSET_FRAMEID_BYTES)
  111. {
  112. return 0;
  113. }
  114. if((dataLen-PACKAGE_CHANNELSET_INDEX_BYTES-PACKAGE_CHANNELSET_CHECK_AREA_BYTES-PACKAGE_CHANNELSET_FRAMEID_BYTES)%PACKAGE_CHANNELSET_DATA_BYTES!=0)
  115. {
  116. return 0;
  117. }
  118. return 1;
  119. }
  120. /*
  121. u32 GetDACConfigWord(struct ParasDAC params,u8* dac_index)
  122. {
  123. u32 ConfigWord;
  124. u8 high = offset_hz;
  125. u8 low = offset_lz;
  126. if(params.isBias==1)
  127. {
  128. high = move_hz;
  129. low = move_lz;
  130. }
  131. ConfigWord = 0x10300000;
  132. u8 dataType = params.high_low == 0 ? high : low;
  133. dac_index[0] = dacPortInfoTable[params.channelId-1][dataType][0] - 5;
  134. u8 dac_indexEx = dacPortInfoTable[params.channelId-1][dataType][2];
  135. u8 port = dacPortInfoTable[params.channelId-1][dataType][1];
  136. ConfigWord |= dac_indexEx << 24;
  137. ConfigWord |= port << 16;
  138. ConfigWord |= params.data;
  139. if(dac_index[0]==1){
  140. dac_index=dac_index; //test point
  141. }
  142. return ConfigWord;
  143. }*/
  144. void AnalogChannel_GetAll4094Word(u8 *pData,u8 channelId){
  145. //控制HC595/CD4094
  146. struct Paras595 params595;
  147. u8 gain = pData[0] ; //放大
  148. u8 att = pData[1] ; //衰减
  149. u8 coupling = pData[2];
  150. u8 high_low = pData[3];
  151. u16 bandwidth = pData[8] + (pData[9]<<8);
  152. u32 ctrlWord595=0;
  153. params595.att = att;
  154. params595.bandwidth = bandwidth;
  155. params595.coupling = coupling;
  156. params595.gain = gain;
  157. params595.high_low = high_low;
  158. if(channelId == 1)
  159. {
  160. channelId=channelId;//test point
  161. }
  162. u8 result = Get4094CtrlWord(params595,&ctrlWord595);
  163. if(result==0){
  164. //参数错误
  165. return;
  166. }
  167. //Low32HC595_new |= (ctrlWord595 << 8*(channelId-1));
  168. Low32HC595 |= (ctrlWord595 << 8*(channelId-1));
  169. if(channelId == 4)
  170. {
  171. channelId=channelId;//test point
  172. }
  173. //Low32HC595 = Low32HC595_new;
  174. }
  175. void AnalogChannel_SetAll4094(u8 *pData){
  176. u8 channelId = pData[0];
  177. Low32HC595 = Low32HC595 & ((u32)1<<31);
  178. u8 gotChData = 0;
  179. for(int i=0; i<MAX_CHANNEL_NUM; i++)
  180. {
  181. if(((channelId>>i) & 0x01) == 1){
  182. AnalogChannel_GetAll4094Word(pData + 1 + gotChData * PACKAGE_CHANNELSET_DATA_BYTES,i+1);
  183. gotChData++;
  184. }
  185. }
  186. CD_4094(High8HC595,1);
  187. CD_4094(Low32HC595,4);
  188. delay_ms(2);
  189. }
  190. void AnalogChannelSet(u8 *pData,u8 channelId)
  191. {
  192. //if(channelId != 1) return;
  193. u8 gain = pData[0] ; //放大
  194. u8 high_low = pData[3];
  195. u16 bias = pData[4] + (pData[5]<<8);
  196. u16 offset = pData[6] + (pData[7]<<8);
  197. //控制字
  198. struct ParasDAC paramsDAC;
  199. //dataType: 0-ref,1-offset_lz,2-offset_hz,3-move_lz,4-move_hz
  200. u32 ConfigWord_bias;
  201. u32 ConfigWord_offset;
  202. u8 dac_index_bias;
  203. u8 dac_index_offset;
  204. //bias
  205. paramsDAC.high_low = high_low;
  206. paramsDAC.channelId = channelId;
  207. paramsDAC.data = bias;
  208. paramsDAC.isBias = 1;
  209. ConfigWord_bias = GetDACConfigWord(paramsDAC,&dac_index_bias);
  210. DAC_AD5628(ConfigWord_bias,dac_index_bias);
  211. //delay_ms(1);
  212. //return;
  213. //offset
  214. paramsDAC.high_low = high_low;
  215. paramsDAC.channelId = channelId;
  216. paramsDAC.data = offset;
  217. paramsDAC.isBias = 0;
  218. if(channelId == 1)
  219. {
  220. channelId = channelId;//test point
  221. }
  222. if(channelId == 2)
  223. {
  224. channelId = channelId;//test point
  225. }
  226. ConfigWord_offset = GetDACConfigWord(paramsDAC,&dac_index_offset);
  227. if(dac_index_offset>=3){
  228. dac_index_offset=dac_index_offset;//test point
  229. }
  230. DAC_AD5628(ConfigWord_offset,dac_index_offset);
  231. //gain
  232. DSA_PE43711(LMH6401_ADDR_GAIN,gain,channelId);
  233. }
  234. void CMD0x22_Request_AnalogChannelSet_process(u8 *pData,u16 dataLen,u8 bIsContentBitInverted_Recv,u8 bIsContentBitInverted_SendBack)
  235. {
  236. if(IsChannelSetting!=0)
  237. {
  238. return;
  239. }
  240. IsChannelSetting = 1;
  241. #ifdef RUNNING_WHERE_AT_BOOT
  242. Command_SendbackErrorMessage(Error0x02_CannotRunAtBoot,1);
  243. #else
  244. memcpy(G_DebugData_AnalogChannel_LastRecvData,pData,dataLen);
  245. if(AnalogChannelSet_Check_Len(dataLen)==0)
  246. {
  247. IsChannelSetting=0;
  248. Command_SendbackErrorMessage(Error0x05_CMD_ParaLentghError,1);
  249. return;
  250. }
  251. //Calc
  252. u8 CRCStartIndex = dataLen - PACKAGE_CHANNELSET_FRAMEID_BYTES - PACKAGE_CHANNELSET_CHECK_AREA_BYTES;
  253. u8 SUMStartIndex = CRCStartIndex + PACKAGE_CHANNELSET_CRC32_BYTES;
  254. //u8 frameId[PACKAGE_CHANNELSET_FRAMEID_BYTES] ;
  255. u32 getCRC32 = pData[CRCStartIndex] + (pData[CRCStartIndex+1]<<8) + (pData[CRCStartIndex+2]<<16)+ (pData[CRCStartIndex+3]<<24);
  256. u16 getSUM16 = pData[SUMStartIndex] + (pData[SUMStartIndex+1]<<8) ;
  257. u32 calcCRC32 = Helper_CRC_CalcBlockCRC8(pData,CRCStartIndex);
  258. u16 calcSUM16 = Helper_Sum16(pData,CRCStartIndex);
  259. if(getCRC32!=calcCRC32 || getSUM16!=calcSUM16)
  260. {
  261. IsChannelSetting=0;
  262. Command_SendbackErrorMessage(Error0xFF_General,1);
  263. return;
  264. }
  265. //Calc End
  266. u8 gotChData = 0;
  267. u8 channelId = pData[0];
  268. AnalogChannel_SetAll4094(pData);
  269. for(int i=0; i<MAX_CHANNEL_NUM; i++)
  270. {
  271. if(((channelId>>i) & 0x01) == 1)
  272. {
  273. AnalogChannelSet(pData + 1 + gotChData * PACKAGE_CHANNELSET_DATA_BYTES,i+1);
  274. gotChData++;
  275. }
  276. }
  277. //Call back
  278. u8 dataBytes=PACKAGE_CHANNELSET_FRAMEID_BYTES;
  279. for(u8 i=0;i<PACKAGE_CHANNELSET_FRAMEID_BYTES;i++)
  280. {
  281. USART_WR_BUF[i] = pData[dataLen-PACKAGE_CHANNELSET_FRAMEID_BYTES+i];
  282. }
  283. USART6_Send(CMD0x22_Request_AnalogChannelSet,dataBytes,bIsContentBitInverted_SendBack);
  284. //end
  285. IsChannelSetting = 0;
  286. #endif
  287. }