OpenSSD Cosmos+ Platform Firmware  0.0.2
The firmware of Cosmos+ OpenSSD Platform for TOSHIBA nand flash module.
debug.h
Go to the documentation of this file.
1
2// debug.h for Cosmos+ OpenSSD
3// Copyright (c) 2016 Hanyang University ENC Lab.
4// Contributed by Yong Ho Song <yhsong@enc.hanyang.ac.kr>
5// Youngjin Jo <yjjo@enc.hanyang.ac.kr>
6// Sangjin Lee <sjlee@enc.hanyang.ac.kr>
7//
8// This file is part of Cosmos+ OpenSSD.
9//
10// Cosmos+ OpenSSD is free software; you can redistribute it and/or modify
11// it under the terms of the GNU General Public License as published by
12// the Free Software Foundation; either version 3, or (at your option)
13// any later version.
14//
15// Cosmos+ OpenSSD is distributed in the hope that it will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18// See the GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Cosmos+ OpenSSD; see the file COPYING.
22// If not, see <http://www.gnu.org/licenses/>.
24
26// Company: ENC Lab. <http://enc.hanyang.ac.kr>
27// Engineer: Sangjin Lee <sjlee@enc.hanyang.ac.kr>
28//
29// Project Name: Cosmos+ OpenSSD
30// Design Name: Cosmos+ Firmware
31// Module Name: Debug Mate
32// File Name: debug.h
33//
34// Version: v1.0.0
35//
36// Description:
37// - defines macros for easy debugging
39
41// Revision History:
42//
43// * v1.0.0
44// - First draft
46
47#ifndef __DEBUG_H_
48#define __DEBUG_H_
49
50#include "stdint.h"
51#include "xil_printf.h"
52
53/* -------------------------------------------------------------------------- */
54/* ANSI escape code */
55/* -------------------------------------------------------------------------- */
56
57#define PR_RESET "\e[0m"
58#define PR_DEBUG "\e[32;49;1mDEBUG "
59#define PR_INFO "\e[34;49;1mINFO "
60#define PR_WARN "\e[33;49;1mWARN "
61#define PR_ERROR "\e[31;49;1mERROR "
62
63/* -------------------------------------------------------------------------- */
64/* logging macros */
65/* -------------------------------------------------------------------------- */
66
67#define CODE_POS_FMT "(%s() at %s:%d):: "
68#define CODE_POS_ARGS __func__, __FILE__, __LINE__
69#define SPLIT_LINE "-----------------------------------------------------------------------------\n"
70
71#ifdef HOST_DEBUG
72#include <stdio.h>
73#define xil_printf printf
74#else
75#define printf xil_printf
76#endif
77
78#define pr_raw xil_printf
79#define pr(fmt, ...) pr_raw(fmt "\r\n", ##__VA_ARGS__)
80
81#ifdef DEBUG
82#define pr_debug(fmt, ...) pr(PR_DEBUG CODE_POS_FMT PR_RESET fmt, CODE_POS_ARGS, ##__VA_ARGS__)
83#else
84#define pr_debug(fmt, ...)
85#endif
86#define pr_info(fmt, ...) pr(PR_INFO PR_RESET fmt, ##__VA_ARGS__)
87#define pr_warn(fmt, ...) pr(PR_WARN CODE_POS_FMT PR_RESET fmt, CODE_POS_ARGS, ##__VA_ARGS__)
88#define pr_error(fmt, ...) pr(PR_ERROR CODE_POS_FMT PR_RESET fmt, CODE_POS_ARGS, ##__VA_ARGS__)
89
90/* -------------------------------------------------------------------------- */
91/* debugging macros */
92/* -------------------------------------------------------------------------- */
93
94#define MEMBER_SIZE(type, mem) (sizeof((((type *)0)->mem)))
95
96#define ASSERT(cond, ...) \
97 ({ \
98 if (!(cond)) \
99 { \
100 pr_error("assert failed: " __VA_ARGS__); \
101 while (1) \
102 ; \
103 } \
104 })
105
106// raise compiler error when (cond == 0), must place in a function
107#define STATIC_ASSERT(cond) ((int)(sizeof(struct { int : (-!(cond)); })))
108
109#endif