blob: 2d728d148693337d8b35e620a2e79ef1db23a36b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
#include "function_target.h"
#include "CARD_request.h"
#include "OS_cache.h"
#include "OS_system.h"
#include "OS_thread.h"
extern CARDiCommon cardi_common;
extern u32 PXI_IsCallbackReady(u32 param1, u32 param2);
ARM_FUNC void CARDi_OnFifoRecv(PXIFifoTag tag, u32 data, BOOL err)
{
#pragma unused (data)
if ((tag == PXI_FIFO_TAG_FS) && err)
{
CARDiCommon *const p = &cardi_common;
p->flag &= ~CARD_STAT_REQ;
OS_WakeupThreadDirect(p->cur_th);
}
}
ARM_FUNC void CARDi_TaskThread(void *arg)
{
#pragma unused (arg)
CARDiCommon *const p = &cardi_common;
while (TRUE)
{
OSIntrMode bak_psr = OS_DisableInterrupts();
while ((p->flag & CARD_STAT_TASK) == 0)
{
p->cur_th = p->thread;
OS_SleepThread(NULL);
}
(void)OS_RestoreInterrupts(bak_psr);
(*p->task_func)(p);
}
}
ARM_FUNC BOOL CARDi_Request(CARDiCommon *p, s32 req_type, s32 retry_count)
{
if ((p->flag & CARD_STAT_INIT_CMD) == 0)
{
p->flag |= CARD_STAT_INIT_CMD;
while (!PXI_IsCallbackReady(PXI_FIFO_TAG_FS, PXI_PROC_ARM7))
{
OS_SpinWait(100);
}
(void)CARDi_Request(p, CARD_REQ_INIT, 1);
}
DC_FlushRange(p->cmd, sizeof(*p->cmd));
DC_WaitWriteBufferEmpty();
do
{
p->command = req_type;
p->flag |= CARD_STAT_REQ;
CARDi_SendPxi((u32)req_type);
switch (req_type)
{
case CARD_REQ_INIT:
CARDi_SendPxi((u32)p->cmd);
break;
}
OSIntrMode bak_psr = OS_DisableInterrupts();
while ((p->flag & CARD_STAT_REQ) != 0)
{
OS_SleepThread(NULL);
}
(void)OS_RestoreInterrupts(bak_psr);
DC_InvalidateRange(p->cmd, sizeof(*p->cmd));
}
while ((p->cmd->result == CARD_RESULT_TIMEOUT) && (--retry_count > 0));
return (p->cmd->result == CARD_RESULT_SUCCESS);
}
|