@@ -24,8 +24,6 @@ LOG_MODULE_REGISTER(dali_low_level, CONFIG_DALI_LOW_LEVEL_LOG_LEVEL);
24
24
SETTLING_TIME_BACKWARD_FRAME_MAX + \
25
25
k_us_to_cyc_floor32(DALI_TX_HALF_BIT_US) * MAX_HALFBIT_TIMES_PER_BACKWARD_FRAME
26
26
27
- #define SEND_TWICE_MAX_TIME k_ms_to_cyc_floor32(95)
28
-
29
27
const uint32_t settling_times_min [] = {
30
28
k_us_to_cyc_floor32 (DALI_TX_BACKWARD_INTERFRAME_MIN_US ), /* Settling time backward min */
31
29
k_us_to_cyc_floor32 (DALI_TX_PRIO_1_INTERFRAME_MIN_US ), /* Settling time prio 1 min */
@@ -156,6 +154,8 @@ struct dali_pwm_config {
156
154
int tx_shift_us ;
157
155
int rx_shift_us ;
158
156
unsigned int tx_rx_propagation_max_us ;
157
+ unsigned int rx_finish_work_delay_us ;
158
+ unsigned int rx_capture_work_delay_us ;
159
159
};
160
160
161
161
/** this function gets called from pwm_capture to finish the frame, after idle time on bus. */
@@ -168,9 +168,18 @@ static void dali_pwm_finish_frame(struct dali_pwm_data *data)
168
168
/* don't alter anything, if there is no data. */
169
169
return ;
170
170
}
171
- uint32_t time_now = k_cycle_get_32 ();
171
+ const uint32_t time_now = k_cycle_get_32 ();
172
+ const uint32_t time_difference_cycle =
173
+ time_now - data -> last_frame_timestamp -
174
+ k_us_to_cyc_floor32 (data -> capture .length * DALI_TX_FULL_BIT_US );
175
+ const struct device * dev = data -> dev ;
176
+ const struct dali_pwm_config * config = dev -> config ;
177
+ const uint32_t max_time_twice_cycle =
178
+ k_us_to_cyc_floor32 (DALI_RX_TWICE_MAX_US + config -> rx_finish_work_delay_us );
172
179
bool is_send_twice = true;
173
- if ((time_now - data -> last_frame_timestamp ) > SEND_TWICE_MAX_TIME ) {
180
+ if (time_difference_cycle > max_time_twice_cycle ) {
181
+ LOG_DBG ("single frame interframe time %d us" ,
182
+ k_cyc_to_us_floor32 (time_difference_cycle ));
174
183
is_send_twice = false;
175
184
}
176
185
@@ -296,7 +305,9 @@ static void dali_pwm_continuous_capture_callback_locked(uint32_t period_cycles,
296
305
/* trigger PWM send */
297
306
k_sem_give (& data -> tx_pwm_sem );
298
307
/* wait for stop condition */
299
- const uint32_t stopbit_timeout_us = DALI_RX_BIT_TIME_STOP_US - 10 * DALI_RX_GREY_AREA ;
308
+ const struct device * dev = data -> dev ;
309
+ const struct dali_pwm_config * config = dev -> config ;
310
+ const uint32_t stopbit_timeout_us = DALI_RX_BIT_TIME_STOP_US - config -> rx_capture_work_delay_us ;
300
311
k_work_reschedule (& data -> frame_finish_work , Z_TIMEOUT_US (stopbit_timeout_us ));
301
312
302
313
if (data -> timings .rx_flank_shift < 0 ) {
@@ -953,6 +964,8 @@ static DEVICE_API(dali, dali_pwm_driver_api) = {
953
964
.tx_shift_us = DT_INST_PROP_OR(idx, tx_flank_shift_us, 0), \
954
965
.rx_shift_us = DT_INST_PROP_OR(idx, rx_flank_shift_us, 0), \
955
966
.tx_rx_propagation_max_us = DT_INST_PROP_OR(idx, tx_rx_propagation_max_us, 200), \
967
+ .rx_finish_work_delay_us = DT_INST_PROP_OR(idx, rx_finish_work_delay_us, 800), \
968
+ .rx_capture_work_delay_us = DT_INST_PROP_OR(idx, rx_capture_work_delay_us, 200), \
956
969
}; \
957
970
DEVICE_DT_INST_DEFINE(idx, dali_pwm_init, NULL, &dali_pwm_data_##idx, \
958
971
&dali_pwm_config_##idx, POST_KERNEL, \
0 commit comments