summaryrefslogtreecommitdiff
path: root/arm9/lib/include/CARD_common.h
diff options
context:
space:
mode:
authorCleverking2003 <30466983+Cleverking2003@users.noreply.github.com>2020-10-11 08:11:54 +0300
committerGitHub <noreply@github.com>2020-10-11 08:11:54 +0300
commit5d7b49bfda5d50c9f80bf2780a8614fe210fbc38 (patch)
tree29a8c295979d58a38cd9a97117d0dce6e1156e83 /arm9/lib/include/CARD_common.h
parent118a8d93c577fdbcef136f17d64791ebc9cd58e4 (diff)
parentbe9205a41e6df7615594bfe47d98adaddb94ab95 (diff)
Merge pull request #288 from red031000/master
arm9 CARD_backup
Diffstat (limited to 'arm9/lib/include/CARD_common.h')
-rw-r--r--arm9/lib/include/CARD_common.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/arm9/lib/include/CARD_common.h b/arm9/lib/include/CARD_common.h
index 051923ce..292b9066 100644
--- a/arm9/lib/include/CARD_common.h
+++ b/arm9/lib/include/CARD_common.h
@@ -3,6 +3,7 @@
#include "nitro/types.h"
#include "OS_thread.h"
+#include "OS_system.h"
#include "MI_dma.h"
#define CARD_THREAD_PRIORITY_DEFAULT 4
@@ -152,6 +153,42 @@ typedef struct CARDiCommon
u8 backup_cache_page_buf[256] ALIGN(32);
} CARDiCommon;
+static inline void CARDi_EndTask(CARDiCommon *p, BOOL is_own_task)
+{
+ const MIDmaCallback func = p->callback;
+ void *const arg = p->callback_arg;
+
+ {
+ OSIntrMode bak_psr = OS_DisableInterrupts();
+
+ p->flag &= ~(CARD_STAT_BUSY | CARD_STAT_TASK | CARD_STAT_CANCEL);
+ OS_WakeupThread(p->busy_q);
+ if ((p->flag & CARD_STAT_RECV) != 0)
+ {
+ OS_WakeupThreadDirect(p->thread);
+ }
+ (void)OS_RestoreInterrupts(bak_psr);
+ }
+
+ if (is_own_task && func)
+ {
+ (*func)(arg);
+ }
+}
+
+static inline void CARDi_WaitTask(CARDiCommon *p, MIDmaCallback callback, void *callback_arg)
+{
+ OSIntrMode bak_psr = OS_DisableInterrupts();
+ while ((p->flag & CARD_STAT_BUSY) != 0)
+ {
+ OS_SleepThread(p->busy_q);
+ }
+ p->flag |= CARD_STAT_BUSY;
+ p->callback = callback;
+ p->callback_arg = callback_arg;
+ (void)OS_RestoreInterrupts(bak_psr);
+}
+
void CARDi_SetTask(void (*task) (CARDiCommon *));
void CARDi_InitCommon(void);
BOOL CARD_IsEnabled(void);