39 IRX_ID(
"sio2man_logger", 2, 1);
41#ifdef BUILDING_XSIO2MAN
42#ifdef BUILDING_XSIO2MAN_V2
43 IRX_ID(
"sio2man", 2, 4);
45 IRX_ID(
"sio2man", 2, 1);
48 IRX_ID(
"sio2man", 1, 1);
54#define SIO2_REG_BASE 0xbf808200
55#define SIO2_REG_PORT0_CTRL1 0xbf808240
56#define SIO2_REG_PORT0_CTRL2 0xbf808244
57#define SIO2_REG_DATA_OUT 0xbf808260
58#define SIO2_REG_DATA_IN 0xbf808264
59#define SIO2_REG_CTRL 0xbf808268
60#define SIO2_REG_STAT6C 0xbf80826c
61#define SIO2_REG_STAT70 0xbf808270
62#define SIO2_REG_STAT74 0xbf808274
63#define SIO2_REG_UNKN78 0xbf808278
64#define SIO2_REG_UNKN7C 0xbf80827c
65#define SIO2_REG_STAT 0xbf808280
68#define EF_PAD_TRANSFER_INIT 0x00000001
69#define EF_PAD_TRANSFER_READY 0x00000002
70#define EF_MC_TRANSFER_INIT 0x00000004
71#define EF_MC_TRANSFER_READY 0x00000008
72#ifdef BUILDING_XSIO2MAN
73#define EF_MTAP_TRANSFER_INIT 0x00000010
74#define EF_MTAP_TRANSFER_READY 0x00000020
75#ifdef BUILDING_XSIO2MAN_V2
76 #define EF_RM_TRANSFER_INIT 0x00000040
77 #define EF_RM_TRANSFER_READY 0x00000080
78 #define EF_UNK_TRANSFER_INIT 0x00000100
79 #define EF_UNK_TRANSFER_READY 0x00000200
80 #define EF_TRANSFER_START 0x00000400
81 #define EF_TRANSFER_FINISH 0x00000800
82 #define EF_TRANSFER_RESET 0x00001000
83 #define EF_SIO2_INTR_COMPLETE 0x00002000
85 #define EF_TRANSFER_START 0x00000040
86 #define EF_TRANSFER_FINISH 0x00000080
87 #define EF_TRANSFER_RESET 0x00000100
88 #define EF_SIO2_INTR_COMPLETE 0x00000200
91 #define EF_TRANSFER_START 0x00000010
92 #define EF_TRANSFER_FINISH 0x00000020
93 #define EF_TRANSFER_RESET 0x00000040
94 #define EF_SIO2_INTR_COMPLETE 0x00000080
97#define EPRINTF(format, args...) printf("%s: " format, _irx_id.n , ## args)
103int (*mtap_change_slot_cb)(s32 *) = NULL;
104int (*mtap_get_slot_max_cb)(int) = NULL;
105int (*mtap_get_slot_max2_cb)(int) = NULL;
106void (*mtap_update_slots_cb)(void) = NULL;
108int sio2_intr_handler(
void *arg)
110 int ef = *(
int *)arg;
112 sio2_stat_set(sio2_stat_get());
114 iSetEventFlag(ef, EF_SIO2_INTR_COMPLETE);
124 log_default(LOG_TRS);
127 for (i = 0; i < 4; i++) {
128 sio2_portN_ctrl1_set(i, td->port_ctrl1[i]);
129 sio2_portN_ctrl2_set(i, td->port_ctrl2[i]);
133 log_portdata(td->port_ctrl1, td->port_ctrl2);
136 for (i = 0; i < 16; i++)
137 sio2_regN_set(i, td->regdata[i]);
140 log_regdata(td->regdata);
144 for (i = 0; (u32)i < td->in_size; i++)
145 sio2_data_out(td->in[i]);
147 log_data(LOG_TRS_DATA, td->in, td->in_size);
151 if (td->in_dma.addr) {
152 sceSetSliceDMA(IOP_DMAC_SIO2in, td->in_dma.addr, td->in_dma.size,
153 td->in_dma.count, DMAC_FROM_MEM);
154 sceStartDMA(IOP_DMAC_SIO2in);
157 log_dma(LOG_TRS_DMA_IN, &td->in_dma);
161 if (td->out_dma.addr) {
162 sceSetSliceDMA(IOP_DMAC_SIO2out, td->out_dma.addr, td->out_dma.size,
163 td->out_dma.count, DMAC_TO_MEM);
164 sceStartDMA(IOP_DMAC_SIO2out);
167 log_dma(LOG_TRS_DMA_OUT, &td->out_dma);
176 log_default(LOG_TRR);
178 td->stat6c = sio2_stat6c_get();
179 td->stat70 = sio2_stat70_get();
180 td->stat74 = sio2_stat74_get();
182 log_stat(td->stat6c, td->stat70, td->stat74);
185 for (i = 0; (u32)i < td->out_size; i++)
186 td->out[i] = sio2_data_in();
188 log_data(LOG_TRR_DATA, td->out, td->out_size);
193void main_thread(
void *unused)
203 WaitEventFlag(
event_flag, EF_PAD_TRANSFER_INIT |
205#ifdef BUILDING_XSIO2MAN
206 | EF_MTAP_TRANSFER_INIT
207#ifdef BUILDING_XSIO2MAN_V2
208 | EF_RM_TRANSFER_INIT | EF_UNK_TRANSFER_INIT
213 if (resbits[0] & EF_PAD_TRANSFER_INIT) {
214 ClearEventFlag(
event_flag, ~EF_PAD_TRANSFER_INIT);
215 SetEventFlag(
event_flag, EF_PAD_TRANSFER_READY);
217 log_default(LOG_PAD_READY);
219 }
else if (resbits[0] & EF_MC_TRANSFER_INIT) {
220 ClearEventFlag(
event_flag, ~EF_MC_TRANSFER_INIT);
221 SetEventFlag(
event_flag, EF_MC_TRANSFER_READY);
223 log_default(LOG_MC_READY);
226#ifdef BUILDING_XSIO2MAN
227 else if (resbits[0] & EF_MTAP_TRANSFER_INIT) {
228 ClearEventFlag(
event_flag, ~EF_MTAP_TRANSFER_INIT);
229 SetEventFlag(
event_flag, EF_MTAP_TRANSFER_READY);
231 log_default(LOG_MTAP_READY);
234#ifdef BUILDING_XSIO2MAN_V2
235 else if (resbits[0] & EF_RM_TRANSFER_INIT) {
236 ClearEventFlag(
event_flag, ~EF_RM_TRANSFER_INIT);
237 SetEventFlag(
event_flag, EF_RM_TRANSFER_READY);
239 log_default(LOG_RM_READY);
241 }
else if (resbits[0] & EF_UNK_TRANSFER_INIT) {
242 ClearEventFlag(
event_flag, ~EF_UNK_TRANSFER_INIT);
243 SetEventFlag(
event_flag, EF_UNK_TRANSFER_READY);
245 log_default(LOG_UNK_READY);
251#ifdef BUILDING_XSIO2MAN
252 EPRINTF(
"Unknown event %08lx. Exiting.\n", resbits[0]);
254 EPRINTF(
"SIO2_BASIC_THREAD : why I wakeup ? %08lx\n", resbits[0]);
259#ifdef BUILDING_XSIO2MAN
263#ifdef BUILDING_XSIO2MAN
268#ifdef BUILDING_XSIO2MAN
269 if (resbits[0] & EF_TRANSFER_RESET) {
270 ClearEventFlag(
event_flag, ~EF_TRANSFER_RESET);
272 log_default(LOG_RESET);
278 ClearEventFlag(
event_flag, ~EF_TRANSFER_START);
280 sio2_ctrl_set(sio2_ctrl_get() | 0xc);
281 send_td(transfer_data);
282 sio2_ctrl_set(sio2_ctrl_get() | 1);
284 WaitEventFlag(
event_flag, EF_SIO2_INTR_COMPLETE, 0, NULL);
285 ClearEventFlag(
event_flag, ~EF_SIO2_INTR_COMPLETE);
287 recv_td(transfer_data);
289#ifndef BUILDING_XSIO2MAN
290 WaitEventFlag(
event_flag, EF_TRANSFER_RESET, 0, NULL);
291 ClearEventFlag(
event_flag, ~EF_TRANSFER_RESET);
302#ifdef BUILDING_XSIO2MAN
308int create_main_thread(
void)
314 thread.thread = main_thread;
315 thread.stacksize = 0x8000;
317 return CreateThread(&
thread);
320int create_event_flag(
void)
327 return CreateEventFlag(&
event);
341 sceDisableDMAChannel(IOP_DMAC_SIO2in);
342 sceDisableDMAChannel(IOP_DMAC_SIO2out);
345int _start(
int argc,
char *argv[])
354 if (RegisterLibraryEntries(&_exp_sio2man) != 0)
355 return MODULE_NO_RESIDENT_END;
358 return MODULE_NO_RESIDENT_END;
362 sio2_ctrl_set(0x3bc);
364 mtap_change_slot_cb = NULL; mtap_get_slot_max_cb = NULL; mtap_get_slot_max2_cb = NULL; mtap_update_slots_cb = NULL;
366 thid = create_main_thread();
373 sceSetDMAPriority(IOP_DMAC_SIO2in, 3);
374 sceSetDMAPriority(IOP_DMAC_SIO2out, 3);
375 sceEnableDMAChannel(IOP_DMAC_SIO2in);
376 sceEnableDMAChannel(IOP_DMAC_SIO2out);
378 StartThread(thid, NULL);
380 EPRINTF(
"Logging started.\n");
382 return MODULE_RESIDENT_END;
385void sio2_pad_transfer_init(
void)
387 SetEventFlag(
event_flag, EF_PAD_TRANSFER_INIT);
389 WaitEventFlag(
event_flag, EF_PAD_TRANSFER_READY, 0, NULL);
390 ClearEventFlag(
event_flag, ~EF_PAD_TRANSFER_READY);
393void sio2_mc_transfer_init(
void)
395 SetEventFlag(
event_flag, EF_MC_TRANSFER_INIT);
397 WaitEventFlag(
event_flag, EF_MC_TRANSFER_READY, 0, NULL);
398 ClearEventFlag(
event_flag, ~EF_MC_TRANSFER_READY);
401#ifdef BUILDING_XSIO2MAN
402void sio2_mtap_transfer_init(
void)
404 SetEventFlag(
event_flag, EF_MTAP_TRANSFER_INIT);
406 WaitEventFlag(
event_flag, EF_MTAP_TRANSFER_READY, 0, NULL);
407 ClearEventFlag(
event_flag, ~EF_MTAP_TRANSFER_READY);
416 WaitEventFlag(
event_flag, EF_TRANSFER_FINISH, 0, NULL);
417 ClearEventFlag(
event_flag, ~EF_TRANSFER_FINISH);
419#ifndef BUILDING_XSIO2MAN
425#ifdef BUILDING_XSIO2MAN
426#ifdef BUILDING_XSIO2MAN_V2
427void sio2_rm_transfer_init(
void)
429 SetEventFlag(
event_flag, EF_RM_TRANSFER_INIT);
431 WaitEventFlag(
event_flag, EF_RM_TRANSFER_READY, 0, NULL);
432 ClearEventFlag(
event_flag, ~EF_RM_TRANSFER_READY);
435void sio2_unk_transfer_init(
void)
437 SetEventFlag(
event_flag, EF_UNK_TRANSFER_INIT);
439 WaitEventFlag(
event_flag, EF_UNK_TRANSFER_READY, 0, NULL);
440 ClearEventFlag(
event_flag, ~EF_UNK_TRANSFER_READY);
445#ifdef BUILDING_XSIO2MAN
446void sio2_transfer_reset(
void)
451int sio2_mtap_change_slot(s32 *status)
455 if (mtap_change_slot_cb)
456 return mtap_change_slot_cb(status);
458 for (i = 0; i < 4; i++, status++) {
459 if ((*status + 1) < 2)
470int sio2_mtap_get_slot_max(
int port)
472 if (mtap_get_slot_max_cb)
473 return mtap_get_slot_max_cb(port);
478int sio2_mtap_get_slot_max2(
int port)
480 if (mtap_get_slot_max2_cb)
481 return mtap_get_slot_max2_cb(port);
486void sio2_mtap_update_slots(
void)
488 if (mtap_update_slots_cb)
489 mtap_update_slots_cb();
493#ifdef BUILDING_XSIO2MAN
494void sio2_mtap_change_slot_set(sio2_mtap_change_slot_cb_t cb) { mtap_change_slot_cb = cb; }
495void sio2_mtap_get_slot_max_set(sio2_mtap_get_slot_max_cb_t cb) { mtap_get_slot_max_cb = cb; }
496void sio2_mtap_get_slot_max2_set(sio2_mtap_get_slot_max2_cb_t cb) { mtap_get_slot_max2_cb = cb; }
497void sio2_mtap_update_slots_set(sio2_mtap_update_slots_t cb) { mtap_update_slots_cb = cb; }
500void sio2_ctrl_set(u32 val) { _sw(val, SIO2_REG_CTRL); }
501u32 sio2_ctrl_get() {
return _lw(SIO2_REG_CTRL); }
502u32 sio2_stat6c_get() {
return _lw(SIO2_REG_STAT6C); }
503void sio2_portN_ctrl1_set(
int N, u32 val) { _sw(val, SIO2_REG_PORT0_CTRL1 + (N * 8)); }
504u32 sio2_portN_ctrl1_get(
int N) {
return _lw(SIO2_REG_PORT0_CTRL1 + (N * 8)); }
505void sio2_portN_ctrl2_set(
int N, u32 val) { _sw(val, SIO2_REG_PORT0_CTRL2 + (N * 8)); }
506u32 sio2_portN_ctrl2_get(
int N) {
return _lw(SIO2_REG_PORT0_CTRL2 + (N * 8)); }
507u32 sio2_stat70_get() {
return _lw(SIO2_REG_STAT70); }
508void sio2_regN_set(
int N, u32 val) { _sw(val, SIO2_REG_BASE + (N * 4)); }
509u32 sio2_regN_get(
int N) {
return _lw(SIO2_REG_BASE + (N * 4)); }
510u32 sio2_stat74_get() {
return _lw(SIO2_REG_STAT74); }
511void sio2_unkn78_set(u32 val) { _sw(val, SIO2_REG_UNKN78); }
512u32 sio2_unkn78_get() {
return _lw(SIO2_REG_UNKN78); }
513void sio2_unkn7c_set(u32 val) { _sw(val, SIO2_REG_UNKN7C); }
514u32 sio2_unkn7c_get() {
return _lw(SIO2_REG_UNKN7C); }
515void sio2_data_out(u8 val) { _sb(val, SIO2_REG_DATA_OUT); }
516u8 sio2_data_in() {
return _lb(SIO2_REG_DATA_IN); }
517void sio2_stat_set(u32 val) { _sw(val, SIO2_REG_STAT); }
518u32 sio2_stat_get() {
return _lw(SIO2_REG_STAT); }
int CpuResumeIntr(int state)
int RegisterIntrHandler(int irq, int mode, int(*handler)(void *), void *arg)
int ReleaseIntrHandler(int irq)
int DisableIntr(int irq, int *res)
int CpuSuspendIntr(int *state)