cardmgr.c
1.73 KB
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
#include "osint.h"
#include "rcp.h"
#include "os_bb.h"
#include "bbint.h"
#define NUM_EV_MESG 5 /* Number of message entries in event queue */
static OSMesgQueue cardEventQueue; /* Event queue structure */
static OSMesg cardEventBuf[NUM_EV_MESG];
static OSIoMesg cardFlashMsg, cardMdMsg;
void
__osBbCardInitEvent(void) {
/* Create the input event queue */
osCreateMesgQueue(&cardEventQueue, cardEventBuf, NUM_EV_MESG);
cardFlashMsg.hdr.type = OS_MESG_TYPE_FLASH;
cardFlashMsg.hdr.pri = OS_MESG_PRI_NORMAL;
cardFlashMsg.hdr.retQueue = NULL;
cardMdMsg.hdr.type = OS_MESG_TYPE_MD;
cardMdMsg.hdr.pri = OS_MESG_PRI_NORMAL;
cardMdMsg.hdr.retQueue = NULL;
/* Take over FLASH interrupt */
osSetEventMesg(OS_EVENT_FLASH, &cardEventQueue, (OSMesg)&cardFlashMsg);
/* Take over MD interrupt */
osSetEventMesg(OS_EVENT_MD, &cardEventQueue, (OSMesg)&cardMdMsg);
}
s32
__osBbCardFlushEvent(void) {
s32 rv = 0;
OSIoMesg* mb;
while (osRecvMesg(&cardEventQueue, (OSMesg *)&mb, OS_MESG_NOBLOCK) != -1){
#ifdef _DEBUG
osSyncPrintf("flush cardEventQueue: %d\n",mb->hdr.type);
#endif
rv = 1;
}
return rv;
}
s32
__osBbCardWaitEvent(void) {
OSIoMesg* mb;
/* wait for correspoding interrupt */
(void)osRecvMesg(&cardEventQueue, (OSMesg *)&mb, OS_MESG_BLOCK);
switch (mb->hdr.type) {
case OS_MESG_TYPE_FLASH:
/* flash operation completion */
//osSyncPrintf("flash completion, send to %x\n", mb0->hdr.retQueue);
return 0;
case OS_MESG_TYPE_MD:
/* decode insertion/removal */
#ifdef _DEBUG
osSyncPrintf("md interrupt\n");
#endif
__osBbCardChange = 1;
return BBCARD_ERR_CHANGED;
default:
return BBCARD_ERR_FAIL;
}
}