Project

General

Profile

Download (10.4 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
#include "../sam3u.h"
22

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

    
29
extern void ispVMStateMachine( char a_cNextState );
30

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

    
50
unsigned char readPort()
51
{
52
	uint32_t value;
53

    
54
	sam3uRead32(g_ispFd, 0x400e0e00 + 0x3c, &value);
55

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

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

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

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

    
102
	if(a_ucValue)
103
		sam3uWrite32(g_ispFd, 0x400e0e00 + 0x30, value);
104
	else sam3uWrite32(g_ispFd, 0x400e0e00 + 0x34, value);
105
}
106

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

    
170
/* the unit of a_uiDelay is milliseconds */
171
void ispVMDelay( unsigned int a_uiDelay )
172
{	
173
	//printf("sleep %d\n", a_uiDelay);
174
	//usleep(a_uiDelay * 1000);
175
}
176

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

    
195
void EnableHardware()
196
{
197
	ispVMStateMachine(RESET);
198
}
199

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

    
218
void DisableHardware()
219
{
220
	ispVMStateMachine(RESET);
221
}
222

    
223

    
(1-1/5)
Add picture from clipboard (Maximum size: 48.8 MB)