2 Copyright � 2015, The AROS Development Team. All rights reserved.
8 #include <aros/debug.h>
9 #include <aros/macros.h>
10 #include <aros/symbolsets.h>
11 #include <aros/libcall.h>
12 #include <proto/kernel.h>
13 #include <proto/exec.h>
14 #include <proto/gpio.h>
16 #include "gpio_private.h"
18 APTR KernelBase
__attribute__((used
)) = NULL
;
20 static int gpio_init(struct GPIOBase
*GPIOBase
)
24 D(bug("[GPIO] %s()\n", __PRETTY_FUNCTION__
));
26 KernelBase
= OpenResource("kernel.resource");
28 if ((GPIOBase
->gpio_periiobase
= KrnGetSystemAttr(KATTR_PeripheralBase
)) != 0)
30 InitSemaphore(&GPIOBase
->gpio_Sem
);
32 D(bug("[GPIO] %s: Initialised Semaphore @ 0x%p\n", __PRETTY_FUNCTION__
, &GPIOBase
->gpio_Sem
));
39 AROS_LH2(void, GPIOSet
,
40 AROS_LHA( unsigned int, pin
, D0
),
41 AROS_LHA( unsigned int, val
, D1
),
42 struct GPIOBase
*, GPIOBase
, 1, Gpio
)
46 volatile unsigned int reg
;
49 D(bug("[GPIO] %s(#%d,%d)\n", __PRETTY_FUNCTION__
, pin
, val
));
51 if (GPIOBase
->gpio_periiobase
&& (pin
<= 53))
53 reg
= val
? GPSET0
: GPCLR0
;
54 reg
+= (pin
>> 5) << 2; /* (pin / 32) << 2 */
56 bit
= 1 << (pin
& 0x1F);
58 ObtainSemaphore(&GPIOBase
->gpio_Sem
);
60 *(volatile unsigned int *)reg
= AROS_LONG2LE(bit
);
62 ReleaseSemaphore(&GPIOBase
->gpio_Sem
);
68 AROS_LH2(void, GPIOSetFunc
,
69 AROS_LHA( unsigned int, pin
, D0
),
70 AROS_LHA( unsigned int, func
, D1
),
71 struct GPIOBase
*, GPIOBase
, 2, Gpio
)
75 volatile unsigned int reg
;
77 D(bug("[GPIO] %s(#%d,%d)\n", __PRETTY_FUNCTION__
, pin
, func
));
79 if (GPIOBase
->gpio_periiobase
&& (pin
<= 53))
90 ObtainSemaphore(&GPIOBase
->gpio_Sem
);
92 *(volatile unsigned int *)reg
= AROS_LONG2LE(func
);
94 ReleaseSemaphore(&GPIOBase
->gpio_Sem
);
100 ADD2INITLIB(gpio_init
, 0)