|
|
1 #ifndef _LOG_H_
1 c8 y1 D u& e6 Q- j 2 #define _LOG_H_
5 \: c R! C8 i) O! d w 3
. D4 x3 w9 m* w3 D! K2 j' ~5 k* b 4 /* 0: printf; 1: UART1 */8 U3 ?' V C2 ^
5 #define OUTPUT_TO_UART1 1
6 ^$ j7 \8 I( w' q6 n+ h# Q 6 5 |! s& ?# v; L. x
7 /* Switch Log Output */6 u; s' x* A% R
8 #if OUTPUT_TO_UART1
# v9 J! H5 l* {, ^& E* e 9 /* For UART1 Initial */. f/ I, n: E! d* r
10 #include <stdlib.h>& ~! H4 e" t6 }! @
11 #include "hw_types.h" & t7 q. n9 o, g1 \
12 #include "hw_syscfg0_C6748.h"
+ k+ d6 n$ x4 Q* U: D$ f, A4 W7 I 13 #include "soc_C6748.h"
' P ]" ?6 m( {8 ?4 h1 n) {' R 14 #include "psc.h"
' s$ F$ t3 p0 g/ q: u% w# h 15 #include "gpio.h" 2 j2 ~; r) S9 ?
16 #include "uart.h"6 S/ ^& T# B3 ^" G; O0 m+ t
17 #include "uartStdio.h"
+ C/ T1 Z# Z/ c7 r0 W% T 18
; R" q* n9 u4 ]: Y s* ]' ?5 @7 o 19 #define OUTPUT UARTprintf
; K- N3 @5 K# j! P/ c 20 #else; t3 z0 r7 L. ^ P& ?
21 #include <stdio.h>: I. g: f$ i- @4 i" c3 k
22 #include <stdbool.h>
9 f6 \0 J+ o0 B, B2 t& ~0 P* \: D0 z 23
8 k( U# i9 F3 \# B, ] 24 #define OUTPUT printf9 A" L- r4 O% }8 U$ x5 G9 i0 h! y
25 #endif
, T8 d$ b& `# G& W# y6 {2 L) z 26 / Y0 ?9 y# \# B* w, N
27 /* Log init */
! r" n+ H# o2 z" s 28 #if OUTPUT_TO_UART1
& k: {; d0 {* Z3 l 29 #define LOG_INIT() do { \' K7 P. V& s2 E# G& H* E
30 PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_GPIO, \: D! |! `4 @7 g* A" ]/ c; y
31 PSC_POWERDOMAIN_ALWAYS_ON, \4 W } R v$ d9 k W5 P
32 PSC_MDCTL_NEXT_ENABLE); \
" e0 c# b( m0 A4 _6 K/ w 33 GPIOBank6Pin12PinMuxSetup(); \8 @6 u" C# F% C+ o$ U7 v
34 GPIOBank6Pin13PinMuxSetup(); \
% P, N: h* S% C. e9 _/ G 35 GPIODirModeSet(SOC_GPIO_0_REGS, 109, GPIO_DIR_OUTPUT); \4 ~0 P. a: I, q# t# n) X
36 GPIODirModeSet(SOC_GPIO_0_REGS, 110, GPIO_DIR_OUTPUT); \& f; B" O2 { E" s" g- q: G; N' v' r
37 UARTStdioInit(); \( t% h; L1 j* X. m& ^$ R5 l/ h- }
38 } while (0)
3 t! X9 Q2 ]5 l, \! W 39 #else5 m" ?! E: l# M2 w( \& M- y; L, Q
40 #define LOG_INIT() do { } while (0)
% s, ]9 J8 I2 w5 o6 C$ ? 41 #endif
3 [, t( d' U# N- q6 P 42
% q* U) X: C9 c2 Q 43 /* Log Output */
: d1 F& z/ B& ` 44 #define LOG_INFO(format, ...) \
9 ^& v& t; z4 E. v7 s8 E 45 do { \0 a. l; e) l! g' G3 h
46 OUTPUT("[%s|%s@%s,%d] " format "\n", "INFO ", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
- Q) a) m S k* l4 A: C 47 } while (0)
8 L6 O5 L- y$ z; S/ h 48
; h' _2 T- S* z* C+ S! A 49 #define LOG_ERROR(format, ...) \
3 L( L, h4 x' f' ?8 s 50 do { \+ q( v6 A9 a9 O( Y/ I
51 OUTPUT("[%s|%s@%s,%d] " format "\n", "ERROR", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
2 O0 o6 n# [5 n2 U/ _ 52 } while (0)* M4 {- p0 [% t% C2 s
53
2 i- p" F4 x% q, d C+ ?. ] 54 #define LOG_DEBUG(format, ...) \6 A* y; O9 K! d7 U6 f
55 do { \6 v8 X9 f& q4 P7 _
56 OUTPUT("[%s|%s@%s,%d] " format "\n", "DEBUG", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
% i* x: x/ [( V& t0 r% u+ E9 F 57 } while (0)5 Y; f& M/ |3 X0 L& p1 |4 m5 p
58
9 c4 B5 P8 W7 w7 W1 R U! e 59 #define LOG_WARN(format, ...) \4 L: q$ s# l/ Z: t7 Z, J
60 do { \; a( T. C) y f, X; Z4 m6 H: C
61 OUTPUT("[%s|%s@%s,%d] " format "\n", "WRAN ", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \4 U1 f+ y7 R# O7 N D
62 } while (0)
8 z' {! k3 q( h8 U( N 63
6 x# G+ W- @3 }; ~ N 64 #define LOG_TRACE(format, ...) \
8 i* G& H( S& W$ S( q8 T 65 do { \+ Z7 Q) s9 w% t6 Q
66 OUTPUT("[%s|%s@%s,%d] " format "\n", "TRACE", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
7 _3 ?2 _: y* d% {- e+ B2 v 67 } while (0)
4 l/ H, Y L @+ K2 h$ P9 K- @- X, E 68 5 W0 d- K0 U. x& }- D: V
69 #define LOG_FATAL(format, ...) \7 `$ ?6 n& U6 t$ D$ q& c) \! F
70 do { \& M9 M0 E9 n, A2 h$ P% C
71 OUTPUT("[%s|%s@%s,%d] " format "\n", "FATAL", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \/ }" ^: J4 A) f& [! N
72 exit(1); \
8 g0 T* @. i( c4 Q# _( S 73 } while (0)
& ]' O9 K# b1 b/ P [; m; @ 74 5 p% l0 Q% B$ m8 j4 ^& x6 G
75 /* Assert */$ z# J+ _# t! _+ Y, H
76 #define ASSERT(EXP) \
0 X* p2 a- d9 J2 h7 I 77 do{ \
! `% B/ W/ w; X 78 if (!(EXP)) { \' ?8 s5 U7 ~0 @5 L7 n
79 OUTPUT("[%s@%s,%d] ASSERT: " #EXP "\n", __func__, __FILE__, __LINE__ ); \
^2 M2 r$ H* \& u- f; C8 B, U 80 exit(1); \
- w( |0 G* q) m9 O' W1 f7 h 81 } \- U+ \% M5 A7 ]7 \3 r" c3 j
82 } while(0)& l- ^4 e" O0 n' \1 ^8 A
83 , W7 W. N5 u! S3 N6 U+ C! B) S
84 #endif
% T* ]. L7 p# E/ q |
|