diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/nitro/OS_interrupt_shared.h | 9 | ||||
-rw-r--r-- | include/nitro/OS_thread_shared.h | 116 | ||||
-rw-r--r-- | include/nitro/consts_shared.h | 1 | ||||
-rw-r--r-- | include/nitro/registers_shared.h | 17 |
4 files changed, 143 insertions, 0 deletions
diff --git a/include/nitro/OS_interrupt_shared.h b/include/nitro/OS_interrupt_shared.h index 97bed8b1..9b5974e5 100644 --- a/include/nitro/OS_interrupt_shared.h +++ b/include/nitro/OS_interrupt_shared.h @@ -17,4 +17,13 @@ typedef u32 OSIrqMask; +typedef void (*OSIrqFunction) (void); + +typedef struct +{ + void (*func) (void *); + u32 enable; + void* arg; +} OSIrqCallbackInfo; + #endif //POKEDIAMOND_OS_INTERRUPT_SHARED_H diff --git a/include/nitro/OS_thread_shared.h b/include/nitro/OS_thread_shared.h new file mode 100644 index 00000000..28d8a503 --- /dev/null +++ b/include/nitro/OS_thread_shared.h @@ -0,0 +1,116 @@ +#ifndef POKEDIAMOND_OS_THREAD_SHARED_H +#define POKEDIAMOND_OS_THREAD_SHARED_H + +#include "nitro/types.h" + +typedef struct OSiAlarm OSAlarm; + +typedef struct _OSThread OSThread; + +typedef struct _OSThreadQueue OSThreadQueue; +typedef struct _OSThreadLink OSThreadLink; +typedef struct _OSMutexQueue OSMutexQueue; +typedef struct _OSMutexLink OSMutexLink; +typedef struct OSMutex OSMutex; + +struct _OSThreadQueue +{ + OSThread *head; + OSThread *tail; +}; + +struct _OSThreadLink +{ + OSThread *prev; + OSThread *next; +}; + +struct _OSMutexQueue +{ + OSMutex *head; + OSMutex *tail; +}; + +struct _OSMutexLink +{ + OSMutex *next; + OSMutex *prev; +}; + +typedef struct OSThreadInfo { + u16 isNeedRescheduling; + u16 irqDepth; + OSThread* current; + OSThread* list; + void* switchCallback; // type: OSSwitchThreadCallback +} OSThreadInfo; + +typedef enum { + OS_THREAD_STATE_WAITING = 0, + OS_THREAD_STATE_READY = 1, + OS_THREAD_STATE_TERMINATED = 2 +} OSThreadState; + +typedef void (*OSSwitchThreadCallback) (OSThread *from, OSThread *to); + +typedef void (*OSThreadDestructor) (void *); + +struct _OSThread +{ + OSContext context; + OSThreadState state; + OSThread *next; + u32 id; + u32 priority; + void *profiler; + + OSThreadQueue *queue; + OSThreadLink link; + + OSMutex *mutex; + OSMutexQueue mutexQueue; + + u32 stackTop; + u32 stackBottom; + u32 stackWarningOffset; + + OSThreadQueue joinQueue; + + void *specific[3]; + OSAlarm *alarmForSleep; + OSThreadDestructor destructor; + void *userParameter; + + u32 systemErrno; +}; + +extern OSThreadInfo OSi_ThreadInfo; + +static inline OSThreadInfo *OS_GetThreadInfo(void) +{ + return &OSi_ThreadInfo; +} + +static inline BOOL OS_IsThreadRunnable(const OSThread *thread) +{ + return thread->state == OS_THREAD_STATE_READY; +} + +static inline void OS_InitThreadQueue(OSThreadQueue * queue) +{ + queue->head = queue->tail = NULL; +} + +static inline OSThread *OS_GetCurrentThread(void) +{ + return OS_GetThreadInfo()->current; +} + +static inline void OS_SetCurrentThread(OSThread *thread) +{ + OS_GetThreadInfo()->current = thread; +} + +#define OSi_GetCurrentThread() (*OSi_CurrentThreadPtr) + +#endif //POKEDIAMOND_OS_THREAD_SHARED_H diff --git a/include/nitro/consts_shared.h b/include/nitro/consts_shared.h index 151212d1..b6342172 100644 --- a/include/nitro/consts_shared.h +++ b/include/nitro/consts_shared.h @@ -15,6 +15,7 @@ #include "nitro/types.h" #include "nitro/mmap_shared.h" +#include "nitro/registers_shared.h" //Shared Consts diff --git a/include/nitro/registers_shared.h b/include/nitro/registers_shared.h new file mode 100644 index 00000000..60152ab0 --- /dev/null +++ b/include/nitro/registers_shared.h @@ -0,0 +1,17 @@ +/* + * NOTE: + * This file is shared between ARM9 and ARM7 + * DO NOT PUT PROC SPECIFIC CODE IN HERE + * Thank You! + */ + +#ifndef POKEDIAMOND_REGISTERS_SHARED_H +#define POKEDIAMOND_REGISTERS_SHARED_H + +#include "nitro/types.h" + +#define reg_OS_IME (*(REGType16v *)0x4000208) +#define reg_OS_IE (*(REGType32v *)0x4000210) +#define reg_OS_IF (*(REGType32v *)0x4000214) + +#endif //POKEDIAMOND_REGISTERS_SHARED_H |