[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 6/7] hw/sd: Add sdbus_read_data() to read multiples bytes on the
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH 6/7] hw/sd: Add sdbus_read_data() to read multiples bytes on the data line |
Date: |
Fri, 14 Aug 2020 11:23:45 +0200 |
Add a sdbus_read_data() method to read multiple bytes on the
data line of a SD bus.
We might improve the tracing later, for now keep logging each
byte individually.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
include/hw/sd/sd.h | 9 +++++++++
hw/sd/core.c | 15 +++++++++++++++
2 files changed, 24 insertions(+)
diff --git a/include/hw/sd/sd.h b/include/hw/sd/sd.h
index 3ae3e8939b..ac02d61a7a 100644
--- a/include/hw/sd/sd.h
+++ b/include/hw/sd/sd.h
@@ -184,6 +184,15 @@ uint8_t sdbus_read_byte(SDBus *sd);
* Write multiple bytes of data on the data lines of a SD bus.
*/
void sdbus_write_data(SDBus *sdbus, const void *buf, size_t length);
+/**
+ * Read data from a SD bus.
+ * @sdbus: bus
+ * @buf: buffer to read data into
+ * @length: number of bytes to read
+ *
+ * Read multiple bytes of data on the data lines of a SD bus.
+ */
+void sdbus_read_data(SDBus *sdbus, void *buf, size_t length);
bool sdbus_data_ready(SDBus *sd);
bool sdbus_get_inserted(SDBus *sd);
bool sdbus_get_readonly(SDBus *sd);
diff --git a/hw/sd/core.c b/hw/sd/core.c
index 9c2781ebf9..957d116f1a 100644
--- a/hw/sd/core.c
+++ b/hw/sd/core.c
@@ -144,6 +144,21 @@ uint8_t sdbus_read_byte(SDBus *sdbus)
return value;
}
+void sdbus_read_data(SDBus *sdbus, void *buf, size_t length)
+{
+ SDState *card = get_card(sdbus);
+ uint8_t *data = buf;
+
+ if (card) {
+ SDCardClass *sc = SD_CARD_GET_CLASS(card);
+
+ for (size_t i = 0; i < length; i++) {
+ data[i] = sc->read_byte(card);
+ trace_sdbus_read(sdbus_name(sdbus), data[i]);
+ }
+ }
+}
+
bool sdbus_data_ready(SDBus *sdbus)
{
SDState *card = get_card(sdbus);
--
2.21.3
- [PATCH 0/7] hw/sd: Use sdbus_read_data/sdbus_write_data for multiple bytes access, Philippe Mathieu-Daudé, 2020/08/14
- [PATCH 1/7] hw/sd: Rename read/write_data() as read/write_byte(), Philippe Mathieu-Daudé, 2020/08/14
- [PATCH 2/7] hw/sd: Rename sdbus_write_data() as sdbus_write_byte(), Philippe Mathieu-Daudé, 2020/08/14
- [PATCH 4/7] hw/sd: Add sdbus_write_data() to write multiples bytes on the data line, Philippe Mathieu-Daudé, 2020/08/14
- [PATCH 3/7] hw/sd: Rename sdbus_read_data() as sdbus_read_byte(), Philippe Mathieu-Daudé, 2020/08/14
- [PATCH 5/7] hw/sd: Use sdbus_write_data() instead of sdbus_write_byte when possible, Philippe Mathieu-Daudé, 2020/08/14
- [PATCH 6/7] hw/sd: Add sdbus_read_data() to read multiples bytes on the data line,
Philippe Mathieu-Daudé <=
- [PATCH 7/7] hw/sd: Use sdbus_read_data() instead of sdbus_read_byte() when possible, Philippe Mathieu-Daudé, 2020/08/14
- Re: [PATCH 0/7] hw/sd: Use sdbus_read_data/sdbus_write_data for multiple bytes access, Richard Henderson, 2020/08/14
- Re: [PATCH 0/7] hw/sd: Use sdbus_read_data/sdbus_write_data for multiple bytes access, Philippe Mathieu-Daudé, 2020/08/21