mc90hdnc1a_comm.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. #include "plt.h"
  2. void mc90hdnc1a_comm_dac( int idx )
  3. {
  4. unsigned short tab_us[128]={0};
  5. struct mc90hdnc1a_t* dev = &mc90hdnc1a[idx];
  6. struct comm_t* comm = &dev->comm;
  7. int chanidx = comm->chanidx;
  8. int addr = comm->adr;
  9. int start, nb, rc, i;
  10. int ret = 0;
  11. if(comm_get_state(comm) != COMMST_NORMAL){
  12. return;
  13. }
  14. comm_start_cal_dac_timing(comm);
  15. nb = 52;
  16. start = 0x1000;
  17. chan_lock(chanidx);
  18. usleep(100000); // 100ms
  19. rc = chan_read_holdingregisters_with_retry( chanidx, addr, start, nb, tab_us);
  20. if( rc < 0){
  21. comm_set_state(comm, COMMST_ERR);
  22. }
  23. chan_unlock(chanidx);
  24. if( rc == 0 ){ /* read ok */
  25. mc90hdnc1a_set_workstat(idx, tab_us[0x1000 - start]);
  26. mc90hdnc1a_set_infan_stat(idx, tab_us[0x1002 - start]);
  27. mc90hdnc1a_set_outfan_stat(idx, tab_us[0x1004 - start]);
  28. mc90hdnc1a_set_compstat(idx, tab_us[0x1006 - start]);
  29. mc90hdnc1a_set_rtnwind_temp(idx, tab_us[0x1008 - start]/10);
  30. mc90hdnc1a_set_cond_temp(idx, tab_us[0x100E - start]/10);
  31. mc90hdnc1a_set_eva_temp(idx, tab_us[0x1010 - start]/10);
  32. mc90hdnc1a_set_infan_spd(idx, tab_us[0x1012 - start]);
  33. mc90hdnc1a_set_outfan_spd(idx, tab_us[0x1014 - start]);
  34. }else{
  35. return;
  36. }
  37. nb = 32;
  38. start = 0x0001;
  39. chan_lock(chanidx);
  40. usleep(100000); // 100ms
  41. rc = chan_read_holdingregisters_with_retry( chanidx, addr, start, nb, tab_us);
  42. if( rc < 0){
  43. comm_set_state(comm, COMMST_ERR);
  44. }
  45. chan_unlock(chanidx);
  46. if( rc == 0 ){ /* read ok */
  47. mc90hdnc1a_set_comp_start_temp(idx, tab_us[0x000A - start]/10);
  48. mc90hdnc1a_set_comp_gap_temp(idx, tab_us[0x000C - start]/10);
  49. mc90hdnc1a_set_heat_start_temp(idx, tab_us[0x001C - start]/10);
  50. mc90hdnc1a_set_heat_gap_temp(idx, tab_us[0x001E - start]/10);
  51. }else{
  52. return;
  53. }
  54. nb = 17;
  55. start = 0x0300;
  56. chan_lock(chanidx);
  57. usleep(100000); // 100ms
  58. rc = chan_read_holdingregisters_with_retry( chanidx, addr, start, nb, tab_us);
  59. if( rc < 0){
  60. comm_set_state(comm, COMMST_ERR);
  61. }
  62. chan_unlock(chanidx);
  63. if( 0 == rc ){ /* read ok */
  64. for( i = 1; i <= 17; i++ ){
  65. dev->warnings[i] = tab_us[0x0300 - start + i - 1];
  66. }
  67. comm_stop_cal_dac_timing(comm);
  68. }else{
  69. return;
  70. }
  71. }
  72. int mc90hdnc1a_set_dev_start( int idx)
  73. {
  74. int ret = 0;
  75. struct mc90hdnc1a_t* dev = &mc90hdnc1a[idx];
  76. struct comm_t* comm = &dev->comm;
  77. chan_lock(comm->chanidx);
  78. ret = chan_write_single_register_with_retry( comm->chanidx, comm->adr, 0x0202, 1);
  79. chan_unlock(comm->chanidx);
  80. log_dbg("%s, idx:%d", __func__, idx);
  81. return ret;
  82. }
  83. int mc90hdnc1a_set_dev_stop( int idx)
  84. {
  85. int ret = 0;
  86. struct mc90hdnc1a_t* dev = &mc90hdnc1a[idx];
  87. struct comm_t* comm = &dev->comm;
  88. chan_lock(comm->chanidx);
  89. ret = chan_write_single_register_with_retry( comm->chanidx, comm->adr, 0x0202, 2);
  90. chan_unlock(comm->chanidx);
  91. log_dbg("%s, idx:%d", __func__, idx);
  92. return ret;
  93. }
  94. int mc90hdnc1a_set_dev_comp_start_temp( int idx, int val)
  95. {
  96. int ret = 0;
  97. struct mc90hdnc1a_t* dev = &mc90hdnc1a[idx];
  98. struct comm_t* comm = &dev->comm;
  99. chan_lock(comm->chanidx);
  100. ret = chan_write_single_register_with_retry( comm->chanidx, comm->adr, 0x000A, val*10);
  101. chan_unlock(comm->chanidx);
  102. log_dbg("%s, idx:%d, val:%d, ret:%d", __func__, idx, val, ret);
  103. return ret;
  104. }
  105. int mc90hdnc1a_set_dev_comp_gap_temp( int idx, int val)
  106. {
  107. int ret = 0;
  108. struct mc90hdnc1a_t* dev = &mc90hdnc1a[idx];
  109. struct comm_t* comm = &dev->comm;
  110. chan_lock(comm->chanidx);
  111. ret = chan_write_single_register_with_retry( comm->chanidx, comm->adr, 0x000C, val*10);
  112. chan_unlock(comm->chanidx);
  113. log_dbg("%s, idx:%d, val:%d, ret:%d", __func__, idx, val, ret);
  114. return ret;
  115. }
  116. int mc90hdnc1a_set_dev_heat_start_temp( int idx, int val)
  117. {
  118. int ret = 0;
  119. struct mc90hdnc1a_t* dev = &mc90hdnc1a[idx];
  120. struct comm_t* comm = &dev->comm;
  121. chan_lock(comm->chanidx);
  122. ret = chan_write_single_register_with_retry( comm->chanidx, comm->adr, 0x001C, val*10);
  123. chan_unlock(comm->chanidx);
  124. log_dbg("%s, idx:%d, val:%d, ret:%d", __func__, idx, val, ret);
  125. return ret;
  126. }
  127. int mc90hdnc1a_set_dev_heat_gap_temp( int idx, int val)
  128. {
  129. int ret = 0;
  130. struct mc90hdnc1a_t* dev = &mc90hdnc1a[idx];
  131. struct comm_t* comm = &dev->comm;
  132. chan_lock(comm->chanidx);
  133. ret = chan_write_single_register_with_retry( comm->chanidx, comm->adr, 0x001E, val*10);
  134. chan_unlock(comm->chanidx);
  135. log_dbg("%s, idx:%d, val:%d, ret:%d", __func__, idx, val, ret);
  136. return ret;
  137. }
  138. int mc90hdnc1a_set_dev_mbadr( int idx, int val)
  139. {
  140. int ret = 0;
  141. struct mc90hdnc1a_t* dev = &mc90hdnc1a[idx];
  142. struct comm_t* comm = &dev->comm;
  143. chan_lock(comm->chanidx);
  144. ret = chan_write_single_register_with_retry( comm->chanidx, comm->adr, 0x0007, val);
  145. chan_unlock(comm->chanidx);
  146. log_dbg("%s, idx:%d, val:%d, ret:%d", __func__, idx, val, ret);
  147. return ret;
  148. }
  149. int mc90hdnc1a_comm_init(int idx)
  150. {
  151. struct mc90hdnc1a_t* dev = &mc90hdnc1a[idx];
  152. struct comm_t* comm = &dev->comm;
  153. comm_set_state( comm, COMMST_ERR );
  154. }
  155. int mc90hdnc1a_comm_reset(int idx)
  156. {
  157. struct mc90hdnc1a_t* dev = &mc90hdnc1a[idx];
  158. struct comm_t* comm = &dev->comm;
  159. comm_set_state( comm, COMMST_NORMAL );
  160. }