|
|
1 #ifndef _LOG_H_
7 t! h% a( \! ]) ^ 2 #define _LOG_H_& s' C Y/ n! b4 `2 \
3
0 w$ p2 g7 q5 w* M 4 /* 0: printf; 1: UART1 */" L5 ?7 C( D# N% Z% i/ U6 u
5 #define OUTPUT_TO_UART1 12 _) w0 N9 s) X3 U; W/ N y
6
0 o: T0 O- [$ v& \9 \ 7 /* Switch Log Output */
4 k" u) } A ?" ^ 8 #if OUTPUT_TO_UART1
1 e8 I T6 b# [: f( m 9 /* For UART1 Initial */
, v: z- J# E+ { 10 #include <stdlib.h>, m4 T% r+ Y, a7 W2 Z8 J
11 #include "hw_types.h" # ]4 w/ c& g) {
12 #include "hw_syscfg0_C6748.h"- x1 X4 ^& q# ?. j
13 #include "soc_C6748.h"
, G8 q2 I) c" K0 W3 f. ] 14 #include "psc.h" 0 N J1 x# q; k7 {" x) B4 Q0 r; V7 w
15 #include "gpio.h" 3 P8 y, v; {, K0 W
16 #include "uart.h"
8 |9 T9 y# `5 i! X" e! B3 N7 M 17 #include "uartStdio.h"8 E. z/ B* P+ N$ ~+ X( V \
18 7 Z! O7 U# f. a# E
19 #define OUTPUT UARTprintf
8 A/ y) B# w: p% V5 K 20 #else- z! {* @3 s( s9 z0 ^& [
21 #include <stdio.h>
: G/ d! l* `; U: E; l& e, M 22 #include <stdbool.h>& l9 S& @1 @2 P# n2 _8 ^4 G
23 0 i9 L7 ~; B6 u7 N: ~
24 #define OUTPUT printf
5 B( b8 L" _7 ^) R! [ 25 #endif
h5 p# y7 ~+ R. A 26
q! V/ V+ r8 @- P+ R 27 /* Log init */. X* U3 S$ I9 M: e; p* \8 Q
28 #if OUTPUT_TO_UART1& N; n# i6 _2 D5 r `' x9 [
29 #define LOG_INIT() do { \; B8 B5 Q: }) F& W7 [4 Z7 ?0 v1 {
30 PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_GPIO, \) w5 u: I1 X. R# k. e) c( K9 ]4 L
31 PSC_POWERDOMAIN_ALWAYS_ON, \& o, a# p/ f# ]: {1 ?& F7 d8 z
32 PSC_MDCTL_NEXT_ENABLE); \) T) d; O" H, T5 [- U% l
33 GPIOBank6Pin12PinMuxSetup(); \
9 E% J; b- ^1 w 34 GPIOBank6Pin13PinMuxSetup(); \
$ w4 C# k% d$ a, [6 }4 z" L g 35 GPIODirModeSet(SOC_GPIO_0_REGS, 109, GPIO_DIR_OUTPUT); \( `+ I" ]. R7 L
36 GPIODirModeSet(SOC_GPIO_0_REGS, 110, GPIO_DIR_OUTPUT); \
$ o$ ]/ X7 O. [. `) Z4 ]; ~ 37 UARTStdioInit(); \. A8 Z8 y( N& t
38 } while (0)+ n, ]6 u" J, G# ~9 @
39 #else
0 r2 `* t2 t) T; p: ^% @ 40 #define LOG_INIT() do { } while (0)
. E* B3 G5 w' f4 M7 g4 }8 s0 ~ 41 #endif
. U' y/ c8 P+ E/ Z 42 % G$ m# v6 S P0 P2 m
43 /* Log Output */
6 q7 c; @6 c4 B7 j- `$ t: o 44 #define LOG_INFO(format, ...) \. f5 u \6 e) `1 C7 n) t; B& B F$ v
45 do { \: V4 z* t5 P6 w2 O; b% P
46 OUTPUT("[%s|%s@%s,%d] " format "\n", "INFO ", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
6 L* n# V8 T) A7 T3 [; x9 E8 }6 l 47 } while (0)! `: f6 y1 _4 Y
48 ; A; t+ r: ~- f8 n3 u: N# `
49 #define LOG_ERROR(format, ...) \: Q: o3 ^5 ?# m" @% H6 t
50 do { \
- W9 Q6 q0 \. Q( C- | 51 OUTPUT("[%s|%s@%s,%d] " format "\n", "ERROR", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \. S, k. Q; [% q. i# M# s
52 } while (0)2 i8 R3 U5 C. g( d1 F
53
; |& X b/ O2 a; j" t# ` 54 #define LOG_DEBUG(format, ...) \; c. b0 C- E2 d5 F/ p6 D) k1 v1 X
55 do { \
) p& s1 r0 r% }8 ~! _& j 56 OUTPUT("[%s|%s@%s,%d] " format "\n", "DEBUG", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
" d' E4 R1 Y, j) @ 57 } while (0)8 B& O$ C6 Q1 H: e' t2 z
58 ! w6 J' c- a9 C$ x; R
59 #define LOG_WARN(format, ...) \# O! M. k/ w3 l$ U: D
60 do { \; w9 ]3 p& @6 ]( K
61 OUTPUT("[%s|%s@%s,%d] " format "\n", "WRAN ", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \' v; E& s0 z- \9 [, g( W! K5 Y( F) g
62 } while (0)
% @3 C/ W+ i0 S" T 63
! M! h E7 h& g) g M/ S; h3 D 64 #define LOG_TRACE(format, ...) \/ e* A% R$ R" |. O; D' t) s; ]
65 do { \
( A. {% O$ q3 B& ]( i) o 66 OUTPUT("[%s|%s@%s,%d] " format "\n", "TRACE", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
& @, p. R6 |+ c% d% \- E9 i0 V% Q' B: { 67 } while (0)5 Y) P0 `& I3 i" ?) Z
68 # V! i9 u8 a4 ^9 f/ A+ ^' f
69 #define LOG_FATAL(format, ...) \ R' h/ U! L9 ~2 E
70 do { \
% R2 v. a6 T3 e- a! b+ @$ B 71 OUTPUT("[%s|%s@%s,%d] " format "\n", "FATAL", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
) @; d! e' a. B+ }% Q 72 exit(1); \
T: R2 ~5 m0 A4 z' v 73 } while (0). f$ F h: d5 n( G8 g p7 O$ @8 h: `6 r
74
6 n; B3 t3 u( D. Z+ u" [9 k! S 75 /* Assert */2 Y/ B% P7 u, W5 E' a1 {$ |4 M
76 #define ASSERT(EXP) \- B( y# k2 h2 u% L; _9 E, M
77 do{ \
; s- h& e; B7 y+ ]0 z& i3 s- s 78 if (!(EXP)) { \
' a! I# }7 y8 `" a$ l( x8 V& E7 f 79 OUTPUT("[%s@%s,%d] ASSERT: " #EXP "\n", __func__, __FILE__, __LINE__ ); \
# x+ Q4 T( L5 |4 r/ h 80 exit(1); \
# ?" Y& C8 F8 Y 81 } \" x; I" A2 M3 D- V4 o3 N4 P
82 } while(0)3 V) q. V9 M; L- ]1 I, r0 s* X
83
6 T' j, o/ V% Q 84 #endif
+ @3 v4 W8 C9 C: k6 |: @ |
|