mirror of
https://github.com/LNH-team/dspico-usb-examples.git
synced 2026-06-02 09:16:50 +02:00
Initial commit
This commit is contained in:
16
examples/mass-storage/common/dldiIpcCommand.h
Normal file
16
examples/mass-storage/common/dldiIpcCommand.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
typedef enum
|
||||
{
|
||||
DLDI_IPC_CMD_SETUP,
|
||||
DLDI_IPC_CMD_READ_SECTORS,
|
||||
DLDI_IPC_CMD_WRITE_SECTORS
|
||||
} DldiIpcCommand;
|
||||
|
||||
typedef struct alignas(32)
|
||||
{
|
||||
u32 cmd;
|
||||
void* buffer;
|
||||
u32 sector;
|
||||
u32 count;
|
||||
} dldi_ipc_cmd_t;
|
||||
11
examples/mass-storage/common/ipc/IpcService.cpp
Normal file
11
examples/mass-storage/common/ipc/IpcService.cpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "common.h"
|
||||
#include <libtwl/ipc/ipcFifoSystem.h>
|
||||
#include "IpcService.h"
|
||||
|
||||
void IpcService::Start()
|
||||
{
|
||||
ipc_setChannelHandler(_ipcChannel, [] (u32 channel, u32 data, void* arg)
|
||||
{
|
||||
static_cast<IpcService*>(arg)->OnMessageReceived(data);
|
||||
}, this);
|
||||
}
|
||||
19
examples/mass-storage/common/ipc/IpcService.h
Normal file
19
examples/mass-storage/common/ipc/IpcService.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
#include <libtwl/ipc/ipcFifoSystem.h>
|
||||
|
||||
class IpcService
|
||||
{
|
||||
const u32 _ipcChannel;
|
||||
protected:
|
||||
explicit IpcService(u32 ipcChannel)
|
||||
: _ipcChannel(ipcChannel) { }
|
||||
|
||||
void SendResponseMessage(u32 data) const
|
||||
{
|
||||
ipc_sendFifoMessage(_ipcChannel, data);
|
||||
}
|
||||
|
||||
public:
|
||||
virtual void Start();
|
||||
virtual void OnMessageReceived(u32 data) = 0;
|
||||
};
|
||||
33
examples/mass-storage/common/ipc/ThreadIpcService.cpp
Normal file
33
examples/mass-storage/common/ipc/ThreadIpcService.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include "common.h"
|
||||
#include "ThreadIpcService.h"
|
||||
|
||||
void ThreadIpcService::ThreadMain()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
rtos_waitEvent(&_event, false, true);
|
||||
if (_messageValid)
|
||||
{
|
||||
_messageValid = false;
|
||||
HandleMessage(_message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ThreadIpcService::Start()
|
||||
{
|
||||
rtos_createEvent(&_event);
|
||||
rtos_createThread(&_thread, _priority, [] (void* arg)
|
||||
{
|
||||
static_cast<ThreadIpcService*>(arg)->ThreadMain();
|
||||
}, this, _stack, _stackSize);
|
||||
rtos_wakeupThread(&_thread);
|
||||
IpcService::Start();
|
||||
}
|
||||
|
||||
void ThreadIpcService::OnMessageReceived(u32 data)
|
||||
{
|
||||
_message = data;
|
||||
_messageValid = true;
|
||||
rtos_signalEvent(&_event);
|
||||
}
|
||||
26
examples/mass-storage/common/ipc/ThreadIpcService.h
Normal file
26
examples/mass-storage/common/ipc/ThreadIpcService.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
#include <libtwl/rtos/rtosThread.h>
|
||||
#include <libtwl/rtos/rtosEvent.h>
|
||||
#include "IpcService.h"
|
||||
|
||||
class ThreadIpcService : public IpcService
|
||||
{
|
||||
rtos_thread_t _thread;
|
||||
rtos_event_t _event;
|
||||
u32* _stack;
|
||||
u32 _stackSize;
|
||||
u8 _priority;
|
||||
bool _messageValid = false;
|
||||
u32 _message;
|
||||
|
||||
void ThreadMain();
|
||||
|
||||
public:
|
||||
ThreadIpcService(u32 ipcChannel, u8 priority, u32* stack, u32 stackSize)
|
||||
: IpcService(ipcChannel), _stack(stack), _stackSize(stackSize), _priority(priority) { }
|
||||
|
||||
void Start() override;
|
||||
void OnMessageReceived(u32 data) override;
|
||||
|
||||
virtual void HandleMessage(u32 data);
|
||||
};
|
||||
7
examples/mass-storage/common/ipcChannels.h
Normal file
7
examples/mass-storage/common/ipcChannels.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#define IPC_CHANNEL_DSI_SD 16
|
||||
#define IPC_CHANNEL_DLDI 17
|
||||
#define IPC_CHANNEL_LOADER 18
|
||||
#define IPC_CHANNEL_SOUND 19
|
||||
#define IPC_CHANNEL_RTC 20
|
||||
Reference in New Issue
Block a user