Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / demos / multiple_timers.c
blob9b2c0ccd8559267a331db0101abeb2e7fd901740
1 /*
2 * Copyright (c) 1992 Commodore-Amiga, Inc.
3 *
4 * This example is provided in electronic form by Commodore-Amiga, Inc. for
5 * use with the "Amiga ROM Kernel Reference Manual: Devices", 3rd Edition,
6 * published by Addison-Wesley (ISBN 0-201-56775-X).
7 *
8 * The "Amiga ROM Kernel Reference Manual: Devices" contains additional
9 * information on the correct usage of the techniques and operating system
10 * functions presented in these examples. The source and executable code
11 * of these examples may only be distributed in free electronic form, via
12 * bulletin board or as part of a fully non-commercial and freely
13 * redistributable diskette. Both the source and executable code (including
14 * comments) must be included, without modification, in any copy. This
15 * example may not be published in printed form or distributed with any
16 * commercial product. However, the programming techniques and support
17 * routines set forth in these examples may be used in the development
18 * of original executable software products for Commodore Amiga computers.
20 * All other rights reserved.
22 * This example is provided "as-is" and is subject to change; no
23 * warranties are made. All use is at your own risk. No liability or
24 * responsibility is assumed.
26 *****************************************************************************
28 * Multiple_Timers.c
30 * This program is designed to do multiple (3) time requests using one
31 * OpenDevice. It creates a message port - TimerMP, creates an
32 * extended I/O structure of type timerequest named TimerIO[0] and
33 * then uses that to open the device. The other two time request
34 * structures - TimerIO[1] and TimerIO[2] - are created using AllocMem
35 * and then copying TimerIO[0] into them. The tv_secs field of each
36 * structure is set and then three SendIOs are done with the requests.
37 * The program then goes into a while loop until all messages are received.
39 * Compile with SAS C 5.10 lc -b1 -cfistq -v -y -L
41 * Run from CLI only
44 #include <exec/types.h>
45 #include <exec/memory.h>
46 #include <devices/timer.h>
48 #include <proto/exec.h>
49 #include <clib/alib_protos.h>
51 #include <stdio.h>
53 #ifdef LATTICE
54 int CXBRK(void) { return(0); } /* Disable Lattice CTRL/C handling */
55 int chkabort(void) { return(0); } /* really */
56 #endif
58 int main(void)
60 struct timerequest *TimerIO[3];
61 struct MsgPort *TimerMP;
62 struct Message *TimerMSG;
64 ULONG error,x,seconds[3]={4,1,2}, microseconds[3]={0,0,0};
66 int allin = 3;
67 char *position[]={"last","second","first"};
69 if ((TimerMP = CreatePort(0,0)))
71 if ((TimerIO[0] = (struct timerequest *)
72 CreateExtIO(TimerMP,sizeof(struct timerequest))))
74 /* Open the device once */
75 if (!(error=OpenDevice( TIMERNAME, UNIT_VBLANK,(struct IORequest *) TimerIO[0], 0L)))
77 /* Set command to TR_ADDREQUEST */
78 TimerIO[0]->tr_node.io_Command = TR_ADDREQUEST;
80 if ((TimerIO[1]=(struct timerequest *)
81 AllocMem(sizeof(struct timerequest),MEMF_PUBLIC | MEMF_CLEAR)))
83 if ((TimerIO[2]=(struct timerequest *)
84 AllocMem(sizeof(struct timerequest),MEMF_PUBLIC | MEMF_CLEAR)))
86 /* Copy fields from the request used to open the timer device */
87 *TimerIO[1] = *TimerIO[0];
88 *TimerIO[2] = *TimerIO[0];
90 /* Initialize other fields */
91 for (x=0;x<3;x++)
93 TimerIO[x]->tr_time.tv_secs = seconds[x];
94 TimerIO[x]->tr_time.tv_micro = microseconds[x];
95 printf("\nInitializing TimerIO[%ld]",x);
98 printf("\n\nSending multiple requests\n\n");
100 /* Send multiple requests asynchronously */
101 /* Do not got to sleep yet... */
102 SendIO((struct IORequest *)TimerIO[0]);
103 SendIO((struct IORequest *)TimerIO[1]);
104 SendIO((struct IORequest *)TimerIO[2]);
106 /* There might be other processing done here */
108 /* Now go to sleep with WaitPort() waiting for the requests */
109 while (allin)
111 WaitPort(TimerMP);
112 /* Get the reply message */
113 TimerMSG=GetMsg(TimerMP);
114 for (x=0;x<3;x++)
115 if (TimerMSG==(struct Message *)TimerIO[x])
116 printf("Request %ld finished %s\n",x,position[--allin]);
119 FreeMem(TimerIO[2],sizeof(struct timerequest));
122 else
123 printf("Error: could not allocate TimerIO[2] memory\n");
125 FreeMem(TimerIO[1],sizeof(struct timerequest));
128 else
129 printf("Error could not allocate TimerIO[1] memory\n");
131 CloseDevice((struct IORequest *) TimerIO[0]);
134 else
135 printf("\nError: Could not OpenDevice\n");
137 DeleteExtIO((struct IORequest *) TimerIO[0]);
140 else
141 printf("Error: could not create IORequest\n");
143 DeletePort(TimerMP);
146 else
147 printf("\nError: Could not CreatePort\n");
149 return 0;