Zilog CompactFlesh Interface for eZ80Acclaim
Zilog CompactFlesh Interface for eZ80Acclaim
CompactFlash® Interface
for eZ80Acclaim!™
MCUs
AN015401-1103
This publication is subject to replacement by a later edition. To determine whether a later edition
exists, or to request copies of publications, contact:
ZiLOG is a registered trademark of ZiLOG Inc. in the United States and in other countries.
CompactFlash is a registered trademark of Sandisk Corp. All other products and/or service names
mentioned herein may be trademarks of the companies with which they are associated.
Information Integrity
The information contained within this document has been verified according to the general
principles of electrical and mechanical engineering. Any applicable source code illustrated in the
document was either written by an authorized ZiLOG employee or licensed consultant. Permission
to use these codes in any form, besides the intended application, must be approved through a
license agreement between both parties. ZiLOG will not be responsible for any code(s) used
beyond the intended application. Contact the local ZiLOG Sales Office to obtain necessary license
agreements.
Document Disclaimer
©2003 by ZiLOG, Inc. All rights reserved. Information in this publication concerning the devices,
applications, or technology described is intended to suggest possible uses and may be
superseded. ZiLOG, INC. DOES NOT ASSUME LIABILITY FOR OR PROVIDE A
REPRESENTATION OF ACCURACY OF THE INFORMATION, DEVICES, OR TECHNOLOGY
DESCRIBED IN THIS DOCUMENT. ZiLOG ALSO DOES NOT ASSUME LIABILITY FOR
INTELLECTUAL PROPERTY INFRINGEMENT RELATED IN ANY MANNER TO USE OF
INFORMATION, DEVICES, OR TECHNOLOGY DESCRIBED HEREIN OR OTHERWISE. Except
with the express written approval ZiLOG, use of information, devices, or technology as critical
components of life support systems is not authorized. No licenses or other rights are conveyed,
implicitly or otherwise, by this document under any intellectual property rights.
AN015401-1103
Application Note
CompactFlash® Interface for eZ80Acclaim!™ MCUs
iii
Table of Contents
List of Figures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . iv
List of Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .v
Abstract . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
eZ80Acclaim!™ Flash MCU Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
CompactFlash® Storage Card . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Modes of Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Developing the CompactFlash® Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Hardware Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Software Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Equipment Used . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Test Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Test Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Appendix A—References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Appendix B—Flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Appendix C—Schematic Diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Appendix D—Source Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
C Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Assembly File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Header Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Appendix E—API Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
iv
List of Figures
Figure 1. Structure of a CompactFlash Storage Card . . . . . . . . . . . . . . . . . . . 2
Figure 2. System Connections for the CompactFlash Interface with an
eZ80Acclaim! MCU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Figure 3. Flowchart for CompactFlash APIs . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Figure 4. Schematic for Connections between Development Board and
Expansion Board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Figure 5. Schematic for Interface Logic on the CompactFlash Expansion
Board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Figure 6. Schematic for CompactFlash Connector . . . . . . . . . . . . . . . . . . . . . 17
List of Tables
Table 1. eZ80F91 Address Bits and CompactFlash Pins - Connection Details 5
Table 2. Demultiplexer Logic Truth Table. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Table 3. Port B GPIO Interface to CompactFlash Control Signals . . . . . . . . . . 7
Table 4. Derived Addresses for the CompactFlash Registers . . . . . . . . . . . . . 7
Table 5. List of References. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Table 6. CompactFlash Interface APIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Abstract
This Application Note illustrates an interface between an eZ80Acclaim!™ MCU
and a CompactFlash® Storage Card. The CompactFlash card is accessed in the
following modes of operation: the memory mode, the contiguous I/O mode, the
primary I/O mode, and the secondary I/O mode.
The AN0154-SC01.zip file contains the source code associated with this Applica-
tion Note and is available on the ZiLOG website.
Discussion
The CompactFlash interface is a vendor-independent specification that can be
implemented to develop CompactFlash products that are compatible with a wide
range of user applications and across a gamut of manufacturers.
The early CompactFlash cards were meant exclusively for Flash data storage;
however, currently under the CF+ specification, they support various I/O devices,
such as Ethernet cards and fax/modem cards, to name a few.
AN015401-1103 Abstract
Application Note
CompactFlash® Interface for eZ80Acclaim!™ MCUs
holds the command parameters and the command. It is essential to write the com-
mand parameters before the command because the controller executes the com-
mand according to the parameters present in other registers.
Similarly, when a host reads to the command/status tuple, the tuple behaves as a
set of registers that holds the status information about the last executed com-
mand. The start address of the command/status tuple is 0x000.The first register
at address 0x000 is for the data register, which does not contribute to the actual
command/status information.
Storage Memory. Storage memory is a large area of Flash memory. Access to this
space is handled by the controller in a manner that is transparent to the host. The
address space requirement for interfacing a CompactFlash Storage Card is just
2 KB, irrespective of the storage capacity of the card.
Note: The addresses of attribute memory, control/status, and data registers lie
within the 2 KB space.
Modes of Operation
The CompactFlash operates in several modes. Two of these modes are relevant
to this Application Note and are briefly discussed in this section.
Memory Mode. This mode is the default mode of operation for the CompactFlash.
The CompactFlash card enters this mode at Power On or RESET, if the OE pin is
held at a logic HIGH (1).
I/O Mode(s). There are three distinct I/O modes: the primary I/O mode, the sec-
ondary I/O mode, and the contiguous I/O mode. To enter into any of the I/O
modes, it is necessary to enter into the memory mode first and then modify the
card configuration register (in the attribute memory space) accordingly.
Hardware Architecture
The CompactFlash Storage Card consists of pins that operate according to the
mode in which the card is operated, resulting in different interfaces for different
modes. The architecture suggested in Figure 2 considers a superset of these
requirements to illustrate all the three modes with the same hardware setup. The
block diagram in Figure 2 is the basis for the schematics in the Appendix C on
page 15.
D[0:7]
D[0:7]
CS3
CE1
CE2
A[11:14]
OE
WE
PB7 IORD
PB6 IOWR
PB5
PB4
WAIT
PB3
PB2
RDY/BSY
PB1
PB0
CD1
CD2
Figure 2. System Connections for the CompactFlash Interface with an eZ80Acclaim! MCU
Common Requirements
At the outset, it is necessary to determine that a card is present in the slot for
operation. Two signals are located at the two extremes of the CompactFlash con-
nector to facilitate card detection (-CD1, -CD2) and correct insertion. These sig-
nals are pulled low inside the card. An OR-gate (74LVC32AD) combines these
card detect signals to derive one signal that is connected to the Port B pin0 (PB0)
of the eZ80F91 MCU. PB0 is polled by the software to determine if the Compact-
Flash card is present.
The eZ80F91 data bus is byte wide, therefore the D[0:7] data bus is connected to
the corresponding data lines/pins of the CompactFlash. The CompactFlash HIGH
data bus, D[8:15], is not connected.
The 8 most significant bits, A[16:23], decide the chip select, providing the pro-
grammer flexibility to map the 2 KB address space anywhere within the 16 MB
area supported by the eZ80F91 device. For this CompactFlash Interface applica-
tion, the A[16:23] byte is assigned the value of 0xA8.
Finally, as per the CompactFlash specification, 10 K W resistors are used to pull up
each of the following signals to VDD:
• READY
• INPACK
• WAIT
• WP
• VS1
• VS2
• BVD1
• BVD2
Varied Requirements
Some of the control signals in the CompactFlash card are used for multiple pur-
poses while some of the signals differ for different modes. All of these signals
require additional hardware and pins from the CompactFlash host.
As described in the Modes of Operation section on page 3, the change from mem-
ory mode to any of the I/O modes is achieved through the software. However,
such a mode change also requires a change in hardware. In the memory mode,
the RD and WR strobes from the host are connected to the OE and WE signals of
the CompactFlash card. In the I/O modes, the host signals are connected to IORD
and IOWR signals of the CompactFlash card.
The switching functionality is achieved through the use of a de-mux (de-multi-
plexer). The chip select (as decided by the A[16:23]) and PB7 pin control the
action of the de-mux. When the chip select is asserted, the PB7 pin is HIGH for
the memory mode, and LOW for other modes of CompactFlash operation.
For all modes other than the memory mode, the de-mux routes RD and WR sig-
nals from the eZ80F91 to IORD and IOWR, respectively. For the memory mode,
the de-mux routes the WR signal directly to the CompactFlash WE signal. The RD
signal, however, is not directly connected to the OE pin because the OE pin also
handles the other functionality, such as determining if the CompactFlash card
resets into the memory mode or the TrueIDE mode at RESET. The RD signal is
therefore routed out of the de-mux and is referred to as MEM_MODE.
The memory mode is the default mode of operation. If the OE signal is not
grounded, this default mode of operation is functional at power ON or RESET.
However, if the OE pin is grounded, the CompactFlash card enters the True IDE
mode on RESET. Thus, the hardware must be able to perform the following oper-
ations.
To RESET the CompactFlash Storage Card at Run-time. To achieve this functional-
ity, the eZ80F91 port pin, PB4, is connected directly to the CompactFlash RESET
pin. By toggling PB4, the CompactFlash card can be RESET at any point of time.
To Control the OE pin at RESET. To achieve this functionality, the eZ80F91 port
pin, PB6, and the MEM_MODE signal issuing out of the de-multiplexer are AND-
ed, using the AND gate (74LVC08AD), to control the OE pin. The AND operation
forces a 0 (LOW) on the OE that is held at 1 (HIGH) when there are no RD trans-
actions on the CompactFlash.
Thus, a mode conversion can be achieved by forcing a 0 on PB6 and toggling the
PB4 for a RESET.
The port B GPIO lines used to interface the CompactFlash control signals are
summarized in Table 3.
Note: x : Indicates "don't care" condition. All 'x' are replaced by zeros
h : Indicates the preceding value to be a hexadecimal
Note: x : Indicates "don't care" condition. All 'x' are replaced by zeros
h : Indicates the preceding value to be a hexadecimal
Software Implementation
The CompactFlash Interface software is implemented as a set of API functions to
perform the following operations:
• Initialize and set the CompactFlash mode
• Write to a CompactFlash sector
• Identify the CompactFlash drive
• Set features for the CompactFlash card in terms of mode specifications
• Read from a CompactFlash sector
• Erase a CompactFlash sector
Refer to Appendix E on page 54 for details on the API functions. In addition to the
API functions, several supporting functions are implemented that may be useful
while using the CompactFlash card. These include –
• Software block data transfer (DMA operation)
• Delay generation (for various CompactFlash-specified delays)
• Card detection/Error checking
• Function to receive the sector, head and cylinder information
As discussed in the Command/Status Tuple section on page 2, the CompactFlash
interface works with the command tuple. The registers in the tuple are addressed
in a sequential manner. Therefore, it is sufficient to determine the address of the
first register in a specified mode. These addresses are hardware- and mode-
dependent and are hard-coded in the software for every mode.
The CompactFlash operating modes supported by the current CompactFlash
Interface application are the Memory mode and the I/O modes (contiguous/pri-
mary/secondary). When the user selects a particular mode of operation, the
addresses, being mode-dependent, are loaded into the appropriate pointer and
the user is prompted for an operation to be performed on the CompactFlash.
When the command to perform an operation is received, the corresponding regis-
ters in the tuple are loaded with the required command parameters. This is fol-
lowed by a block transfer of data to/from the CompactFlash.
Two buffers, of 512 bytes each, are implemented in the CompactFlash Interface
software to transmit and receive data to/from the CompactFlash.
While switching to the I/O mode, the RD and WR signals from the eZ80F91 must
be connected to the IORD and IOWR signals of the CompactFlash card.
To revert to the memory mode, a 0x00 is written to the configuration register.
10
The algorithm for the read_sector() API, which is the sequence of events for
reading from a sector, is outlined below.
1. Select the CompactFlash mode
2. Load the pointers for command/status tuple, and read buffers
3. Get the sector, cylinder, and head from where reading must begin on the
CompactFlash card
4. Load values from 5 to the appropriate command registers in the command
tuple
5. Load the read command in the command register
6. Wait for the CompactFlash card to be ready
7. Read 512 bytes from the CompactFlash data register
8. Indicate success/error
The algorithm for the write_sector() API, which is the sequence of events for
writing to a sector, is outlined below.
1. Select the CompactFlash mode
2. Load the pointers for command/status tuple, and write buffers
3. Get the data in the write buffer
4. Get the sector, cylinder, and head from where writing must begin on the
CompactFlash card
5. Load values from 5 to the appropriate command registers in the command
tuple
6. Load the write command in the command register
7. Wait for the CompactFlash card to be ready
8. Write 512 bytes from the CompactFlash data register
9. Indicate success/error
Testing
This section describes the setup, requirements, and the procedure followed to
demonstrate the CompactFlash Interface application using the eZ80F91 MCU.
Setup
The CompactFlash Storage Card is mounted on the CompactFlash Expansion
Board connectors of the eZ80F91 Development Kit (connectors J6 and J8). The
AN015401-1103 Testing
Application Note
CompactFlash® Interface for eZ80Acclaim!™ MCUs
11
Equipment Used
• eZ80F91 Development Kit (eZ80F910200ZC0)
• CompactFlash Interface Expansion Board (developed indigenously)
• ZDSII-IDE for eZ80Acclaim! MCUs, v4.6.0
• CompactFlash Storage Card from Kingston technology with 64 MB memory
• PC with HyperTerminal; HyperTerminal is configured for 9600bps, 8 bit, no-
parity, 1 Stop bit, and No flow control.
Test Procedure
The procedure to demonstrate the CompactFlash Interface application is outlined
below.
1. The connections between the Development Board, the CompactFlash
Expansion Board, and the CompactFlash Connector are made according to
the schematics (Refer to Appendix C on page 15).
2. The CompactFlash Storage Card is fitted into the CompactFlash Connector.
3. The PC is connected to the eZ80 Development Board through ZPAKII.
4. Launch the ZDSII-IDE, build the program using the application code
(AN0154-SC01.zip file), and download the resulting .hex file to the
eZ80F91 on-chip Flash.
5. Launch the HyperTerminal. The command menu appears below the CF>>
prompt.
6. Enter m to select the mode. From the sub-menu, enter the appropriate
character for the required mode. The mode is selected and the command
menu appears again.
7. Enter i to identify the CompactFlash Storage Card. This operation tests the
identify_drive() API, which reads the CompactFlash parameters and
compares them with the CompactFlash datasheet.
8. At the CF>> prompt, enter w to write to a CompactFlash sector. This
operation tests the write_sector() API. The write sub-menu appears.
9. Enter values for Track, Head, and Sector within the prompted range.
12
Test Results
The CompactFlash card was identified with the identify_drive() API. The for-
mat of the information received was found to be in agreement with CompactFlash
specification. Data transfer to and from the CompactFlash card was performed
and found to be error free.
Summary
This Application Note illustrates an interface between an eZ80Acclaim! MCU and
the CompactFlash Storage Card. It provides a designer with the basic building
block to develop a slew of applications using the eZ80Acclaim! as a webserver.
The user can benefit from all the advantages that the CompactFlash technology
offers, namely a power efficient and flexible way of storing digital data such as
web-pages, audio/video files, or simple log data.
13
Appendix A—References
Further information regarding eZ80Acclaim! Flash Microcontrollers, and the Com-
pactFlash can be found in the references listed in Table 5.
14
Appendix B—Flowchart
The flowchart for CompactFlash Interface APIs is illustrated in Figure 3.
API START
Load the specific command parameters in to the command Tuple Registers 1-6
API RETURN
15
J1
GND
GND FROM PG 1 OF 3
1
TO PG 2 OF 3 -CD1
26
D3 J8-46
2
27
3
D4 J8-47
28
4 J8-48 A14
29 D5 A13
5 J8-49 A12
30 D6 A11
6
D7 J8-50
31
7 A12 J8-17 PB4
A13 -CE1/-CE 1/ -CS 0 PB3
J8-18 -CE2/-CE2/-CS1
32
PB2
A10 J8-15
8
FROM PG 2 OF 3 -VS1 33 PB1
-O E/ -O E/-A TA _S EL FROM PG 2 OF 3
9
FROM PG 2 OF 3 34 VDD
-IORD VDD GND
A09 J8-14
10
FROM PG 2 OF 3 35 GND
-IOWR
A08 J8-13
11
FROM PG 2 OF 3 -WE
36
A07 J8-10
12
J6-52 PB1 37
RDY-BSY/IREQ/INT RQ VDD
VDD FROM PG 1 OF 3
13
VDD 38
FROM PG 1 OF 3 VDD
A06 J8-9
14 VDD
A14 39
J8-19 -CSEL
A05 J8-8
15
40 VDD
FROM PG 2 OF 3 -VS2
A04 J8-7
16
J6-46 PB4 41
RESET /RESET /-RESET
A03 J8-6
17 C13 C14 C15
J6-13 -WAIT /-WAIT /IORDY
42
A02 J8-5
18 10uF 0.1uF 0.1uF
-INPACK 43
GND
A01 J8-4
19
J8-16 A11 44
-REG
A00 J8-3
20
J6-50 PB2 45
BVD2/-SPKR/-DASP
D0 J8-43
21
J6-48 PB3 46
BVD1/-ST SCHG/-PDIAG 22 J8-44
47 D1
23
D2 J8-45
48
24
49 WP/-IOIS16/-IOIS16
25
-CD2 TO PG 2 OF 3
FROM PG 1 OF 3 GND 50
GND
Title
CompactFlash Interface for eZ80Acclaim! MCU
Size Document Number: AN0154 Rev
A
Date: THURSDAY JULY 24, 2003 Sheet 3 OF 3
Figure 4. Schematic for Connections between Development Board and Expansion Board
16
Figure 5 is the schematic diagram for the Interface Logic on the CompactFlash Expansion Board.
J8
VDD 1 2 GND J6
A0 0 3 4 A0 1 J1-19 VDD 1 2
J1-20
A0 2 5 6 A0 3 J1-17 3 4
VDD VDD
VDD
VDD
Title
COMPACT FLASH INTERFACE FOR eZ80Acclaim! MCUs
Size Doc ument Numbe r: AN0154 Rev
A
Date:Thursday July 24, ,2003 Sheet: 1 of 3
17
CF Spec requirements
PB7 = 1 is for Memory m ode.
Interface Logic PB7 = 0 is for IO mode.
VDD
VDD VCC 74LVC139/SO
GND VDD
GND J8-34 - WR 1 7
-WR EN Y3 6
THE I C FOOTPRI NT CONNEC TS J8-56 - CSX 3 Y2 5 - WE J1-36
-CSX PB7 2 A1 Y1 4 - IOWR -WE
R1 R2 R3 R4 R5 R6 R7 R8 TO VC C AND NOT VDD. J6-40 PB7 A0 Y0 -IOWR J1-35
U4A
10K
10K
10K
10K
10K
10K
10K
10K
74LVC139/SO
J8-33 -RD
- RD 15 9
EN Y3 10
PB3 J6-48 J8-56 - CSX 13 Y2 11 - MEM_MODE
BVD1/-STSCHG/-PDIAG J6-40 PB7 14 A1 Y1 12 - IOR D J1-34
PB2 A0 Y0 -IORD
BVD2/-SPKR/-DASP J6-50
J1-33 U4B SOJ.0 50/16/WB. 300/L.425
-VS1
-VS2 J1-40
U2A
PB1 J6-52 74LVC08/SO
RDY-BSY/IREQ/INTRQ
J1-43 - MEM_MODE 1
-INPACK 3
MWAIT PB6 2 -OE/-OE/-ATA_SEL
-WAIT/-WAIT /IORDY J6-13 J6-42 PB6
WP/-IOIS16/-IOIS16 J1-24 VDD J1-9
C1 C2 C3 C4 C5 C6
0.1uF 0.1uF 0.1uF 0.1uF 0.1uF 0.1uF
LED LED LED LED
D1 D2 D3 D4
Success Power
PB5
J6-44
PB1 Title
PB1
COMPACT FLASH INTERFACE FOR eZ80Acclaim! MCUs
Activity - Memory modeJ6-52
PB0 Size Doc ume ntN umbe r: AN0154 Rev
A
Card Present J6-54
Date : Thursday July 24, 2003 Sh eet: 2 of 3
18
C Files
The following C files are listed in this section:
• CF-interface.c
• Z_FNC_CF.c
• Z_API_CF.c
• Z_CF_SUPPORT.c
• UserIf.c
• utility.c
/*
*********************************************************
* File : CF-interface.c
* Description : Contains main() function.
*
* Copyright 2003 ZiLOG Inc. ALL RIGHTS RESERVED.
*
* The source code in this file was written by an
* authorized ZiLOG employee or a licensed consultant.
* The source code has been verified to the fullest
* extent possible.
*
* Permission to use this code is granted on a royalty-free
* basis. However users are cautioned to authenticate the
* code contained herein.
*
* ZiLOG DOES NOT GUARANTEE THE VERACITY OF THE SOFTWARE.
***********************************************************
*/
include <ez80F91.h>
#include <stdio.h>
#include <sio.h>
#include "UserIF.h"
#include "Z_API_CF.h"
19
main()
{
char command, result;
welcome();
display_mode(current_mode); // Displays current mode of CF
// operation
while(1)
{
display_menu(); // Displays all the options
// or commands supported
display_prompt(); // Prompts user to enter
// a command
switch (command)
{
case 'm' : fn_mode_select(); // Function Mode selection
break;
case 'i' : fn_identify_drive(); // Function Identify Drive
break;
case 's' : fn_
20
/*
*********************************************************
* File : Z_FNC_CF.c
* Description :
*
* Copyright 2003 ZiLOG Inc. ALL RIGHTS RESERVED.
*
* The source code in this file was written by an
* authorized ZiLOG employee or a licensed consultant.
* The source code has been verified to the fullest
* extent possible.
*
* Permission to use this code is granted on a royalty-free
* basis. However users are cautioned to authenticate the
* code contained herein.
*
* ZiLOG DOES NOT GUARANTEE THE VERACITY OF THE SOFTWARE.
***********************************************************
*/
#include <stdio.h>
#include "Z_API_CF.h"
#include "UserIF.h"
#include "utility.h"
21
/* ********************************
** Main Functions are listed here
*********************************** */
void fn_mode_select(void)
{
char mode, result;
if (result == SUCCESS)
{
display_mode(current_mode); // Reflect the new
// current_mode
}
else
{
proc_result(result); // Find and display
// appropriate Error
}
22
// *********************************************************
void fn_identify_drive(void)
{
char result;
result = identify_drive();
if (result == SUCCESS)
{
// -------------------------------------------------------------
// Parse the read Buffer for useful information
// Note: Only some information is extracted as an illustration
// --------------------------------------------------------------
s_temp = POINTER_FOR_SHORT;
// -----------------------------------
// Display the information extracted
23
// *********************************************************
void fn_set_features(void)
{
// -------------
// Settings required are -
// 8-bit data transfers: Enable / Disable
// Power Level 1 commands: Enable / Disable
// POR defaults with soft reset: Enable / Disable
// --------------
// Since most of the features are default and can NOT be altered
// for the present hardware, we will skip this API for time being.
//
char result;
result = set_features();
if (result == SUCCESS)
{
printf("\n *** 8-bit data, Drive# = 0. \n");
}
else
{
24
// *********************************************************
void fn_read_sectors(void)
{
char result;
int sector, head, track;
if (result == SUCCESS)
{
display_read_buffer();
}
25
else
{
proc_result(result); // Find and display
// appropriate Error
}
}
// *********************************************************
void fn_write_sectors(void)
{
volatile char result;
int sector, head, track;
26
if (result == SUCCESS)
{
display_write_buffer();
}
else
{
// printf("\n FNC result \t %x \t %d \n",result, result);
proc_result(result); // Find and display appropriate Error
}
}
// *********************************************************
void fn_erase_sectors(void)
{
volatile char result;
int sector, head, track;
27
{
printf("\n\r Please enter the Track number (0x000-0x3d2):\t");
track = ScanHex(3); // Use HyperTerminal Echo
// in place of printing
} while (track > 0x3d2);
if (result == SUCCESS)
{
printf("\n Sector erase complete \n");
}
else
{
proc_result(result); // Find and display
// appropriate Error
}
}
/*********************************************************
***************** end of file ***************************
*********************************************************/
/*
*********************************************************
* File : Z_API_CF.c
* Description :
*
* Copyright 2003 ZiLOG Inc. ALL RIGHTS RESERVED.
*
* The source code in this file was written by an
* authorized ZiLOG employee or a licensed consultant.
* The source code has been verified to the fullest
* extent possible.
*
* Permission to use this code is granted on a royalty-free
* basis. However users are cautioned to authenticate the
* code contained herein.
*
* ZiLOG DOES NOT GUARANTEE THE VERACITY OF THE SOFTWARE.
***********************************************************
*/
28
#include <stdio.h>
#include <ez80F91.h>
#include "Z_API_CF.h"
#include "UserIF.h"
// ---------------------------------------------------
// Refer to the assembly code in data_structure_def.s
// ---------------------------------------------------
/* ********************* **
** APIs are listed here.
************************* */
char load_CF_mode(char mode)
{
//
// This API does not interact with the CF. It loads tuple pointers with
// appropriate addresses.
// Returns 1 for success, or error_code otherwise. Updates the
// current_mode global variable.
//
char result;
int i;
attr_mem = ATTRIBUTE_MEMORY;
switch(mode)
{
29
30
31
// the RESET
while ((PB_DR & 0x02) == RESET); // Wait till the CF
// completes RESET
for (i = 1; i > 20000; i++);
*(attr_mem) = 0x03; // Load Secondary IO mode
// to Attribute Memory
current_mode = *(attr_mem); // read the config register
// -OE reqd
current_mode &= 0x3F; // Get the specific in
PB_DR = 0x40; // Switch Mux output to ~IORD, ~IOWR
cmd_dest = SEC_IO_MODE_REG0; // Loading base pointer for
// the IO mode
break;
// *********************************************************
char identify_drive(void)
{
//
// This command does not take any parameters.
// After execution by the CF card, the CF buffer is read.
// Later, the information in the buffer is analyzed and results
// are displayed on HyperTerminal through a Support Function.
//
32
/*
// -------------------------------------------------------------
// The Buffer is read from CF into the SRAM
// Now we need to parse it for useful information.
// Note: Only some information is extracted as an illustration.
// --------------------------------------------------------------
s_temp = POINTER_FOR_SHORT;
33
// -----------------------------------
// Display the information extracted.
// *********************************************************
char set_features(void)
{
34
35
// *********************************************************
36
// *********************************************************
37
}
/*********************************************************
***************** end of file ***************************
*********************************************************/
/*
*********************************************************
* File : Z_CF_SUPPORT.c
* Description :
*
* Copyright 2003 ZiLOG Inc. ALL RIGHTS RESERVED.
38
*
* The source code in this file was written by an
* authorized ZiLOG employee or a licensed consultant.
* The source code has been verified to the fullest
* extent possible.
*
* Permission to use this code is granted on a royalty-free
* basis. However users are cautioned to authenticate the
* code contained herein.
*
* ZiLOG DOES NOT GUARANTEE THE VERACITY OF THE SOFTWARE.
***********************************************************
*/
#include <stdio.h>
#include "Z_API_CF.h"
#include "UserIF.h"
#include "utility.h"
#include <ez80F91.h>
char current_mode;
void init_F91(void)
{
// Initialize Port B for CF application.
PB_ALT1 = 0x00; // RESET default
PB_ALT2 = 0x00; // RESET default
PB_DDR = 0x0F; // Upper nibble as output, lower nibble as input
PB_DR = 0xE0; // This is for CF Memory mode. 0b1110----
}
void init_parameters(void)
{
// Initialize the parameters/flags required for this appnote.
current_mode = 0xFF; // current_mode is global. Initialize
// to memory mode (0)
cmd_dest = MEMORY_MODE_REG0; // Mode dependent, global
39
char check_card(void)
{
char card_detect;
do
{
wait = *(cmd_dest + 0x07); // Read status register
error = wait & 0x01;
if (error == 1) return; // Error occurred, abort wait
wait_busy = wait & 0x80; // Wait for BUSY to RESET
} while (wait_busy == 0x80);
do
{
wait = *(cmd_dest + 0x07); // Read status register
error = wait & 0x01;
if (error == 1) return; // Error occurred, abort wait.
wait_drq = wait & 0x08; // Wait for DRQ to SET
} while (wait_drq == 0x00);
if (result == NO_CARD)
printf("\n ! Card not found \n");
40
}
/*********************************************************
***************** end of file ***************************
*********************************************************/
/*
*********************************************************
* File : UserIf.c
* Description :
*
* Copyright 2003 ZiLOG Inc. ALL RIGHTS RESERVED.
*
* The source code in this file was written by an
* authorized ZiLOG employee or a licensed consultant.
* The source code has been verified to the fullest
* extent possible.
*
* Permission to use this code is granted on a royalty-free
* basis. However users are cautioned to authenticate the
* code contained herein.
*
* ZiLOG DOES NOT GUARANTEE THE VERACITY OF THE SOFTWARE.
41
***********************************************************
*/
#include <stdio.h>
#include <ez80F91.h>
#include "Z_API_CF.h"
#include "UserIF.h"
#include "utility.h"
#include "SIO.h"
// -----------------------------------
char mode_select(void);
void display_error(char);
void welcome (void);
// -----------------------------------
extern char rd_buffer[]; // From RD_WR_BUF_ADDR to +511
extern char wr_buffer[]; // From +512 to +1023
extern char cmd_tuple[]; // From +1023 to +1031
extern char sta_tuple[]; // From +1032 to +1039
// -----------------------------------
void welcome(void)
{
printf("\n \n \n-----------------------\n");
printf("Welcome to eZ80 Acclaim!\n");
printf("Compact Flash Interface\n");
printf("-----------------------\n");
}
void display_menu(void)
{
printf("%s\n", menu0); // Mode Select
printf("%s\n", menu1); // Identify Drive
printf("%s\n", menu2); // Set Features
printf("%s\n", menu3); // Read Sector
printf("%s\n", menu4); // Write Sector
printf("%s\n", menu5); // Erase sector
//printf("%s\n", menu6);
//printf("%s\n", menu7);
}
void display_prompt(void)
{
printf(prompt);
42
void display_mode_select(void)
{
printf("%s\n", mode0); // Memory mode
printf("%s\n", mode1); // Contiguous I/O mode
printf("%s\n", mode2); // Primary I/O
printf("%s\n", mode3); // Secondary I/O
//printf("%s\n", mode4); // True IDE
}
void display_read_buffer(void)
{
int j;
printf("\n\n ------- Read buffer ----------\n");
for (j = 0; j < BUF_SIZE; j++)
{
putchar(*(rd_buffer+j));
}
printf("\n ------- Read buffer ----------\n\n");
void display_write_buffer(void)
{
int j;
43
}
/*********************************************************
***************** end of file ***************************
*********************************************************/
/*
*********************************************************
* File : utility.c
* Description :
*
* Copyright 2003 ZiLOG Inc. ALL RIGHTS RESERVED.
*
* The source code in this file was written by an
* authorized ZiLOG employee or a licensed consultant.
* The source code has been verified to the fullest
* extent possible.
*
* Permission to use this code is granted on a royalty-free
* basis. However users are cautioned to authenticate the
* code contained herein.
*
* ZiLOG DOES NOT GUARANTEE THE VERACITY OF THE SOFTWARE.
***********************************************************
*/
#include "SIO.h"
#include <ez80F91.h>
44
do
{
ch=getch(); // Get pressed key from keyboard
temp1 = ascii_to_hex(ch);
} while (temp1 < 0); // Ignore invalid keypress
printhex(temp1);
if (num == 1)
{
ch = temp1 & 0x0F;
return (ch);
}
do
45
{
ch=getch();
temp2 = ascii_to_hex(ch);
} while (temp2 < 0);
printhex(temp2);
if (num == 2)
{
ch = (temp1 << 4) & 0xF0;
ch = (ch | temp2) & 0xFF; // why & ???
return (ch);
}
do
{
ch=getch();
temp3 = ascii_to_hex(ch);
} while (temp3 < 0);
printhex(temp3);
if (num == 3)
{
addr = 0x0000;
addr = (temp1 << 4) & 0x00F0;
addr = (addr | temp2);
addr = (addr << 4) & 0x0FF0;
addr = (addr | temp3) & 0x0FFF;
return (addr);
}
do
{
ch=getch();
temp4 = ascii_to_hex(ch);
} while (temp4 < 0);
printhex(temp4);
if (num == 4)
{
addr = 0x0000;
addr = (temp1 << 4) & 0x00F0;
addr = (addr | temp2);
addr = (addr << 4) & 0x0FF0;
addr = (addr | temp3);
addr = (addr << 4) & 0xFFF0;
addr = (addr | temp4) & 0xFFFF;
return (addr);
}
do
46
{
ch=getch();
temp5 = ascii_to_hex(ch);
} while (temp5 < 0);
printhex(temp5);
addr = 0x000000;
addr = (temp1 << 4) & 0x0000F0;
addr = (addr | temp2);
addr = (addr << 4) & 0x000FF0;
addr = (addr | temp3);
addr = (addr << 4) & 0x00FFF0;
addr = (addr | temp4) & 0x00FFFF;
addr = (addr << 4) & 0x0FFFF0;
addr = (addr | temp5) & 0x0FFFFF;
return (addr);
}
/*********************************************************
***************** end of file ***************************
*********************************************************/
Assembly File
The following assembly file is listed in this section:
• data_structure_def.s
/*
*********************************************************
* File : data_structure_def.s
* Description :
*
* Copyright 2003 ZiLOG Inc. ALL RIGHTS RESERVED.
*
* The source code in this file was written by an
* authorized ZiLOG employee or a licensed consultant.
* The source code has been verified to the fullest
* extent possible.
*
* Permission to use this code is granted on a royalty-free
* basis. However users are cautioned to authenticate the
* code contained herein.
*
* ZiLOG DOES NOT GUARANTEE THE VERACITY OF THE SOFTWARE.
***********************************************************
*/
47
; public__exit
; extern_main
;
; .include"ez80F91.inc"
;
RD_WR_BUF_ADDR: .equ %C30000 ; This is the starting address of the
; buffer section. These map to CS1 mapped
; RAM located on the Module board. The RAM
; is 512KBytes and we are reserving
;1040 bytes here
;*********************************************************************
;* Define global arrays for read and write data buffers.
;* Define global arrays for command/status Tuple data
;*********************************************************************
.def _blkcopy
XDEF _blkcopy
_blkcopy:
push ix
ld ix, 0
add ix, sp
ld de, (ix+6)
48
ld hl, (ix+9)
ld bc, (ix+12)
push hl
ld hl, 0
or a , a
adc hl, bc
pop hl
jr z, done_copy
ldir
ld hl,1
done_copy:
ld sp, ix
pop ix
ret
;
/*********************************************************
***************** end of assembly file *******************
*********************************************************/
Header Files
The following header files are listed in this section:
• userif.h
/*
*********************************************************
* File : userif.h
* Description : Function Prototypes
*
* Copyright 2003 ZiLOG Inc. ALL RIGHTS RESERVED.
*
* The source code in this file was written by an
* authorized ZiLOG employee or a licensed consultant.
* The source code has been verified to the fullest
* extent possible.
*
* Permission to use this code is granted on a royalty-free
* basis. However users are cautioned to authenticate the
* code contained herein.
*
49
void display_prompt(void);
void display_mode(char);
void display_menu(void);
void display_error(char);
void display_read_buffer(void);
void display_write_buffer(void);
/* *************************************
** Define various string constants here
**************************************** */
static const char menu0[] = "\n\r m.\tMode Select";
static const char menu1[] = "\n\r i.\tIdentify Drive";
static const char menu2[] = "\n\r s.\tSet Features";
static const char menu3[] = "\n\r r.\tRead Sector";
static const char menu4[] = "\n\r w.\tWrite Sector";
static const char menu5[] = "\n\r e.\tErase Sector";
// static const char menu6[] = "\n\r 6.\tDisplay Read Buffer";
// static const char menu7[] = "\n\r 7.\tDisplay Write Buffer";
// Error messages
/***************************************************************
******************* End of userif.h file *********************
***************************************************************/
50
/*
*********************************************************
* File : Z_API_CF.h
* Description : Function Prototypes
*
* Copyright 2003 ZiLOG Inc. ALL RIGHTS RESERVED.
*
* The source code in this file was written by an
* authorized ZiLOG employee or a licensed consultant.
* The source code has been verified to the fullest
* extent possible.
*
* Permission to use this code is granted on a royalty-free
* basis. However users are cautioned to authenticate the
* code contained herein.
*
* ZiLOG DOES NOT GUARANTEE THE VERACITY OF THE SOFTWARE.
***********************************************************
*/
void test_temp(void);
void fn_mode_select(void);
void fn_identify_drive(void);
void fn_set_features(void);
void fn_read_sectors(void);
void fn_write_sectors(void);
void fn_erase_sectors(void);
// API declarations
char load_CF_mode(char);
char identify_drive(void);
char read_sectors(int,int,int);
char write_sectors(int,int,int);
char erase_sectors(int,int,int);
char set_features(void);
51
void proc_result(char);
char check_card(void);
// char check_busy(void);
void wait(char *);
/* ******************************************************
Store starting address of command tuple in various modes
********************************************************* */
// -------------------------------------------
#define MEMORY_MODE_REG0(char *)0xA82800; // -REG(A-11) is one.
#define CON_IO_MODE_REG0(char *)0xA82000; // -REG(A-11) is zero
#define PRI_IO_MODE_REG0(char *)0xA821F0; // -REG(A-11) is zero
#define SEC_IO_MODE_REG0(char *)0xA82170; // -REG(A-11) is zero
/*
#define CON_IO_MODE_REG0(char *)0xA82800
#define PRI_IO_MODE_REG0(char *)0xA829F0
#define SEC_IO_MODE_REG0(char *)0xA82970
*/
// -------------------------------------------
#define IDE_MODE_REG0 (char *)0xA82800// -REG(A-11) is one. A3-A10 are
'0'
/* *********************************
* Miscellaneous information storage
********************************* */
#define BUF_SIZE 512
/* ************************************************************
Error codes are defined here.
************************************************************ */
52
/* ************************************
** Command parameters are defined here.
*************************************** */
#define DRIVE_ID 0xAA
#define SET 0x01
#define RESET 0x00
/***************************************************************
******************* End of Z_API_CF.h file *******************
***************************************************************/
/*
*********************************************************
* File : utility.h
* Description : Prototype Definitions
*
* Copyright 2003 ZiLOG Inc. ALL RIGHTS RESERVED.
*
* The source code in this file was written by an
* authorized ZiLOG employee or a licensed consultant.
* The source code has been verified to the fullest
* extent possible.
*
* Permission to use this code is granted on a royalty-free
* basis. However users are cautioned to authenticate the
* code contained herein.
*
* ZiLOG DOES NOT GUARANTEE THE VERACITY OF THE SOFTWARE.
***********************************************************
*/
/***************************************************************
53
/*
*********************************************************
* File : sio.h
* Description : Function Prototypes
*
* Copyright 2003 ZiLOG Inc. ALL RIGHTS RESERVED.
*
* The source code in this file was written by an
* authorized ZiLOG employee or a licensed consultant.
* The source code has been verified to the fullest
* extent possible.
*
* Permission to use this code is granted on a royalty-free
* basis. However users are cautioned to authenticate the
* code contained herein.
*
* ZiLOG DOES NOT GUARANTEE THE VERACITY OF THE SOFTWARE.
***********************************************************
*/
void init_UserIF(void);
char putch(char c);
int kbhit(void);
char getch(void);
/***************************************************************
******************* End of sio.h file ************************
***************************************************************/
54
In general, all of the above mentioned APIs receive relevant information from cor-
responding calling functions from the host, and load the CompactFlash command
tuple with the received parameters and command words. The APIs handle the
data transfer (when required) between the CompactFlash card and the
eZ80Acclaim! microcontroller. Finally the APIs check the error register and report
the success and failure of the operation to the calling function.
Descriptions for the CompactFlash Interface APIs begin on the next page.
55
char load_CF_mode()
char load_CF_mode(char mode)
Description
The load_CF_mode() API initializes the CompactFlash card in a specified mode
of operation. It also modifies the pointers to the command tuple.
The mode parameter takes m, c, p, or s as values to reset the CompactFlash
card to the memory mode, the contiguous I/O mode, the primary I/O mode or the
secondary I/O mode, respectively.
Parameters
Returns
0 On Success
error_codes On Failure
Usage
result = load_CF_mode(mode);
56
char identify_drive()
char identify_drive(void)
Description
The identify_drive() API reads the CompactFlash memory structure (num-
ber of heads, sectors, tracks and so on) and the manufacturer’s information from
the CompactFlash Storage Card and copies the information into the read buffer
for the host to use. The host calling function parses the read buffer and displays
the information on the HyperTerminal.
Parameters
void
Returns
0 On Success
error_codes On Failure
Usage
result = identify_drive();
57
char read_sectors()
char read_sectors(int sector,int head,int track)
Description
The read_sectors() API receives the track, head, and sector number of the
sector to be read from the host. The API then transfers the data residing in the
specified location from the CompactFlash card to the host's read buffer. On com-
pleting the operation, the API returns a success or a failure.
Parameters
Returns
0 On Success
error_code On Failure
Usage
result = read_sectors(sector,head,track);
58
char write_sectors()
char write_sectors(int sector,int head,int track)
Description
The write_sectors() API receives the track, head, and sector number of the
sector where the host requires to write the data. The API then transfers the data
from the host’s write buffer to the CompactFlash card. On completing the opera-
tion, the API returns a success or a failure.
Parameters
int sector The sector number where data is to be written on the CompactFlash card
int head The head number where data is to be written on the CompactFlash card
int track The track number where data is to be written on the CompactFlash card
Returns:
0 On Success
error_code On Failure
Usage
result = write_sectors(sector,head,track);
59
char erase_sectors()
char erase_sectors(int sector,int head,int track)
Description
The erase_sectors() API is used to erase previously written data in a specified
sector. Functionally, this API is similar to the write_sectors() API, except that
instead of the transferring data from the host buffer to the specified sector, the
erase_sector() API populates the specified sector with 0xFF.
Parameters
Returns
0 On Success
error_code On Failure
Usage
result = erase_sectors(sector,head,track);
60
char set_features()
char set_features(void)
Description
The set_features() API is used by the host to establish or select certain fea-
tures of the CompactFlash card.
Parameters
void
Returns
0 On Success
error_code On Failure
Usage
result = set_features();