//-----------------------------------------------------------------------------
// \file test_nand.c
// \brief implementation of OMAP-L138 nand test.
//
//-----------------------------------------------------------------------------
#include "stdio.h"
#include "types.h"
#include "evmomapl138.h"
#include "evmomapl138_timer.h"
#include "evmomapl138_nand.h"
#include "test_nand.h"
//-----------------------------------------------------------------------------
// Private Defines and Macros
//-----------------------------------------------------------------------------
// block/page that should be beyond anything used by u-boot.
#define NAND_SAFE_BLOCK 1//(16)
#define NAND_SAFE_PAGE (0)
// size of test buffers.
#define MAX_BUFFER_SIZE (NAND_PAGE_SIZE)
//-----------------------------------------------------------------------------
// Static Variable Declarations
//-----------------------------------------------------------------------------
static uint8_t tx_buffer[MAX_BUFFER_SIZE];
static uint8_t rx_buffer[MAX_BUFFER_SIZE];
//-----------------------------------------------------------------------------
// Private Function Prototypes
//-----------------------------------------------------------------------------
static uint32_t verifyFlashData(uint32_t verify_block, uint32_t verify_page, uint8_t *ram_start_addr, uint8_t print_data);
//-----------------------------------------------------------------------------
// Public Function Definitions
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// \brief tests the nand.
//
// \param none.
//
// \return uint32_t
//-----------------------------------------------------------------------------
uint32_t TEST_nand(void)
{
uint32_t rtn;
uint32_t block;
uint32_t i;
printf("------------------------------------------------------------\r\n");
printf(" OMAP-L138 NAND Test\r\n\r\n");
printf("Test Description\r\n");
printf("----------------\r\n");
printf("This code will configure the EMIFA to interface with NAND \r\n");
printf("flash on the UI board. Once configured, the code will read \r\n");
printf("and write a block of NAND. \r\n");
printf("------------------------------------------------------------\r\n\r\n");
//-------------------------------------
// initialize the required bsl modules.
//-------------------------------------
printf("Initialize the Required BSL Modules\r\n");
printf("-----------------------------------\r\n\r\n");
rtn = NAND_init();
if (rtn != ERR_NO_ERROR)
{
printf("error initializing nand: %u\r\n", rtn);
return (rtn);
}
//--------------
// execute test.
//--------------
printf("\r\nExecute Test\r\n");
printf("------------\r\n\r\n");
printf("\r\n--- check bad block ---\r\n");
block = NAND_SAFE_BLOCK;
while (NAND_isBadBlock(block) != ERR_NO_ERROR)
{
printf("\tblock: %u is bad!\r\n", block);
block++;
}
printf("\tblock: %u good\r\n", block);
printf("\r\n--- read/print a chunk of nand flash ---\r\n");
for (i = 0; i < 2; i++)
{
rtn = NAND_readPage(block, i, rx_buffer);
if (rtn != ERR_NO_ERROR)
{
printf("\terror reading nand flash: %u\r\n", rtn);
return (rtn);
}
else
{
UTIL_printMem(i, rx_buffer, MAX_BUFFER_SIZE, PRINT_HEADER);
printf("\tnand flash read passed\r\n");
}
}
printf("\r\n--- erase a block of nand flash ---\r\n");
rtn = NAND_eraseBlock(block);
if (rtn != ERR_NO_ERROR)
{
printf("\terror erasing nand flash: %u\r\n", rtn);
return (rtn);
}
else
{
memset(tx_buffer, 0xFF, MAX_BUFFER_SIZE);
USTIMER_delay(DELAY_1_SEC);
rtn = verifyFlashData(block, NAND_SAFE_PAGE, tx_buffer, PRINT_NONE);
if (ERR_NO_ERROR == rtn)
{
printf("\tnand flash erase passed\r\n");
}
else
{
printf("\tnand flash erase failed\r\n");
return (rtn);
}
}
printf("\r\n--- write a page of nand flash ---\r\n");
// populate tx buffer.
for (i = 0; i < MAX_BUFFER_SIZE; i++)
{
tx_buffer[i] = (uint8_t)i;
}
rtn = NAND_writePage(block, NAND_SAFE_PAGE, tx_buffer);
if (rtn != ERR_NO_ERROR)
{
printf("\terror writing nand flash: %u\r\n", rtn);
return (rtn);
}
else
{
USTIMER_delay(DELAY_1_SEC);
rtn = verifyFlashData(block, NAND_SAFE_PAGE, tx_buffer, PRINT_DURING_VERIFY);
if (ERR_NO_ERROR == rtn)
{
printf("\tnand flash write passed\r\n");
}
else
{
printf("\tnand flash write failed\r\n");
return (rtn);
}
}
printf("\r\n--- erase a block of nand flash ---\r\n");
rtn = NAND_eraseBlock(block);
if (rtn != ERR_NO_ERROR)
{
printf("\terror erasing nand flash: %u\r\n", rtn);
return (rtn);
}
else
{
memset(tx_buffer, 0xFF, MAX_BUFFER_SIZE);
USTIMER_delay(DELAY_1_SEC);
rtn = verifyFlashData(block, NAND_SAFE_PAGE, tx_buffer, PRINT_NONE);
if (ERR_NO_ERROR == rtn)
{
printf("\tnand flash erase passed\r\n");
}
else
{
printf("\tnand flash erase failed\r\n");
return (rtn);
}
}
printf("\r\n");
return (ERR_NO_ERROR);
}
//-----------------------------------------------------------------------------
// Private Function Definitions
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// verifies nand flash write worked.
//-----------------------------------------------------------------------------
uint32_t verifyFlashData(uint32_t verify_block, uint32_t verify_page, uint8_t *ram_start_addr, uint8_t print_data)
{
uint32_t rtn = ERR_NO_ERROR;
rtn = NAND_readPage(verify_block, verify_page, rx_buffer);
if (rtn != ERR_NO_ERROR)
{
printf("\terror while reading from nand flash during verify");
return (rtn);
}
// print data if desired.
if (print_data)
{
UTIL_printMem(verify_block, rx_buffer, MAX_BUFFER_SIZE, PRINT_HEADER);
}
if (memcmp(rx_buffer, ram_start_addr, MAX_BUFFER_SIZE) != 0)
{
rtn = ERR_FLASH_VERIFY;
printf("\tdata does not match!");
}
return (rtn);
}
nand.rar_源码
版权申诉
68 浏览量
2022-09-24
19:41:03
上传
评论
收藏 88KB RAR 举报
![avatar](https://profile-avatar.csdnimg.cn/fca2fc36c4174e7caf12f1c9ba2c9265_weixin_42657024.jpg!1)
邓凌佳
- 粉丝: 66
- 资源: 1万+
最新资源
- XuGuManager
- python调CANoe
- TA-Lib-0.4.29-cp312-win-amd64.whl
- springboot底层机制实现: zzw-springboot项目
- 06-18-科文22软件-mybatis-spring整合-上午.wmv
- 海信智能电视刷机数据 LED42K600X3D(1001) 生产用软件数据 务必确认机编一致 强制刷机 整机USB升级程序
- 目标检测-手机屏幕表面缺陷检测数据集-1200张图-+对应VOC-COCO-YOLO三种格式标签+数据集划分脚本
- 「天若有情 」深情版--天下万般兵刃 唯有过往伤人最深.mp3
- 123456daWDdwD
- 用友U810.1数据库字典-只需要1积分
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)