Index: NVDataMgmt.c =================================================================== diff -u -rf45e0c61d9ca26a63c30cbba80cc5e835a89416a -r0170e69752974589e2f3c3507d3fb0ebd771bd89 --- NVDataMgmt.c (.../NVDataMgmt.c) (revision f45e0c61d9ca26a63c30cbba80cc5e835a89416a) +++ NVDataMgmt.c (.../NVDataMgmt.c) (revision 0170e69752974589e2f3c3507d3fb0ebd771bd89) @@ -27,8 +27,9 @@ // Private defines -#define QUEUE_MAX_SIZE 10U +#define QUEUE_MAX_SIZE 20U #define QUEUE_START_INDEX 0U +#define MIN_QUEUE_COUNT_FOR_DATA_LOG 3U // The clock frequency comes from HCLK_FREQ and it has to be rounded up to the // nearest number @@ -48,11 +49,15 @@ #define BANK7_SECTOR3_START_ADDRESS 0xF020C000 #define BANK7_SECTOR3_END_ADDRESS 0xF020FFFF -#define LOG_DATA_MAX_SIZE_BYTES 32U -#define LOG_DATA_START_INDEX 1U +#define MAX_JOB_DATA_SIZE_BYTES 32U +#define LOG_DATA_START_INDEX 0U #define MAX_NUM_OF_SECTORS_FOR_LOG_DATA 3U #define MAX_LOG_DATA_PER_SECTOR (((BANK7_SECTOR1_END_ADDRESS + 1) - \ - BANK7_SECTOR1_START_ADDRESS) / LOG_DATA_MAX_SIZE_BYTES) + BANK7_SECTOR1_START_ADDRESS) / MAX_JOB_DATA_SIZE_BYTES) +#define MAX_NUM_OF_DATA_LOGS_IN_SECTOR3 (MAX_NUM_OF_SECTORS_FOR_LOG_DATA * MAX_LOG_DATA_PER_SECTOR) +#define MAX_NUM_OF_DATA_LOGS_IN_SECTOR2 ((MAX_NUM_OF_SECTORS_FOR_LOG_DATA - 1) * MAX_LOG_DATA_PER_SECTOR) +#define MAX_NUM_OF_DATA_LOGS_IN_SECTOR1 ((MAX_NUM_OF_SECTORS_FOR_LOG_DATA - 2) * MAX_LOG_DATA_PER_SECTOR) + // RTC RAM defines #define BOOTLOADER_FLAG_START_ADDRESS 0x00000000 #define BOOTLOADER_FLAG_LENGTH_BYTES 4U @@ -99,7 +104,7 @@ NVDATAMGMT_NONE = 0, NVDATAMGMT_WRITE, NVDATAMGMT_READ, - NVDATAMGMT_ERASE, + NVDATAMGMT_ERASE_SECTOR, NUM_OF_NVDATAMGMT_OPS_STATES } NVDATAMGMT_OPERATION_STATE_T; @@ -111,14 +116,14 @@ } NVDATAMGMT_LOCATION_STATE_T; #pragma pack(push, 1) -struct MEMORY_OPS_T +typedef struct { NVDATAMGMT_OPERATION_STATE_T memoryOperation; NVDATAMGMT_LOCATION_STATE_T memoryLocation; U32* startAddress; - U08 buffer [ LOG_DATA_MAX_SIZE_BYTES ]; + U08 buffer [ MAX_JOB_DATA_SIZE_BYTES ]; U32 length; -}; +} MEMORY_OPS_T; typedef struct { @@ -127,13 +132,6 @@ U16 nextReadIndex; } LOG_RECORD_T; -typedef struct mfg_Data -{ - char SYSSerialNumber [ MAX_SYS_SERIAL_NUMBER_CHARACTERS ]; - char HWSerialNumber [ MAX_HW_SERIAL_NUMBER_CHARACTERS ]; - char mfgDate [ MAX_MFG_DATE_CHARACTERS ]; -} MFG_DATA_T; - typedef struct { MFG_DATA_T mfgData; @@ -180,11 +178,13 @@ static U32 prepareReadLogJobAndGetStartAddress (); static BOOL isQueueEmpty ( void ); static BOOL isQueueFull ( void ); +static U32 getAvailableQueueCount ( void ); // Private variables -struct MEMORY_OPS_T jobQueue [ QUEUE_MAX_SIZE ]; -static U08 readBuffer [ LOG_DATA_MAX_SIZE_BYTES ]; +static MEMORY_OPS_T jobQueue [ QUEUE_MAX_SIZE ]; +static U08 readBuffer [ MAX_JOB_DATA_SIZE_BYTES ]; +static MEMORY_OPS_T currentJob; static LOG_RECORD_T logRecord; static LOG_DATA_T logData; static MFG_RECORD_T mfgRecord; @@ -252,14 +252,53 @@ return state; } -BOOL setSerialNumber ( char* buffer ) +/************************************************************************* + * @brief setMfgData + * The setMfgData updates the struct that holds the manufacturing data, + * calls another function to calculate the CRC for the provided data and + * calls another function to erase sector 0 and write the new manufacturing + * data. + * @details + * Inputs : data + * Outputs : status (BOOL) + * @param none + * @return status (BOOL) + *************************************************************************/ +BOOL setMfgData ( MFG_DATA_T data ) { - BOOL status = TRUE; + BOOL status = FALSE; + mfgRecord.mfgData = data; + U16 calculateCRC = crc16 ( (U08*)&mfgRecord.mfgData, sizeof( MFG_DATA_T ) ); + mfgRecord.crc = calculateCRC; + //TODO Add min jobs?? + if ( !isQueueFull() ) + { + enqueue ( NVDATAMGMT_ERASE_SECTOR, NVDATAMGMT_EEPROM, BANK7_SECTOR0_START_ADDRESS, 0, 0 ); + enqueue ( NVDATAMGMT_WRITE, NVDATAMGMT_EEPROM, BANK7_SECTOR0_START_ADDRESS, + (U08*)&mfgRecord, sizeof(MFG_RECORD_T) ); + status = TRUE; + } + return status; } /************************************************************************* + * @brief getMfgData + * The getMfgData returns the data in the struct that hold manufacturing + * record to buffer that the caller has provided + * @details + * Inputs : buffer + * Outputs : none + * @param none + * @return none + *************************************************************************/ +void getMfgData ( U08* buffer ) +{ + memcpy ( buffer, (U08*)&mfgRecord, sizeof(MFG_RECORD_T) ); +} + +/************************************************************************* * @brief writeLogData * The writeLogData checks if the queue is not full and if it is not, it calls * enqueue to schedule a job for writing the log data @@ -272,12 +311,14 @@ BOOL writeLogData ( U08* data ) { BOOL status = FALSE; + U32 availableQueue = getAvailableQueueCount(); - if ( !isQueueFull() ) + if ( availableQueue >= MIN_QUEUE_COUNT_FOR_DATA_LOG ) { enqueue ( NVDATAMGMT_WRITE, NVDATAMGMT_EEPROM, 0, data, sizeof( LOG_DATA_T ) ); status = TRUE; } + return status; } @@ -294,12 +335,14 @@ BOOL readLogData ( U08* buffer ) { BOOL status = FALSE; + U32 availableQueue = getAvailableQueueCount(); - if ( !isQueueFull() ) + if ( availableQueue >= MIN_QUEUE_COUNT_FOR_DATA_LOG ) { enqueue( NVDATAMGMT_READ, NVDATAMGMT_EEPROM, 0, buffer, sizeof(buffer) ); status = TRUE; } + return status; } @@ -383,6 +426,7 @@ static NVDATAMGMT_SELF_TEST_STATE_T handleSelfTestReadMfgRecord ( void ) { NVDATAMGMT_SELF_TEST_STATE_T state = NVDATAMGMT_SELF_TEST_STATE_READ_MFG_RECORDS; + if ( isServiceOnEntry ) { EEPROMStatus = Fapi_doMarginRead ( (U32*)BANK7_SECTOR0_START_ADDRESS, (U32*)readBuffer, @@ -410,6 +454,7 @@ state = NVDATAMGMT_SELF_TEST_STATE_CHECK_CRC; isServiceOnEntry = TRUE; } + return state; } @@ -427,6 +472,7 @@ { NVDATAMGMT_SELF_TEST_STATE_T state = NVDATAMGMT_SELF_TEST_STATE_COMPLETE; U16 calculatedCRC = crc16 ( (U08*)&mfgRecord.mfgData, sizeof( MFG_DATA_T ) ); + if ( calculatedCRC == mfgRecord.crc ) { NVDataMgmtSelfTestResult = SELF_TEST_STATUS_PASSED; @@ -435,6 +481,7 @@ { NVDataMgmtSelfTestResult = SELF_TEST_STATUS_FAILED; } + return state; } @@ -578,9 +625,17 @@ logData.data5 = 68; writeLogData ( (U08*)&logData ); - readLogData ( (U08*)&tempBufferForTest ); + //readLogData ( (U08*)&tempBufferForTest ); - //setSerialNumber( (char*)tempBufferForTest ); + /*MFG_DATA_T test; + char sys[7] = {'A', 'B', 'C', 'D', '3', '6', '7'}; + char hw[5] = {'3', '4', '5', '6', '7'}; + char date[10]={'2', '0', '2', '0','-', '0', '3','-', '0', '5'}; + memcpy ( test.SYSSerialNumber, sys, 7 ); + memcpy ( test.HWSerialNumber, hw, 5 ); + memcpy ( test.mfgDate, date, 10 ); + setMfgData(test);*/ + // TODO: REMOVE THIS CODE state = NVDATAMGMT_EXEC_STATE_IDLE; } @@ -604,10 +659,13 @@ static NVDATAMGMT_EXEC_STATE_T handleExecIdleState ( void ) { NVDATAMGMT_EXEC_STATE_T state = NVDATAMGMT_EXEC_STATE_IDLE; + if ( !isQueueEmpty() ) { - NVDATAMGMT_OPERATION_STATE_T ops = jobQueue [ queueFrontIndex ].memoryOperation; - NVDATAMGMT_LOCATION_STATE_T location = jobQueue [ queueFrontIndex ].memoryLocation; + dequeue(); + NVDATAMGMT_OPERATION_STATE_T ops = currentJob.memoryOperation; + NVDATAMGMT_LOCATION_STATE_T location = currentJob.memoryLocation; + if ( ops == NVDATAMGMT_WRITE && location == NVDATAMGMT_EEPROM ) { state = NVDATAMGMT_EXEC_STATE_WRITE_TO_EEPROM; @@ -616,7 +674,7 @@ { state = NVDATAMGMT_EXEC_STATE_READ_FROM_EEPROM; } - else if ( ops == NVDATAMGMT_ERASE ) + else if ( ops == NVDATAMGMT_ERASE_SECTOR ) { state = NVDATAMGMT_EXEC_STATE_ERASE_EEPROM; } @@ -629,6 +687,7 @@ state = NVDATAMGMT_EXEC_STATE_READ_FROM_RTC; } } + return state; } @@ -647,16 +706,15 @@ NVDATAMGMT_EXEC_STATE_T state = NVDATAMGMT_EXEC_STATE_WRITE_TO_EEPROM; if ( isServiceOnEntry ) { - EEPROMStatus = Fapi_issueProgrammingCommand ( jobQueue [ queueFrontIndex ].startAddress, - jobQueue [ queueFrontIndex ].buffer, - jobQueue [ queueFrontIndex ].length, + EEPROMStatus = Fapi_issueProgrammingCommand ( currentJob.startAddress, + currentJob.buffer, + currentJob.length, 0x00, 0, Fapi_DataOnly ); isServiceOnEntry = FALSE; } else if ( FAPI_CHECK_FSM_READY_BUSY == Fapi_Status_FsmReady ) { state = NVDATAMGMT_EXEC_STATE_IDLE; - dequeue(); isServiceOnEntry = TRUE; } return state; @@ -675,19 +733,20 @@ static NVDATAMGMT_EXEC_STATE_T handleExecReadFromEEPROMState ( void ) { NVDATAMGMT_EXEC_STATE_T state = NVDATAMGMT_EXEC_STATE_READ_FROM_EEPROM; + if ( isServiceOnEntry ) { - EEPROMStatus = Fapi_doMarginRead ( jobQueue [ queueFrontIndex ].startAddress, - (U32*)jobQueue [ queueFrontIndex ].buffer, - jobQueue [ queueFrontIndex ].length, Fapi_NormalRead ); + EEPROMStatus = Fapi_doMarginRead ( currentJob.startAddress, + (U32*)currentJob.buffer, + currentJob.length, Fapi_NormalRead ); isServiceOnEntry = FALSE; } else if ( FAPI_CHECK_FSM_READY_BUSY == Fapi_Status_FsmReady ) { state = NVDATAMGMT_EXEC_STATE_IDLE; - dequeue(); isServiceOnEntry = TRUE; } + return state; } @@ -704,17 +763,19 @@ static NVDATAMGMT_EXEC_STATE_T handleExecEraseState ( void ) { NVDATAMGMT_EXEC_STATE_T state = NVDATAMGMT_EXEC_STATE_ERASE_EEPROM; + if ( isServiceOnEntry ) { - EEPROMStatus = Fapi_issueAsyncCommandWithAddress ( Fapi_EraseSector, jobQueue [ queueFrontIndex ].startAddress ); + EEPROMStatus = Fapi_issueAsyncCommandWithAddress ( Fapi_EraseSector, + currentJob.startAddress ); isServiceOnEntry = FALSE; } else if ( FAPI_CHECK_FSM_READY_BUSY == Fapi_Status_FsmReady ) { state = NVDATAMGMT_EXEC_STATE_IDLE; - dequeue(); isServiceOnEntry = TRUE; } + return state; } @@ -732,19 +793,20 @@ static NVDATAMGMT_EXEC_STATE_T handleExecWriteToRAMState ( void ) { NVDATAMGMT_EXEC_STATE_T state = NVDATAMGMT_EXEC_STATE_WRITE_TO_RTC; + if ( isServiceOnEntry && getRTCRAMState() == RTC_RAM_STATE_READY ) { - writeToRAM ( (U32)( jobQueue [ queueFrontIndex ].startAddress ), - jobQueue [ queueFrontIndex ].buffer, - jobQueue [ queueFrontIndex ].length ); + writeToRAM ( (U32)( currentJob.startAddress ), + currentJob.buffer, + currentJob.length ); isServiceOnEntry= FALSE; } if ( getRTCRAMStatus() == RTC_RAM_STATUS_IDLE ) { state = NVDATAMGMT_EXEC_STATE_IDLE; - dequeue(); isServiceOnEntry = TRUE; } + return state; } @@ -765,16 +827,15 @@ NVDATAMGMT_EXEC_STATE_T state = NVDATAMGMT_EXEC_STATE_READ_FROM_RTC; if ( isServiceOnEntry && getRTCRAMState() == RTC_RAM_STATE_READY ) { - readFromRAM( (U32)( jobQueue [ queueFrontIndex ].startAddress ), - jobQueue [ queueFrontIndex ].length ); + readFromRAM( (U32)( currentJob.startAddress ), + currentJob.length ); isServiceOnEntry= FALSE; } if ( getRTCRAMStatus() == RTC_RAM_STATUS_IDLE ) { - getDataFromRAM( jobQueue [ queueFrontIndex ].buffer, - jobQueue [ queueFrontIndex ].length ); + getDataFromRAM( currentJob.buffer, + currentJob.length ); state = NVDATAMGMT_EXEC_STATE_IDLE; - dequeue(); isServiceOnEntry = TRUE; } return state; @@ -792,99 +853,175 @@ static void setMemoryOpsStruct ( NVDATAMGMT_OPERATION_STATE_T ops, NVDATAMGMT_LOCATION_STATE_T location, U32 startAddress, U08* data, U32 length ) { - jobQueue [ queueRearIndex ].memoryOperation = ops; - jobQueue [ queueRearIndex ].memoryLocation = location; - jobQueue [ queueRearIndex ].startAddress = (U32*)startAddress; - jobQueue [ queueRearIndex ].length = length; - memcpy ( jobQueue [ queueRearIndex ].buffer, data, length ); - queueRearIndex++; - // check the wrap + U32 myAddIndex; + + _disable_IRQ(); + myAddIndex = queueRearIndex; + if ( FALSE == isQueueFull() ) + { + queueCount++; + INC_WRAP( queueRearIndex, 0, QUEUE_MAX_SIZE - 1 ); + } + _enable_IRQ(); + + jobQueue [ myAddIndex ].memoryOperation = ops; + jobQueue [ myAddIndex ].memoryLocation = location; + jobQueue [ myAddIndex ].startAddress = (U32*)startAddress; + jobQueue [ myAddIndex ].length = length; + memcpy ( jobQueue [ myAddIndex ].buffer, data, length ); + +// if ( !isQueueFull() ) +// { +// queueRearIndex++; +// } +// else +// { +// queueRearIndex = QUEUE_START_INDEX; +// } +// queueCount++; } +/************************************************************************* + * @brief prepareWriteLogJobAndGetStartAddress + * The prepareWriteLogJobAndGetStartAddress checks whether the next write + * is at edge of the any of the sectors and if yes, it will update the log + * header accordingly. If the write is not at the edge, it will prepare a + * normal write to EEPROM job. + * @details + * Inputs : data + * Outputs : opsStartAddress + * @param none + * @return opsStartAddress + *************************************************************************/ static U32 prepareWriteLogJobAndGetStartAddress ( U08* data ) { - U32 modulus = 0; - U32 opsStartAddress = 0; - U16 readIndex = 0; + U32 modulus = 0; + U32 opsStartAddress = 0; + U16 readIndexChange = 0; + U16 writeIndexChange = 1; + U16 recordCountChange = 1; + // The write address is calculated using the next write index and is and offset from // the start of sector 1. Sectors 1,2, and 3 have been allocated for logging data - opsStartAddress = ( logRecord.nextWriteIndex * LOG_DATA_MAX_SIZE_BYTES ) + BANK7_SECTOR1_START_ADDRESS; + opsStartAddress = ( logRecord.nextWriteIndex * MAX_JOB_DATA_SIZE_BYTES ) + BANK7_SECTOR1_START_ADDRESS; modulus = logRecord.nextWriteIndex % MAX_LOG_DATA_PER_SECTOR; + + // Modulus is 0 so it is at any of the edges if ( modulus == 0 ) { - readIndex = logRecord.nextReadIndex; - // define - if ( logRecord.nextWriteIndex == MAX_LOG_DATA_PER_SECTOR * MAX_NUM_OF_SECTORS_FOR_LOG_DATA ) + // If full + // 1. set readIndexChange = +512 + // 2. set recordCountchange = -512 + readIndexChange = MAX_LOG_DATA_PER_SECTOR; + logRecord.recordCount = logRecord.recordCount - MAX_LOG_DATA_PER_SECTOR; + + // Start of sector 1 + /*if ( writeIndex == 0 ) { opsStartAddress = BANK7_SECTOR1_START_ADDRESS; - // It is at the end of sector 3, it needs to start over - logRecord.nextWriteIndex = LOG_DATA_START_INDEX; - // Sector 1 is being erased and the maximum number of logs that can be - // stored in it is erased (in this case 512) - logRecord.recordCount = logRecord.recordCount - MAX_LOG_DATA_PER_SECTOR; - // If the read index is somewhere in sector 1, then it will be set to 0 - if ( readIndex > ( MAX_NUM_OF_SECTORS_FOR_LOG_DATA - 1 ) * MAX_LOG_DATA_PER_SECTOR && - readIndex < MAX_LOG_DATA_PER_SECTOR * MAX_NUM_OF_SECTORS_FOR_LOG_DATA ) + writeIndexChange++; + recordCountChange++; + // Sector 1 will be erased so if the read index is somewhere is + // sector 1(0 MAX_NUM_OF_DATA_LOGS_IN_SECTOR1 && + readIndex <= MAX_NUM_OF_DATA_LOGS_IN_SECTOR2 ) { - opsStartAddress = BANK7_SECTOR2_START_ADDRESS; - if ( readIndex > 0 && readIndex < MAX_LOG_DATA_PER_SECTOR ) - { - logRecord.nextReadIndex = MAX_LOG_DATA_PER_SECTOR + 1; - } + readIndexChange = MAX_NUM_OF_DATA_LOGS_IN_SECTOR2 + 1; } - else if ( logRecord.nextWriteIndex == ( MAX_NUM_OF_SECTORS_FOR_LOG_DATA - 1 ) * MAX_LOG_DATA_PER_SECTOR ) + } + // End of sector 2 + else if ( writeIndex == MAX_NUM_OF_DATA_LOGS_IN_SECTOR2 ) + { + // Moving to sector 3 + opsStartAddress = BANK7_SECTOR3_START_ADDRESS; + // Record will be 1024 as the maximum number of logs + // in sector 2. All the logs in sector 3 will be erased + recordCountChange = MAX_NUM_OF_DATA_LOGS_IN_SECTOR2; + writeIndex++; + // If the readIndex is (1024 MAX_NUM_OF_DATA_LOGS_IN_SECTOR2 && + readIndex <= MAX_NUM_OF_DATA_LOGS_IN_SECTOR3 ) { - opsStartAddress = BANK7_SECTOR3_START_ADDRESS; - if ( readIndex > ( MAX_NUM_OF_SECTORS_FOR_LOG_DATA - 1 ) * MAX_LOG_DATA_PER_SECTOR && - readIndex < MAX_LOG_DATA_PER_SECTOR ) - { - logRecord.nextReadIndex = 0; - } + readIndexChange = 0; } - if ( logRecord.recordCount > MAX_NUM_OF_SECTORS_FOR_LOG_DATA ) + } + // End of sector 3 + else if ( writeIndex == MAX_NUM_OF_DATA_LOGS_IN_SECTOR3 ) + { + // Moving to sector 1 + opsStartAddress = BANK7_SECTOR1_START_ADDRESS; + // Changing the record count to 2 full sectors (1024) + recordCountChange = MAX_NUM_OF_DATA_LOGS_IN_SECTOR2; + // writeIndex will be put at the beginning of sector 1 + writeIndex = 0; + // If the readIndex is somewhere is sector 1 (0= MAX_NUM_OF_DATA_LOGS_IN_SECTOR3 - 1 ) { + logRecord.nextReadIndex = LOG_DATA_START_INDEX; } else { logRecord.nextReadIndex++; - } + }*/ // Update the log record setMemoryOpsStruct ( NVDATAMGMT_WRITE, NVDATAMGMT_RTC, LOG_RECORD_START_ADDRESS, (U08*)&logRecord, sizeof( LOG_RECORD_T ) ); @@ -901,7 +1038,7 @@ * it schedules the write jobs. The function breaks the write to EEPROM jobs to * 16 bytes at the time * @details - * Inputs : none + * Inputs : ops, location, startAddress, data, length * Outputs : none * @param none * @return none @@ -911,32 +1048,32 @@ { U32 quotient = 0; U32 modulus = 0; - U32 maxBufferLength = 0; + U32 maxBufferLength = length; U32 opsStartAddress = startAddress; U08 i; - // Remove - if ( !isQueueFull() ) - { - queueRearIndex = QUEUE_START_INDEX; - } + // Setup EEPROM write log event - if ( ops == NVDATAMGMT_WRITE && location == NVDATAMGMT_EEPROM && startAddress == 0 ) + if ( ops == NVDATAMGMT_WRITE && location == NVDATAMGMT_EEPROM ) { maxBufferLength = MAX_EEPROM_WRITE_BUFFER_BYTES; - opsStartAddress = prepareWriteLogJobAndGetStartAddress ( data ); + if ( startAddress == 0 ) + { + opsStartAddress = prepareWriteLogJobAndGetStartAddress ( data ); + } } // Setup EEPROM read log event - else if ( ops == NVDATAMGMT_READ && location == NVDATAMGMT_EEPROM && startAddress == 0 ) + else if ( ops == NVDATAMGMT_READ && location == NVDATAMGMT_EEPROM ) { - maxBufferLength = LOG_DATA_MAX_SIZE_BYTES; - opsStartAddress = prepareReadLogJobAndGetStartAddress(); + maxBufferLength = MAX_JOB_DATA_SIZE_BYTES; + if ( startAddress == 0 ) + { + opsStartAddress = prepareReadLogJobAndGetStartAddress(); + } } - else if ( ops == NVDATAMGMT_WRITE && location == NVDATAMGMT_EEPROM && startAddress == BANK7_SECTOR0_START_ADDRESS ) - { - // schedule this at the function for mfg data in sector 0 - setMemoryOpsStruct ( NVDATAMGMT_ERASE, NVDATAMGMT_EEPROM, opsStartAddress, 0, 0 ); - } - // Comments + // Maximum length for write is 16 bytes + // Maximum length for read is 32 bytes + // If the length is greater than the specified max lengths, + // the operation will be broken into multiple pieces if ( length > maxBufferLength ) { quotient = length / maxBufferLength; @@ -952,6 +1089,7 @@ data + ( quotient * maxBufferLength ), modulus ); } } + // The length is less than maximum specified, normal operations else { setMemoryOpsStruct ( ops, location, opsStartAddress, data, length ); @@ -970,6 +1108,8 @@ *************************************************************************/ static void dequeue ( void ) { + currentJob = jobQueue [ queueFrontIndex ]; + if ( queueFrontIndex >= QUEUE_MAX_SIZE - 1 ) { queueFrontIndex = QUEUE_START_INDEX; @@ -990,15 +1130,15 @@ * it will return a false * @details * Inputs : none - * Outputs : BOOL + * Outputs : isEmpty (BOOL) * @param none - * @return BOOL + * @return isEmpty (BOOL) *************************************************************************/ static BOOL isQueueEmpty ( void ) { BOOL isEmpty = TRUE; - if ( queueCount == 0 ) + if ( queueCount > 0 ) { isEmpty = FALSE; } @@ -1012,9 +1152,9 @@ * it will return a true * @details * Inputs : none - * Outputs : BOOL + * Outputs : isFull (BOOL) * @param none - * @return BOOL + * @return isFull (BOOL) *************************************************************************/ static BOOL isQueueFull ( void ) { @@ -1028,5 +1168,17 @@ return isFull; } +/************************************************************************* + * @brief getAvailableQueueCount + * The getAvailableQueueCount returns the number of available queues left + * @details + * Inputs : none + * Outputs : U32 + * @param none + * @return BOOL + *************************************************************************/ +static U32 getAvailableQueueCount ( void ) +{ + return QUEUE_MAX_SIZE - queueCount - 1; +} -