|
1 #ifndef _LOG_H_
& ~2 P! ^4 \6 f% P" ^! b 2 #define _LOG_H_+ r) d5 D3 E1 k9 }- e$ l4 U- K1 l
3
& @# ~2 w. F9 w1 L1 t 4 /* 0: printf; 1: UART1 */
# S2 |4 K: \! ^" q: p 5 #define OUTPUT_TO_UART1 1
8 r+ Q- o" i( t" Y7 H 6
* f& K; L' R# u/ p0 H 7 /* Switch Log Output */# V' ^# Y8 ^/ Z+ M( b3 F1 c
8 #if OUTPUT_TO_UART10 s7 k9 u+ M9 l- {" P7 s5 y
9 /* For UART1 Initial */
3 j, t z2 t/ }; |* J' l 10 #include <stdlib.h>
5 C4 O, o. Y- r Y 11 #include "hw_types.h"
. s$ J4 f% q0 j2 |- L 12 #include "hw_syscfg0_C6748.h"1 L' Z- x' h* a. u, w
13 #include "soc_C6748.h"
+ s* q3 W& o. x d) [% H 14 #include "psc.h" ; K$ d. {; l6 W: V U2 C
15 #include "gpio.h"
9 R# g6 S# u+ l4 y 16 #include "uart.h"0 D: }" Q, p/ ]) B0 }8 j j0 j; ^% U
17 #include "uartStdio.h"
+ V, h5 X/ D7 t% X 18
/ S) K+ X, D8 J 19 #define OUTPUT UARTprintf
/ V8 W K" D, D- v& |' v' o+ q 20 #else
+ n% b3 V7 B; r' l3 T 21 #include <stdio.h>
* q* z1 K. z. r, w/ q 22 #include <stdbool.h>
5 l. W9 k4 b9 K/ X. R 23 # s4 @4 I( o: V6 v) n9 X
24 #define OUTPUT printf; o3 A. {& w2 f4 b2 Z
25 #endif
$ \! q+ h) j! [3 O: P 26 - R9 b' |# D3 w7 W
27 /* Log init */
( ^0 u* S% c8 d2 l/ i 28 #if OUTPUT_TO_UART1
4 b% x+ ?# M) J' z 29 #define LOG_INIT() do { \
: k9 ~8 @: D; t. H5 B |8 F 30 PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_GPIO, \
: ^: r3 r7 }# V2 X4 I 31 PSC_POWERDOMAIN_ALWAYS_ON, \( f; D8 X9 k" U% i
32 PSC_MDCTL_NEXT_ENABLE); \9 @+ W) Y2 ~: ^' {
33 GPIOBank6Pin12PinMuxSetup(); \
# ]$ c+ q. e$ l/ [2 x& A$ y) [ 34 GPIOBank6Pin13PinMuxSetup(); \
) m8 [6 }3 J- l; f |. K 35 GPIODirModeSet(SOC_GPIO_0_REGS, 109, GPIO_DIR_OUTPUT); \
* z X* L7 J; ? i1 U/ l 36 GPIODirModeSet(SOC_GPIO_0_REGS, 110, GPIO_DIR_OUTPUT); \
9 N0 V+ \& a! ] b0 I4 w @ 37 UARTStdioInit(); \
4 X! c L( O& s0 f( R 38 } while (0)+ n" x/ t& C+ j" k9 i P- l
39 #else
* [( v2 V9 m) }( w 40 #define LOG_INIT() do { } while (0)
- v' x' V8 g4 ^9 o2 ^. j- G 41 #endif
$ k" q/ A) {' b; U" e* ^ 42
8 [( A' Y; i" F; B. }2 {5 S 43 /* Log Output */
, |. h7 Z0 i- ?: _$ W8 n8 o8 W# N5 ^ 44 #define LOG_INFO(format, ...) \
' B5 Y n8 b) K& [9 L0 q 45 do { \
" A3 p& W, l- H; C( E6 [# r$ W 46 OUTPUT("[%s|%s@%s,%d] " format "\n", "INFO ", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \# H1 a1 |! J% L' ^4 s
47 } while (0)1 A6 t, `3 R6 q# Q- @5 Z
48
, t5 m- s& ^2 u; Y& {; B 49 #define LOG_ERROR(format, ...) \
, w9 S7 y7 R, u" k6 U- Q7 B8 ^ 50 do { \
% e7 R9 M( ]$ N1 |' X! `& ` 51 OUTPUT("[%s|%s@%s,%d] " format "\n", "ERROR", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \; w. s% c1 Q W( N. ~* m
52 } while (0)6 F0 }+ z8 h; @! @
53 & @; I* _1 _; k& T
54 #define LOG_DEBUG(format, ...) \* b( |# S6 S* q2 [. U* t) `2 W8 g
55 do { \( X1 e( P2 K1 v0 I# }. x1 g1 [- t8 l
56 OUTPUT("[%s|%s@%s,%d] " format "\n", "DEBUG", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
3 z& t" y, F1 R- y; P0 U$ m' X 57 } while (0)
8 H7 V {0 C1 k% W 58
( ]- X8 |* p1 G2 R 59 #define LOG_WARN(format, ...) \5 }! } ^+ ]0 S* n& P5 N+ s
60 do { \
- b d/ V+ e. [! }# p2 I 61 OUTPUT("[%s|%s@%s,%d] " format "\n", "WRAN ", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \. Z, U/ K3 |9 K( {, P
62 } while (0)& Y4 \: N6 P, }5 I
63
" u+ A2 }+ d* P' J 64 #define LOG_TRACE(format, ...) \
( M3 y7 R9 w% I7 S# v6 f L( t 65 do { \
2 w. d1 R8 O$ Q% ~' p0 W 66 OUTPUT("[%s|%s@%s,%d] " format "\n", "TRACE", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
- ?7 k" e+ d$ y) V2 ~ 67 } while (0)& P6 V, t5 D3 b
68 $ B. |5 K: C# j1 F- \
69 #define LOG_FATAL(format, ...) \1 y7 d, J4 o' N% p9 s5 F
70 do { \+ |1 P3 V+ V0 X7 G+ C/ P
71 OUTPUT("[%s|%s@%s,%d] " format "\n", "FATAL", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
% Z) D! o, l, `! Q' ?/ m1 S1 x 72 exit(1); \% y/ z* e6 o% M8 K
73 } while (0)8 W6 o) e( p" v* T+ E3 G2 k
74
( [0 C* t& ~5 c. |; M8 |* A 75 /* Assert */# [8 @4 J% `# \1 ^6 ]" R6 I
76 #define ASSERT(EXP) \& \7 l. ?, O7 X8 G
77 do{ \
/ B6 K1 f. n6 u& Y7 M l* | 78 if (!(EXP)) { \
4 `6 w2 s! G4 P 79 OUTPUT("[%s@%s,%d] ASSERT: " #EXP "\n", __func__, __FILE__, __LINE__ ); \# G) L! _/ x" i, [5 x( z
80 exit(1); \5 j( X/ {1 \2 ~/ B6 h; p+ ^
81 } \
7 @) s7 ~ [' ^$ m 82 } while(0)
; g- n0 s# [, v3 f4 G 83
7 r" P9 p) o, w% A 84 #endif3 u( _9 G' y! i# z
|
|