diff options
author | red031000 <rubenru09@aol.com> | 2020-09-26 16:08:57 +0100 |
---|---|---|
committer | red031000 <rubenru09@aol.com> | 2020-09-26 16:08:57 +0100 |
commit | e1bf83033ec9bd59285b3eaa5e54bdf75ab9a7aa (patch) | |
tree | 173d7f7fee345e9095d4cd10858105c1dcc3dd9e /arm9/lib/include/CARD_common.h | |
parent | 311f383ea4ef3d7f3d0682b5d889b62cd0fe2f77 (diff) |
arm9 CARD_backup
Diffstat (limited to 'arm9/lib/include/CARD_common.h')
-rw-r--r-- | arm9/lib/include/CARD_common.h | 37 |
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); |