Skyward boardcore
Loading...
Searching...
No Matches
Debug.h
Go to the documentation of this file.
1/* Copyright (c) 2015-2018 Skyward Experimental Rocketry
2 * Author: Luca Erbetta
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23#pragma once
24
25#ifdef DEBUG
26#include <miosix.h>
27#include <utils/KernelTime.h>
28
29#include <cstdarg>
30#include <cstdio>
31#include <string>
32
33// linter off
34
35extern miosix::FastMutex traceMutex;
36
37#define D(x) x
38
39inline void TRACE(const char* format, ...)
40{
41 miosix::Lock<miosix::FastMutex> lock(traceMutex); // Synchronize TRACEs
42
43 va_list argptr;
44 va_start(argptr, format);
45
46 printf("%.2f> ", Boardcore::Kernel::getOldTick() / 1000.0f);
47 vprintf(format, argptr);
48
49 va_end(argptr);
50}
51
52// #define TRACE(...) printf("%.2f> ", Boardcore::Kernel::getOldTick()/1000.0f);
53// printf(__VA_ARGS__)
54
55#else
56
57#define D(x)
58#define TRACE(...) (void)0
59
60#endif // DEBUG
61
62#ifdef LOG_THREAD_STACK
63
64namespace Boardcore
65{
66
67inline void LOG_STACK(std::string threadName)
68{
69 using namespace miosix;
70 printf("[STACK %s] Abs: %d, Curr: %d, Size: %d\n", threadName.c_str(),
71 (int)MemoryProfiling::getAbsoluteFreeStack(),
72 (int)MemoryProfiling::getCurrentFreeStack(),
73 (int)MemoryProfiling::getStackSize());
74}
75
76} // namespace Boardcore
77
78#else
79
80#define LOG_STACK(...) (void)0
81
82#endif // LOG_THREAD_STACK
83
84// clang-format on
#define TRACE(...)
Definition Debug.h:58
#define LOG_STACK(...)
Definition Debug.h:80
long long getOldTick()
Get the current time in milliseconds.
Definition KernelTime.h:43
This file includes all the types the logdecoder script will decode.