mirror of
https://github.com/pret/pokediamond.git
synced 2026-10-01 12:56:48 -05:00
Merge branch 'master' into pikalax_work
This commit is contained in:
@@ -11,7 +11,7 @@ add_compile_options(-fms-extensions)
|
||||
file(GLOB_RECURSE SOURCES RELATIVE ${CMAKE_SOURCE_DIR} "*.c" "*.cpp")
|
||||
|
||||
add_executable(PokeDiamond ${SOURCES})
|
||||
target_include_directories(PokeDiamond PRIVATE include include-mw arm9/lib/include)
|
||||
target_include_directories(PokeDiamond PRIVATE include include-mw arm9/lib/include arm7/lib/include)
|
||||
|
||||
add_executable(calcrom .travis/calcrom/calcrom.cpp)
|
||||
target_include_directories(calcrom PRIVATE /usr/local/include)
|
||||
|
||||
@@ -12,4 +12,14 @@ void MIi_CpuCopyFast(register u32 * src, register u32 * dst, register u32 size);
|
||||
void MI_CpuFill8(register u8 value, register u8 * dst, register u32 size);
|
||||
void MI_CpuCopy8(register u8 * src, register u8 * dst, register u32 size);
|
||||
|
||||
static inline void MI_CpuFill32(void *dest, u32 data, u32 size)
|
||||
{
|
||||
MIi_CpuClear32(data, dest, size);
|
||||
}
|
||||
|
||||
static inline void MI_CpuClear32(void *dest, u32 size)
|
||||
{
|
||||
MI_CpuFill32(dest, 0, size);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
9
arm7/lib/include/OS_alarm.h
Normal file
9
arm7/lib/include/OS_alarm.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef POKEDIAMOND_ARM7_OS_ALARM_H
|
||||
#define POKEDIAMOND_ARM7_OS_ALARM_H
|
||||
|
||||
#include "nitro/OS_alarm_shared.h"
|
||||
|
||||
void OS_CreateAlarm(OSAlarm *alarm);
|
||||
void OS_SetAlarm(OSAlarm *alarm, OSTick tick, OSAlarmHandler handler, void *arg);
|
||||
|
||||
#endif //POKEDIAMOND_ARM7_OS_ALARM_H
|
||||
@@ -13,4 +13,8 @@ typedef struct OSContext
|
||||
u32 sp_svc;
|
||||
} OSContext;
|
||||
|
||||
extern u32 OS_SaveContext(OSContext *context);
|
||||
extern void OS_LoadContext(OSContext *context);
|
||||
extern void OS_InitContext(OSContext *context, u32 func, u32 stack);
|
||||
|
||||
#endif //POKEDIAMOND_ARM7_OS_CONTEXT_H
|
||||
|
||||
9
arm7/lib/include/OS_mutex.h
Normal file
9
arm7/lib/include/OS_mutex.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef POKEDIAMOND_ARM7_OS_MUTEX_H
|
||||
#define POKEDIAMOND_ARM7_OS_MUTEX_H
|
||||
|
||||
#include "OS_context.h"
|
||||
#include "nitro/OS_mutex_shared.h"
|
||||
|
||||
void OSi_UnlockAllMutex(OSThread * thread);
|
||||
|
||||
#endif //POKEDIAMOND_ARM7_OS_MUTEX_H
|
||||
@@ -4,4 +4,33 @@
|
||||
#include "OS_context.h"
|
||||
#include "nitro/OS_thread_shared.h"
|
||||
|
||||
static s32 OSi_GetUnusedThreadId(void);
|
||||
static void OSi_InsertLinkToQueue(OSThreadQueue *queue, OSThread *thread);
|
||||
static OSThread *OSi_RemoveLinkFromQueue(OSThreadQueue *queue);
|
||||
static OSThread *OSi_RemoveSpecifiedLinkFromQueue(OSThreadQueue *queue, OSThread *thread);
|
||||
OSMutex *OSi_RemoveMutexLinkFromQueue(OSMutexQueue *queue);
|
||||
static void OSi_InsertThreadToList(OSThread *thread);
|
||||
static void OSi_RemoveThreadFromList(OSThread *thread);
|
||||
static void OSi_RescheduleThread(void);
|
||||
void OS_InitThread(void);
|
||||
void OS_CreateThread(OSThread *thread, void (*func) (void *), void *arg, void *stack, u32 stackSize, u32 prio);
|
||||
void OS_ExitThread(void);
|
||||
static void OSi_ExitThread_ArgSpecified(OSThread *thread, void *arg);
|
||||
static void OSi_ExitThread(void *arg);
|
||||
static void OSi_ExitThread_Destroy(void);
|
||||
void OS_JoinThread(OSThread *thread);
|
||||
BOOL OS_IsThreadTerminated(const OSThread *thread);
|
||||
void OS_SleepThread(OSThreadQueue *queue);
|
||||
void OS_WakeupThread(OSThreadQueue *queue);
|
||||
void OS_WakeupThreadDirect(OSThread *thread);
|
||||
OSThread *OS_SelectThread(void);
|
||||
void OS_RescheduleThread(void);
|
||||
BOOL OS_SetThreadPriority(OSThread *thread, u32 prio);
|
||||
void OS_Sleep(u32 msec);
|
||||
static void OSi_SleepAlarmCallback(void *arg);
|
||||
OSSwitchThreadCallback OS_SetSwitchThreadCallback(OSSwitchThreadCallback callback);
|
||||
u32 OS_DisableScheduler(void);
|
||||
u32 OS_EnableScheduler(void);
|
||||
void OS_SetThreadDestructor(OSThread *thread, OSThreadDestructor dtor);
|
||||
|
||||
#endif //POKEDIAMOND_ARM7_OS_THREAD_H
|
||||
|
||||
@@ -4,5 +4,6 @@
|
||||
#include "nitro/consts_shared.h"
|
||||
#include "mmap.h"
|
||||
#include "registers.h"
|
||||
#include "systemWork.h"
|
||||
|
||||
#endif //POKEDIAMOND_ARM7_CONSTS_H
|
||||
|
||||
7
arm7/lib/include/systemWork.h
Normal file
7
arm7/lib/include/systemWork.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#ifndef POKEDIAMOND_ARM7_SYSTEMWORK_H
|
||||
#define POKEDIAMOND_ARM7_SYSTEMWORK_H
|
||||
|
||||
#include "OS_context.h"
|
||||
#include "nitro/OS_systemWork_shared.h"
|
||||
|
||||
#endif //POKEDIAMOND_ARM7_SYSTEMWORK_H
|
||||
597
arm7/lib/src/OS_thread.c
Normal file
597
arm7/lib/src/OS_thread.c
Normal file
@@ -0,0 +1,597 @@
|
||||
#include "OS_thread.h"
|
||||
#include "function_target.h"
|
||||
#include "OS_system.h"
|
||||
#include "consts.h"
|
||||
#include "OS_terminate_proc.h"
|
||||
#include "OS_mutex.h"
|
||||
#include "OS_alarm.h"
|
||||
#include "OS_context.h"
|
||||
#include "nitro/OS_systemWork_shared.h"
|
||||
#include "MI_memory.h"
|
||||
|
||||
extern void SDK_SYS_STACKSIZE(void);
|
||||
extern void SDK_IRQ_STACKSIZE(void);
|
||||
|
||||
u32 OSi_RescheduleCount = 0;
|
||||
|
||||
void *OSi_StackForDestructor = NULL;
|
||||
|
||||
OSThreadInfo OSi_ThreadInfo;
|
||||
|
||||
BOOL OSi_IsThreadInitialized = FALSE;
|
||||
|
||||
OSThread **OSi_CurrentThreadPtr = NULL;
|
||||
|
||||
void *OSi_SystemCallbackInSwitchThread = NULL;
|
||||
|
||||
static s32 OSi_ThreadIdCount = 0;
|
||||
|
||||
OSThread OSi_LauncherThread;
|
||||
OSThread OSi_IdleThread;
|
||||
|
||||
ARM_FUNC static s32 OSi_GetUnusedThreadId(void)
|
||||
{
|
||||
return ++OSi_ThreadIdCount;
|
||||
}
|
||||
|
||||
ARM_FUNC static void OSi_InsertLinkToQueue(OSThreadQueue *queue, OSThread *thread)
|
||||
{
|
||||
OSThread *next = queue->head;
|
||||
|
||||
while (next && next->priority <= thread->priority)
|
||||
{
|
||||
if (next == thread)
|
||||
return;
|
||||
next = next->link.next;
|
||||
}
|
||||
|
||||
if (!next)
|
||||
{
|
||||
OSThread *prev = queue->tail;
|
||||
|
||||
if (!prev)
|
||||
{
|
||||
queue->head = thread;
|
||||
}
|
||||
else
|
||||
{
|
||||
prev->link.next = thread;
|
||||
}
|
||||
|
||||
thread->link.prev = prev;
|
||||
thread->link.next = NULL;
|
||||
queue->tail = thread;
|
||||
}
|
||||
else
|
||||
{
|
||||
OSThread *prev = next->link.prev;
|
||||
|
||||
if (!prev)
|
||||
{
|
||||
queue->head = thread;
|
||||
}
|
||||
else
|
||||
{
|
||||
prev->link.next = thread;
|
||||
}
|
||||
|
||||
thread->link.prev = prev;
|
||||
thread->link.next = next;
|
||||
next->link.prev = thread;
|
||||
}
|
||||
}
|
||||
|
||||
ARM_FUNC static OSThread *OSi_RemoveLinkFromQueue(OSThreadQueue *queue)
|
||||
{
|
||||
OSThread *thread = queue->head;
|
||||
|
||||
if (thread)
|
||||
{
|
||||
OSThread *next = thread->link.next;
|
||||
|
||||
queue->head = next;
|
||||
|
||||
if (next)
|
||||
{
|
||||
next->link.prev = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
queue->tail = NULL;
|
||||
thread->queue = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return thread;
|
||||
}
|
||||
|
||||
ARM_FUNC static OSThread *OSi_RemoveSpecifiedLinkFromQueue(OSThreadQueue *queue, OSThread *thread)
|
||||
{
|
||||
OSThread *queueHead = queue->head;
|
||||
|
||||
while (queueHead)
|
||||
{
|
||||
OSThread *next = queueHead->link.next;
|
||||
|
||||
if (queueHead == thread)
|
||||
{
|
||||
OSThread *prev = queueHead->link.prev;
|
||||
|
||||
if (queue->head == queueHead)
|
||||
{
|
||||
queue->head = next;
|
||||
}
|
||||
else
|
||||
{
|
||||
prev->link.next = next;
|
||||
}
|
||||
|
||||
if (queue->tail == queueHead)
|
||||
{
|
||||
queue->tail = prev;
|
||||
}
|
||||
else
|
||||
{
|
||||
next->link.prev = prev;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
queueHead = next;
|
||||
}
|
||||
|
||||
return queueHead;
|
||||
}
|
||||
|
||||
ARM_FUNC OSMutex *OSi_RemoveMutexLinkFromQueue(OSMutexQueue *queue)
|
||||
{
|
||||
OSMutex *mutexHead = queue->head;
|
||||
|
||||
if (mutexHead)
|
||||
{
|
||||
OSMutex *next = mutexHead->link.next;
|
||||
|
||||
queue->head = next;
|
||||
|
||||
if (next)
|
||||
{
|
||||
next->link.prev = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
queue->tail = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return mutexHead;
|
||||
}
|
||||
|
||||
ARM_FUNC static void OSi_InsertThreadToList(OSThread *thread)
|
||||
{
|
||||
OSThread *t = OSi_ThreadInfo.list;
|
||||
OSThread *pre = NULL;
|
||||
|
||||
while(t && t->priority < thread->priority)
|
||||
{
|
||||
pre = t;
|
||||
t = t->next;
|
||||
}
|
||||
|
||||
if (!pre)
|
||||
{
|
||||
thread->next = OSi_ThreadInfo.list;
|
||||
OSi_ThreadInfo.list = thread;
|
||||
}
|
||||
else
|
||||
{
|
||||
thread->next = pre->next;
|
||||
pre->next = thread;
|
||||
}
|
||||
}
|
||||
|
||||
ARM_FUNC static void OSi_RemoveThreadFromList(OSThread *thread)
|
||||
{
|
||||
OSThread *t = OSi_ThreadInfo.list;
|
||||
OSThread *pre = NULL;
|
||||
|
||||
while (t && t != thread)
|
||||
{
|
||||
pre = t;
|
||||
t = t-> next;
|
||||
}
|
||||
|
||||
if (!pre)
|
||||
{
|
||||
OSi_ThreadInfo.list = thread->next;
|
||||
}
|
||||
else
|
||||
{
|
||||
pre->next = thread->next;
|
||||
}
|
||||
}
|
||||
|
||||
ARM_FUNC static void OSi_RescheduleThread(void)
|
||||
{
|
||||
if (OSi_RescheduleCount <= 0)
|
||||
{
|
||||
OSThreadInfo *info = &OSi_ThreadInfo;
|
||||
if (info->irqDepth > 0 || OS_GetProcMode() == OS_PROCMODE_IRQ)
|
||||
{
|
||||
info->isNeedRescheduling = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
OSThread *currentThread = OSi_GetCurrentThread();
|
||||
OSThread *nextThread = OS_SelectThread();
|
||||
|
||||
if (currentThread == nextThread || !nextThread)
|
||||
return;
|
||||
|
||||
if (currentThread->state != OS_THREAD_STATE_TERMINATED
|
||||
&& OS_SaveContext(¤tThread->context))
|
||||
return;
|
||||
|
||||
if (OSi_SystemCallbackInSwitchThread)
|
||||
{
|
||||
((OSSwitchThreadCallback)OSi_SystemCallbackInSwitchThread) (currentThread, nextThread);
|
||||
}
|
||||
|
||||
if (info->switchCallback)
|
||||
{
|
||||
((OSSwitchThreadCallback)info->switchCallback) (currentThread, nextThread);
|
||||
}
|
||||
|
||||
OS_SetCurrentThread(nextThread);
|
||||
|
||||
OS_LoadContext(&nextThread->context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ARM_FUNC void OS_InitThread(void)
|
||||
{
|
||||
if (OSi_IsThreadInitialized)
|
||||
return;
|
||||
OSi_IsThreadInitialized = TRUE;
|
||||
|
||||
OSi_CurrentThreadPtr = &(OSi_ThreadInfo.current);
|
||||
|
||||
OSi_LauncherThread.priority = OS_THREAD_LAUNCHER_PRIORITY;
|
||||
OSi_LauncherThread.id = 0;
|
||||
OSi_LauncherThread.state = OS_THREAD_STATE_READY;
|
||||
OSi_LauncherThread.next = NULL;
|
||||
|
||||
OSi_LauncherThread.profiler = NULL;
|
||||
|
||||
OSi_ThreadInfo.list = &OSi_LauncherThread;
|
||||
|
||||
OS_SetCurrentThread(&OSi_LauncherThread);
|
||||
|
||||
void *stackLo = (((s32)SDK_SYS_STACKSIZE) <= 0) ?
|
||||
(void *)((u32)HW_WRAM - (s32)SDK_SYS_STACKSIZE) :
|
||||
(void *)((u32)(HW_PRV_WRAM_IRQ_STACK_END - (s32)SDK_IRQ_STACKSIZE) - (s32)SDK_SYS_STACKSIZE);
|
||||
|
||||
OSi_LauncherThread.stackBottom = (u32)(HW_PRV_WRAM_IRQ_STACK_END - (s32)SDK_IRQ_STACKSIZE);
|
||||
OSi_LauncherThread.stackTop = (u32)stackLo;
|
||||
OSi_LauncherThread.stackWarningOffset = 0;
|
||||
|
||||
//checksums
|
||||
*(u32 *)(OSi_LauncherThread.stackBottom - sizeof(u32)) = 0xd73bfdf7UL;
|
||||
*(u32 *)OSi_LauncherThread.stackTop = 0xfbdd37bbUL;
|
||||
|
||||
OS_InitThreadQueue(&OSi_LauncherThread.joinQueue);
|
||||
|
||||
OSi_ThreadInfo.isNeedRescheduling = FALSE;
|
||||
OSi_ThreadInfo.irqDepth = 0;
|
||||
|
||||
OS_GetSystemWork()->threadinfo_subp = &OSi_ThreadInfo;
|
||||
|
||||
(void)OS_SetSwitchThreadCallback(NULL);
|
||||
}
|
||||
|
||||
ARM_FUNC void OS_CreateThread(OSThread *thread, void (*func) (void *), void *arg, void *stack, u32 stackSize, u32 prio)
|
||||
{
|
||||
OSIntrMode enable = OS_DisableInterrupts();
|
||||
|
||||
s32 index = OSi_GetUnusedThreadId();
|
||||
|
||||
thread->priority = prio;
|
||||
thread->id = (u32)index;
|
||||
thread->state = OS_THREAD_STATE_WAITING;
|
||||
|
||||
thread->profiler = NULL;
|
||||
|
||||
OSi_InsertThreadToList(thread);
|
||||
|
||||
thread->stackBottom = (u32)stack;
|
||||
thread->stackTop = (u32)stack - stackSize;
|
||||
thread->stackWarningOffset = 0;
|
||||
|
||||
*(u32 *)(thread->stackBottom - sizeof(u32)) = 0xd73bfdf7UL;
|
||||
*(u32 *)thread->stackTop = 0xfbdd37bbUL;
|
||||
|
||||
OS_InitThreadQueue(&thread->joinQueue);
|
||||
|
||||
OS_InitContext(&thread->context, (u32)func, (u32)stack - 4);
|
||||
|
||||
thread->context.r[0] = (u32)arg;
|
||||
thread->context.lr = (u32)OS_ExitThread;
|
||||
|
||||
MI_CpuClear32((void *)((u32)stack - stackSize + 4), stackSize - 8);
|
||||
|
||||
thread->mutex = NULL;
|
||||
thread->mutexQueue.head = NULL;
|
||||
thread->mutexQueue.tail = NULL;
|
||||
|
||||
OS_SetThreadDestructor(thread, NULL);
|
||||
|
||||
thread->queue = NULL;
|
||||
thread->link.prev = thread->link.next = NULL;
|
||||
|
||||
MI_CpuClear32(&thread->specific[0], sizeof(void *) * OS_THREAD_SPECIFIC_MAX);
|
||||
|
||||
thread->alarmForSleep = NULL;
|
||||
|
||||
(void)OS_RestoreInterrupts(enable);
|
||||
}
|
||||
|
||||
ARM_FUNC void OS_ExitThread(void)
|
||||
{
|
||||
(void)OS_DisableInterrupts();
|
||||
OSi_ExitThread_ArgSpecified(OS_GetCurrentThread(), 0);
|
||||
}
|
||||
|
||||
ARM_FUNC static void OSi_ExitThread_ArgSpecified(OSThread *thread, void *arg)
|
||||
{
|
||||
if (OSi_StackForDestructor)
|
||||
{
|
||||
OS_InitContext(&thread->context, (u32)OSi_ExitThread, (u32)OSi_StackForDestructor);
|
||||
thread->context.r[0] = (u32)arg;
|
||||
thread->context.cpsr |= HW_PSR_DISABLE_IRQ;
|
||||
thread->state = OS_THREAD_STATE_READY;
|
||||
OS_LoadContext(&thread->context);
|
||||
}
|
||||
else
|
||||
{
|
||||
OSi_ExitThread(arg);
|
||||
}
|
||||
}
|
||||
|
||||
ARM_FUNC static void OSi_ExitThread(void *arg)
|
||||
{
|
||||
OSThread *currentThread = OSi_GetCurrentThread();
|
||||
OSThreadDestructor destructor = currentThread->destructor;
|
||||
|
||||
if (destructor)
|
||||
{
|
||||
currentThread->destructor = NULL;
|
||||
destructor(arg);
|
||||
(void)OS_DisableInterrupts();
|
||||
}
|
||||
|
||||
OSi_ExitThread_Destroy();
|
||||
}
|
||||
|
||||
ARM_FUNC static void OSi_ExitThread_Destroy(void)
|
||||
{
|
||||
OSThread *currentThread = OSi_GetCurrentThread();
|
||||
(void)OS_DisableScheduler();
|
||||
|
||||
OSi_UnlockAllMutex(currentThread);
|
||||
|
||||
if (currentThread->queue)
|
||||
{
|
||||
(void)OSi_RemoveSpecifiedLinkFromQueue(currentThread->queue, currentThread);
|
||||
}
|
||||
|
||||
OSi_RemoveThreadFromList(currentThread);
|
||||
|
||||
currentThread->state = OS_THREAD_STATE_TERMINATED;
|
||||
|
||||
OS_WakeupThread(¤tThread->joinQueue);
|
||||
|
||||
(void)OS_EnableScheduler();
|
||||
|
||||
OS_RescheduleThread();
|
||||
|
||||
OS_Terminate();
|
||||
}
|
||||
|
||||
ARM_FUNC void OS_JoinThread(OSThread *thread)
|
||||
{
|
||||
OSIntrMode enabled = OS_DisableInterrupts();
|
||||
|
||||
if (thread->state != OS_THREAD_STATE_TERMINATED)
|
||||
{
|
||||
OS_SleepThread(&thread->joinQueue);
|
||||
}
|
||||
|
||||
(void)OS_RestoreInterrupts(enabled);
|
||||
}
|
||||
|
||||
ARM_FUNC BOOL OS_IsThreadTerminated(const OSThread *thread)
|
||||
{
|
||||
return (thread->state == OS_THREAD_STATE_TERMINATED) ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
ARM_FUNC void OS_SleepThread(OSThreadQueue *queue)
|
||||
{
|
||||
OSIntrMode enabled = OS_DisableInterrupts();
|
||||
OSThread *currentThread = OSi_GetCurrentThread();
|
||||
|
||||
if (queue)
|
||||
{
|
||||
currentThread->queue = queue;
|
||||
OSi_InsertLinkToQueue(queue, currentThread);
|
||||
}
|
||||
|
||||
currentThread->state = OS_THREAD_STATE_WAITING;
|
||||
OSi_RescheduleThread();
|
||||
|
||||
(void)OS_RestoreInterrupts(enabled);
|
||||
}
|
||||
|
||||
ARM_FUNC void OS_WakeupThread(OSThreadQueue *queue)
|
||||
{
|
||||
OSIntrMode enabled = OS_DisableInterrupts();
|
||||
|
||||
if (queue->head)
|
||||
{
|
||||
while (queue->head)
|
||||
{
|
||||
OSThread *thread = OSi_RemoveLinkFromQueue(queue);
|
||||
|
||||
thread->state = OS_THREAD_STATE_READY;
|
||||
thread->queue = NULL;
|
||||
thread->link.prev = thread->link.next = NULL;
|
||||
}
|
||||
|
||||
OS_InitThreadQueue(queue);
|
||||
OSi_RescheduleThread();
|
||||
}
|
||||
|
||||
(void)OS_RestoreInterrupts(enabled);
|
||||
}
|
||||
|
||||
ARM_FUNC void OS_WakeupThreadDirect(OSThread *thread)
|
||||
{
|
||||
OSIntrMode enabled = OS_DisableInterrupts();
|
||||
|
||||
thread->state = OS_THREAD_STATE_READY;
|
||||
OSi_RescheduleThread();
|
||||
|
||||
(void)OS_RestoreInterrupts(enabled);
|
||||
}
|
||||
|
||||
ARM_FUNC OSThread *OS_SelectThread(void)
|
||||
{
|
||||
OSThread *thread = OSi_ThreadInfo.list;
|
||||
|
||||
while (thread && !OS_IsThreadRunnable(thread))
|
||||
{
|
||||
thread = thread->next;
|
||||
}
|
||||
|
||||
return thread;
|
||||
}
|
||||
|
||||
ARM_FUNC void OS_RescheduleThread(void)
|
||||
{
|
||||
OSIntrMode enabled = OS_DisableInterrupts();
|
||||
OSi_RescheduleThread();
|
||||
(void)OS_RestoreInterrupts(enabled);
|
||||
}
|
||||
|
||||
ARM_FUNC BOOL OS_SetThreadPriority(OSThread *thread, u32 prio)
|
||||
{
|
||||
OSThread *t = OSi_ThreadInfo.list;
|
||||
OSThread *pre = NULL;
|
||||
OSIntrMode enabled = OS_DisableInterrupts();
|
||||
|
||||
while (t && t != thread)
|
||||
{
|
||||
pre = t;
|
||||
t = t->next;
|
||||
}
|
||||
|
||||
if (!t || t == &OSi_IdleThread)
|
||||
{
|
||||
(void)OS_RestoreInterrupts(enabled);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (t->priority != prio)
|
||||
{
|
||||
if (!pre)
|
||||
{
|
||||
OSi_ThreadInfo.list = thread->next;
|
||||
}
|
||||
else
|
||||
{
|
||||
pre->next = thread->next;
|
||||
}
|
||||
|
||||
thread->priority = prio;
|
||||
OSi_InsertThreadToList(thread);
|
||||
|
||||
OSi_RescheduleThread();
|
||||
}
|
||||
|
||||
(void)OS_RestoreInterrupts(enabled);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
ARM_FUNC void OS_Sleep(u32 msec)
|
||||
{
|
||||
OSAlarm alarm;
|
||||
|
||||
OS_CreateAlarm(&alarm);
|
||||
OSThread *volatile p_thread = OSi_GetCurrentThread();
|
||||
OSIntrMode enabled = OS_DisableInterrupts();
|
||||
|
||||
p_thread->alarmForSleep = &alarm;
|
||||
|
||||
OS_SetAlarm(&alarm, OS_MilliSecondsToTicks(msec), &OSi_SleepAlarmCallback,
|
||||
(void*)&p_thread);
|
||||
while (p_thread != NULL)
|
||||
{
|
||||
OS_SleepThread(NULL);
|
||||
}
|
||||
(void)OS_RestoreInterrupts(enabled);
|
||||
}
|
||||
|
||||
ARM_FUNC static void OSi_SleepAlarmCallback(void *arg)
|
||||
{
|
||||
OSThread **pp_thread = (OSThread **)arg;
|
||||
OSThread *p_thread = *pp_thread;
|
||||
*pp_thread = NULL;
|
||||
|
||||
p_thread->alarmForSleep = NULL;
|
||||
|
||||
OS_WakeupThreadDirect(p_thread);
|
||||
}
|
||||
|
||||
ARM_FUNC OSSwitchThreadCallback OS_SetSwitchThreadCallback(OSSwitchThreadCallback callback)
|
||||
{
|
||||
OSIntrMode enabled = OS_DisableInterrupts();
|
||||
OSSwitchThreadCallback prev = OSi_ThreadInfo.switchCallback;
|
||||
OSi_ThreadInfo.switchCallback = callback;
|
||||
|
||||
(void)OS_RestoreInterrupts(enabled);
|
||||
return prev;
|
||||
}
|
||||
|
||||
ARM_FUNC u32 OS_DisableScheduler(void)
|
||||
{
|
||||
OSIntrMode enabled = OS_DisableInterrupts();
|
||||
u32 count;
|
||||
|
||||
if (OSi_RescheduleCount < (u32)-1)
|
||||
{
|
||||
count = OSi_RescheduleCount++;
|
||||
}
|
||||
(void)OS_RestoreInterrupts(enabled);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
ARM_FUNC u32 OS_EnableScheduler(void)
|
||||
{
|
||||
OSIntrMode enabled = OS_DisableInterrupts();
|
||||
u32 count = 0;
|
||||
|
||||
if (OSi_RescheduleCount > 0)
|
||||
{
|
||||
count = OSi_RescheduleCount--;
|
||||
}
|
||||
(void)OS_RestoreInterrupts(enabled);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
ARM_FUNC void OS_SetThreadDestructor(OSThread *thread, OSThreadDestructor dtor)
|
||||
{
|
||||
thread->destructor = dtor;
|
||||
}
|
||||
@@ -1,28 +1,13 @@
|
||||
#ifndef POKEDIAMOND_OS_ALARM_H
|
||||
#define POKEDIAMOND_OS_ALARM_H
|
||||
#ifndef POKEDIAMOND_ARM9_OS_ALARM_H
|
||||
#define POKEDIAMOND_ARM9_OS_ALARM_H
|
||||
|
||||
#include "nitro/types.h"
|
||||
#include "OS_thread.h"
|
||||
#include "OS_tick.h"
|
||||
|
||||
typedef void (*OSAlarmHandler) (void *);
|
||||
|
||||
struct OSiAlarm
|
||||
{
|
||||
OSAlarmHandler handler;
|
||||
void *arg;
|
||||
|
||||
u32 tag;
|
||||
OSTick fire;
|
||||
OSAlarm *prev;
|
||||
OSAlarm *next;
|
||||
|
||||
OSTick period;
|
||||
OSTick start;
|
||||
};
|
||||
#include "nitro/OS_alarm_shared.h"
|
||||
|
||||
void OS_CancelAlarm(OSAlarm *alarm);
|
||||
void OS_CreateAlarm(OSAlarm *alarm);
|
||||
void OS_SetAlarm(OSAlarm *alarm, OSTick tick, OSAlarmHandler handler, void *arg);
|
||||
|
||||
#endif //POKEDIAMOND_OS_ALARM_H
|
||||
#endif //POKEDIAMOND_ARM9_OS_ALARM_H
|
||||
|
||||
@@ -1,16 +1,10 @@
|
||||
#ifndef POKEDIAMOND_OS_MUTEX_H
|
||||
#define POKEDIAMOND_OS_MUTEX_H
|
||||
#ifndef POKEDIAMOND_ARM9_OS_MUTEX_H
|
||||
#define POKEDIAMOND_ARM9_OS_MUTEX_H
|
||||
|
||||
#include "nitro/types.h"
|
||||
#include "OS_thread.h"
|
||||
|
||||
struct OSMutex {
|
||||
OSThreadQueue queue;
|
||||
OSThread *thread;
|
||||
s32 count;
|
||||
OSMutexLink link;
|
||||
};
|
||||
#include "OS_context.h"
|
||||
#include "nitro/OS_mutex_shared.h"
|
||||
|
||||
void OSi_UnlockAllMutex(OSThread * thread);
|
||||
|
||||
#endif //POKEDIAMOND_OS_MUTEX_H
|
||||
#endif //POKEDIAMOND_ARM9_OS_MUTEX_H
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
#ifndef POKEDIAMOND_OS_TICK_H
|
||||
#define POKEDIAMOND_OS_TICK_H
|
||||
#ifndef POKEDIAMOND_ARM9_OS_TICK_H
|
||||
#define POKEDIAMOND_ARM9_OS_TICK_H
|
||||
|
||||
#include "consts.h"
|
||||
#include "OS_timer.h"
|
||||
|
||||
typedef u64 OSTick;
|
||||
|
||||
#define OS_SYSTEM_CLOCK HW_SYSTEM_CLOCK
|
||||
|
||||
#define OS_MilliSecondsToTicks(msec) ((OSTick)(((OS_SYSTEM_CLOCK/1000) * (u64)(msec)) / 64))
|
||||
#include "nitro/OS_tick_shared.h"
|
||||
|
||||
#define OSi_TICK_TIMERCONTROL (REG_OS_TM0CNT_H_E_MASK | REG_OS_TM0CNT_H_I_MASK | OS_TIMER_PRESCALER_64)
|
||||
|
||||
@@ -18,4 +13,4 @@ static void OSi_CountUpTick(void);
|
||||
OSTick OS_GetTick(void);
|
||||
u16 OS_GetTickLo(void);
|
||||
|
||||
#endif //POKEDIAMOND_OS_TICK_H
|
||||
#endif //POKEDIAMOND_ARM9_OS_TICK_H
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "nitro/consts_shared.h"
|
||||
#include "mmap.h"
|
||||
#include "registers.h"
|
||||
#include "systemWork.h"
|
||||
|
||||
#define HW_C6_PR_4KB 0x16
|
||||
#define HW_C6_PR_8KB 0x18
|
||||
@@ -27,8 +28,6 @@
|
||||
#define HW_C6_PR_2GB 0x3c
|
||||
#define HW_C6_PR_4GB 0x3e
|
||||
|
||||
#define HW_SYSTEM_CLOCK 33514000
|
||||
|
||||
#define PXI_PROC_ARM7 0x01
|
||||
|
||||
#define OSi_CONSOLE_NOT_DETECT 0xffffffff
|
||||
@@ -38,12 +37,6 @@
|
||||
#define OS_CONSOLE_SIZE_MASK 0x00000003
|
||||
#define OS_CONSOLE_SIZE_4MB 0x00000001
|
||||
|
||||
#define OS_THREAD_LAUNCHER_PRIORITY 0x10
|
||||
#define OS_THREAD_PRIORITY_MIN 0x00
|
||||
#define OS_THREAD_PRIORITY_MAX 0x1F
|
||||
|
||||
#define OS_THREAD_SPECIFIC_MAX 0x03
|
||||
|
||||
#define OSi_TCM_REGION_BASE_MASK 0xfffff000
|
||||
|
||||
#define OS_IE_V_BLANK (1UL << 0)
|
||||
|
||||
@@ -14,8 +14,6 @@ extern u32 SDK_AUTOLOAD_DTCM_START[];
|
||||
#define HW_ITCM_SIZE 0x00008000
|
||||
#define HW_ITCM_END (HW_ITCM + HW_ITCM_SIZE)
|
||||
|
||||
#define HW_WRAM 0x037F8000
|
||||
|
||||
#define HW_DTCM ((u32)SDK_AUTOLOAD_DTCM_START)
|
||||
#define HW_DTCM_SIZE 0x00004000
|
||||
|
||||
@@ -29,7 +27,6 @@ extern u32 SDK_AUTOLOAD_DTCM_START[];
|
||||
#define HW_ROM_BASE_OFFSET_BUF (HW_MAIN_MEM + 0x007ffc2c)
|
||||
#define HW_ROM_HEADER_BUF (HW_MAIN_MEM + 0x007ffe00) // ROM registration area data buffer
|
||||
#define HW_RED_RESERVED (HW_MAIN_MEM + 0x007ff800) // Some kind of reserved data for shared memory
|
||||
#define HW_MAIN_MEM_SYSTEM (HW_MAIN_MEM + 0x007ffc00)
|
||||
#define HW_MAIN_MEM_EX_END (HW_MAIN_MEM + HW_MAIN_MEM_EX_SIZE)
|
||||
#define HW_MAIN_MEM_SHARED (HW_MAIN_MEM_EX_END - HW_MAIN_MEM_SHARED_SIZE)
|
||||
#define HW_DTCM_SVC_STACK_END (HW_DTCM + 0x00003fc0)
|
||||
@@ -60,52 +57,4 @@ extern u32 SDK_AUTOLOAD_DTCM_START[];
|
||||
#define OSi_WRAM_MAIN_ARENA_HI_DEFAULT (HW_WRAM)
|
||||
#define OSi_WRAM_MAIN_ARENA_LO_DEFAULT (HW_WRAM)
|
||||
|
||||
#include "OS_thread.h" //not ideal but it's necessary
|
||||
#include "OS_spinLock.h"
|
||||
|
||||
typedef struct {
|
||||
u8 bootCheckInfo[0x20]; // 000-01f: 32byte boot check info
|
||||
u32 resetParameter; // 020-023: 4byte reset parameter
|
||||
u8 padding5[0x8]; // 024-02c: (8byte)
|
||||
u32 romBaseOffset; // 02c-02f: 4byte ROM offset of own program
|
||||
u8 cartridgeModuleInfo[12]; // 030-03b: 12byte cartridge module info
|
||||
u32 vblankCount; // 03c-03f: 4byte V-Blank Count
|
||||
u8 wmBootBuf[0x40]; // 040-07f: 64byte WM multiboot buffer
|
||||
u8 nvramUserInfo[0x100]; // 080-17f: 256bytes NVRAM user info
|
||||
u8 isd_reserved1[0x20]; // 180-19f: 32bytes ISDebugger reserved
|
||||
u8 arenaInfo[0x48]; // 1a0-1e7: 72byte Arena information
|
||||
u8 real_time_clock[8]; // 1e8-1ef: 8bytes RTC
|
||||
u32 dmaClearBuf[4]; // 1f0-1ff: 16bytes DMA clear information buffer (for ARM9-TEG)
|
||||
u8 rom_header[0x160]; // 200-35f: 352bytes ROM registration area info storage buffer
|
||||
u8 isd_reserved2[32]; // 360-37f: 32bytes ISDebugger reserved
|
||||
u32 pxiSignalParam[2]; // 380-387: 8bytes Param for PXI Signal
|
||||
u32 pxiHandleChecker[2]; // 388-38f: 8bytes Flag for PXI Command Handler Installed
|
||||
u32 mic_last_address; // 390-393: 4bytes MIC latest sampling result storage address
|
||||
u16 mic_sampling_data; // 394-395: 2bytes MIC sampling result
|
||||
u16 wm_callback_control; // 396-397: 2bytes Parameter for WM callback synchronization
|
||||
u16 wm_rssi_pool; // 398-399: 2bytes Random number source depends on WM received signal intensity
|
||||
u8 padding3[2]; // 39a-39b: (2bytes)
|
||||
u32 component_param; // 39c-39f: 4bytes Parameter for Component synchronization
|
||||
OSThreadInfo *threadinfo_mainp; // 3a0-3a3: 4bytes Verify that the pointer to ARM9 thread information is initial value 0
|
||||
OSThreadInfo *threadinfo_subp; // 3a4-3a7: 4bytes Verify that the pointer to ARM7 thread information is initial value 0
|
||||
u16 button_XY; // 3a8-3a9: 2bytes XY button information storage location
|
||||
u8 touch_panel[4]; // 3aa-3ad: 4bytes Touch Screen information storage location
|
||||
u16 autoloadSync; // 3ae-3af: 2bytes autoload sync between processors
|
||||
u32 lockIDFlag_mainp[2]; // 3b0-3b7: 8bytes lockID management flag (ARM9)
|
||||
u32 lockIDFlag_subp[2]; // 3b8-3bf: 8bytes lockID management flag (ARM7)
|
||||
struct OSLockWord lock_VRAM_C; // 3c0-3c7: 8bytes C - lock buffer
|
||||
struct OSLockWord lock_VRAM_D; // 3c8-3cf: 8bytes VRAM-D - lock buffer
|
||||
struct OSLockWord lock_WRAM_BLOCK0; // 3d0-3d7: 8bytes Block0 - lock buffer
|
||||
struct OSLockWord lock_WRAM_BLOCK1; // 3d8-3df: 8bytes CPU internal work RAM - Block1 - lock buffer
|
||||
struct OSLockWord lock_CARD; // 3e0-3e7: 8bytes Game Card - lock buffer
|
||||
struct OSLockWord lock_CARTRIDGE; // 3e8-3ef: 8bytes DS Pak - lock buffer
|
||||
struct OSLockWord lock_INIT; // 3f0-3f7: 8bytes Initialization lock buffer
|
||||
u16 mmem_checker_mainp; // 3f8-3f9: 2bytes MainMomory Size Checker for Main processor
|
||||
u16 mmem_checker_subp; // 3fa-3fb: 2bytes MainMomory Size Checker for Sub processor
|
||||
u8 padding4[2]; // 3fc-3fd: (2bytes)
|
||||
u16 command_area; // 3fe-3ff: 2bytes Command Area
|
||||
} OSSystemWork; //0x027FFC00
|
||||
|
||||
#define OS_GetSystemWork() ((OSSystemWork *)HW_MAIN_MEM_SYSTEM)
|
||||
|
||||
#endif //POKEDIAMOND_ARM9_MMAP_H
|
||||
7
arm9/lib/include/systemWork.h
Normal file
7
arm9/lib/include/systemWork.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#ifndef POKEDIAMOND_ARM9_SYSTEMWORK_H
|
||||
#define POKEDIAMOND_ARM9_SYSTEMWORK_H
|
||||
|
||||
#include "OS_context.h"
|
||||
#include "nitro/OS_systemWork_shared.h"
|
||||
|
||||
#endif //POKEDIAMOND_ARM9_SYSTEMWORK_H
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "OS_terminate_proc.h"
|
||||
#include "OS_interrupt.h"
|
||||
#include "OS_system.h"
|
||||
#include "OS_spinLock.h"
|
||||
#include "sections.h"
|
||||
|
||||
static u16 OSi_IsInitReset = 0;
|
||||
|
||||
35
include/nitro/OS_alarm_shared.h
Normal file
35
include/nitro/OS_alarm_shared.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* NOTE:
|
||||
* This file is shared between ARM9 and ARM7
|
||||
* DO NOT PUT PROC SPECIFIC CODE IN HERE
|
||||
* Thank You!
|
||||
*/
|
||||
|
||||
/*
|
||||
* DO NOT INCLUDE THIS FILE DIRECTLY
|
||||
* Include OS_alarm.h from the specific proc's lib
|
||||
*/
|
||||
|
||||
#ifndef POKEDIAMOND_OS_ALARM_SHARED_H
|
||||
#define POKEDIAMOND_OS_ALARM_SHARED_H
|
||||
|
||||
#include "nitro/types.h"
|
||||
#include "nitro/OS_tick_shared.h"
|
||||
|
||||
typedef void (*OSAlarmHandler) (void *);
|
||||
|
||||
struct OSiAlarm
|
||||
{
|
||||
OSAlarmHandler handler;
|
||||
void *arg;
|
||||
|
||||
u32 tag;
|
||||
OSTick fire;
|
||||
OSAlarm *prev;
|
||||
OSAlarm *next;
|
||||
|
||||
OSTick period;
|
||||
OSTick start;
|
||||
};
|
||||
|
||||
#endif //POKEDIAMOND_OS_ALARM_SHARED_H
|
||||
26
include/nitro/OS_mutex_shared.h
Normal file
26
include/nitro/OS_mutex_shared.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* NOTE:
|
||||
* This file is shared between ARM9 and ARM7
|
||||
* DO NOT PUT PROC SPECIFIC CODE IN HERE
|
||||
* Thank You!
|
||||
*/
|
||||
|
||||
/*
|
||||
* DO NOT INCLUDE THIS FILE DIRECTLY
|
||||
* Include OS_mutex.h from the specific proc's lib
|
||||
*/
|
||||
|
||||
#ifndef POKEDIAMOND_OS_MUTEX_SHARED_H
|
||||
#define POKEDIAMOND_OS_MUTEX_SHARED_H
|
||||
|
||||
#include "nitro/OS_thread_shared.h"
|
||||
#include "nitro/types.h"
|
||||
|
||||
struct OSMutex {
|
||||
OSThreadQueue queue;
|
||||
OSThread *thread;
|
||||
s32 count;
|
||||
OSMutexLink link;
|
||||
};
|
||||
|
||||
#endif //POKEDIAMOND_OS_MUTEX_SHARED_H
|
||||
66
include/nitro/OS_systemWork_shared.h
Normal file
66
include/nitro/OS_systemWork_shared.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* NOTE:
|
||||
* This file is shared between ARM9 and ARM7
|
||||
* DO NOT PUT PROC SPECIFIC CODE IN HERE
|
||||
* Thank You!
|
||||
*/
|
||||
|
||||
/*
|
||||
* DO NOT INCLUDE THIS FILE DIRECTLY
|
||||
* Include consts.h from the specific proc's lib
|
||||
*/
|
||||
|
||||
#ifndef POKEDIAMOND_OS_SYSTEMWORK_SHARED_H
|
||||
#define POKEDIAMOND_OS_SYSTEMWORK_SHARED_H
|
||||
|
||||
#include "nitro/types.h"
|
||||
#include "nitro/mmap_shared.h"
|
||||
#include "nitro/OS_thread_shared.h"
|
||||
#include "nitro/OS_spinLock_shared.h"
|
||||
|
||||
typedef struct {
|
||||
u8 bootCheckInfo[0x20]; // 000-01f: 32byte boot check info
|
||||
u32 resetParameter; // 020-023: 4byte reset parameter
|
||||
u8 padding5[0x8]; // 024-02c: (8byte)
|
||||
u32 romBaseOffset; // 02c-02f: 4byte ROM offset of own program
|
||||
u8 cartridgeModuleInfo[12]; // 030-03b: 12byte cartridge module info
|
||||
u32 vblankCount; // 03c-03f: 4byte V-Blank Count
|
||||
u8 wmBootBuf[0x40]; // 040-07f: 64byte WM multiboot buffer
|
||||
u8 nvramUserInfo[0x100]; // 080-17f: 256bytes NVRAM user info
|
||||
u8 isd_reserved1[0x20]; // 180-19f: 32bytes ISDebugger reserved
|
||||
u8 arenaInfo[0x48]; // 1a0-1e7: 72byte Arena information
|
||||
u8 real_time_clock[8]; // 1e8-1ef: 8bytes RTC
|
||||
u32 dmaClearBuf[4]; // 1f0-1ff: 16bytes DMA clear information buffer (for ARM9-TEG)
|
||||
u8 rom_header[0x160]; // 200-35f: 352bytes ROM registration area info storage buffer
|
||||
u8 isd_reserved2[32]; // 360-37f: 32bytes ISDebugger reserved
|
||||
u32 pxiSignalParam[2]; // 380-387: 8bytes Param for PXI Signal
|
||||
u32 pxiHandleChecker[2]; // 388-38f: 8bytes Flag for PXI Command Handler Installed
|
||||
u32 mic_last_address; // 390-393: 4bytes MIC latest sampling result storage address
|
||||
u16 mic_sampling_data; // 394-395: 2bytes MIC sampling result
|
||||
u16 wm_callback_control; // 396-397: 2bytes Parameter for WM callback synchronization
|
||||
u16 wm_rssi_pool; // 398-399: 2bytes Random number source depends on WM received signal intensity
|
||||
u8 padding3[2]; // 39a-39b: (2bytes)
|
||||
u32 component_param; // 39c-39f: 4bytes Parameter for Component synchronization
|
||||
OSThreadInfo *threadinfo_mainp; // 3a0-3a3: 4bytes Verify that the pointer to ARM9 thread information is initial value 0
|
||||
OSThreadInfo *threadinfo_subp; // 3a4-3a7: 4bytes Verify that the pointer to ARM7 thread information is initial value 0
|
||||
u16 button_XY; // 3a8-3a9: 2bytes XY button information storage location
|
||||
u8 touch_panel[4]; // 3aa-3ad: 4bytes Touch Screen information storage location
|
||||
u16 autoloadSync; // 3ae-3af: 2bytes autoload sync between processors
|
||||
u32 lockIDFlag_mainp[2]; // 3b0-3b7: 8bytes lockID management flag (ARM9)
|
||||
u32 lockIDFlag_subp[2]; // 3b8-3bf: 8bytes lockID management flag (ARM7)
|
||||
struct OSLockWord lock_VRAM_C; // 3c0-3c7: 8bytes C - lock buffer
|
||||
struct OSLockWord lock_VRAM_D; // 3c8-3cf: 8bytes VRAM-D - lock buffer
|
||||
struct OSLockWord lock_WRAM_BLOCK0; // 3d0-3d7: 8bytes Block0 - lock buffer
|
||||
struct OSLockWord lock_WRAM_BLOCK1; // 3d8-3df: 8bytes CPU internal work RAM - Block1 - lock buffer
|
||||
struct OSLockWord lock_CARD; // 3e0-3e7: 8bytes Game Card - lock buffer
|
||||
struct OSLockWord lock_CARTRIDGE; // 3e8-3ef: 8bytes DS Pak - lock buffer
|
||||
struct OSLockWord lock_INIT; // 3f0-3f7: 8bytes Initialization lock buffer
|
||||
u16 mmem_checker_mainp; // 3f8-3f9: 2bytes MainMomory Size Checker for Main processor
|
||||
u16 mmem_checker_subp; // 3fa-3fb: 2bytes MainMomory Size Checker for Sub processor
|
||||
u8 padding4[2]; // 3fc-3fd: (2bytes)
|
||||
u16 command_area; // 3fe-3ff: 2bytes Command Area
|
||||
} OSSystemWork; //0x027FFC00
|
||||
|
||||
#define OS_GetSystemWork() ((OSSystemWork *)HW_MAIN_MEM_SYSTEM)
|
||||
|
||||
#endif //POKEDIAMOND_OS_SYSTEMWORK_SHARED_H
|
||||
@@ -1,3 +1,15 @@
|
||||
/*
|
||||
* NOTE:
|
||||
* This file is shared between ARM9 and ARM7
|
||||
* DO NOT PUT PROC SPECIFIC CODE IN HERE
|
||||
* Thank You!
|
||||
*/
|
||||
|
||||
/*
|
||||
* DO NOT INCLUDE THIS FILE DIRECTLY
|
||||
* Include OS_thread.h from the specific proc's lib
|
||||
*/
|
||||
|
||||
#ifndef POKEDIAMOND_OS_THREAD_SHARED_H
|
||||
#define POKEDIAMOND_OS_THREAD_SHARED_H
|
||||
|
||||
|
||||
24
include/nitro/OS_tick_shared.h
Normal file
24
include/nitro/OS_tick_shared.h
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* NOTE:
|
||||
* This file is shared between ARM9 and ARM7
|
||||
* DO NOT PUT PROC SPECIFIC CODE IN HERE
|
||||
* Thank You!
|
||||
*/
|
||||
|
||||
/*
|
||||
* DO NOT INCLUDE THIS FILE DIRECTLY
|
||||
* Include OS_tick.h from the specific proc's lib
|
||||
*/
|
||||
|
||||
#ifndef POKEDIAMOND_OS_TICK_SHARED_H
|
||||
#define POKEDIAMOND_OS_TICK_SHARED_H
|
||||
|
||||
#include "nitro/types.h"
|
||||
|
||||
typedef u64 OSTick;
|
||||
|
||||
#define OS_SYSTEM_CLOCK HW_SYSTEM_CLOCK
|
||||
|
||||
#define OS_MilliSecondsToTicks(msec) ((OSTick)(((OS_SYSTEM_CLOCK/1000) * (u64)(msec)) / 64))
|
||||
|
||||
#endif //POKEDIAMOND_OS_TICK_SHARED_H
|
||||
@@ -30,6 +30,14 @@
|
||||
#define OSi_InRange(targ, a, b) ((u32)(a) <= (u32)(targ) && (u32)(targ) < (u32)(b))
|
||||
#define OSi_OFFSET(n, a) (((u32) (n)) & ((a) - 1))
|
||||
|
||||
#define OS_THREAD_SPECIFIC_MAX 0x03
|
||||
|
||||
#define OS_THREAD_LAUNCHER_PRIORITY 0x10
|
||||
#define OS_THREAD_PRIORITY_MIN 0x00
|
||||
#define OS_THREAD_PRIORITY_MAX 0x1F
|
||||
|
||||
#define HW_SYSTEM_CLOCK 33514000
|
||||
|
||||
#define OSi_GetArenaInfo() (*(OSArenaInfo*)HW_ARENA_INFO_BUF)
|
||||
|
||||
#endif //POKEDIAMOND_CONSTS_SHARED_H
|
||||
|
||||
@@ -18,6 +18,9 @@
|
||||
#define HW_MAIN_MEM_MAIN_SIZE 0x003E0000
|
||||
#define HW_MAIN_MEM_SHARED_SIZE 0x00001000
|
||||
|
||||
#define HW_WRAM 0x037F8000
|
||||
|
||||
#define HW_MAIN_MEM_SYSTEM (HW_MAIN_MEM + 0x007ffc00)
|
||||
#define HW_WM_BOOT_BUF (HW_MAIN_MEM + 0x007ffc40)
|
||||
#define HW_ARENA_INFO_BUF (HW_MAIN_MEM + 0x007ffda0)
|
||||
#define HW_CTRDG_LOCK_BUF (HW_MAIN_MEM + 0x007fffe8)
|
||||
|
||||
Reference in New Issue
Block a user