Project

General

Profile

Download (10.5 KB) Statistics
| Branch: | Tag: | Revision:
1
/**************************************************************
2
*
3
* Lattice Semiconductor Corp. Copyright 2008
4
* 
5
*
6
***************************************************************/
7

    
8

    
9
/**************************************************************
10
* 
11
* Revision History of hardware.c
12
* 
13
* 
14
* 09/11/07 NN type cast all the mismatch variables
15
***************************************************************/
16

    
17
#include <stdio.h>
18
#include <unistd.h>
19
#include "opcode.h"
20
#include "hardware.h"
21

    
22
/*************************************************************
23
*                                                            *
24
* EXTERNAL FUNCTION                                          *
25
*                                                            *
26
*************************************************************/
27

    
28
extern void ispVMStateMachine( char a_cNextState );
29

    
30
/*************************************************************
31
*                                                            *
32
* READPORT                                                   *
33
*                                                            *
34
* INPUT:                                                     *
35
*     None.                                                  *
36
*                                                            *
37
* RETURN:                                                    *
38
*     Returns the bit read back from the device.             *
39
*                                                            *
40
* DESCRIPTION:                                               *
41
*     This function is used to read the TDO pin from the     *
42
*     input port.                                            *
43
*                                                            *
44
*     NOTE: This function should be modified in an embedded  *
45
*     system!                                                *
46
*                                                            *
47
*************************************************************/
48

    
49
int readPort()
50
{
51
	uint32_t value;
52

    
53
	value = *((volatile uint32_t*)(0x400e0e00 + 0x3c));
54

    
55
	if(value & (1 << 6))
56
		return 1;
57
	else return 0;
58
} 
59

    
60
/*************************************************************
61
*                                                            *
62
* WRITEPORT                                                  *
63
*                                                            *
64
* INPUT:                                                     *
65
*     a_ucPins: a byte to indicate which pin will be         *
66
*     depending on the value.                                *
67
*                                                            *
68
*     a_ucValue: the value to determine of the pin above     *
69
*     will be written out or not.                            *
70
*                                                            *
71
* RETURN:                                                    *
72
*     None.                                                  *
73
*                                                            *
74
* DESCRIPTION:                                               *
75
*     To apply the specified value to the pins indicated.    *
76
*     This routine will likely be modified for specific      *
77
*     systems. As an example, this code is for the PC, as    *
78
*     described below.                                       *
79
*                                                            *
80
*     This routine uses the IBM-PC standard Parallel port,   *
81
*     along with the schematic shown in Lattice              *
82
*     documentation, to apply the signals to the programming *
83
*     loop.                                                  *
84
*                                                            *
85
*     NOTE: This function should be modified in an embedded  *
86
*     system!                                                *
87
*                                                            *
88
*************************************************************/
89

    
90
void writePort( unsigned int a_ucPins, unsigned int a_ucValue )
91
{
92
	uint32_t value = 0;
93

    
94
	if(a_ucPins & pinTDI)
95
		value |= (1 << 8);
96
	if(a_ucPins & pinTCK)
97
		value |= (1 << 7);
98
	if(a_ucPins & pinTMS)
99
		value |= (1 << 5);
100

    
101
	if(a_ucValue)
102
		*((volatile uint32_t*)(0x400e0e00 + 0x30)) = value;
103
	else *((volatile uint32_t*)(0x400e0e00 + 0x34)) = value;
104
}
105

    
106
/*************************************************************
107
*                                                            *
108
* ISPVMDELAY                                                 *
109
*                                                            *
110
* INPUT:                                                     *
111
*     a_uiDelay: delay in milliseconds                       *
112
*                                                            *
113
* RETURN:                                                    *
114
*     None.                                                  *
115
*                                                            *
116
* DESCRIPTION:                                               *
117
* The user must implement a delay to observe a_uiDelay,	     *
118
* where a_uiDelay is the number of milliseconds that must    *
119
* pass before data is read from in_port.  Since platforms and*
120
* processor speeds vary greatly, this task is left to the    *
121
* user. This subroutine is called upon to provide a delay    *
122
* from 1 millisecond to a few hundreds milliseconds each time*
123
* That is the reason behind using unsigned long integer in   *
124
* this subroutine. It is OK to provide longer delay than     *
125
* required. It is not acceptable if the delay is shorter than*
126
* required.                                                  *
127
*                                                            *
128
* Note: user must re - implement to target specific hardware.*
129
*                                                            *
130
* Example: Use the for loop to create the microsecond delay. *
131
*          Loop 1K times to produce the milliseconds delay.  *
132
*                                                            *
133
*          Let the CPU clock (system clock) be F Mhz.        *
134
*                                                            *
135
*          Let the for loop represented by the 2 lines of    *
136
*          machine code:                                     *
137
*                    LOOP:  DEC RA;                          *
138
*                           JNZ LOOP;                        *
139
*          Let the for loop number for one microsecond be L. *
140
*          Lets assume 4 system clocks for each line of      *
141
*          machine code.                                     *
142
*          Then 1 us = 1/F (microseconds per clock)          *
143
*                       x (2 lines) x (4 clocks per line) x L*
144
*                     = 8L/F                                 *
145
*          Or L = F/8;                                       *
146
*                                                            *
147
*          Convert the unit in microseconds to               *
148
*          milliseconds.                                     *
149
*          L = F/8 x 1000;                                   *
150
*          Lets assume the CPU clock is set to 48MHZ. The C  *
151
*          code then is:                                     *
152
*                                                            *
153
*          unsigned int F = 48;   //MHZ.                     * 
154
*          unsigned int L = F/8;  //microseconds.            *          
155
*          unsigned int index, m;                            *
156
*                                                            *
157
*                                                            *
158
*          if (L < 1) L = 1;   //minimum is i microsecond.   *              
159
*          for (index=0; index < a_uiDelay * L; index++)     *
160
*              {                                             *
161
*   //loop 1K times to produce milliseconds delay            *
162
*                for (m=0; m<1000; m++); //milliseconds      *
163
*              }                                             *
164
*          return 0;                                         *
165
*                                                            *
166
*                                                            *
167
*************************************************************/
168

    
169
/* the unit of a_uiDelay is milliseconds */
170
void ispVMDelay( unsigned int a_uiDelay )
171
{	
172
	// yes, this is more or less calibrated - cd
173
	volatile int i, j;
174
	for(i = 0; i < a_uiDelay; i++) {
175
		for(j = 0; j < 5000; j++)
176
			asm("nop");
177
	}
178
}
179

    
180
/*************************************************************
181
*                                                            *
182
* ENABLEHARDWARE                                             *
183
*                                                            *
184
* INPUT:                                                     *
185
*     None.                                                  *
186
*                                                            *
187
* RETURN:                                                    *
188
*     None.                                                  *
189
*                                                            *
190
* DESCRIPTION:                                               *
191
*     This function is called to enable the hardware.        *
192
*                                                            *
193
*     NOTE: This function should be modified in an embedded  *
194
*     system!                                                *
195
*                                                            *
196
*************************************************************/
197

    
198
void EnableHardware()
199
{
200
	ispVMStateMachine(RESET);
201
}
202

    
203
/*************************************************************
204
*                                                            *
205
* DISABLEHARDWARE                                            *
206
*                                                            *
207
* INPUT:                                                     *
208
*     None.                                                  *
209
*                                                            *
210
* RETURN:                                                    *
211
*     None.                                                  *
212
*                                                            *
213
* DESCRIPTION:                                               *
214
*     This function is called to disable the hardware.       *
215
*                                                            *
216
*     NOTE: This function should be modified in an embedded  *
217
*     system!                                                *
218
*                                                            *
219
*************************************************************/
220

    
221
void DisableHardware()
222
{
223
	ispVMStateMachine(RESET);
224
}
225

    
226

    
(4-4/11)
Add picture from clipboard (Maximum size: 48.8 MB)