Files
2016-10-07 23:44:50 +02:00

71 lines
2.8 KiB
C

#ifndef LOG_H_
#define LOG_H_
/** @file */
#include "Common.h"
#define LOG_SIZE 2048
#define FRAM_LOG_START_ADDR 0x4000 // from the start of the second half of FRAM
#define FRAM_LOG_SIZE 0x4000 // the whole second half
/** Enum for log entry type. \note Every entry type has a specific integer value, which can be found in the source code. */
typedef enum {
/* Generic */
LOG_INFO_GENERIC = 0x10, ///< Unspecific log entry.
LOG_INFO_CONFIG_SET = 0x11, ///< Configuration change.
LOG_INFO_SETTING_SET = 0x12, ///< Setting change.
LOG_INFO_UID_SET = 0x13, ///< UID change.
LOG_INFO_RESET_APP = 0x20, ///< Application reset.
/* Codec */
LOG_INFO_CODEC_RX_DATA = 0x40, ///< Currently active codec received data.
LOG_INFO_CODEC_TX_DATA = 0x41, ///< Currently active codec sent data.
/* App */
LOG_INFO_APP_CMD_READ = 0x80, ///< Application processed read command.
LOG_INFO_APP_CMD_WRITE = 0x81, ///< Application processed write command.
LOG_INFO_APP_CMD_INC = 0x84, ///< Application processed increment command.
LOG_INFO_APP_CMD_DEC = 0x85, ///< Application processed decrement command.
LOG_INFO_APP_CMD_TRANSFER = 0x86, ///< Application processed transfer command.
LOG_INFO_APP_CMD_RESTORE = 0x87, ///< Application processed restore command.
LOG_INFO_APP_CMD_AUTH = 0x90, ///< Application processed authentication command.
LOG_INFO_APP_CMD_HALT = 0x91, ///< Application processed halt command.
LOG_INFO_APP_CMD_UNKNOWN = 0x92, ///< Application processed an unknown command.
LOG_INFO_APP_AUTHING = 0xA0, ///< Application is in `authing` state.
LOG_INFO_APP_AUTHED = 0xA1, ///< Application is in `auth` state.
LOG_ERR_APP_AUTH_FAIL = 0xC0, ///< Application authentication failed.
LOG_ERR_APP_CHECKSUM_FAIL = 0xC1, ///< Application had a checksum fail.
LOG_ERR_APP_NOT_AUTHED = 0xC2, ///< Application is not authenticated.
LOG_EMPTY = 0x00 ///< Empty Log Entry. This is not followed by a length byte nor the two systick bytes nor any data.
} LogEntryEnum;
typedef enum {
LOG_MODE_OFF,
LOG_MODE_MEMORY,
LOG_MODE_LIVE
} LogModeEnum;
typedef void (*LogFuncType) (LogEntryEnum Entry, const void* Data, uint8_t Length);
extern LogFuncType CurrentLogFunc;
void LogInit(void);
void LogTick(void);
void LogTask(void);
void LogMemClear(void);
uint16_t LogMemFree(void);
/* XModem callback */
bool LogMemLoadBlock(void* Buffer, uint32_t BlockAddress, uint16_t ByteCount);
void LogSetModeById(LogModeEnum Mode);
bool LogSetModeByName(const char* Mode);
void LogGetModeByName(char* Mode, uint16_t BufferSize);
void LogGetModeList(char* List, uint16_t BufferSize);
void LogSRAMToFRAM(void);
/* Wrapper function to call current logging function */
INLINE void LogEntry(LogEntryEnum Entry, const void* Data, uint8_t Length) { CurrentLogFunc(Entry, Data, Length); }
#endif /* LOG_H_ */