|
|
1 #ifndef _LOG_H_8 \; z* |3 G9 G. J# P( |# i* b' [
2 #define _LOG_H_
0 s6 M9 u( h9 a9 W2 I 3 $ j2 Q f7 F6 K: h! b! q
4 /* 0: printf; 1: UART1 */
: Q/ X! \2 @2 d3 R 5 #define OUTPUT_TO_UART1 1
8 ^7 n O ]' ~5 M! f% O' t/ A 6
) k* k* I& w0 I J% W5 ~/ B5 g 7 /* Switch Log Output */
$ t! H9 l, ] V- {) }! U7 P; I 8 #if OUTPUT_TO_UART1* V( |8 ^- A' R" b1 D
9 /* For UART1 Initial */
* o6 R z9 u$ }# U 10 #include <stdlib.h>4 ]& l- G) ?$ c2 D2 }, @2 y# Y( ?
11 #include "hw_types.h" / `4 D- t. H, k) l- {
12 #include "hw_syscfg0_C6748.h"8 {, {8 N+ M1 ~- D5 \
13 #include "soc_C6748.h"
4 a+ c% u3 Y1 b: V I% y 14 #include "psc.h"
& q' P0 |, m7 n M9 z r 15 #include "gpio.h" # z+ M9 q9 J! z6 ]
16 #include "uart.h"/ H' |9 ~- F V5 Z' F
17 #include "uartStdio.h"
, `% k7 m- b% F5 ^ 18 $ H( v+ ?. v1 s
19 #define OUTPUT UARTprintf- |. h$ G C2 B: P/ n: d
20 #else, E* o. `0 ^0 I
21 #include <stdio.h>
0 `) H' t; J+ A/ Y1 R 22 #include <stdbool.h>" D q! S; N7 }) \0 U3 Y. O' L
23
" I& U- O5 _1 q+ O% g/ `$ O 24 #define OUTPUT printf
7 C6 s8 J' C: w 25 #endif* p4 E+ K3 o/ c" ^. r
26
+ Y: ^; d0 E; s1 V" Q 27 /* Log init */( h, Y, S) C6 l6 \
28 #if OUTPUT_TO_UART1( g8 s6 u" X+ ]5 p1 p
29 #define LOG_INIT() do { \1 B1 P1 E6 s9 Q; Q
30 PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_GPIO, \! B1 o; A4 {" R7 @" d1 {0 C( V4 o
31 PSC_POWERDOMAIN_ALWAYS_ON, \
9 @; `$ z$ r# Y# R 32 PSC_MDCTL_NEXT_ENABLE); \
; `: d8 R4 P4 ]4 U 33 GPIOBank6Pin12PinMuxSetup(); \
4 Z4 e( U# }6 z) g! B. t2 H 34 GPIOBank6Pin13PinMuxSetup(); \
, @+ M, @- l" a& `% t 35 GPIODirModeSet(SOC_GPIO_0_REGS, 109, GPIO_DIR_OUTPUT); \5 p/ E. c4 F* g; Y$ t' O
36 GPIODirModeSet(SOC_GPIO_0_REGS, 110, GPIO_DIR_OUTPUT); \
& ]; \( M, q: F; V. t# j' M2 U 37 UARTStdioInit(); \( A/ D/ g% }) V1 v5 u9 [( M# W
38 } while (0)
4 V0 I) W' V" ]! W 39 #else
7 U4 K& E8 \# V" U0 _ 40 #define LOG_INIT() do { } while (0)1 J% K* l( b9 v0 g+ Q
41 #endif( P4 @0 o& ~' o
42
/ \* Z0 u) @% V- P. U% W2 I( H 43 /* Log Output */$ G1 [8 V4 Y- r+ ?. b. e
44 #define LOG_INFO(format, ...) \
$ b6 ?- H! F* q7 o( Z 45 do { \# I" g, u" Z/ G% s2 U% I3 e
46 OUTPUT("[%s|%s@%s,%d] " format "\n", "INFO ", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \ |' e' c. C. ?$ ^& L3 ^
47 } while (0)
, T; t# h5 U9 C9 H7 N 48
; a/ m; V+ {3 _8 \% d$ L2 I9 Y) \ 49 #define LOG_ERROR(format, ...) \; b! g" t5 I% `. {" I: x `! T
50 do { \# c% o+ V& P# c. a
51 OUTPUT("[%s|%s@%s,%d] " format "\n", "ERROR", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
- ?- b: I' m% Y& r$ Q 52 } while (0)
# ~" I% ^. t" Q5 {- n' Q9 ~ 53 - G' C0 j0 N, a2 ~3 ~& L
54 #define LOG_DEBUG(format, ...) \/ J: t# n+ L: m f0 m/ r O# I" I
55 do { \' _2 }, ~- d/ U$ i
56 OUTPUT("[%s|%s@%s,%d] " format "\n", "DEBUG", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
) ?( }; [% }& @+ p5 B, n, U1 } 57 } while (0)2 t4 w; _* Q8 `
58
, A4 s/ A' P/ b 59 #define LOG_WARN(format, ...) \
7 R3 o* g5 t9 V5 {7 ]4 D8 S- H# {' y 60 do { \
( J0 W/ _+ n2 J% k! e* K- h 61 OUTPUT("[%s|%s@%s,%d] " format "\n", "WRAN ", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \1 u h: u( M$ L( ?4 a2 e5 j5 \2 r
62 } while (0)
( H. U# Y/ \7 k7 q1 z; `7 n' r1 m/ } 63
, W0 }; M# m7 I, R+ v 64 #define LOG_TRACE(format, ...) \
1 I# @, g/ C& S0 l0 c/ ^- g, R) z 65 do { \6 {' P" T: e8 V7 n1 K: T1 {
66 OUTPUT("[%s|%s@%s,%d] " format "\n", "TRACE", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
9 N( H& ^ i6 O9 I* }& }/ A. y0 s 67 } while (0)
5 f' @7 T. J! Z 68 / k6 d# c) P1 w
69 #define LOG_FATAL(format, ...) \
! ~4 [4 f b. ]+ _, ^$ U 70 do { \' Q( Q ]( S4 t' a
71 OUTPUT("[%s|%s@%s,%d] " format "\n", "FATAL", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \( h: {9 C4 `, e( Q3 C$ c* Z7 n- O" b
72 exit(1); \( f1 Q/ h" q: L+ A/ V
73 } while (0)
3 r. X! J1 J$ m w0 W 74
1 H2 i K7 X, m. G i" o 75 /* Assert */, L8 ^3 _! p1 w' |0 g& O
76 #define ASSERT(EXP) \
6 e$ ]8 H" d& l0 u% l* A8 L 77 do{ \/ O5 I6 f2 n8 ?
78 if (!(EXP)) { \
5 f$ V: A# ~, H- v* S 79 OUTPUT("[%s@%s,%d] ASSERT: " #EXP "\n", __func__, __FILE__, __LINE__ ); \
$ o" q0 j' M5 t; I( U* {, c 80 exit(1); \: |7 U5 m0 @/ i& ?
81 } \" X$ L# a3 Y' U7 t
82 } while(0)2 r' Y0 D* j& ^1 {0 `$ Y" P# @
83
) c: ?! k% S5 L. e/ d7 F9 e6 ] 84 #endif4 S, r: p) W5 w2 P. a5 N
|
|