Wifly Driver  V1.0
Log.c
Go to the documentation of this file.
1 /*
2  * Log.c
3  *
4  * Created on: 10/10/2015
5  * Author: Victor
6  */
7 
8 #include "LPC17xx.h"
9 #include "stdio.h"
10 #include "stdlib.h"
11 #include <string.h>
12 #include <stdarg.h>
13 #include "FreeRTOS.h"
14 #include "semphr.h"
15 
16 #include "Type.h"
17 #include "Config.h"
18 #include "PrintF.h"
19 #include "Log.h"
20 
21 /* BUFFER SIZE */
22 #define LOGBUFSIZE (BUFSIZE_DEBUG)
23 
24 uint32_t PortNumLog;
25 char string[LOGBUFSIZE];
26 xSemaphoreHandle xMutexLOG;
28 uint32_t Log_start( uint32_t PortNum, uint32_t baudrate )
29 {
30  uint8_t rtn = FALSE;
31  /* Es crea el semàfor si no està creat */
32  if( xMutexLOG == NULL )
33  {
34  xMutexLOG = xSemaphoreCreateMutex();
35  }
36  /*S'utilitza el semàfor per inicialitzar el Port */
37  xSemaphoreTakeRecursive( xMutexLOG, portMAX_DELAY );
38  {
39  /*Inicialitza el Port UART a la velocitat indicada */
40  PortNumLog=PortNum;
41  rtn =PrintF_start(PortNumLog, baudrate);
42 
43  }
44  xSemaphoreGiveRecursive( xMutexLOG );
45  return rtn;
46 }
47 
48 void Log_slog(const char * restrict format,...)
49 {
50  va_list arg;
51  va_start( arg, format );
52  xSemaphoreTakeRecursive( xMutexLOG, portMAX_DELAY );
53  {
54  /* Mostra el text sel·leccionat amb el Prefix del LOG */
55  PrintF_print(PortNumLog, STRACE, format);
56  }
57  xSemaphoreGiveRecursive( xMutexLOG );
58  return;
59 }
60 
61 void Log_log( uint8_t severity, uint8_t logLevel, const char * restrict format,...)
62 {
63  va_list arg;
64 
65  //Check if the severity level is equivalent to the requested type of log to send
66  if (severity>=logLevel)
67  {
68  xSemaphoreTakeRecursive( xMutexLOG, portMAX_DELAY );
69  {
70  va_start( arg, format);
71 
72  Log_level(logLevel); /* writes the type of log prefix */
73  vsprintf(string, format, arg);
74  strcat(string,SCRLF);
75  PrintF_print(PortNumLog, string);
76 
77  va_end(arg);
78  }
79  xSemaphoreGiveRecursive( xMutexLOG );
80  }
81  return;
82 }
83 
84 void Log_level(uint8_t logLevel)
85 {
86 
87  xSemaphoreTakeRecursive( xMutexLOG, portMAX_DELAY );
88  {
89  switch (logLevel)
90  {
91  case LV_TRACE: /* Trace level */
93  break;
94 
95  case LV_INFO: /* Info level */
97  break;
98 
99  case LV_ERR: /* Error level */
101  break;
102  }
103  }
104  xSemaphoreGiveRecursive( xMutexLOG );
105  return;
106 }
107 
#define LOGBUFSIZE
Definition: Log.c:22
#define SERROR
Definition: Log.h:16
void Log_level(uint8_t logLevel)
Definition: Log.c:84
#define LV_INFO
Definition: Log.h:20
uint32_t PortNumLog
Definition: Log.c:24
#define LV_TRACE
Definition: Log.h:19
void Log_slog(const char *restrict format,...)
Definition: Log.c:48
#define FALSE
Definition: type.h:22
#define NULL
Definition: type.h:18
#define SCRLF
Definition: Log.h:17
uint32_t Log_start(uint32_t PortNum, uint32_t baudrate)
Definition: Log.c:28
#define SINFO
Definition: Log.h:15
void PrintF_print(uint32_t portNum, const char *restrict format,...)
Definition: PrintF.c:137
#define LV_ERR
Definition: Log.h:21
void Log_log(uint8_t severity, uint8_t logLevel, const char *restrict format,...)
Definition: Log.c:61
#define STRACE
Definition: Log.h:14
uint32_t PrintF_start(uint32_t portNum, uint32_t baudRate)
Definition: PrintF.c:27
xSemaphoreHandle xMutexLOG
Definition: Log.c:26