revert between 56095 -> 55830 in arch
[AROS.git] / arch / m68k-amiga / lowlevel / addtimerint.c
blob6724adf156ce7df1150d98a705558c355dc57a28
1 /*
2 Copyright © 2017, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <aros/libcall.h>
8 #include <proto/cia.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)))
23 return CIAICRB_TA;
24 else if (!(AddICRVector(LowLevelBase->ll_CIA.llciat_Base, CIAICRB_TB, &LowLevelBase->ll_CIA.llciat_Int)))
25 return CIAICRB_TB;
27 LowLevelBase->ll_CIA.llciat_Base = NULL;
28 return -1;
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)
37 AROS_LIBFUNC_INIT
39 APTR result = NULL;
41 if (intRoutine)
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;
55 else
56 LowLevelBase->ll_CIA.llciat_Int.is_Code = NULL;
59 ReleaseSemaphore(&LowLevelBase->ll_Lock);
61 return result;
63 AROS_LIBFUNC_EXIT