|
|
1 #ifndef _LOG_H_
* b8 t6 j0 v( | 2 #define _LOG_H_
9 w! s t5 c& K% \, g: X( L 3 : d8 u: t# n4 x3 u1 h( Z8 `" V0 }
4 /* 0: printf; 1: UART1 */' f; V( w) l7 L7 G
5 #define OUTPUT_TO_UART1 1
6 C* X/ {/ `! c+ I' B! F. a 6 * ^8 x' U; F: x: K
7 /* Switch Log Output */( a4 ^( ?3 J7 j
8 #if OUTPUT_TO_UART1
4 x- J) s, V$ r+ N 9 /* For UART1 Initial */
9 Q0 d: f6 y' t U6 O 10 #include <stdlib.h>% ~! l; X: u' w5 _! {! R$ K' j8 r+ }
11 #include "hw_types.h"
6 p. ~ M. _( z+ t6 b/ m 12 #include "hw_syscfg0_C6748.h"
3 w# V; T$ u: Q3 a" ~8 z 13 #include "soc_C6748.h"
( y2 M& L1 L3 `4 g4 Z 14 #include "psc.h" ( E& x! |* `/ x( o1 _; W6 h [
15 #include "gpio.h"
3 `1 w! M/ m3 J 16 #include "uart.h"- s1 @; z8 c$ R6 H. U& D% [" H
17 #include "uartStdio.h"
& t3 C! V4 s; j- f* q( n 18 5 y4 c7 G4 P3 g% m! `$ L/ Q) R
19 #define OUTPUT UARTprintf" C& @3 \" e0 ~& ] y5 Y# ?0 \
20 #else7 }* U# h1 f" x8 j5 I
21 #include <stdio.h>
% I+ H+ w+ [$ I4 k I2 f% [9 ~ J 22 #include <stdbool.h>
+ ]( |2 v) ]0 E' J5 G& E" K, ]5 r 23
" \( I P& _3 R" {$ h. D7 b 24 #define OUTPUT printf
6 I6 P( g; o) r 25 #endif4 Q6 j& g2 |/ V/ q$ F# @8 { Y: |
26
8 j; F0 p- V4 u& Z+ ~8 W( s( g 27 /* Log init */
; n6 o- c$ ~3 \1 k1 O 28 #if OUTPUT_TO_UART1, H. H! q i) o2 d$ z1 v# F: @. c
29 #define LOG_INIT() do { \
# F/ v- I4 r9 P' b- f2 Q- O. x 30 PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_GPIO, \
( M2 | u4 j2 O F' ~4 p) H3 Q 31 PSC_POWERDOMAIN_ALWAYS_ON, \
) B7 u2 j2 U0 q# `; d& Z& T 32 PSC_MDCTL_NEXT_ENABLE); \) K! K% ]' @( m1 O) E: k0 d# h& O
33 GPIOBank6Pin12PinMuxSetup(); \
0 f u6 ]0 d) F4 ^( q 34 GPIOBank6Pin13PinMuxSetup(); \
# Z" C* |4 F) { d0 q# x' E K 35 GPIODirModeSet(SOC_GPIO_0_REGS, 109, GPIO_DIR_OUTPUT); \
2 d8 E' N) m; u3 Y 36 GPIODirModeSet(SOC_GPIO_0_REGS, 110, GPIO_DIR_OUTPUT); \
& k8 T& ] P7 m8 @2 j 37 UARTStdioInit(); \
$ E( M) x% g m# j3 |% ~ 38 } while (0)* c Q) V8 x6 X* s7 K
39 #else
! _6 k3 i, P, @' O; C( Q 40 #define LOG_INIT() do { } while (0)
5 A9 v$ N& i. d& Q3 ` 41 #endif" A' P4 A/ ~: V2 k
42 4 ]8 N) q3 ^& E* t9 ?. I' B% K% p
43 /* Log Output */" U( K/ p g) r# c
44 #define LOG_INFO(format, ...) \" _0 U4 p9 i( D- E1 t: n7 u f
45 do { \/ c0 s) J9 K+ S2 m- y
46 OUTPUT("[%s|%s@%s,%d] " format "\n", "INFO ", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \# }- X# y$ S$ ?
47 } while (0)
0 U* `5 C t& _ ^# S 48
8 A6 X9 x) b2 M, H2 E/ z 49 #define LOG_ERROR(format, ...) \
' w, n* x0 S* T4 R 50 do { \% M! l( d6 c' a5 C
51 OUTPUT("[%s|%s@%s,%d] " format "\n", "ERROR", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
# t% F/ k" W8 v& ?) P8 E 52 } while (0)
y% o! K- A/ D 53
5 t* S$ p6 J. R! R* Y 54 #define LOG_DEBUG(format, ...) \/ }9 V2 c( @/ h9 C9 T
55 do { \
3 f0 s7 W2 D3 {5 [5 M0 ` 56 OUTPUT("[%s|%s@%s,%d] " format "\n", "DEBUG", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
- M' i' N( a, n 57 } while (0)
. {4 d V5 \& u( f l9 _' z/ Y 58 * G& k! Z# ^( J" q O
59 #define LOG_WARN(format, ...) \
O m6 N" ? x 60 do { \. V# n' i# {5 o
61 OUTPUT("[%s|%s@%s,%d] " format "\n", "WRAN ", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
- x0 B8 ~9 c3 T) {: P# L 62 } while (0)2 f7 C" r( K+ [# g$ H4 w8 W5 J
63 " E% u. w3 W9 \7 z. A o& O, M
64 #define LOG_TRACE(format, ...) \
. m% I* q P. @1 P2 t 65 do { \8 q' A1 T' Q# d! T
66 OUTPUT("[%s|%s@%s,%d] " format "\n", "TRACE", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
; k( F: T( D/ {" d; U3 [ 67 } while (0)
* z- q" x3 z, ]4 u: \ 68
9 J4 x& b6 x3 T" d. D3 ? 69 #define LOG_FATAL(format, ...) \
/ _% F( o$ \2 t& D; _ 70 do { \) Q1 ~/ ^& C; L" V
71 OUTPUT("[%s|%s@%s,%d] " format "\n", "FATAL", __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
# X( N: D4 ]/ T 72 exit(1); \
* ^& T# I& x' I3 W# J* Q2 B, m# j 73 } while (0). [; L7 x4 ~8 J* F
74
7 ^3 D1 p. ^9 T6 {4 S* C( [ 75 /* Assert */
, C7 u) l5 V2 M1 ? 76 #define ASSERT(EXP) \' \: q4 c9 W* h4 ]. o- {$ p
77 do{ \
* Y2 Y. P o; \: X& H 78 if (!(EXP)) { \
, B( m: o& p. h4 }- l 79 OUTPUT("[%s@%s,%d] ASSERT: " #EXP "\n", __func__, __FILE__, __LINE__ ); \# ?5 b" P# X3 ?+ v; n8 i
80 exit(1); \9 i2 i( _3 R( h
81 } \
# v9 m$ Q! G! @3 I: j6 h$ l% `( I1 Y0 ? 82 } while(0)3 X6 c# k& I% Y- E) v2 @
83
& }3 W' E1 d% u* V 84 #endif2 N7 s( t" S$ T" D6 `
|
|