kasjer commented on a change in pull request #2286:
URL: https://github.com/apache/mynewt-core/pull/2286#discussion_r432821159



##########
File path: sys/memfault/src/memfault_platform_core.c
##########
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "sysinit/sysinit.h"
+#include "os/os.h"
+
+#include "memfault/core/debug_log.h"
+#include "memfault/core/event_storage.h"
+#include "memfault/core/trace_event.h"
+#include "memfault/metrics/metrics.h"
+#include "memfault/metrics/platform/timer.h"
+#include "memfault/panics/reboot_tracking.h"
+#include "memfault/panics/platform/coredump.h"
+
+#include "memfault_common.h"
+
+/* Your .ld file:
+ * MEMORY
+ * {
+ *     [...]
+ *     NOINIT (rw) :  ORIGIN = <RAM_REGION_END>, LENGTH = 64
+ * }
+ * SECTIONS
+ * {
+ *     .noinit (NOLOAD): { KEEP(*(*.mflt_reboot_info)) } > NOINIT
+ * }
+ */
+static uint8_t s_reboot_tracking[MEMFAULT_REBOOT_TRACKING_REGION_SIZE]
+    __attribute__((section(".mflt_reboot_info")));
+
+static struct os_callout metrics_callout;
+static uint32_t metrics_period_sec;
+static MemfaultPlatformTimerCallback *metrics_callback;
+
+static void
+metrics_callout_cb(struct os_event *ev)
+{
+    if (metrics_callback) {
+        metrics_callback();
+    }
+    os_callout_reset(&metrics_callout,
+                     os_time_ms_to_ticks32(metrics_period_sec * 1000));
+}
+
+void
+memfault_platform_halt_if_debugging(void)
+{
+    if (hal_debugger_connected()) {
+        __asm("bkpt");
+    }
+}
+
+void
+memfault_platform_reboot(void)
+{
+    os_reboot(HAL_RESET_REQUESTED);
+    MEMFAULT_UNREACHABLE;
+}
+
+bool
+memfault_platform_metrics_timer_boot(uint32_t period_sec,
+                                     MemfaultPlatformTimerCallback callback)
+{
+    metrics_period_sec = period_sec;
+    metrics_callback = callback;
+    metrics_callout_cb(NULL);
+    return true;
+}
+
+uint64_t
+memfault_platform_get_time_since_boot_ms(void)
+{
+    return (uint64_t) (os_get_uptime_usec() / 1000);

Review comment:
       case here seems superfluous

##########
File path: sys/memfault/src/memfault_platform_core.c
##########
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "sysinit/sysinit.h"
+#include "os/os.h"
+
+#include "memfault/core/debug_log.h"
+#include "memfault/core/event_storage.h"
+#include "memfault/core/trace_event.h"
+#include "memfault/metrics/metrics.h"
+#include "memfault/metrics/platform/timer.h"
+#include "memfault/panics/reboot_tracking.h"
+#include "memfault/panics/platform/coredump.h"
+
+#include "memfault_common.h"
+
+/* Your .ld file:
+ * MEMORY
+ * {
+ *     [...]
+ *     NOINIT (rw) :  ORIGIN = <RAM_REGION_END>, LENGTH = 64
+ * }
+ * SECTIONS
+ * {
+ *     .noinit (NOLOAD): { KEEP(*(*.mflt_reboot_info)) } > NOINIT
+ * }
+ */
+static uint8_t s_reboot_tracking[MEMFAULT_REBOOT_TRACKING_REGION_SIZE]
+    __attribute__((section(".mflt_reboot_info")));
+
+static struct os_callout metrics_callout;
+static uint32_t metrics_period_sec;
+static MemfaultPlatformTimerCallback *metrics_callback;
+
+static void
+metrics_callout_cb(struct os_event *ev)
+{
+    if (metrics_callback) {
+        metrics_callback();
+    }
+    os_callout_reset(&metrics_callout,
+                     os_time_ms_to_ticks32(metrics_period_sec * 1000));
+}
+
+void
+memfault_platform_halt_if_debugging(void)
+{
+    if (hal_debugger_connected()) {
+        __asm("bkpt");
+    }
+}
+
+void
+memfault_platform_reboot(void)
+{
+    os_reboot(HAL_RESET_REQUESTED);
+    MEMFAULT_UNREACHABLE;
+}
+
+bool
+memfault_platform_metrics_timer_boot(uint32_t period_sec,
+                                     MemfaultPlatformTimerCallback callback)
+{
+    metrics_period_sec = period_sec;
+    metrics_callback = callback;
+    metrics_callout_cb(NULL);
+    return true;
+}
+
+uint64_t
+memfault_platform_get_time_since_boot_ms(void)
+{
+    return (uint64_t) (os_get_uptime_usec() / 1000);
+}
+
+void
+memfault_platform_core_init(void)
+{
+    static uint8_t s_event_storage[MYNEWT_VAL(MEMFAULT_EVENT_STORAGE_SIZE)];
+    int rc;
+
+    SYSINIT_ASSERT_ACTIVE();
+    os_callout_init(&metrics_callout, os_eventq_dflt_get(),
+                    metrics_callout_cb, NULL);
+    SYSINIT_PANIC_ASSERT(metrics_callout.c_evq != NULL);
+
+    const sResetBootupInfo reset_reason = {

Review comment:
       variables are declared all over the place in this function

##########
File path: sys/memfault/src/memfault_platform_core.c
##########
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "sysinit/sysinit.h"
+#include "os/os.h"
+
+#include "memfault/core/debug_log.h"
+#include "memfault/core/event_storage.h"
+#include "memfault/core/trace_event.h"
+#include "memfault/metrics/metrics.h"
+#include "memfault/metrics/platform/timer.h"
+#include "memfault/panics/reboot_tracking.h"
+#include "memfault/panics/platform/coredump.h"
+
+#include "memfault_common.h"
+
+/* Your .ld file:
+ * MEMORY
+ * {
+ *     [...]
+ *     NOINIT (rw) :  ORIGIN = <RAM_REGION_END>, LENGTH = 64
+ * }
+ * SECTIONS
+ * {
+ *     .noinit (NOLOAD): { KEEP(*(*.mflt_reboot_info)) } > NOINIT
+ * }
+ */
+static uint8_t s_reboot_tracking[MEMFAULT_REBOOT_TRACKING_REGION_SIZE]
+    __attribute__((section(".mflt_reboot_info")));
+
+static struct os_callout metrics_callout;
+static uint32_t metrics_period_sec;
+static MemfaultPlatformTimerCallback *metrics_callback;
+
+static void
+metrics_callout_cb(struct os_event *ev)
+{
+    if (metrics_callback) {
+        metrics_callback();
+    }
+    os_callout_reset(&metrics_callout,
+                     os_time_ms_to_ticks32(metrics_period_sec * 1000));
+}
+
+void
+memfault_platform_halt_if_debugging(void)
+{
+    if (hal_debugger_connected()) {
+        __asm("bkpt");
+    }
+}
+
+void
+memfault_platform_reboot(void)
+{
+    os_reboot(HAL_RESET_REQUESTED);
+    MEMFAULT_UNREACHABLE;
+}
+
+bool
+memfault_platform_metrics_timer_boot(uint32_t period_sec,
+                                     MemfaultPlatformTimerCallback callback)
+{
+    metrics_period_sec = period_sec;
+    metrics_callback = callback;
+    metrics_callout_cb(NULL);
+    return true;
+}
+
+uint64_t
+memfault_platform_get_time_since_boot_ms(void)
+{
+    return (uint64_t) (os_get_uptime_usec() / 1000);
+}
+
+void
+memfault_platform_core_init(void)
+{
+    static uint8_t s_event_storage[MYNEWT_VAL(MEMFAULT_EVENT_STORAGE_SIZE)];
+    int rc;
+
+    SYSINIT_ASSERT_ACTIVE();
+    os_callout_init(&metrics_callout, os_eventq_dflt_get(),
+                    metrics_callout_cb, NULL);
+    SYSINIT_PANIC_ASSERT(metrics_callout.c_evq != NULL);
+
+    const sResetBootupInfo reset_reason = {
+        .reset_reason_reg = NRF_POWER->RESETREAS,
+    };
+
+    memfault_reboot_tracking_boot(s_reboot_tracking, &reset_reason);
+    /* Note: MCU reset reason register bits are usually "sticky" and
+     * need to be cleared.
+     */
+    NRF_POWER->RESETREAS |= NRF_POWER->RESETREAS;

Review comment:
       On memfault page they claim that not only Nordic is supported. Is our 
implementation is limited to NRF?

##########
File path: sys/memfault/pkg.yml
##########
@@ -0,0 +1,48 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+pkg.name: sys/memfault
+pkg.description: Memfault integration package (https://memfault.com/)
+pkg.author: "Apache Mynewt <d...@mynewt.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/";
+pkg.keywords:
+pkg.type: sdk
+pkg.deps:
+    - "@apache-mynewt-core/kernel/os"
+    - "@apache-mynewt-core/sys/shell"
+    - "@apache-mynewt-core/sys/flash_map"
+    - "@apache-mynewt-core/hw/hal"
+    - "@apache-mynewt-core/mgmt/imgmgr"
+    - "@mcuboot/boot/bootutil"
+
+pkg.deps.MEMFAULT_MGMT:
+    - "@apache-mynewt-mcumgr/cmd/memfault_mgmt"

Review comment:
       non existing package




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to