|
1 #ifndef _LOG_H_1 h& B, \) Z! L
2 #define _LOG_H_% C& q! P8 E. O3 Y* g: I( q
3
( R0 n0 z. q$ `, q! \ 4 /* 0: printf; 1: UART1 */
$ U1 q0 n1 }9 q" o' p. s 5 #define OUTPUT_TO_UART1 1" G6 j" t) {' `- _& N* s
6 ~$ L: g3 j0 g6 I
7 /* Switch Log Output */
8 f. a2 q0 l1 l 8 #if OUTPUT_TO_UART1, m, p0 M. J+ U# r- `
9 /* For UART1 Initial */6 |+ f: U1 p i
10 #include <stdlib.h>
# Z N; K8 X* g: T0 X 11 #include "hw_types.h"
s8 x! a" w% |6 g2 Y5 t 12 #include "hw_syscfg0_C6748.h"
" ], C. [% {% E& ?; z/ o' @+ B 13 #include "soc_C6748.h"0 g+ B9 V' V) _* k0 C: e
14 #include "psc.h" 3 @6 k: K- Z6 a0 t
15 #include "gpio.h"
( E: {2 E3 L) z 16 #include "uart.h"0 H' a, t8 R+ y" O" x! l. `3 ?+ C2 V
17 #include "uartStdio.h"
- X% b# d; q: T( O' a: ^3 q+ x 18 9 L& I+ d @7 h* n
19 #define OUTPUT UARTprintf2 ~. m# S$ W3 E5 p) ~. B1 V- l
20 #else
6 N* _: L7 p2 a% R 21 #include <stdio.h>* R4 W$ l. c) S4 h3 {- z
22 #include <stdbool.h>
$ a9 Y- K1 t: B4 i6 V6 {/ j 23 ' X4 `4 w( a# r6 s1 d9 z6 ~
24 #define OUTPUT printf
7 C8 q6 x( [, i$ e. K 25 #endif
' j3 @8 V. Q3 G: ^0 y- c 26
8 w5 v7 I1 [ c X) G8 B 27 /* Log init */- Z: [* `# T2 L& D( _
28 #if OUTPUT_TO_UART1
% ?* l3 z6 V+ I# x& r/ l: ` 29 #define LOG_INIT() do { \
3 m2 f0 Z, `5 y- m1 N 30 PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_GPIO, \% R( v0 a- l+ K6 C& i2 @8 \9 v
31 PSC_POWERDOMAIN_ALWAYS_ON, \
4 y3 ?/ |- I0 E% X. _: h 32 PSC_MDCTL_NEXT_ENABLE); \- h) x3 a- J9 G' S, c+ t
33 GPIOBank6Pin12PinMuxSetup(); \
/ C7 n$ M/ K, K+ Z$ v7 F* _ 34 GPIOBank6Pin13PinMuxSetup(); \, C/ A9 F$ ]5 X$ d* C: `8 F
35 GPIODirModeSet(SOC_GPIO_0_REGS, 109, GPIO_DIR_OUTPUT); \
4 U: l2 ^" G' U9 q2 g4 l 36 GPIODirModeSet(SOC_GPIO_0_REGS, 110, GPIO_DIR_OUTPUT); \
( W7 H: {# g- `# j ~! S5 ~ 37 UARTStdioInit(); \8 u5 S( W% F1 S0 K& n9 J3 J4 e& f8 v/ ]( n
38 } while (0)
" K- F# l/ U5 ^4 U9 G; x/ @ 39 #else
! m4 m7 `0 k# I+ J9 p 40 #define LOG_INIT() do { } while (0)+ _2 ~% ~, o5 v& A( t2 q8 x: w% s% c' p
41 #endif# n* s3 m {' x+ n
42
' k& S) p) X4 c' p) }3 j 43 /* Log Output */
0 @5 S C# d- c 44 #define LOG_INFO(format, ...) \
/ G) W3 }' E0 O) }$ Y0 H; X) k 45 do { \
, G2 Z! V! h2 u 46 OUTPUT("[%s|%s@%s,%d] " format "\n", "INFO ", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \6 r2 x* P. H" P6 \" W/ [; m
47 } while (0)5 ^( I$ v. m6 r1 M: t6 Q$ ?" J2 W
48 6 w5 `" J, I0 [& y0 n
49 #define LOG_ERROR(format, ...) \
3 b9 O1 U8 O3 H' k+ w; q( ~5 S 50 do { \
( J: k% s1 @8 [2 \3 Q, V 51 OUTPUT("[%s|%s@%s,%d] " format "\n", "ERROR", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \) |7 D2 K6 Z: I f
52 } while (0)
1 \) P z( E; B8 R6 V& t6 b 53 ' S3 Y4 P, h$ n2 d4 y
54 #define LOG_DEBUG(format, ...) \
- G( S0 w7 z; V7 V" T# v7 k- q 55 do { \
# U( I! z% I* L9 _ 56 OUTPUT("[%s|%s@%s,%d] " format "\n", "DEBUG", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
; ?" y! o: p- H 57 } while (0) D, |4 i1 S# r* c8 O v W3 Y
58
% R( L+ O0 P0 K* D1 i$ ^ J 59 #define LOG_WARN(format, ...) \
' B% ?# C$ _# g {4 q9 s8 T; S 60 do { \# M. Y# O' [2 C8 [' J6 y8 Q5 c" b( x
61 OUTPUT("[%s|%s@%s,%d] " format "\n", "WRAN ", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
. R+ U: s- b2 q8 I3 G# r 62 } while (0)8 \, @* S- p2 A) ]: M, b
63
$ t6 W! S9 x4 g) f+ }3 Y8 q1 d 64 #define LOG_TRACE(format, ...) \. S7 ~* v* s; e/ ]% P
65 do { \
9 M+ x X. j* ^" p0 O5 R" J 66 OUTPUT("[%s|%s@%s,%d] " format "\n", "TRACE", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
7 p' y& t& s% w* P. i' q- f6 s 67 } while (0)
1 U8 _$ z) f/ e& ~! W 68
# i5 |) x- @1 { 69 #define LOG_FATAL(format, ...) \0 Q4 V1 U) }' \- U
70 do { \5 j0 h$ I2 A- l$ A1 D8 y8 q
71 OUTPUT("[%s|%s@%s,%d] " format "\n", "FATAL", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \2 Q( x- @$ g6 N: u3 g8 q i
72 exit(1); \
4 _ ?2 R+ `% U1 F! ?) E S1 v 73 } while (0)
4 r6 U$ j$ X! w9 V' a' t 74
7 ~& e2 n" s" p, ]9 W% v- O 75 /* Assert */7 z) g1 N2 u5 L9 O
76 #define ASSERT(EXP) \
' }, E! o+ A# ^3 z' m/ S5 P* h 77 do{ \
3 ^- A, G! y1 T8 G: k1 x 78 if (!(EXP)) { \9 m8 _, h5 w, ?9 g! s
79 OUTPUT("[%s@%s,%d] ASSERT: " #EXP "\n", __func__, __FILE__, __LINE__ ); \
" [: X& s$ W9 o8 R A 80 exit(1); \( X- t: D+ w4 T! `; K$ K" K
81 } \7 O4 E* z: o9 ]% b* B1 w& G+ x
82 } while(0)+ J5 Z; i1 F: {& A
83 : i9 y% Y4 c: D
84 #endif
! t x! q& k( z |
|