This is an automated email from the ASF dual-hosted git repository.

jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit f20a9d358f996979b047f1a947e3fd14e583d1fd
Author: Jerzy Kasenberg <[email protected]>
AuthorDate: Fri May 10 14:48:39 2019 +0200

    Add HAL_DEBUG_BREAK
    
    HAL_DEBUG_BREAK sets software breakpoint that if debugger is present
    stop execution.
    Before execution is stopped user provided function hal_break_hook()
    is called that can change configuration of hardware when leaving
    CPU stopped could damage device.
    
    Software breakpoints placed with HAL_DEBUG_BREAK can be disabled
    by setting HAL_ENABLE_SOFTWARE_BREAKPOINTS syscfg value to 0.
    
    Example package is added that shows how such callback could be used.
    Example package defines hal_break_hook() and syscfg variable that
    activates it.
---
 hw/hal/include/hal/hal_debug.h                     | 61 ++++++++++++++++++++++
 hw/hal/syscfg.yml                                  |  5 ++
 hw/util/break_hook_example/pkg.yml                 | 37 +++++++++++++
 .../break_hook_example/src/break_hook_example.c    | 27 ++++++++++
 hw/{hal => util/break_hook_example}/syscfg.yml     | 27 ++--------
 5 files changed, 134 insertions(+), 23 deletions(-)

diff --git a/hw/hal/include/hal/hal_debug.h b/hw/hal/include/hal/hal_debug.h
new file mode 100644
index 0000000..165daea
--- /dev/null
+++ b/hw/hal/include/hal/hal_debug.h
@@ -0,0 +1,61 @@
+/*
+ * 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.
+ */
+
+
+/**
+ * @addtogroup HAL
+ * @{
+ *   @defgroup HALDebug HAL Debug
+ *   @{
+ */
+
+#ifndef H_HAL_DEBUG_
+#define H_HAL_DEBUG_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <syscfg/syscfg.h>
+
+#if MYNEWT_VAL(HAL_BREAK_HOOK)
+/* User defined function to be called before code is stopped in debugger */
+void hal_break_hook(void);
+#else
+static inline void hal_break_hook() {}
+#endif
+
+#ifndef HAL_DEBUG_BREAK
+#define HAL_DEBUG_BREAK()                                      \
+        (void)(MYNEWT_VAL(HAL_ENABLE_SOFTWARE_BREAKPOINTS) &&  \
+               hal_debugger_connected() &&                     \
+               (hal_break_hook(), 1) &&                        \
+               (hal_debug_break(), 1))
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* H_HAL_DEBUG_ */
+
+/**
+ *   @} HALDebug
+ * @} HAL
+ */
diff --git a/hw/hal/syscfg.yml b/hw/hal/syscfg.yml
index 4b67dce..29bd002 100644
--- a/hw/hal/syscfg.yml
+++ b/hw/hal/syscfg.yml
@@ -37,6 +37,11 @@ syscfg.defs:
         description: >
             If set, hal system reset callback gets called inside 
hal_system_reset().
         value: 0
+    HAL_ENABLE_SOFTWARE_BREAKPOINTS:
+        description: >
+            If set to 0 software breakpoints placed with HAL_DEBUG_BREAK macro 
will not
+            be executed.
+        value: 1
 
 syscfg.vals.OS_DEBUG_MODE:
     HAL_FLASH_VERIFY_WRITES: 1
diff --git a/hw/util/break_hook_example/pkg.yml 
b/hw/util/break_hook_example/pkg.yml
new file mode 100644
index 0000000..cf27252
--- /dev/null
+++ b/hw/util/break_hook_example/pkg.yml
@@ -0,0 +1,37 @@
+#
+# 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: hw/util/break_hook_example
+pkg.description: >
+    Break hook example.
+    This package defines HAL_BREAK_HOOK syscfg value which informs 
HAL_DEBUG_BREAK to
+    use user provided callback before execution stops.
+    Example prints some log. Production code hook should not do any printing 
it should
+    do minimum to leave platform in safe state before CPU stops.
+
+pkg.author: "Apache Mynewt <[email protected]>"
+pkg.homepage: "http://mynewt.apache.org/";
+pkg.keywords:
+    - break_hook
+
+pkg.deps:
+    - "@apache-mynewt-core/hw/hal"
+
+pkg.req_apis:
+    - console
diff --git a/hw/util/break_hook_example/src/break_hook_example.c 
b/hw/util/break_hook_example/src/break_hook_example.c
new file mode 100644
index 0000000..e03f64c
--- /dev/null
+++ b/hw/util/break_hook_example/src/break_hook_example.c
@@ -0,0 +1,27 @@
+/*
+ * 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 <syscfg/syscfg.h>
+#include <console/console.h>
+
+void
+hal_break_hook(void)
+{
+    console_printf("hal_break_hook called\n");
+}
diff --git a/hw/hal/syscfg.yml b/hw/util/break_hook_example/syscfg.yml
similarity index 51%
copy from hw/hal/syscfg.yml
copy to hw/util/break_hook_example/syscfg.yml
index 4b67dce..181eff7 100644
--- a/hw/hal/syscfg.yml
+++ b/hw/util/break_hook_example/syscfg.yml
@@ -1,3 +1,4 @@
+#
 # 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
@@ -17,27 +18,7 @@
 #
 
 syscfg.defs:
-    HAL_FLASH_VERIFY_WRITES:
-        description: >
-            If enabled, flash contents are read back and verified after each
-            write.
-        value: 0
-    HAL_FLASH_VERIFY_ERASES:
-        description: >
-            If enabled, flash contents are read back and verified after each
-            erase.
-        value: 0
-    HAL_FLASH_VERIFY_BUF_SZ:
+    HAL_BREAK_HOOK:
         description: >
-            The buffer size to use when verifying writes and erases.  One
-            buffer of this size is allocated on the stack during verify
-            operations.
-        value: 16
-    HAL_SYSTEM_RESET_CB:
-        description: >
-            If set, hal system reset callback gets called inside 
hal_system_reset().
-        value: 0
-
-syscfg.vals.OS_DEBUG_MODE:
-    HAL_FLASH_VERIFY_WRITES: 1
-    HAL_FLASH_VERIFY_ERASES: 1
+            Informs hal that hal_break_hook exists and should be used.
+        value: 1

Reply via email to