ppb_msq.h revision 38061
1204431Sraj/*-
2204431Sraj * Copyright (c) 1998 Nicolas Souchu
3204431Sraj * All rights reserved.
4204431Sraj *
5204431Sraj * Redistribution and use in source and binary forms, with or without
6204431Sraj * modification, are permitted provided that the following conditions
7204431Sraj * are met:
8204431Sraj * 1. Redistributions of source code must retain the above copyright
9204431Sraj *    notice, this list of conditions and the following disclaimer.
10204431Sraj * 2. Redistributions in binary form must reproduce the above copyright
11204431Sraj *    notice, this list of conditions and the following disclaimer in the
12204431Sraj *    documentation and/or other materials provided with the distribution.
13204431Sraj *
14204431Sraj * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15204431Sraj * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16204431Sraj * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17204431Sraj * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18204431Sraj * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19204431Sraj * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20204431Sraj * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21204431Sraj * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22204431Sraj * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23204431Sraj * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24204431Sraj * SUCH DAMAGE.
25204431Sraj *
26204431Sraj *	$Id: ppb_msq.h,v 1.1.2.6 1998/06/17 00:37:12 son Exp $
27204431Sraj *
28204431Sraj */
29204431Sraj#ifndef __PPB_MSQ_H
30204431Sraj#define __PPB_MSQ_H
31204431Sraj
32204431Sraj/*
33204431Sraj * Basic definitions
34204431Sraj */
35204431Sraj
36204431Sraj/* microsequence parameter descriptor */
37204431Sraj#define MS_INS_MASK	0x00ff	/* mask to retrieve the instruction position */
38204431Sraj#define MS_ARG_MASK	0x0f00	/* mask to retrieve the argument number */
39204431Sraj#define MS_TYP_MASK	0xf000	/* mask to retrieve the type of the param */
40204431Sraj
41204431Sraj/* offset of each mask (see above) */
42204431Sraj#define MS_INS_OFFSET	0
43204431Sraj#define MS_ARG_OFFSET	8
44204431Sraj#define MS_TYP_OFFSET	12
45204431Sraj
46204431Sraj/* list of parameter types */
47204431Sraj#define MS_TYP_INT	0x0	/* integer */
48204431Sraj#define MS_TYP_CHA	0x1	/* character */
49204431Sraj#define MS_TYP_PTR	0x2	/* void pointer */
50204431Sraj#define MS_TYP_FUN	0x3	/* function pointer */
51204431Sraj
52204431Sraj#define MS_PARAM(ins,arg,typ) \
53204431Sraj	(((ins<<MS_INS_OFFSET) & MS_INS_MASK) | \
54204431Sraj	 ((arg<<MS_ARG_OFFSET) & MS_ARG_MASK) | \
55204431Sraj	 ((typ<<MS_TYP_OFFSET) & MS_TYP_MASK))
56204431Sraj
57204431Sraj#define MS_INS(param) ((param & MS_INS_MASK) >> MS_INS_OFFSET)
58204431Sraj#define MS_ARG(param) ((param & MS_ARG_MASK) >> MS_ARG_OFFSET)
59204431Sraj#define MS_TYP(param) ((param & MS_TYP_MASK) >> MS_TYP_OFFSET)
60204431Sraj
61204431Sraj/* microsequence opcodes - do not change! */
62204431Sraj#define MS_OP_GET       0	/* get <ptr>, <len>			*/
63204431Sraj#define MS_OP_PUT       1	/* put <ptr>, <len>			*/
64204431Sraj
65204431Sraj#define MS_OP_RFETCH	2	/* rfetch <reg>, <mask>, <ptr>		*/
66204431Sraj#define MS_OP_RSET	3	/* rset <reg>, <mask>, <mask>		*/
67204431Sraj#define MS_OP_RASSERT	4	/* rassert <reg>, <mask>		*/
68204431Sraj#define MS_OP_DELAY     5	/* delay <val>				*/
69204431Sraj#define MS_OP_SET       6	/* set <val>				*/
70204431Sraj#define MS_OP_DBRA      7	/* dbra <offset>			*/
71204431Sraj#define MS_OP_BRSET     8	/* brset <mask>, <offset>		*/
72204431Sraj#define MS_OP_BRCLEAR   9	/* brclear <mask>, <offset>		*/
73204431Sraj#define MS_OP_RET       10	/* ret <retcode>			*/
74204431Sraj#define MS_OP_C_CALL	11	/* c_call <function>, <parameter>	*/
75204431Sraj#define MS_OP_PTR	12	/* ptr <pointer>			*/
76204431Sraj#define MS_RESERVED_1	13	/* reserved				*/
77204433Sraj#define MS_RESERVED_2	14	/* reserved				*/
78204431Sraj#define MS_OP_SUBRET	15	/* subret <code>			*/
79204431Sraj#define MS_OP_CALL	16	/* call <microsequence>			*/
80204431Sraj#define MS_OP_RASSERT_P	17	/* rassert_p <iter>, <reg>		*/
81204431Sraj#define MS_OP_RFETCH_P	18	/* rfetch_p <iter>, <reg>, <mask>	*/
82204431Sraj#define MS_OP_TRIG	19	/* trigger <reg>, <len>, <array>	*/
83204431Sraj
84204431Sraj/* common masks */
85204431Sraj#define MS_CLEAR_ALL	0x0
86204431Sraj#define MS_ASSERT_NONE	0x0
87204431Sraj#define MS_ASSERT_ALL	0xff
88204431Sraj#define MS_FETCH_ALL	0xff
89204431Sraj
90204431Sraj/* undefined parameter value */
91204431Sraj#define MS_UNKNOWN	0
92204431Sraj
93204433Sraj/* these are register numbers according to our PC-like parallel port model */
94204431Sraj#define MS_REG_DTR	0x0
95204431Sraj#define MS_REG_STR	0x1
96204431Sraj#define MS_REG_CTR	0x2
97204433Sraj#define MS_REG_EPP	0x4
98204431Sraj
99204431Sraj/*
100204433Sraj * Microsequence macro abstraction level
101204431Sraj */
102204433Sraj
103204431Sraj/* register operations */
104204431Sraj#define MS_RSET(reg,assert,clear) { MS_OP_RSET, { reg, assert, clear} }
105204431Sraj#define MS_RASSERT(reg,byte)	  { MS_OP_RASSERT, { reg, byte } }
106204431Sraj#define MS_RCLR(reg,clear)	  { MS_OP_RSET, { reg, MS_ASSERT_NONE, clear } }
107204433Sraj
108204431Sraj#define MS_RFETCH(reg,mask,ptr) { MS_OP_RFETCH, { reg, mask, ptr } }
109204431Sraj
110204431Sraj/* trigger the port with array[char, delay,...] */
111204431Sraj#define MS_TRIG(reg,len,array)	{ MS_OP_TRIG, { reg, len, array } }
112204431Sraj
113204431Sraj/* assert/fetch from/to ptr */
114204433Sraj#define MS_RASSERT_P(n,reg)	  { MS_OP_RASSERT_P, { n, reg } }
115204433Sraj#define MS_RFETCH_P(n,reg,mask)	  { MS_OP_RFETCH_P, { n, reg, mask } }
116204431Sraj
117204433Sraj/* ptr manipulation */
118204431Sraj#define MS_PTR(ptr)	{ MS_OP_PTR, { ptr } }
119204431Sraj
120204433Sraj#define MS_DASS(byte) MS_RASSERT(MS_REG_DTR,byte)
121204433Sraj#define MS_SASS(byte) MS_RASSERT(MS_REG_STR,byte)
122204433Sraj#define MS_CASS(byte) MS_RASSERT(MS_REG_CTR,byte)
123204433Sraj
124204433Sraj#define MS_SET(offset)		{ MS_OP_SET, { offset } }
125204431Sraj#define MS_BRSET(mask,offset)	{ MS_OP_BRSET, { mask, offset } }
126204433Sraj#define MS_DBRA(offset)		{ MS_OP_DBRA, { offset } }
127204433Sraj
128204433Sraj/* C function or submicrosequence call */
129204433Sraj#define MS_C_CALL(function,parameter) \
130204433Sraj		{ MS_OP_C_CALL, { function, parameter } }
131204433Sraj#define MS_CALL(microseq) { MS_OP_CALL, { microseq } }
132204433Sraj
133204433Sraj/* mode dependent read/write operations
134204431Sraj * ppb_MS_xxx_init() call required otherwise default is
135204431Sraj * IEEE1284 operating mode */
136204433Sraj#define MS_PUT(ptr,len) { MS_OP_PUT, { ptr, len } }
137204433Sraj#define MS_GET(ptr,len) { MS_OP_GET, { ptr, len } }
138204431Sraj
139204433Sraj/* delay in microseconds */
140204431Sraj#define MS_DELAY(delay) { MS_OP_DELAY, { delay } }
141204431Sraj
142204431Sraj/* return from submicrosequence execution or microseqence execution */
143204431Sraj#define MS_SUBRET(code)	{ MS_OP_SUBRET,	{ code } }
144204431Sraj#define MS_RET(code)	{ MS_OP_RET, { code } }
145204431Sraj
146204431Sraj/*
147204431Sraj * Function abstraction level
148204431Sraj */
149204431Sraj
150204431Sraj#define ppb_MS_GET_init(dev,body) ppb_MS_init(dev, body, MS_OP_GET)
151204431Sraj
152204431Sraj#define ppb_MS_PUT_init(dev,body) ppb_MS_init(dev, body, MS_OP_PUT)
153204431Sraj
154204431Srajextern int ppb_MS_init(
155204431Sraj		struct ppb_device *,		/* ppbus device */
156204431Sraj		struct ppb_microseq *,		/* loop msq to assign */
157204431Sraj		int opcode			/* MS_OP_GET, MS_OP_PUT */
158204431Sraj		);
159204431Sraj
160204431Srajextern int ppb_MS_init_msq(
161204431Sraj		struct ppb_microseq *,
162204431Sraj		int,				/* number of parameters */
163204431Sraj		...				/* descriptor, value, ... */
164204431Sraj		);
165204431Sraj
166204431Srajextern int ppb_MS_exec(
167204431Sraj		struct ppb_device *,		/* ppbus device */
168204431Sraj		int,				/* microseq opcode */
169204431Sraj		union ppb_insarg,		/* param1 */
170204431Sraj		union ppb_insarg,		/* param2 */
171204431Sraj		union ppb_insarg,		/* param3 */
172204431Sraj		int *				/* returned value */
173204431Sraj		);
174204431Sraj
175204431Srajextern int ppb_MS_loop(
176204433Sraj		struct ppb_device *,		/* ppbus device */
177204433Sraj		struct ppb_microseq *,		/* prologue msq of loop */
178204431Sraj		struct ppb_microseq *,		/* body msq of loop */
179204431Sraj		struct ppb_microseq *,		/* epilogue msq of loop */
180204431Sraj		int,				/* number of iter */
181204433Sraj		int *				/* returned value */
182204433Sraj		);
183204433Sraj
184204433Srajextern int ppb_MS_microseq(
185204433Sraj		struct ppb_device *,		/* ppbus device */
186204431Sraj		struct ppb_microseq *,		/* msq to execute */
187204431Sraj		int *				/* returned value */
188204431Sraj		);
189204431Sraj
190204431Sraj#endif
191204431Sraj