Contiki-NG
tsch-log.h
Go to the documentation of this file.
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 /**
34  * \addtogroup tsch
35  * @{
36  * \file
37  * TSCH per-slot logging
38 */
39 
40 #ifndef __TSCH_LOG_H__
41 #define __TSCH_LOG_H__
42 
43 /********** Includes **********/
44 
45 #include "contiki.h"
46 #include "sys/rtimer.h"
47 
48 /******** Configuration *******/
49 
50 /* TSCH per-slot logging. Enabled by default if DBG is enabled */
51 #ifdef TSCH_LOG_CONF_PER_SLOT
52 #define TSCH_LOG_PER_SLOT TSCH_LOG_CONF_PER_SLOT
53 #else /* TSCH_LOG_CONF_PER_SLOT */
54 #include "sys/log.h"
55 #define TSCH_LOG_PER_SLOT (LOG_CONF_LEVEL_MAC >= LOG_LEVEL_DBG)
56 #endif /* TSCH_LOG_CONF_PER_SLOT */
57 
58 /* The length of the log queue, i.e. maximum number postponed log messages */
59 #ifdef TSCH_LOG_CONF_QUEUE_LEN
60 #define TSCH_LOG_QUEUE_LEN TSCH_LOG_CONF_QUEUE_LEN
61 #else /* TSCH_LOG_CONF_QUEUE_LEN */
62 #define TSCH_LOG_QUEUE_LEN 8
63 #endif /* TSCH_LOG_CONF_QUEUE_LEN */
64 
65 #if (TSCH_LOG_PER_SLOT == 0)
66 
67 #define tsch_log_init()
68 #define tsch_log_process_pending()
69 #define TSCH_LOG_ADD(log_type, init_code)
70 
71 #else /* (TSCH_LOG_PER_SLOT == 0) */
72 
73 /************ Types ***********/
74 
75 /** \brief Structure for a log. Union of different types of logs */
76 struct tsch_log_t {
77  enum { tsch_log_tx,
78  tsch_log_rx,
79  tsch_log_message
80  } type;
81  struct tsch_asn_t asn;
82  struct tsch_link *link;
83  uint8_t burst_count;
84  uint8_t channel;
85  union {
86  char message[48];
87  struct {
88  int mac_tx_status;
89  linkaddr_t dest;
90  int drift;
91  uint8_t num_tx;
92  uint8_t datalen;
93  uint8_t is_data;
94  uint8_t sec_level;
95  uint8_t drift_used;
96  uint8_t seqno;
97  } tx;
98  struct {
99  linkaddr_t 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  uint8_t seqno;
108  } rx;
109  };
110 };
111 
112 /********** Functions *********/
113 
114 /**
115  * \brief Prepare addition of a new log.
116  * \return A pointer to log structure if success, NULL otherwise
117  */
118 struct tsch_log_t *tsch_log_prepare_add(void);
119 /**
120  * \brief Actually add the previously prepared log
121  */
122 void tsch_log_commit(void);
123 /**
124  * \brief Initialize log module
125  */
126 void tsch_log_init(void);
127 /**
128  * \brief Process pending log messages
129  */
130 void tsch_log_process_pending(void);
131 /**
132  * \brief Stop logging module
133  */
134 void tsch_log_stop(void);
135 
136 /************ Macros **********/
137 
138 /** \brief Use this macro to add a log to the queue (will be printed out
139  * later, after leaving interrupt context) */
140 #define TSCH_LOG_ADD(log_type, init_code) do { \
141  struct tsch_log_t *log = tsch_log_prepare_add(); \
142  if(log != NULL) { \
143  log->type = (log_type); \
144  init_code; \
145  tsch_log_commit(); \
146  } \
147 } while(0);
148 
149 #endif /* (TSCH_LOG_PER_SLOT == 0) */
150 
151 #endif /* __TSCH_LOG_H__ */
152 /** @} */
void tsch_log_process_pending(void)
Process pending log messages.
Structure for a log.
Definition: tsch-log.h:76
void tsch_log_init(void)
Initialize log module.
struct tsch_log_t * tsch_log_prepare_add(void)
Prepare addition of a new log.
void tsch_log_stop(void)
Stop logging module.
Header file for the real-time timer module.
void tsch_log_commit(void)
Actually add the previously prepared log.
Header file for the logging system
The ASN is an absolute slot number over 5 bytes.
Definition: tsch-asn.h:48