You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/09/08 07:28:34 UTC

[GitHub] [incubator-nuttx] pkarashchenko commented on a diff in pull request #7037: Add watchdog driver support to RP2040

pkarashchenko commented on code in PR #7037:
URL: https://github.com/apache/incubator-nuttx/pull/7037#discussion_r965599715


##########
arch/arm/include/rp2040/watchdog.h:
##########
@@ -0,0 +1,95 @@
+/****************************************************************************
+ * arch/arm/include/rp2040/watchdog.h
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef __ARCH_ARM_INCLUDE_RP2040_I2C_SLAVE_H
+#define __ARCH_ARM_INCLUDE_RP2040_I2C_SLAVE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/timers/watchdog.h>
+
+#ifndef __ASSEMBLY__
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+#ifdef CONFIG_WATCHDOG
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* IOCTL Commands ***********************************************************/
+
+/* The watchdog driver uses a standard character driver framework.  However,
+ * since the watchdog driver is a device control interface and not a data
+ * transfer interface, the majority of the functionality is implemented in
+ * driver ioctl calls.
+ *
+ * See nuttx/timers/watchdog.h for the IOCTLs handled by the upper half.
+ *
+ * These are detected and handled by the "lower half" watchdog timer driver.
+ *
+ *  WDIOC_SET_SCRATCHn  - save a 32-bit "arg" value in a scratch register
+ *                        that will be preserved over soft resets. A hard
+ *                        reset sets all scratch values to zero.
+ *
+ *  WDIOC_GET_SCRATCHn  - fetch a 32-bit value from a scratch register
+ *                        into a uint32_t pointed to by "arg".
+ */
+
+#define WDIOC_SET_SCRATCH0   _WDIOC(0x180)
+#define WDIOC_SET_SCRATCH1   _WDIOC(0x181)
+#define WDIOC_SET_SCRATCH2   _WDIOC(0x182)
+#define WDIOC_SET_SCRATCH3   _WDIOC(0x183)
+#define WDIOC_SET_SCRATCH4   _WDIOC(0x184)
+#define WDIOC_SET_SCRATCH5   _WDIOC(0x185)
+#define WDIOC_SET_SCRATCH6   _WDIOC(0x186)
+#define WDIOC_SET_SCRATCH7   _WDIOC(0x187)
+
+#define WDIOC_SET_SCRATCH(n) _WDIOC(0x180 + n)

Review Comment:
   ```suggestion
   #define WDIOC_SET_SCRATCH(n) _WDIOC(0x180 + (n))
   ```



##########
arch/arm/src/rp2040/rp2040_wdt.c:
##########
@@ -0,0 +1,281 @@
+/****************************************************************************
+ * arch/arm/src/rp2040/rp2040_wdt.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include "rp2040_wdt.h"
+
+#include <sys/types.h>
+#include <stdbool.h>
+#include <string.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <arch/chip/watchdog.h>
+
+#include <hardware/rp2040_watchdog.h>
+#include <hardware/rp2040_psm.h>
+
+#include <arch/rp2040/watchdog.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/clock.h>
+#include <nuttx/timers/watchdog.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define WD_RESETS_BITS    RP2040_PSM_CLOCKS              \
+                        | RP2040_PSM_RESETS              \
+                        | RP2040_PSM_BUSFABRIC           \
+                        | RP2040_PSM_ROM                 \
+                        | RP2040_PSM_SRAM0               \
+                        | RP2040_PSM_SRAM1               \
+                        | RP2040_PSM_SRAM2               \
+                        | RP2040_PSM_SRAM3               \
+                        | RP2040_PSM_SRAM4               \
+                        | RP2040_PSM_SRAM5               \
+                        | RP2040_PSM_XIP                 \
+                        | RP2040_PSM_VREG_AND_CHIP_RESET \
+                        | RP2040_PSM_SIO                 \
+                        | RP2040_PSM_PROC0               \
+                        | RP2040_PSM_PROC1
+
+#define WD_ENABLE_BITS    RP2040_WATCHDOG_CTRL_ENABLE     \
+                        | RP2040_WATCHDOG_CTRL_PAUSE_DBG0 \
+                        | RP2040_WATCHDOG_CTRL_PAUSE_DBG1 \
+                        | RP2040_WATCHDOG_CTRL_PAUSE_JTAG

Review Comment:
   ```suggestion
   #define WD_ENABLE_BITS   (RP2040_WATCHDOG_CTRL_ENABLE     \
                           | RP2040_WATCHDOG_CTRL_PAUSE_DBG0 \
                           | RP2040_WATCHDOG_CTRL_PAUSE_DBG1 \
                           | RP2040_WATCHDOG_CTRL_PAUSE_JTAG)
   ```



##########
arch/arm/include/rp2040/watchdog.h:
##########
@@ -0,0 +1,95 @@
+/****************************************************************************
+ * arch/arm/include/rp2040/watchdog.h
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef __ARCH_ARM_INCLUDE_RP2040_I2C_SLAVE_H
+#define __ARCH_ARM_INCLUDE_RP2040_I2C_SLAVE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/timers/watchdog.h>
+
+#ifndef __ASSEMBLY__
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+#ifdef CONFIG_WATCHDOG
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* IOCTL Commands ***********************************************************/
+
+/* The watchdog driver uses a standard character driver framework.  However,
+ * since the watchdog driver is a device control interface and not a data
+ * transfer interface, the majority of the functionality is implemented in
+ * driver ioctl calls.
+ *
+ * See nuttx/timers/watchdog.h for the IOCTLs handled by the upper half.
+ *
+ * These are detected and handled by the "lower half" watchdog timer driver.
+ *
+ *  WDIOC_SET_SCRATCHn  - save a 32-bit "arg" value in a scratch register
+ *                        that will be preserved over soft resets. A hard
+ *                        reset sets all scratch values to zero.
+ *
+ *  WDIOC_GET_SCRATCHn  - fetch a 32-bit value from a scratch register
+ *                        into a uint32_t pointed to by "arg".
+ */
+
+#define WDIOC_SET_SCRATCH0   _WDIOC(0x180)
+#define WDIOC_SET_SCRATCH1   _WDIOC(0x181)
+#define WDIOC_SET_SCRATCH2   _WDIOC(0x182)
+#define WDIOC_SET_SCRATCH3   _WDIOC(0x183)
+#define WDIOC_SET_SCRATCH4   _WDIOC(0x184)
+#define WDIOC_SET_SCRATCH5   _WDIOC(0x185)
+#define WDIOC_SET_SCRATCH6   _WDIOC(0x186)
+#define WDIOC_SET_SCRATCH7   _WDIOC(0x187)
+
+#define WDIOC_SET_SCRATCH(n) _WDIOC(0x180 + n)
+
+#define WDIOC_GET_SCRATCH0   _WDIOC(0x1f0)
+#define WDIOC_GET_SCRATCH1   _WDIOC(0x1f1)
+#define WDIOC_GET_SCRATCH2   _WDIOC(0x1f2)
+#define WDIOC_GET_SCRATCH3   _WDIOC(0x1f3)
+#define WDIOC_GET_SCRATCH4   _WDIOC(0x1f4)
+#define WDIOC_GET_SCRATCH5   _WDIOC(0x1f5)
+#define WDIOC_GET_SCRATCH6   _WDIOC(0x1f6)
+#define WDIOC_GET_SCRATCH7   _WDIOC(0x1f7)
+
+#define WDIOC_GET_SCRATCH(n) _WDIOC(0x1f0 + n)

Review Comment:
   ```suggestion
   #define WDIOC_GET_SCRATCH(n) _WDIOC(0x1f0 + (n))
   ```



##########
arch/arm/include/rp2040/watchdog.h:
##########
@@ -0,0 +1,95 @@
+/****************************************************************************
+ * arch/arm/include/rp2040/watchdog.h
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef __ARCH_ARM_INCLUDE_RP2040_I2C_SLAVE_H
+#define __ARCH_ARM_INCLUDE_RP2040_I2C_SLAVE_H

Review Comment:
   ```suggestion
   #ifndef __ARCH_ARM_INCLUDE_RP2040_WATCHDOG_H
   #define __ARCH_ARM_INCLUDE_RP2040_WATCHDOG_H
   ```



##########
arch/arm/src/rp2040/rp2040_wdt.c:
##########
@@ -0,0 +1,281 @@
+/****************************************************************************
+ * arch/arm/src/rp2040/rp2040_wdt.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include "rp2040_wdt.h"
+
+#include <sys/types.h>
+#include <stdbool.h>
+#include <string.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <arch/chip/watchdog.h>
+
+#include <hardware/rp2040_watchdog.h>
+#include <hardware/rp2040_psm.h>
+
+#include <arch/rp2040/watchdog.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/clock.h>
+#include <nuttx/timers/watchdog.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define WD_RESETS_BITS    RP2040_PSM_CLOCKS              \
+                        | RP2040_PSM_RESETS              \
+                        | RP2040_PSM_BUSFABRIC           \
+                        | RP2040_PSM_ROM                 \
+                        | RP2040_PSM_SRAM0               \
+                        | RP2040_PSM_SRAM1               \
+                        | RP2040_PSM_SRAM2               \
+                        | RP2040_PSM_SRAM3               \
+                        | RP2040_PSM_SRAM4               \
+                        | RP2040_PSM_SRAM5               \
+                        | RP2040_PSM_XIP                 \
+                        | RP2040_PSM_VREG_AND_CHIP_RESET \
+                        | RP2040_PSM_SIO                 \
+                        | RP2040_PSM_PROC0               \
+                        | RP2040_PSM_PROC1

Review Comment:
   ```suggestion
   #define WD_RESETS_BITS   (RP2040_PSM_CLOCKS              \
                           | RP2040_PSM_RESETS              \
                           | RP2040_PSM_BUSFABRIC           \
                           | RP2040_PSM_ROM                 \
                           | RP2040_PSM_SRAM0               \
                           | RP2040_PSM_SRAM1               \
                           | RP2040_PSM_SRAM2               \
                           | RP2040_PSM_SRAM3               \
                           | RP2040_PSM_SRAM4               \
                           | RP2040_PSM_SRAM5               \
                           | RP2040_PSM_XIP                 \
                           | RP2040_PSM_VREG_AND_CHIP_RESET \
                           | RP2040_PSM_SIO                 \
                           | RP2040_PSM_PROC0               \
                           | RP2040_PSM_PROC1)
   ```



##########
arch/arm/include/rp2040/watchdog.h:
##########
@@ -0,0 +1,95 @@
+/****************************************************************************
+ * arch/arm/include/rp2040/watchdog.h
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef __ARCH_ARM_INCLUDE_RP2040_I2C_SLAVE_H
+#define __ARCH_ARM_INCLUDE_RP2040_I2C_SLAVE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/timers/watchdog.h>
+
+#ifndef __ASSEMBLY__
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+#ifdef CONFIG_WATCHDOG
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* IOCTL Commands ***********************************************************/
+
+/* The watchdog driver uses a standard character driver framework.  However,
+ * since the watchdog driver is a device control interface and not a data
+ * transfer interface, the majority of the functionality is implemented in
+ * driver ioctl calls.
+ *
+ * See nuttx/timers/watchdog.h for the IOCTLs handled by the upper half.
+ *
+ * These are detected and handled by the "lower half" watchdog timer driver.
+ *
+ *  WDIOC_SET_SCRATCHn  - save a 32-bit "arg" value in a scratch register
+ *                        that will be preserved over soft resets. A hard
+ *                        reset sets all scratch values to zero.
+ *
+ *  WDIOC_GET_SCRATCHn  - fetch a 32-bit value from a scratch register
+ *                        into a uint32_t pointed to by "arg".
+ */
+
+#define WDIOC_SET_SCRATCH0   _WDIOC(0x180)
+#define WDIOC_SET_SCRATCH1   _WDIOC(0x181)
+#define WDIOC_SET_SCRATCH2   _WDIOC(0x182)
+#define WDIOC_SET_SCRATCH3   _WDIOC(0x183)
+#define WDIOC_SET_SCRATCH4   _WDIOC(0x184)
+#define WDIOC_SET_SCRATCH5   _WDIOC(0x185)
+#define WDIOC_SET_SCRATCH6   _WDIOC(0x186)
+#define WDIOC_SET_SCRATCH7   _WDIOC(0x187)
+
+#define WDIOC_SET_SCRATCH(n) _WDIOC(0x180 + n)
+
+#define WDIOC_GET_SCRATCH0   _WDIOC(0x1f0)
+#define WDIOC_GET_SCRATCH1   _WDIOC(0x1f1)
+#define WDIOC_GET_SCRATCH2   _WDIOC(0x1f2)
+#define WDIOC_GET_SCRATCH3   _WDIOC(0x1f3)
+#define WDIOC_GET_SCRATCH4   _WDIOC(0x1f4)
+#define WDIOC_GET_SCRATCH5   _WDIOC(0x1f5)
+#define WDIOC_GET_SCRATCH6   _WDIOC(0x1f6)
+#define WDIOC_GET_SCRATCH7   _WDIOC(0x1f7)
+
+#define WDIOC_GET_SCRATCH(n) _WDIOC(0x1f0 + n)
+
+#endif /* CONFIG_WATCHDOG */
+
+#undef EXTERN
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* __ASSEMBLY__ */
+#endif /* __ARCH_ARM_INCLUDE_RP2040_I2C_SLAVE_H */

Review Comment:
   ```suggestion
   #endif /* __ARCH_ARM_INCLUDE_RP2040_WATCHDOG_H */
   ```



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

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