[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH v2 01/23] fifo32: add peek function
From: |
Octavian Purdila |
Subject: |
[RFC PATCH v2 01/23] fifo32: add peek function |
Date: |
Sat, 17 Aug 2024 03:25:44 -0700 |
Add fifo32_peek() that returns the first element from the queue
without popping it.
Signed-off-by: Octavian Purdila <tavip@google.com>
---
include/qemu/fifo32.h | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/include/qemu/fifo32.h b/include/qemu/fifo32.h
index 4e9fd1b5ef..77aab488ae 100644
--- a/include/qemu/fifo32.h
+++ b/include/qemu/fifo32.h
@@ -140,6 +140,34 @@ static inline uint32_t fifo32_pop(Fifo32 *fifo)
return ret;
}
+/**
+ * fifo32_peek:
+ * @fifo: fifo to peek at
+ *
+ * Returns the value from the FIFO's head without poping it. Behaviour
+ * is undefined if the FIFO is empty. Clients are responsible for
+ * checking for emptiness using fifo32_is_empty().
+ *
+ * Returns: the value from the FIFO's head
+ */
+
+static inline uint32_t fifo32_peek(Fifo32 *fifo)
+{
+ uint32_t ret = 0, num;
+ const uint8_t *buf;
+
+ buf = fifo8_peek_buf(&fifo->fifo, 4, &num);
+ if (num != 4) {
+ return ret;
+ }
+
+ for (int i = 0; i < sizeof(uint32_t); i++) {
+ ret |= buf[i] << (i * 8);
+ }
+
+ return ret;
+}
+
/**
* There is no fifo32_pop_buf() because the data is not stored in the buffer
* as a set of native-order words.
--
2.46.0.184.g6999bdac58-goog
- [RFC PATCH v2 00/23] NXP i.MX RT595, ARM SVD and device model unit tests, Octavian Purdila, 2024/08/17
- [RFC PATCH v2 02/23] tests/unit: add fifo test, Octavian Purdila, 2024/08/17
- [RFC PATCH v2 01/23] fifo32: add peek function,
Octavian Purdila <=
- [RFC PATCH v2 05/23] hw: add register access utility functions, Octavian Purdila, 2024/08/17
- [RFC PATCH v2 03/23] scripts: add script to generate C header files from SVD XML files, Octavian Purdila, 2024/08/17
- [RFC PATCH v2 10/23] hw/char: add support for flexcomm usart, Octavian Purdila, 2024/08/17
- [RFC PATCH v2 04/23] Add mcux-soc-svd subproject, Octavian Purdila, 2024/08/17
- [RFC PATCH v2 13/23] test/unit: add i2c-tester, Octavian Purdila, 2024/08/17
- [RFC PATCH v2 09/23] test/unit: add flexcomm unit test, Octavian Purdila, 2024/08/17
- [RFC PATCH v2 11/23] test/unit: add flexcomm usart unit test, Octavian Purdila, 2024/08/17
- [RFC PATCH v2 06/23] hw/misc: add basic flexcomm device model, Octavian Purdila, 2024/08/17
- [RFC PATCH v2 08/23] test/unit: add register access macros and functions, Octavian Purdila, 2024/08/17
- [RFC PATCH v2 07/23] tests/unit: add system bus mock, Octavian Purdila, 2024/08/17