[libcamera-devel] [PATCH 5/5] ipa: vimc: Add support for test back channel

Jacopo Mondi jacopo at jmondi.org
Thu Oct 3 17:20:37 CEST 2019


Add support to the dummy VIMC IPA for communication with the IPA
interface test unit.

Use the test channel, if available, to send a confirmation code when
the init() operation is called.

Signed-off-by: Jacopo Mondi <jacopo at jmondi.org>
---
 src/ipa/ipa_vimc.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)

diff --git a/src/ipa/ipa_vimc.cpp b/src/ipa/ipa_vimc.cpp
index abc06e7f5fd5..781f5796b082 100644
--- a/src/ipa/ipa_vimc.cpp
+++ b/src/ipa/ipa_vimc.cpp
@@ -7,20 +7,74 @@
 
 #include <iostream>
 
+#include <fcntl.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
 #include <ipa/ipa_interface.h>
 #include <ipa/ipa_module_info.h>
 
 namespace libcamera {
 
+/* Keep these in sync with the IPA Interface test unit. */
+static const char *vimcFifoPath = "/tmp/vimc_ipa_fifo";
+#define IPA_INIT_CODE 0x01
+
 class IPAVimc : public IPAInterface
 {
 public:
+	IPAVimc();
+	~IPAVimc();
+
 	int init();
+
+private:
+	unsigned int fd_;
 };
 
+IPAVimc::IPAVimc()
+	: fd_(0)
+{
+	/* Set up the test unit back-channel, if available. */
+	struct stat fifoStat;
+	int ret = stat(vimcFifoPath, &fifoStat);
+	if (ret)
+		return;
+
+	ret = ::open(vimcFifoPath, O_WRONLY);
+	if (ret < 0) {
+		std::cerr << "Failed to open vimc IPA test fifo at: "
+			  << vimcFifoPath << ": " << strerror(errno)
+			  << std::endl;
+		return;
+	}
+	fd_ = ret;
+}
+
+IPAVimc::~IPAVimc()
+{
+	if (fd_)
+		::close(fd_);
+}
+
 int IPAVimc::init()
 {
 	std::cout << "initializing vimc IPA!" << std::endl;
+
+	if (!fd_)
+		return 0;
+
+	int8_t data = IPA_INIT_CODE;
+	int ret = ::write(fd_, &data, 1);
+	if (ret < 0) {
+		ret = -errno;
+		std::cerr << "Failed to write to vimc IPA test fifo at: "
+			  << vimcFifoPath << ": " << strerror(-ret)
+			  << std::endl;
+		return ret;
+	}
+
 	return 0;
 }
 
-- 
2.23.0



More information about the libcamera-devel mailing list