2 Copyright © 2017, The AROS Development Team. All rights reserved.
6 #include <aros/libcall.h>
10 #include <exec/types.h>
11 #include <libraries/lowlevel.h>
12 #include <hardware/cia.h>
13 #include <resources/cia.h>
15 #include "lowlevel_intern.h"
17 /* Attempt to open the specified cia resource, and add the timer interrupt ... */
18 WORD
FindFreeTimer(char *timeres
, struct LowLevelBase
*LowLevelBase
)
20 if ((LowLevelBase
->ll_CIA
.llciat_Base
= OpenResource(timeres
)) != NULL
)
22 if (!(AddICRVector(LowLevelBase
->ll_CIA
.llciat_Base
, CIAICRB_TA
, &LowLevelBase
->ll_CIA
.llciat_Int
)))
24 else if (!(AddICRVector(LowLevelBase
->ll_CIA
.llciat_Base
, CIAICRB_TB
, &LowLevelBase
->ll_CIA
.llciat_Int
)))
27 LowLevelBase
->ll_CIA
.llciat_Base
= NULL
;
31 /* Public Implementation ... */
32 AROS_LH2(APTR
, AddTimerInt
,
33 AROS_LHA(APTR
, intRoutine
, A0
),
34 AROS_LHA(APTR
, intData
, A1
),
35 struct LowLevelBase
*, LowLevelBase
, 13, LowLevel
)
43 ObtainSemaphore(&LowLevelBase
->ll_Lock
);
45 if (LowLevelBase
->ll_CIA
.llciat_Int
.is_Code
== NULL
)
47 LowLevelBase
->ll_CIA
.llciat_Int
.is_Code
= intRoutine
;
48 LowLevelBase
->ll_CIA
.llciat_Int
.is_Data
= intData
;
49 if ((LowLevelBase
->ll_CIA
.llciat_iCRBit
= FindFreeTimer(CIAANAME
, LowLevelBase
)) == -1)
51 LowLevelBase
->ll_CIA
.llciat_iCRBit
= FindFreeTimer(CIABNAME
, LowLevelBase
);
53 if (LowLevelBase
->ll_CIA
.llciat_Base
&& (LowLevelBase
->ll_CIA
.llciat_iCRBit
!= -1))
54 result
= (APTR
)&LowLevelBase
->ll_CIA
.llciat_Int
;
56 LowLevelBase
->ll_CIA
.llciat_Int
.is_Code
= NULL
;
59 ReleaseSemaphore(&LowLevelBase
->ll_Lock
);