|
|
1 #ifndef _LOG_H_
6 @3 y9 |+ L# Z" n% S: E4 ]9 o 2 #define _LOG_H_" B7 n' M. f# \# B/ e7 u+ R
3
o+ v E- {8 r k 4 /* 0: printf; 1: UART1 */
) F% z7 K$ z. S. n+ v: Q6 Z- X+ h 5 #define OUTPUT_TO_UART1 1: u3 u, A- ?8 U8 V8 q3 I
6 3 v( B' Q" U+ X; `
7 /* Switch Log Output */
) L, G a. u! Y& W 8 #if OUTPUT_TO_UART1
4 E: }5 I% ]' [8 Q& ]$ b* G 9 /* For UART1 Initial */
4 b# l% T! S; {; r- W 10 #include <stdlib.h>
3 l7 {+ M1 q5 @: Q 11 #include "hw_types.h" 6 h( P, K, T$ v/ I7 [# g& V; R
12 #include "hw_syscfg0_C6748.h"
! q( l( [3 y% a! x+ d1 Z9 z0 @( b1 G 13 #include "soc_C6748.h"
* P+ D+ b! x \5 h$ j 14 #include "psc.h"
7 W L# v0 f$ Y# i J2 P- i2 H 15 #include "gpio.h"
/ I3 O6 r- c# G% _- t 16 #include "uart.h"" ]4 `4 o( O4 }( r9 D
17 #include "uartStdio.h"
[* |( p7 W( V( G 18 & ^6 |1 \5 a" q# s# m: S2 `/ i
19 #define OUTPUT UARTprintf3 J1 V! T( R3 J
20 #else
- R0 I5 Z' Z) i8 L 21 #include <stdio.h>
# S( l8 ^' n7 a! F 22 #include <stdbool.h>
5 W9 V B2 K( e' R 23 + z8 n- T8 A8 D u# h! S
24 #define OUTPUT printf
* _; o N) {$ A" N% d 25 #endif
{6 a* o4 A, s: _' N: D 26 $ Z# d' [% h" m1 G
27 /* Log init */
9 l3 n3 \7 @! O" K 28 #if OUTPUT_TO_UART1
: |9 V3 u p0 v7 F# B 29 #define LOG_INIT() do { \) R, y$ v% x, P1 i ^& I6 }
30 PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_GPIO, \+ a/ [; h) \4 N6 p1 q# }( r) S5 u# z+ ]
31 PSC_POWERDOMAIN_ALWAYS_ON, \- ]% E0 q# L) B( ^9 R; l
32 PSC_MDCTL_NEXT_ENABLE); \! b$ b: ?! l0 E o& ]; c
33 GPIOBank6Pin12PinMuxSetup(); \8 _ G3 c8 p" U
34 GPIOBank6Pin13PinMuxSetup(); \4 O5 h2 h8 u3 @8 p) ?
35 GPIODirModeSet(SOC_GPIO_0_REGS, 109, GPIO_DIR_OUTPUT); \
5 F2 p4 |1 y" t$ T# M" B8 L 36 GPIODirModeSet(SOC_GPIO_0_REGS, 110, GPIO_DIR_OUTPUT); \
, i' i0 j! Y5 A% f: X; S) T 37 UARTStdioInit(); \
$ E4 j6 `! w8 H5 d0 t 38 } while (0)
1 E+ z. V. [8 z- A5 l 39 #else
" V% T2 r1 X4 o/ J! C 40 #define LOG_INIT() do { } while (0); B8 I+ W( z! B$ p
41 #endif+ O! x+ @ H4 A; V% c+ q0 a7 T
42 - P6 f4 \ P* o9 [* m; V! K
43 /* Log Output */( l- l6 ^) A; E6 ^
44 #define LOG_INFO(format, ...) \
5 B/ B( F5 `: k& u+ Q1 T' h2 O% C 45 do { \
- A% f- L, B+ E# h6 ~9 X& i 46 OUTPUT("[%s|%s@%s,%d] " format "\n", "INFO ", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \; r" m3 ^7 ^9 E, P% B3 Y T
47 } while (0)
( N1 p. b! I: `$ J5 q: H 48
- N. o) S; V& c8 c2 H2 {, M: t8 v 49 #define LOG_ERROR(format, ...) \' R' k" w. h. M; d0 Q4 A5 R5 _* x
50 do { \# f: t5 ?5 N7 S' b5 G A+ s6 i/ B
51 OUTPUT("[%s|%s@%s,%d] " format "\n", "ERROR", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
6 R ]- V7 Z9 u2 E% ? 52 } while (0)9 g$ t0 ^( r7 |% x! A* L
53
- q2 G- f( I8 Q 54 #define LOG_DEBUG(format, ...) \8 D0 }# }7 X" D- C+ I
55 do { \. J$ N$ E" z7 P5 G4 J
56 OUTPUT("[%s|%s@%s,%d] " format "\n", "DEBUG", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \- M' t# s8 C& x; E/ H
57 } while (0)6 x( D) [3 z2 _, Q
58 + S0 m( b* Q8 g7 T5 g
59 #define LOG_WARN(format, ...) \
* ^& V# L' k) O) b; b$ X5 C. B 60 do { \% r$ P P: K. j: h$ y y: M
61 OUTPUT("[%s|%s@%s,%d] " format "\n", "WRAN ", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
- Q) N% k( _0 q; X, k+ e 62 } while (0)/ R& v/ d$ c$ x8 y
63 ! H8 p" X8 @% @& C
64 #define LOG_TRACE(format, ...) \) W& E& P6 k) r: p3 Q
65 do { \$ {3 b9 c+ j* E
66 OUTPUT("[%s|%s@%s,%d] " format "\n", "TRACE", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \ m( ~( x( M5 b4 I$ ~6 a$ p( q
67 } while (0)
* R4 _$ A% Q+ m 68
. `4 }# F( ?' { 69 #define LOG_FATAL(format, ...) \0 I; Z. K2 H+ X4 \$ g, X
70 do { \9 K6 ^& l. N2 y3 S) ?8 B
71 OUTPUT("[%s|%s@%s,%d] " format "\n", "FATAL", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \$ h/ Y- j! X- V8 N* l( ]! C' v5 M/ z; U
72 exit(1); \
8 d/ e& U0 H& C l 73 } while (0). ~9 p$ n( a5 l3 k: X) C
74 % R% q w" I+ V
75 /* Assert */
4 _# }: ~& B0 X 76 #define ASSERT(EXP) \; o1 ~2 @6 o5 Y. a6 R4 B- w6 b% b
77 do{ \
6 f/ o$ L* m) Z) v, F9 A, } 78 if (!(EXP)) { \
' Y; ?/ Q9 j& f- ]5 k' | 79 OUTPUT("[%s@%s,%d] ASSERT: " #EXP "\n", __func__, __FILE__, __LINE__ ); \
# _5 L0 I5 V+ Y" R3 q" O/ T 80 exit(1); \( k# f0 D. s. f0 M7 R
81 } \" e; E! @ f) n
82 } while(0)5 D& _5 a n0 H9 O0 K' U
83
" T$ V F3 u- X/ s" l8 i/ R+ {( J# P' o 84 #endif6 X U6 }( h7 V r3 q; B4 C' }
|
|