1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: 15: 16: 17:
18:
19: #include <tk/typedef.h>
20: #include <sys/sysdef.h>
21:
22: #if USE_TMONITOR
23: #include "../../libtm.h"
24:
25: #ifdef IOTE_M367
26: #if TM_COM_SERIAL_DEV
27:
28: #define UART_BASE (0x40049000UL)
29:
30: #define UART_DR (*(_UW*)(UART_BASE + 0x0000))
31: #define UART_FR (*(_UW*)(UART_BASE + 0x0018))
32: #define UART_IBDR (*(_UW*)(UART_BASE + 0x0024))
33: #define UART_FBDR (*(_UW*)(UART_BASE + 0x0028))
34: #define UART_LCR_H (*(_UW*)(UART_BASE + 0x002C))
35: #define UART_CR (*(_UW*)(UART_BASE + 0x0030))
36: #define UART_IMSC (*(_UW*)(UART_BASE + 0x0038))
37: #define UART_RIS (*(_UW*)(UART_BASE + 0x003C))
38: #define UART_ICR (*(_UW*)(UART_BASE + 0x0044))
39: #define UART_DMACR (*(_UW*)(UART_BASE + 0x0048))
40:
41: #define UART_FR_TXFE (1 << 7)
42: #define UART_FR_RXFE (1 << 4)
43:
44: #define UART_LCR_H_WLEN(n) (((n)-5) << 5)
45:
46: #define UART_CR_RTS (1 << 11)
47: #define UART_CR_DTR (1 << 10)
48: #define UART_CR_RXE (1 << 9)
49: #define UART_CR_TXE (1 << 8)
50: #define UART_CR_UARTEN (1 << 0)
51:
52:
53: EXPORT void tm_snd_dat( const UB* buf, INT size )
54: {
55: UB *b;
56:
57: for( b = (UB *)buf; size > 0; size--, b++ ){
58: while ( (UART_FR & UART_FR_TXFE) == 0 );
59: UART_DR = *b;
60: while ( (UART_FR & UART_FR_TXFE) == 0 );
61: }
62: }
63:
64:
65: EXPORT void tm_rcv_dat( UB* buf, INT size )
66: {
67: for( ; size > 0; size--, buf++ ){
68: while ( (UART_FR & UART_FR_RXFE) != 0 );
69: *buf = UART_DR & 0xff;
70: }
71: }
72:
73:
74: EXPORT void tm_com_init(void)
75: {
76: UW n;
77:
78: UART_CR = 0;
79: UART_DMACR = 0;
80: UART_IMSC = 0;
81: UART_ICR = UART_RIS;
82:
83: n = CLOCK_fsys * (64*2 / 16) / 115200;
84: n = (n + 1) >> 1;
85: UART_IBDR = n >> 6;
86: UART_FBDR = n & 0x3f;
87:
88:
89: UART_LCR_H = UART_LCR_H_WLEN(8);
90:
91: UART_CR =
92: UART_CR_RTS | UART_CR_DTR |
93: UART_CR_RXE | UART_CR_TXE | UART_CR_UARTEN;
94: }
95:
96: #endif
97: #endif
98: #endif