Skip to content

Commit faadf6b

Browse files
author
Sven Hädrich
committed
Fixup - additional parameters for pwm driver
1 parent c9e8506 commit faadf6b

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

drivers/dali/dali_pwm.c

+18-5
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ LOG_MODULE_REGISTER(dali_low_level, CONFIG_DALI_LOW_LEVEL_LOG_LEVEL);
2424
SETTLING_TIME_BACKWARD_FRAME_MAX + \
2525
k_us_to_cyc_floor32(DALI_TX_HALF_BIT_US) * MAX_HALFBIT_TIMES_PER_BACKWARD_FRAME
2626

27-
#define SEND_TWICE_MAX_TIME k_ms_to_cyc_floor32(95)
28-
2927
const uint32_t settling_times_min[] = {
3028
k_us_to_cyc_floor32(DALI_TX_BACKWARD_INTERFRAME_MIN_US), /* Settling time backward min */
3129
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 {
156154
int tx_shift_us;
157155
int rx_shift_us;
158156
unsigned int tx_rx_propagation_max_us;
157+
unsigned int rx_finish_work_delay_us;
158+
unsigned int rx_capture_work_delay_us;
159159
};
160160

161161
/** 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)
168168
/* don't alter anything, if there is no data. */
169169
return;
170170
}
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);
172179
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));
174183
is_send_twice = false;
175184
}
176185

@@ -296,7 +305,9 @@ static void dali_pwm_continuous_capture_callback_locked(uint32_t period_cycles,
296305
/* trigger PWM send */
297306
k_sem_give(&data->tx_pwm_sem);
298307
/* 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;
300311
k_work_reschedule(&data->frame_finish_work, Z_TIMEOUT_US(stopbit_timeout_us));
301312

302313
if (data->timings.rx_flank_shift < 0) {
@@ -953,6 +964,8 @@ static DEVICE_API(dali, dali_pwm_driver_api) = {
953964
.tx_shift_us = DT_INST_PROP_OR(idx, tx_flank_shift_us, 0), \
954965
.rx_shift_us = DT_INST_PROP_OR(idx, rx_flank_shift_us, 0), \
955966
.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), \
956969
}; \
957970
DEVICE_DT_INST_DEFINE(idx, dali_pwm_init, NULL, &dali_pwm_data_##idx, \
958971
&dali_pwm_config_##idx, POST_KERNEL, \

dts/bindings/dali/zephyr,dali-pwm.yaml

+21-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,26 @@ properties:
2929
type: int
3030
required: false
3131
description: |
32-
The maximal time from a transmitted change to read observation.
32+
The maximal time from a transmitted change to read observation.
3333
This value needs to be set for proper collision detection.
3434
The delay is measured in micro seconds.
35+
36+
rx-finish-work-delay-us:
37+
type: int
38+
required: false
39+
description: |
40+
This is the time that elapses from the time the stop bit period has
41+
expired until the corresponding workqueue processing has started.
42+
This time depends on the clockrate and architecture of the target system.
43+
This parameter might need adjustment to pass the test item 3.15 of
44+
the DALI tests. The delay is measured in micro seconds.
45+
46+
rx-capture-work-delay-us:
47+
type: int
48+
required: false
49+
description: |
50+
This is time that elapses from the moment a DALI bus event is
51+
captured until the corresponding workqueue pricessing has started.
52+
This time depends on the clockrate and architecture of the target system.
53+
This parameter might need adjustment to pass the test item 3.14 of
54+
the DALI tests. The delay is measured in micro seconds.

samples/drivers/dali/boards/nucleo_f091rc.overlay

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
tx-flank-shift-us = <(-46)>;
1212
rx-flank-shift-us = <(-56)>;
1313
tx-rx-propagation-max-us = <2400>;
14+
rx-finish-work-delay-us = <1000>;
15+
rx-capture-work-delay-us = <200>;
1416
};
1517
};
1618

0 commit comments

Comments
 (0)