SCMGR.C
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:25k
- /****************************************************************************************
- * Copyright (c) 2002 ZORAN Corporation, All Rights Reserved
- * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF ZORAN CORPORATION
- *
- * File: $Workfile: SCMGR.C $
- *
- * Description:
- * ============
- *
- *
- * Log:
- * ====
- * $Revision: 7 $
- * Last Modified by $Author: Leonh $ at $Modtime: 11/19/03 12:58p $
- ****************************************************************************************
- * Updates:
- ****************************************************************************************
- * $Log: /I76/I76_Common/I76_Reference/Playcore/ScPad/SCMGR.C $
- *
- * 7 11/20/03 1:54p Leonh
- * remove the useless code
- *
- * 6 11/15/03 7:11p Leslie
- * Replace old Video API Low Level Files with new ones
- *
- * 5 11/06/03 15:17 Eyalr
- *
- * 4 10/23/03 11:41a Leslie
- * add the function for read RAW data from SDRAM
- *
- * 3 03-07-09 10:23 Leonh
- * cache enable
- *
- * 9 23/05/02 14:09 Ettim
- * Adding support for an absolute 32 bit address on the scratch pad.
- *
- * 8 23/04/02 9:36 Nirm
- * - Added dependency in "Config.h".
- *
- * 7 4/03/02 18:11 Nirm
- * Code cleanup.
- *
- * 6 3/03/02 15:01 Nirm
- * - Code cleanup;
- * - Enhanced efficiency.
- *
- * 5 30/01/02 20:26 Nirm
- * Replaced min() with MIN().
- *
- * 4 16/01/02 15:55 Atai
- * Change debug printing
- *
- * 3 9/01/02 16:53 Nirm
- * Corrected Include-Paths.
- *
- * 2 30/12/01 13:16 Atai
- * correct varaible initial assignment
- ****************************************************************************************/
- #include "Config.h" // Global Configuration - do not remove!
- #ifdef _DEBUG
- #undef IFTRACE
- #define IFTRACE if (gTraceScPad)
- #include "DebugDbgMain.h"
- #endif //_DEBUG
- #include "Includemath-macro.h"
- #include "KerneluITRONRTOS.h"
- #include "PlaycoreAuxCacheAuxCache.h"
- #include "PlaycoreScPadSCMGR.h"
- #include "PlaycoreScPadScLLMgr.h"
- #include "Decoderlow_levelDEC_LL_Reg.h"
- /////////////////////////////////////////////////////////////////////////////
- // Constants and Enumerations
- // (2^SC_CLUSTER_EXP = Cluster Size in Bytes) for the SC Dynamic Memory
- #define SC_CLUSTER_EXP 6
- #define SC_BYTES_PER_CLUSTER (0x1 << SC_CLUSTER_EXP) // = 64 Bytes = 16 DWORDS
- #define SC_DWORDS_PER_CLUSTER (SC_BYTES_PER_CLUSTER / sizeof(DWORD))
- // Size (in DWORDs) of the SC Dynamic Memory
- #define SC_DYNAMIC_SZ (WORD)(wSC_CLUSTERS_CNT * SC_DWORDS_PER_CLUSTER)
- // Define the Dynamic Memory Allocation Base
- #ifdef DVD_VR_SUPPORT
- #define SC_BASEDYN_ADDR (WORD)0 //the position of dynamic memory is in the front of the scratch-pad
- #else
- #define SC_BASEDYN_ADDR (WORD)(wSC_SDRAM_SZ - SC_DYNAMIC_SZ)
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // Macros
- /////////////////////////////////////////////////////////////////////////////
- // Globals and Singletons
- static CONST BYTE g_aAllocBitMap[8]= { 0x80, 0xC0, 0xE0, 0xF0,
- 0xF8, 0xFC, 0xFE, 0xFF };
- /////////////////////////////////////////////////////////////////////////////
- // Implementation of Public Services
- /////////////////////////////////////////////////////////////////////////////
- // sc_Init()
- //
- // Description: Initializes the Scratch-Pad and fills its contents with
- // some desired value.
- //
- // Input: i_wInitVal - The desired value to fill the memory with.
- // Output: None
- // In/Out: None
- // Return: TRUE if the Scratch-Pad was successfully initialized;
- // FALSE otherwise.
- //
- // Remarks:
- BOOL sc_Init(WORD i_wInitVal)
- {
- BYTE bArrayElementTemp;
- int i;
- BOOL bSuccess;
- // Clear the Memory-Clusters Registry, and set the last Entry to 0xFF,
- // to increase efficiency during allocations.
- // memset(g_aMemClustersRegistry, 0, (bSizeof_MemClustersRegistry-1));
- // memset(g_aMemClustersRegistry, 0, (bSizeof_MemClustersRegistry-1));
- bArrayElementTemp = 0x00;
- for(i=0; i<bSizeof_MemClustersRegistry-1; i++)
- {
- sc_SetBytes(SC_MEMORY_CLUSTERS_REGISTRY_ADDR, (WORD)i,
- (WORD)1, (BYTE *)&bArrayElementTemp);
- }
- bSuccess = sc_ll_Init(i_wInitVal);
- // g_aMemClustersRegistry[bSizeof_MemClustersRegistry-1]= 0xFF;
- bArrayElementTemp = 0xFF;
- sc_SetBytes(SC_MEMORY_CLUSTERS_REGISTRY_ADDR, (WORD)(bSizeof_MemClustersRegistry-1),
- (WORD)1, (BYTE *)&bArrayElementTemp);
-
- return bSuccess;
- }
- /////////////////////////////////////////////////////////////////////////////
- // sc_Read()
- //
- // Description: Reads a sequence of successive Containers from the Scratch-
- // Pad.
- //
- // Input: i_hAddress - The Source-Address to read from;
- // i_uContainersCnt - The number of Containers to read.
- // Output: o_pDestBuff - Points to a buffer of Containers, which will
- // receive the data read.
- // In/Out: None
- // Return: Number of successfully read Containers.
- //
- // Remarks:
- WORD sc_Read(WORD i_hAddress, WORD i_uContainersCnt, Sc_cont *o_pDestBuff)
- {
- return sc_ll_Read(i_hAddress, i_uContainersCnt, &o_pDestBuff->dwDWORD);
- }
- WORD sc_Read32(UINT32 i_hAddress, WORD i_uContainersCnt, Sc_cont *o_pDestBuff)
- {
- return sc_ll_Read32(i_hAddress, i_uContainersCnt, &o_pDestBuff->dwDWORD);
- }
- /////////////////////////////////////////////////////////////////////////////
- // sc_Write()
- //
- // Description: Writes a sequence of successive Containers to the Scratch-
- // Pad.
- //
- // Input: i_hAddress - The Target-Address to write to;
- // i_uContainersCnt - The number of Containers to write;
- // i_pSourceBuff - Points to a buffer of Containers, which holds
- // data to write.
- // Output: None
- // In/Out: None
- // Return: Number of successfully written Containers.
- //
- // Remarks:
- WORD sc_Write(WORD i_hAddress, WORD i_uContainersCnt,
- const Sc_cont *i_pSourceBuff)
- {
- return sc_ll_Write(i_hAddress, i_uContainersCnt,
- (DWORD *)&i_pSourceBuff->dwDWORD);
- }
- WORD sc_Write32(UINT32 i_hAddress, WORD i_uContainersCnt,
- const Sc_cont *i_pSourceBuff)
- {
- return sc_ll_Write32(i_hAddress, i_uContainersCnt,
- (DWORD *)&i_pSourceBuff->dwDWORD);
- }
- /////////////////////////////////////////////////////////////////////////////
- // sc_Malloc()
- //
- // Description: Allocates memory from the Dynamic section of the Scratch-Pad.
- //
- // Input: i_uContainersCnt - Holds the number of Containers to allocate.
- // Output: None
- // In/Out: None
- // Return: The Address of the newly allocated Memory; NULL_HANDLE if the
- // request couldn't be satisfied.
- //
- // Remarks:
- // - The minimal allocation is of a single Cluster. If the number of
- // requested Containers is not an integer multiple of a Cluster, then
- // the request is rounded upwards, towards the closest Cluster boundary.
- // In this case, Memory gets wasted.
- // - The allocation is done using the Memory-Clusters Registry, and the
- // search utilizes either the "Best-Fit" or the "First-Fit" algorithm,
- // depending on the corresponding compilation-switch.
- #define SC_BESTFIT_ALLOCATION_ALGORITHM
- WORD sc_Malloc(UINT16 i_uContainersCnt)
- {
- STATUS_REG SRkeep;
- BYTE bArrayElementTemp;
- UINT8 uRegistryPos, uSlotPos;
- UINT16 uFreeClustersCnt;
- UINT16 uRequestedClustersCnt= ((i_uContainersCnt + (SC_DWORDS_PER_CLUSTER-1)) / SC_DWORDS_PER_CLUSTER);
- struct BestFit_TAG {
- UINT8 uRegistryPos;
- UINT8 uSlotPos;
- UINT16 uClustersCnt;
- } BestFit;
- // Search for the best-fit allocation
- BestFit.uRegistryPos= 0;
- BestFit.uSlotPos= 0;
- BestFit.uClustersCnt= 0xFFFF;
- uFreeClustersCnt= 0;
- // Critical-Section Start
- SRkeep = InterruptDisable();
- // Scan all the Memory-Clusters Registry Bytes
- for (uRegistryPos=0; uRegistryPos < bSizeof_MemClustersRegistry; uRegistryPos++) {
- UINT8 uSlotMask= 0x80;
- // Scan all the Bits (slots) within each Registry Byte
- for (uSlotPos=0; uSlotPos < 8; uSlotPos++) {
- // Check if the current Slot is Allocated or Free
- sc_GetBytes(SC_MEMORY_CLUSTERS_REGISTRY_ADDR, (WORD)uRegistryPos, (WORD)1, (BYTE *)&bArrayElementTemp);
- // if (0 == (g_aMemClustersRegistry[uRegistryPos] & uSlotMask)) {
- if (0 == (bArrayElementTemp & uSlotMask)) {
- // Free Cluster
- uFreeClustersCnt++;
- }
- else {
- // Allocated Cluster: Check if the amount of Free clusters found so far
- // satisfies the request.
- // If it does, and if the amount is samller than the Best-Fit, make it the new
- // Best-Fit.
- if ((uFreeClustersCnt >= uRequestedClustersCnt) &&
- (uFreeClustersCnt < BestFit.uClustersCnt))
- {
- UINT16 uChunkStart= (((uRegistryPos * 8) + uSlotPos) - uFreeClustersCnt);
- BestFit.uRegistryPos= (uChunkStart / 8);
- BestFit.uSlotPos= (uChunkStart % 8);
- BestFit.uClustersCnt= uFreeClustersCnt;
- #ifndef SC_BESTFIT_ALLOCATION_ALGORITHM
- break;
- #endif //SC_BESTFIT_ALLOCATION_ALGORITHM
- }
- // Reset the amount of Free clusters
- uFreeClustersCnt= 0;
- }
- // Move to the next Slot
- uSlotMask >>= 1;
- }
- }
- // Now, check if anything was found
- if (0xFFFF != BestFit.uClustersCnt) {
- BYTE ucAllocMask;
- // Allocate the free Clusters
- uRegistryPos= BestFit.uRegistryPos;
- uSlotPos= BestFit.uSlotPos;
- // Handle an allocation from an aligned slot
- while (uRequestedClustersCnt > 0) {
- uFreeClustersCnt= MIN(uRequestedClustersCnt, (8 - uSlotPos));
- ucAllocMask= (g_aAllocBitMap[uFreeClustersCnt-1] >> uSlotPos);
-
- // g_aMemClustersRegistry[uRegistryPos++] |= ucAllocMask;
- sc_GetBytes(SC_MEMORY_CLUSTERS_REGISTRY_ADDR, (WORD)uRegistryPos, (WORD)1, (BYTE *)&bArrayElementTemp);
- bArrayElementTemp |= ucAllocMask;
- sc_SetBytes(SC_MEMORY_CLUSTERS_REGISTRY_ADDR, (WORD)uRegistryPos,(WORD)1, (BYTE *)&bArrayElementTemp);
- uRegistryPos++;
- uRequestedClustersCnt -= uFreeClustersCnt;
- uSlotPos= 0;
- }
- }
- // Critical-Section End
- set_SR(SRkeep);
- // Prepare the return value
- if (0xFFFF == BestFit.uClustersCnt) {
- dbg_printf(("WARNING: sc_Malloc() Failed [1]: Request cannot be satisfied.n"));
- return NULL_HANDLE;
- }
- return (SC_BASEDYN_ADDR +
- (SC_DWORDS_PER_CLUSTER * ((BestFit.uRegistryPos * 8) + BestFit.uSlotPos)));
- }
- /////////////////////////////////////////////////////////////////////////////
- // sc_Free()
- //
- // Description: Frees memory that was previously allocated using sc_Malloc().
- //
- // Input: i_hAddress - The Address of the Memory to free;
- // i_uContainersCnt - The number of Containers to free.
- // Output: None
- // In/Out: None
- // Return: TRUE if the memory was freed successfully; FALSE otherwise.
- //
- // Remarks:
- // - The minimal deallocation is of a single Cluster. If the number of
- // requested Containers is not an integer multiple of a Cluster, then
- // the request is rounded upwards, towards the closest Cluster boundary.
- BOOL sc_Free(WORD i_hAddress, UINT16 i_uContainersCnt)
- {
- BYTE bArrayElementTemp;
- STATUS_REG SRkeep;
- BYTE ucFreeMask;
- UINT8 uRegistryPos, uSlotPos;
- UINT16 uClustersCnt;
- UINT16 uFreedClustersCnt= ((i_uContainersCnt + (SC_DWORDS_PER_CLUSTER-1)) / SC_DWORDS_PER_CLUSTER);
- // Make sure that there's anything to free
- if (0 == uFreedClustersCnt) {
- dbg_printf(("WARNING: sc_Free() Failed [1]: Nothing to free.n"));
- return FALSE;
- }
- #ifdef _DEBUG
- // Verify validity of the supplied Address
- if (i_hAddress < SC_BASEDYN_ADDR) {
- tr_printf(("FATAL: sc_Free() Failed [2]: Invalid Dynamic-Memory address.n"));
- return FALSE;
- }
- #endif //_DEBUG
- // Compute the Memory-Clusters Registry Entry corresponding to the supplied Address
- uClustersCnt= ((i_hAddress - SC_BASEDYN_ADDR) / SC_DWORDS_PER_CLUSTER);
- uRegistryPos= (uClustersCnt / 8);
- uSlotPos= (uClustersCnt % 8);
- #ifdef _DEBUG
- // Verify that the Clusters to be freed have not yet been freed
- uClustersCnt= uFreedClustersCnt;
- while (uClustersCnt > 0) {
- UINT8 uCurrClustersCnt= MIN(uClustersCnt, (8 - uSlotPos));
- ucFreeMask= (g_aAllocBitMap[uCurrClustersCnt-1] >> uSlotPos);
- sc_GetBytes(SC_MEMORY_CLUSTERS_REGISTRY_ADDR, (WORD)(uRegistryPos), (WORD)1, (BYTE *)&bArrayElementTemp);
- uRegistryPos++;
- // if (ucFreeMask != (g_aMemClustersRegistry[uRegistryPos++] & ucFreeMask)) {
- if (ucFreeMask != (bArrayElementTemp & ucFreeMask)) {
- dbg_printf(("WARNING: sc_Free() Failed [3]: Attempting to free an unallocated Cluster.n"));
- return FALSE;
- }
- uSlotPos= 0;
- uClustersCnt -= uCurrClustersCnt;
- }
- // Prepare for the deallocation (recompute Registry Entry)
- uClustersCnt= ((i_hAddress - SC_BASEDYN_ADDR) / SC_DWORDS_PER_CLUSTER);
- uRegistryPos= (uClustersCnt / 8);
- uSlotPos= (uClustersCnt % 8);
- #endif //_DEBUG
- // Critical-Section Start
- SRkeep = InterruptDisable();
- // Actually free the Clusters
- uClustersCnt= uFreedClustersCnt;
- while (uClustersCnt > 0) {
- UINT8 uCurrClustersCnt= MIN(uClustersCnt, (8 - uSlotPos));
- ucFreeMask= (g_aAllocBitMap[uCurrClustersCnt-1] >> uSlotPos);
- // g_aMemClustersRegistry[uRegistryPos++] &= (~ucFreeMask);
- sc_GetBytes(SC_MEMORY_CLUSTERS_REGISTRY_ADDR, (WORD)uRegistryPos, (WORD)1, (BYTE *)&bArrayElementTemp);
- bArrayElementTemp &= (~ucFreeMask);
- sc_SetBytes(SC_MEMORY_CLUSTERS_REGISTRY_ADDR, (WORD)(uRegistryPos), (WORD)1, (BYTE *)&bArrayElementTemp);
- uRegistryPos++;
- uSlotPos= 0;
- uClustersCnt -= uCurrClustersCnt;
- }
- // Critical-Section End
- set_SR(SRkeep);
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // sc_CopyFromDisc()
- //
- // Description: Copies data from the disc directly into the Scratch-Pad
- // memory.
- //
- // Input: i_dwStartLBN - Holds the Start-LBN of the data to copy;
- // i_dwOffset - Holds the offset, in Bytes, from the Start-LBN;
- // i_uBytesCnt - Gives the total number of Bytes to copy;
- // i_hSourceAddress - Holds the Destination-Address in the
- // Scratch-Pad.
- // Output: None
- // In/Out: None
- // Return: TRUE if the data was successfully copied; FALSE otherwise.
- //
- // Remarks:
- #define CONTAINERS_PER_TRANSFER 4
- BOOL sc_CopyFromDisc(DWORD i_dwStartLBN, DWORD i_dwOffset, WORD i_uBytesCnt,
- WORD i_hDestinationAddress)
- {
- BYTE aBuffer[CONTAINERS_PER_TRANSFER * BYTE_PER_CONTAINER];
- UINT8 cbCurrTransferSize;
- while (i_uBytesCnt > 0) {
- // Compute the size of the current Transfer
- cbCurrTransferSize= (UINT8)MIN(i_uBytesCnt, sizeof(aBuffer));
- // Read the data
- if (! AuxCache_GetBytes(i_dwStartLBN, i_dwOffset, cbCurrTransferSize, aBuffer)) {
- tr_printf(("FATAL: sc_CopyFromDisc() Failed [1]n"));
- return FALSE;
- }
- // Copy the data to the Scratch-Pad
- if (0 == CONTAINER_MOD(cbCurrTransferSize)) {
- // The Transfer is of an integer number of Containers
- sc_Write(i_hDestinationAddress, CONTAINER_COUNT(cbCurrTransferSize),
- (const Sc_cont *)aBuffer);
- }
- else {
- // The Transfer is not of an integer number of Containers
- sc_SetBytes(i_hDestinationAddress, 0, cbCurrTransferSize, aBuffer);
- }
- // Prepare for the next Transfer
- i_dwOffset += (DWORD)cbCurrTransferSize;
- i_hDestinationAddress += CONTAINERS_PER_TRANSFER;
- i_uBytesCnt -= cbCurrTransferSize;
- }
- return TRUE;
- }
- BOOL sc_CopyFromDisc32(DWORD i_dwStartLBN, DWORD i_dwOffset, WORD i_uBytesCnt,
- DWORD i_hDestinationAddress)
- {
- BYTE aBuffer[CONTAINERS_PER_TRANSFER * BYTE_PER_CONTAINER];
- UINT8 cbCurrTransferSize;
- while (i_uBytesCnt > 0) {
- // Compute the size of the current Transfer
- cbCurrTransferSize= (UINT8)MIN(i_uBytesCnt, sizeof(aBuffer));
- // Read the data
- if (! AuxCache_GetBytes(i_dwStartLBN, i_dwOffset, cbCurrTransferSize, aBuffer)) {
- tr_printf(("FATAL: sc_CopyFromDisc() Failed [1]n"));
- return FALSE;
- }
- // Copy the data to the Scratch-Pad
- if (0 == CONTAINER_MOD(cbCurrTransferSize)) {
- // The Transfer is of an integer number of Containers
- sc_Write32(i_hDestinationAddress, CONTAINER_COUNT(cbCurrTransferSize),
- (const Sc_cont *)aBuffer);
- }
- else {
- // The Transfer is not of an integer number of Containers
- sc_SetBytes32(i_hDestinationAddress, 0, cbCurrTransferSize, aBuffer);
- }
- // Prepare for the next Transfer
- i_dwOffset += (DWORD)cbCurrTransferSize;
- i_hDestinationAddress += CONTAINERS_PER_TRANSFER;
- i_uBytesCnt -= cbCurrTransferSize;
- }
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // sc_GetBytes()
- //
- // Description: Retrieves Bytes from the Scratch-Pad memory.
- //
- // Input: i_hSourceAddress - The Source Address from which to retrieve
- // the Bytes;
- // i_cbOffset - An offset, in Bytes, from the given Address;
- // i_cbSize - The amount of Bytes to get.
- //
- // Output: o_pDestBuff - Points to a buffer, which will receive the
- // requested Bytes.
- // In/Out: None
- // Return: None
- //
- // Remarks:
- void sc_GetBytes(WORD i_hSourceAddress, WORD i_cbOffset, WORD i_cbSize, BYTE *o_pDestBuff)
- {
- UINT8 cbInitialOffset;
- UINT16 uTransferSize;
- UINT16 uDestPos= 0;
- // Adjust the Source-Address
- i_hSourceAddress += CONTAINER_NORM(i_cbOffset);
- cbInitialOffset= CONTAINER_MOD(i_cbOffset);
- // If there is an initial Byte offset, first collect these Bytes
- if (0 != cbInitialOffset) {
- Sc_cont scFirstCont;
- // Read the first Container
- sc_Read(i_hSourceAddress++, 1, &scFirstCont);
- // Copy only the relevant Bytes
- uTransferSize= MIN(i_cbSize, (BYTE_PER_CONTAINER - cbInitialOffset));
- memcpy(&o_pDestBuff[0], &scFirstCont.ucBYTE[cbInitialOffset], uTransferSize);
- // Update the number of Bytes read, and the position in the Destination Buffer
- i_cbSize -= uTransferSize;
- uDestPos= uTransferSize;
- }
- // Now read as many Containers as possible, in an aligned manner
- uTransferSize= CONTAINER_NORM(i_cbSize);
- if (uTransferSize > 0) {
- sc_Read(i_hSourceAddress, uTransferSize, (Sc_cont *)&o_pDestBuff[uDestPos]);
- // Update the Source-Address
- i_hSourceAddress += uTransferSize;
- // Update the number of Bytes read, and the position in the Destination Buffer
- i_cbSize -= (uTransferSize * BYTE_PER_CONTAINER);
- uDestPos += (uTransferSize * BYTE_PER_CONTAINER);
- }
- // Read any remaining Bytes
- if (i_cbSize > 0) {
- Sc_cont scLastCont;
- // Read the last Container
- sc_Read(i_hSourceAddress, 1, &scLastCont);
- // Copy only the relevant Bytes
- memcpy(&o_pDestBuff[uDestPos], &scLastCont.ucBYTE[0], i_cbSize);
- }
- return;
- }
- void sc_GetBytes32(UINT32 i_hSourceAddress, WORD i_cbOffset, WORD i_cbSize, BYTE *o_pDestBuff)
- {
- UINT8 cbInitialOffset;
- UINT16 uTransferSize;
- UINT16 uDestPos= 0;
- // Adjust the Source-Address
- i_hSourceAddress += CONTAINER_NORM(i_cbOffset);
- cbInitialOffset= CONTAINER_MOD(i_cbOffset);
- // If there is an initial Byte offset, first collect these Bytes
- if (0 != cbInitialOffset) {
- Sc_cont scFirstCont;
- // Read the first Container
- sc_Read32(i_hSourceAddress++, 1, &scFirstCont);
- // Copy only the relevant Bytes
- uTransferSize= MIN(i_cbSize, (BYTE_PER_CONTAINER - cbInitialOffset));
- memcpy(&o_pDestBuff[0], &scFirstCont.ucBYTE[cbInitialOffset], uTransferSize);
- // Update the number of Bytes read, and the position in the Destination Buffer
- i_cbSize -= uTransferSize;
- uDestPos= uTransferSize;
- }
- // Now read as many Containers as possible, in an aligned manner
- uTransferSize= CONTAINER_NORM(i_cbSize);
- if (uTransferSize > 0) {
- sc_Read32(i_hSourceAddress, uTransferSize, (Sc_cont *)&o_pDestBuff[uDestPos]);
- // Update the Source-Address
- i_hSourceAddress += (UINT32)uTransferSize;
- // Update the number of Bytes read, and the position in the Destination Buffer
- i_cbSize -= (uTransferSize * BYTE_PER_CONTAINER);
- uDestPos += (uTransferSize * BYTE_PER_CONTAINER);
- }
- // Read any remaining Bytes
- if (i_cbSize > 0) {
- Sc_cont scLastCont;
- // Read the last Container
- sc_Read32(i_hSourceAddress, 1, &scLastCont);
- // Copy only the relevant Bytes
- memcpy(&o_pDestBuff[uDestPos], &scLastCont.ucBYTE[0], i_cbSize);
- }
- return;
- }
- /////////////////////////////////////////////////////////////////////////////
- // sc_SetBytes()
- //
- // Description: Writes Bytes to the Scratch-Pad memory.
- //
- // Input: i_hDestinationAddress - The Destination Address of the Bytes
- // to set;
- // i_cbOffset - An offset, in Bytes, from the given Address;
- // i_cbSize - The amount of Bytes to set;
- // i_pSrcBuff - Points to a Source Buffer from which to copy
- // the data.
- // Output: None
- // In/Out: None
- // Return: None
- //
- // Remarks:
- void sc_SetBytes(WORD i_hDestinationAddress, WORD i_cbOffset, WORD i_cbSize,
- const BYTE *i_pSrcBuff)
- {
- UINT8 cbInitialOffset;
- UINT16 uTransferSize;
- UINT16 uSrcPos= 0;
- // Adjust the Destination-Address
- i_hDestinationAddress += CONTAINER_NORM(i_cbOffset);
- cbInitialOffset= CONTAINER_MOD(i_cbOffset);
- // If there is an initial Byte offset, first set these Bytes
- if (0 != cbInitialOffset) {
- Sc_cont scFirstCont;
- // Read the first Container
- sc_Read(i_hDestinationAddress, 1, &scFirstCont);
- // Copy only the relevant Bytes
- uTransferSize= MIN(i_cbSize, (BYTE_PER_CONTAINER - cbInitialOffset));
- memcpy(&scFirstCont.ucBYTE[cbInitialOffset], &i_pSrcBuff[0], uTransferSize);
- // Write the first Container back
- sc_Write(i_hDestinationAddress++, 1, &scFirstCont);
- // Update the number of Bytes written, and the position in the Destination Buffer
- i_cbSize -= uTransferSize;
- uSrcPos= uTransferSize;
- }
- // Now write as many Containers as possible, in an aligned manner
- uTransferSize= CONTAINER_NORM(i_cbSize);
- if (uTransferSize > 0) {
- sc_Write(i_hDestinationAddress, uTransferSize, (const Sc_cont *)&i_pSrcBuff[uSrcPos]);
- // Update the Destination-Address
- i_hDestinationAddress += uTransferSize;
- // Update the number of Bytes read, and the position in the Source Buffer
- i_cbSize -= (uTransferSize * BYTE_PER_CONTAINER);
- uSrcPos += (uTransferSize * BYTE_PER_CONTAINER);
- }
- // Write any remaining Bytes
- if (i_cbSize > 0) {
- Sc_cont scLastCont;
- // Read the last Container
- sc_Read(i_hDestinationAddress, 1, &scLastCont);
- // Copy only the relevant Bytes
- memcpy(&scLastCont.ucBYTE[0], &i_pSrcBuff[uSrcPos], i_cbSize);
- // Write the last Container back
- sc_Write(i_hDestinationAddress, 1, &scLastCont);
- }
- return;
- }
- void sc_SetBytes32(UINT32 i_hDestinationAddress, WORD i_cbOffset, WORD i_cbSize,
- const BYTE *i_pSrcBuff)
- {
- UINT8 cbInitialOffset;
- UINT16 uTransferSize;
- UINT16 uSrcPos= 0;
- // Adjust the Destination-Address
- i_hDestinationAddress += CONTAINER_NORM(i_cbOffset);
- cbInitialOffset= CONTAINER_MOD(i_cbOffset);
- // If there is an initial Byte offset, first set these Bytes
- if (0 != cbInitialOffset) {
- Sc_cont scFirstCont;
- // Read the first Container
- sc_Read32(i_hDestinationAddress, 1, &scFirstCont);
- // Copy only the relevant Bytes
- uTransferSize= MIN(i_cbSize, (BYTE_PER_CONTAINER - cbInitialOffset));
- memcpy(&scFirstCont.ucBYTE[cbInitialOffset], &i_pSrcBuff[0], uTransferSize);
- // Write the first Container back
- sc_Write32(i_hDestinationAddress++, 1, &scFirstCont);
- // Update the number of Bytes written, and the position in the Destination Buffer
- i_cbSize -= uTransferSize;
- uSrcPos= uTransferSize;
- }
- // Now write as many Containers as possible, in an aligned manner
- uTransferSize= CONTAINER_NORM(i_cbSize);
- if (uTransferSize > 0) {
- sc_Write32(i_hDestinationAddress, uTransferSize, (const Sc_cont *)&i_pSrcBuff[uSrcPos]);
- // Update the Destination-Address
- i_hDestinationAddress += (UINT32)uTransferSize;
- // Update the number of Bytes read, and the position in the Source Buffer
- i_cbSize -= (uTransferSize * BYTE_PER_CONTAINER);
- uSrcPos += (uTransferSize * BYTE_PER_CONTAINER);
- }
- // Write any remaining Bytes
- if (i_cbSize > 0) {
- Sc_cont scLastCont;
- // Read the last Container
- sc_Read32(i_hDestinationAddress, 1, &scLastCont);
- // Copy only the relevant Bytes
- memcpy(&scLastCont.ucBYTE[0], &i_pSrcBuff[uSrcPos], i_cbSize);
- // Write the last Container back
- sc_Write32(i_hDestinationAddress, 1, &scLastCont);
- }
- return;
- }
- /////////////////////////////////////////////////////////////////////////////
- // sc_PrintStatus()
- //
- // Description: Prints-out the current allocation status
- //
- // Input: None
- // Output: None
- // In/Out: None
- // Return: None
- //
- // Remarks:
- #ifdef _DEBUG
- void sc_PrintStatus(void)
- {
- UINT8 uRegistryPos, uSlotPos;
- BYTE bArrayElementTemp;
- dbg_printf(("Scratch-Pad Allocation-status:n"));
- for (uRegistryPos=0; uRegistryPos < (bSizeof_MemClustersRegistry - 1); uRegistryPos++) {
- BYTE ucClusterMask= 0x80;
- if (0 == (uRegistryPos % 4)) {
- dbg_printf(("tClusters [%03d .. %03d] => ",
- (uRegistryPos * 8), ((uRegistryPos+3) * 8) ));
- }
- for (uSlotPos=0; uSlotPos < 8; uSlotPos++) {
- sc_GetBytes(SC_MEMORY_CLUSTERS_REGISTRY_ADDR, (WORD)uRegistryPos, (WORD)1, (BYTE *)&bArrayElementTemp);
- // dbg_printf(("%c", ((0 == (g_aMemClustersRegistry[uRegistryPos] & ucClusterMask)) ?
- dbg_printf(("%c", ((0 == (bArrayElementTemp & ucClusterMask)) ?
- '0' : '1') ));
- ucClusterMask >>= 1;
- }
- dbg_printf(("%c", (3 == (uRegistryPos % 4)) ? 'n' : ' '));
- }
- return;
- }
- #endif //_DEBUG