diff --git a/arch/arm/src/armv7-m/Kconfig b/arch/arm/src/armv7-m/Kconfig index 0652771567..404dce0753 100644 --- a/arch/arm/src/armv7-m/Kconfig +++ b/arch/arm/src/armv7-m/Kconfig @@ -160,7 +160,7 @@ config ARMV7M_STACKCHECK config ARMV7M_ITMSYSLOG bool "ITM SYSLOG support" default n - select ARCH_HAVE_SYSLOG + select ARCH_SYSLOG select SYSLOG ---help--- Enable hooks to support ITM syslog output. This requires additional diff --git a/drivers/syslog/Kconfig b/drivers/syslog/Kconfig index e8a426383a..9046b3d261 100644 --- a/drivers/syslog/Kconfig +++ b/drivers/syslog/Kconfig @@ -7,7 +7,7 @@ comment "System Logging" # Selected if the architecture has its own, built-in SYSLOGgin enabled -config ARCH_HAVE_SYSLOG +config ARCH_SYSLOG bool default n @@ -29,7 +29,7 @@ if RAMLOG config RAMLOG_SYSLOG bool "Use RAMLOG for SYSLOG" default n - depends on SYSLOG && !ARCH_HAVE_SYSLOG + depends on SYSLOG && !ARCH_SYSLOG ---help--- Use the RAM logging device for the syslogging interface. If this feature is enabled (along with SYSLOG), then all debug output (only) will be re-directed @@ -107,7 +107,7 @@ if SYSLOG config SYSLOG_CHAR bool "System log character device support" default y - depends on !ARCH_HAVE_SYSLOG + depends on !ARCH_SYSLOG ---help--- Enable the generic character device for the SYSLOG. The full path to the SYSLOG device is provided by SYSLOG_DEVPATH. A valid character device (or diff --git a/drivers/syslog/Make.defs b/drivers/syslog/Make.defs index d736da5927..b9d04c2dec 100644 --- a/drivers/syslog/Make.defs +++ b/drivers/syslog/Make.defs @@ -39,6 +39,10 @@ CSRCS += syslog_initialize.c vsyslog.c vlowsyslog.c syslogstream.c +ifneq ($(CONFIG_ARCH_SYSLOG),y) + CSRCS += syslog_initialize.c +endif + # The note driver is hosted in this directory, but is not associated with # SYSLOGging diff --git a/drivers/syslog/syslog_device.c b/drivers/syslog/syslog_device.c index 360edc61af..bebc8f38e6 100644 --- a/drivers/syslog/syslog_device.c +++ b/drivers/syslog/syslog_device.c @@ -76,7 +76,7 @@ /* This enumeration represents the state of the SYSLOG device interface */ -enum syslog_state_e +enum syslog_dev_state { SYSLOG_UNINITIALIZED = 0, /* SYSLOG has not been initialized */ SYSLOG_INITIALIZING, /* SYSLOG is being initialized */ @@ -89,7 +89,7 @@ enum syslog_state_e struct syslog_dev_s { - uint8_t sl_state; /* See enum syslog_state_e */ + uint8_t sl_state; /* See enum syslog_dev_state */ sem_t sl_sem; /* Enforces mutually exclusive access */ pid_t sl_holder; /* PID of the thread that holds the semaphore */ struct file sl_file; /* The syslog file structure */ @@ -101,7 +101,7 @@ struct syslog_dev_s /* This is the device structure for the console or syslogging function. */ -static struct syslog_dev_s g_sysdev; +static struct syslog_dev_s g_syslog_dev; static const uint8_t g_syscrlf[2] = { '\r', '\n' @@ -112,25 +112,25 @@ static const uint8_t g_syscrlf[2] = ****************************************************************************/ /**************************************************************************** - * Name: syslog_takesem + * Name: syslog_dev_takesem * * Description: * Write to the syslog device * ****************************************************************************/ -static inline int syslog_takesem(void) +static inline int syslog_dev_takesem(void) { pid_t me = getpid(); int ret; /* Does this thread already hold the semaphore? That could happen if * we wer called recursively, i.e., if the logic kicked off by - * syslog_write() where to generate more debug output. Return an error + * syslog_dev_write() where to generate more debug output. Return an error * in that case. */ - if (g_sysdev.sl_holder == me) + if (g_syslog_dev.sl_holder == me) { /* Return an error (instead of deadlocking) */ @@ -141,7 +141,7 @@ static inline int syslog_takesem(void) * thread. Wait for it to become available. */ - ret = sem_wait(&g_sysdev.sl_sem); + ret = sem_wait(&g_syslog_dev.sl_sem); if (ret < 0) { return -get_errno(); @@ -151,53 +151,53 @@ static inline int syslog_takesem(void) * of the semaphore. */ - g_sysdev.sl_holder = me; + g_syslog_dev.sl_holder = me; return OK; } /**************************************************************************** - * Name: syslog_givesem + * Name: syslog_dev_givesem * * Description: * Write to the syslog device * ****************************************************************************/ -static inline void syslog_givesem(void) +static inline void syslog_dev_givesem(void) { #ifdef CONFIG_DEBUG_ASSERTIONS pid_t me = getpid(); - DEBUGASSERT(g_sysdev.sl_holder == me); + DEBUGASSERT(g_syslog_dev.sl_holder == me); #endif /* Relinquish the semaphore */ - g_sysdev.sl_holder = NO_HOLDER; - sem_post(&g_sysdev.sl_sem); + g_syslog_dev.sl_holder = NO_HOLDER; + sem_post(&g_syslog_dev.sl_sem); } /**************************************************************************** - * Name: syslog_write + * Name: syslog_dev_write * * Description: * Write to the syslog device * ****************************************************************************/ -static inline ssize_t syslog_write(FAR const void *buf, size_t nbytes) +static inline ssize_t syslog_dev_write(FAR const void *buf, size_t nbytes) { FAR struct inode *inode; /* Let the driver perform the write */ - inode = g_sysdev.sl_file.f_inode; + inode = g_syslog_dev.sl_file.f_inode; DEBUGASSERT(inode != NULL); - return inode->u.i_ops->write(&g_sysdev.sl_file, buf, nbytes); + return inode->u.i_ops->write(&g_syslog_dev.sl_file, buf, nbytes); } /**************************************************************************** - * Name: syslog_flush + * Name: syslog_dev_flush * * Description: * Flush any buffer data in the file system to media. @@ -205,9 +205,9 @@ static inline ssize_t syslog_write(FAR const void *buf, size_t nbytes) ****************************************************************************/ #ifndef CONFIG_DISABLE_MOUNTPOINT -static inline void syslog_flush(void) +static inline void syslog_dev_flush(void) { - FAR struct inode *inode = g_sysdev.sl_file.f_inode; + FAR struct inode *inode = g_syslog_dev.sl_file.f_inode; /* Is this a mountpoint? Does it support the sync method? */ @@ -216,7 +216,7 @@ static inline void syslog_flush(void) { /* Yes... synchronize to the stream */ - (void)inode->u.i_mops->sync(&g_sysdev.sl_file); + (void)inode->u.i_mops->sync(&g_syslog_dev.sl_file); } } #endif @@ -259,10 +259,10 @@ int syslog_dev_initialize(void) * SYSLOG_REOPEN.. Not SYSLOG_INITIALIZING, SYSLOG_FAILURE, SYSLOG_OPENED. */ - DEBUGASSERT(g_sysdev.sl_state == SYSLOG_UNINITIALIZED || - g_sysdev.sl_state == SYSLOG_REOPEN); + DEBUGASSERT(g_syslog_dev.sl_state == SYSLOG_UNINITIALIZED || + g_syslog_dev.sl_state == SYSLOG_REOPEN); - g_sysdev.sl_state = SYSLOG_INITIALIZING; + g_syslog_dev.sl_state = SYSLOG_INITIALIZING; /* Open the device driver. */ @@ -282,7 +282,7 @@ int syslog_dev_initialize(void) * not yet been installed. */ - g_sysdev.sl_state = SYSLOG_REOPEN; + g_syslog_dev.sl_state = SYSLOG_REOPEN; return -errcode; } @@ -291,23 +291,23 @@ int syslog_dev_initialize(void) * descriptor allows us to use the device on all threads in all tasks. */ - ret = file_detach(fd, &g_sysdev.sl_file); + ret = file_detach(fd, &g_syslog_dev.sl_file); if (ret < 0) { /* This should not happen and means that something very bad has * occurred. */ - g_sysdev.sl_state = SYSLOG_FAILURE; + g_syslog_dev.sl_state = SYSLOG_FAILURE; close(fd); return ret; } /* The SYSLOG device is open and ready for writing. */ - sem_init(&g_sysdev.sl_sem, 0, 1); - g_sysdev.sl_holder = NO_HOLDER; - g_sysdev.sl_state = SYSLOG_OPENED; + sem_init(&g_syslog_dev.sl_sem, 0, 1); + g_syslog_dev.sl_holder = NO_HOLDER; + g_syslog_dev.sl_state = SYSLOG_OPENED; return OK; } @@ -368,12 +368,12 @@ int syslog_putc(int ch) * has been successfully opened. */ - if (g_sysdev.sl_state != SYSLOG_OPENED) + if (g_syslog_dev.sl_state != SYSLOG_OPENED) { /* Case (1) and (2) */ - if (g_sysdev.sl_state == SYSLOG_UNINITIALIZED || - g_sysdev.sl_state == SYSLOG_INITIALIZING) + if (g_syslog_dev.sl_state == SYSLOG_UNINITIALIZED || + g_syslog_dev.sl_state == SYSLOG_INITIALIZING) { errcode = EAGAIN; /* Can't access the SYSLOG now... maybe next time? */ goto errout_with_errcode; @@ -381,7 +381,7 @@ int syslog_putc(int ch) /* Case (6) */ - if (g_sysdev.sl_state == SYSLOG_FAILURE) + if (g_syslog_dev.sl_state == SYSLOG_FAILURE) { errcode = ENXIO; /* There is no SYSLOG device */ goto errout_with_errcode; @@ -399,7 +399,7 @@ int syslog_putc(int ch) */ sched_lock(); - if (g_sysdev.sl_state == SYSLOG_REOPEN) + if (g_syslog_dev.sl_state == SYSLOG_REOPEN) { /* Try again to initialize the device. We may do this repeatedly * because the log device might be something that was not ready @@ -418,7 +418,7 @@ int syslog_putc(int ch) } sched_unlock(); - DEBUGASSERT(g_sysdev.sl_state == SYSLOG_OPENED); + DEBUGASSERT(g_syslog_dev.sl_state == SYSLOG_OPENED); } /* Ignore carriage returns */ @@ -432,11 +432,11 @@ int syslog_putc(int ch) * value to write. */ - ret = syslog_takesem(); + ret = syslog_dev_takesem(); if (ret < 0) { /* We probably already hold the semaphore and were probably - * re-entered by the logic kicked off by syslog_write(). + * re-entered by the logic kicked off by syslog_dev_write(). * We might also have been interrupted by a signal. Either * way, we are outta here. */ @@ -451,7 +451,7 @@ int syslog_putc(int ch) { /* Write the CR-LF sequence */ - nbytes = syslog_write(g_syscrlf, 2); + nbytes = syslog_dev_write(g_syscrlf, 2); /* Synchronize the file when each CR-LF is encountered (i.e., * implements line buffering always). @@ -460,7 +460,7 @@ int syslog_putc(int ch) #ifndef CONFIG_DISABLE_MOUNTPOINT if (nbytes > 0) { - syslog_flush(); + syslog_dev_flush(); } #endif } @@ -469,10 +469,10 @@ int syslog_putc(int ch) /* Write the non-newline character (and don't flush) */ uch = (uint8_t)ch; - nbytes = syslog_write(&uch, 1); + nbytes = syslog_dev_write(&uch, 1); } - syslog_givesem(); + syslog_dev_givesem(); /* Check if the write was successful. If not, nbytes will be * a negated errno value. diff --git a/drivers/syslog/syslog_initialize.c b/drivers/syslog/syslog_initialize.c index 7c4956c6af..21bf757464 100644 --- a/drivers/syslog/syslog_initialize.c +++ b/drivers/syslog/syslog_initialize.c @@ -45,6 +45,8 @@ #include "syslog.h" +#ifndef CONFIG_ARCH_SYSLOG + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -54,10 +56,19 @@ * * Description: * One power up, the SYSLOG facility is non-existent or limited to very - * low-level output. This function is called later in the intialization + * low-level output. This function is called later in the initialization * sequence after full driver support has been initialized. It installs * the configured SYSLOG drivers and enables full SYSLOGing capability. * + * This function performs these basic operations: + * + * - Initialize the SYSLOG device + * - Call syslog_channel() to begin using that device. + * + * If CONFIG_ARCH_SYSLOG is selected, then the architecture-specifica + * logic will provide its own SYSLOG device initialize which must include + * as a minimum a call to syslog_channel() to use the device. + * * Input Parameters: * None * @@ -92,3 +103,5 @@ int syslog_initialize(void) return ret; } + +#endif /* CONFIG_ARCH_SYSLOG */ diff --git a/include/nuttx/syslog/syslog.h b/include/nuttx/syslog/syslog.h index e9572ba790..c18a714676 100644 --- a/include/nuttx/syslog/syslog.h +++ b/include/nuttx/syslog/syslog.h @@ -97,15 +97,25 @@ extern "C" /**************************************************************************** * Public Function Prototypes ****************************************************************************/ + /**************************************************************************** * Name: syslog_initialize * * Description: * One power up, the SYSLOG facility is non-existent or limited to very - * low-level output. This function is called later in the intialization + * low-level output. This function is called later in the initialization * sequence after full driver support has been initialized. It installs * the configured SYSLOG drivers and enables full SYSLOGing capability. * + * This function performs these basic operations: + * + * - Initialize the SYSLOG device + * - Call syslog_channel() to begin using that device. + * + * If CONFIG_ARCH_SYSLOG is selected, then the architecture-specifica + * logic will provide its own SYSLOG device initialize which must include + * as a minimum a call to syslog_channel() to use the device. + * * Input Parameters: * None * @@ -115,7 +125,11 @@ extern "C" * ****************************************************************************/ +#ifndef CONFIG_ARCH_SYSLOG int syslog_initialize(void); +#else +# define syslog_initialize() +#endif /**************************************************************************** * Name: syslog_putc