|
|
1 #ifndef _LOG_H_
/ S& w. F% E4 D2 u$ }5 M 2 #define _LOG_H_0 x( g' s3 J; e: D
3
+ o D: ?5 G- K& q$ a: g 4 /* 0: printf; 1: UART1 */# R6 b ~ j- n' E7 B: f# a$ \
5 #define OUTPUT_TO_UART1 1
1 z S y& _: q' w5 C: C 6
) u' B" K# d" X 7 /* Switch Log Output */
9 ]7 t7 |, v5 ~6 }8 f7 ? 8 #if OUTPUT_TO_UART1
& R; t* Z9 A0 m5 V6 F; [- c 9 /* For UART1 Initial */
5 I" ~! p% |/ u, y. C 10 #include <stdlib.h> W: R _! q0 W3 w/ ^
11 #include "hw_types.h" # `8 ~3 q3 @, k% d- {9 n
12 #include "hw_syscfg0_C6748.h"
- t9 S4 T! @+ Z( M% u) ?; F, ]/ J 13 #include "soc_C6748.h"; v d' a/ S. | e
14 #include "psc.h" $ D' x. t C; q# W& Q: f7 k0 P
15 #include "gpio.h" $ ^6 V# ^+ e/ n4 K, ~( X
16 #include "uart.h"" M- Q$ V$ c# q8 _8 I g# d
17 #include "uartStdio.h"& V& \: g$ S# W$ h- i. B+ U. K
18 ( ]- m; S3 i+ j% T a
19 #define OUTPUT UARTprintf
: G J+ f& N8 w$ k0 L 20 #else2 u/ J# [: i4 H% h3 h
21 #include <stdio.h>
, d5 G" u6 t7 d6 A3 H8 I6 c/ g 22 #include <stdbool.h>
2 u3 R# j" P! { 23
9 V1 ?2 o+ ]' J) e; m 24 #define OUTPUT printf+ f/ f+ u4 y& |
25 #endif9 } F! G6 b1 Q2 s5 P; k: j9 ?
26 . c( U. u6 f- Q4 u6 Y+ P
27 /* Log init */& r2 h& G5 ~- ?2 G# _: h' ?6 T
28 #if OUTPUT_TO_UART1
: w* ~9 X, j! h+ x% z 29 #define LOG_INIT() do { \
5 x) T. ?" P; m3 Q' f3 |) w& } 30 PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_GPIO, \
8 Q/ {/ a0 x/ p5 s H 31 PSC_POWERDOMAIN_ALWAYS_ON, \/ C+ P, n; W1 Z9 j2 o8 R; w- N
32 PSC_MDCTL_NEXT_ENABLE); \
. \* D6 d2 |; V, n, e 33 GPIOBank6Pin12PinMuxSetup(); \
9 M' K2 K& ~6 b 34 GPIOBank6Pin13PinMuxSetup(); \
, G" x* m3 T% K! v' @# y/ @ 35 GPIODirModeSet(SOC_GPIO_0_REGS, 109, GPIO_DIR_OUTPUT); \; I9 y o$ v+ q- J
36 GPIODirModeSet(SOC_GPIO_0_REGS, 110, GPIO_DIR_OUTPUT); \" n J! i2 |7 o! z# k6 u3 G
37 UARTStdioInit(); \
' [8 a/ l% M3 x& |' \0 M# I 38 } while (0)1 W, _) @4 S6 M- A0 p
39 #else9 l3 c* N+ g/ ]# }. h
40 #define LOG_INIT() do { } while (0)
- s( z$ {: H3 b3 f# u 41 #endif
; s G, q/ f. E& j8 o 42 ; v% }! {; e! G6 P3 z4 ~" H# d8 x
43 /* Log Output */
) c6 j4 Y" L) T9 Q$ U# i2 E0 l 44 #define LOG_INFO(format, ...) \$ Z3 U) h2 W# H; U; G( Y# M
45 do { \2 F4 G/ p$ A2 |8 T5 Y+ }, f
46 OUTPUT("[%s|%s@%s,%d] " format "\n", "INFO ", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \! z0 R/ N* E3 t1 a* v( ^, m( d
47 } while (0)0 ^$ j0 T6 j. a
48
# @3 } g" Q3 U* P& ]' n1 K 49 #define LOG_ERROR(format, ...) \/ W) b# K; x N
50 do { \
) F* ~( F4 Z/ D# o5 u' ] 51 OUTPUT("[%s|%s@%s,%d] " format "\n", "ERROR", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
0 D7 T; W6 y" k4 x 52 } while (0)9 M2 p( a! Q% P3 x' b. V
53
8 m$ I# x3 d+ Z% b) N2 N 54 #define LOG_DEBUG(format, ...) \
2 d# _' r5 @6 z6 K) }9 i8 U- P 55 do { \
9 [5 M A" i8 q 56 OUTPUT("[%s|%s@%s,%d] " format "\n", "DEBUG", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
% I+ @: r" A0 ` 57 } while (0)$ Q, Z! c/ s2 c* a3 Q' n' v& B
58
8 f {! P i3 ^! b$ \* {) V* ~ 59 #define LOG_WARN(format, ...) \$ w# p) ~1 s% T/ U
60 do { \
' x8 [5 [4 F9 u 61 OUTPUT("[%s|%s@%s,%d] " format "\n", "WRAN ", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
1 D9 G% c/ T0 K3 y( o( w 62 } while (0)- T" w0 ?$ @0 D. r# ~& {
63
$ q3 j% V! T# K1 X3 Y* r8 y2 X 64 #define LOG_TRACE(format, ...) \
- g x6 u r' x% J/ f; l5 B+ k 65 do { \6 L) @9 k+ R ]
66 OUTPUT("[%s|%s@%s,%d] " format "\n", "TRACE", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
& Y; z! b' P$ b, e 67 } while (0)
3 U3 y" \% C- h& a+ z" y1 t$ _- i 68 ; d% S- W& Q' Z0 u. M/ Q% }4 N' A
69 #define LOG_FATAL(format, ...) \
) R5 ^+ K0 J$ f4 H, E# b; y9 j. a 70 do { \
! e$ ~( ?+ S. x& s6 v2 Q; U 71 OUTPUT("[%s|%s@%s,%d] " format "\n", "FATAL", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
; W' V5 |% \8 @' G9 [. Z 72 exit(1); \
! T4 U- w# |/ j5 E0 X* W, ? 73 } while (0)
2 i+ `) {- c v$ }; c8 N7 C 74 0 r7 c: r" c$ e% {* `) M* K
75 /* Assert */' d A4 K7 g' l. H1 U
76 #define ASSERT(EXP) \$ r; ?2 Y* l$ ]' E7 e0 `& c5 x
77 do{ \. g- F, G7 p+ r1 ?3 w7 Q
78 if (!(EXP)) { \
7 ], {" |( v) F2 T3 Y 79 OUTPUT("[%s@%s,%d] ASSERT: " #EXP "\n", __func__, __FILE__, __LINE__ ); \
9 L. f; P' X3 [3 f+ U/ E+ K( y- a 80 exit(1); \ \. } u* i/ e/ Y! n( x/ j( g2 x
81 } \- y5 k. ~2 z3 b* M; J- {
82 } while(0)4 i: i2 m+ Q/ R0 ?
83
" D+ q) |" A. |/ q# ^0 {3 U% Y5 B 84 #endif
. X- a* h" } {5 a |
|