git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@428 05563f52-14a8-4384-a975-3d1654cca0fa
182 lines
4.8 KiB
C
182 lines
4.8 KiB
C
// -----------------------------------------------------------------------------
|
|
/// @file Logger.h
|
|
/// @brief File description
|
|
// -----------------------------------------------------------------------------
|
|
// Micro-Key bv
|
|
// Industrieweg 28, 9804 TG Noordhorn
|
|
// Postbus 92, 9800 AB Zuidhorn
|
|
// The Netherlands
|
|
// Tel: +31 594 503020
|
|
// Fax: +31 594 505825
|
|
// Email: support@microkey.nl
|
|
// Web: www.microkey.nl
|
|
// -----------------------------------------------------------------------------
|
|
/// $Revision$
|
|
/// $Author$
|
|
/// $Date$
|
|
// (c) 2017 Micro-Key bv
|
|
// -----------------------------------------------------------------------------
|
|
|
|
/**
|
|
* %Logger implementation
|
|
* \defgroup Logger Package Logger
|
|
* \ingroup HAL
|
|
* @{
|
|
*/
|
|
|
|
#ifndef _LOGGER_H_
|
|
#define _LOGGER_H_
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// Include files
|
|
// -----------------------------------------------------------------------------
|
|
|
|
#include "stm32f10x.h"
|
|
|
|
#include <stdbool.h>
|
|
#include "FreeRTOS.h"
|
|
|
|
#include "semphr.h"
|
|
#include "queue.h"
|
|
#include "task.h"
|
|
|
|
#include "platform.h"
|
|
#include "IODevice.h"
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// Constant and macro definitions
|
|
// -----------------------------------------------------------------------------
|
|
|
|
/**
|
|
* Logs an error
|
|
* \memberof Logger
|
|
*/
|
|
#define LOGGER_ERROR(a, ...) \
|
|
Logger_log(a, __FILE__, __func__, __LINE__, LOGTYPE_ERROR, ##__VA_ARGS__)
|
|
|
|
/**
|
|
* Logs an error
|
|
* \memberof Logger
|
|
*/
|
|
#define LOGGER_WARNING(a, ...) \
|
|
Logger_log(a, __FILE__, __func__, __LINE__, LOGTYPE_WARNING, ##__VA_ARGS__)
|
|
|
|
/**
|
|
* Logs an error
|
|
* \memberof Logger
|
|
*/
|
|
#define LOGGER_INFO(a, ...) \
|
|
Logger_log(a, __FILE__, __func__, __LINE__, LOGTYPE_INFO, ##__VA_ARGS__)
|
|
|
|
/**
|
|
* Logs an error
|
|
* \memberof Logger
|
|
*/
|
|
#define LOGGER_DEBUG(a, ...) \
|
|
Logger_log(a, __FILE__, __func__, __LINE__, LOGTYPE_DEBUG, ##__VA_ARGS__)
|
|
|
|
/**
|
|
* Logs an error
|
|
* \memberof Logger
|
|
*/
|
|
#define LOGGER_PRINT(a, ...) \
|
|
Logger_log(a, "", "", 0, LOGTYPE_PRINT, ##__VA_ARGS__)
|
|
|
|
/**
|
|
* Logs an error
|
|
* \memberof Logger
|
|
*/
|
|
#define LOGGER_ERROR_ISR(a, ...) \
|
|
Logger_logISR(a, __FILE__, __func__, __LINE__, LOGTYPE_ERROR, ##__VA_ARGS__)
|
|
|
|
/**
|
|
* Logs an error
|
|
* \memberof Logger
|
|
*/
|
|
#define LOGGER_WARNING_ISR(a, ...) \
|
|
Logger_logISR(a, __FILE__, __func__, __LINE__, LOGTYPE_WARNING, ##__VA_ARGS__)
|
|
|
|
/**
|
|
* Logs an error
|
|
* \memberof Logger
|
|
*/
|
|
#define LOGGER_INFO_ISR(a, ...) \
|
|
Logger_logISR(a, __FILE__, __func__, __LINE__, LOGTYPE_INFO, ##__VA_ARGS__)
|
|
|
|
/**
|
|
* Logs an error
|
|
* \memberof Logger
|
|
*/
|
|
#define LOGGER_DEBUG_ISR(a, ...) \
|
|
Logger_logISR(a, __FILE__, __func__, __LINE__, LOGTYPE_DEBUG, ##__VA_ARGS__)
|
|
|
|
/**
|
|
* Logs an error
|
|
* \memberof Logger
|
|
*/
|
|
#define LOGGER_PRINT_ISR(a, ...) \
|
|
Logger_logISR(a, "", "", 0, LOGTYPE_PRINT, ##__VA_ARGS__)
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// Type definitions.
|
|
// -----------------------------------------------------------------------------
|
|
|
|
typedef enum
|
|
{
|
|
LOGTYPE_PRINT, /**< Raw print */
|
|
LOGTYPE_DEBUG, /**< Debug information only; will not be stored on SD-card */
|
|
LOGTYPE_INFO, /**< Informational messages of important events */
|
|
LOGTYPE_WARNING, /**< Recoverable fault */
|
|
LOGTYPE_ERROR /**< Unrecoverable fault */
|
|
} LogType;
|
|
|
|
|
|
struct LogQueueItem
|
|
{
|
|
char fileName[32];
|
|
char functionName[32];
|
|
char context[128];
|
|
int lineNumber;
|
|
LogType logType;
|
|
};
|
|
|
|
struct Logger
|
|
{
|
|
struct IODevice* loggingDevice;
|
|
TaskHandle_t taskHandle;
|
|
int TaskPriority;
|
|
uint16_t stackSize;
|
|
bool runTask;
|
|
QueueHandle_t logQueue;
|
|
bool initialized;
|
|
};
|
|
// -----------------------------------------------------------------------------
|
|
// Function declarations
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
extern ErrorStatus Logger_construct(struct Logger* self, struct IODevice* const device, int taskPriority, uint16_t stackSize);
|
|
extern void Logger_terminate(struct Logger* self);
|
|
|
|
void Logger_logISR(struct Logger* self, const char* fileName, const char* functionName, int lineNumber, LogType logType, const char* context);
|
|
|
|
/**
|
|
* Logs a string.
|
|
* Use the Logging macros instead
|
|
* \memberof Logger
|
|
* \private
|
|
* \param fileName File name to be logged
|
|
* \param functionName Function name to be logged
|
|
* \param lineNumber Line number to be logged
|
|
* \param logType Type of logging
|
|
* \param format printf-type formatting string
|
|
* \param ... Variable arguments according to the formatting string
|
|
*/
|
|
void Logger_log(struct Logger* self, const char* fileName, const char* functionName, int lineNumber, LogType logType, const char* format, ...) __attribute__((format(printf, 6, 7)));
|
|
|
|
#endif
|
|
|
|
/** @} */
|