|
|
1 #ifndef _LOG_H_
1 V3 C& R w. P" ~1 r& Q 2 #define _LOG_H_- Y+ p5 w# \ V2 }- A7 K; N' p) {
3
: ?% a- K2 g3 L0 `& y6 }; E( M* { 4 /* 0: printf; 1: UART1 */
7 \ K; f5 m6 T( r) W4 m 5 #define OUTPUT_TO_UART1 1
. M+ l8 {% A% `( e: T% W 6
2 [8 U1 I v! l5 {8 c0 U 7 /* Switch Log Output */
+ A: F8 I: T' D3 J. e 8 #if OUTPUT_TO_UART1' _/ {0 @# x: L- ~) b4 W
9 /* For UART1 Initial */
$ X& _# x. s- I4 n* C8 D 10 #include <stdlib.h>
/ r* C& P1 [' R8 p1 `5 } 11 #include "hw_types.h" / `4 o! H0 n3 {) Y" n1 n- K" G0 k+ |
12 #include "hw_syscfg0_C6748.h"
; m! J& S2 K- c8 ]5 I! i6 T) [ 13 #include "soc_C6748.h"2 _3 W5 h4 U! v! b
14 #include "psc.h" 9 `) `; O$ X* y( J m4 b
15 #include "gpio.h"
6 i( S2 i( C# A. x 16 #include "uart.h"
7 {' w5 x7 P$ n6 X; G$ W5 |4 _% O 17 #include "uartStdio.h"
4 J8 Z$ L% f S) b: E$ v) P 18 ! l8 Y5 n' |( J- ]6 I
19 #define OUTPUT UARTprintf
: |: l; A" n6 A& R 20 #else( K& J, }1 s& w. U. |
21 #include <stdio.h>
9 U# z) z1 k, z" q1 `9 n9 Z 22 #include <stdbool.h>% ^8 U$ Y: C: n, P
23 - D; ]. p V9 S, ~3 p8 F) A
24 #define OUTPUT printf
b2 v0 I" I) \, i 25 #endif P/ S9 M6 u a
26
3 j7 s. X+ @, t6 `' Q( G; z* ]; ` 27 /* Log init *// `& t! \: f7 [! P/ h
28 #if OUTPUT_TO_UART1
& g; ~% I1 v$ Q* t9 Q 29 #define LOG_INIT() do { \
3 Q5 J" O' y' W( k6 U$ \ 30 PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_GPIO, \
, n. B4 a9 I; u/ P& q% ^ 31 PSC_POWERDOMAIN_ALWAYS_ON, \
' S, ~% n" g8 `% z/ `( A4 ]/ V 32 PSC_MDCTL_NEXT_ENABLE); \- ~- i2 B; j. r
33 GPIOBank6Pin12PinMuxSetup(); \
O8 y5 I! |7 g! L 34 GPIOBank6Pin13PinMuxSetup(); \' V3 t! W7 d+ P/ n9 I% y' O
35 GPIODirModeSet(SOC_GPIO_0_REGS, 109, GPIO_DIR_OUTPUT); \
' Q2 \$ d- k( E* B; i 36 GPIODirModeSet(SOC_GPIO_0_REGS, 110, GPIO_DIR_OUTPUT); \
* R; i4 N" i6 j# m3 J 37 UARTStdioInit(); \
% m, I+ T7 e( N* @ 38 } while (0)5 f5 H( i! ~- ` O
39 #else
3 }- V/ \; f, P4 _4 A1 `* d& Q 40 #define LOG_INIT() do { } while (0)
5 j7 }" D7 f- O+ D9 t6 V1 z. ^+ I 41 #endif: u! m+ G& e! D2 X: w G( O8 w
42 , w* w7 n. X: t
43 /* Log Output */! p7 X4 \( S( C& Y# n
44 #define LOG_INFO(format, ...) \
1 R! |' l8 a+ a% [- r+ V 45 do { \" d$ y) I2 n# ]! ?
46 OUTPUT("[%s|%s@%s,%d] " format "\n", "INFO ", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
" x! b* u, z& e; m1 n% n+ E 47 } while (0): H; e6 S7 ?) b- z
48
8 {# w( p3 x7 u6 d* ~ 49 #define LOG_ERROR(format, ...) \
$ W7 Y2 ^* K. L# H% D% f0 @ 50 do { \
p( p) N/ k- f; a5 ~. D 51 OUTPUT("[%s|%s@%s,%d] " format "\n", "ERROR", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \" G- s$ j/ Y- ?+ f/ {7 P
52 } while (0), I( U( \- b0 v' I" e6 f
53
! ]/ E5 G, @& f0 d* M5 r2 }% j5 Z 54 #define LOG_DEBUG(format, ...) \
W" x' V8 Q0 A" E 55 do { \
% X) J8 k% t$ H5 \ 56 OUTPUT("[%s|%s@%s,%d] " format "\n", "DEBUG", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \. ?' c& Q, Q" z0 B6 Q4 r
57 } while (0)
- c7 m* j* i; j: Z& o/ l 58
" J8 }' [) n: `( r1 }! M" x2 [ 59 #define LOG_WARN(format, ...) \& w8 @0 f- I0 G
60 do { \
$ t+ t: o! m% D0 h: X! S( A* I 61 OUTPUT("[%s|%s@%s,%d] " format "\n", "WRAN ", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
; k/ m4 n+ @& `# i* e( {% ` 62 } while (0)1 I$ @$ A8 x& q2 Q9 O
63
; K h0 d& L/ w% e7 \$ C 64 #define LOG_TRACE(format, ...) \* L; Z% X2 f2 d8 w
65 do { \* ?5 p1 W3 G0 P# h& Y. N4 g m
66 OUTPUT("[%s|%s@%s,%d] " format "\n", "TRACE", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \1 S$ W& t2 p L U# `7 w
67 } while (0)# N* D1 u% }0 Q6 d' x; d
68
2 w$ {* U2 L- q2 I- a) \ 69 #define LOG_FATAL(format, ...) \$ s4 @( D, I/ h8 f3 X
70 do { \
& _- q; r; ?2 r; l z 71 OUTPUT("[%s|%s@%s,%d] " format "\n", "FATAL", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
6 }7 w2 e+ T* t; _' { 72 exit(1); \
3 M' y, G& R0 N* \9 R4 S 73 } while (0)7 d6 _' ?* W! K6 V5 L. U4 N
74 / b& E- S; ~8 B% s3 K, k1 B, @
75 /* Assert */
# U$ ~+ z d" t& l, B# D$ I0 Z 76 #define ASSERT(EXP) \/ a- {( Q% ?. A3 y5 ]6 F( O3 f5 w3 P
77 do{ \: l$ G9 {2 M5 n) |0 Q" r; {
78 if (!(EXP)) { \
/ H7 y8 @% }1 P% I$ Q! x! q3 S0 q 79 OUTPUT("[%s@%s,%d] ASSERT: " #EXP "\n", __func__, __FILE__, __LINE__ ); \9 }5 ?: u E& g4 v1 b8 V6 Z
80 exit(1); \* g/ \" f* v$ O; h$ {
81 } \( Z h: n, C- s) Y8 T& M% s5 J
82 } while(0)
3 P( s* {7 B* x: r 83 ) d& P" G: `; F& M3 W) k, t- a$ |$ ~
84 #endif
a" @# y. Y& \6 a4 s0 X7 E( V |
|