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

📄 memtest.c

📁 硬件要求:基于合纵达的SEED-VPM642的示例。软件要求:CCS2.2以上版本。对于想用DSP/BIOS开发的同道中人来说是很好的学习实例。
💻 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.
 *  
 */
/* "@(#) DSP/BIOS 4.90.270 06-11-03 (barracuda-m10)" */
/*
 *  ======== memtest.c ========
 *  This program allocates and frees memory from
 *  different memory segments.
 */
 
#include <std.h>

#include <log.h>
#include <mem.h>

#include "memtestcfg.h"


#define NALLOCS 2       /* # of allocations from each segment */
#define BUFSIZE 128     /* size of allocations */

extern Int SEG0;

static Void printmem(Int segid);

/*
 *  ======== main ========
 */
Void main()
{
    LOG_printf(&trace, "memtest example started.\n");
}

/*
 *  ======== initTask ========
 */
Void initTask()
{
    Int i;
    Ptr ram[NALLOCS];

    LOG_printf(&trace, "before allocating ...");

    /* print initial memory status */
    printmem(SEG0);

    LOG_printf(&trace, "allocating ...");

    /* allocate some memory from each segment */
    for (i = 0; i < NALLOCS; i++) {
        ram[i] = MEM_alloc(SEG0, BUFSIZE, 0);
#ifdef _28_
        LOG_printf(&trace, "seg %d: ptr = %p", (Arg)SEG0, (Arg)ram[i]);
#else
        LOG_printf(&trace, "seg %d: ptr = %p", SEG0, ram[i]);
#endif
    }

    LOG_printf(&trace, "after allocating ...");

    /* print memory status */
    printmem(SEG0);

    /* free memory */
    for (i = 0; i < NALLOCS; i++) {
        MEM_free(SEG0, ram[i], BUFSIZE);
    }

    LOG_printf(&trace, "after freeing ...");

    /* print memory status */
    printmem(SEG0);

    LOG_printf(&trace, "Test Complete");
}

/*
 *  ======== printmem ========
 */
static Void printmem(Int segid)
{
    MEM_Stat    statbuf;

    MEM_stat(segid, &statbuf);

#ifdef _28_
    LOG_printf(&trace, "seg %d: O 0x%x", (Arg)segid,(Arg)statbuf.size);
    LOG_printf(&trace, "\tU 0x%x\tA 0x%x", (Arg)statbuf.used,(Arg)statbuf.length);
#else
    LOG_printf(&trace, "seg %d: O 0x%x", segid, statbuf.size);
    LOG_printf(&trace, "\tU 0x%x\tA 0x%x", statbuf.used, statbuf.length);
#endif
}

⌨️ 快捷键说明

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