|
1 #ifndef _LOG_H_
7 H. \6 _8 S, |, C8 H 2 #define _LOG_H_
. s! C1 K" m2 z/ {5 F4 ]- ?3 ^9 P" f 3 * {+ C0 J P1 @& {
4 /* 0: printf; 1: UART1 */
( q7 T F5 X$ R) U0 p 5 #define OUTPUT_TO_UART1 1
* L0 k2 s/ g8 [5 m6 j 6
. ?9 f, H" J, G) W5 ?8 j 7 /* Switch Log Output */
0 ]1 ]' s' ]1 b# f" c 8 #if OUTPUT_TO_UART10 T3 }9 B3 \6 Z+ a
9 /* For UART1 Initial */+ X+ x! ?9 G. T" F, n% o; s
10 #include <stdlib.h>8 h9 m# l. i+ ~
11 #include "hw_types.h" : [ F5 g6 D3 A/ h$ g
12 #include "hw_syscfg0_C6748.h"# ^% m0 X# v2 ^4 d
13 #include "soc_C6748.h") q* ~9 q& l) f' T2 C# Y* l& w4 w
14 #include "psc.h" 6 V8 I; }, H7 j3 y
15 #include "gpio.h"
: A5 t7 S |# h% s: A 16 #include "uart.h"
/ L& @! b$ t9 u, O- P5 U/ Z% U3 C 17 #include "uartStdio.h"& d' ?/ @* |. D5 {/ O9 v) S8 z
18
2 V+ E5 B" W- e) c 19 #define OUTPUT UARTprintf
0 ^ [ {' L# [, q) G2 n 20 #else# R, s( V9 p; H: x" u- Y/ h i
21 #include <stdio.h>
! F1 r/ v* T2 V0 m- j 22 #include <stdbool.h>
( s/ C* N: H/ V# Q7 ]3 O 23
" l5 f0 W$ Z! [4 k; o) {1 b 24 #define OUTPUT printf
( o8 G0 q9 V6 o ~) n* m 25 #endif
9 q0 s6 ]' Q8 O1 h" ?& p& [ 26 4 b4 l. s% p0 l; d- H
27 /* Log init */
' ?0 X0 f7 |# f) Z [( D 28 #if OUTPUT_TO_UART1
0 b* T' Z2 v3 k! s( w 29 #define LOG_INIT() do { \
# g# v" Y* }3 f" I0 L9 g7 p 30 PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_GPIO, \
. A9 |7 L8 j/ M 31 PSC_POWERDOMAIN_ALWAYS_ON, \! U! _+ X7 i8 w+ \8 N9 p4 |
32 PSC_MDCTL_NEXT_ENABLE); \
% u$ k5 ~# P- E' g 33 GPIOBank6Pin12PinMuxSetup(); \1 ~; w: F- q4 T6 e
34 GPIOBank6Pin13PinMuxSetup(); \0 P) y4 w1 K6 V, y# v
35 GPIODirModeSet(SOC_GPIO_0_REGS, 109, GPIO_DIR_OUTPUT); \
8 a9 E9 ~2 a2 L6 L" k 36 GPIODirModeSet(SOC_GPIO_0_REGS, 110, GPIO_DIR_OUTPUT); \% O% l# [9 w5 n# a/ |
37 UARTStdioInit(); \
9 ^! b" A U) `2 D- A' _3 ]% N% D 38 } while (0). g- l7 U& i1 j( E
39 #else8 L& I4 i2 _+ W& ~' v
40 #define LOG_INIT() do { } while (0). L1 e- t' C; \7 B" O e, h0 F8 b* |
41 #endif3 A8 e# q, m+ z9 G
42 & X- b. z1 _" e1 B
43 /* Log Output */
* _ f$ x5 D. O 44 #define LOG_INFO(format, ...) \
, |# O5 D# U y- A6 I% l/ V 45 do { \
* @# U1 F+ @& d2 e) p) i 46 OUTPUT("[%s|%s@%s,%d] " format "\n", "INFO ", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \: E4 {! C3 m x# X- f ?6 @/ b" v
47 } while (0)
& n' R v! U( F8 R& c 48 # q9 ^$ }. W% F% i% }
49 #define LOG_ERROR(format, ...) \
% m3 G- H( y( u 50 do { \" O [ j- l. M0 d) x" p" k
51 OUTPUT("[%s|%s@%s,%d] " format "\n", "ERROR", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
8 G, e2 n$ }. C+ } 52 } while (0)
8 k- v2 C/ O/ r6 t- f, Y 53
5 K* [( O7 l2 T3 a" | u4 w 54 #define LOG_DEBUG(format, ...) \
( c8 ]+ \9 ]4 O4 H* R# g/ X$ J 55 do { \
! H/ Y M+ O, _5 o 56 OUTPUT("[%s|%s@%s,%d] " format "\n", "DEBUG", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
; \3 w( S" P* \( Q 57 } while (0)) O3 K% D' g* {! y, h5 X" B- j
58
# F% b8 x; [, e% z 59 #define LOG_WARN(format, ...) \" Q+ f8 t+ D- y* V
60 do { \
m4 y, D8 k: z& r' E9 [+ v 61 OUTPUT("[%s|%s@%s,%d] " format "\n", "WRAN ", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \$ |( Z( w, f) o! }, ~9 T U
62 } while (0)! j! g+ a8 h. W( t. I
63 7 s3 g S! s1 N2 R7 M" C/ z: q3 h
64 #define LOG_TRACE(format, ...) \
. l( D/ O7 a+ V 65 do { \
9 h7 B6 x5 Q2 }+ P' f6 ~# }+ W9 w/ g 66 OUTPUT("[%s|%s@%s,%d] " format "\n", "TRACE", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
/ V) x% x& T$ c8 t 67 } while (0)
/ ]8 D3 x3 p9 M; K' G1 K) z 68 7 o9 s7 m: y% f; i0 I
69 #define LOG_FATAL(format, ...) \
( o* O9 a5 @7 o1 W 70 do { \
' S+ N1 l; [4 L' K0 H) n. x+ {* ]2 H 71 OUTPUT("[%s|%s@%s,%d] " format "\n", "FATAL", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
: v! L+ ]2 q0 G7 ~5 l 72 exit(1); \: B, Z/ b8 w* ~8 E" \
73 } while (0)7 ?" {# |# W" I' ?; _( P7 q
74
1 O/ k8 g6 x% S3 p 75 /* Assert */
2 ], Y V8 F0 p7 O8 \ 76 #define ASSERT(EXP) \
* H& u3 A" s+ i& N' d 77 do{ \
- w7 o8 \0 t, }7 t0 v+ a% N 78 if (!(EXP)) { \" H! ?4 B9 ]: O% l8 Z/ Q
79 OUTPUT("[%s@%s,%d] ASSERT: " #EXP "\n", __func__, __FILE__, __LINE__ ); \
) B8 E# _- q6 Q7 ~* A5 P( y 80 exit(1); \
! b" v& Q* _! ?2 T 81 } \
- L4 Q$ S9 U$ b0 z) G2 I 82 } while(0)
! I+ T. z9 c2 r- M 83 ! q8 S% G2 ?5 ^, d' ^5 v2 H
84 #endif
) f4 l( ?0 D7 A2 g) [+ x |
|