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  uint8_t channel_offset;
86  union {
87  char message[48];
88  struct {
89  int mac_tx_status;
90  linkaddr_t 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  uint8_t seqno;
98  } tx;
99  struct {
100  linkaddr_t src;
101  int drift;
102  int estimated_drift;
103  uint8_t datalen;
104  uint8_t is_unicast;
105  uint8_t is_data;
106  uint8_t sec_level;
107  uint8_t drift_used;
108  uint8_t seqno;
109  } rx;
110  };
111 };
112 
113 /********** Functions *********/
114 
115 /**
116  * \brief Prepare addition of a new log.
117  * \return A pointer to log structure if success, NULL otherwise
118  */
119 struct tsch_log_t *tsch_log_prepare_add(void);
120 /**
121  * \brief Actually add the previously prepared log
122  */
123 void tsch_log_commit(void);
124 /**
125  * \brief Initialize log module
126  */
127 void tsch_log_init(void);
128 /**
129  * \brief Process pending log messages
130  */
131 void tsch_log_process_pending(void);
132 /**
133  * \brief Stop logging module
134  */
135 void tsch_log_stop(void);
136 
137 /************ Macros **********/
138 
139 /** \brief Use this macro to add a log to the queue (will be printed out
140  * later, after leaving interrupt context) */
141 #define TSCH_LOG_ADD(log_type, init_code) do { \
142  struct tsch_log_t *log = tsch_log_prepare_add(); \
143  if(log != NULL) { \
144  log->type = (log_type); \
145  init_code; \
146  tsch_log_commit(); \
147  } \
148 } while(0);
149 
150 #endif /* (TSCH_LOG_PER_SLOT == 0) */
151 
152 #endif /* __TSCH_LOG_H__ */
153 /** @} */
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