KM3NeT CLB  2.0
KM3NeT CLB v2 Embedded Software
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
loghist.h
Go to the documentation of this file.
1 /*
2  * KM3NeT CLB v2 Firmware
3  * ----------------------
4  *
5  * Copyright 2012-2015 KM3NeT Collaboration
6  *
7  * All Rights Reserved.
8  *
9  *
10  * File : loghist.h
11  * Created : 28 sep. 2015
12  * Author : Vincent van Beveren
13  */
14 #ifndef KERNEL_LOGHIST_H_
15 #define KERNEL_LOGHIST_H_
16 
17 /**
18  * @file
19  *
20  * @ingroup kernel
21  *
22  * Stores logging history. It uses RAM (fast) and FLASH (log term)
23  */
24 #define LH_BUFFER_LENGTH 16 ///< Maximum number of entries stored in memory
25 #define LH_BUFFER_WIDTH 80 ///< Maximum width of the in memory log lines
26 
27 #include <stdbool.h>
28 #include <stdint.h>
29 #include "util/log.h"
30 
31 /**
32  * Boolean to enable to disable the writing of logging to the flash.
33  *
34  * Set to true by default, but will only work after successful initialization of flash through
35  * lhFlashInit.
36  */
37 extern bool lhEnableFlashWrite;
38 
39 /**
40  * Initializes the flash storage (may take a while).
41  */
42 bool lhFlashInit();
43 
44 
45 /**
46  * Start the iteration through the flash entries.
47  *
48  * @param count The maximum number of entries you wish to retrieve.
49  *
50  * @retval true Success
51  * @retval false Failure, check error module.
52  */
53 bool lhFlashItStart(int count);
54 
55 /**
56  * Get the next element.
57  *
58  * @retval true Next log entry written to buffer.
59  * @retval false No new entry.
60  */
61 bool lhFlashItNext(char * bufPtr, int bufSize);
62 
63 
64 /**
65  * Stores a line in the buffer, and in flash if activated.
66  */
67 void lhStore(LogLevel level, char * msg);
68 
69 /**
70  * Returns a line from the in memory log, where index 0 is the last
71  * logged line.
72  *
73  * The maximum number of idx is defined in SYS_LOG_BUFFER_LENGTH.
74  *
75  * @param idx Index, 0 - last logged line.
76  * @return A pointer to the logging entry, or NULL / empty string if there is none.
77  */
78 char * lhGetLine(int idx);
79 
80 /**
81  * Returns the last log-line based on log-line ID.
82  *
83  * Returns from the log-buffer a single log line. The provided ID represents the log-line you last
84  * got returned, or 0 if you did not receive a line yet.
85  *
86  * The provided character pointer-pointer will point to a log line, if available, or else NULL.
87  *
88  * If there is any logging available, and which you did get yet, it will return the oldest still
89  * available logging, and return its ID. Usually this is lastId + 1.
90  *
91  * If the lastId provided is older than what is available in the log buffer, the oldest available
92  * entry is returned, and the associated ID.
93  *
94  * If the lastId provided is the last logged line, the returned log line ID is the same, and the
95  * log-line pointer will not be filled.
96  *
97  * @note this feature is especially for remote devices wishing to load the latest logging lines.
98  *
99  *
100  * @param lastId The last logID returned
101  * @param logLinePtr A pointer pointer to be set
102  *
103  * @return A new log-line ID.
104  */
105 uint32_t lhGetLineById(uint32_t lastId, char ** logLinePtr);
106 
107 
108 
109 #endif /* KERNEL_LOGHIST_H_ */
char * lhGetLine(int idx)
Returns a line from the in memory log, where index 0 is the last logged line.
Definition: loghist.c:328
bool lhFlashInit()
Initializes the flash storage (may take a while).
Definition: loghist.c:110
bool lhFlashItNext(char *bufPtr, int bufSize)
Get the next element.
Definition: loghist.c:250
void lhStore(LogLevel level, char *msg)
Stores a line in the buffer, and in flash if activated.
Definition: loghist.c:316
uint32_t lhGetLineById(uint32_t lastId, char **logLinePtr)
Returns the last log-line based on log-line ID.
Definition: loghist.c:214
LogLevel
Logging levels.
Definition: log.h:68
bool lhEnableFlashWrite
Boolean to enable to disable the writing of logging to the flash.
Definition: loghist.c:58
bool lhFlashItStart(int count)
Start the iteration through the flash entries.
Definition: loghist.c:230
Implements a generic logger facility.