Index: NVDataMgmt.c =================================================================== diff -u -rfd1a4ea5198033bcbd17986c3079967afb1f220f -ra26f096ba8f55604062fa36bfacc3f3e7f4acecd --- NVDataMgmt.c (.../NVDataMgmt.c) (revision fd1a4ea5198033bcbd17986c3079967afb1f220f) +++ NVDataMgmt.c (.../NVDataMgmt.c) (revision a26f096ba8f55604062fa36bfacc3f3e7f4acecd) @@ -535,6 +535,7 @@ // Record operations queue functions static void enqueueRecordJob( NVDATAMGMT_OPERATION_STATE_T ops, NVDATAMGMT_LOCATION_STATE_T location, RECORD_JOBS_STATE_T job ); static void dequeueRecordJob( void ); +static BOOL areResourcesAvailableForNextJob( void ); static BOOL isRecordQueueEmpty( void ); static U32 getAvailableRecordQueueCount( void ); static BOOL enqueueSector0Records( void ); @@ -1632,16 +1633,14 @@ U08* bufferAddress; U32 maxBufferLength; - // TODO queue peek - // If power off command has been issued, do not process any new jobs if ( powerOffIsImminent != TRUE ) { // Check if the service record has to be updated //updateServiceRecord(); // TODO what is this doing here? // If the record processing queue is not empty, process the queues - if ( FALSE == isRecordQueueEmpty() ) + if ( ( FALSE == isRecordQueueEmpty() ) && ( TRUE == areResourcesAvailableForNextJob() ) ) { dequeueRecordJob(); @@ -1658,11 +1657,11 @@ activeQueue = NVDATAMGMT_PROCESS_RECORDS; // Choose the right buffer size - if ( ( NVDATAMGMT_WRITE == ops ) ) + if ( NVDATAMGMT_WRITE == ops ) { maxBufferLength = jobSpecs.maxWriteBufferSize; } - else if ( ops == NVDATAMGMT_READ ) + else if ( NVDATAMGMT_READ == ops ) { maxBufferLength = jobSpecs.maxReadBufferSize; @@ -1681,15 +1680,17 @@ if ( NVDATAMGMT_ERASE_SECTOR == ops ) { Fapi_issueAsyncCommandWithAddress( Fapi_EraseSector, (U32*)startAddress ); + state = NVDATAMGMT_EXEC_STATE_ERASE_EEPROM; } else if ( ( NVDATAMGMT_WRITE == ops ) && ( NVDATAMGMT_EEPROM == location ) ) { Fapi_issueProgrammingCommand( (U32*)startAddress, (U08*)bufferAddress, maxBufferLength, 0x00, 0, Fapi_DataOnly ); + currentTime = getMSTimerCount(); - state = NVDATAMGMT_EXEC_STATE_WRITE_TO_EEPROM; + state = NVDATAMGMT_EXEC_STATE_WRITE_TO_EEPROM; } - else if ( ops == NVDATAMGMT_READ && location == NVDATAMGMT_EEPROM ) + else if ( ( NVDATAMGMT_READ == ops ) && ( NVDATAMGMT_EEPROM == location ) ) { if ( FAPI_CHECK_FSM_READY_BUSY == Fapi_Status_FsmReady ) { @@ -1699,23 +1700,25 @@ state = NVDATAMGMT_EXEC_STATE_READ_FROM_EEPROM; } } - else if ( ops == NVDATAMGMT_WRITE && location == NVDATAMGMT_RTC ) + else if ( ( NVDATAMGMT_WRITE == ops ) && ( NVDATAMGMT_RTC == location ) ) { - if ( ( RTC_RAM_STATE_READY == getRTCRAMState() ) && ( TRUE == getSemaphore( SEMAPHORE_RTC ) ) ) + //if ( ( RTC_RAM_STATE_READY == getRTCRAMState() ) && ( TRUE == getSemaphore( SEMAPHORE_RTC ) ) ) { - currentTime = getMSTimerCount(); writeToRAM( startAddress, bufferAddress, maxBufferLength ); - state = NVDATAMGMT_EXEC_STATE_WRITE_TO_RTC; + + currentTime = getMSTimerCount(); + state = NVDATAMGMT_EXEC_STATE_WRITE_TO_RTC; } } - else if ( ops == NVDATAMGMT_READ && location == NVDATAMGMT_RTC ) + else if ( ( NVDATAMGMT_READ == ops ) && ( NVDATAMGMT_RTC == location) ) { - if ( ( RTC_RAM_STATE_READY == getRTCRAMState() ) && ( TRUE == getSemaphore( SEMAPHORE_RTC ) ) ) + //if ( ( RTC_RAM_STATE_READY == getRTCRAMState() ) && ( TRUE == getSemaphore( SEMAPHORE_RTC ) ) ) { - currentTime = getMSTimerCount(); readFromRAM( startAddress, maxBufferLength ); //currentJob.externalAddress->status = NVDATAMGMT_READ_IN_PROGRESS; // TODO Phase 1B for logging - state = NVDATAMGMT_EXEC_STATE_READ_FROM_RTC; + + currentTime = getMSTimerCount(); + state = NVDATAMGMT_EXEC_STATE_READ_FROM_RTC; } } } @@ -3684,10 +3687,9 @@ { PROCESS_RECORD_JOB_T currentJob; - currentJob.memoryLocation = location; - currentJob.memoryOperation = ops; - currentJob.recordJob = job; - + currentJob.memoryLocation = location; + currentJob.memoryOperation = ops; + currentJob.recordJob = job; recordJobQueue[ recordQueueRearIndex ] = currentJob; recordQueueCount++; @@ -3710,7 +3712,7 @@ _disable_IRQ(); tempIndex = recordQueueFrontIndex; - if ( !isRecordQueueEmpty() ) + if ( FALSE == isRecordQueueEmpty() ) { recordQueueFrontIndex = INC_WRAP( recordQueueFrontIndex, 0, QUEUE_MAX_SIZE - 1 ); recordCurrentJob = recordJobQueue[ tempIndex ]; @@ -3724,6 +3726,47 @@ /*********************************************************************//** * @brief + * The areResourcesAvailableForNextJob checks whether the resources such as + * semaphore for RTC is available prior to dequeuing the job to be processed. + * @details Inputs: recordQueueFrontIndex + * @details Outputs: none + * @return TRUE if the resources are available otherwise, FALSE + *************************************************************************/ +static BOOL areResourcesAvailableForNextJob( void ) +{ + BOOL status = FALSE; + U32 tempIndex; + PROCESS_RECORD_JOB_T tempJob; + + _disable_IRQ(); + tempIndex = recordQueueFrontIndex; + + if ( FALSE == isRecordQueueEmpty() ) + { + tempJob = recordJobQueue[ tempIndex ]; + } + _enable_IRQ(); + + if ( NVDATAMGMT_RTC == tempJob.memoryLocation ) + { + if ( ( RTC_RAM_STATE_READY == getRTCRAMState() ) && ( TRUE == getSemaphore( SEMAPHORE_RTC ) ) ) + { + status = TRUE; + } + } + else if ( NVDATAMGMT_EEPROM == tempJob.memoryLocation ) + { + if ( Fapi_Status_FsmReady == FAPI_CHECK_FSM_READY_BUSY ) + { + status = TRUE; + } + } + + return status; +} + +/*********************************************************************//** + * @brief * The isRecordQueueEmpty checks whether the queue is empty and if it is * empty, it will return a false. * @details Inputs: recordQueueCount