23#define BANNER "FREEMTAP %s\n"
26#define EF_UPDATE_SLOTS 0x1
27#define EF_EXIT_THREAD 0x2
33IRX_ID(
"multitap_manager", 2, 2);
36static s32 threadid_main;
38static u32 state_open[4];
39static u32 state_getcon[4];
40static u32 state_slots[4];
41static u8 in_buffer[256];
42static u8 out_buffer[256];
49 case 0:
return (tdata->stat6c >> 16) & 1;
50 case 1:
return (tdata->stat6c >> 17) & 1;
51 case 2:
return (tdata->stat6c >> 18) & 1;
52 case 3:
return (tdata->stat6c >> 19) & 1;
53 case 4:
return (tdata->stat6c >> 20) & 1;
54 case 5:
return (tdata->stat6c >> 21) & 1;
55 case 6:
return (tdata->stat6c >> 22) & 1;
56 case 7:
return (tdata->stat6c >> 23) & 1;
57 case 8:
return (tdata->stat6c >> 24) & 1;
58 case 9:
return (tdata->stat6c >> 25) & 1;
59 case 10:
return (tdata->stat6c >> 26) & 1;
60 case 11:
return (tdata->stat6c >> 27) & 1;
61 case 12:
return (tdata->stat6c >> 28) & 1;
62 case 13:
return (tdata->stat6c >> 29) & 1;
63 case 14:
return (tdata->stat6c >> 30) & 1;
64 case 15:
return (tdata->stat6c >> 31) & 1;
69void get_slot_number_setup_td(u32 port, u32 reg)
74 td.port_ctrl1[p] = 0xFF020505;
75 td.port_ctrl2[p] = 0x00030064;
77 td.regdata[reg] = (p & 0x3) | 0x180640;
79 for(i=0; i < 6 ; i++) td.in[td.in_size + i] = 0;
81 td.in[td.in_size] = 0x21;
84 td.in[td.in_size + 1] = 0x12;
86 td.in[td.in_size + 1] = 0x13;
94s32 get_slot_number_check_td(u32 bit)
99 if(read_stat6c_bit(bit, &td) != 1)
101 if(td.out[5] == 0x66)
111 for(i=0; i < 250; i++) td.out[i] = td.out[i+6];
117s32 get_slot_number(u32 port, u32 retries)
122 if(port >= 4)
return -3;
124 if(state_open[port] == 0)
return -4;
128 while((slots < 0) && (i <= retries))
130 sio2_mtap_transfer_init();
135 for(j=0; j < 16; j++) td.regdata[j] = 0;
137 get_slot_number_setup_td(port, 0);
139 slots = get_slot_number_check_td(0);
141 sio2_transfer_reset2();
143 if((slots == -2) || (slots >= 0))
return slots;
153void update_slot_numbers_thread()
160 WaitEventFlag(
event_flag, EF_UPDATE_SLOTS | EF_EXIT_THREAD, 0x11, &resbits);
162 if(resbits & EF_EXIT_THREAD)
168 for(port=0; port < 4; port++)
170 if(state_open[port] == 1)
172 if(state_getcon[port] == 0)
173 slots = get_slot_number(port, 10);
175 slots = get_slot_number(port, 0);
179 state_slots[port] = 1;
180 state_getcon[port] = 0;
184 state_slots[port] = slots;
185 state_getcon[port] = 1;
194s32 change_slot_setup_td(u32 port, s32 slot, u32 reg)
199 td.port_ctrl1[p] = 0xFF020505;
200 td.port_ctrl2[p] = 0x00030064;
202 td.regdata[reg] = (p & 0x3) | 0x1c0740;
204 for(i=0; i < 7; i++) td.in[td.in_size + i] = 0;
206 td.in[td.in_size] = 0x21;
210 td.in[td.in_size + 1] = 0x21;
214 td.in[td.in_size + 1] = 0x22;
217 td.in[td.in_size + 2] = (u8)slot;
228s32 change_slot_check_td(u32 a)
235 if(read_stat6c_bit(a, &td) != 1)
237 if(td.out[5] == 0x66)
254 for(i=0; i < 249; i++)
256 td.out[i] = td.out[i+7];
265int change_slot(s32 *arg)
272 while((loop < 10) && (
count != 0))
280 for(i=0; i < 16; i++) td.regdata[i] = 0;
283 for(port=0; port < 4; port++)
289 if((state_open[port] == 1) && (state_getcon[port] == 1))
291 if(state_slots[port] > (u32)(arg[port]))
293 change_slot_setup_td(port, arg[port], reg);
324 for(port=0; port < 4; port++)
328 s32 res = change_slot_check_td(data[port]);
355 if(
count != 0) loop++;
368int get_slots1(
int port)
370 return state_slots[port];
373int get_slots2(
int port)
375 return state_slots[port];
378void update_slot_numbers()
383int _start(
int argc,
char *argv[])
392 printf(BANNER,VERSION);
394 if(RegisterLibraryEntries(&_exp_mtapman) != 0)
396 M_PRINTF(
"RegisterLibraryEntries failed.\n");
397 return MODULE_NO_RESIDENT_END;
400 if(InitRpcServers() == 0)
402 M_PRINTF(
"Failed to setup RPC Servers.\n");
403 return MODULE_NO_RESIDENT_END;
413 M_PRINTF(
"Could not create event flag (%i)\n.", (
int)
event_flag);
414 return MODULE_NO_RESIDENT_END;
418 thread.thread = update_slot_numbers_thread;
422 threadid_main = CreateThread(&
thread);
424 if(threadid_main < 0)
426 M_PRINTF(
"Could not create thread (%i)\n.", (
int)threadid_main);
427 return MODULE_NO_RESIDENT_END;
430 StartThread(threadid_main, 0);
439 sio2_mtap_change_slot_set(change_slot);
440 sio2_mtap_get_slot_max_set(get_slots1);
441 sio2_mtap_get_slot_max2_set(get_slots2);
442 sio2_mtap_update_slots_set(update_slot_numbers);
447 return MODULE_RESIDENT_END;
455 sio2_mtap_change_slot_set(NULL);
456 sio2_mtap_get_slot_max_set(NULL);
457 sio2_mtap_get_slot_max2_set(NULL);
458 sio2_mtap_update_slots_set(NULL);
472 state_open[port] = 1;
474 s32 res = get_slot_number(port, 10);
478 state_getcon[port] = 0;
479 state_slots[port] = 1;
484 state_getcon[port] = 1;
485 state_slots[port] = res;
495 state_open[port] = 0;
496 state_getcon[port] = 0;
503 return state_getcon[port];
506s32 mtapGetSlotNumber(u32 port)
510 if(port >= 4)
return -1;
512 if(state_open[port] == 0)
return 1;
514 res = get_slot_number(port, 10);
522s32 mtapChangeSlot(u32 port, u32 slot)
527 if(port >= 4)
return 0;
529 if(state_open[port] == 0)
531 M_PRINTF(
"mtap manager doesn't work\n");
540 sio2_mtap_transfer_init();
544 sio2_transfer_reset2();
548 M_PRINTF(
"Failed to change slot.\n");
553 M_PRINTF(
"Change slot complete.\n");
int mtapGetConnection(int port)
int mtapPortClose(int port)
int mtapPortOpen(int port)
u32 count
start sector of fragmented bd/file