|
1 #ifndef _LOG_H_
7 B" q9 ?% z. _" I 2 #define _LOG_H_+ O' K! s8 W1 f' h& y9 _# s( ^' ?8 R
3 6 `* M; N1 v( d$ g6 \
4 /* 0: printf; 1: UART1 */
# {. \2 ^; A2 f# p, _1 B8 ^ 5 #define OUTPUT_TO_UART1 1
1 t* S& `/ D0 {( N8 ~ 6
% j, o) e0 J$ f) v 7 /* Switch Log Output */5 d; ]5 E( U( x3 a+ }
8 #if OUTPUT_TO_UART13 |+ J6 {" e2 @0 k' J( s& f
9 /* For UART1 Initial */
% v1 X7 X w( x! I' T4 R' {. n 10 #include <stdlib.h>
4 q2 c; w5 @) @- D6 _' { 11 #include "hw_types.h" # D* e, G8 i: P' D. \! x7 G* j
12 #include "hw_syscfg0_C6748.h"( d0 ?, ?' ?7 K* t2 }
13 #include "soc_C6748.h"
. Z6 Y$ t6 S7 l: p 14 #include "psc.h" 9 r1 H8 r. Q" J# x7 n) `
15 #include "gpio.h"
3 l2 [( t5 b# ^; R* n0 q* ~ 16 #include "uart.h") S" }! n7 d9 N$ @- i
17 #include "uartStdio.h"6 ?0 P; J( u; w' Q
18 8 \4 V% f' S' O7 I5 ]8 M
19 #define OUTPUT UARTprintf
! I: l2 l, o9 f, ^ 20 #else
+ n0 s& J0 h; d6 a4 ?( j. ~1 d8 e 21 #include <stdio.h>8 C7 k' F, f+ ]2 U
22 #include <stdbool.h>
! e( y; G) m" F0 h2 T; W% O) t 23 + V9 D6 W- E- X, D# i
24 #define OUTPUT printf
* {. T! V0 E) P' R" Z 25 #endif" K8 C! z+ r' N( c$ v; | V8 b7 U. L) D
26
$ Z7 z \0 X) F4 G6 d4 y( I |3 A! d 27 /* Log init */
0 z7 }1 r' H% `" s4 [' t7 r 28 #if OUTPUT_TO_UART1: h/ {4 p5 m) F. a( U( F
29 #define LOG_INIT() do { \
! I( a l7 q1 O0 \1 K4 O+ C 30 PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_GPIO, \$ q) X: l1 b9 D4 a V: @& P
31 PSC_POWERDOMAIN_ALWAYS_ON, \
% P: z3 u7 j. z! @% W& U K 32 PSC_MDCTL_NEXT_ENABLE); \
' ]0 Z) @: N0 ~4 T6 M) f8 w; H) v- K 33 GPIOBank6Pin12PinMuxSetup(); \
' E, c" X" L( X( `5 e3 k5 n4 _ 34 GPIOBank6Pin13PinMuxSetup(); \, E1 Q# K4 `9 r ~: ?0 N* V: a/ L' r: C
35 GPIODirModeSet(SOC_GPIO_0_REGS, 109, GPIO_DIR_OUTPUT); \
: i2 l& X! |% I, ?) h2 ]) J6 q 36 GPIODirModeSet(SOC_GPIO_0_REGS, 110, GPIO_DIR_OUTPUT); \+ T+ y& [; |) U- {
37 UARTStdioInit(); \+ i' H3 o$ f w b! ?
38 } while (0)
* J, \& e# [3 r( ?+ t 39 #else i I. d; Q% f- G# b
40 #define LOG_INIT() do { } while (0)
9 Y x# l2 N6 G4 i# C8 G2 T# M 41 #endif9 | @2 s6 T4 k' t6 T% J! H
42
) l$ m; m6 o1 W U6 h) [& g 43 /* Log Output */
2 q P$ Y$ [% c& M( b! X7 b \: K 44 #define LOG_INFO(format, ...) \* B( U- w7 X! k
45 do { \1 ]7 [* v, K# B8 Z) ]# L, _: d
46 OUTPUT("[%s|%s@%s,%d] " format "\n", "INFO ", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
- [, P; x. S5 C& t" Y( Y 47 } while (0)( }0 I- c1 \5 a
48
8 y: J; ^( j* T 49 #define LOG_ERROR(format, ...) \
2 }: n: X& i# \: @7 { 50 do { \' R& F+ s5 _7 o' B- J
51 OUTPUT("[%s|%s@%s,%d] " format "\n", "ERROR", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
+ T. z; X4 @ x6 t0 O 52 } while (0)+ @& c/ Q+ e" V9 ~( K
53
6 }9 c7 L( T8 e+ U4 E/ v6 _; C 54 #define LOG_DEBUG(format, ...) \6 A% g2 \$ b3 S a8 k k
55 do { \, R& M3 N1 P% H* s* {2 D
56 OUTPUT("[%s|%s@%s,%d] " format "\n", "DEBUG", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \" Q$ S0 G) G6 H$ U2 H. I
57 } while (0)4 z; t6 P4 d0 g, K8 Z' \
58
" E4 ^9 d1 X% H9 i 59 #define LOG_WARN(format, ...) \
& x/ }" c9 X1 W% I9 A0 p8 _ 60 do { \
$ w4 E1 _! B% S' [; { 61 OUTPUT("[%s|%s@%s,%d] " format "\n", "WRAN ", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
% \( J/ A1 ~% |) t/ ] 62 } while (0)
) L' N# D! k& k 63 5 |2 Z# E( n0 z6 u$ U5 Y
64 #define LOG_TRACE(format, ...) \0 K6 {! T0 l9 O6 M
65 do { \- Z, ^( t1 _) W3 m
66 OUTPUT("[%s|%s@%s,%d] " format "\n", "TRACE", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
0 m) x- ^- E% b 67 } while (0)
7 e& g$ E' G% Q- Y3 T% l 68 4 z# U( O5 O) {( }
69 #define LOG_FATAL(format, ...) \9 q K, S4 ?$ J3 |9 J( m
70 do { \0 P5 Y% x& D+ O' k' Z
71 OUTPUT("[%s|%s@%s,%d] " format "\n", "FATAL", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \" j6 y& Y( {4 e5 D8 w
72 exit(1); \' r, N% l# Q# G/ |9 x
73 } while (0)
; B7 w( V0 b. B$ l S 74 : U9 _% J6 M* J6 A: f2 e: l
75 /* Assert */
" ^+ n* R4 {' x. @; Z7 w+ G6 Y 76 #define ASSERT(EXP) \
; P( S6 b4 D, c3 A 77 do{ \
9 E0 T5 }& F8 ]8 B! u5 H& A; V' t 78 if (!(EXP)) { \
* n% W7 u! C9 X5 S6 m 79 OUTPUT("[%s@%s,%d] ASSERT: " #EXP "\n", __func__, __FILE__, __LINE__ ); \+ u7 K3 n2 V2 L- o0 R o: h) w, U
80 exit(1); \
. Z* U; o- A0 y3 Z5 {8 ? 81 } \
; [3 T ]; L2 d+ x- u6 X# v 82 } while(0)3 `+ u8 r. y9 |7 a
83
% n9 P1 Z# f; D, { 84 #endif
* a% q4 _$ P/ c* `; B6 b: v# d |
|