@@ -1055,41 +1055,43 @@ static uint8_t limit_rx_len(volatile measurement_t *meas, int rx_len, int eof_id
10551055 }
10561056}
10571057
1058- //! Adjust the rx length so that it's compatible with continuous RX
1059- /*! In continuous RX mode, the total RX length must be set to an integer number
1060- * of RX samples. The number of RX samples given RX length (in SMCLK cycles)
1061- * depends on the ODR. This function will truncate the RX length such that the
1062- * new length satisfies the integer number of samples condition.
1063- *
1064- * This also prevents glitches with non-continuous RX at certain RX
1065- * lengths, though not strictly required.
1066- *
1067- * \param meas a pointer to a measurement_t. The instructions contained in the
1068- * measurement_t will be potentially modified by this function.
1069- * \param rx_len the total rx length in SMCLK cycles
1070- * \param eof_idx the index of the EOF instruction
1071- */
1072- static uint8_t adjust_rx_len (volatile measurement_t * meas , int rx_len , int eof_idx ) {
1073- const int rx_samples = rx_len >> (11 - meas -> odr );
1074- const int new_rx_len = rx_samples << (11 - meas -> odr );
1058+ uint8_t chdrv_adjust_rx_len (volatile pmut_transceiver_inst_t * trx_inst , uint8_t cic_odr , int rx_len , int eof_idx ) {
1059+ const int rx_samples = rx_len >> (11 - cic_odr );
1060+ const int new_rx_len = rx_samples << (11 - cic_odr );
10751061 int len_to_cut = rx_len - new_rx_len ;
10761062
10771063 CH_LOG_DEBUG ("rx_len=%d rx_samples=%d new_rx_len=%d len_to_cut=%d" , rx_len , rx_samples , new_rx_len , len_to_cut );
10781064
10791065 if (len_to_cut == 0 ) {
10801066 // No modification needed for this rx instruction
10811067 return 0 ;
1082- } else if (meas -> trx_inst [eof_idx - 1 ].length >= (1 << (11 - meas -> odr )) + len_to_cut ) {
1068+ } else if (trx_inst [eof_idx - 1 ].length >= (1 << (11 - cic_odr )) + len_to_cut ) {
10831069 // make sure resulting rx instruction will have at least one RX sample left
10841070 // in it after the cut.
1085- meas -> trx_inst [eof_idx - 1 ].length -= len_to_cut ;
1071+ trx_inst [eof_idx - 1 ].length -= len_to_cut ;
10861072 return 0 ;
10871073 } else {
10881074 // return error otherwise
10891075 return 1 ;
10901076 }
10911077}
10921078
1079+ static uint8_t adjust_rx_len (volatile measurement_t * meas , int rx_len , int eof_idx ) {
1080+ return chdrv_adjust_rx_len (meas -> trx_inst , meas -> odr , rx_len , eof_idx );
1081+ }
1082+
1083+ void chdrv_enable_mq_sanitize (ch_dev_t * dev_ptr ) {
1084+ dev_ptr -> mq_sanitize_enabled = 1 ;
1085+ }
1086+
1087+ void chdrv_disable_mq_sanitize (ch_dev_t * dev_ptr ) {
1088+ dev_ptr -> mq_sanitize_enabled = 0 ;
1089+ }
1090+
1091+ int16_t chdrv_is_mq_sanitize_enabled (const ch_dev_t * dev_ptr ) {
1092+ return dev_ptr -> mq_sanitize_enabled ;
1093+ }
1094+
10931095//! Sanitize the measurement queue
10941096/*! This function sanitizes the measurement queue by performing several checks
10951097 * to ensure it is compatible with the selected sensor mode. This function
@@ -1187,12 +1189,14 @@ uint8_t chdrv_meas_queue_write(ch_dev_t *dev_ptr, measurement_queue_t *q_buf_ptr
11871189 if (q_buf_ptr == NULL ) {
11881190 q_buf_ptr = & (dev_ptr -> meas_queue ); // source is local copy in ch_dev_t
11891191 }
1190- // Note that we do not abort the write when the sanitize funciton returns an
1191- // error. This is mostly for historical reasons. We have previously allowed
1192- // writing invalid queues. It is OK to write them so long as they are not
1193- // used, and it's a bit confusing for us to just arbitrarily set them when
1194- // the user has not requested it
1195- meas_queue_sanitize (q_buf_ptr , dev_ptr -> current_fw -> max_samples );
1192+ if (chdrv_is_mq_sanitize_enabled (dev_ptr )) {
1193+ // Note that we do not abort the write when the sanitize funciton returns an
1194+ // error. This is mostly for historical reasons. We have previously allowed
1195+ // writing invalid queues. It is OK to write them so long as they are not
1196+ // used, and it's a bit confusing for us to just arbitrarily set them when
1197+ // the user has not requested it
1198+ meas_queue_sanitize (q_buf_ptr , dev_ptr -> current_fw -> max_samples );
1199+ }
11961200 err |= chdrv_burst_write (dev_ptr , meas_queue_addr , (uint8_t * )q_buf_ptr , sizeof (measurement_queue_t ));
11971201
11981202 return err ;
@@ -2415,9 +2419,18 @@ static inline uint8_t shasta_detect_and_program(ch_dev_t *dev_ptr) {
24152419 if (!ch_err ) {
24162420 ch_err = chdrv_read_buf_addr (dev_ptr );
24172421 }
2422+ if (!ch_err ) {
2423+ uint16_t ver_major_addr = (uint16_t )(uintptr_t )& dev_ptr -> sens_cfg_addr -> common .reg_map_format .major ;
2424+ uint16_t ver_minor_addr = (uint16_t )(uintptr_t )& dev_ptr -> sens_cfg_addr -> common .reg_map_format .minor ;
2425+ ch_err = chdrv_read_byte (dev_ptr , ver_major_addr , & dev_ptr -> reg_fmt_ver_major );
2426+ if (!ch_err ) {
2427+ ch_err = chdrv_read_byte (dev_ptr , ver_minor_addr , & dev_ptr -> reg_fmt_ver_minor );
2428+ }
2429+ }
24182430
24192431 CH_LOG_INFO ("Sensor shared mem addr = 0x%04x" , (uint16_t )(uintptr_t )dev_ptr -> sens_cfg_addr );
24202432 CH_LOG_INFO ("Sensor algo info addr = 0x%04x" , (uint16_t )(uintptr_t )dev_ptr -> sens_algo_info_addr );
2433+ CH_LOG_INFO ("Sensor register map version = %u.%u" , dev_ptr -> reg_fmt_ver_major , dev_ptr -> reg_fmt_ver_minor );
24212434 }
24222435
24232436 /* Copy OTP (one-time-programmable) mem contents to sensor ram and process contents.
0 commit comments