2 Copyright © 2015, The AROS Development Team. All rights reserved.
8 #include <aros/debug.h>
9 #include <aros/symbolsets.h>
10 #include <aros/libcall.h>
11 #include <proto/kernel.h>
12 #include <proto/exec.h>
13 #include <proto/gpio.h>
15 #include "gpio_private.h"
17 APTR KernelBase
__attribute__((used
)) = NULL
;
19 static int gpio_init(struct GPIOBase
*GPIOBase
)
23 D(bug("[GPIO] %s()\n", __PRETTY_FUNCTION__
));
25 KernelBase
= OpenResource("kernel.resource");
27 if ((GPIOBase
->gpio_periiobase
= KrnGetSystemAttr(KATTR_PeripheralBase
)) != 0)
29 InitSemaphore(&GPIOBase
->gpio_Sem
);
31 D(bug("[GPIO] %s: Initialised Semaphore @ 0x%p\n", __PRETTY_FUNCTION__
, &GPIOBase
->gpio_Sem
));
38 AROS_LH2(void, GPIOSet
,
39 AROS_LHA( unsigned int, pin
, D0
),
40 AROS_LHA( unsigned int, val
, D1
),
41 struct GPIOBase
*, GPIOBase
, 1, Gpio
)
45 volatile unsigned int reg
;
48 D(bug("[GPIO] %s(#%d,%d)\n", __PRETTY_FUNCTION__
, pin
, val
));
50 if (GPIOBase
->gpio_periiobase
&& (pin
<= 53))
52 reg
= val
? GPSET0
: GPCLR0
;
53 reg
+= (pin
>> 5) << 2; /* (pin / 32) << 2 */
55 bit
= 1 << (pin
& 0x1F);
57 ObtainSemaphore(&GPIOBase
->gpio_Sem
);
59 *(volatile unsigned int *)reg
= bit
;
61 ReleaseSemaphore(&GPIOBase
->gpio_Sem
);
67 AROS_LH2(void, GPIOSetFunc
,
68 AROS_LHA( unsigned int, pin
, D0
),
69 AROS_LHA( unsigned int, func
, D1
),
70 struct GPIOBase
*, GPIOBase
, 2, Gpio
)
74 volatile unsigned int reg
;
76 D(bug("[GPIO] %s(#%d,%d)\n", __PRETTY_FUNCTION__
, pin
, func
));
78 if (GPIOBase
->gpio_periiobase
&& (pin
<= 53))
89 ObtainSemaphore(&GPIOBase
->gpio_Sem
);
91 *(volatile unsigned int *)reg
= func
;
93 ReleaseSemaphore(&GPIOBase
->gpio_Sem
);
99 ADD2INITLIB(gpio_init
, 0)