|
1 #ifndef _LOG_H_3 ~4 F1 a5 P/ j' \3 a5 j% e5 t* G
2 #define _LOG_H_
3 t0 {" v& F& `: ^ 3
( k0 z) I4 `8 a7 ^( k, u 4 /* 0: printf; 1: UART1 */$ `5 ^0 r; f2 M
5 #define OUTPUT_TO_UART1 12 t2 o; [* X8 h/ G0 M1 t7 G
6
! P& }1 c c: W: } 7 /* Switch Log Output */
" X5 L: B; J- b) T& b 8 #if OUTPUT_TO_UART17 |% H4 a! q- D5 C Y
9 /* For UART1 Initial */
q$ i/ K0 B) t9 B 10 #include <stdlib.h>
5 ]' m% Q- o$ `' L4 T8 { 11 #include "hw_types.h" ( t a+ M a# B
12 #include "hw_syscfg0_C6748.h"8 _1 j2 b/ B$ i
13 #include "soc_C6748.h"
1 c- \' R8 ] L" V* Q 14 #include "psc.h" + i$ I o$ u" W8 l% e7 N
15 #include "gpio.h" 8 l+ |. [& d( O3 R5 C! o1 d3 [* n
16 #include "uart.h"
# Z& X2 o5 ^6 @' |" L$ _* ? 17 #include "uartStdio.h"
5 p; ]* J- [# r1 O: X! ` 18
3 v. F* d# H F/ h3 G: J 19 #define OUTPUT UARTprintf
2 w' o) a# u# ]$ K F& b 20 #else% c! b$ _5 ~5 m# ?: o r+ J
21 #include <stdio.h>" R) n- g* ?2 w! X( F; a
22 #include <stdbool.h>
4 t7 {2 O9 w1 ~; A% Z4 j 23 * D$ V* L+ D, p" I1 G6 e y
24 #define OUTPUT printf
% q3 y: `' L% U! U( K 25 #endif/ X* g% Z7 ?$ ^- J
26
; `1 t2 y" f: Y5 \# S" g' l8 K& n, n 27 /* Log init */+ Q8 p4 g2 y& ^9 n9 g
28 #if OUTPUT_TO_UART1 v2 S8 b; B( z7 ~8 o" H7 P) B7 i
29 #define LOG_INIT() do { \" S0 X" S6 c" V4 N$ R' H
30 PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_GPIO, \
3 _0 C$ J) }5 z$ L# W( k 31 PSC_POWERDOMAIN_ALWAYS_ON, \
+ r0 ?( m" B* X 32 PSC_MDCTL_NEXT_ENABLE); \
' B8 _% g! P4 x6 g 33 GPIOBank6Pin12PinMuxSetup(); \
0 ?) ]/ t; r9 e, U ?5 r8 d 34 GPIOBank6Pin13PinMuxSetup(); \
$ e6 B/ V, j! M 35 GPIODirModeSet(SOC_GPIO_0_REGS, 109, GPIO_DIR_OUTPUT); \
. K! J) v9 i. w$ j/ z. r. N; G; T7 D 36 GPIODirModeSet(SOC_GPIO_0_REGS, 110, GPIO_DIR_OUTPUT); \5 E7 V9 [, {" r, D* d% n1 S. X$ j4 f
37 UARTStdioInit(); \
- O6 h9 @7 c) w. l0 n 38 } while (0)& U& @* R J4 k; [( `
39 #else
7 i$ E6 ~4 S: L7 a8 v/ b8 } 40 #define LOG_INIT() do { } while (0)
! w+ \- s' h, V$ s0 a3 |2 c9 J3 a 41 #endif& a# b; S" g. Y: ^, Q5 x: w" K+ ?
42
D, O0 ]. x9 w) t% C3 k- w 43 /* Log Output */% O6 g# M2 y1 e# A) [7 U
44 #define LOG_INFO(format, ...) \
. b! N" \ `5 V6 O' z) H 45 do { \
@* n8 P: D8 [ 46 OUTPUT("[%s|%s@%s,%d] " format "\n", "INFO ", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
& R* H' g9 @" b6 C- T; } 47 } while (0)
G. p6 A) v/ k, S! g 48 0 M# D7 N" x( O2 {9 ?
49 #define LOG_ERROR(format, ...) \( G2 M/ E3 K/ ^. Z6 _
50 do { \& P/ j; I; N! g$ ]! y$ R
51 OUTPUT("[%s|%s@%s,%d] " format "\n", "ERROR", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
! e* P2 K1 e! |! b) \3 j 52 } while (0)+ H- j) c6 c0 a
53
8 v* Z) n6 r; Y, X 54 #define LOG_DEBUG(format, ...) \* h+ I4 U5 ?4 \. V" d5 Y! @
55 do { \8 h9 ~- K, W8 U3 a9 w
56 OUTPUT("[%s|%s@%s,%d] " format "\n", "DEBUG", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
. |2 q6 Z3 i4 B2 v) `+ N 57 } while (0)
* V5 a! z1 ?& g" k 58 7 N* A8 P8 W7 S5 } e+ [7 ?3 j
59 #define LOG_WARN(format, ...) \5 q! e+ ~1 @2 H9 x
60 do { \
& k( B$ E" a2 ~% o7 ~* d 61 OUTPUT("[%s|%s@%s,%d] " format "\n", "WRAN ", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
) W# r' N( F5 H& X7 K 62 } while (0)
+ y- d' j" d X/ u T 63 9 v H; t, M7 V7 O% P+ c# U
64 #define LOG_TRACE(format, ...) \/ B6 }+ X# L& p. o9 ~
65 do { \
2 F% A' L' w$ G0 y 66 OUTPUT("[%s|%s@%s,%d] " format "\n", "TRACE", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
) k, r; S! a. `/ b" J- [( u$ e 67 } while (0)
% O+ a9 J& a$ S1 S 68 ( W r t3 D% M3 v S
69 #define LOG_FATAL(format, ...) \
1 E5 ^8 f4 { B! Q 70 do { \$ j) x7 b9 m# t1 X2 x
71 OUTPUT("[%s|%s@%s,%d] " format "\n", "FATAL", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
) P1 u' t* _) v$ p- X 72 exit(1); \1 z* S; k2 B ^2 A7 \
73 } while (0)
4 t6 @) I; j+ l 74 ( r4 K$ S4 A& g" D( z) k
75 /* Assert */
! z( z& S; y" f* L3 W 76 #define ASSERT(EXP) \( q# F3 [$ \4 I3 l5 B) M
77 do{ \
3 q4 [- E [: `/ k& |/ I 78 if (!(EXP)) { \
+ f; I1 m( W& U6 ^1 j 79 OUTPUT("[%s@%s,%d] ASSERT: " #EXP "\n", __func__, __FILE__, __LINE__ ); \6 y1 ~" i6 g3 K
80 exit(1); \
. \0 ?% I4 R2 J! n v/ H2 K* \ 81 } \
' ~2 N/ V& H; F$ O2 ~ y8 g 82 } while(0)( x( S9 K4 C( y8 d; j6 V$ P
83
% u, V+ t5 P! C0 p 84 #endif6 P& O% a7 T( S8 V, ]) H* Y
|
|