ANALOG DEVICES AN-1050 Service Manual

AN-1050
APPLICATON NOTE
One Technology Way P. O . Box 9106 Norwood, MA 02062-9106, U.S.A. Tel : 781.329.4700 Fax : 781.461.3113 www.analog.com
2
C Scripts for the
ADV74xx/AD V78xx V75xx/ADV76xx/AD
by Witold Kaczurba

INTRODUCTION

This application note describes a method for compressing larg
2
sets of I ation herein is targeted for applications where the user needs to put over 50 scripts to the memory of one single microcon This method provides excellent results for sets of scripts containing m an I C bus.
Analog Devices, Inc., multiformat decoders allow users decode various standards of video. Because a variety of standards are supported, these video decoders provide various settings. Each setting contains the bulk of I mode. These writes are collected as scripts.
In some cases, the user may use hundreds of scripts to conf many I
C scripts for microcontroller platforms. The inform-
ore than 200 scripts for more than six devices on
2
2
C
writes for each
2
C devices. In such a case, the user requires a lot of
TEXT FILE:
2
SET OF I
C SCRIPTS
troller.
to
igure
COMPRESSING
Figure 1. Concept of Compressing Algorithms
e
OCTAVE
SCRIPT
memory in a small microcontroller to keep all of these scripts. Note that these scripts may have similar writes as well as unique writes. This application note details how to compress the script on the PC side, as well as how to write an efficient decompress sing method on the microcontroller side. The decompressing algorithm utilizes more efficient functions requiring less RAM.
This application note includes a script for an Octave program. Octave is a free
(GNU/GPL license) computer program for
numerical computations. This Octave script can compress scripts and export the results to the C code with decompressi procedures. The resulting C code p
ortable to any microcontroller.
is easy to use, and is easily
ng
C-CODE:
-COMPRESSED SCRIPT R-DECOMPRESSO
8522-001
-
Rev. 0 | Page 1 of 20
AN-1050 Application Note

TABLE OF CONTENTS

Introduction ...................................................................................... 1
About the Scripts .............................................................................. 3
Basic Knowledge ........................................................................... 3
Construction of the Script ........................................................... 3
Compression/Decompression..................................................... 6
Usage .............................................................................................. 7
Octave Source Code ......................................................................... 8
main.m ........................................................................................... 8
load_script.m .............................................................................. 10
number_of_scripts_in_file.m ................................................... 11
fsubst.m ........................................................................................ 12
find_mat2.m ................................................................................ 12
script_to_c.m .............................................................................. 13
Conclusion....................................................................................... 19
Results .......................................................................................... 19
Further Optimizations ............................................................... 19
References and Licensing Information .................................... 19
Rev. 0 | Page 2 of 20
Application Note AN-1050

ABOUT THE SCRIPTS

BASIC KNOWLEDGE

The compression method described in this application note is intended to be used with sets of scripts constructed as shown in the Construction of the Script section. One I three values:
device address (to address the device on the I
register address
value to be written to the register
Usually scripts provided with evaluation boards by Analog Devices use ascending order by I
2
C writes. This means that writes to the same device are in ascending order of register addresses, such as:
42 00 AB
42 01 CD
42 02 EF
This not accidential; the order of writes makes compression more efficient because it is more likely to find the same pattern across various scripts. Note that it is unlikely to find the same write to the same register of the same device, such as:
42 03 04
42 03 08
This increases the probability of the same sequences of writes occurring in different scripts. This is why this application note describes algorithms in which scripts are checked for occurrence of sequences of four identical writes, as shown in Figure 2.
##SCRIPT## :SCRIPT 1:
42 03 04; 42 04 06; 42 0A 53; 42 0C 23; 42 0F 45; 42 22 39; 42 AA 10; 42 FF 03; ...
Figure 2. Sequence of Four Identical Writes Occurs in Two Different Scripts
##SCRIPT## :SCRIPT 2:
42 00 03; 42 02 27; 42 03 09; 42 04 FF; 42 0A 53; 42 0C 23; 42 0F 45; 42 22 39; 42 FF 02; ...
2
C write consists of
2
C bus)
08522-002
Storing large sequences (of four writes) that are common for various script big blocks is beneficial to the microcontroller side. These common blocks (also called keys) can be stored as a continuous array in a C program. Thus, each key is easily addressable. This ease of addressing the keys eliminates many pointers that would otherwise have to be used in the decom­presssing algorithm. Each constant pointer requires memory.

CONSTRUCTION OF THE SCRIPT

The Octave script that is used for compression requires an original set of scripts to be stored in a file in a particular way. Each original script starts with a header (the first line) contain­ing the characters ## at both the beginning and the end of the line. The next line in the script is a small header that must contain colons at both the beginning and at the end of the line. The following line, the third line, contains proper I such as:
42 05 02 ; Prim_Mode = 010b for GR
where: 42 indicates the device’s 8-bit, I
2
C address (0x42). 05 is the 8-bit, register address (0x05). 02 is the 8-bit value (0x02). Prim_Mode = 010b for GR is an optional, user-defined comment.
Note the spaces and semicolon in the equation. The last line of the script is single word End, without any spaces. Scripts are split by the use of empty lines.
The following pages provide an example portion of the set of scripts for the ADV7401 evaluation board (EVAL-ADV7401EBZ).
2
C writes,
Rev. 0 | Page 3 of 20
AN-1050 Application Note
##CP VGA 640x480## :640x480 _@ 60 Autodetecting sync source 25.175 MHz out through DAC: 42 05 02 ; Prim_Mode = 010b for GR 42 06 08 ; VID_STD = 1000b for 640 × 480 @ 60 42 1D 47 ; Enable 28 MHz crystal 42 3A 11 ; Set latch clock settings to 001b, Power down ADC3 42 3B 80 ; Enable external bias 42 3C 5C ; PLL_QPUMP to 100b 42 6A 00 ; DLL phase adjust 42 6B 82 ; Enable DE output, swap Pr& Pb 42 73 90 ; Set man_gain 42 7B 1D ; TURN OFF EAV & SAV CODES Set BLANK_RGB_SEL 42 85 03 ; Enable DS_OUT 42 86 0B ; Enable stdi_line_count_mode 42 8A 90 ; VCO range to 00b 42 F4 3F ; Max drive strength 42 0E 80 ; Analog Devices recommended setting 42 52 46 ; Analog Devices recommended setting 42 54 00 ; Analog Devices recommended setting 42 0E 00 ; Analog Devices recommended setting 54 00 13 ; Power-down encoder 74 EE EE ; Power-down HDMI End
##CP VGA 640x480## :640x480 _@ 72 Autodetecting sync source 31.5 MHz out through DAC: 42 05 02 ; Prim_Mode = 010b for GR 42 06 09 ; VID_STD = 1001b for 640 × 480 @ 72 42 1D 47 ; Enable 28 MHz crystal 42 3A 11 ; set latch clock settings to 001b, Power down ADC3 42 3B 80 ; Enable external bias 42 3C 5C ; PLL_QPUMP to 100b 42 6A 00 ; DLL phase adjust 42 6B 82 ; Enable DE output, swap Pr& Pb 42 73 90 ; Set man_gain 42 7B 1D ; TURN OFF EAV & SAV CODES Set BLANK_RGB_SEL 42 85 03 ; Enable DS_OUT 42 86 0B ; Enable stdi_line_count_mode 42 F4 3F ; Max drive strength 42 0E 80 ; Analog Devices recommended setting 42 52 46 ; Analog Devices recommended setting 42 54 00 ; Analog Devices recommended setting 42 0E 00 ; Analog Devices recommended setting 54 00 13 ; Power down encoder 74 EE EE ; Power down HDMI End
Rev. 0 | Page 4 of 20
Application Note AN-1050
##CP VGA 640x480## :640x480 _@ 75 Autodetecting sync source 31.5 MHz Out through DAC: 42 05 02 ; Prim_Mode = 010b for GR 42 06 0A ; VID_STD =1 010b for 640 × 480 @ 75 42 1D 47 ; Enable 28 MHz crystal 42 3A 11 ; set latch clock settings to 001b, Power down ADC3 42 3B 80 ; Enable external bias 42 3C 5C ; PLL_QPUMP to 100b 42 6A 00 ; DLL phase adjust 42 6B 82 ; Enable DE output, swap Pr& Pb 42 73 90 ; Set man_gain 42 7B 1D ; TURN OFF EAV & SAV CODES Set BLANK_RGB_SEL 42 85 03 ; Enable DS_OUT 42 86 0B ; Enable stdi_line_count_mode 42 F4 3F ; Max drive strength 42 0E 80 ; Analog Devices recommended setting 42 52 46 ; Analog Devices recommended setting 42 54 00 ; Analog Devices recommended setting 42 0E 00 ; Analog Devices recommended setting 54 00 13 ; Power down encoder 74 EE EE ; Power down HDMI End
Rev. 0 | Page 5 of 20
AN-1050 Application Note
Note that the device address used in the scripts is always an even number greater than 0. Odd addresses are used for reading back from the device, which does not occur in this case. Thus, Address 0x00 is used as an escape code, a special code used for decompressing.

COMPRESSION/DECOMPRESSION

The Octave script in the Octave Source Code section com­presses the script on the PC side. An output of Octave script is C code containing compressed data and the decompression algorithm.
The Octave script algorithm consists of the following steps:
1. The script is loaded into matrices of various dimensions
(size is dependent on length of script).
2. The matrices are searched for common blocks or keys
where each key consists of four writes.
0x00, 0x00, 0x09
0x42, 0x3A, 0x13 0x00, 0x00, 0x01
0x42, 0x69, 0x03 0x42, 0x86, 0x0B 0x42, 0xF3, 0x03 0x00, 0x00, 0x02
0x00, 0x00, 0x03
0x00, 0x00, 0x04
0x00, 0x00, 0x0A 0x54, 0x87, 0x20
0x74, 0xFC, 0xFC
COMPRESSED SCRI P T
9TH KEY
ST
1
ND
2
RD
3
TH
4
TH
10
KEYS ARE SHARED BETW E EN COMPRESSED SCRI P TS
0x42, 0x03, 0x0C 0x42, 0x04, 0x57 0x42, 0x1D, 0x47 0x42, 0x31, 0x02
KEY
KEY
KEY
KEY
KEY
0x42, 0x3B, 0x80 0x42, 0x3D, 0xA2 0x42, 0x3E, 0x6A 0x42, 0x3F, 0xA0
0x42, 0xF9, 0x03 0x42, 0x0E, 0x80 0x42, 0x52, 0x46 0x42, 0x54, 0x00
0x42, 0x7F, 0xFF 0x42, 0x81, 0x30 0x42, 0x90, 0xC9 0x42, 0x91, 0x40
0x42, 0x92, 0x3C 0x42, 0x93, 0xCA 0x42, 0x94, 0xD5 0x42, 0xB1, 0xFF
0x00, 0x00, 0x05 0x00, 0x00, 0x06 0x00, 0x00, 0x07 0x00, 0x00, 0x08
Figure 3. Structure of Compressed Scripts
3. If a common block is found, it is written to a separate block
called keys with a key_number index.
4. Where there is a common block, the block is replaced with
a single write: (0x00, A, B) where A × 256 + B is a value key_number.
5. The key_number index is increased by one.
6. Finding and replacing the common blocks is repeated until
a search from beginning to end produces no results.
This process creates the structure of matrices as shown in Figure 3.
KEYS ARE SHARED BETWEEN
5TH KEY
TH
6
TH
7
TH
8
COMPRESSED SCRI P TS
0x42, 0xB6, 0x08 0x42, 0xC0, 0x9A 0x42, 0xCF, 0x50 0x42, 0xD0, 0x4E
KEY
0x42, 0xD1, 0xB9 0x42, 0xD6, 0xDD 0x42, 0xD7, 0xE2 0x42, 0xE5, 0x51
KEY
0x42, 0x0E, 0x00 0x54, 0x17, 0x02 0x54, 0x00, 0xFC 0x54, 0x01, 0x80
KEY
0x54, 0x80, 0x10 0x54, 0x82, 0xC9 0x54, 0x84, 0x06 0x54, 0x88, 0x00
08522-003
Rev. 0 | Page 6 of 20
Loading...
+ 14 hidden pages