Skip to content

Commit 71f5405

Browse files
committed
drivers: i2c: i2c_mspm0g3xxx: fix watchdog init
start the watchdog timer only before we are about to receive a byte and after we set the ack/nack Signed-off-by: Dimitris Karnikis <[email protected]>
1 parent b6bb7c2 commit 71f5405

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

drivers/i2c/i2c_mspm0g3xxx.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ static void i2c_mspm0g3xxx_target_stop_watchdog(struct i2c_mspm0g3xxx_data *data
131131
}
132132
}
133133

134-
static void i2c_mspm0g3xxx_target_reset(const struct device *dev, uint8_t channel, uint32_t ticks,
134+
static void i2c_mspm0g3xxx_panic(const struct device *dev, uint8_t channel, uint32_t ticks,
135135
void *user_data)
136136
{
137137
struct i2c_mspm0g3xxx_data *data = user_data;
@@ -197,25 +197,22 @@ void i2c_mspm0g3xxx_target_thread_work(void)
197197
if (data->state == I2C_mspm0g3xxx_TARGET_STARTED) {
198198
data->state = I2C_mspm0g3xxx_TARGET_RX_INPROGRESS;
199199
if (tconfig->callbacks->write_requested != NULL) {
200-
i2c_mspm0g3xxx_target_start_watchdog(data);
201200
data->target_rx_valid =
202201
tconfig->callbacks->write_requested(tconfig);
203-
i2c_mspm0g3xxx_target_stop_watchdog(data);
204202
}
205203
}
206204
/* Store received data in buffer */
207205
if (tconfig->callbacks->write_received != NULL) {
208206
uint8_t nextByte;
209207
while (DL_I2C_isTargetRXFIFOEmpty((I2C_Regs *)config->base) !=
210208
true) {
209+
i2c_mspm0g3xxx_target_start_watchdog(data);
211210
if (data->target_rx_valid == 0) {
212211
nextByte = DL_I2C_receiveTargetData(
213212
(I2C_Regs *)config->base);
214-
i2c_mspm0g3xxx_target_start_watchdog(data);
215213
data->target_rx_valid =
216214
tconfig->callbacks->write_received(
217215
tconfig, nextByte);
218-
i2c_mspm0g3xxx_target_stop_watchdog(data);
219216

220217
if (data->target_rx_valid == 0) {
221218
DL_I2C_setTargetACKOverrideValue(
@@ -233,6 +230,7 @@ void i2c_mspm0g3xxx_target_thread_work(void)
233230
(I2C_Regs *)config->base,
234231
DL_I2C_TARGET_RESPONSE_OVERRIDE_VALUE_NACK);
235232
}
233+
i2c_mspm0g3xxx_target_stop_watchdog(data);
236234
}
237235
}
238236

@@ -241,11 +239,10 @@ void i2c_mspm0g3xxx_target_thread_work(void)
241239
data->state = I2C_mspm0g3xxx_TARGET_TX_INPROGRESS;
242240
/* Fill TX FIFO if there are more bytes to send */
243241
if (tconfig->callbacks->read_requested != NULL) {
244-
uint8_t nextByte;
245242
i2c_mspm0g3xxx_target_start_watchdog(data);
243+
uint8_t nextByte;
246244
data->target_tx_valid =
247245
tconfig->callbacks->read_requested(tconfig, &nextByte);
248-
i2c_mspm0g3xxx_target_stop_watchdog(data);
249246
if (data->target_tx_valid == 0) {
250247
DL_I2C_transmitTargetData((I2C_Regs *)config->base,
251248
nextByte);
@@ -254,20 +251,22 @@ void i2c_mspm0g3xxx_target_thread_work(void)
254251
* 0's are transmitted */
255252
DL_I2C_transmitTargetData((I2C_Regs *)config->base, 0x00);
256253
}
254+
255+
i2c_mspm0g3xxx_target_stop_watchdog(data);
257256
}
258257
break;
259258
case DL_I2C_IIDX_TARGET_TXFIFO_EMPTY:
260259
if (tconfig->callbacks->read_processed != NULL) {
260+
i2c_mspm0g3xxx_target_start_watchdog(data);
261261
/* still using the FIFO, we call read_processed in order to add
262262
* additional data rather than from a buffer. If the write-received
263263
* function chooses to return 0 (no more data present), then 0's
264264
* will be filled in */
265265
uint8_t nextByte;
266+
266267
if (data->target_tx_valid == 0) {
267-
i2c_mspm0g3xxx_target_start_watchdog(data);
268268
data->target_tx_valid = tconfig->callbacks->read_processed(
269269
tconfig, &nextByte);
270-
i2c_mspm0g3xxx_target_stop_watchdog(data);
271270
}
272271

273272
if (data->target_tx_valid == 0) {
@@ -278,15 +277,15 @@ void i2c_mspm0g3xxx_target_thread_work(void)
278277
* 0's are transmitted */
279278
DL_I2C_transmitTargetData((I2C_Regs *)config->base, 0x00);
280279
}
280+
281+
i2c_mspm0g3xxx_target_stop_watchdog(data);
281282
}
282283
break;
283284
case DL_I2C_IIDX_TARGET_STOP:
284285
data->state = I2C_mspm0g3xxx_IDLE;
285286
k_sem_give(&data->i2c_busy_sem);
286287
if (tconfig->callbacks->stop) {
287-
i2c_mspm0g3xxx_target_start_watchdog(data);
288288
tconfig->callbacks->stop(tconfig);
289-
i2c_mspm0g3xxx_target_stop_watchdog(data);
290289
}
291290
break;
292291
default:
@@ -847,7 +846,7 @@ static int i2c_mspm0g3xxx_init(const struct device *dev)
847846
}
848847

849848
data->watchdog_timer_cfg.user_data = (void *)data;
850-
data->watchdog_timer_cfg.callback = i2c_mspm0g3xxx_target_reset;
849+
data->watchdog_timer_cfg.callback = i2c_mspm0g3xxx_panic;
851850
data->watchdog_timer_cfg.ticks = counter_us_to_ticks(
852851
config->watchdog_timer, CONFIG_I2C_MSPM0G3XXX_WATCHDOG_TIMEOUT);
853852
}

0 commit comments

Comments
 (0)