|
1 #ifndef _LOG_H_
, D+ U1 c; q/ R- r6 }6 v 2 #define _LOG_H_+ ]( z# [7 F2 C$ |+ l
3 ( w N7 ~5 t) _; ~( a
4 /* 0: printf; 1: UART1 */! R" F9 o1 H) _. G+ u8 ?* U
5 #define OUTPUT_TO_UART1 1
+ O! x- @) P* ~3 I3 G 6
) i7 m' W$ S8 M- }( d/ {/ }+ \ 7 /* Switch Log Output */3 {) c N5 O1 W7 l+ c6 Z7 l, h& O
8 #if OUTPUT_TO_UART1
! ~: {: B2 O# U 9 /* For UART1 Initial */! S) s* J$ J" ~9 @- v
10 #include <stdlib.h>
1 E$ B- e5 n) } 11 #include "hw_types.h"
! E, h8 {5 p- l- m 12 #include "hw_syscfg0_C6748.h"
3 `4 C9 U) ~. |: j/ ^ 13 #include "soc_C6748.h"
, T3 J6 y+ E2 g# O2 f( m; h# i/ J' _ 14 #include "psc.h"
5 ]9 F7 _. T! J9 Z7 C7 N 15 #include "gpio.h"
4 E5 H+ @7 R! ?8 k, W2 D 16 #include "uart.h"
& i6 u# I( ?$ X: P. A- P 17 #include "uartStdio.h"
" h+ [5 K; A8 Y! d 18
3 p/ l. P( b$ H 19 #define OUTPUT UARTprintf* r* \2 X! K* j
20 #else& h- a; @: S2 f! A/ G& m$ q
21 #include <stdio.h>
, `7 q5 J1 k% V+ c; P M4 _ r 22 #include <stdbool.h> n* J" Y' f. O8 }) e9 }, ^, o- A# f
23
' ~+ I0 {8 H" f8 R3 i 24 #define OUTPUT printf" e" a- M+ ^- r
25 #endif
9 [) d8 P6 k& j7 M0 o" ]5 k2 A 26
3 `5 E. R7 C5 M4 R( n+ C6 A( U6 G# I, a 27 /* Log init */6 B# B! E# X. u9 |" f. ?9 c
28 #if OUTPUT_TO_UART1
0 X: J5 h: p& y0 A# A4 g m; _ i 29 #define LOG_INIT() do { \2 U% \. B; ~9 U# a
30 PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_GPIO, \: \2 q' m6 M7 Y0 K
31 PSC_POWERDOMAIN_ALWAYS_ON, \- N) p Y" O& C$ t6 q a. ]6 r
32 PSC_MDCTL_NEXT_ENABLE); \
( {' x- W! D5 s! |* P( K) c! g 33 GPIOBank6Pin12PinMuxSetup(); \; H+ T. O! @" G& n9 ~
34 GPIOBank6Pin13PinMuxSetup(); \ H2 U# {- Z. A/ L8 F
35 GPIODirModeSet(SOC_GPIO_0_REGS, 109, GPIO_DIR_OUTPUT); \0 h( k" c' M0 f2 l( t! {
36 GPIODirModeSet(SOC_GPIO_0_REGS, 110, GPIO_DIR_OUTPUT); \! a. }. o4 b) ~; r: B6 _% `& n
37 UARTStdioInit(); \
9 N0 e8 \; ~# k8 ~- h 38 } while (0)
0 ?' B: n4 I4 s6 u% V$ z' { 39 #else
' l) P8 r' j& P; X* V6 A5 A 40 #define LOG_INIT() do { } while (0)
5 k7 A2 S$ {* @; ]0 o3 p 41 #endif4 H0 d- Y, H4 R }$ C2 a7 Y
42
+ X8 r5 |- Y5 f. u 43 /* Log Output */
7 S3 B' f" i8 p. w' s 44 #define LOG_INFO(format, ...) \
7 ?( J q- `+ b7 {( G6 R) b7 M# ~5 ~% b 45 do { \
% K4 E6 k" l3 Z6 b 46 OUTPUT("[%s|%s@%s,%d] " format "\n", "INFO ", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \9 }& x5 d" t* J/ v
47 } while (0)
$ I! ]- G& I n3 i; M 48
2 m: l- F# m" ?7 L o. T& K6 l 49 #define LOG_ERROR(format, ...) \
# b) a6 l" }6 z/ N ^ 50 do { \) }' H4 b: F. I6 E- J8 ?
51 OUTPUT("[%s|%s@%s,%d] " format "\n", "ERROR", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
, o1 q+ i! q2 o) T1 u/ f; _1 [ 52 } while (0)
4 Z6 L! Z% S: q9 ~* T$ d 53 " F' u% W3 E5 E# l' X& r# @. T
54 #define LOG_DEBUG(format, ...) \. v0 l9 ?5 ]( {- c; V
55 do { \
9 e9 i. W/ d. z 56 OUTPUT("[%s|%s@%s,%d] " format "\n", "DEBUG", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
2 i+ Q7 H2 F w$ i/ d2 `7 ~8 } 57 } while (0)
) P% u# f! J+ K- M' _% @ 58 6 w4 i9 l+ S- R3 k5 ?4 K% n
59 #define LOG_WARN(format, ...) \
7 c# G0 e, y) ~4 {- _: |, _& W1 q9 u2 g 60 do { \9 b- S: c4 s: h
61 OUTPUT("[%s|%s@%s,%d] " format "\n", "WRAN ", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \4 U- p1 Z* ?9 w! k3 }8 V
62 } while (0)1 o+ P, e4 }, W" }- {; z( W8 M
63
8 F7 K3 F: p) V, Z+ {# m 64 #define LOG_TRACE(format, ...) \! g# t6 f+ G* Y; i' W* g
65 do { \' X: |4 b. W6 D S* R1 n' k1 D
66 OUTPUT("[%s|%s@%s,%d] " format "\n", "TRACE", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \) P ~. m1 S1 M- U; u
67 } while (0)! H+ X+ Z- G+ R$ ?/ e: {- _4 F
68
" A( Q6 a# N' h1 T- {2 ]2 T 69 #define LOG_FATAL(format, ...) \
8 A4 n) C5 N, u6 E+ _$ w 70 do { \( D6 g4 }: T4 t
71 OUTPUT("[%s|%s@%s,%d] " format "\n", "FATAL", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
' e- r" ^; z* g$ ?" u$ J# O 72 exit(1); \) w% F- G% c) C6 X
73 } while (0)3 ]$ B5 M6 |/ s" @
74 " Q) R3 ~, ?4 Q8 T
75 /* Assert */
( N' P) A% l: U; _* v9 r* T, f" B 76 #define ASSERT(EXP) \
% `& s W4 @+ V# V4 e$ | E1 @ 77 do{ \
+ c. a ?9 v4 { 78 if (!(EXP)) { \# L$ A+ s: x3 L, U1 P
79 OUTPUT("[%s@%s,%d] ASSERT: " #EXP "\n", __func__, __FILE__, __LINE__ ); \9 E. y1 Q& g: @$ f5 y
80 exit(1); \
4 i. ]$ }# D$ P9 Q( U! N$ D" F C4 O 81 } \ }9 H: f4 h) ?: q, S) h+ ~
82 } while(0)6 U8 z) |6 ~9 v9 N1 o( [2 o1 }
83 + a2 U/ ]0 X% l$ q
84 #endif
/ T8 ?$ X; q; \/ ^% q |
|