        -:    0:Source:../../../os/rt/src/chtrace.c
        -:    0:Programs:17
        -:    1:/*
        -:    2:    ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio.
        -:    3:
        -:    4:    This file is part of ChibiOS.
        -:    5:
        -:    6:    ChibiOS is free software; you can redistribute it and/or modify
        -:    7:    it under the terms of the GNU General Public License as published by
        -:    8:    the Free Software Foundation; either version 3 of the License, or
        -:    9:    (at your option) any later version.
        -:   10:
        -:   11:    ChibiOS is distributed in the hope that it will be useful,
        -:   12:    but WITHOUT ANY WARRANTY; without even the implied warranty of
        -:   13:    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        -:   14:    GNU General Public License for more details.
        -:   15:
        -:   16:    You should have received a copy of the GNU General Public License
        -:   17:    along with this program.  If not, see <http://www.gnu.org/licenses/>.
        -:   18:*/
        -:   19:
        -:   20:/**
        -:   21: * @file    chtrace.c
        -:   22: * @brief   Tracer code.
        -:   23: *
        -:   24: * @addtogroup trace
        -:   25: * @details System events tracing service.
        -:   26: * @{
        -:   27: */
        -:   28:
        -:   29:#include "ch.h"
        -:   30:
        -:   31:/*===========================================================================*/
        -:   32:/* Module local definitions.                                                 */
        -:   33:/*===========================================================================*/
        -:   34:
        -:   35:/*===========================================================================*/
        -:   36:/* Module exported variables.                                                */
        -:   37:/*===========================================================================*/
        -:   38:
        -:   39:/*===========================================================================*/
        -:   40:/* Module local types.                                                       */
        -:   41:/*===========================================================================*/
        -:   42:
        -:   43:/*===========================================================================*/
        -:   44:/* Module local variables.                                                   */
        -:   45:/*===========================================================================*/
        -:   46:
        -:   47:/*===========================================================================*/
        -:   48:/* Module local functions.                                                   */
        -:   49:/*===========================================================================*/
        -:   50:
        -:   51:#if (CH_DBG_TRACE_MASK != CH_DBG_TRACE_MASK_DISABLED) || defined(__DOXYGEN__)
        -:   52:/**
        -:   53: * @brief   Writes a time stamp and increases the trace buffer pointer.
        -:   54: *
        -:   55: * @notapi
        -:   56: */
function trace_next called 0 returned 0% blocks executed 0%
    #####:   57:static NOINLINE void trace_next(void) {
        -:   58:
    #####:   59:  ch.dbg.trace_buffer.ptr->time    = chVTGetSystemTimeX();
call    0 never executed
        -:   60:#if PORT_SUPPORTS_RT == TRUE
    #####:   61:  ch.dbg.trace_buffer.ptr->rtstamp = chSysGetRealtimeCounterX();
call    0 never executed
        -:   62:#else
        -:   63:  ch.dbg.trace_buffer.ptr->rtstamp = (rtcnt_t)0;
        -:   64:#endif
        -:   65:
        -:   66:  /* Trace hook, useful in order to interface debug tools.*/
        -:   67:  CH_CFG_TRACE_HOOK(ch.dbg.trace_buffer.ptr);
        -:   68:
    #####:   69:  if (++ch.dbg.trace_buffer.ptr >=
branch  0 never executed
branch  1 never executed
        -:   70:      &ch.dbg.trace_buffer.buffer[CH_DBG_TRACE_BUFFER_SIZE]) {
    #####:   71:    ch.dbg.trace_buffer.ptr = &ch.dbg.trace_buffer.buffer[0];
unconditional  0 never executed
        -:   72:  }
    #####:   73:}
        -:   74:#endif
        -:   75:
        -:   76:/*===========================================================================*/
        -:   77:/* Module exported functions.                                                */
        -:   78:/*===========================================================================*/
        -:   79:
        -:   80:#if (CH_DBG_TRACE_MASK != CH_DBG_TRACE_MASK_DISABLED) || defined(__DOXYGEN__)
        -:   81:/**
        -:   82: * @brief   Trace circular buffer subsystem initialization.
        -:   83: * @note    Internal use only.
        -:   84: */
function _trace_init called 1 returned 100% blocks executed 100%
        1:   85:void _trace_init(void) {
        -:   86:  unsigned i;
        -:   87:
        1:   88:  ch.dbg.trace_buffer.suspended = (uint16_t)CH_DBG_TRACE_MASK;
        1:   89:  ch.dbg.trace_buffer.size      = CH_DBG_TRACE_BUFFER_SIZE;
        1:   90:  ch.dbg.trace_buffer.ptr       = &ch.dbg.trace_buffer.buffer[0];
      129:   91:  for (i = 0U; i < (unsigned)CH_DBG_TRACE_BUFFER_SIZE; i++) {
unconditional  0 taken 100%
unconditional  1 taken 100%
branch  2 taken 99%
branch  3 taken 1% (fallthrough)
      128:   92:    ch.dbg.trace_buffer.buffer[i].type = CH_TRACE_TYPE_UNUSED;
        -:   93:  }
        1:   94:}
        -:   95:
        -:   96:/**
        -:   97: * @brief   Inserts in the circular debug trace buffer a context switch record.
        -:   98: *
        -:   99: * @param[in] ntp       the thread being switched in
        -:  100: * @param[in] otp       the thread being switched out
        -:  101: *
        -:  102: * @notapi
        -:  103: */
function _trace_switch called 149456786 returned 100% blocks executed 67%
149456786:  104:void _trace_switch(thread_t *ntp, thread_t *otp) {
        -:  105:
        -:  106:  (void)ntp;
        -:  107:
149456786:  108:  if ((ch.dbg.trace_buffer.suspended & CH_DBG_TRACE_MASK_SWITCH) == 0U) {
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
    #####:  109:    ch.dbg.trace_buffer.ptr->type        = CH_TRACE_TYPE_SWITCH;
    #####:  110:    ch.dbg.trace_buffer.ptr->state       = (uint8_t)otp->state;
    #####:  111:    ch.dbg.trace_buffer.ptr->u.sw.ntp    = currp;
    #####:  112:    ch.dbg.trace_buffer.ptr->u.sw.wtobjp = otp->u.wtobjp;
    #####:  113:    trace_next();
call    0 never executed
unconditional  1 never executed
        -:  114:  }
149456786:  115:}
        -:  116:
        -:  117:/**
        -:  118: * @brief   Inserts in the circular debug trace buffer an ISR-enter record.
        -:  119: *
        -:  120: * @param[in] isr       name of the isr
        -:  121: *
        -:  122: * @notapi
        -:  123: */
function _trace_isr_enter called 14592 returned 100% blocks executed 40%
    14592:  124:void _trace_isr_enter(const char *isr) {
        -:  125:
    14592:  126:  if ((ch.dbg.trace_buffer.suspended & CH_DBG_TRACE_MASK_ISR) == 0U) {
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
    #####:  127:    port_lock_from_isr();
call    0 never executed
    #####:  128:    ch.dbg.trace_buffer.ptr->type        = CH_TRACE_TYPE_ISR_ENTER;
    #####:  129:    ch.dbg.trace_buffer.ptr->state       = 0U;
    #####:  130:    ch.dbg.trace_buffer.ptr->u.isr.name  = isr;
    #####:  131:    trace_next();
call    0 never executed
    #####:  132:    port_unlock_from_isr();
call    0 never executed
unconditional  1 never executed
        -:  133:  }
    14592:  134:}
        -:  135:
        -:  136:/**
        -:  137: * @brief   Inserts in the circular debug trace buffer an ISR-leave record.
        -:  138: *
        -:  139: * @param[in] isr       name of the isr
        -:  140: *
        -:  141: * @notapi
        -:  142: */
function _trace_isr_leave called 14592 returned 100% blocks executed 40%
    14592:  143:void _trace_isr_leave(const char *isr) {
        -:  144:
    14592:  145:  if ((ch.dbg.trace_buffer.suspended & CH_DBG_TRACE_MASK_ISR) == 0U) {
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
    #####:  146:    port_lock_from_isr();
call    0 never executed
    #####:  147:    ch.dbg.trace_buffer.ptr->type        = CH_TRACE_TYPE_ISR_LEAVE;
    #####:  148:    ch.dbg.trace_buffer.ptr->state       = 0U;
    #####:  149:    ch.dbg.trace_buffer.ptr->u.isr.name  = isr;
    #####:  150:    trace_next();
call    0 never executed
    #####:  151:    port_unlock_from_isr();
call    0 never executed
unconditional  1 never executed
        -:  152:  }
    14592:  153:}
        -:  154:
        -:  155:/**
        -:  156: * @brief   Inserts in the circular debug trace buffer an halt record.
        -:  157: *
        -:  158: * @param[in] reason    the halt error string
        -:  159: *
        -:  160: * @notapi
        -:  161: */
function _trace_halt called 0 returned 0% blocks executed 0%
    #####:  162:void _trace_halt(const char *reason) {
        -:  163:
    #####:  164:  if ((ch.dbg.trace_buffer.suspended & CH_DBG_TRACE_MASK_HALT) == 0U) {
branch  0 never executed
branch  1 never executed
    #####:  165:    ch.dbg.trace_buffer.ptr->type          = CH_TRACE_TYPE_HALT;
    #####:  166:    ch.dbg.trace_buffer.ptr->state         = 0;
    #####:  167:    ch.dbg.trace_buffer.ptr->u.halt.reason = reason;
    #####:  168:    trace_next();
call    0 never executed
unconditional  1 never executed
        -:  169:  }
    #####:  170:}
        -:  171:
        -:  172:/**
        -:  173: * @brief   Adds an user trace record to the trace buffer.
        -:  174: *
        -:  175: * @param[in] up1       user parameter 1
        -:  176: * @param[in] up2       user parameter 2
        -:  177: *
        -:  178: * @iclass
        -:  179: */
function chDbgWriteTraceI called 0 returned 0% blocks executed 0%
    #####:  180:void chDbgWriteTraceI(void *up1, void *up2) {
        -:  181:
        -:  182:  chDbgCheckClassI();
        -:  183:
    #####:  184:  if ((ch.dbg.trace_buffer.suspended & CH_DBG_TRACE_MASK_USER) == 0U) {
branch  0 never executed
branch  1 never executed
    #####:  185:    ch.dbg.trace_buffer.ptr->type       = CH_TRACE_TYPE_USER;
    #####:  186:    ch.dbg.trace_buffer.ptr->state      = 0;
    #####:  187:    ch.dbg.trace_buffer.ptr->u.user.up1 = up1;
    #####:  188:    ch.dbg.trace_buffer.ptr->u.user.up2 = up2;
    #####:  189:    trace_next();
call    0 never executed
unconditional  1 never executed
        -:  190:  }
    #####:  191:}
        -:  192:
        -:  193:/**
        -:  194: * @brief   Adds an user trace record to the trace buffer.
        -:  195: *
        -:  196: * @param[in] up1       user parameter 1
        -:  197: * @param[in] up2       user parameter 2
        -:  198: *
        -:  199: * @api
        -:  200: */
function chDbgWriteTrace called 0 returned 0% blocks executed 0%
    #####:  201:void chDbgWriteTrace(void *up1, void *up2) {
        -:  202:
    #####:  203:  chSysLock();
call    0 never executed
    #####:  204:  chDbgWriteTraceI(up1, up2);
call    0 never executed
    #####:  205:  chSysUnlock();
call    0 never executed
    #####:  206:}
        -:  207:
        -:  208:/**
        -:  209: * @brief   Suspends one or more trace events.
        -:  210: *
        -:  211: * @paramin mask        mask of the trace events to be suspended
        -:  212: *
        -:  213: * @iclass
        -:  214: */
function chDbgSuspendTraceI called 0 returned 0% blocks executed 0%
    #####:  215:void chDbgSuspendTraceI(uint16_t mask) {
        -:  216:
        -:  217:  chDbgCheckClassI();
        -:  218:
    #####:  219:  ch.dbg.trace_buffer.suspended |= mask;
    #####:  220:}
        -:  221:
        -:  222:/**
        -:  223: * @brief   Suspends one or more trace events.
        -:  224: *
        -:  225: * @paramin mask        mask of the trace events to be suspended
        -:  226: *
        -:  227: * @api
        -:  228: */
function chDbgSuspendTrace called 0 returned 0% blocks executed 0%
    #####:  229:void chDbgSuspendTrace(uint16_t mask) {
        -:  230:
    #####:  231:  chSysLock();
call    0 never executed
    #####:  232:  chDbgSuspendTraceI(mask);
call    0 never executed
    #####:  233:  chSysUnlock();
call    0 never executed
    #####:  234:}
        -:  235:
        -:  236:/**
        -:  237: * @brief   Resumes one or more trace events.
        -:  238: *
        -:  239: * @paramin mask        mask of the trace events to be resumed
        -:  240: *
        -:  241: * @iclass
        -:  242: */
function chDbgResumeTraceI called 0 returned 0% blocks executed 0%
    #####:  243:void chDbgResumeTraceI(uint16_t mask) {
        -:  244:
        -:  245:  chDbgCheckClassI();
        -:  246:
    #####:  247:  ch.dbg.trace_buffer.suspended &= ~mask;
    #####:  248:}
        -:  249:
        -:  250:/**
        -:  251: * @brief   Resumes one or more trace events.
        -:  252: *
        -:  253: * @paramin mask        mask of the trace events to be resumed
        -:  254: *
        -:  255: * @api
        -:  256: */
function chDbgResumeTrace called 0 returned 0% blocks executed 0%
    #####:  257:void chDbgResumeTrace(uint16_t mask) {
        -:  258:
    #####:  259:  chSysLock();
call    0 never executed
    #####:  260:  chDbgResumeTraceI(mask);
call    0 never executed
    #####:  261:  chSysUnlock();
call    0 never executed
    #####:  262:}
        -:  263:#endif /* CH_DBG_TRACE_MASK != CH_DBG_TRACE_MASK_DISABLED */
        -:  264:
        -:  265:/** @} */
