|
|
1 #ifndef _LOG_H_
) |8 A; @5 B8 \# j8 v8 @ 2 #define _LOG_H_9 \" V. l6 u' J+ `5 s
3
6 J& a8 o r9 }* f. ` 4 /* 0: printf; 1: UART1 */2 c& M* P' _: `$ a& l. p+ A3 Y, R
5 #define OUTPUT_TO_UART1 1
" l" r/ H* [/ y: u 6 # p; K0 X& n: l9 t& f$ O
7 /* Switch Log Output */) X0 [4 |4 q9 H) H, z% l
8 #if OUTPUT_TO_UART1; B" D# @4 E; X! j. L* P
9 /* For UART1 Initial */( ] P! ?8 _6 `
10 #include <stdlib.h>$ t* ^& L; f" g, |1 Z8 m
11 #include "hw_types.h"
" h) h) ^: H' I$ N8 }6 f 12 #include "hw_syscfg0_C6748.h"
) |+ p% p3 q- G' R; b- u& [ 13 #include "soc_C6748.h"- |4 x" d, X, t
14 #include "psc.h" ! g3 |! \2 V4 b% {# i( u: c
15 #include "gpio.h" . d" S" `7 ^' A3 {
16 #include "uart.h"/ X1 j' n4 v) Y0 d" r6 r# Z4 H" {. Y
17 #include "uartStdio.h") G# h S; O5 U1 }* I4 U, q
18
& V3 ?5 }5 V( r/ A9 M 19 #define OUTPUT UARTprintf
4 H' ?$ G; G3 ^* @ d 20 #else t9 n- |6 B( _( k" i" K7 k7 f
21 #include <stdio.h>, ~! u3 M5 v5 M; ?
22 #include <stdbool.h>9 R. w' a8 k, X% N% l" J l
23
$ P( k: j- u* S1 F2 e7 B 24 #define OUTPUT printf3 t$ u B. Q$ q. O# m! u
25 #endif
( u5 e& n- ]6 g 26 + q+ A7 ^! E8 O
27 /* Log init */; X$ R# f1 C: A8 e* X, w
28 #if OUTPUT_TO_UART1
/ _, i) z9 S/ }: n& V4 i i% q5 v 29 #define LOG_INIT() do { \
v6 I; L3 E% Z/ C! C0 c* n4 o' k 30 PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_GPIO, \
0 g$ X3 ]2 [+ u! o- H. s; Q 31 PSC_POWERDOMAIN_ALWAYS_ON, \2 ^' I' L' Z: \7 w' J5 e" F# T) z
32 PSC_MDCTL_NEXT_ENABLE); \" k7 v/ j+ t2 Z- |
33 GPIOBank6Pin12PinMuxSetup(); \
+ c! C0 i/ C/ ? 34 GPIOBank6Pin13PinMuxSetup(); \8 J, q% M3 J7 b& j
35 GPIODirModeSet(SOC_GPIO_0_REGS, 109, GPIO_DIR_OUTPUT); \
9 W, [: l* e } 36 GPIODirModeSet(SOC_GPIO_0_REGS, 110, GPIO_DIR_OUTPUT); \
7 _3 W, X# `- Q9 W 37 UARTStdioInit(); \
[/ }5 L: e1 g( P9 w. A 38 } while (0)8 S4 G( \' ^) |! [- {) K
39 #else0 d- t& O8 q- d. m
40 #define LOG_INIT() do { } while (0)$ C$ V) G$ w9 K+ D) _
41 #endif, E/ e1 b5 i5 X! x$ M( F) C
42 6 R$ Q T, t* V# Y7 i: |0 w
43 /* Log Output */
) W# q y, \5 x 44 #define LOG_INFO(format, ...) \( @) Y6 n- b5 B. w( B) t
45 do { \
" |) s. E r& J# e [7 Z 46 OUTPUT("[%s|%s@%s,%d] " format "\n", "INFO ", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
: M0 J$ x" K0 w 47 } while (0)/ j& ~" p6 l$ Z! v
48 4 X% j4 G4 E' X( _; b3 ~ J
49 #define LOG_ERROR(format, ...) \
* L7 G9 \$ }3 K% P5 G 50 do { \4 g$ {4 z8 x$ ^( p! u, V
51 OUTPUT("[%s|%s@%s,%d] " format "\n", "ERROR", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
9 F* g) [( s) {/ W; u4 O/ a 52 } while (0)
9 {- v& C4 E* v 53 0 ~4 P& Z& U& _1 }
54 #define LOG_DEBUG(format, ...) \9 c8 J4 j9 A0 u( Q. v
55 do { \
8 w2 ]3 k: O X `6 j* G/ @& K' C 56 OUTPUT("[%s|%s@%s,%d] " format "\n", "DEBUG", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \' j3 s& p1 V( ~! W# m& L4 i2 y- P
57 } while (0)
2 ]% Q/ ]7 @% C& g& ~ 58
% {0 j5 K9 J& Y 59 #define LOG_WARN(format, ...) \
1 ^* P8 k; Y2 t7 C% c 60 do { \
7 t9 M( Q3 a; n* J' l) ~% p' P, l 61 OUTPUT("[%s|%s@%s,%d] " format "\n", "WRAN ", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \6 U0 X, t, S; y, ~
62 } while (0)
! }5 K# F c) r! U. j( E 63
' P; \3 e" A. H, Q! i$ W 64 #define LOG_TRACE(format, ...) \
" k! g4 j) W: q/ T% [ 65 do { \
/ v+ H/ b8 d1 D: |. N 66 OUTPUT("[%s|%s@%s,%d] " format "\n", "TRACE", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \3 O9 G, C# s$ W9 }" q% [3 C
67 } while (0)1 S" t2 ^5 F7 x; U& }" a7 c
68 ' q4 k4 K4 g) r) @
69 #define LOG_FATAL(format, ...) \
. W8 R Q( i5 p# f! G: [ 70 do { \
& l w3 j `$ ~# I 71 OUTPUT("[%s|%s@%s,%d] " format "\n", "FATAL", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \! a9 G7 Q# X: q' o
72 exit(1); \
! R' G( G! F: P# `" K# P 73 } while (0)
% t0 \( @0 F; G7 `0 U8 O 74 0 r* Z) C/ ]: t+ L0 a
75 /* Assert */
% g0 y6 R2 b% s% _) x c7 ] 76 #define ASSERT(EXP) \! c' }* H1 z7 k
77 do{ \
8 u7 V# [6 i: e: q; o. Y 78 if (!(EXP)) { \
3 w$ f* m# E. Y9 A- ^6 a- F 79 OUTPUT("[%s@%s,%d] ASSERT: " #EXP "\n", __func__, __FILE__, __LINE__ ); \
% _ O: q6 {- [8 f6 F) u$ e. s 80 exit(1); \) u* i6 r4 N/ C/ @! c
81 } \$ p7 u3 m3 A7 R @
82 } while(0)
) E" G4 a! b3 `% _. e X+ T+ B 83
5 c9 @+ _; U" t; `, s' ^- D: G" e 84 #endif( e2 g+ x6 E. m& ?- j; d
|
|