rh811ad053f_comm.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include "plt.h"
  2. int rh811ad053f_comm_init(int idx)
  3. {
  4. struct rh811ad053f_t *dev = &rh811ad053f[idx];
  5. struct comm_t *comm = &dev->comm;
  6. comm_set_state(comm, COMMST_ERR);
  7. }
  8. int rh811ad053f_comm_reset(int idx)
  9. {
  10. struct rh811ad053f_t *dev = &rh811ad053f[idx];
  11. struct comm_t *comm = &dev->comm;
  12. comm_set_state(comm, COMMST_NORMAL);
  13. }
  14. void rh811ad053f_comm_dac(int idx)
  15. {
  16. unsigned short tab_us[256] = {0};
  17. struct rh811ad053f_t *dev = &rh811ad053f[idx];
  18. struct comm_t *comm = &dev->comm;
  19. int chanidx = comm->chanidx;
  20. int addr = comm->adr;
  21. int start, nb, rc, i;
  22. int ret = 0;
  23. if (comm_get_state(comm) != COMMST_NORMAL)
  24. {
  25. return;
  26. }
  27. comm_start_cal_dac_timing(comm);
  28. nb = 2;
  29. start = 0x0002;
  30. chan_lock(comm->chanidx);
  31. if (chan_read_holdingregisters_with_retry(chanidx, addr, start, nb, tab_us) < 0)
  32. {
  33. chan_unlock(comm->chanidx);
  34. comm_set_state(comm, COMMST_ERR);
  35. return;
  36. }
  37. else
  38. { /* read ok */
  39. chan_unlock(comm->chanidx);
  40. dev->humi = tab_us[0x0003 - start] / 10.0;
  41. dev->temp = *((SHORT *)&tab_us[0x0002 - start]) / 10.0;
  42. comm_stop_cal_dac_timing(comm);
  43. }
  44. }