Initial commit

This commit is contained in:
Gericom
2025-11-22 17:21:45 +01:00
commit 5d6f67c612
517 changed files with 63025 additions and 0 deletions

11
common/ipc/IpcService.cpp Normal file
View 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
common/ipc/IpcService.h Normal file
View 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;
};

View 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, 5, [] (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);
}

View 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);
};