2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
9 #include <exec/types.h>
10 #include <proto/exec.h>
11 #include <devices/timer.h>
13 #include "card_intern.h"
15 void pcmcia_newowner(struct CardResource
*CardResource
, BOOL doNotify
)
17 struct CardHandle
*handle
= NULL
, *nexthandle
;
18 CARDDEBUG(bug("pcmcia_newowner: n=%d owned=%x rem=%d listempty=%d\n",
19 doNotify
, CardResource
->ownedcard
, CardResource
->removed
, IsListEmpty(&CardResource
->handles
)));
21 ForeachNode(&CardResource
->handles
, nexthandle
) {
22 CARDDEBUG(bug("Possible node %p flags %02x\n", nexthandle
, nexthandle
->cah_CardFlags
));
23 if (!(nexthandle
->cah_CardFlags
& CARDF_USED
)) {
28 if (handle
!= NULL
&& CardResource
->ownedcard
== NULL
&& CardResource
->removed
== FALSE
) {
29 CardResource
->ownedcard
= handle
;
30 CardResource
->resetberr
= (CardResource
->ownedcard
->cah_CardFlags
& CARDF_RESETREMOVE
) ? GAYLE_IRQ_RESET
: 0;
31 CARDDEBUG(bug("pcmcia_newowner: %p\n", CardResource
->ownedcard
));
32 CardResource
->ownedcard
->cah_CardFlags
|= CARDF_USED
;
33 if (doNotify
&& CardResource
->ownedcard
->cah_CardInserted
) {
34 CARDDEBUG(bug("Executing cah_CardInserted(%p, %p)\n",
35 CardResource
->ownedcard
->cah_CardInserted
->is_Data
,
36 CardResource
->ownedcard
->cah_CardInserted
->is_Code
));
37 AROS_CARDC(CardResource
->ownedcard
->cah_CardInserted
->is_Code
,
38 CardResource
->ownedcard
->cah_CardInserted
->is_Data
, 0);
44 void pcmcia_removeowner(struct CardResource
*CardResource
)
46 CARDDEBUG(bug("pcmcia_removeowner: owned=%p\n", CardResource
->ownedcard
));
48 if (CardResource
->ownedcard
!= NULL
) {
49 if (CardResource
->ownedcard
->cah_CardRemoved
) {
50 CARDDEBUG(bug("Executing cah_CardRemoved(%p, %p)\n",
51 CardResource
->ownedcard
->cah_CardRemoved
->is_Data
,
52 CardResource
->ownedcard
->cah_CardRemoved
->is_Code
));
53 AROS_CARDC(CardResource
->ownedcard
->cah_CardRemoved
->is_Code
,
54 CardResource
->ownedcard
->cah_CardRemoved
->is_Data
, 0);
60 void CardTask(struct Task
*parent
, struct CardResource
*CardResource
)
64 signal
= AllocSignal(-1);
65 CardResource
->signalmask
= 1 << signal
;
67 CardResource
->timermp
= CreateMsgPort();
68 CardResource
->timerio
= (struct timerequest
*) CreateIORequest(CardResource
->timermp
, sizeof(struct timerequest
));
69 if (!CardResource
->timermp
|| !CardResource
->timerio
)
70 Alert(AT_DeadEnd
| AG_NoMemory
);
71 if (OpenDevice("timer.device", UNIT_MICROHZ
, (struct IORequest
*)CardResource
->timerio
, 0))
72 Alert(AT_DeadEnd
| AG_OpenDev
);
74 Signal(parent
, SIGBREAKF_CTRL_F
);
80 Wait(CardResource
->signalmask
);
82 CARDDEBUG(bug("CardTask woken up\n"));
84 CardResource
->changecount
++;
88 if (CardResource
->removed
== FALSE
) {
89 CardResource
->removed
= TRUE
;
90 pcmcia_removeowner(CardResource
);
96 /* Debounce wait, not sure if needed */
98 CardResource
->timerio
->tr_node
.io_Command
= TR_ADDREQUEST
;
99 CardResource
->timerio
->tr_time
.tv_secs
= 0;
100 CardResource
->timerio
->tr_time
.tv_micro
= 100000;
101 DoIO((struct IORequest
*)CardResource
->timerio
);
102 if (gotstatus
&& status
== pcmcia_havecard())
104 status
= pcmcia_havecard();
108 CARDDEBUG(bug("PCMCIA changecnt=%d removed=%d\n", CardResource
->changecount
, status
== FALSE
));
110 CardResource
->timerio
->tr_time
.tv_secs
= 0;
111 CardResource
->timerio
->tr_time
.tv_micro
= 10000;
112 DoIO((struct IORequest
*)CardResource
->timerio
);
114 SetSignal(0, CardResource
->signalmask
);
116 CardResource
->removed
= status
== FALSE
;
118 pcmcia_reset(CardResource
);
120 CardResource
->disabled
= FALSE
;
121 pcmcia_clear_requests(CardResource
);
122 pcmcia_enable_interrupts();
126 if (CardResource
->removed
== FALSE
) {
127 pcmcia_cardreset(CardResource
);
128 pcmcia_newowner(CardResource
, TRUE
);