Contiki 3.x
tsch-log.h
1 /*
2  * Copyright (c) 2014, SICS Swedish ICT.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * This file is part of the Contiki operating system.
30  *
31  */
32 
33 #ifndef __TSCH_LOG_H__
34 #define __TSCH_LOG_H__
35 
36 /********** Includes **********/
37 
38 #include "contiki.h"
39 #include "sys/rtimer.h"
41 
42 /******** Configuration *******/
43 
44 /* The length of the log queue, i.e. maximum number postponed log messages */
45 #ifdef TSCH_LOG_CONF_QUEUE_LEN
46 #define TSCH_LOG_QUEUE_LEN TSCH_LOG_CONF_QUEUE_LEN
47 #else /* TSCH_LOG_CONF_QUEUE_LEN */
48 #define TSCH_LOG_QUEUE_LEN 8
49 #endif /* TSCH_LOG_CONF_QUEUE_LEN */
50 
51 /* Returns an integer ID from a link-layer address */
52 #ifdef TSCH_LOG_CONF_ID_FROM_LINKADDR
53 #define TSCH_LOG_ID_FROM_LINKADDR(addr) TSCH_LOG_CONF_ID_FROM_LINKADDR(addr)
54 #else /* TSCH_LOG_ID_FROM_LINKADDR */
55 #define TSCH_LOG_ID_FROM_LINKADDR(addr) ((addr) ? (addr)->u8[LINKADDR_SIZE - 1] : 0)
56 #endif /* TSCH_LOG_ID_FROM_LINKADDR */
57 
58 /* TSCH log levels:
59  * 0: no log
60  * 1: basic PRINTF enabled
61  * 2: basic PRINTF enabled and tsch-log module enabled */
62 #ifdef TSCH_LOG_CONF_LEVEL
63 #define TSCH_LOG_LEVEL TSCH_LOG_CONF_LEVEL
64 #else /* TSCH_LOG_CONF_LEVEL */
65 #define TSCH_LOG_LEVEL 2
66 #endif /* TSCH_LOG_CONF_LEVEL */
67 
68 #if TSCH_LOG_LEVEL < 2 /* For log level 0 or 1, the logging functions do nothing */
69 
70 #define tsch_log_init()
71 #define tsch_log_process_pending()
72 #define TSCH_LOG_ADD(log_type, init_code)
73 
74 #else /* TSCH_LOG_LEVEL */
75 
76 /************ Types ***********/
77 
78 /* Structure for a log. Union of different types of logs */
79 struct tsch_log_t {
80  enum { tsch_log_tx,
81  tsch_log_rx,
82  tsch_log_message
83  } type;
84  struct asn_t asn;
85  struct tsch_link *link;
86  union {
87  char message[48];
88  struct {
89  int mac_tx_status;
90  int dest;
91  int drift;
92  uint8_t num_tx;
93  uint8_t datalen;
94  uint8_t is_data;
95  uint8_t sec_level;
96  uint8_t drift_used;
97  } tx;
98  struct {
99  int src;
100  int drift;
101  int estimated_drift;
102  uint8_t datalen;
103  uint8_t is_unicast;
104  uint8_t is_data;
105  uint8_t sec_level;
106  uint8_t drift_used;
107  } rx;
108  };
109 };
110 
111 /********** Functions *********/
112 
113 /* Prepare addition of a new log.
114  * Returns pointer to log structure if success, NULL otherwise */
115 struct tsch_log_t *tsch_log_prepare_add(void);
116 /* Actually add the previously prepared log */
117 void tsch_log_commit(void);
118 /* Initialize log module */
119 void tsch_log_init(void);
120 /* Process pending log messages */
121 void tsch_log_process_pending(void);
122 
123 /************ Macros **********/
124 
125 /* Use this macro to add a log to the queue (will be printed out
126  * later, after leaving interrupt context) */
127 #define TSCH_LOG_ADD(log_type, init_code) do { \
128  struct tsch_log_t *log = tsch_log_prepare_add(); \
129  if(log != NULL) { \
130  log->type = (log_type); \
131  init_code; \
132  tsch_log_commit(); \
133  } \
134 } while(0);
135 
136 #endif /* TSCH_LOG_LEVEL */
137 
138 #endif /* __TSCH_LOG_H__ */
Header file for the real-time timer module.
Private TSCH definitions (meant for use by TSCH implementation files only) ...