⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 storage.c

📁 MSP430与DSP接口技术3 编辑环境C语言,未试过,仅供参考
💻 C
字号:
/*
 *  Copyright 2003 by Texas Instruments Incorporated.
 *  All rights reserved. Property of Texas Instruments Incorporated.
 *  Restricted rights to use, duplicate or disclose this code are
 *  granted through contract.
 *  
 */
/* "@(#) XDSP_Audio 3.00.00.36 12-18-03 (swat-f30)" */
/*
 *  ======== storage.c ========
 *
 *  Implementation of the storage module
 */
#include <std.h>
#include <mem.h>

#include <utl.h>            /* debug/diagnostics utility functions */

#include "storage.h"

static Int heapId;			/* storage heap's identifier */
static Uns *storageAddr;	
static Long storageSize = 0;
static Uns storageMaxCnt;

Void STORAGE_setup( Int heapIdentifier, Long size ) 
{
 	heapId = heapIdentifier;
 	storageSize = size;
 	
 	storageAddr = MEM_alloc( heapId, storageSize, 0 );
 	UTL_assert( storageAddr != MEM_ILLEGAL );
 	storageMaxCnt = 0;
} 	
 
Void STORAGE_new( STORAGE_Handle storageObjectAddress ) 
{
	storageObjectAddress->offset = 0;
}

Void STORAGE_rewind( STORAGE_Handle storageObjectAddress ) 
{
	storageObjectAddress->offset = 0;
}

Bool STORAGE_store( STORAGE_Handle stHandle, Ptr dataBuffer, 
	   Int bufferSize )
{
	Int i;
	Uns *src = (Uns *)dataBuffer;
	Uns *dst = storageAddr + stHandle->offset;
	Uns size = storageSize - stHandle->offset;
	
	if (stHandle->offset < storageSize) {
		if (size > bufferSize) {
			size = bufferSize;
		}
		for (i = 0; i < size; i++) {
			dst[i] = src[i];
		}
		stHandle->offset += size;
		if (stHandle->offset > storageMaxCnt) {
		    storageMaxCnt = stHandle->offset;
		}
		return FALSE;
	}
	else {
		stHandle->offset = 0;
		return TRUE;
	}		
}	

Bool STORAGE_retrieve( STORAGE_Handle stHandle, Ptr dataBuffer, 
	   Int bufferSize )
{	   
	Int i;
	Uns *src;
	Uns *dst = (Uns *)dataBuffer;
	Uns size = storageMaxCnt - stHandle->offset; 
	Bool retVal = FALSE;
	
    if (size > bufferSize) {
        size = bufferSize;
    }
    else {
	    stHandle->offset = 0;
	    retVal = TRUE; //Specify that there has been a rewind
    }    	
    
    src = storageAddr + stHandle->offset;
    for (i = 0; i < size; i++) {		
	    dst[i] = src[i];
    }
	stHandle->offset += size;
    return retVal;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -