1 /* @(#)ecc.h	1.6 12/12/02 Copyright 1998-2002 Heiko Eissfeldt, Joerg Schilling */
2 
3 /*
4  * compact disc reed-solomon routines
5  *
6  * (c) 1998-2002 by Heiko Eissfeldt, heiko@colossus.escape.de
7  * (c) 2002-2012 by Joerg Schilling
8  */
9 /*
10  * The contents of this file are subject to the terms of the
11  * Common Development and Distribution License, Version 1.0 only
12  * (the "License").  You may not use this file except in compliance
13  * with the License.
14  *
15  * See the file CDDL.Schily.txt in this distribution for details.
16  * A copy of the CDDL is also available via the Internet at
17  * http://www.opensource.org/licenses/cddl1.txt
18  *
19  * When distributing Covered Code, include this CDDL HEADER in each
20  * file and include the License file CDDL.Schily.txt from this distribution.
21  */
22 
23 #define	RS_L12_BITS	8
24 
25 /* audio sector definitions for CIRC */
26 #define	FRAMES_PER_SECTOR	98
27 /* user data bytes per frame */
28 #define	L1_RAW	24
29 /* parity bytes with 8 bit */
30 #define	L1_Q	4
31 #define	L1_P	4
32 
33 /* audio sector Cross Interleaved Reed-Solomon Code (CIRC) encoder (layer 1) */
34 /*
35  * adds P- and Q- parity information to audio (f2) frames. Also
36  * optionally handles the various delays and permutations. The output with all
37  * stages enabled can be fed into the Eight-Fourteen-Modulator.
38  * On input: 2352 bytes of audio data is given.
39  * On output: 3136 bytes of CIRC enriched audio data are returned.
40  */
41 int do_encode_L1 __PR((unsigned char in[L1_RAW*FRAMES_PER_SECTOR],
42 		unsigned char out[(L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR],
43 		int delay1, int delay2, int delay3, int scramble));
44 
45 /* data sector definitions for RSPC */
46 /* user data bytes per frame */
47 #define	L2_RAW	(1024*2)
48 /* parity bytes for 16 bit units */
49 #define	L2_Q	(26*2*2)
50 #define	L2_P	(43*2*2)
51 
52 /* known sector types */
53 #define	MODE_0	0
54 #define	MODE_1	1
55 #define	MODE_2	2
56 #define	MODE_2_FORM_1	3
57 #define	MODE_2_FORM_2	4
58 
59 /* set one of the MODE_* constants for subsequent data sector formatting */
60 int set_sector_type	__PR((int st));
61 /* get the current sector type setting for data sector formatting */
62 int get_sector_type	__PR((void));
63 
64 /* data sector layer 2 Reed-Solomon Product Code encoder */
65 /*
66  * encode the given data portion depending on sector type (see
67  * get/set_sector_type() functions). Use the given address for the header.
68  * The returned data is __unscrambled__ and not in F2-frame format (for that
69  * see function scramble_L2()).
70  * Supported sector types:
71  *   MODE_0: a 12-byte sync field, a header and 2336 zeros are returned.
72  *   MODE_1: the user data portion (2048 bytes) has to be given
73  *           at offset 16 in the inout array.
74  *           Sync-, header-, edc-, spare-, p- and q- fields will be added.
75  *   MODE_2: the user data portion (2336 bytes) has to be given
76  *           at offset 16 in the inout array.
77  *           Sync- and header- fields will be added.
78  *   MODE_2_FORM_1: the user data portion (8 bytes subheader followed
79  *                  by 2048 bytes data) has to be given at offset 16
80  *                  in the inout array.
81  *                  Sync-, header-, edc-, p- and q- fields will be added.
82  *   MODE_2_FORM_2: the user data portion (8 bytes subheader followed
83  *                  by 2324 bytes data) has to be given at offset 16
84  *                  in the inout array.
85  *                  Sync-, header- and edc- fields will be added.
86  */
87 int do_encode_L2	__PR((unsigned char *inout, int sectortype, unsigned address));
88 int encode_L2_Q		__PR((unsigned char inout[4 + L2_RAW + 4 + 8 + L2_P + L2_Q]));
89 int encode_L2_P		__PR((unsigned char inout[4 + L2_RAW + 4 + 8 + L2_P]));
90 
91 int decode_L2_Q		__PR((unsigned char inout[4 + L2_RAW + 12 + L2_Q]));
92 int decode_L2_P		__PR((unsigned char inout[4 + L2_RAW + 12 + L2_Q + L2_P]));
93 unsigned int build_edc	__PR((unsigned char inout[], int from, int upto));
94 
95 /*
96  * generates f2 frames from otherwise fully formatted sectors (generated by
97  * do_encode_L2()).
98  */
99 #define	EDC_SCRAMBLE_NOSWAP	1	/* Do not swap bytes while scrambling */
100 int scramble_L2		__PR((unsigned char *inout));
101 
102 /* r-w sub channel definitions */
103 #define	RS_SUB_RW_BITS	6
104 
105 #define	PACKETS_PER_SUBCHANNELFRAME	4
106 #define	LSUB_RAW			18
107 #define	LSUB_QRAW			2
108 /* 6 bit */
109 #define	LSUB_Q	2
110 #define	LSUB_P	4
111 
112 /* R-W subchannel encoder */
113 /*
114  * On input: 72 bytes packed user data, four frames with each 18 bytes.
115  * On output: per frame: 2 bytes user data, 2 bytes Q parity,
116  *                       16 bytes user data, 4 bytes P parity.
117  * Options:
118  *   delay1: use low level delay line
119  *   scramble: perform low level permutations
120  */
121 int do_encode_sub __PR((unsigned char in[LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME],
122 		unsigned char out[(LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME],
123 		int delay1, int scramble));
124 int do_decode_sub __PR((unsigned char in[(LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME],
125 		unsigned char out[LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME],
126 		int delay1, int scramble));
127 
128 int decode_LSUB_Q	__PR((unsigned char inout[LSUB_QRAW + LSUB_Q]));
129 int decode_LSUB_P	__PR((unsigned char inout[LSUB_RAW + LSUB_Q + LSUB_P]));
130