diff --git a/arch/arm/src/s32k1xx/Kconfig b/arch/arm/src/s32k1xx/Kconfig index f542bcada6..57ee616db5 100644 --- a/arch/arm/src/s32k1xx/Kconfig +++ b/arch/arm/src/s32k1xx/Kconfig @@ -347,6 +347,15 @@ config S32K1XX_EEEPROM endmenu # S32K1XX Peripheral Selection +menu "S32K1xx Reset Control Module (RCM)" + +config S32K1XX_RESETCAUSE_PROCFS + bool "S32K1XX MCU Reset Cause PROCFS entry" + default n + depends on !DISABLE_MOUNTPOINT && FS_PROCFS && FS_PROCFS_REGISTER + +endmenu # S32K1XX Reset Control Module (RCM) + menu "S32K1XX FTM PWM Configuration" depends on S32K1XX_FTM diff --git a/arch/arm/src/s32k1xx/Make.defs b/arch/arm/src/s32k1xx/Make.defs index 1362f46539..b63f0fdd9c 100644 --- a/arch/arm/src/s32k1xx/Make.defs +++ b/arch/arm/src/s32k1xx/Make.defs @@ -98,8 +98,8 @@ ifneq ($(CONFIG_ARCH_CUSTOM_PMINIT),y) CHIP_CSRCS += s32k1xx_pminitialize.c endif -ifeq ($(CONFIG_RESET_CAUSE_PROC_FS), y) -CHIP_CSRCS += s32k1xx_resetcause.c +ifeq ($(CONFIG_S32K1XX_RESETCAUSE_PROCFS), y) +CHIP_CSRCS += s32k1xx_resetcause_procfs.c endif # Source files specific to the ARM CPU family and to the S32K1xx chip family diff --git a/arch/arm/src/s32k1xx/s32k1xx_resetcause.c b/arch/arm/src/s32k1xx/s32k1xx_resetcause_procfs.c similarity index 56% rename from arch/arm/src/s32k1xx/s32k1xx_resetcause.c rename to arch/arm/src/s32k1xx/s32k1xx_resetcause_procfs.c index 7518a511ac..c4e9f7ff9e 100644 --- a/arch/arm/src/s32k1xx/s32k1xx_resetcause.c +++ b/arch/arm/src/s32k1xx/s32k1xx_resetcause_procfs.c @@ -1,5 +1,5 @@ /**************************************************************************** - * arch/arm/src/s32k1xx/s32k1xx_resetcause.c + * arch/arm/src/s32k1xx/s32k1xx_resetcause_procfs.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -23,17 +23,15 @@ ****************************************************************************/ #include +#include #include -#include #include #include #include #include #include #include -#include #include -#include #include #include #include @@ -41,12 +39,9 @@ #include "arm_arch.h" #include "hardware/s32k1xx_rcm.h" +#include "s32k1xx_resetcause_procfs.h" -#include "s32k1xx_resetcause.h" - -#include "arm_internal.h" - -#include /* Include last: has dependencies */ +#ifdef CONFIG_S32K1XX_RESETCAUSE_PROCFS /**************************************************************************** * Pre-processor Definitions @@ -55,7 +50,8 @@ /* Determines the size of an intermediate buffer that must be large enough * to handle the longest line generated by this logic. */ -#define RESETCAUSE_LINELEN 6 + +#define S32K1XX_RESETCAUSE_LINELEN 11 /**************************************************************************** * Private Types @@ -63,60 +59,50 @@ /* This structure describes one open "file" */ -struct resetcause_file_s +struct s32k1xx_resetcause_procfs_file_s { - struct procfs_file_s base; /* Base open file structure */ - unsigned int linesize; /* Number of valid characters in line[] */ - char line[RESETCAUSE_LINELEN]; /* Pre-allocated buffer for formatted lines */ - unsigned int resetcause; /* Variable representing the MCU specific reset cause */ + struct procfs_file_s base; /* Base open file structure */ + unsigned int linesize; /* Number of valid characters in line[] */ + char line[S32K1XX_RESETCAUSE_LINELEN]; /* Pre-allocated buffer for formatted lines */ }; -static unsigned int g_reset_cause = 0; - -#if defined(CONFIG_RESET_CAUSE_PROC_FS) && defined(CONFIG_FS_PROCFS) - /**************************************************************************** * Private Function Prototypes ****************************************************************************/ -/* File system methods */ - -static int resetcause_open(FAR struct file *filep, - FAR const char *relpath, int oflags, mode_t mode); -static int resetcause_close(FAR struct file *filep); -static ssize_t resetcause_read(FAR struct file *filep, FAR char *buffer, - size_t buflen); - -static int resetcause_dup(FAR const struct file *oldp, - FAR struct file *newp); - -static int resetcause_stat(FAR const char *relpath, - FAR struct stat *buf); +static int s32k1xx_resetcause_procfs_open(FAR struct file *filep, + FAR const char *relpath, + int oflags, mode_t mode); +static int s32k1xx_resetcause_procfs_close(FAR struct file *filep); +static ssize_t s32k1xx_resetcause_procfs_read(FAR struct file *filep, + FAR char *buffer, + size_t buflen); +static int s32k1xx_resetcause_procfs_dup(FAR const struct file *oldp, + FAR struct file *newp); +static int s32k1xx_resetcause_procfs_stat(FAR const char *relpath, + FAR struct stat *buf); /**************************************************************************** - * Public Data + * Private Data ****************************************************************************/ -const struct procfs_operations resetcause_operations = +const struct procfs_operations s32k1xx_resetcause_procfs_ops = { - resetcause_open, /* open */ - resetcause_close, /* close */ - resetcause_read, /* read */ - NULL, /* write */ - - resetcause_dup, /* dup */ - - NULL, /* opendir */ - NULL, /* closedir */ - NULL, /* readdir */ - NULL, /* rewinddir */ - - resetcause_stat /* stat */ + s32k1xx_resetcause_procfs_open, /* open */ + s32k1xx_resetcause_procfs_close, /* close */ + s32k1xx_resetcause_procfs_read, /* read */ + NULL, /* write */ + s32k1xx_resetcause_procfs_dup, /* dup */ + NULL, /* opendir */ + NULL, /* closedir */ + NULL, /* readdir */ + NULL, /* rewinddir */ + s32k1xx_resetcause_procfs_stat, /* stat */ }; -static const struct procfs_entry_s g_resetcause_procfs = +static const struct procfs_entry_s g_s32k1xx_resetcause_procfs = { - "resetcause", &resetcause_operations + "resetcause", &s32k1xx_resetcause_procfs_ops }; /**************************************************************************** @@ -124,13 +110,14 @@ static const struct procfs_entry_s g_resetcause_procfs = ****************************************************************************/ /**************************************************************************** - * Name: resetcause_open + * Name: s32k1xx_resetcause_procfs_open ****************************************************************************/ -static int resetcause_open(FAR struct file *filep, FAR const char *relpath, - int oflags, mode_t mode) +static int s32k1xx_resetcause_procfs_open(FAR struct file *filep, + FAR const char *relpath, + int oflags, mode_t mode) { - FAR struct resetcause_file_s *attr; + FAR struct s32k1xx_resetcause_procfs_file_s *attr; finfo("Open '%s'\n", relpath); @@ -148,7 +135,7 @@ static int resetcause_open(FAR struct file *filep, FAR const char *relpath, /* Allocate a container to hold the file attributes */ - attr = kmm_zalloc(sizeof(struct resetcause_file_s)); + attr = kmm_zalloc(sizeof(struct s32k1xx_resetcause_procfs_file_s)); if (!attr) { ferr("ERROR: Failed to allocate file attributes\n"); @@ -162,16 +149,16 @@ static int resetcause_open(FAR struct file *filep, FAR const char *relpath, } /**************************************************************************** - * Name: resetcause_close + * Name: s32k1xx_resetcause_procfs_close ****************************************************************************/ -static int resetcause_close(FAR struct file *filep) +static int s32k1xx_resetcause_procfs_close(FAR struct file *filep) { - FAR struct resetcause_file_s *attr; + FAR struct s32k1xx_resetcause_procfs_file_s *attr; /* Recover our private data from the struct file instance */ - attr = (FAR struct resetcause_file_s *)filep->f_priv; + attr = (FAR struct s32k1xx_resetcause_procfs_file_s *)filep->f_priv; DEBUGASSERT(attr); /* Release the file attributes structure */ @@ -182,69 +169,66 @@ static int resetcause_close(FAR struct file *filep) } /**************************************************************************** - * Name: resetcause_read + * Name: s32k1xx_resetcause_procfs_read ****************************************************************************/ -static ssize_t resetcause_read(FAR struct file *filep, FAR char *buffer, - size_t buflen) +static ssize_t s32k1xx_resetcause_procfs_read(FAR struct file *filep, + FAR char *buffer, + size_t buflen) { - FAR struct resetcause_file_s *attr; - size_t linesize; + FAR struct s32k1xx_resetcause_procfs_file_s *attr; + uint32_t resetcause; off_t offset; - ssize_t ret; finfo("buffer=%p buflen=%d\n", buffer, (int)buflen); /* Recover our private data from the struct file instance */ - attr = (FAR struct resetcause_file_s *)filep->f_priv; + attr = (FAR struct s32k1xx_resetcause_procfs_file_s *)filep->f_priv; DEBUGASSERT(attr); - /* Get the resetcause value and store it */ + /* Retrieve the reset cause */ - attr->resetcause = g_reset_cause; + resetcause = getreg32(S32K1XX_RCM_SRS); - /* Convert the resetcause to a string */ + /* Convert the resetcause to a string and save the linesize in case we are + * re-entered with f_pos > 0 + */ - linesize = snprintf(attr->line, RESETCAUSE_LINELEN, - "0x%x", attr->resetcause); - - /* Save the linesize in case we are re-entered with f_pos > 0 */ - - attr->linesize = linesize; + attr->linesize = snprintf(attr->line, S32K1XX_RESETCAUSE_LINELEN, + "0x%08" PRIx32, resetcause); /* Transfer the system reset cause to user receive buffer */ offset = filep->f_pos; - ret = procfs_memcpy(attr->line, attr->linesize, buffer, buflen, &offset); - - return ret; + return procfs_memcpy(attr->line, attr->linesize, buffer, buflen, &offset); } /**************************************************************************** - * Name: resetcause_dup + * Name: s32k1xx_resetcause_procfs_dup * * Description: * Duplicate open file data in the new file structure. * ****************************************************************************/ -static int resetcause_dup(FAR const struct file *oldp, FAR struct file *newp) +static int s32k1xx_resetcause_procfs_dup(FAR const struct file *oldp, + FAR struct file *newp) { - FAR struct resetcause_file_s *oldattr; - FAR struct resetcause_file_s *newattr; + FAR struct s32k1xx_resetcause_procfs_file_s *oldattr; + FAR struct s32k1xx_resetcause_procfs_file_s *newattr; finfo("Dup %p->%p\n", oldp, newp); /* Recover our private data from the old struct file instance */ - oldattr = (FAR struct resetcause_file_s *)oldp->f_priv; + oldattr = (FAR struct s32k1xx_resetcause_procfs_file_s *)oldp->f_priv; DEBUGASSERT(oldattr); /* Allocate a new container to hold the task and attribute selection */ - newattr = kmm_malloc(sizeof(struct resetcause_file_s)); + newattr = kmm_malloc(sizeof(struct s32k1xx_resetcause_procfs_file_s)); if (!newattr) { ferr("ERROR: Failed to allocate file attributes\n"); @@ -253,7 +237,7 @@ static int resetcause_dup(FAR const struct file *oldp, FAR struct file *newp) /* The copy the file attributes from the old attributes to the new */ - memcpy(newattr, oldattr, sizeof(struct resetcause_file_s)); + memcpy(newattr, oldattr, sizeof(struct s32k1xx_resetcause_procfs_file_s)); /* Save the new attributes in the new file structure */ @@ -262,13 +246,14 @@ static int resetcause_dup(FAR const struct file *oldp, FAR struct file *newp) } /**************************************************************************** - * Name: resetcause_stat + * Name: s32k1xx_resetcause_procfs_stat * * Description: Return information about a file or directory * ****************************************************************************/ -static int resetcause_stat(FAR const char *relpath, FAR struct stat *buf) +static int s32k1xx_resetcause_procfs_stat(FAR const char *relpath, + FAR struct stat *buf) { /* "resetcause" is the name for a read-only file */ @@ -282,37 +267,19 @@ static int resetcause_stat(FAR const char *relpath, FAR struct stat *buf) ****************************************************************************/ /**************************************************************************** - * Name: s32k1xx_resetcause_init + * Name: s32k1xx_resetcause_procfs_register * - * Description: This function initializes the resetcause - * It will get the resetcause and store it + * Description: + * Register the S32K1XX Reset Cause procfs file system entry + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure * ****************************************************************************/ -void s32k1xx_resetcause_init(void) +int s32k1xx_resetcause_procfs_register(void) { - uint32_t reset_cause_register = 0; - - /* get the reset cause */ - - reset_cause_register = getreg32(S32K1XX_RCM_SRS); - - /* save it in the global variable */ - - g_reset_cause = (unsigned int) reset_cause_register; + return procfs_register(&g_s32k1xx_resetcause_procfs); } -/**************************************************************************** - * Name: s32k1xx_resetcause_initialize_procfs - * - * Description: This function registrates the reset cause as a proc fs - * Returns 0 if OK, error number otherwise - * - ****************************************************************************/ - -int s32k1xx_resetcause_initialize_procfs(void) -{ - return procfs_register(&g_resetcause_procfs); -} - -#endif /* CONFIG_RESET_CAUSE_PROC_FS && CONFIG_FS_PROCFS */ +#endif /* CONFIG_S32K1XX_RESETCAUSE_PROCFS */ diff --git a/arch/arm/src/s32k1xx/s32k1xx_resetcause.h b/arch/arm/src/s32k1xx/s32k1xx_resetcause_procfs.h similarity index 59% rename from arch/arm/src/s32k1xx/s32k1xx_resetcause.h rename to arch/arm/src/s32k1xx/s32k1xx_resetcause_procfs.h index 8e20e25a9a..951d124019 100644 --- a/arch/arm/src/s32k1xx/s32k1xx_resetcause.h +++ b/arch/arm/src/s32k1xx/s32k1xx_resetcause_procfs.h @@ -1,5 +1,5 @@ /**************************************************************************** - * arch/arm/src/s32k1xx/s32k1xx_resetcause.h + * arch/arm/src/s32k1xx/s32k1xx_resetcause_procfs.h * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -18,46 +18,33 @@ * ****************************************************************************/ -#ifndef __ARCH_ARM_SRC_S32K1XX_RESETCAUSE_H -#define __ARCH_ARM_SRC_S32K1XX_RESETCAUSE_H +#ifndef __ARCH_ARM_SRC_S32K1XX_S32K1XX_RESETCAUSE_PROCFS_H +#define __ARCH_ARM_SRC_S32K1XX_S32K1XX_RESETCAUSE_PROCFS_H /**************************************************************************** * Included Files ****************************************************************************/ #include -#include -#include -#include -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ +#ifdef CONFIG_S32K1XX_RESETCAUSE_PROCFS /**************************************************************************** * Public Function Prototypes ****************************************************************************/ /**************************************************************************** - * Name: s32k1xx_resetcause_init + * Name: s32k1xx_resetcause_procfs_register * - * Description: This function initializes the resetcause - * It will get the resetcause and store it + * Description: + * Register the S32K1XX Reset Cause procfs file system entry + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure * ****************************************************************************/ -void s32k1xx_resetcause_init(void); +int s32k1xx_resetcause_procfs_register(void); -/**************************************************************************** - * Name: s32k1xx_resetcause_initialize_procfs - * - * Description: This function registrates the reset cause as a proc fs - * Returns 0 if OK, error number otherwise - * - ****************************************************************************/ - -int s32k1xx_resetcause_initialize_procfs(void); - -#endif /* __ARCH_ARM_SRC_S32K1XX_RESETCAUSE_H */ +#endif /* CONFIG_S32K1XX_RESETCAUSE_PROCFS */ +#endif /* __ARCH_ARM_SRC_S32K1XX_S32K1XX_RESETCAUSE_PROCFS_H */ diff --git a/boards/arm/s32k1xx/s32k144evb/src/s32k1xx_bringup.c b/boards/arm/s32k1xx/s32k144evb/src/s32k1xx_bringup.c index 9ce12ffc78..b1f4a0f4cc 100644 --- a/boards/arm/s32k1xx/s32k144evb/src/s32k1xx_bringup.c +++ b/boards/arm/s32k1xx/s32k144evb/src/s32k1xx_bringup.c @@ -38,6 +38,10 @@ #ifdef CONFIG_FS_PROCFS # include + +# ifdef CONFIG_S32K1XX_RESETCAUSE_PROCFS +# include "s32k1xx_resetcause_procfs.h" +# endif #endif #ifdef CONFIG_S32K1XX_PROGMEM @@ -93,6 +97,17 @@ int s32k1xx_bringup(void) #endif #ifdef CONFIG_FS_PROCFS + /* Register procfs entries before mounting */ + +# ifdef CONFIG_S32K1XX_RESETCAUSE_PROCFS + ret = s32k1xx_resetcause_procfs_register(); + if (ret < 0) + { + syslog(LOG_ERR, + "ERROR: Failed to register resetcause procfs entry: %d\n", ret); + } +# endif /* CONFIG_RESETCAUSE_PROCFS */ + /* Mount the procfs file system */ ret = nx_mount(NULL, "/proc", "procfs", 0, NULL);