[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 06/26] hw/i2c/bitbang_i2c: Trace state changes
From: |
Peter Maydell |
Subject: |
[PULL 06/26] hw/i2c/bitbang_i2c: Trace state changes |
Date: |
Mon, 23 Jan 2023 13:35:33 +0000 |
From: Philippe Mathieu-Daudé <philmd@linaro.org>
Trace bitbang state machine changes with trace events.
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Acked-by: Corey Minyard <cminyard@mvista.com>
Message-id: 20230111085016.44551-5-philmd@linaro.org
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/i2c/bitbang_i2c.c | 33 ++++++++++++++++++++++++++++-----
hw/i2c/trace-events | 3 +++
2 files changed, 31 insertions(+), 5 deletions(-)
diff --git a/hw/i2c/bitbang_i2c.c b/hw/i2c/bitbang_i2c.c
index bf4b781393d..efc49b7502f 100644
--- a/hw/i2c/bitbang_i2c.c
+++ b/hw/i2c/bitbang_i2c.c
@@ -16,6 +16,7 @@
#include "hw/sysbus.h"
#include "qemu/module.h"
#include "qom/object.h"
+#include "trace.h"
//#define DEBUG_BITBANG_I2C
@@ -26,15 +27,41 @@ do { printf("bitbang_i2c: " fmt , ## __VA_ARGS__); } while
(0)
#define DPRINTF(fmt, ...) do {} while(0)
#endif
+/* bitbang_i2c_state enum to name */
+static const char * const sname[] = {
+#define NAME(e) [e] = stringify(e)
+ NAME(STOPPED),
+ [SENDING_BIT7] = "SENDING_BIT7 (START)",
+ NAME(SENDING_BIT6),
+ NAME(SENDING_BIT5),
+ NAME(SENDING_BIT4),
+ NAME(SENDING_BIT3),
+ NAME(SENDING_BIT2),
+ NAME(SENDING_BIT1),
+ NAME(SENDING_BIT0),
+ NAME(WAITING_FOR_ACK),
+ [RECEIVING_BIT7] = "RECEIVING_BIT7 (ACK)",
+ NAME(RECEIVING_BIT6),
+ NAME(RECEIVING_BIT5),
+ NAME(RECEIVING_BIT4),
+ NAME(RECEIVING_BIT3),
+ NAME(RECEIVING_BIT2),
+ NAME(RECEIVING_BIT1),
+ NAME(RECEIVING_BIT0),
+ NAME(SENDING_ACK),
+ NAME(SENT_NACK)
+#undef NAME
+};
+
static void bitbang_i2c_set_state(bitbang_i2c_interface *i2c,
bitbang_i2c_state state)
{
+ trace_bitbang_i2c_state(sname[i2c->state], sname[state]);
i2c->state = state;
}
static void bitbang_i2c_enter_stop(bitbang_i2c_interface *i2c)
{
- DPRINTF("STOP\n");
if (i2c->current_addr >= 0)
i2c_end_transfer(i2c->bus);
i2c->current_addr = -1;
@@ -73,7 +100,6 @@ int bitbang_i2c_set(bitbang_i2c_interface *i2c, int line,
int level)
return bitbang_i2c_nop(i2c);
}
if (level == 0) {
- DPRINTF("START\n");
/* START condition. */
bitbang_i2c_set_state(i2c, SENDING_BIT7);
i2c->current_addr = -1;
@@ -122,7 +148,6 @@ int bitbang_i2c_set(bitbang_i2c_interface *i2c, int line,
int level)
/* NACK (either addressing a nonexistent device, or the
* device we were sending to decided to NACK us).
*/
- DPRINTF("Got NACK\n");
bitbang_i2c_set_state(i2c, SENT_NACK);
bitbang_i2c_enter_stop(i2c);
return bitbang_i2c_ret(i2c, 1);
@@ -147,11 +172,9 @@ int bitbang_i2c_set(bitbang_i2c_interface *i2c, int line,
int level)
case SENDING_ACK:
if (data != 0) {
- DPRINTF("NACKED\n");
bitbang_i2c_set_state(i2c, SENT_NACK);
i2c_nack(i2c->bus);
} else {
- DPRINTF("ACKED\n");
bitbang_i2c_set_state(i2c, RECEIVING_BIT7);
}
return bitbang_i2c_ret(i2c, 1);
diff --git a/hw/i2c/trace-events b/hw/i2c/trace-events
index 52dbd53a234..48aee4887c4 100644
--- a/hw/i2c/trace-events
+++ b/hw/i2c/trace-events
@@ -1,5 +1,8 @@
# See docs/devel/tracing.rst for syntax documentation.
+# bitbang_i2c.c
+bitbang_i2c_state(const char *old_state, const char *new_state) "state %s ->
%s"
+
# core.c
i2c_event(const char *event, uint8_t address) "%s(addr:0x%02x)"
--
2.34.1
- [PULL 11/26] hw/i2c/versatile_i2c: Use ARM_SBCON_I2C() macro, (continued)
- [PULL 11/26] hw/i2c/versatile_i2c: Use ARM_SBCON_I2C() macro, Peter Maydell, 2023/01/23
- [PULL 19/26] target/arm/sme: Unify set_pstate() SM/ZA helpers as set_svcr(), Peter Maydell, 2023/01/23
- [PULL 22/26] target/arm: Don't set EXC_RETURN.ES if Security Extension not present, Peter Maydell, 2023/01/23
- [PULL 16/26] target/arm/sme: Reset SVE state in aarch64_set_svcr(), Peter Maydell, 2023/01/23
- [PULL 21/26] target/arm: Fix in_debug path in S1_ptw_translate, Peter Maydell, 2023/01/23
- [PULL 18/26] target/arm/sme: Rebuild hflags in aarch64_set_svcr(), Peter Maydell, 2023/01/23
- [PULL 02/26] target/arm: Unify checking for M Main Extension in MRS/MSR, Peter Maydell, 2023/01/23
- [PULL 03/26] hw/i2c/bitbang_i2c: Define TYPE_GPIO_I2C in public header, Peter Maydell, 2023/01/23
- [PULL 04/26] hw/i2c/bitbang_i2c: Remove unused dummy MemoryRegion, Peter Maydell, 2023/01/23
- [PULL 08/26] hw/i2c/versatile_i2c: Drop useless casts from void * to pointer, Peter Maydell, 2023/01/23
- [PULL 06/26] hw/i2c/bitbang_i2c: Trace state changes,
Peter Maydell <=
- [PULL 10/26] hw/i2c/versatile_i2c: Replace TYPE_VERSATILE_I2C -> TYPE_ARM_SBCON_I2C, Peter Maydell, 2023/01/23
- [PULL 05/26] hw/i2c/bitbang_i2c: Change state calling bitbang_i2c_set_state() helper, Peter Maydell, 2023/01/23
- [PULL 12/26] hw/i2c/versatile_i2c: Rename versatile_i2c -> arm_sbcon_i2c, Peter Maydell, 2023/01/23
- [PULL 17/26] target/arm/sme: Reset ZA state in aarch64_set_svcr(), Peter Maydell, 2023/01/23
- [PULL 23/26] target/arm: implement DBGCLAIM registers, Peter Maydell, 2023/01/23
- [PULL 20/26] target/arm: Fix physical address resolution for MTE, Peter Maydell, 2023/01/23
- [PULL 25/26] target/arm: Reorg do_coproc_insn, Peter Maydell, 2023/01/23
- [PULL 14/26] target/arm/sme: Rebuild hflags in set_pstate() helpers, Peter Maydell, 2023/01/23
- [PULL 13/26] target/arm/sme: Reorg SME access handling in handle_msr_i(), Peter Maydell, 2023/01/23
- [PULL 24/26] target/arm: provide stubs for more external debug registers, Peter Maydell, 2023/01/23