Accessing SD Card via usb (MSC) under FreeRTOS+FAT

Hi, I am currently using freeRTOS and freeRTOS+FAT on a Hitex eval board (LPC4350). I was trying to develop an application that exposes an SD Card via usb as a mass storage class. I am using lpcopen library and the MSC interface requires read and write functions. My current implementation uses the read and write function of the IOManager as follow: ~~~ usbtranslaterd(…) { /* Process the parameters */
FF_BlockRead(xSDCard->pxIOManager,...);
} ~~~ With usbtranslaterd being the read callback function for the usb msc interface. Now as part of the read process the application goes into the following function defined in ff_sddisk.c:: ~~~ /* Sets up the SD event driven wakeup */ static void prvSDMMCSetupWakeup( void *pvInfo ) { uint32_t *ulWaitStatus = ( uint32_t * ) pvInfo;
/* Wait for IRQ - for an RTOS, you would pend on an event here with a IRQ
based wakeup. */
/*_RB_ Don't understand why this is spinning on a block time of 0.  Is it
really meant to be != pdFALSE? */
while( xSemaphoreTake( xSDCardSemaphore, 0 ) != pdFALSE )
{
}

NVIC_ClearPendingIRQ( SDIO_IRQn );
lSDIOWaitExit = 0;
Chip_SDIF_SetIntMask( LPC_SDMMC, *ulWaitStatus );
NVIC_EnableIRQ( SDIO_IRQn );
} ~~~ The xSemaphoreTake macro fails an assertion in when in goes into taskENTER_CRITICAL() in xQueueGenericReceive. ~~~ void vPortEnterCritical( void ) { portDISABLE_INTERRUPTS(); uxCriticalNesting++;
/* This is not the interrupt safe version of the enter critical function so
assert() if it is being called from an interrupt context.  Only API
functions that end in "FromISR" can be used in an interrupt.  Only assert if
the critical nesting count is 1 to protect against recursive calls if the
assert function also uses a critical section. */
if( uxCriticalNesting == 1 )
{
    configASSERT( ( portNVIC_INT_CTRL_REG & portVECTACTIVE_MASK ) == 0 );
}
} ~~~ configASSERT( ( portNVICINTCTRLREG & portVECTACTIVEMASK ) == 0 ); -> Fails My first assumption is that I would need to handle the usb read/write callbacks as interrupts and therefore I would need to either defer the read to say a task (sending it the data via a queue for example) or have a FF_BlockReadfromISR.
  1. Is my assumption correct?
  2. I was wondering if there was a “preferred” way of implementing this from a freeRTOS point of view.
Cheers, Sof