11#include "irx_imports.h"
26IRX_ID(
"sio2man_logger", 3, 17);
28IRX_ID(
"sio2man", 3, 17);
41 int m_transfer_semaphore;
44 sio2_mtap_change_slot_cb_t m_mtap_change_slot_cb;
45 sio2_mtap_get_slot_max_cb_t m_mtap_get_slot_max_cb;
46 sio2_mtap_get_slot_max2_cb_t m_mtap_get_slot_max2_cb;
47 sio2_mtap_update_slots_t m_mtap_update_slots_cb;
50#define EPRINTF(format, args...) printf("%s: " format, _irx_id.n, ##args)
55#define sio2_ctrl_set inl_sio2_ctrl_set
56#define sio2_ctrl_get inl_sio2_ctrl_get
57#define sio2_stat6c_get inl_sio2_stat6c_get
58#define sio2_portN_ctrl1_set inl_sio2_portN_ctrl1_set
59#define sio2_portN_ctrl2_set inl_sio2_portN_ctrl2_set
60#define sio2_regN_set inl_sio2_regN_set
61#define sio2_stat74_get inl_sio2_stat74_get
62#define sio2_data_out inl_sio2_data_out
63#define sio2_data_in inl_sio2_data_in
64#define sio2_stat_set inl_sio2_stat_set
65#define sio2_stat_get inl_sio2_stat_get
66#define sio2_set_ctrl_c inl_sio2_set_ctrl_c
67#define sio2_set_ctrl_1 inl_sio2_set_ctrl_1
68#define NANO_STATIC static inline
73NANO_STATIC
void sio2_ctrl_set(u32 val)
75 USE_IOP_MMIO_HWPORT();
77 iop_mmio_hwport->sio2.ctrl = val;
80NANO_STATIC u32 sio2_ctrl_get(
void)
82 USE_IOP_MMIO_HWPORT();
84 return iop_mmio_hwport->sio2.ctrl;
87NANO_STATIC u32 sio2_stat6c_get(
void)
89 USE_IOP_MMIO_HWPORT();
91 return iop_mmio_hwport->sio2.recv1;
94NANO_STATIC
void sio2_portN_ctrl1_set(
int N, u32 val)
96 USE_IOP_MMIO_HWPORT();
98 iop_mmio_hwport->sio2.send1_2_buf[N * 2] = val;
102u32 sio2_portN_ctrl1_get(
int N)
104 USE_IOP_MMIO_HWPORT();
106 return iop_mmio_hwport->sio2.send1_2_buf[N * 2];
110NANO_STATIC
void sio2_portN_ctrl2_set(
int N, u32 val)
112 USE_IOP_MMIO_HWPORT();
114 iop_mmio_hwport->sio2.send1_2_buf[(N * 2) + 1] = val;
118u32 sio2_portN_ctrl2_get(
int N)
120 USE_IOP_MMIO_HWPORT();
122 return iop_mmio_hwport->sio2.send1_2_buf[(N * 2) + 1];
126u32 sio2_stat70_get(
void)
128 USE_IOP_MMIO_HWPORT();
130 return iop_mmio_hwport->sio2.recv2;
133NANO_STATIC
void sio2_regN_set(
int N, u32 val)
135 USE_IOP_MMIO_HWPORT();
137 iop_mmio_hwport->sio2.send3_buf[N] = val;
141u32 sio2_regN_get(
int N)
143 USE_IOP_MMIO_HWPORT();
145 return iop_mmio_hwport->sio2.send3_buf[N];
149NANO_STATIC u32 sio2_stat74_get(
void)
151 USE_IOP_MMIO_HWPORT();
153 return iop_mmio_hwport->sio2.recv3;
157void sio2_unkn78_set(u32 val)
159 USE_IOP_MMIO_HWPORT();
161 iop_mmio_hwport->sio2.unk_78 = val;
166u32 sio2_unkn78_get(
void)
168 USE_IOP_MMIO_HWPORT();
170 return iop_mmio_hwport->sio2.unk_78;
175void sio2_unkn7c_set(u32 val)
177 USE_IOP_MMIO_HWPORT();
179 iop_mmio_hwport->sio2.unk_7c = val;
184u32 sio2_unkn7c_get(
void)
186 USE_IOP_MMIO_HWPORT();
188 return iop_mmio_hwport->sio2.unk_7c;
192NANO_STATIC
void sio2_data_out(u8 val)
194 USE_IOP_MMIO_HWPORT();
196 iop_mmio_hwport->sio2.out_fifo = val;
199NANO_STATIC u8 sio2_data_in(
void)
201 USE_IOP_MMIO_HWPORT();
203 return iop_mmio_hwport->sio2.in_fifo;
206NANO_STATIC
void sio2_stat_set(u32 val)
208 USE_IOP_MMIO_HWPORT();
210 iop_mmio_hwport->sio2.stat = val;
213NANO_STATIC u32 sio2_stat_get(
void)
215 USE_IOP_MMIO_HWPORT();
217 return iop_mmio_hwport->sio2.stat;
225 log_default(LOG_TRS);
228 for ( i = 0; i < 4; i += 1 )
230 sio2_portN_ctrl1_set(i, td->port_ctrl1[i]);
231 sio2_portN_ctrl2_set(i, td->port_ctrl2[i]);
235 log_portdata(td->port_ctrl1, td->port_ctrl2);
238 for ( i = 0; i < 16; i += 1 )
239 sio2_regN_set(i, td->regdata[i]);
242 log_regdata(td->regdata);
245 for ( i = 0; i < (int)td->in_size; i += 1 )
246 sio2_data_out(td->in[i]);
249 log_data(LOG_TRS_DATA, td->in, td->in_size);
251 if ( td->in_dma.addr )
253 sceSetSliceDMA(IOP_DMAC_SIO2in, td->in_dma.addr, td->in_dma.size, td->in_dma.count, DMAC_FROM_MEM);
254 sceStartDMA(IOP_DMAC_SIO2in);
256 log_dma(LOG_TRS_DMA_IN, &td->in_dma);
259 if ( td->out_dma.addr )
261 sceSetSliceDMA(IOP_DMAC_SIO2out, td->out_dma.addr, td->out_dma.size, td->out_dma.count, DMAC_TO_MEM);
262 sceStartDMA(IOP_DMAC_SIO2out);
264 log_dma(LOG_TRS_DMA_OUT, &td->out_dma);
274 log_default(LOG_TRR);
276 td->stat6c = sio2_stat6c_get();
277 td->stat70 = sio2_stat70_get();
278 td->stat74 = sio2_stat74_get();
280 log_stat(td->stat6c, td->stat70, td->stat74);
282 for ( i = 0; i < (int)td->out_size; i += 1 )
283 td->out[i] = sio2_data_in();
286 log_data(LOG_TRR_DATA, td->out, td->out_size);
292 sio2_stat_set(sio2_stat_get());
293 iSignalSema(arg->m_intr_sema);
297int _start(
int ac,
char **av)
305 if ( RegisterLibraryEntries(&_exp_sio2man) != 0 )
308 _exp_sio2man1.name[7] =
'\x00';
309 if ( RegisterLibraryEntries(&_exp_sio2man1) != 0 )
311 if ( g_sio2man_data.m_inited )
313 g_sio2man_data.m_inited = 1;
314 g_sio2man_data.m_sdk13x_flag = 0;
316 g_sio2man_data.m_mtap_change_slot_cb = 0;
317 g_sio2man_data.m_mtap_get_slot_max_cb = 0;
318 g_sio2man_data.m_mtap_get_slot_max2_cb = 0;
319 g_sio2man_data.m_mtap_update_slots_cb = 0;
321 sio2_ctrl_set(0x3BC);
326 sceSetDMAPriority(IOP_DMAC_SIO2in, 3);
327 sceSetDMAPriority(IOP_DMAC_SIO2out, 3);
328 sceEnableDMAChannel(IOP_DMAC_SIO2in);
329 sceEnableDMAChannel(IOP_DMAC_SIO2out);
331 semaparam.option = 0;
332 semaparam.initial = 1;
334 g_sio2man_data.m_transfer_semaphore = CreateSema(&semaparam);
336 semaparam.option = 0;
337 semaparam.initial = 0;
339 g_sio2man_data.m_intr_sema = CreateSema(&semaparam);
341 EPRINTF(
"Logging started.\n");
351 if ( !g_sio2man_data.m_inited )
357 g_sio2man_data.m_inited = 0;
363 sceDisableDMAChannel(IOP_DMAC_SIO2in);
364 sceDisableDMAChannel(IOP_DMAC_SIO2out);
365 DeleteSema(g_sio2man_data.m_intr_sema);
366 DeleteSema(g_sio2man_data.m_transfer_semaphore);
370void sio2_set_intr_handler(
int (*handler)(
void *),
void *userdata)
378 IOP_IRQ_SIO2, 1, handler ? handler : (int (*)(void *))sio2_intr_handler, handler ? userdata : &g_sio2man_data);
384NANO_STATIC
void sio2_set_ctrl_c()
387 sio2_ctrl_set(sio2_ctrl_get() | 0xC);
390NANO_STATIC
void sio2_set_ctrl_1()
393 sio2_ctrl_set(sio2_ctrl_get() | 1);
396void sio2_wait_for_intr()
398 WaitSema(g_sio2man_data.m_intr_sema);
409 sio2_wait_for_intr();
411 if ( g_sio2man_data.m_sdk13x_flag )
412 sio2_transfer_reset();
419void sio2_pad_transfer_init(
void)
424 WaitSema(g_sio2man_data.m_transfer_semaphore);
426 log_default(LOG_PAD_READY);
428 g_sio2man_data.m_sdk13x_flag = 0;
431void sio2_pad_transfer_init_possiblysdk13x(
void)
433 sio2_pad_transfer_init();
434 g_sio2man_data.m_sdk13x_flag = 1;
437void sio2_transfer_reset(
void)
439 g_sio2man_data.m_sdk13x_flag = 0;
440 SignalSema(g_sio2man_data.m_transfer_semaphore);
442 log_default(LOG_RESET);
446void sio2_mtap_change_slot_set(sio2_mtap_change_slot_cb_t cb)
448 g_sio2man_data.m_mtap_change_slot_cb = cb;
451void sio2_mtap_get_slot_max_set(sio2_mtap_get_slot_max_cb_t cb)
453 g_sio2man_data.m_mtap_get_slot_max_cb = cb;
456void sio2_mtap_get_slot_max2_set(sio2_mtap_get_slot_max2_cb_t cb)
458 g_sio2man_data.m_mtap_get_slot_max2_cb = cb;
461void sio2_mtap_update_slots_set(sio2_mtap_update_slots_t cb)
463 g_sio2man_data.m_mtap_update_slots_cb = cb;
466int sio2_mtap_change_slot(s32 *arg)
471 g_sio2man_data.m_sdk13x_flag = 0;
472 if ( g_sio2man_data.m_mtap_change_slot_cb )
473 return g_sio2man_data.m_mtap_change_slot_cb(arg);
475 for ( i = 0; i < 4; i += 1 )
477 arg[i + 4] = ((arg[i] + 1) < 2);
483int sio2_mtap_get_slot_max(
int port)
485 return g_sio2man_data.m_mtap_get_slot_max_cb ? g_sio2man_data.m_mtap_get_slot_max_cb(port) : 1;
488int sio2_mtap_get_slot_max2(
int port)
490 return g_sio2man_data.m_mtap_get_slot_max2_cb ? g_sio2man_data.m_mtap_get_slot_max2_cb(port) : 1;
493void sio2_mtap_update_slots(
void)
495 if ( g_sio2man_data.m_mtap_update_slots_cb )
496 g_sio2man_data.m_mtap_update_slots_cb();
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)