23extern u32 openSlots[2];
28extern int padman_init;
30static void UpdatePadThread(
void *arg)
38 ReferThreadStatus(
TH_SELF, &tstatus);
43 WaitClearEvent(pstate->eventflag, EF_UPDATE_PAD, WEF_AND|WEF_CLEAR, NULL);
46 if( ReadData(pstate) == 1)
50 if( (pstate->outbuffer[2] != 0x5a) || ( pstate->outbuffer[1] != pstate->modeCurId) || (pstate->outbuffer[1] == 0xf3) )
52 pstate->buttonDataReady = 0;
53 pstate->state = PAD_STATE_EXECCMD ;
54 pstate->currentTask = TASK_QUERY_PAD;
55 StartThread(pstate->querypadTid, NULL);
62 pstate->buttonStatus[i] = pstate->outbuffer[i];
64 pstate->buttonDataReady = 1;
66 if(pstate->modeConfig == MODE_CONFIG_QUERY_PAD)
67 pstate->state = PAD_STATE_FINDCTP1;
69 pstate->state = PAD_STATE_STABLE ;
71 if( (pstate->reqState == PAD_RSTAT_BUSY) && (pstate->runTask == TASK_NONE))
72 pstate->reqState = PAD_RSTAT_COMPLETE;
77 pstate->buttonDataReady = 0;
78 pstate->state = PAD_STATE_ERROR;
79 pstate->findPadRetries++;
81 res += pdGetError( pstate->port, pstate->slot );
85 pstate->currentTask = TASK_QUERY_PAD;
86 StartThread(pstate->querypadTid, NULL);
92static void QueryPadThread(
void *arg)
103 ReferThreadStatus(
TH_SELF, &tinfo);
107 pstate->modeConfig = 0;
108 pstate->modeCurId = 0;
110 pstate->numModes = 0;
111 pstate->numActuators = 0;
112 pstate->numActComb = 0;
116 pstate->buttonInfo[i] = 0;
117 pstate->buttonMask[i] = 0;
120 pstate->buttonDataReady = 0;
121 pstate->ee_actDirectSize = 0;
122 pstate->findPadRetries = 0;
123 pstate->modeCurId = 0;
126 D_PRINTF(
"QueryPadThread: Checking for pad (%i,%i)\n", pstate->port, pstate->slot);
130 WaitClearEvent( pstate->eventflag, EF_QUERY_PAD, WEF_AND|WEF_CLEAR, NULL);
132 res = PadIsSupported(pstate);
136 if(pstate->modeCurId != 0xFF)
138 modeCurId = pstate->modeCurId;
139 pstate->modeCurId = 0;
140 pstate->state = PAD_STATE_EXECCMD;
144 pstate->state = PAD_STATE_DISCONN;
145 pstate->disconnected = 1;
150 pstate->state = PAD_STATE_DISCONN;
151 pstate->disconnected = 1;
154 while( (res != 1) || (pstate->modeCurId == 0xFF) );
157 if(pstate->disconnected != 0)
160 pstate->ee_actAlignData.data[i] = 0xFF;
163 D_PRINTF(
"Found pad (%i,%i) - modeCurId: 0x%x\n", (
int)pstate->port, (
int)pstate->slot, (
int)modeCurId);
167 for(i=0; (i < 10) && (res != 1); i++)
169 WaitClearEvent( pstate->eventflag, EF_QUERY_PAD, WEF_AND|WEF_CLEAR, NULL);
171 res = EnterConfigMode(modeCurId, pstate);
173 if(res == 1) pstate->modeConfig = MODE_CONFIG_READY;
178 D_PRINTF(
"EnterConfigMode (%i, %i): Failed\n", (
int)pstate->port, (
int)pstate->slot);
180 pstate->modeConfig = MODE_CONFIG_QUERY_PAD;
181 pstate->modeCurId = modeCurId;
182 pstate->currentTask = TASK_UPDATE_PAD;
187 D_PRINTF(
"EnterConfigMode (%i, %i): Success\n", (
int)pstate->port, (
int)pstate->slot);
189 for(i=0,res=0; res != 1; i++)
191 WaitClearEvent( pstate->eventflag, EF_QUERY_PAD, WEF_AND|WEF_CLEAR, NULL);
192 res = QueryModel(pstate);
194 if((res != 1) && (i >= 10))
196 D_PRINTF(
"QueryModel (%i, %i): Failed\n",(
int)pstate->port, (
int)pstate->slot);
198 pstate->modeCurId = 0;
199 pstate->currentTask = TASK_UPDATE_PAD;
204 D_PRINTF(
"QueryModel (%i, %i): Success\n", (
int)pstate->port, (
int)pstate->slot);
206 if( (pstate->disconnected == 1) && (pstate->modeCurOffs != 0))
211 for(i=0,res=0; res != 1; i++)
213 WaitClearEvent( pstate->eventflag, EF_QUERY_PAD, WEF_AND|WEF_CLEAR, NULL);
215 res = SetMainMode(pstate);
219 D_PRINTF(
"SetMainMode (%i,%i): Success\n", (
int)pstate->port, (
int)pstate->slot);
220 D_PRINTF(
"QueryPadThread: Done (%i,%i)\n", (
int)pstate->port, (
int)pstate->slot);
222 pstate->modeCurId = 0;
223 pstate->currentTask = TASK_UPDATE_PAD;
224 pstate->disconnected = 0;
231 D_PRINTF(
"SetMainMode (%i, %i): Failed\n", (
int)pstate->port, (
int)pstate->slot);
233 pstate->reqState = PAD_RSTAT_FAILED;
234 pstate->currentTask = TASK_UPDATE_PAD;
243 for(i=0,res=0; res != 1; i++)
245 WaitClearEvent( pstate->eventflag, EF_QUERY_PAD, WEF_AND|WEF_CLEAR, NULL);
247 res = QueryAct(
count, pstate);
249 if((res != 1) && (i >= 10))
251 D_PRINTF(
"QueryAct (%i,%i): Failed\n", (
int)pstate->port, (
int)pstate->slot);
253 pstate->modeCurId = 0;
254 pstate->currentTask = TASK_UPDATE_PAD;
260 D_PRINTF(
"QueryAct (%i,%i): Success\n", (
int)pstate->port, (
int)pstate->slot);
264 for(i=0,res=0; res != 1; i++)
266 WaitClearEvent( pstate->eventflag, EF_QUERY_PAD, WEF_AND|WEF_CLEAR, NULL);
268 res = QueryComb(
count, pstate);
270 if((res != 1) && (i >= 10))
272 D_PRINTF(
"QueryComb (%i,%i): Failed\n", (
int)pstate->port, (
int)pstate->slot);
274 pstate->modeCurId = 0;
275 pstate->currentTask = TASK_UPDATE_PAD;
281 D_PRINTF(
"QueryComb (%i,%i): Success\n", (
int)pstate->port, (
int)pstate->slot);
285 for(i=0,res=0; res != 1; i++)
287 WaitClearEvent( pstate->eventflag, EF_QUERY_PAD, WEF_AND|WEF_CLEAR, NULL);
289 res = QueryMode(
count, pstate);
291 if((res != 1) && (i >= 10))
293 D_PRINTF(
"QueryMode (%i,%i): Failed\n", (
int)pstate->port, (
int)pstate->slot);
295 pstate->modeCurId = 0;
296 pstate->currentTask = TASK_UPDATE_PAD;
302 D_PRINTF(
"QueryMode (%i,%i): Success\n", (
int)pstate->port, (
int)pstate->slot);
304 for(i=0,res=0; res != 1; i++)
306 WaitClearEvent( pstate->eventflag, EF_QUERY_PAD, WEF_AND|WEF_CLEAR, NULL);
308 res = SetActAlign(pstate);
310 if((res != 1) && (i >= 10))
312 D_PRINTF(
"SetActAlign (%i,%i): Failed\n", (
int)pstate->port, (
int)pstate->slot);
314 pstate->reqState = PAD_RSTAT_FAILED;
315 pstate->currentTask = TASK_UPDATE_PAD;
320 D_PRINTF(
"SetActAlign (%i,%i): Success\n", (
int)pstate->port, (
int)pstate->slot);
322 if(((pstate->modeConfig & 0xFF) == 0x02) &&
323 ((pstate->model & 0x02) == 0x02))
325 for(i=0,res=0; res != 1; i++)
327 WaitClearEvent( pstate->eventflag, EF_QUERY_PAD, WEF_AND|WEF_CLEAR, NULL);
329 res = QueryButtonMask(pstate);
331 if((res != 1) && (i >= 10))
333 D_PRINTF(
"QueryButtonMask (%i,%i): Failed\n", (
int)pstate->port, (
int)pstate->slot);
335 pstate->modeCurId = 0;
336 pstate->currentTask = TASK_UPDATE_PAD;
341 D_PRINTF(
"QueryButtonMask (%i,%i): Success\n", (
int)pstate->port, (
int)pstate->slot);
344 for(i=0,res=0; res != 1; i++)
346 WaitClearEvent( pstate->eventflag, EF_QUERY_PAD, WEF_AND|WEF_CLEAR, NULL);
348 res = ExitConfigMode(pstate);
350 if((res != 1) && (i >= 10))
352 D_PRINTF(
"ExitConfigMode (%i,%i): Failed\n", (
int)pstate->port, (
int)pstate->slot);
354 pstate->modeCurId = 0;
355 pstate->currentTask = TASK_UPDATE_PAD;
360 D_PRINTF(
"ExitConfigMode (%i,%i): Success\n", (
int)pstate->port, (
int)pstate->slot);
362 for(i=0,res=0; res != 1; i++)
364 WaitClearEvent( pstate->eventflag, EF_QUERY_PAD, WEF_AND|WEF_CLEAR, NULL);
366 res = PadIsSupported(pstate);
368 if((res != 1) && (i >= 10))
370 D_PRINTF(
"PadIsSupported (%i,%i): Failed\n", (
int)pstate->port, (
int)pstate->slot);
372 pstate->modeCurId = 0;
373 pstate->currentTask = TASK_UPDATE_PAD;
378 D_PRINTF(
"PadIsSupported (%i,%i): Success\n", (
int)pstate->port, (
int)pstate->slot);
380 D_PRINTF(
"QueryPadThread: Done (%i,%i)\n", (
int)pstate->port, (
int)pstate->slot);
382 modeCurId = pstate->modeCurId;
383 pstate->state = PAD_STATE_EXECCMD;
384 pstate->modeCurId = 0;
385 pstate->currentTask = TASK_UPDATE_PAD;
386 pstate->disconnected = 0;
387 pstate->modeCurId = modeCurId;
392static void SetMainModeThread(
void *arg)
400 ReferThreadStatus(
TH_SELF, &tinfo);
404 pstate->buttonDataReady = 0;
405 pstate->state = PAD_STATE_EXECCMD;
407 for(i=0,res=0; res != 1; i++)
409 WaitClearEvent( pstate->eventflag, EF_SET_MAIN_MODE, WEF_AND|WEF_CLEAR, NULL);
411 res = EnterConfigMode(pstate->modeCurId, pstate);
413 if((res != 1) && (i >= 10))
415 pstate->reqState = PAD_RSTAT_FAILED;
416 pstate->currentTask = TASK_UPDATE_PAD;
421 for(i=0,res=0; res != 1; i++)
423 WaitClearEvent( pstate->eventflag, EF_SET_MAIN_MODE, WEF_AND|WEF_CLEAR, NULL);
425 res = SetMainMode( pstate);
427 if((res != 1) && (i >= 10))
429 pstate->reqState = PAD_RSTAT_FAILED;
430 pstate->currentTask = TASK_UPDATE_PAD;
435 for(i=0,res=0; res != 1; i++)
437 WaitClearEvent( pstate->eventflag, EF_SET_MAIN_MODE, WEF_AND|WEF_CLEAR, NULL);
439 res = ExitConfigMode(pstate);
441 if((res != 1) && (i >= 10))
443 pstate->reqState = PAD_RSTAT_FAILED;
444 pstate->currentTask = TASK_UPDATE_PAD;
449 pstate->currentTask = TASK_UPDATE_PAD;
454void SetActAlignThread(
void *arg)
462 ReferThreadStatus(
TH_SELF, &tinfo);
466 pstate->buttonDataReady = 0;
467 pstate->state = PAD_STATE_EXECCMD;
469 for(i=0,res=0; res != 1; i++)
471 WaitClearEvent( pstate->eventflag, EF_SET_ACT_ALIGN, WEF_AND|WEF_CLEAR, NULL);
473 res = EnterConfigMode(pstate->modeCurId, pstate);
475 if((res != 1) && (i >= 10))
477 pstate->reqState = PAD_RSTAT_FAILED;
478 pstate->currentTask = TASK_UPDATE_PAD;
483 for(i=0,res=0; res != 1; i++)
485 WaitClearEvent( pstate->eventflag, EF_SET_ACT_ALIGN, WEF_AND|WEF_CLEAR, NULL);
487 res = SetActAlign(pstate);
489 if((res != 1) && (i >= 10))
491 pstate->reqState = PAD_RSTAT_FAILED;
492 pstate->currentTask = TASK_UPDATE_PAD;
497 for(i=0,res=0; res != 1; i++)
499 WaitClearEvent( pstate->eventflag, EF_SET_ACT_ALIGN, WEF_AND|WEF_CLEAR, NULL);
501 res = ExitConfigMode(pstate);
503 if((res != 1) && (i >= 10))
505 pstate->reqState = PAD_RSTAT_FAILED;
506 pstate->currentTask = TASK_UPDATE_PAD;
511 pstate->currentTask = TASK_UPDATE_PAD;
516static void SetButtonInfoThread(
void *arg)
525 ReferThreadStatus(
TH_SELF, &tinfo);
529 pstate->buttonDataReady = 0;
530 pstate->state = PAD_STATE_EXECCMD;
532 for(i=0,res=0; res != 1; i++)
534 WaitClearEvent( pstate->eventflag, EF_SET_SET_BUTTON_INFO, WEF_AND|WEF_CLEAR, NULL);
536 res = EnterConfigMode(pstate->modeCurId, pstate);
538 if((res != 1) && (i >= 10))
540 pstate->reqState = PAD_RSTAT_FAILED;
541 pstate->currentTask = TASK_UPDATE_PAD;
546 for(i=0,res=0; res != 1; i++)
548 WaitClearEvent( pstate->eventflag, EF_SET_SET_BUTTON_INFO, WEF_AND|WEF_CLEAR, NULL);
550 res = SetButtonInfo(pstate);
552 if((res != 1) && (i >= 10))
554 pstate->reqState = PAD_RSTAT_FAILED;
555 pstate->currentTask = TASK_UPDATE_PAD;
560 for(val = 0; val < 12; val++)
562 for(i=0,res=0; res != 1; i++)
564 WaitClearEvent( pstate->eventflag, EF_SET_SET_BUTTON_INFO, WEF_AND|WEF_CLEAR, NULL);
566 res = VrefParam(val, pstate);
568 if((res != 1) && (i >= 10))
570 pstate->reqState = PAD_RSTAT_FAILED;
571 pstate->currentTask = TASK_UPDATE_PAD;
577 for(i=0,res=0; res != 1; i++)
579 WaitClearEvent( pstate->eventflag, EF_SET_SET_BUTTON_INFO, WEF_AND|WEF_CLEAR, NULL);
581 res = ExitConfigMode(pstate);
583 if((res != 1) && (i >= 10))
585 pstate->reqState = PAD_RSTAT_FAILED;
586 pstate->currentTask = TASK_UPDATE_PAD;
592 pstate->currentTask = TASK_UPDATE_PAD;
596static void SetVrefParamThread(
void *arg)
605 ReferThreadStatus(
TH_SELF, &tinfo);
609 pstate->buttonDataReady = 0;
610 pstate->state = PAD_STATE_EXECCMD;
612 for(i=0,res=0; res != 1; i++)
614 WaitClearEvent( pstate->eventflag, EF_SET_VREF_PARAM, WEF_AND|WEF_CLEAR, NULL);
616 res = EnterConfigMode(pstate->modeCurId, pstate);
618 if((res != 1) && (i >= 10))
620 pstate->reqState = PAD_RSTAT_FAILED;
621 pstate->currentTask = TASK_UPDATE_PAD;
626 for(val = 0; val < 12; val++)
628 for(i=0,res=0; res != 1; i++)
630 WaitClearEvent( pstate->eventflag, EF_SET_VREF_PARAM, WEF_AND|WEF_CLEAR, NULL);
632 res = VrefParam(val, pstate);
634 if((res != 1) && (i >= 10))
636 pstate->reqState = PAD_RSTAT_FAILED;
637 pstate->currentTask = TASK_UPDATE_PAD;
643 for(i=0,res=0; res != 1; i++)
645 WaitClearEvent( pstate->eventflag, EF_SET_VREF_PARAM, WEF_AND|WEF_CLEAR, NULL);
647 res = ExitConfigMode( pstate);
649 if((res != 1) && (i >= 10))
651 pstate->reqState = PAD_RSTAT_FAILED;
652 pstate->currentTask = TASK_UPDATE_PAD;
657 pstate->currentTask = TASK_UPDATE_PAD;
662s32
padPortOpen(s32 port, s32 slot, s32 pad_area_ee_addr, u32 *buf)
671 M_PRINTF(
"Invalid port number: %d\n", (
int)port);
675#ifdef BUILDING_XPADMAN
681 M_PRINTF(
"Invalid slot number: %d\n", (
int)port);
685 if (padman_init == 0)
690 if( (openSlots[port] >> slot) & 0x1)
692 M_PRINTF(
"The slot will be refreshed: (%d, %d)\n", (
int)port, (
int)slot);
696 padState[port][slot].port = port;
697 padState[port][slot].slot = slot;
699 openSlots[port] |= 1 << slot;
701 padState[port][slot].state = PAD_STATE_EXECCMD;
702 padState[port][slot].modeCurId = 0;
703 padState[port][slot].reqState = PAD_RSTAT_COMPLETE;
704 padState[port][slot].frame = 0;
705 padState[port][slot].padarea_ee_addr = pad_area_ee_addr;
706 padState[port][slot].buttonDataReady = 0;
707 padState[port][slot].ee_actDirectSize = 0;
708 padState[port][slot].val_c6 = 0;
709 padState[port][slot].currentTask = TASK_NONE;
710 padState[port][slot].runTask = TASK_NONE;
711 padState[port][slot].val_184 = 0;
713 padState[port][slot].disconnected = 1;
714 padState[port][slot].stat70bit = 0;
719 if((padState[port][slot].eventflag = CreateEventFlag(&
event)) == 0)
721 M_PRINTF(
"Port open failed (CreateEventFlag).\n");
728 thread.option = (u32)&padState[port][slot];
729 thread.thread = &UpdatePadThread;
731 thread.priority = thpri_lo;
733 padState[port][slot].updatepadTid = CreateThread(&
thread);
735 if(padState[port][slot].updatepadTid == 0)
737 M_PRINTF(
"Port open failed (CreateThread UpdatePadThread).\n");
743 thread.option = (u32)&padState[port][slot];
744 thread.thread = &QueryPadThread;
746 thread.priority = thpri_lo;
748 padState[port][slot].querypadTid = CreateThread(&
thread);
750 if(padState[port][slot].querypadTid == 0)
752 M_PRINTF(
"Port open failed (CreateThread QueryPadThread).\n");
758 thread.option = (u32)&padState[port][slot];
759 thread.thread = &SetMainModeThread;
761 thread.priority = thpri_lo;
763 padState[port][slot].setmainmodeTid = CreateThread(&
thread);
765 if(padState[port][slot].setmainmodeTid == 0)
767 M_PRINTF(
"Port open failed (CreateThread SetMainModeThread)\n.");
773 thread.option = (u32)&padState[port][slot];
774 thread.thread = &SetActAlignThread;
776 thread.priority = thpri_lo;
778 padState[port][slot].setactalignTid = CreateThread(&
thread);
780 if(padState[port][slot].setactalignTid == 0)
782 M_PRINTF(
"Port open failed (CreateThread SetActAlignThread).\n");
788 thread.option = (u32)&padState[port][slot];
789 thread.thread = &SetButtonInfoThread;
791 thread.priority = thpri_lo;
793 padState[port][slot].setbuttoninfoTid = CreateThread(&
thread);
795 if(padState[port][slot].setbuttoninfoTid == 0)
797 M_PRINTF(
"Port open failed (CreateThread SetButtonInfoThread).\n");
803 thread.option = (u32)&padState[port][slot];
804 thread.thread = &SetVrefParamThread;
806 thread.priority = thpri_lo;
808 padState[port][slot].setvrefparamTid = CreateThread(&
thread);
810 if(padState[port][slot].setvrefparamTid == 0)
812 M_PRINTF(
"Port open failed (CreateThread SetVrefParamThread).\n");
816 if(padState[port][slot].currentTask < TASK_QUERY_PAD)
818 StartThread(padState[port][slot].updatepadTid, NULL);
819 padState[port][slot].currentTask = TASK_UPDATE_PAD;
823 M_PRINTF(
"Port open failed, busy.\n");
int padPortOpen(int port, int slot, void *padArea)
int padPortClose(int port, int slot)
u32 count
start sector of fragmented bd/file