cardmgr.c 1.73 KB
#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;
    }
}