mirror of
https://github.com/LNH-team/dspico-usb-examples.git
synced 2026-06-02 17:26:50 +02:00
Initial commit
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
#include "common.h"
|
||||
#include <string.h>
|
||||
#include <nds/disc_io.h>
|
||||
#include "DldiIpcService.h"
|
||||
|
||||
extern FN_MEDIUM_STARTUP _DLDI_startup_ptr;
|
||||
extern FN_MEDIUM_READSECTORS _DLDI_readSectors_ptr;
|
||||
extern FN_MEDIUM_WRITESECTORS _DLDI_writeSectors_ptr;
|
||||
|
||||
void DldiIpcService::HandleMessage(u32 data)
|
||||
{
|
||||
auto cmd = reinterpret_cast<const dldi_ipc_cmd_t*>(data << 2);
|
||||
switch (cmd->cmd)
|
||||
{
|
||||
case DLDI_IPC_CMD_SETUP:
|
||||
SetupDldi(cmd);
|
||||
break;
|
||||
|
||||
case DLDI_IPC_CMD_READ_SECTORS:
|
||||
ReadSectors(cmd);
|
||||
break;
|
||||
|
||||
case DLDI_IPC_CMD_WRITE_SECTORS:
|
||||
WriteSectors(cmd);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void DldiIpcService::SetupDldi(const dldi_ipc_cmd_t* cmd) const
|
||||
{
|
||||
memcpy((void*)0x037F8000, cmd->buffer, 16 * 1024);
|
||||
bool result;
|
||||
rtos_lockMutex(&gCardMutex);
|
||||
result = _DLDI_startup_ptr();
|
||||
rtos_unlockMutex(&gCardMutex);
|
||||
SendResponseMessage(result);
|
||||
}
|
||||
|
||||
void DldiIpcService::ReadSectors(const dldi_ipc_cmd_t* cmd) const
|
||||
{
|
||||
rtos_lockMutex(&gCardMutex);
|
||||
_DLDI_readSectors_ptr(cmd->sector, cmd->count, cmd->buffer);
|
||||
rtos_unlockMutex(&gCardMutex);
|
||||
SendResponseMessage(0);
|
||||
}
|
||||
|
||||
void DldiIpcService::WriteSectors(const dldi_ipc_cmd_t* cmd) const
|
||||
{
|
||||
rtos_lockMutex(&gCardMutex);
|
||||
_DLDI_writeSectors_ptr(cmd->sector, cmd->count, cmd->buffer);
|
||||
rtos_unlockMutex(&gCardMutex);
|
||||
SendResponseMessage(0);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
#include "ipc/ThreadIpcService.h"
|
||||
#include "dldiIpcCommand.h"
|
||||
#include "ipcChannels.h"
|
||||
|
||||
class DldiIpcService : public ThreadIpcService
|
||||
{
|
||||
u32 _threadStack[128];
|
||||
|
||||
void SetupDldi(const dldi_ipc_cmd_t* cmd) const;
|
||||
void ReadSectors(const dldi_ipc_cmd_t* cmd) const;
|
||||
void WriteSectors(const dldi_ipc_cmd_t* cmd) const;
|
||||
|
||||
public:
|
||||
DldiIpcService()
|
||||
: ThreadIpcService(IPC_CHANNEL_DLDI, 6, _threadStack, sizeof(_threadStack)) { }
|
||||
|
||||
void HandleMessage(u32 data) override;
|
||||
};
|
||||
Reference in New Issue
Block a user