2015-09-21 20:01:01 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014, SICS Swedish ICT.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the Institute nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* This file is part of the Contiki operating system.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-09-29 20:18:48 +00:00
|
|
|
/**
|
|
|
|
* \addtogroup tsch
|
|
|
|
* @{
|
2018-04-28 20:02:11 +00:00
|
|
|
* \file
|
|
|
|
* TSCH per-slot logging
|
2017-09-29 20:18:48 +00:00
|
|
|
*/
|
|
|
|
|
2015-09-21 20:01:01 +00:00
|
|
|
#ifndef __TSCH_LOG_H__
|
|
|
|
#define __TSCH_LOG_H__
|
|
|
|
|
|
|
|
/********** Includes **********/
|
|
|
|
|
|
|
|
#include "contiki.h"
|
|
|
|
#include "sys/rtimer.h"
|
|
|
|
|
|
|
|
/******** Configuration *******/
|
|
|
|
|
2017-06-20 16:26:31 +00:00
|
|
|
/* TSCH per-slot logging. Enabled by default if DBG is enabled */
|
|
|
|
#ifdef TSCH_LOG_CONF_PER_SLOT
|
|
|
|
#define TSCH_LOG_PER_SLOT TSCH_LOG_CONF_PER_SLOT
|
|
|
|
#else /* TSCH_LOG_CONF_PER_SLOT */
|
|
|
|
#include "sys/log.h"
|
2017-10-12 11:24:14 +00:00
|
|
|
#define TSCH_LOG_PER_SLOT (LOG_CONF_LEVEL_MAC >= LOG_LEVEL_DBG)
|
2017-06-20 16:26:31 +00:00
|
|
|
#endif /* TSCH_LOG_CONF_PER_SLOT */
|
|
|
|
|
2015-09-21 20:01:01 +00:00
|
|
|
/* The length of the log queue, i.e. maximum number postponed log messages */
|
|
|
|
#ifdef TSCH_LOG_CONF_QUEUE_LEN
|
|
|
|
#define TSCH_LOG_QUEUE_LEN TSCH_LOG_CONF_QUEUE_LEN
|
|
|
|
#else /* TSCH_LOG_CONF_QUEUE_LEN */
|
|
|
|
#define TSCH_LOG_QUEUE_LEN 8
|
|
|
|
#endif /* TSCH_LOG_CONF_QUEUE_LEN */
|
|
|
|
|
2017-06-20 16:06:30 +00:00
|
|
|
#if (TSCH_LOG_PER_SLOT == 0)
|
2015-09-21 20:01:01 +00:00
|
|
|
|
|
|
|
#define tsch_log_init()
|
|
|
|
#define tsch_log_process_pending()
|
|
|
|
#define TSCH_LOG_ADD(log_type, init_code)
|
|
|
|
|
2017-06-20 16:06:30 +00:00
|
|
|
#else /* (TSCH_LOG_PER_SLOT == 0) */
|
2015-09-21 20:01:01 +00:00
|
|
|
|
|
|
|
/************ Types ***********/
|
|
|
|
|
2018-04-14 19:18:14 +00:00
|
|
|
/** \brief Structure for a log. Union of different types of logs */
|
2015-09-21 20:01:01 +00:00
|
|
|
struct tsch_log_t {
|
|
|
|
enum { tsch_log_tx,
|
|
|
|
tsch_log_rx,
|
|
|
|
tsch_log_message
|
|
|
|
} type;
|
2016-12-14 15:50:28 +00:00
|
|
|
struct tsch_asn_t asn;
|
2015-09-21 20:01:01 +00:00
|
|
|
struct tsch_link *link;
|
2018-03-26 18:15:45 +00:00
|
|
|
uint8_t burst_count;
|
2018-05-12 17:53:24 +00:00
|
|
|
uint8_t channel;
|
2015-09-21 20:01:01 +00:00
|
|
|
union {
|
|
|
|
char message[48];
|
|
|
|
struct {
|
|
|
|
int mac_tx_status;
|
2017-06-23 19:12:36 +00:00
|
|
|
linkaddr_t dest;
|
2015-09-21 20:01:01 +00:00
|
|
|
int drift;
|
|
|
|
uint8_t num_tx;
|
|
|
|
uint8_t datalen;
|
|
|
|
uint8_t is_data;
|
|
|
|
uint8_t sec_level;
|
|
|
|
uint8_t drift_used;
|
2017-06-23 19:12:36 +00:00
|
|
|
uint8_t seqno;
|
2015-09-21 20:01:01 +00:00
|
|
|
} tx;
|
|
|
|
struct {
|
2017-06-23 19:12:36 +00:00
|
|
|
linkaddr_t src;
|
2015-09-21 20:01:01 +00:00
|
|
|
int drift;
|
|
|
|
int estimated_drift;
|
|
|
|
uint8_t datalen;
|
|
|
|
uint8_t is_unicast;
|
|
|
|
uint8_t is_data;
|
|
|
|
uint8_t sec_level;
|
|
|
|
uint8_t drift_used;
|
2017-06-23 19:12:36 +00:00
|
|
|
uint8_t seqno;
|
2015-09-21 20:01:01 +00:00
|
|
|
} rx;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
/********** Functions *********/
|
|
|
|
|
2018-04-14 19:18:14 +00:00
|
|
|
/**
|
|
|
|
* \brief Prepare addition of a new log.
|
|
|
|
* \return A pointer to log structure if success, NULL otherwise
|
|
|
|
*/
|
2015-09-21 20:01:01 +00:00
|
|
|
struct tsch_log_t *tsch_log_prepare_add(void);
|
2018-04-14 19:18:14 +00:00
|
|
|
/**
|
|
|
|
* \brief Actually add the previously prepared log
|
|
|
|
*/
|
2015-09-21 20:01:01 +00:00
|
|
|
void tsch_log_commit(void);
|
2018-04-14 19:18:14 +00:00
|
|
|
/**
|
|
|
|
* \brief Initialize log module
|
|
|
|
*/
|
2015-09-21 20:01:01 +00:00
|
|
|
void tsch_log_init(void);
|
2018-04-14 19:18:14 +00:00
|
|
|
/**
|
|
|
|
* \brief Process pending log messages
|
|
|
|
*/
|
2015-09-21 20:01:01 +00:00
|
|
|
void tsch_log_process_pending(void);
|
2018-04-14 19:18:14 +00:00
|
|
|
/**
|
|
|
|
* \brief Stop logging module
|
|
|
|
*/
|
2017-07-06 17:43:44 +00:00
|
|
|
void tsch_log_stop(void);
|
2015-09-21 20:01:01 +00:00
|
|
|
|
|
|
|
/************ Macros **********/
|
|
|
|
|
2018-04-14 19:18:14 +00:00
|
|
|
/** \brief Use this macro to add a log to the queue (will be printed out
|
2015-09-21 20:01:01 +00:00
|
|
|
* later, after leaving interrupt context) */
|
|
|
|
#define TSCH_LOG_ADD(log_type, init_code) do { \
|
|
|
|
struct tsch_log_t *log = tsch_log_prepare_add(); \
|
|
|
|
if(log != NULL) { \
|
|
|
|
log->type = (log_type); \
|
|
|
|
init_code; \
|
|
|
|
tsch_log_commit(); \
|
|
|
|
} \
|
|
|
|
} while(0);
|
|
|
|
|
2017-06-20 16:06:30 +00:00
|
|
|
#endif /* (TSCH_LOG_PER_SLOT == 0) */
|
2015-09-21 20:01:01 +00:00
|
|
|
|
|
|
|
#endif /* __TSCH_LOG_H__ */
|
2017-09-29 20:18:48 +00:00
|
|
|
/** @} */
|