Skip to content

Commit

Permalink
mraa: Add patch to enable explicit cleanup of resources
Browse files Browse the repository at this point in the history
Enables proper node-red node teardown.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
  • Loading branch information
jan-kiszka committed Nov 27, 2020
1 parent 6ffa9e2 commit 633a77e
Show file tree
Hide file tree
Showing 5 changed files with 265 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 7606faa9af13de293be17fafc1600b8df8999775 Mon Sep 17 00:00:00 2001
From 3de416751128a725c2d7e11a69dd6ae55e797291 Mon Sep 17 00:00:00 2001
From: "le.jin" <le.jin@siemens.com>
Date: Fri, 1 Nov 2019 18:02:54 +0800
Subject: [PATCH 1/3] aio.c: fix mraa_aio_set_bit for result scaling
Subject: [PATCH 1/4] aio.c: fix mraa_aio_set_bit for result scaling

Signed-off-by: le.jin <le.jin@siemens.com>
---
Expand All @@ -28,5 +28,5 @@ index 48a390b..b1e0478 100644
}

--
2.22.0
2.26.2

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 28e96d6f9da99dcff425df4e0cb87401c02dde31 Mon Sep 17 00:00:00 2001
From 6385b47325d8266d032a963ff73eec86b59b5dee Mon Sep 17 00:00:00 2001
From: "le.jin" <le.jin@siemens.com>
Date: Fri, 24 May 2019 14:33:42 +0800
Subject: [PATCH 2/3] feat:iot2050:add iot2050 platform support
Subject: [PATCH 2/4] feat:iot2050:add iot2050 platform support

Add new iot2050 platform support with some modifications
due to lack of support with register level pin mux hooks.
Expand Down Expand Up @@ -2193,5 +2193,5 @@ index da28c65..c4cd5fd 100644
syslog(LOG_ERR, "uart%i: set_timeout: tcsetattr() failed: %s", dev->index, strerror(errno));
return MRAA_ERROR_FEATURE_NOT_SUPPORTED;
--
2.22.0
2.26.2

Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
From a387d2954da4ee92187b88c22d91f30d7dfe2e65 Mon Sep 17 00:00:00 2001
From 953c82e926ff5419cbf61ba73ac67fd680cf0c1a Mon Sep 17 00:00:00 2001
From: "le.jin" <le.jin@siemens.com>
Date: Tue, 18 Jun 2019 16:16:02 +0800
Subject: [PATCH 3/3] feat:iot2050:add some example code for testing
Subject: [PATCH 3/4] feat:iot2050:add some example code for testing

Signed-off-by: le.jin <le.jin@siemens.com>
---
examples/platform/CMakeLists.txt | 12 ++++
examples/platform/aio_iot2050.c | 95 ++++++++++++++++++++++++++++
examples/platform/led_iot2050.c | 81 ++++++++++++++++++++++++
examples/platform/pwm_iot2050.c | 105 +++++++++++++++++++++++++++++++
examples/platform/spi_iot2050.c | 82 ++++++++++++++++++++++++
examples/platform/aio_iot2050.c | 95 ++++++++++++++++++++++++++++
examples/platform/led_iot2050.c | 81 ++++++++++++++++++++++++
examples/platform/pwm_iot2050.c | 105 +++++++++++++++++++++++++++++++
examples/platform/spi_iot2050.c | 82 ++++++++++++++++++++++++
5 files changed, 375 insertions(+)
create mode 100644 examples/platform/aio_iot2050.c
create mode 100644 examples/platform/led_iot2050.c
create mode 100644 examples/platform/pwm_iot2050.c
create mode 100644 examples/platform/spi_iot2050.c

diff --git a/examples/platform/CMakeLists.txt b/examples/platform/CMakeLists.txt
index 08b7bb4..b283a0d 100644
index 08b7bb4..b03ce8d 100644
--- a/examples/platform/CMakeLists.txt
+++ b/examples/platform/CMakeLists.txt
@@ -4,6 +4,18 @@ target_link_libraries (gpio_edison mraa)
Expand Down Expand Up @@ -428,5 +428,5 @@ index 0000000..81d0171
+}
\ No newline at end of file
--
2.22.0
2.26.2

Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
From 28b3c1966212b9497d99681c331ec0ae483c9814 Mon Sep 17 00:00:00 2001
From: Jan Kiszka <jan.kiszka@siemens.com>
Date: Fri, 27 Nov 2020 07:26:50 +0100
Subject: [PATCH 4/4] api: Add explicit close methods to classes

This is needed for bindings to languages which perform implicit and lazy
object cleanups. The explicit close methods allow to release resources
when they are no longer required, permitting deterministic reuse. One
example is node-red-node-intel-gpio which will use the new calls on node
closing.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
api/mraa/aio.hpp | 11 +++++++++++
api/mraa/gpio.hpp | 11 +++++++++++
api/mraa/i2c.hpp | 12 ++++++++++++
api/mraa/iio.hpp | 13 ++++++++++++-
api/mraa/led.hpp | 12 ++++++++++++
api/mraa/pwm.hpp | 11 +++++++++++
api/mraa/spi.hpp | 12 ++++++++++++
api/mraa/uart.hpp | 12 ++++++++++++
api/mraa/uart_ow.hpp | 12 ++++++++++++
9 files changed, 105 insertions(+), 1 deletion(-)

diff --git a/api/mraa/aio.hpp b/api/mraa/aio.hpp
index 75c45bf..4e0272e 100644
--- a/api/mraa/aio.hpp
+++ b/api/mraa/aio.hpp
@@ -73,8 +73,19 @@ class Aio
* Aio destructor
*/
~Aio()
+ {
+ if (m_aio != NULL) {
+ mraa_aio_close(m_aio);
+ }
+ }
+ /**
+ * Closes AIO explicitly, prior to implicit closing on object destruction
+ */
+ void
+ close()
{
mraa_aio_close(m_aio);
+ m_aio = NULL;
}
/**
* Read a value from the AIO pin. By default mraa will shift
diff --git a/api/mraa/gpio.hpp b/api/mraa/gpio.hpp
index 909ca43..2b5d798 100644
--- a/api/mraa/gpio.hpp
+++ b/api/mraa/gpio.hpp
@@ -141,8 +141,19 @@ class Gpio
* the owner
*/
~Gpio()
+ {
+ if (m_gpio != NULL) {
+ mraa_gpio_close(m_gpio);
+ }
+ }
+ /**
+ * Closes Gpio explicitly, prior to implicit closing on object destruction
+ */
+ void
+ close()
{
mraa_gpio_close(m_gpio);
+ m_gpio = NULL;
}
/**
* Set the edge mode for ISR
diff --git a/api/mraa/i2c.hpp b/api/mraa/i2c.hpp
index e0ea945..c666d42 100644
--- a/api/mraa/i2c.hpp
+++ b/api/mraa/i2c.hpp
@@ -81,8 +81,20 @@ class I2c
* slaves.
*/
~I2c()
+ {
+ if (m_i2c != NULL) {
+ mraa_i2c_stop(m_i2c);
+ }
+ }
+
+ /**
+ * Closes I2c explicitly, prior to implicit closing on object destruction
+ */
+ void
+ close()
{
mraa_i2c_stop(m_i2c);
+ m_i2c = NULL;
}

/**
diff --git a/api/mraa/iio.hpp b/api/mraa/iio.hpp
index ec3090f..a0051fa 100644
--- a/api/mraa/iio.hpp
+++ b/api/mraa/iio.hpp
@@ -129,9 +129,20 @@ class Iio
*/
~Iio()
{
- mraa_iio_close(m_iio);
+ if (m_iio != NULL) {
+ mraa_iio_close(m_iio);
+ }
}

+ /**
+ * Closes Iio explicitly, prior to implicit closing on object destruction
+ */
+ void
+ close()
+ {
+ mraa_iio_close(m_iio);
+ m_iio = NULL;
+ }

/**
* Get device name
diff --git a/api/mraa/led.hpp b/api/mraa/led.hpp
index dcbc37a..316198a 100644
--- a/api/mraa/led.hpp
+++ b/api/mraa/led.hpp
@@ -87,8 +87,20 @@ class Led
* LED object destructor
*/
~Led()
+ {
+ if (m_led != NULL) {
+ mraa_led_close(m_led);
+ }
+ }
+
+ /*
+ * Closes LED explicitly, prior to implicit closing on object destruction
+ */
+ void
+ close()
{
mraa_led_close(m_led);
+ m_led = NULL;
}

/**
diff --git a/api/mraa/pwm.hpp b/api/mraa/pwm.hpp
index 494541b..f25661d 100644
--- a/api/mraa/pwm.hpp
+++ b/api/mraa/pwm.hpp
@@ -84,8 +84,19 @@ class Pwm
* Pwm destructor
*/
~Pwm()
+ {
+ if (m_pwm != NULL) {
+ mraa_pwm_close(m_pwm);
+ }
+ }
+ /*
+ * Closes Pwm explicitly, prior to implicit closing on object destruction
+ */
+ void
+ close()
{
mraa_pwm_close(m_pwm);
+ m_pwm = NULL;
}
/**
* Set the output duty-cycle percentage, as a float
diff --git a/api/mraa/spi.hpp b/api/mraa/spi.hpp
index 855d389..339f4b0 100644
--- a/api/mraa/spi.hpp
+++ b/api/mraa/spi.hpp
@@ -103,8 +103,20 @@ class Spi
* Closes spi bus
*/
~Spi()
+ {
+ if (m_spi != NULL) {
+ mraa_spi_stop(m_spi);
+ }
+ }
+
+ /**
+ * Closes Spi explicitly, prior to implicit closing on object destruction
+ */
+ void
+ close()
{
mraa_spi_stop(m_spi);
+ m_spi = NULL;
}

/**
diff --git a/api/mraa/uart.hpp b/api/mraa/uart.hpp
index c7b217e..4a1bad4 100644
--- a/api/mraa/uart.hpp
+++ b/api/mraa/uart.hpp
@@ -93,8 +93,20 @@ class Uart
* Uart destructor
*/
~Uart()
+ {
+ if (m_uart != NULL) {
+ mraa_uart_stop(m_uart);
+ }
+ }
+
+ /*
+ * Closes Uart explicitly, prior to implicit closing on object destruction
+ */
+ void
+ close()
{
mraa_uart_stop(m_uart);
+ m_uart = NULL;
}

/**
diff --git a/api/mraa/uart_ow.hpp b/api/mraa/uart_ow.hpp
index 2d7b459..222f6fb 100644
--- a/api/mraa/uart_ow.hpp
+++ b/api/mraa/uart_ow.hpp
@@ -93,8 +93,20 @@ class UartOW
* Uart destructor
*/
~UartOW()
+ {
+ if (m_uart != NULL) {
+ mraa_uart_ow_stop(m_uart);
+ }
+ }
+
+ /*
+ * Closes UartOW explicitly, prior to implicit closing on object destruction
+ */
+ void
+ close()
{
mraa_uart_ow_stop(m_uart);
+ m_uart = NULL;
}

/**
--
2.26.2

Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ SRC_URI += "git://github.com/intel-iot-devkit/mraa.git;protocol=https;branch=${M
file://0001-aio.c-fix-mraa_aio_set_bit-for-result-scaling.patch \
file://0002-feat-iot2050-add-iot2050-platform-support.patch \
file://0003-feat-iot2050-add-some-example-code-for-testing.patch \
file://0004-api-Add-explicit-close-methods-to-classes.patch \
file://rules"
SRC_URI[sha256sum] = "15783b4c4431a36d44ba95daf134318a04ff44a8190ba3f19abbda89ede35a26"
MRAA_BRANCH = "master"
MRAA_REV = "967585c9ea0e1a8818d2172d2395d8502f6180a2"

S = "${WORKDIR}/git"
PV = "2.0"

MRAA_BUILD_SWIG30_PATCH_FILE = "0001-Add-Node-7.x-aka-V8-5.2-support.patch"
MRAA_BUILD_SWIG30_DIR = "${BUILDCHROOT_HOST_DIR}/usr/share/swig3.0"
Expand Down

0 comments on commit 633a77e

Please sign in to comment.