How to Make eZ80 Code Execute Faster with Copy To RAM

Application Note
How to Make eZ80®
Code Execute Faster
with Copy To RAM
AN015102-0404
ZiLOG Worldwide Headquarters • 532 Race Street • San Jose, CA 95126
Telephone: 408.558.8500 • Fax: 408.558.8300 • www.ZiLOG.com
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 Worldwide Headquarters
532 Race Street
San Jose, CA 95126
Telephone: 408.558.8500
Fax: 408.558.8300
www.zilog.com
ZiLOG is a registered trademark of ZiLOG Inc. in the United States and in other countries. 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
©2004 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.
AN015102-0404
Application Note
How to Make eZ80® Code Execute Faster with Copy To RAM
iii
Table of Contents
List of Figures and Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . iii
Abstract . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
eZ80® General-Purpose Microprocessors Overview . . . . . . . . . . . . . . . . . . . . . 1
eZ80L92Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
eZ80Acclaim!™ Flash Microcontrollers Overview . . . . . . . . . . . . . . . . . . . . . . . . 2
eZ80Acclaim!™ Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Source Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
List of Figures and Tables
Figure 1. The Copy to RAM and Boot Loader Execution Flow . . . . . . . . . . . . . 4
Table 1.
AN015102-0404
How to Copy Code from Flash and Execute in RAM . . . . . . . . . . . . . 6
Table of Contents
Application Note
How to Make eZ80® Code Execute Faster with Copy To RAM
1
Abstract
This Application Note discusses how eZ80® code can execute faster by running
from RAM memory instead of Flash memory, yet still be able to store the eZ80®
code in Flash. With ZiLOG’s feature-rich ZDS II code development tools, all it
takes for speedy code execution is just a few simple changes to the project settings and the project link file. The leddemo project that is included with the
eZ80L92 device, which uses the ZDS II toolset for eZ80® microprocessors, is
used in this Application Note as an example. However, the information in this document is also applicable to the ZDS II toolset for eZ80Acclaim!™ microcontrollers.
eZ80® General-Purpose Microprocessors Overview
Just as the Z80 revolutionized the semiconductor industry, the next generation
eZ80® is revolutionizing the way communications are happening today. It executes Z80 code four times faster at the same clock speed of traditional Z80s and
can operate at frequencies up to 50MHz. Unlike most 8-bit microprocessors,
which can only address 64KB, the eZ80® can address 16MB without a Memory
Management Unit (MMU).
Designed with over 25 years of experience with the Z80, this microprocessor is
suited for embedded internet appliances, industrial control, automation, web management, modem controller, electronic games, and personal digital assistant
(PDA) applications.
Two popular versions of the eZ80® offered by ZiLOG are the eZ80® General-Purpose MPU (eZ80L92) and the eZ80Acclaim!™ Family of Flash Microcontrollers,
which includes the eZ80F91, eZ80F92, and eZ80F93 devices.
eZ80L92 Features
AN015102-0404
•
•
Single-cycle instruction fetch, high-performance, pipelined eZ80® CPU core
•
•
•
•
•
•
Two UARTs with independent baud rate generators
Low power features including SLEEP mode, HALT mode, and selective
peripheral power-down control
SPI with independent clock rate generator
I2C with independent clock rate generator
Infrared Data Association (IrDA)-compliant infrared encoder/decoder
New DMA-like eZ80® instructions for efficient block data transfer
Glueless external peripheral interface with 4 Chip Selects, individual Wait
State generators, and an external WAIT input pin—supports Intel-and
Motorola-style buses
Abstract
Application Note
How to Make eZ80® Code Execute Faster with Copy To RAM
2
•
Fixed-priority vectored interrupts (both internal and external) and interrupt
controller
•
Real-time clock with on-chip 32 KHz oscillator, selectable 50/60Hz input, and
separate VDD pin for battery backup
•
•
•
•
•
•
Six 16-bit Counter/Timers with prescalers and direct input/output drive
Watch-Dog Timer
24 bits of General-Purpose I/O
JTAG and ZDI debug interfaces
100-pin LQFP package
3.0–3.6 V supply voltage with 5 V tolerant inputs
eZ80Acclaim!™ Flash Microcontrollers Overview
eZ80Acclaim!™ on-chip Flash Microcontrollers are an exceptional value for customers designing high performance, 8-bit MCU-based systems. With speeds up
to 50MHz and an on-chip Ethernet MAC (eZ80F91 only), designers have the performance necessary to execute complex applications quickly and efficiently. Combining Flash and SRAM, eZ80Acclaim!™ devices provide the memory required to
implement communication protocol stacks and achieve flexibility when performing
in-system updates of application firmware.
The eZ80Acclaim!™ Flash MCU can operate in full 24-bit linear mode addressing
16MB without a Memory Management Unit. Additionally, support for the Z80-compatible mode allows Z80/Z180 customers to execute legacy code within multiple
64KB memory blocks with minimum modification. With an external bus supporting
eZ80®, Z80, Intel and Motorola bus modes and a rich set of serial communications peripherals, designers have several options when interfacing to external
devices.
Some of the many applications suitable for eZ80Acclaim!™ devices include vending machines, point-of-sale terminals, security systems, automation, communications, industrial control and facility monitoring, and remote control.
eZ80Acclaim!™ Features
AN015102-0404
•
•
Single-cycle instruction fetch, high-performance, pipelined eZ80® CPU core
•
256 KB Flash memory and 16 KB SRAM (8 KB user, 8 KB EMAC)
10/100 BaseT Ethernet Media Access Controller with Media-Independent
Interface (MII)
eZ80Acclaim!™ Flash Microcontrollers Overview
Application Note
How to Make eZ80® Code Execute Faster with Copy To RAM
3
•
Low power features including SLEEP mode, HALT mode, and selective
peripheral power-down control
•
•
•
•
•
Two UARTs with independent baud rate generators
•
Fixed-priority vectored interrupts (both internal and external) and interrupt
controller
•
Real-time clock with on-chip 32 KHz oscillator, selectable 50/60Hz input, and
separate VDD pin for battery backup
•
•
•
•
•
•
•
Four 16-bit Counter/Timers with prescalers and direct input/output drive
SPI with independent clock rate generator
I2C with independent clock rate generator
IrDA-compliant infrared encoder/decoder
Glueless external peripheral interface with 4 Chip Selects, individual Wait
State generators, and an external WAIT input pin—supports Z80-, Intel-, and
Motorola-style buses
Watch-Dog Timer with internal oscillator clocking option
32 bits of General-Purpose I/O
OCI™ and ZDI debug interfaces
1149.1-compliant JTAG
144-pin LQFP package
3.0–3.6 V supply voltage with 5 V tolerant inputs
Discussion
Whether working with the eZ80L92 device or one of the eZ80Acclaim!™ devices,
you arrive at a stage of development in which you have debugged your code in
RAM using the ZDS II development tool, you have experimented with it in Flash,
and have found that it does not run fast enough. What do you do now? The solution is to copy the code from Flash to RAM and execute it from this faster memory.
This Application Note shows you how to perform this task using ZDS II. The example described within this document uses the ZDS II development toolset for the
eZ80® that is contained in the eZ80L92 Development Kit.
In the ZDS II development environment, there are project settings that allow the
user to select the type of configuration that the code stores and executes. These
configurations include the Standard configuration, the All RAM configuration, the
Custom configuration, and the Copy to RAM configuration. These four configurations are all described in the ZiLOG Developer Studio II—eZ80Acclaim!™ User
AN015102-0404
Discussion
Application Note
How to Make eZ80® Code Execute Faster with Copy To RAM
4
Manual (UM0144) and in the technical article titled How Code and Data are
Placed in Memory Using ZDS II (TA0004).
The Copy to RAM configuration is described in this Application Note. The objective is to:
1.
Program Flash memory with a hex file containing your application code and
data.
2.
On startup, direct the application program to copy the remainder of the
program from Flash into RAM.
3.
Continue executing from RAM.
The end result is increased code execution speed.
The code that executes upon reset (initiated by a power-on reset or the pushbutton on the eZ80® Development Platform) is the Boot Loader. The Boot Loader is
part of the external Flash Loader utility that is packaged with the eZ80® development kits. This external Flash Loader programs Flash memory on the eZ80®
Development Platform starting at a location in Flash that the Boot Loader jumps to
after reset. The typical flow of the Copy to RAM and Boot Loader functions is illustrated in Figure 2.
RAM
Memory
Code
BSS
Data
Copy to RAM
Flash
Memory
Code execution
8200h
Code Copy
Data Copy
Start-Up
Code execution
0000h
Flash Loader
Boot Loader
Reset
Figure 2. The Copy to RAM and Boot Loader Execution Flow
AN015102-0404
Discussion
Application Note
How to Make eZ80® Code Execute Faster with Copy To RAM
5
Figure 2 shows the Start-up code, Data Copy, and Code Copy programmed into
Flash by the Flash Loader. Pushing the reset button on the eZ80® Development
Platform starts the Boot Loader. Pressing the space bar on your keyboard while
pushing the reset button causes the Boot Loader to jump to the Flash Loader utility. When the Flash Loader starts executing, it waits for data on serial port 0. Data
received on this port is programmed into Flash starting at location 08200h. Alternatively, Flash memory can be programmed using the ZDS II internal Flash
Loader, which is the tested utility described in this Application Note.
After Flash memory is programmed, push the reset button a second time without
pressing the space bar. The Boot Loader again starts execution. This time, it
jumps to location 8200h, where the start-up code resides. This start-up code performs the following sequence:
1.
Initializes the required processor registers.
2.
Copies the Data Copy section in ROM to the Data section in RAM.
3.
Creates the BSS section in RAM.
4.
Copies the Copy Code section in ROM to the Code section in RAM.
5.
Jumps to the first line of code in the code section.
Note: The start-up code is not copied. Additionally, the Code section is the main
portion of code that runs after startup.
In this Application Note, we use the eZ80L92 device to show an example of how
to use the Copy to Ram feature. The leddemozdsFlash.pro project file that is
packaged with ZDS II version ez80_4.4.2 is used to show how to change the
project such that the code can be copied from Flash to RAM and executed. This
file is found in the ZDSII_eZ80_4.4.2/samples/ez80L92_LedDemo/src directory. The ZDS II build generates a hex file that can be programmed into Flash by
either the external Flash Loader or the Flash Loader internal to ZDS II.
The leddemozdsFlash project uses the Custom configuration and a start-up module that is included in the project. The start-up module is named
l92_extFlashboot.s. Two other source files are used in the project: ledDemo.c
and ledInit.c. The project is configured to access the header files in the
include directory.
The steps in Table 2 show how to make a new project that copies the Code section from Flash and execute it from RAM. It is assumed that the reader has successfully built, downloaded, and run the leddemozdsFlash project, or at least is
familiar with the procedure.
AN015102-0404
Discussion
Application Note
How to Make eZ80® Code Execute Faster with Copy To RAM
6
Table 2. How to Copy Code from Flash and Execute in RAM
Step
Comment
1. Create a new directory and name it ramcopy.
Create ramcopy as a subdirectory within the
ez80L92_LedDemo directory, and at the same
level as src.
2. Copy the following files from the src directory to
the ramcopy directory:
• leddemozdsFlash.pro
• ledDemo.c
• ledInit.c
• l92_Flashboot.s
All of the project settings in leddemozdsFlash.pro
are also copied. The path set in the Project
Settings dialog box identifies the header files that
are referenced in the include directory.
3. Change the name of the project file leddemozds- Files are generated with the new project filename.
Flash.pro to leddemoRamCopy.pro.
4. Start ZDS II_eZ80_4.4.2.
Ensure that you use this version of ZDS II for
eZ80® or a more recent version.
5. Open the leddemoRamCopy project.
6. Click on the Linker tab in the Project Settings
dialog box. Select the General category and
change the output file name from leddemozdsFlash to leddemoRamCopy.
Output files are generated with the new filename.
7. Using ZDS II, open the l92_Flashboot.s file and
remove or comment out the following lines of
code:
• Define .invect, space = ROM, org = %0000
• Segment .invect
• jp.lil (%8200)
Removing these instructions from the start-up
code in l92_Flashboot.s removes the instructions
that cause the linker to place the jump to 08200h
instruction at location 0000h for resets. Flash
memory should already contain the Flash Loader
boot code at this location and should not be
overwritten if it is to be used.
8. In the General category of the Linker tab of the
Project Settings dialog box, click on Link Configuration and select Copy to RAM. Click OK. A
pop-up dialog is displayed, which asks if you
want to use the Standard Startup Module. Click
Yes.
This step sets the configuration to Copy to RAM.
To place the Copy to RAM linker commands into
the Link Control File, the Standard Startup
Module must also be selected. (With this warning,
ZDS II selects the Standard Startup Module for
you.)
9. Click OK in the Project Settings dialog box.
A Link Control File named leddemoRamCopy is
Another A pop-up dialog is displayed, which asks created. This file requires further modification, as
if you want to rebuild the files. Click Yes.
shown in the next step.
10. Using ZDS II, open the leddemoRamCopy.lnk
link control file and make the following changes
near the end of the file:
• Remove the line containing …\lib\startup.obj
• Remove the line locate .startup at 8200h
AN015102-0404
leddemoRamCopy.lnk can show up as a shortcut
file with no extension. Performing this step
modifies the reference to the start-up code in the
Standard Start-up Module to reference the start-up
code in l92_Flashboot.s.
Discussion
Application Note
How to Make eZ80® Code Execute Faster with Copy To RAM
7
Table 2. How to Copy Code from Flash and Execute in RAM
Step
Comment
11. Perform a Save As... for this file and name it
ledemoRamCopy2.lnk. Select this file from the
Use Existing text box in the Input Category field
of the Linker tab of the Project Settings dialog
box.
The link file leddemoRamCopy2.lnk is now used
in the build. Renaming the file also protects the link
control file from being overwritten if Create New is
accidentally selected.
12. In ZDS II, open the Standard Startup Module file The startup.asm file is located in the ZDS II
startup.asm and the l92_Flashboot.s file
directory …src\rtl\common.
included in the project.
13. Copy the Copy to RAM code from startup.asm
and paste it into the l92_Flashboot.s file. This
code starts after label _c_data_done and ends
with label _copy_code_to_ram_done.
This code segment should be located after the
copy of initialized data code, in both files, to
provide the Copy to RAM code in the
l92_Flashboot.s start-up module
14. Change the selection from Standard to Included Everything is now changed to use the start-up
in Project for the Startup Module in the Input
code included in the project from the start-up code
Category field of the Linker tab in the Project
provided by the Standard Startup Module.
Settings dialog box.
15. Now click Build or Build All to build the leddemoRamCopy project.
The leddemoRamCopy.hex file is generated and
can be programmed into Flash memory using
either the external Flash Loader or the ZDS II
internal Flash Loader.
16. To program Flash memory using the ZDS II inter- It is assumed that the eZ80® Development
nal Flash Loader, start by selecting the ZDS II
Platform is set up and the leddemozdsFlash
Flash Loader command from the Tools menu project has been successfully demonstrated.
to bring up the Flash Loader Processor dialog
box.
17. In the External Flash Devices pane, select the
Micron MT 28F008B3 Non-Prot 0x8000 entry
and click the ERASE button. A pop-up dialog is
displayed, which asks if you want to erase Flash
8000 to FFFFF. Click Yes.
The user portion of Flash memory is erased and
not the Flash Loader/Boot Loader portion. Be
patient, because the erase can take a few
seconds.
18. Using the browser in the File pane, find and
select the leddemoRamCopy.hex file.
19. Click Burn and Verify in the Flash Controls
pane.
Flash memory is programmed with the leddemo
code that includes Copy to RAM.
20. After Flash memory is programmed, push the
reset button on the eZ80® Development Platform.
Notice the difference in the speed of the LED
flashing between the leddemozdsFlash code and
the leddemoRamCopy code.
Included in this applications note is the leddemoRamCopy project, which already
contains the modifications performed in Table 2. The project is located in the .zip
AN015102-0404
Discussion
Application Note
How to Make eZ80® Code Execute Faster with Copy To RAM
8
file RamCopy.zip. After this file is unzipped, place the ramcopy folder in the following directory path.
c:\program files\Zilog\ZDSII_eZ80_4.4.2\samples\ez80L92_LedDemo\
The include file for this project should already reside within the include folder
located in the same path. If the ramcopy folder already exists from completing the
steps in Table 2, rename the existing folder. Using ZDSII_eZ80_4.4.2, build and
Flash-load the project. Press the reset button on the eZ80® Development Platform to run the program.
Conclusion
This Application Note discusses how a few changes to an existing project that had
formerly stored and executed code from Flash memory could be made into a
project in which the code is stored in Flash and executed from RAM. The resulting
increase in execution speed was easily observed in the rate of the LED display
sequence. Achieving faster code execution involved creating a new link file by
modifying the existing file and making changes to the startup source code file.
AN015102-0404
Conclusion
Application Note
How to Make eZ80® Code Execute Faster with Copy To RAM
9
Source Code
The remainder of the pages in this Application Note list the source code and link
files. If viewing this document online, click the hyperlink below to jump to a pertinent file.
•
•
•
•
•
l92_flashboot.s
ledDemo.c
leddemoRamCopy.lnk
leddemoRamCopy2.lnk
ledInit.c
;*********************************************************************
l92_flashboot.s
;*********************************************************************
;*
source: l92_flashboot.s ( Runtime Startup )
;*
; Scope: The boot file configures Chip select CS0=28,CS1= 28( with one
; wait state)
;
;
; Copyright (c) ZiLOG, 2003
; Objective: To demonstrate memory mapped IO operation. This project
; displays a string 'eZ80'on 5*7 LED matrix.
;
; * Program Developed by : Rajiv I.Pujar
; * Unit
: CTBU, Zilog Inc., San Jose, CA, USA
; * Date
: 05/27/2002
;
;*********************************************************************
public
extern
__exit
_main
.include "ez80l92.inc"
AN015102-0404
Source Code
Application Note
How to Make eZ80® Code Execute Faster with Copy To RAM
10
CS_LBR0_DATA: .equ
CS_UBR0_DATA: .equ
CS_CTL0_DATA: .equ
%00
%3f
%e8
CS_LBR1_DATA: .equ
CS_UBR1_DATA: .equ
CS_CTL1_DATA: .equ
%c0
%c7
%28
CS_LBR2_DATA: .equ
CS_UBR2_DATA: .equ
CS_CTL2_DATA: .equ
%00
%00
%00
CS_LBR3_DATA: .equ
CS_UBR3_DATA: .equ
CS_CTL3_DATA: .equ
%00
%00
%00
;*********************************************************************
;
define
const, space=ROM
;
segment const
;
define
define
startup,
.intvect,
space=ROM, org=%8200
space=ROM, org=%0000
;*********************************************************************
;
segment .intvect
;
jp.lil (%8200)
segment startup
;**********************************
; Program entry point
;**********************************
;*********************************************************************
; Initialize Stack pointer
extern
TOSPS
extern
TOSPL
.assume ADL=1
di
jp.lil
_c_int0:
ld.sis
AN015102-0404
_c_int0
sp,TOSPS
; Setup SPS
Source Code
Application Note
How to Make eZ80® Code Execute Faster with Copy To RAM
11
ld.lil
sp,TOSPL
ld
out0
ld
out0
ld
out0
a,CS_LBR0_DATA
(CS0_LBR),a
a,CS_UBR0_DATA
(CS0_UBR),a
a,CS_CTL0_DATA
(CS0_CTL),a
ld
out0
ld
out0
ld
out0
a,CS_LBR1_DATA
(CS1_LBR),a
a,CS_UBR1_DATA
(CS1_UBR),a
a,CS_CTL1_DATA
(CS1_CTL),a
ld
out0
ld
out0
ld
out0
a,CS_LBR2_DATA
(CS2_LBR),a
a,CS_UBR2_DATA
(CS2_UBR),a
a,CS_CTL2_DATA
(CS2_CTL),a
ld
out0
ld
out0
ld
out0
a,CS_LBR3_DATA
(CS3_LBR),a
a,CS_UBR3_DATA
(CS3_UBR),a
a,CS_CTL3_DATA
(CS3_CTL),a
; Setup SPL
;--------------------------------------------; Initialize the .NBSS section to zero
extern
BSS_BASE
extern
BSS_LENGTH
ld
ld
or
sbc
jr
hl,BSS_LENGTH
bc,0
a,a
hl,bc
z,_c_nbss_done
;
;
;
;
;
Check for non-zero length
*
*
*
.NBSS is zero-length ...
ld
ld
ld
hl,BSS_BASE
bc,BSS_LENGTH
(hl),0
; [hl]=.nbss
$$:
AN015102-0404
Source Code
Application Note
How to Make eZ80® Code Execute Faster with Copy To RAM
12
dec
ld
sbc
jr
ld
ld
ldir
_c_nbss_done:
bc
hl,0
hl,bc
z,_c_nbss_done
hl,BSS_BASE
de,BSS_BASE+1
; 1st byte's taken care of
; Just 1 byte ...
; reset hl
; [de]=.nbss+1
;--------------------------------------------; Copy the initialized data section
extern
DATA_BASE
extern
DATA_COPY
extern
DATA_LENGTH
ld
ld
or
sbc
jr
hl,DATA_LENGTH
bc,0
a,a
hl,bc
z,_c_ndata_done
;
;
;
;
;
;
Address of initialized data
section
Address of initialized data
section copy
Length of initialized data
section
;
;
;
;
;
Check for non-zero length
*
*
*
.DATA is zero-length ...
;
;
;
;
[hl]= .ndata_copy
[de]= .ndata
[bc]= .ndata length
Copy the .ndata section
$$:
ld
hl,DATA_COPY
ld
de,DATA_BASE
ld
bc,DATA_LENGTH
ldir
_c_ndata_done:
;----- Copy CODE (which may be in FLASH) to RAM if the
;----- copy_code_to_ram symbol is set in the link control file
;
.ref
__copy_code_to_ram
.ref
__len_code,__low_code,__low_romcode
ld
a,__copy_code_to_ram
or
a,a
jr
z,_copy_code_to_ram_done
ld
ld
or
sbc
AN015102-0404
hl,__len_code
bc,0
a,a
hl,bc
;
;
;
;
Check for non-zero length
*
Clears carry flag
*
Source Code
Application Note
How to Make eZ80® Code Execute Faster with Copy To RAM
13
jr
z,_copy_code_to_ram_done ; __len_code is zero-length ...
ld
ld
ld
ldir
hl,__low_romcode
de,__low_code
bc,__len_code
;
;
;
;
[hl]=.code_copy
[de]=.code
[bc]= code length
Copy the code section
_copy_code_to_ram_done:
;--------------------------------------------ld
push
ld
add
push
hl,0
hl
ix,0
ix,sp
ix
; hl=NULL
; argv[0] = NULL
pop
ld
call
pop
__exit:
jr
hl
de,0
_main
af
; argc==0
; main()
; clean the stack
$
; ?
; ix=&argv[0]
; &argv[0]
;*********************************************************************
;*********************************************************************
ledDemo.c
;*********************************************************************
* Source: ledDemo.c
* Scope: Main program for the LED Matrix Display that works on the
* eZ80L92 device.
;*********************************************************************
* Copyright (c)2003 ZiLOG Inc.*
* Objective: To demonstrate memory mapped I/O operation. This project
* displays a string 'eZ80'on 5*7 LED
matrix.
AN015102-0404
Source Code
Application Note
How to Make eZ80® Code Execute Faster with Copy To RAM
14
*
*
*
*
Program Developed by : Rajiv I.Pujar
Unit
: CTBU, Zilog Inc., San Jose, CA, USA
Date
: 05/27/2002
ZDS II (Beta 2 ) Project Settings: Please refer to the readme file
;*********************************************************************
#include <ez80l92.h>
char zds2[22] = "ZDS II Sample Project";
void test()
{
int a =1;
int b =2;
int c =3;
c = b+a+2;
c++;
c++;
}
void main(void) {
;*********************************************************************
The led_message() function calls the other functions which are
responsible for initialization of the LED matrix and display the
characters on the matrix.
;*********************************************************************
test();
led_message();
}
;*********************************************************************
leddemoRamCopy.lnk
;*********************************************************************
AN015102-0404
Source Code
Application Note
How to Make eZ80® Code Execute Faster with Copy To RAM
15
/* Link Control File - leddemoRamCopy Debug */
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
compiler options */
-alias -asm -const:RAM -debug -define:_EZ80L92 -define:FLASH*/
-NOexpmac -NOfplib -intsrc -intrinsic -NOkeepasm -NOkeeplst*/
-NOlist -NOlistinc -maxerrs:50 -NOmodsect -promote -quiet*/
-NOstrict -NOwatch -optsize -localopt -localcse -localfold*/
-localcopy -peephole -globalopt -NOglobalcse -NOglobalfold*/
-NOglobalcopy -NOloopopt -NOsdiopt -NOjmpopt*/
-stdinc:"..\include;C:\PROGRA~1\ZiLOG\ZDSII_~1.2\include"*/
-usrinc:"..\include" -cpu:EZ80L92 -bitfieldsize:24 -charsize:8*/
-doublesize:32 -floatsize:32 -intsize:24 -longsize:32*/
-shortsize:16 -asmsw:"-cpu:EZ80L92"*/
/* assembler options */
/* -debug -genobj -NOigcase -include:"..\include" -list -NOlistmac*/
/* -name -pagelen:56 -pagewidth:80 -quiet -warn -NOzmasm -cpu:EZ80L92*/
-FORMAT=INTEL32
-NOigcase -map -NOquiet -warn -NOxref
RANGE
RANGE
RANGE
RANGE
ROM $8200 : $0FFFFF
RAM $C00000 : $C7FFFF
EXTIO $0 : $FFFF
INTIO $0 : $FF
/* additional user-defined directives */
RANGE ROM $0:$4, $8200 : $0FFFFF
CHANGE STRSECT is ROM
COPY DATA ROM
DEFINE BSS_BASE = base of BSS
DEFINE BSS_LENGTH = length of BSS
DEFINE DATA_BASE = base of DATA
DEFINE DATA_COPY = copy base of DATA
DEFINE DATA_LENGTH = length of DATA
DEFINE TOSPL = highaddr of RAM - 2
DEFINE TOSPS = $0FFE
ORDER startup, CODE, STRSECT, DATA, BSS
/* end additional user-defined directives */
AN015102-0404
Source Code
Application Note
How to Make eZ80® Code Execute Faster with Copy To RAM
16
change strsect is code
change text is code
change CODE is RAM
COPY DATA ROM
COPY CODE ROM
define __low_romdata = copy base of DATA
define __low_data = base of DATA
define __len_data = length of DATA
define __low_bss = base of BSS
define __len_bss = length of BSS
define __heaptop = top of RAM
define __stack = highaddr of RAM
define __heapbot = base of RAM + length of CODE + length of BSS + length
of DATA
define __vector_base = base of DATA
define __low_romcode = copy base of code
define __low_code = base of code
define __len_code = length of code
define __copy_code_to_ram = 1
"C:\PROGRA~1\ZiLOG\ZDSII_~1.2\Samples\EZ80L9~1\RamCopy\leddemoramcopy.
hex"= \
C:\PROGRA~1\ZiLOG\ZDSII_~1.2\lib\startup.obj, \
.\l92_flashboot.obj, \
.\ledDemo.obj, \
.\ledInit.obj, \
C:\PROGRA~1\ZiLOG\ZDSII_~1.2\lib\crtD.lib, \
C:\PROGRA~1\ZiLOG\ZDSII_~1.2\lib\fpdumy.obj
locate .startup at $8200
;*********************************************************************
;*********************************************************************
leddemoRamCopy2.lnk
;*********************************************************************
/* Link Control File - leddemoRamCopy Debug */
AN015102-0404
Source Code
Application Note
How to Make eZ80® Code Execute Faster with Copy To RAM
17
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
compiler options */
-alias -asm -const:RAM -debug -define:_EZ80L92 -define:FLASH*/
-NOexpmac -NOfplib -intsrc -intrinsic -NOkeepasm -NOkeeplst*/
-NOlist -NOlistinc -maxerrs:50 -NOmodsect -promote -quiet*/
-NOstrict -NOwatch -optsize -localopt -localcse -localfold*/
-localcopy -peephole -globalopt -NOglobalcse -NOglobalfold*/
-NOglobalcopy -NOloopopt -NOsdiopt -NOjmpopt*/
-stdinc:"..\include;C:\PROGRA~1\ZiLOG\ZDSII_~1.2\include"*/
-usrinc:"..\include" -cpu:EZ80L92 -bitfieldsize:24 -charsize:8*/
-doublesize:32 -floatsize:32 -intsize:24 -longsize:32*/
-shortsize:16 -asmsw:"-cpu:EZ80L92"*/
/* assembler options */
/* -debug -genobj -NOigcase -include:"..\include" -list -NOlistmac*/
/* -name -pagelen:56 -pagewidth:80 -quiet -warn -NOzmasm -cpu:EZ80L92*/
-FORMAT=INTEL32
-NOigcase -map -NOquiet -warn -NOxref
RANGE
RANGE
RANGE
RANGE
ROM $8200 : $0FFFFF
RAM $C00000 : $C7FFFF
EXTIO $0 : $FFFF
INTIO $0 : $FF
/* additional user-defined directives */
RANGE ROM $0:$4, $8200 : $0FFFFF
CHANGE STRSECT is ROM
COPY DATA ROM
DEFINE BSS_BASE = base of BSS
DEFINE BSS_LENGTH = length of BSS
DEFINE DATA_BASE = base of DATA
DEFINE DATA_COPY = copy base of DATA
DEFINE DATA_LENGTH = length of DATA
DEFINE TOSPL = highaddr of RAM - 2
DEFINE TOSPS = $0FFE
ORDER startup, CODE, STRSECT, DATA, BSS
/* end additional user-defined directives */
change strsect is code
change text is code
AN015102-0404
Source Code
Application Note
How to Make eZ80® Code Execute Faster with Copy To RAM
18
change CODE is RAM
COPY DATA ROM
COPY CODE ROM
define __low_romdata = copy base of DATA
define __low_data = base of DATA
define __len_data = length of DATA
define __low_bss = base of BSS
define __len_bss = length of BSS
define __heaptop = top of RAM
define __stack = highaddr of RAM
define __heapbot = base of RAM + length of CODE + length of BSS + length
of DATA
define __vector_base = base of DATA
define __low_romcode = copy base of code
define __low_code = base of code
define __len_code = length of code
define __copy_code_to_ram = 1
"C:\PROGRA~1\ZiLOG\ZDSII_~1.2\Samples\EZ80L9~1\RamCopy\leddemoramcopy.
hex"= \
.\l92_flashboot.obj, \
.\ledDemo.obj, \
.\ledInit.obj, \
C:\PROGRA~1\ZiLOG\ZDSII_~1.2\lib\crtD.lib, \
C:\PROGRA~1\ZiLOG\ZDSII_~1.2\lib\fpdumy.obj
;*********************************************************************
ledInit.c
;*********************************************************************
* Source: ledinit.c
* Scope: eZ80L92 Memory Mapped IO -Initialization
*
*
*
*
*
Copyright (c) ZiLOG, 2003
Objective: To demonstrate memory mapped IO operation in s very simple
way. This program is developed with a very simple procedure for a
better clarity without any complicated 'c' routines.
AN015102-0404
Source Code
Application Note
How to Make eZ80® Code Execute Faster with Copy To RAM
19
* Program Developed by: Rajiv I.Pujar
* Unit: CTBU, Zilog Inc., San Jose, CA
* Date: 05/27/2002
*
*
****************************************************************/
#include "ledinit.h"
#include <ez80l92.h>
#ifdef FLASH
#define DELAY 125
#else
#define DELAY 500
#endif
/* Variables */
unsigned
unsigned
int data
unsigned
char *ledan;
char *ledca;
;
char *output;
/* LED Anode
*/
/* LED Cathode */
;*********************************************************************
led_message() function display 'eZ80' on LED Matrix
;*********************************************************************
void led_message(void){
int i,j,k,l;
unsigned int data,datacat;
data =0x01;
datacat =0x01;
for(;;){
/* The below code segment which clears LED display */
clear_led();
AN015102-0404
Source Code
Application Note
How to Make eZ80® Code Execute Faster with Copy To RAM
20
/* wait */
for (k=0; k<100 ;k++){
delay();
}
;*********************************************************************
Chip Select CS2 Configuration
LED Matrix is memory-mapped and selected by selecting chip select
2 Low (i.e cs2).
;*********************************************************************
CS2_LBR
CS2_UBR
CS2_CTL
ledan
ledca
=
=
=
=
=
0X80;
0xbf;
0x28;
0x800000;
0x800001;
;*********************************************************************
Display characters 'e' 'z' '8' '0'
;*********************************************************************
;*********************************************************************
Display the character 'e'
This block turns on respective anode and cathode bits of LED matrix to
display character ' e '
;*********************************************************************
for (l=0;l<250;l++){
*ledca= 0x11;
*ledan = 0x01;
delay();
*ledca= 0x0e;
*ledan = 0x02;
delay();
AN015102-0404
Source Code
Application Note
How to Make eZ80® Code Execute Faster with Copy To RAM
21
*ledca= 0x01;
*ledan = 0x04;
delay();
*ledca= 0x0f;
*ledan = 0x08;
delay();
*ledca= 0x0f;
*ledan = 0x10;
delay();
*ledca= 0x0e;
*ledan = 0x20;
delay();
*ledca= 0x11;
*ledan = 0x40;
delay();
}
;*********************************************************************
Display the character 'z'
This block turns on respective anode and cathode bits of the LED matrix
to display the character 'z'.
;*********************************************************************
for (l=0;l<250;l++){
*ledca= 0x00;
*ledan = 0x01;
delay();
*ledca= 0x1e;
*ledan = 0x02;
delay();
*ledca= 0x1d;
*ledan = 0x04;
AN015102-0404
Source Code
Application Note
How to Make eZ80® Code Execute Faster with Copy To RAM
22
delay();
*ledca= 0x1b;
*ledan = 0x08;
delay();
*ledca= 0x17;
*ledan = 0x10;
delay();
*ledca= 0x0f;
*ledan = 0x20;
delay();
*ledca= 0x00;
*ledan = 0x40;
delay();
}
;*********************************************************************
Display the character '8'
This block turns on the respective anode and cathode bits of the LED
matrix to display character ' 8 '
;*********************************************************************
for (l=0;l<250;l++){
*ledca= 0x11;
*ledan = 0x01;
delay();
*ledca= 0x0e;
*ledan = 0x02;
delay();
*ledca= 0x0e;
*ledan = 0x04;
delay();
*ledca= 0x11;
AN015102-0404
Source Code
Application Note
How to Make eZ80® Code Execute Faster with Copy To RAM
23
*ledan = 0x08;
delay();
*ledca= 0x0e;
*ledan = 0x10;
delay();
*ledca= 0x0e;
*ledan = 0x20;
delay();
*ledca= 0x11;
*ledan = 0x40;
delay();
}
;*********************************************************************
Display the character '0’
This block turns on the respective anode and cathode bits of the LED
matrix to display the character '0'.
;*********************************************************************
for (l=0;l<250;l++){
*ledca= 0x11;
*ledan = 0x01;
delay();
*ledca= 0x0e;
*ledan = 0x02;
delay();
*ledca= 0x0e;
*ledan = 0x04;
delay();
*ledca= 0x0e;
*ledan = 0x08;
delay();
*ledca= 0x0e;
AN015102-0404
Source Code
Application Note
How to Make eZ80® Code Execute Faster with Copy To RAM
24
*ledan = 0x10;
delay();
*ledca= 0x0e;
*ledan = 0x20;
delay();
*ledca= 0x11;
*ledan = 0x40;
delay();
}
for (k=0; k<50000 ;k++){
for(i=0;i<3;i++){
clear_led();
}
}
;*********************************************************************
LED Rolling and Flashing Display
;*********************************************************************
led_rolling_flashing();
}
}
;*********************************************************************
led_rolling_flashing() -> is rollover and flashing display
;*********************************************************************
void led_rolling_flashing(){
int i;
AN015102-0404
Source Code
Application Note
How to Make eZ80® Code Execute Faster with Copy To RAM
25
led_lefToRight_roll();
for (i=0;i<5;i++){
led_flash();
}
for (i=0;i<10;i++){
delay();
}
led_rightToLeft_roll();
}
;*********************************************************************
This routine rolls LED display from left to right.
;*********************************************************************
void led_lefToRight_roll(){
int i,j,k;
unsigned int adata;
adata =0x01;
/* Left to Right Roll Display */
for(i=0;i<7;i++){
CS2_LBR
CS2_UBR
CS2_CTL
ledan =
ledca =
= 0X80;
= 0xbf;
= 0x28;
0x800000;
0x800001;
if (adata ==00){ adata =0x01 ;}
adata=adata<<0x01;
*ledan=adata;
AN015102-0404
Source Code
Application Note
How to Make eZ80® Code Execute Faster with Copy To RAM
26
*ledca=0x00;
for (j=0; j<10 ;j++){
delay();
}
for (k=0; k<50000 ;k++){
clear_led();
}
}
}
;*********************************************************************
This routine rolls LED display from right to left.
;*********************************************************************
void led_rightToLeft_roll(){
int i,j,k;
unsigned int adata;
adata=0x80;
for(i=0;i<7;i++){
CS2_LBR
CS2_UBR
CS2_CTL
ledan =
ledca =
=0X80;
= 0xbf;
= 0x28;
0x800000;
0x800001;
if (adata ==00){ adata =0x01 ;}
adata=adata>>0x01;
*ledan=adata;
*ledca=0x00;
AN015102-0404
Source Code
Application Note
How to Make eZ80® Code Execute Faster with Copy To RAM
27
for (j=0; j<10 ;j++){
delay();
}
for (k=0; k<10000 ;k++){
clear_led();
}
}
}
;*********************************************************************
This is a flashing display function.
;*********************************************************************
void led_flash(void){
int i,j,k;
for(i=0;i<10;i++){
CS2_LBR
CS2_UBR
CS2_CTL
ledan =
ledca =
= 0X80;
= 0xbf;
= 0x28;
0x800000;
0x800001;
*ledca= 0x00;
*ledan = 0xff;
delay();
delay();
delay();
delay();
delay();
for (k=0; k<1000 ;k++){
/* Instead of using clear_Led() function ,the below code segment
* which clears LED display is written in Assembly just to
AN015102-0404
Source Code
Application Note
How to Make eZ80® Code Execute Faster with Copy To RAM
28
* illustrate Mixed Mode operation */
asm("\n\tld A,%80\n\tout0 (%AE),A\n\tld
(%AF),A\n\tld A,%E8\n\tout0 (%B0),A\n\t");
asm("\n\tpush HL\n\tld HL,%800001\n\tld
HL\n\t");
asm("\n\tld A,%80\n\tout0 (%AE),A\n\tld
(%AF),A\n\tld A,%E8\n\tout0 (%B0),A\n\t");
asm("\n\tpush HL\n\tld HL,%800000\n\tld
HL\n\t");
A,%bf\n\tout0
A,%ff\n\tld (HL),A\n\tpop
A,%bf\n\tout0
A,%00\n\tld (HL),A\n\tpop
}
}
for (j=0; j<100 ;j++){
delay();
}
}
;*********************************************************************
Delay routine
;*********************************************************************
void delay(){
int j;
for (j=0; j<DELAY ;j++){
}
}
;*********************************************************************
Clear LED Display -
clear_led()
;*********************************************************************
void clear_led(void ){
CS2_LBR =0X80;
AN015102-0404
Source Code
Application Note
How to Make eZ80® Code Execute Faster with Copy To RAM
29
CS2_UBR =0xbf;
CS2_CTL =0x28;
ledan= 0x800000;
ledca =0x800001;
*ledca=0xff;
*ledan=0x00;
}
AN015102-0404
Source Code