~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/tools/fg-servers/dtserver/dasmd.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2 Dasm_Driver: dasmd.c
  3 
  4 Dasm driver for dasm-to-tina interface
  5 
  6 Author: A. J. Lacey
  7 Date  : 11-1-93
  8 */
  9 
 10 #include <stdio.h>
 11 #include <stdlib.h>
 12 #include <string.h>
 13 #include <math.h>
 14 #include <grabdefs.h>
 15 #include <grabsrv.h>
 16 #include <dasm.h>
 17 
 18 /*
 19         Definitions
 20 */
 21 
 22 #define BLOCK_SIZE 512
 23 #define BUFFER_SIZE 4096
 24 #define LB1_LSB 3
 25 #define LB1_MSB 0
 26 #define LB2_LSB 3
 27 #define LB2_MSB 0
 28 
 29 
 30 /*
 31         Channels
 32 */
 33 
 34         static int      channel1 = 0xb7;
 35         static int      channel2 = 0xd7;
 36         static int      channel3 = 0xf7;
 37         static int      ch1 = 1;
 38         static int      ch2 = 2;
 39         static int      ch3 = 3;
 40         static int  lba = LB1_LSB;
 41         static int  lbb = LB1_MSB;
 42         
 43 /*
 44         Opcode definitions for DASM 
 45 */
 46 
 47         static unsigned char config[BLOCK_SIZE] = 
 48                 { 44, 0, 0xff };
 49         static unsigned char grab_image[BLOCK_SIZE] = 
 50                 { 132, 0, 0, 1, 1, 0xb7, LB1_MSB, LB1_LSB, 0xff };
 51         int target_handle;
 52 
 53 
 54 
 55 int               x_dasm_com(command)
 56 unsigned char command[BLOCK_SIZE];
 57 {
 58         extern  int             suppress;
 59         int                     err = 0;
 60 
 61         if (!suppress)
 62                 printf("%s: command %d, %d, %d sent to dasm\n", DASM_SERVICE,
 63                                 command[0], command[3], command[5]);
 64 
 65         err = write_scsi(target_handle, command, (long)0, 1);
 66 
 67         if (!suppress)
 68                 printf("%s: status %d recieved from dasm\n", DASM_SERVICE, err);
 69 
 70         return err;
 71 }
 72 
 73 
 74 
 75 int     get_handle()
 76 {
 77         target_handle = initialize_scsi(TARGET_DASM);
 78         if (target_handle == -1)
 79            return (-1);
 80 }
 81 
 82 
 83 int     initialise_dasm(width, length, spacing, type)
 84 int     width, length, spacing;
 85 int     type;
 86 {
 87 /*
 88         Function:
 89                 
 90         - configure the DASM to its initial state using the dconfig opcode
 91         - download image configuration information
 92           Note: spacing = scan rate
 93 */
 94 
 95         unsigned char   com_buf[BLOCK_SIZE];
 96         unsigned char   err_msg[512];
 97         unsigned int    start_line, stop_line;
 98         unsigned int    start_pixel, stop_pixel;
 99         int                     err;
100 
101 /*
102         Calculate configuration data
103 */
104         start_line = ((480 - (length * spacing))/2) + 1;
105         stop_line = start_line + (length * spacing) - 1;
106         start_pixel = ((640 - (width * spacing))/2) + 1;
107         stop_pixel = start_pixel + (width * spacing) - 1;
108         
109 /*
110         Run dconfig routine on DASM
111 */
112         if (config_dasm() < 0)
113                 return (-1);     
114 /*
115         Generate and send configuration data to DASM
116 */
117 
118         com_buf[0] = 129;
119         com_buf[1] = 0;
120         com_buf[2] = spacing;   
121         com_buf[3] = 1;
122         com_buf[4] = 255;
123         com_buf[5] = 1;
124         com_buf[6] = start_line>>8;
125         com_buf[7] = start_line;
126         com_buf[8] = stop_line>>8;
127         com_buf[9] = stop_line;
128         com_buf[10]= start_pixel>>8;
129         com_buf[11]= start_pixel;
130         com_buf[12]= stop_pixel>>8;
131         com_buf[13]= stop_pixel;
132         com_buf[14]= 0xff;
133 
134         switch (type)
135         {
136                 case MONO_IM:
137                         com_buf[3] = ch1;
138                         break;
139 
140                 case LEFT_IM:
141                         com_buf[3] = ch1;
142                         break;
143 
144                 case RIGHT_IM:
145                         com_buf[3] = ch2;
146                         break;
147         }
148 
149         if ((err = x_dasm_com(com_buf)) < 0)
150         {
151                 sprintf(err_msg,"%s server: DASM configuration error", DASM_SERVICE);
152                 perror(err_msg);
153                 return -1;
154          }
155          
156         return err;
157 }
158 
159 
160 
161 int      up_load(data_hole)
162 Grabber *data_hole;
163 {
164 /*
165         Function:
166 
167         - retrieve the captured image from the DASM box and place it in the
168           host memory at the location specified by the pointer; buffer
169 */
170         double                  image_size;
171         char               *buffer;
172         char                    temp_buf[BUFFER_SIZE];
173         unsigned char   err_mssg[512];
174         unsigned int    start, stop;
175         unsigned int    blocks; 
176         unsigned int    buf_size, i;
177         int                     err;
178 
179 /*
180         Calculate SCSI information
181 */
182         blocks = BUFFER_SIZE/BLOCK_SIZE;        
183         image_size = (data_hole->width) * (data_hole->length);
184         start = data_hole->count;
185         stop = start + ceil(image_size/BLOCK_SIZE);
186 
187 /*
188         Assign memory address to buffer
189 */
190         buffer = data_hole->im_buffer;
191 /*
192         Read from DASM
193 */
194         for (i = start; i < stop; i += blocks)
195             {
196                 if ((err = read_scsi(target_handle, temp_buf, (long)(lba + lbb + i), blocks)) != 0)
197                    {
198                         sprintf(err_mssg,"%s server: scsi read error", DASM_SERVICE);
199                         perror(err_mssg);
200                         return -1;
201                    }
202 /*
203         Transfer data to main buffer
204 */
205                   else
206                    {
207                         memcpy(buffer, temp_buf, BUFFER_SIZE);
208                         buffer += BUFFER_SIZE;
209                    }
210             }
211 /*
212         Calculate total number of bytes retrieved
213 */
214         data_hole->count = stop;
215 
216         buf_size = stop * BLOCK_SIZE;
217         return buf_size;
218 
219 }
220 
221 
222 
223 int     grab_sequence(number)
224 int     number;
225 {
226 
227         unsigned char   com_buf[20];
228         int                     err;
229         
230         com_buf[0] = 0x9a;
231         com_buf[1] = 0;
232         com_buf[2] = number>>8;
233         com_buf[3] = number;
234         com_buf[4] = number>>8;
235         com_buf[5] = number;
236         com_buf[6] = 0;
237         com_buf[7] = lba;
238         com_buf[8] = 0;
239         com_buf[9] = 0;
240         com_buf[10] = 0;
241         com_buf[11] = 0;
242         com_buf[12] = 0xff;
243 
244         if ((err = x_dasm_com(com_buf)) < 0)
245                         return (-1);
246 
247         return (0);
248 }
249 
250 
251 
252 int     config_dasm()
253 {
254 
255         char            buf[BLOCK_SIZE];
256         int             err;
257 
258         if ((err = x_dasm_com(config)) < 0)
259            {
260                 sprintf(buf,"%s server: config error", DASM_SERVICE);
261                 perror(buf);
262                 return -1;
263            }
264 
265 /*
266         Read and dump configuration information
267 */
268 
269         if ((err = read_scsi(target_handle, buf, (long)1, 1)) != 0)
270            {
271                 sprintf(buf,"%s server: config error", DASM_SERVICE);
272                 perror(buf);
273                 return (-1);
274            }
275 
276         return (0);
277 }
278 
279 
280 
281 int             dasmd(params, type)
282 Grabber    *params;
283 int                     type;
284 {
285 /*
286         Function:
287 
288         - Initialise host memory
289         - Initialise DASM box
290         - Configure DASM box
291         - Grab image 
292         - Upload image from DASM box to host
293 */
294         unsigned char   err_msg[512];
295         int                             error;
296 
297         if (get_handle() < 0)
298                 return (-1);
299 /*
300         If only a configuration (signalled by spacing = 0)
301 */
302         
303         if (params->spacing == 0)
304         {
305                 config_dasm();
306                 return CONFIG;
307         }
308 
309         if ((error = initialise_dasm(   params->width,
310                                                                         params->length,
311                                                                         params->spacing,
312                                                                         type)) < 0)
313                 return error;
314 
315 /*
316         Get image(s)
317 */
318         if ((params->number > 1) && (type == MONO_IM))
319         {
320 
321                 if ((error = grab_sequence(params->number)) < 0)
322                 {
323                         sprintf(err_msg,"%s server: DASM grab sequence error", DASM_SERVICE);
324                         perror(err_msg);
325                         return error;
326                 }
327         }
328 
329         else
330         if ((type == MONO_IM) || (type == LEFT_IM)  || (type == RIGHT_IM))
331         {               
332                 switch (type)
333                 {
334                         case MONO_IM:
335                                 grab_image[5] = channel1;
336                                 lbb = LB1_MSB;
337                                 lba = LB1_LSB;
338                                 break;
339 
340                         case LEFT_IM:
341                                 grab_image[5] = channel1;
342                                 lbb = LB1_MSB;
343                                 lba = LB1_LSB;
344                                 break;
345 
346                         case RIGHT_IM:
347                                 grab_image[5] = channel2;
348                                 lbb = LB2_MSB;
349                                 lba = LB2_LSB;
350                                 break;
351                 }
352 
353                 grab_image[6] = lbb;
354                 grab_image[7] = lba;
355 
356                 if ((error = x_dasm_com(grab_image)) < 0)
357                 {
358                         sprintf(err_msg,"%s server: grab image error");
359                         perror(err_msg);
360                         return error;
361                 }
362         }
363 
364         return error;   
365 }
366 
367 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.