1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 00:49:45 +01:00

Merge pull request #20894 from Enoch247/littlefs-logging

pkg/littlefs: make use of RIOT's log module instead of pkg provided macros
This commit is contained in:
mguetschow 2024-10-17 08:18:37 +00:00 committed by GitHub
commit 4f5c0ed3f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 179 additions and 8 deletions

View File

@ -8,10 +8,8 @@ include $(RIOTBASE)/pkg/pkg.mk
CFLAGS += -Wno-format
# Disable debug printing
ifneq ($(DEVELHELP),1)
CFLAGS += -DLFS_NO_DEBUG -DLFS_NO_WARN -DLFS_NO_ERROR
endif
# replace pkg supplied logging macros with RIOT's
CFLAGS += -include $(PKG_DIR)/lfs_log.h
all:
$(QQ)"$(MAKE)" -C $(PKG_SOURCE_DIR) -f $(RIOTBASE)/Makefile.base

74
pkg/littlefs/lfs_log.h Normal file
View File

@ -0,0 +1,74 @@
/*
* Copyright (C) 2024 Joshua DeWeese <josh.deweese@gmail.com>
*
* This file is subject to the terms and conditions of the GNU Lesser General
* Public License v2.1. See the file LICENSE in the top level directory for more
* details.
*/
/**
* @ingroup sys_littlefs
* @{
*
* @file
* @brief littlefs logging macro overrides
*
* This header provides re-implementations of the logging and debugging macros
* used in littlefs. This is to allow the package to make use of RIOT's own
* modules for logging and debugging.
*
* @author Joshua DeWeese <josh.deweese@gmail.com>
*
*/
#ifndef LFS_LOG_H
#define LFS_LOG_H
#ifdef __cplusplus
extern "C" {
#endif
#include "log.h"
/**
* @brief Private macro for routing littlefs log msgs to RIOT's log module.
*
* @param[in] level log level of this log message
* @param[in] fmt printf style format string
* @param[inout] ... printf style variadic args
*/
#define _LFS_LOG(level, fmt, ...)\
LOG(level, "lfs: " fmt "%s\n", __VA_ARGS__)
/** */
/**
* @name littlefs overrides
* @{
* @brief Re-implementation of littlefs's logging and debugging macros.
*/
/** override of littlefs's `LFS_DEBUG()` */
#ifndef LFS_NO_DEBUG
# define LFS_DEBUG(...) _LFS_LOG(LOG_DEBUG, __VA_ARGS__, "")
#else
# define LFS_DEBUG(...)
#endif
/** override of littlefs's `LFS_WARN()` */
#ifndef LFS_NO_WARN
# define LFS_WARN(...) _LFS_LOG(LOG_WARNING, __VA_ARGS__, "")
#else
# define LFS_WARN(...)
#endif
/** override of littlefs's `LFS_ERROR()` */
#ifndef LFS_NO_ERROR
# define LFS_ERROR(...) _LFS_LOG(LOG_ERROR, __VA_ARGS__, "")
#else
# define LFS_ERROR(...)
#endif
/** @} */
#endif /* LFS_LOG_H */
/** @} */

View File

@ -8,10 +8,8 @@ include $(RIOTBASE)/pkg/pkg.mk
CFLAGS += -Wno-format
# Disable debug printing
ifneq ($(DEVELHELP),1)
CFLAGS += -DLFS_NO_DEBUG -DLFS_NO_WARN -DLFS_NO_ERROR
endif
# replace pkg supplied logging macros with RIOT's
CFLAGS += -include $(PKG_DIR)/lfs_log.h
all:
$(QQ)"$(MAKE)" -C $(PKG_SOURCE_DIR) -f $(RIOTBASE)/Makefile.base

95
pkg/littlefs2/lfs_log.h Normal file
View File

@ -0,0 +1,95 @@
/*
* Copyright (C) 2024 Joshua DeWeese <josh.deweese@gmail.com>
*
* This file is subject to the terms and conditions of the GNU Lesser General
* Public License v2.1. See the file LICENSE in the top level directory for more
* details.
*/
/**
* @ingroup sys_littlefs2
* @{
*
* @file
* @brief littlefs v2 logging macro overrides
*
* This header provides re-implementations of the logging and debugging macros
* used in littlefs. This is to allow the package to make use of RIOT's own
* modules for logging and debugging.
*
* @author Joshua DeWeese <josh.deweese@gmail.com>
*
*/
#ifndef LFS_LOG_H
#define LFS_LOG_H
#ifdef __cplusplus
extern "C" {
#endif
#include "log.h"
#ifdef LFS_YES_TRACE
# define ENABLE_DEBUG 1
#endif
#include "debug.h"
/**
* @brief Private macro for routing littlefs trace msgs to RIOT's DEBUG macro.
*
* @param[in] fmt printf style format string
* @param[inout] ... printf style variadic args
*/
#define _LFS_TRACE(fmt, ...) \
DEBUG("%s:%d: " fmt "%s\n", __FILE__, __LINE__, __VA_ARGS__)
/**
* @brief Private macro for routing littlefs log msgs to RIOT's log module.
*
* @param[in] level log level of this log message
* @param[in] fmt printf style format string
* @param[inout] ... printf style variadic args
*/
#define _LFS_LOG(level, fmt, ...)\
LOG(level, "lfs: " fmt "%s\n", __VA_ARGS__)
/** */
/**
* @name littlefs overrides
* @{
* @brief Re-implementation of littlefs's logging and debugging macros.
*/
/** override of littlefs's `LFS_TRACE()` */
#ifdef LFS_YES_TRACE
# define LFS_TRACE(...) _LFS_TRACE(__VA_ARGS__, "")
#else
# define LFS_TRACE(...)
#endif
/** override of littlefs's `LFS_DEBUG()` */
#ifndef LFS_NO_DEBUG
# define LFS_DEBUG(...) _LFS_LOG(LOG_DEBUG, __VA_ARGS__, "")
#else
# define LFS_DEBUG(...)
#endif
/** override of littlefs's `LFS_WARN()` */
#ifndef LFS_NO_WARN
# define LFS_WARN(...) _LFS_LOG(LOG_WARNING, __VA_ARGS__, "")
#else
# define LFS_WARN(...)
#endif
/** override of littlefs's `LFS_ERROR()` */
#ifndef LFS_NO_ERROR
# define LFS_ERROR(...) _LFS_LOG(LOG_ERROR, __VA_ARGS__, "")
#else
# define LFS_ERROR(...)
#endif
/** @} */
#endif /* LFS_LOG_H */
/** @} */

View File

@ -4,4 +4,7 @@ USEMODULE += littlefs
USEMODULE += embunit
USEMODULE += mtd_emulated
# silence expected errors
CFLAGS += -DLOG_LEVEL=LOG_NONE
include $(RIOTBASE)/Makefile.include

View File

@ -4,4 +4,7 @@ USEPKG += littlefs2
USEMODULE += embunit
USEMODULE += mtd_emulated
# silence expected errors
CFLAGS += -DLOG_LEVEL=LOG_NONE
include $(RIOTBASE)/Makefile.include