|
|
1 #ifndef _LOG_H_
/ k( u5 N7 G$ R8 Y7 S 2 #define _LOG_H_
8 t' T; l, _% z! r: x 3
2 s$ W9 } j8 Q' I# X% _ 4 /* 0: printf; 1: UART1 */0 r$ ?6 M+ s- j# e+ W: Y) Z# M
5 #define OUTPUT_TO_UART1 1
; B# o7 A' r( V2 A 6
$ R# ~) q6 s3 P& O2 B" o 7 /* Switch Log Output */
; H0 P% h) K0 m! o8 d0 e1 { 8 #if OUTPUT_TO_UART13 C8 S3 i+ s* w1 C
9 /* For UART1 Initial */
9 |9 m2 C3 V) n. D( U! f K* u 10 #include <stdlib.h>( K* J9 k+ G3 ]$ _5 [
11 #include "hw_types.h"
$ p8 f1 a; V, U5 Q9 W( T; m; @7 R3 g2 l* O 12 #include "hw_syscfg0_C6748.h"
- E/ x7 y% C$ M O 13 #include "soc_C6748.h"
6 P2 p( \: S. X5 H* E+ l 14 #include "psc.h"
* u1 k$ l9 @7 U; x6 H 15 #include "gpio.h" 8 b3 ?# M5 V+ @' x( L6 x4 S
16 #include "uart.h"
+ _8 L/ b n# h0 @; W. \2 w 17 #include "uartStdio.h"4 h0 A" c1 f9 `1 r% {
18
- V; o# V! i1 c8 p3 v3 `* C6 ` 19 #define OUTPUT UARTprintf0 N4 N8 X+ W. t4 `5 y# s9 s- E
20 #else
% }8 [1 V8 f! a: ]% ~! Q- ?/ q 21 #include <stdio.h>1 V5 G3 L# ]$ F0 j9 V3 S
22 #include <stdbool.h>
1 I. m: n) e, ]) J 23
+ R' x: c# V* | 24 #define OUTPUT printf
$ m4 Z/ @. i3 k6 |- o( K# c6 V 25 #endif' t" N. g4 z3 C4 t% y
26 9 M/ y' x! ~8 v% ^; _7 }
27 /* Log init */- @0 Z/ r: d: |7 a- D7 W
28 #if OUTPUT_TO_UART1
3 q0 c; k# l% D8 I! m 29 #define LOG_INIT() do { \
7 G9 p% j& M7 D k/ D 30 PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_GPIO, \ H% f2 R3 z, R8 `% j3 h' z
31 PSC_POWERDOMAIN_ALWAYS_ON, \
+ u1 U5 d* I; w& S; b 32 PSC_MDCTL_NEXT_ENABLE); \
$ ~5 D& P$ s* t# x 33 GPIOBank6Pin12PinMuxSetup(); \6 {" A* x5 E/ _; v
34 GPIOBank6Pin13PinMuxSetup(); \
/ E! x; Z5 T$ H" A% n! Z- k 35 GPIODirModeSet(SOC_GPIO_0_REGS, 109, GPIO_DIR_OUTPUT); \! f. j' l5 h1 [" c6 V$ R: F# g
36 GPIODirModeSet(SOC_GPIO_0_REGS, 110, GPIO_DIR_OUTPUT); \
5 ~: l5 d g5 ^6 g8 L2 G9 C 37 UARTStdioInit(); \ {0 B6 V3 l0 J) ]# X
38 } while (0)
& F+ A/ F1 M$ w S* ~7 o4 D# T 39 #else' O$ r. @& {/ k8 S4 }3 V
40 #define LOG_INIT() do { } while (0)- G9 R0 U0 f, ~
41 #endif
* O v7 U1 F3 C. O 42 9 d. B. ^3 |) Y0 P6 T' R+ K! J
43 /* Log Output */5 w0 B. i7 b: A p6 y2 [" r
44 #define LOG_INFO(format, ...) \- {- K* w9 M' E
45 do { \
+ E0 v& `3 W1 D, W$ u' r" x" s6 ` 46 OUTPUT("[%s|%s@%s,%d] " format "\n", "INFO ", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \1 }" {/ [# P" Z5 Y, `+ t
47 } while (0)
, U& Q, l3 n: j( Z+ n+ ~ 48 1 L7 o: h4 C" \* d; ?- I
49 #define LOG_ERROR(format, ...) \5 e- P$ ^# J; C" o
50 do { \1 d6 p ?, F. r
51 OUTPUT("[%s|%s@%s,%d] " format "\n", "ERROR", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
2 N- y5 I: B- j% s- [ 52 } while (0)
: B! f n5 G3 p; Z0 ]1 J 53 1 e: x% m, x( M" @1 s# K) W9 v; E
54 #define LOG_DEBUG(format, ...) \
& V" {9 R: Q7 b2 y4 y c6 Z" c 55 do { \, N9 p& U* U$ \" |7 n) n& j
56 OUTPUT("[%s|%s@%s,%d] " format "\n", "DEBUG", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
4 Q& h! }9 ~9 ?, t& y- N 57 } while (0)
6 w. l" s7 y, P( u9 V, A 58
! P, N# @3 }! Q0 \' o 59 #define LOG_WARN(format, ...) \
! H- i- g! f- m( n. g$ \ 60 do { \
: ? W4 N9 N! y K) f 61 OUTPUT("[%s|%s@%s,%d] " format "\n", "WRAN ", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \9 j) h; X- `( v5 Z' m/ c- U
62 } while (0)
! j: C" D4 J0 ]3 V. ? 63
" `: d9 v1 Y' g- S0 m. _/ s 64 #define LOG_TRACE(format, ...) \( T* n2 b& O: G0 ~0 Q0 v4 i
65 do { \- M: J8 \% y7 c" t0 f; N3 }( J
66 OUTPUT("[%s|%s@%s,%d] " format "\n", "TRACE", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \) Q p3 ^& ~. Q0 N `/ _
67 } while (0)
! h7 S7 |- o1 ]8 ]* C 68
+ u. M8 K4 Q7 x% }; t& q 69 #define LOG_FATAL(format, ...) \
' h, ]7 K; x! m, S, @1 Y4 T 70 do { \
0 u3 ?6 E9 W+ c0 e( W! d0 n 71 OUTPUT("[%s|%s@%s,%d] " format "\n", "FATAL", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \* t2 }7 q1 @: Y! X
72 exit(1); \
+ H7 R- k, V" F7 x6 G 73 } while (0)4 R( ^% {$ w& q5 O" [7 t; p
74 3 W) V# x: [% F
75 /* Assert */
* F m, X* [0 R. I$ b# ^8 s 76 #define ASSERT(EXP) \
# s" ?: t# b# n$ y 77 do{ \
8 L+ |/ u: `7 V& `* ], N2 j 78 if (!(EXP)) { \) Y+ o3 K6 z0 V4 l
79 OUTPUT("[%s@%s,%d] ASSERT: " #EXP "\n", __func__, __FILE__, __LINE__ ); \
( g8 z S, [. C; M3 d7 t& d 80 exit(1); \
* [) [3 A1 [0 @! s5 ?0 H: S- t9 k 81 } \
, n1 K; z% J% m: c 82 } while(0)
0 l; J- o0 z, ^0 n8 h 83
2 ?7 v3 G% g6 G. B% [ 84 #endif) L7 f; G _4 D' Y9 p+ v& x
|
|