MessageIO.cpp
4.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
//////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------//
//-- Copyright 2001 VAutomation Inc. Nashua NH USA. All rights reserved.//
//-- This software is provided under license and contains proprietary //
//-- and confidential material which is the property of VAutomation Inc.//
//-- HTTP://www.vautomation.com //
//----------------------------------------------------------------------//
//////////////////////////////////////////////////////////////////////////
// MessageIO.cpp: implementation of the CMessageIO class.
//
//////////////////////////////////////////////////////////////////////
#include "DeviceSpecificInclude.h"
#include "MessageIO.h"
#include "DataTypes.h"
#include <stdio.h>
#include <string.h>
CMessageIO::CMessageIO()
{
}
CMessageIO::~CMessageIO()
{
}
char CMessageIO::GetChar()
{
#ifdef MESSAGES_TO_UART
//Typedefs used to access the UART
typedef volatile unsigned char* RegisterAddressType;
typedef volatile char* DataIOType;
typedef volatile char BusDataType;
//Define the UART interface
AddressType UART1BaseAddress = (AddressType)0x00FC1000;
RegisterAddressType RXEmptyRegister = (RegisterAddressType)( 0x14 + UART1BaseAddress);
RegisterAddressType BaudLowRegister = (RegisterAddressType)( 0x18 + UART1BaseAddress);
RegisterAddressType BaudHighRegister = (RegisterAddressType)( 0x1C + UART1BaseAddress);
DataIOType RXDataRegister = (DataIOType)( 0x10 + UART1BaseAddress);
static bool uart_init = false;
//Only set the setup once
if( uart_init == false )
{
*BaudLowRegister = UART_BAUD_LOW; //30MHZ chip clock
*BaudHighRegister = UART_BAUD_HIGH;
uart_init = true;
}
volatile char return_char;
// wait till transmit_is_ready = 1 - ready to transmit
volatile unsigned char receive_fifo_empty = 0x20;
while( receive_fifo_empty == 0x20 )
{
receive_fifo_empty = *RXEmptyRegister & 0x20;
}
return_char = *RXDataRegister;
return( return_char );
#else
return( '\0' );
#endif
}
void PrintUART( char* print_string )
{
#ifdef MESSAGES_TO_UART
//Typedefs used to access the UART
typedef volatile unsigned char* RegisterAddressType;
typedef volatile char* DataIOType;
typedef volatile char BusDataType;
//Define the UART interface
AddressType UART1BaseAddress = (AddressType)0x00FC1000;
RegisterAddressType TXEmptyRegister = (RegisterAddressType)( 0x14 + UART1BaseAddress);
RegisterAddressType BaudLowRegister = (RegisterAddressType)( 0x18 + UART1BaseAddress);
RegisterAddressType BaudHighRegister = (RegisterAddressType)( 0x1C + UART1BaseAddress);
DataIOType TXDataRegister = (DataIOType)( 0x10 + UART1BaseAddress);
static bool uart_init = false;
//Only set the setup once
if( uart_init == false )
{
*BaudLowRegister = UART_BAUD_LOW; //30MHZ chip clock
*BaudHighRegister = UART_BAUD_HIGH;
uart_init = true;
}
//Get the size of the string.
UnSignedLong chars_to_print = strlen( print_string );
//Loop over the string and put chars on the interface
for (UnSignedLong i=0; i< chars_to_print; i++ )
{
// wait till transmit_is_ready = 1 - ready to transmit
volatile unsigned char transmit_is_ready = 0;
while( transmit_is_ready == 0 )
{
transmit_is_ready = *TXEmptyRegister >> 7; //We want bit 7
}
BusDataType bus_char = print_string[i]; //Send char to uart, The TX data should be in bit 0-7 and should use volitile
*TXDataRegister = bus_char;
}
#endif
}
void PrintForTCLTerm( char* print_string )
{
//Typedefs used to access the bus
typedef volatile char* DataIOType;
typedef volatile char BusDataType;
//Define the address for putting data on the bus
DataIOType bus_data_address = (DataIOType)DEVICE_1_OFFSET_ADDRESS;
//Get the size of the string.
UnSignedLong chars_to_print = strlen( print_string );
//Loop over the string and put chars on the bus to be grabbed by the term
for (UnSignedLong i=0; i< chars_to_print; i++ )
{
BusDataType bus_char = print_string[i]; //Set the data to a volitile
*bus_data_address = bus_char; //Send char to bus using the volitile
}
}
void PrintStringStdioAll( char* string_buffer )
{
//Print to all the outputs
PrintUART( string_buffer );
printf("%s",string_buffer );
PrintForTCLTerm( string_buffer );
}
void PrintStringStdioLFAll( char* string_buffer )
{
PrintUART( "\n\r" );
PrintUART( string_buffer );
printf("\n%s",string_buffer );
PrintForTCLTerm( "\n" );
PrintForTCLTerm( string_buffer );
}
void CMessageIO::PrintStringStdio( char* string_buffer )
{
PrintStringStdioAll( string_buffer );
}
void CMessageIO::PrintStringStdioLF( char* string_buffer )
{
PrintStringStdioLFAll( string_buffer );
}