Embedded之memory test
1 main.c
#include "led.h" #define BASE_ADDRESS (volatile datum *) 0x10000000
#define NUM_BYTES 0x10000 /**********************************************************************
*
* Function: main()
*
* Description: Test the second 64 KB bank of SRAM.
*
* Notes:
*
* Returns: 0 on success.
* Otherwise -1 indicates failure.
*
**********************************************************************/
main(void)
{
if ((memTestDataBus(BASE_ADDRESS) != ) ||
(memTestAddressBus(BASE_ADDRESS, NUM_BYTES) != NULL) ||
(memTestDevice(BASE_ADDRESS, NUM_BYTES) != NULL))
{
toggleLed(LED_RED);
return (-);
}
else
{
toggleLed(LED_GREEN);
return ();
} } /* main() */
1.1 Data bus test
// typedef unsigned char datum; /* Set the data bus width to 8 bits. */
/**********************************************************************
*
* Function: memTestDataBus()
*
* Description: Test the data bus wiring in a memory region by
* performing a walking 1's test at a fixed address
* within that region. The address (and hence the
* memory region) is selected by the caller.
*
* Notes:
*
* Returns: 0 if the test succeeds.
* A non-zero result is the first pattern that failed.
*
**********************************************************************/
datum
memTestDataBus(volatile datum * address)
{
datum pattern;
/*
* Perform a walking 1's test at the given address.
*/
for (pattern = ; pattern != ; pattern <<= )
{
/*
* Write the test pattern.
*/
*address = pattern;
/*
* Read it back (immediately is okay for this test).
*/
if (*address != pattern)
{
return (pattern);
}
}
return ();
} /* memTestDataBus() */
1.2 Address bus test
/**********************************************************************
*
* Function: memTestAddressBus()
*
* Description: Test the address bus wiring in a memory region by
* performing a walking 1's test on the relevant bits
* of the address and checking for aliasing. This test
* will find single-bit address failures such as stuck
* -high, stuck-low, and shorted pins. The base address
* and size of the region are selected by the caller.
*
* Notes: For best results, the selected base address should
* have enough LSB 0's to guarantee single address bit
* changes. For example, to test a 64-Kbyte region,
* select a base address on a 64-Kbyte boundary. Also,
* select the region size as a power-of-two--if at all
* possible.
*
* Returns: NULL if the test succeeds.
* A non-zero result is the first address at which an
* aliasing problem was uncovered. By examining the
* contents of memory, it may be possible to gather
* additional information about the problem.
*
**********************************************************************/
datum * memTestAddressBus(volatile datum * baseAddress, unsigned long nBytes)
{
unsigned long addressMask = (nBytes/sizeof(datum) - );
unsigned long offset;
unsigned long testOffset;
datum pattern = (datum) 0xAAAAAAAA;
datum antipattern = (datum) 0x55555555;
/*
* Write the default pattern at each of the power-of-two offsets.
*/
for (offset = ; (offset & addressMask) != ; offset <<= )
{
baseAddress[offset] = pattern;
}
/*
* Check for address bits stuck high.
*/
testOffset = ;
baseAddress[testOffset] = antipattern;
for (offset = ; (offset & addressMask) != ; offset <<= )
{
if (baseAddress[offset] != pattern)
{
return ((datum *) &baseAddress[offset]);
}
}
baseAddress[testOffset] = pattern;
/*
* Check for address bits stuck low or shorted.
*/
for (testOffset = ; (testOffset & addressMask) != ; testOffset <<= )
{
baseAddress[testOffset] = antipattern;
if (baseAddress[] != pattern)
{
return ((datum *) &baseAddress[testOffset]);
}
for (offset = ; (offset & addressMask) != ; offset <<= )
{
if ((baseAddress[offset] != pattern) && (offset != testOffset))
{
return ((datum *) &baseAddress[testOffset]);
}
}
baseAddress[testOffset] = pattern;
}
return (NULL);
} /* memTestAddressBus() */
1.3 Device test
/**********************************************************************
*
* Function: memTestDevice()
*
* Description: Test the integrity of a physical memory device by
* performing an increment/decrement test over the
* entire region. In the process every storage bit
* in the device is tested as a zero and a one. The
* base address and the size of the region are
* selected by the caller.
*
* Notes:
*
* Returns: NULL if the test succeeds. Also, in that case, the
* entire memory region will be filled with zeros.
*
* A non-zero result is the first address at which an
* incorrect value was read back. By examining the
* contents of memory, it may be possible to gather
* additional information about the problem.
*
**********************************************************************/
datum * memTestDevice(volatile datum * baseAddress, unsigned long nBytes)
{
unsigned long offset;
unsigned long nWords = nBytes / sizeof(datum);
datum pattern;
datum antipattern;
/*
* Fill memory with a known pattern.
*/
for (pattern = , offset = ; offset < nWords; pattern++, offset++)
{
baseAddress[offset] = pattern;
}
/*
* Check each location and invert it for the second pass.
*/
for (pattern = , offset = ; offset < nWords; pattern++, offset++)
{
if (baseAddress[offset] != pattern)
{
return ((datum *) &baseAddress[offset]);
}
antipattern = ~pattern;
baseAddress[offset] = antipattern;
}
/*
* Check each location for the inverted pattern and zero it.
*/
for (pattern = , offset = ; offset < nWords; pattern++, offset++)
{
antipattern = ~pattern;
if (baseAddress[offset] != antipattern)
{
return ((datum *) &baseAddress[offset]);
}
}
return (NULL);
} /* memTestDevice() */
Embedded之memory test的更多相关文章
- Embedded之memory type
1 Types of memory 2 Characteristics
- lwIP Memory Management
http://lwip.wikia.com/wiki/Lwipopts.h Memory management (RAM usage) /** * MEM_LIBC_MALLOC==1: Use ma ...
- STM32 DMA使用详解
DMA部分我用到的相对简单,当然,可能这是新东西,我暂时还用不到它的复杂功能吧.下面用问答的形式表达我的思路. DMA有什么用? 直接存储器存取用来提供在外设和存储器之间或者存储器和存储器之间的高速数 ...
- 基于WDF的PCI/PCIe接口卡Windows驱动程序(4)- 驱动程序代码(源文件)
原文出处:http://www.cnblogs.com/jacklu/p/4687325.html 本篇文章将对PCIe驱动程序的源文件代码作详细解释与说明.整个WDF驱动程序工程共包含4个头文件(已 ...
- STM32 flash 内存分布介绍
摘要: 本文以STM32F103RBT6为例介绍了片上Flash(Embedded Flash)若干问题,包括Flash大小(内存映射).块大小.页面大小.寄存器.这些知识,有利于写Flash驱动. ...
- STM32L071CBTX操作ECC508
因为我是在stm32上面做的加密操作,所以我只对stm32的方案做总结. 1.ATECC508的底层接口是i2c的,工程中跟i2c相关的操作放在文件hal_stm32l0_ateccx08_i2c.c ...
- 主机-配件-接口-整机-3c-2
pc机,服务器,智能手机与各种嵌入式乃至物联网 http://www.mifalife.net/hk/mall.html MIFA F5 户外无线蓝牙音箱2.0声道高保真可通话插卡便携低音炮迷你iph ...
- 驱动之DMA的介绍与应用20170210
本文主要介绍的是DMA相关的知识,首先: 1)在实现DMA传输时,是由DMA控制器直接掌管总线,因此,存在着一个总线控制权转移问题.即DMA传输前,CPU要把 总线控制权交给DMA控制器,而在结束DM ...
- PatentTips - Method for booting a host device from an MMC/SD device
FIELD OF THE INVENTION The present invention relates to a memory device and especially to the interf ...
随机推荐
- Html 全屏切换效果
来源 http://www.imooc.com/learn/374 pageswitch.js (function ($) { var defaults = { 'container': '#cont ...
- git环境搭建
Linux kernel 的官方 GIT地址是: http://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git 可以从这个地 ...
- (六)C#中判断空字符串的三种方法性能分析
三种方法分别是: string a=""; 1.if(a=="") 2.if(a==string.Empty) 3.if(a.Length==0) 三种方法是等 ...
- Just Have a Change
If you still do something meaningless or live a purposeless and empty life. Now, it may be time for ...
- Newtonsoft.Json高级用法 1.忽略某些属性 2.默认值的处理 3.空值的处理 4.支持非公共成员 5.日期处理 6.自定义序列化的字段名称
手机端应用讲究速度快,体验好.刚好手头上的一个项目服务端接口有性能问题,需要进行优化.在接口多次修改中,实体添加了很多字段用于中间计算或者存储,然后最终用Newtonsoft.Json进行序列化返回数 ...
- 35.3wCF编程
1.新建一个空白的解决方案文件,然后添加新建项目,项目类型为WCF服务应用程序,CH35Ex01 2.添加新建控制台应用程序Ch35Ex01Client 3.生成解决方案 4.右键Ch35Ex01Cl ...
- Order to Cash Process
order to cash process steps can be listed as below · Enter the Sales Order · Book the Sales Order · ...
- 如何有效地报告 Bug
如何有效地报告 Bug 引言 为公众写过软件的人,大概都收到过很拙劣的bug(计算机程序代码中的错误或程序运行时的瑕疵--译者注)报告,例如: 在报告中说"不好用": 所报告内容毫 ...
- Hibernate HQL注入攻击入门
SQL注入是一种大家非常熟悉的攻击方式,目前网络上有大量存在注入漏洞的DBMS(如MySQL,Oracle,MSSQL等).但是,我在网络上找不到针对Hibernate查询语言的相关资源.因此本文总结 ...
- 【笨嘴拙舌WINDOWS】实践检验之按键精灵【Delphi】
通过记录键盘和鼠标位置和输入信息,然后模拟发送,就能够创建一个按键精灵! 主要代码如下: library KeyBoardHook; { Important note about DLL memory ...