You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/04/12 07:00:06 UTC

[GitHub] mkiiskila closed pull request #996: WIP: hal_nvreg (Retained register interface)

mkiiskila closed pull request #996: WIP: hal_nvreg (Retained register interface)
URL: https://github.com/apache/mynewt-core/pull/996
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/boot/boot_serial/src/boot_serial.c b/boot/boot_serial/src/boot_serial.c
index 60c9694ce0..176798d4b1 100644
--- a/boot/boot_serial/src/boot_serial.c
+++ b/boot/boot_serial/src/boot_serial.c
@@ -31,6 +31,7 @@
 #include <hal/hal_system.h>
 #include <hal/hal_gpio.h>
 #include <hal/hal_watchdog.h>
+#include <hal/hal_nvreg.h>
 
 #include <tinycbor/cbor.h>
 #include <tinycbor/cbor_buf_reader.h>
@@ -652,13 +653,32 @@ boot_serial_os_dev_init(void)
      * Configure GPIO line as input. This is read later to see if
      * we should stay and keep waiting for input.
      */
+#if MYNEWT_VAL(BOOT_SERIAL_DETECT_PIN) != -1
     hal_gpio_init_in(MYNEWT_VAL(BOOT_SERIAL_DETECT_PIN),
                      MYNEWT_VAL(BOOT_SERIAL_DETECT_PIN_CFG));
+#endif
 }
 
 void
 boot_serial_pkg_init(void)
 {
+
+    /*
+     * Read retained register and compare with expected magic value.
+     * If it matches, await for download commands from serial.
+     */
+#if MYNEWT_VAL(BOOT_SERIAL_NVREG_INDEX) != -1
+    if (hal_nvreg_read(MYNEWT_VAL(BOOT_SERIAL_NVREG_INDEX)) ==
+        MYNEWT_VAL(BOOT_SERIAL_NVREG_MAGIC)) {
+
+        hal_nvreg_write(MYNEWT_VAL(BOOT_SERIAL_NVREG_INDEX), 0);
+
+        boot_serial_start(BOOT_SERIAL_INPUT_MAX);
+        assert(0);
+    }
+
+#endif
+
     /*
      * Configure a GPIO as input, and compare it against expected value.
      * If it matches, await for download commands from serial.
diff --git a/boot/boot_serial/syscfg.yml b/boot/boot_serial/syscfg.yml
index 028871aa6a..fd9815190d 100644
--- a/boot/boot_serial/syscfg.yml
+++ b/boot/boot_serial/syscfg.yml
@@ -69,3 +69,18 @@ syscfg.defs:
         description: >
             The toggle rate, in Hz, of the serial boot loader report pin.
         value: 4
+
+    BOOT_SERIAL_NVREG_MAGIC:
+        description: >
+            Magic number, to be saved in a retained (reset-surviving) register.
+            If the value in the register matches, the serial bootloader will
+            load. Value must not be 0.
+        value: 0xB7
+        restrictions:
+            - '(BOOT_SERIAL_NVREG_MAGIC != 0)'
+
+    BOOT_SERIAL_NVREG_INDEX:
+        description: >
+            Index of retained register to use (using hal_nvreg_read) for reading
+            magic value.
+        value: -1
diff --git a/hw/hal/include/hal/hal_nvreg.h b/hw/hal/include/hal/hal_nvreg.h
new file mode 100644
index 0000000000..1878fc030d
--- /dev/null
+++ b/hw/hal/include/hal/hal_nvreg.h
@@ -0,0 +1,66 @@
+/*
+ * 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 HALNvreg HAL NVReg
+ *   @{
+ */
+
+#ifndef __HAL_NVREG_H_
+#define __HAL_NVREG_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <inttypes.h>
+
+/**
+ * Writes to a retained register
+ */
+void hal_nvreg_write(unsigned int reg, uint32_t val);
+
+/**
+ * Reads from a retained register
+ */
+uint32_t hal_nvreg_read(unsigned int reg);
+
+/**
+ * Get number of available retained registers
+ */
+unsigned int hal_nvreg_get_num_regs(void);
+
+/**
+ * Get retained register width (in bytes)
+ */
+unsigned int hal_nvreg_get_reg_width(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+/**
+ *   @} HALNvreg
+ * @} HAL
+ */
diff --git a/hw/mcu/nordic/nrf52xxx/src/hal_nvreg.c b/hw/mcu/nordic/nrf52xxx/src/hal_nvreg.c
new file mode 100644
index 0000000000..f8686331e9
--- /dev/null
+++ b/hw/mcu/nordic/nrf52xxx/src/hal_nvreg.c
@@ -0,0 +1,63 @@
+/*
+ * 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 <mcu/cortex_m4.h>
+#include "hal/hal_nvreg.h"
+#include "nrf.h"
+
+/* There are two GPREGRET registers on the NRF52 */
+#define HAL_NVREG_MAX (2)
+
+/* GPREGRET registers only save the 8 lsbits */
+#define HAL_NVREG_WIDTH_BYTES (1)
+
+static volatile uint32_t *regs[HAL_NVREG_MAX] = {
+    &NRF_POWER->GPREGRET,
+    &NRF_POWER->GPREGRET2
+};
+
+void
+hal_nvreg_write(unsigned int reg, uint32_t val)
+{
+    if(reg < HAL_NVREG_MAX) {
+        *regs[reg] = val;
+    }
+}
+
+uint32_t
+hal_nvreg_read(unsigned int reg)
+{
+    uint32_t val = 0;
+
+    if(reg < HAL_NVREG_MAX) {
+        val = *regs[reg];
+    }
+
+    return val;
+}
+
+unsigned int hal_nvreg_get_num_regs(void)
+{
+    return HAL_NVREG_MAX;
+}
+
+unsigned int hal_nvreg_get_reg_width(void)
+{
+    return HAL_NVREG_WIDTH_BYTES;
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services