|
|
1 #ifndef _LOG_H_
/ E/ K6 z v8 E5 M 2 #define _LOG_H_/ ~' Q& e7 c: e4 e) F
3 ) T: d' B! _1 l' g C! Y! ?
4 /* 0: printf; 1: UART1 */# B6 z! r. O' `2 b% Y& l
5 #define OUTPUT_TO_UART1 1 z- S2 B( O* x/ ^& h4 g
6
% P/ Y3 V% D% s( K. D* H 7 /* Switch Log Output */
" N5 }, |8 J* v/ c0 L# F/ U+ | 8 #if OUTPUT_TO_UART1
( U' v y+ W. I/ T3 I3 [& q* o. ^ 9 /* For UART1 Initial */3 g" q1 Y& W' ^# H% @' P: u7 n
10 #include <stdlib.h>
# }9 |; b# x# T 11 #include "hw_types.h" & ?& u- m1 B! d/ ~0 @" [. t
12 #include "hw_syscfg0_C6748.h"
! p" f7 m! o& s* O/ r' ~8 t 13 #include "soc_C6748.h"
4 ?, } ]8 M8 v3 l( O/ w* i 14 #include "psc.h" 3 x: v5 W- n. H! v; A2 p" s
15 #include "gpio.h" - K4 |# l, M7 L/ C) d$ j9 ~! M
16 #include "uart.h"
* h1 d" M+ X0 E7 L 17 #include "uartStdio.h"
" H f+ r# f% M 18 $ w# c" U, U2 n" }, K
19 #define OUTPUT UARTprintf
& e& n" n, Z; L: r/ C* J; z 20 #else: u# G8 T# {2 h! q
21 #include <stdio.h>: F9 O3 F2 o- o& Y- C
22 #include <stdbool.h>
/ M3 O( C* ?( z 23
- o9 O' J) R0 f: C 24 #define OUTPUT printf
( Y! T& {6 x5 C4 V2 W& v+ g4 E 25 #endif
; g2 c, ?% B8 }3 y 26
$ s0 \/ m- O% } 27 /* Log init */# ?- y5 F* ^( [, i! c
28 #if OUTPUT_TO_UART1
! _- Z, _! Y1 L7 J$ F* x 29 #define LOG_INIT() do { \# C4 L s, Y7 F; {
30 PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_GPIO, \
6 z. `6 w& D, f. E0 L! Z 31 PSC_POWERDOMAIN_ALWAYS_ON, \
+ ]% @( L: x$ |+ A 32 PSC_MDCTL_NEXT_ENABLE); \0 M. {5 T$ u' n6 e8 |
33 GPIOBank6Pin12PinMuxSetup(); \; r" f. n' E8 K+ g0 b& |
34 GPIOBank6Pin13PinMuxSetup(); \$ C7 u2 s( v M8 A5 A& i+ e
35 GPIODirModeSet(SOC_GPIO_0_REGS, 109, GPIO_DIR_OUTPUT); \
9 b" L; l& S! v% V4 ], ]( @6 F2 x 36 GPIODirModeSet(SOC_GPIO_0_REGS, 110, GPIO_DIR_OUTPUT); \+ Z3 s9 G9 q' f) E* U, X6 `
37 UARTStdioInit(); \
1 g, c2 e: {6 f& m# g6 |4 j! ?7 X 38 } while (0)1 ]( y' Z) W, N5 {
39 #else6 x2 I2 w% |& c8 M
40 #define LOG_INIT() do { } while (0)
5 y$ k1 K( |. X9 p 41 #endif
" J6 s+ h' ]$ _1 J 42
: Z, ^, F% f" z* z ~ 43 /* Log Output */4 p' G- {8 Y/ q& n
44 #define LOG_INFO(format, ...) \
" {" n i3 T8 B& B0 P 45 do { \+ ?# Y& ~3 ^9 n# v5 h* l* s
46 OUTPUT("[%s|%s@%s,%d] " format "\n", "INFO ", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \: n# W, f$ t( b! S t$ b$ G
47 } while (0)
F; ^8 e) f1 s! ^ 48
5 Z8 y) o8 ~3 \ q( `1 l, P: i 49 #define LOG_ERROR(format, ...) \4 V1 b. ^ a, W: a' N4 A& t! e* b
50 do { \. w. t5 d8 n+ U& e7 ~$ u+ b- ~% A5 P
51 OUTPUT("[%s|%s@%s,%d] " format "\n", "ERROR", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \; R& R5 e2 a& U' x* i; S! A l
52 } while (0)) e0 H% v# ~9 F+ v% u: @" U, }, d
53
+ B( S# D+ ] t4 c) C 54 #define LOG_DEBUG(format, ...) \
9 \8 G5 l: S& r; Y0 y; X 55 do { \
' `& K$ q% w# M7 h$ j 56 OUTPUT("[%s|%s@%s,%d] " format "\n", "DEBUG", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
) `& z* B8 [2 I3 k) r 57 } while (0)
8 r1 L2 ]2 S0 c# i* Q$ r 58 + {8 x1 x' |9 |2 ~+ ?
59 #define LOG_WARN(format, ...) \
- f% ]" b7 c9 M' `+ B8 q 60 do { \
0 e$ G& b6 K+ ]. E" {; J 61 OUTPUT("[%s|%s@%s,%d] " format "\n", "WRAN ", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
8 A( Z; b7 p% G8 { 62 } while (0); h4 d" v0 e- I, p0 ^$ u& ]
63 4 p4 `- v" |- i; `6 S
64 #define LOG_TRACE(format, ...) \
: d" G% s7 X( p. Q 65 do { \( @# u( J3 o7 B- @$ w+ g: u
66 OUTPUT("[%s|%s@%s,%d] " format "\n", "TRACE", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
- b6 ]5 O% S% F; P6 s2 j( E 67 } while (0)7 L( d9 P! x2 Q+ y
68
$ p2 C5 z/ B% f! v: W( E 69 #define LOG_FATAL(format, ...) \
* h2 x3 p* H4 S+ F 70 do { \
9 `+ A R+ |9 q) ]% O; _+ U" X% @3 { 71 OUTPUT("[%s|%s@%s,%d] " format "\n", "FATAL", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \' U# s( r+ l2 b
72 exit(1); \
( ]2 m5 N2 q* p+ z- P 73 } while (0)
) e9 K8 {- C9 h1 f T 74 4 h. O3 B& w& `5 P5 C* z4 F7 n; `
75 /* Assert */
' m* s3 Y. @" w* l: y 76 #define ASSERT(EXP) \$ N: U5 b3 ~7 K9 f( w1 w) \/ ]
77 do{ \
5 U q, C' ?! V1 h. F8 Q0 j" H 78 if (!(EXP)) { \
O$ h( u- ]2 p. p, H$ m 79 OUTPUT("[%s@%s,%d] ASSERT: " #EXP "\n", __func__, __FILE__, __LINE__ ); \/ n# X! ~ }/ ?- p& K5 \# b
80 exit(1); \. O* X$ C& o! t) j4 g
81 } \
- |6 R6 F9 \; `* B: ~4 w' i 82 } while(0)
2 x8 Z' d5 K' J; F 83 3 B) T5 ~- Z, _* ~7 M
84 #endif
" p# d* S6 n9 H* t' G/ h2 g |
|