tdc_tof.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #ifndef __TDC_TOF_H__
  2. #define __TDC_TOF_H__
  3. #include "board.h"
  4. #define TDC_CFG_DO_CKENA (0x00000001u)
  5. #define TDC_CFG_DO_CKDIS (0x00000002u)
  6. #define TDC_CFG_DO_WREG (0x00000008u)
  7. #define TDC_CFG_FIRE_UP (0x00000010u)
  8. #define TDC_CFG_FIRE_DOWN (0x00000020u)
  9. #define TOF_ST_INIT (0x0001u)
  10. #define TOF_ST_CALIB (0x0002u)
  11. #define TOF_ST_TEST (0x0004u)
  12. #define TOF_ST_METER (0x0008u)
  13. #define TOF_ST_VOID (0x0010u)
  14. #define TOF_FLAG_BLANK_PIPE (0x00000001u)
  15. #define TOF_FLAG_UNPAIR_WAVE (0x00000002u)
  16. #define TOF_FLAG_UP_EARLY (0x00000004u)
  17. #define TOF_FLAG_UNALGND_CHOP (0x00000008u)
  18. #define TOF_FLAG_VALID_FLOW (0x00000010u)
  19. #define TOF_FLAG_CALIB_FLOW (0x00000020u)
  20. #define TOF_FLAG_CALIB_FALL (0x00000040u)
  21. #define TOF_FLAG_CALIB_DONE (0x00000080u)
  22. #define TOF_FLAG_TDC_FAULT (0x40000000u)
  23. #define CALIB_TIME_LTH (10)
  24. #define RTC_CNTMSK_VOID (0x3u)
  25. #define RTC_CNTMSK_CAL (0x7u)
  26. #define RTC_CNTMSK_TEMP (0x7u)
  27. //modified by yuewei 20260520 start
  28. /*
  29. typedef struct {
  30. float SpdLvl; // start SpdLvl for this Quad
  31. float Coe[4]; // m0, m1, m2, m3 for this Quad
  32. } Quad_Cell_t;
  33. */
  34. typedef struct {
  35. float m; // 常数
  36. float k; // 系数
  37. } Coeff_t;
  38. typedef struct {
  39. float value; // 温度值 / 流速等级
  40. Coeff_t coe; // 补偿系数 {m, k}
  41. } Quad_Cell_t;
  42. //modified by yuewei 20260520 end
  43. extern uint32_t RTC_CntInt;
  44. extern uint16_t tof_state;
  45. extern uint32_t tof_flag;
  46. extern uint8_t TdcIntStep;
  47. extern uint16_t TdcStatus;
  48. extern uint16_t TdcUPwFw;
  49. extern uint16_t TdcUPwHw;
  50. extern uint16_t TdcDPwFw;
  51. extern uint16_t TdcDPwHw;
  52. extern uint32_t TdcUToF[9];
  53. extern uint32_t TdcDToF[9];
  54. extern float WaterPrmt[2];
  55. extern float TdcScale;
  56. #define WaterTemp (WaterPrmt[0])
  57. #define UsonicSpd (WaterPrmt[1])
  58. extern float UToFAvg;
  59. extern float DToFAvg;
  60. extern float DiffToF;
  61. extern float DiffToFAvg;
  62. extern float DiffToFAvg128;
  63. extern uint8_t TdcFwOfst;
  64. extern double CumFlow;
  65. extern double FwCumFlow;
  66. extern double BwCumFlow;
  67. extern double FlowVol;
  68. extern float RefFlow;
  69. extern uint16_t CalibTime;
  70. extern float CalibSpdLvl;
  71. extern float CalibTemp;
  72. extern float DiffTofThres[4];
  73. typedef void (*flow_vol_itf)(double flow_vol, float tmp_float);
  74. typedef void (*pipe_blank_itf)(uint8_t ch);
  75. typedef void (*check_flow_itf)(double cum_flow, float spdLvl, float temp);
  76. typedef struct {
  77. uint8_t bw_flow_flag;
  78. uint32_t ch_bit_map;
  79. uint32_t blank_flag;
  80. float pipe_coe;
  81. float path_skew[MUX_CH_NUM];
  82. uint32_t ch_num;
  83. uint8_t mux_ch_no[MUX_CH_NUM];
  84. uint32_t mux_switch;
  85. uint16_t ntc_num;
  86. const uint16_t *ntc_ohm_ary;
  87. const float *ntc_slp_ary;
  88. uint16_t row_num;
  89. uint16_t col_num;
  90. const float *row_temp_ary;
  91. //modified by yuewei 20260409
  92. //const Quad_Cell_t *quad_cell_ary;
  93. Quad_Cell_t *quad_cell_ary;
  94. pipe_blank_itf set_blank;
  95. pipe_blank_itf clr_blank;
  96. flow_vol_itf flow_vol;
  97. check_flow_itf check_flow;
  98. }tdc_itf_t;
  99. extern tdc_itf_t TdcItf;
  100. extern tdc_itf_t *pTdcItf;
  101. extern const uint16_t Quad_Cell_NUM;//wxl2026-4-14
  102. extern Quad_Cell_t Quad_Cell_Ary[];//wxl2026-4-14
  103. void tdc_tof_init(void);
  104. void tdc_start_tof(uint32_t cfg);
  105. void tdc_read_tof(uint32_t cfg);
  106. void tdc_start_cal(uint32_t cfg);
  107. void tdc_read_cal(uint32_t cfg);
  108. void tdc_start_temp(uint32_t cfg);
  109. void tdc_read_temp(uint32_t cfg);
  110. void Ohm2Dgr2USSpd(uint16_t ohmX10, float *p);
  111. float bilinear_quad_apsr(float WatSpdLvl, float WatTemp);
  112. // tdc_itf.c
  113. void tdc_flow_itf(double flow_vol, float tmp_float);
  114. void set_pipe_blank(uint8_t ch);
  115. void clr_pipe_blank(uint8_t ch);
  116. void set_tdc_itf(tdc_itf_t *itf);
  117. uint32_t get_tof_flag(void);
  118. void set_tof_flag(uint32_t flag);
  119. uint16_t get_tof_state(void);
  120. void set_tof_state(uint16_t state);
  121. float get_diff_tof(void);
  122. uint8_t get_tdc_fw_ofst(void);
  123. void set_tdc_fw_ofst(uint8_t fw_ofst);
  124. uint8_t get_tdc_int_step(void);
  125. void set_tdc_int_step(uint8_t int_step);
  126. #endif