Project

General

Profile

Download (10.5 KB) Statistics
| Branch: | Tag: | Revision:
1 c46bad77 Christian Daniel
/**************************************************************
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
#if 0
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
unsigned char readPort()
50
{
51
	uint32_t value;
52
53
	sam3uRead32(g_ispFd, 0x400e0e00 + 0x3c, &value);
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 char a_ucPins, unsigned char 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
		sam3uWrite32(g_ispFd, 0x400e0e00 + 0x30, value);
103
	else sam3uWrite32(g_ispFd, 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
#endif
170
171
void writePort( unsigned char a_ucPins, unsigned char a_ucValue )
172
{
173
}
174
175
/* the unit of a_uiDelay is milliseconds */
176
void ispVMDelay( unsigned int a_uiDelay )
177
{	
178
	//printf("sleep %d\n", a_uiDelay);
179
	//usleep(a_uiDelay * 1000);
180
}
181
182
/*************************************************************
183
*                                                            *
184
* ENABLEHARDWARE                                             *
185
*                                                            *
186
* INPUT:                                                     *
187
*     None.                                                  *
188
*                                                            *
189
* RETURN:                                                    *
190
*     None.                                                  *
191
*                                                            *
192
* DESCRIPTION:                                               *
193
*     This function is called to enable the hardware.        *
194
*                                                            *
195
*     NOTE: This function should be modified in an embedded  *
196
*     system!                                                *
197
*                                                            *
198
*************************************************************/
199
200
void EnableHardware()
201
{
202
	ispVMStateMachine(RESET);
203
}
204
205
/*************************************************************
206
*                                                            *
207
* DISABLEHARDWARE                                            *
208
*                                                            *
209
* INPUT:                                                     *
210
*     None.                                                  *
211
*                                                            *
212
* RETURN:                                                    *
213
*     None.                                                  *
214
*                                                            *
215
* DESCRIPTION:                                               *
216
*     This function is called to disable the hardware.       *
217
*                                                            *
218
*     NOTE: This function should be modified in an embedded  *
219
*     system!                                                *
220
*                                                            *
221
*************************************************************/
222
223
void DisableHardware()
224
{
225
	ispVMStateMachine(RESET);
226
}
Add picture from clipboard (Maximum size: 48.8 MB)