📄 smedia.c
字号:
//****************************************************************************
//
// SMEDIA.C - Performs a non-destructive test on a SmartMedia card.
//
// Copyright (c) 1999 - 2001 Cirrus Logic, Inc.
//
//****************************************************************************
#include "lib7312.h"
//****************************************************************************
//
// ucBuffer is used to save the contents of a block of the SmartMedia card
// during the test. This buffer is the maximum size of a block of a
// SmartMedia card.
//
//****************************************************************************
unsigned char ucBuffer[528 * 32];
//****************************************************************************
//
// PrintLong prints the value of a variable on the LCD in hexadecimal.
//
//****************************************************************************
void
PrintLong(unsigned long ulValue, long lX, long lY, CPixel sColor)
{
char cMap[17] = "0123456789ABCDEF";
//
// Print out the value the way "%04X" would in C.
//
LCDColorPrintChar(cMap[(ulValue & 0xF000) >> 12], lX, lY, sColor);
LCDColorPrintChar(cMap[(ulValue & 0x0F00) >> 8], lX + 8, lY, sColor);
LCDColorPrintChar(cMap[(ulValue & 0x00F0) >> 4], lX + 16, lY, sColor);
LCDColorPrintChar(cMap[ulValue & 0x000F], lX + 24, lY, sColor);
}
//****************************************************************************
//
// This program performs a non-destructive memory test on a SmartMedia card.
// The memory on the card is tested a block at a time, with the original
// contents of the block being restored after the block is tested. This is
// not to be construed as an effective test of the NAND FLASH on the
// SmartMedia card, but more as a means of showing how to read and write data
// via the SmartMedia interface.
//
//****************************************************************************
void
entry(void)
{
unsigned long ulSize, ulPageSize, ulPagesPerBlock, ulNumBlocks;
unsigned long ulBlock, ulPattern, ulIdx, ulLoop, ulErrors = 0, ulBadBlock;
unsigned char ucData[512 + 16];
unsigned char ucPatterns[] = { 0x00, 0x55, 0xaa, 0xff };
CPixel sWrite, sErase;
char cTemp;
//
// Enable the LCD controller, clear the frame buffer, and turn on the LCD
// panel.
//
LCDColorEnable();
LCDColorCls();
LCDColorOn();
LCDColorBacklightOn();
LCDColorContrastEnable();
//
// Set the Write color to white.
//
sWrite.r = 15;
sWrite.g = 15;
sWrite.b = 15;
//
// Set the Erase color to black.
//
sErase.r = 0;
sErase.g = 0;
sErase.b = 0;
//
// Get the device geometry of the SmartMedia card.
//
if(!(SMGetSize(&ulSize, &ulPageSize, &ulPagesPerBlock, &ulNumBlocks)))
{
LCDColorPrintString("Error retrieving the Smart Media Size", 5, 20,
sWrite);
LCDColorPrintString("information.", 5, 30, sWrite);
LCDColorPrintString("Smart Media card may not be inserted.", 5, 42,
sWrite);
}
else
{
//
// The page size returned is just the main storage area. We want to save
// and restore (and therefore test) the save area as well. If we do not
// preserve the save area, the SSFDC file system on the card will be
// destroyed.
//
ulPageSize += ulPageSize / 32;
//
// Display the basic progress information.
//
LCDColorPrintString("Block:", 100, 70, sWrite);
LCDColorPrintString("Failures:", 100, 80, sWrite);
LCDColorPrintString("0000", 175, 80, sWrite);
//
// Test each block of the SmartMedia card a block at a time.
//
for(ulBlock = 0; ulBlock < ulNumBlocks; ulBlock++)
{
//
// If we're not on the first block, erase the block
// number from the LCD.
//
if (ulBlock != 0)
{
PrintLong(ulBlock - 1, 175, 70, sErase);
}
//
// Display this sector number on the LCD screen.
//
PrintLong(ulBlock, 175, 70, sWrite);
//
// Initially, this block is not bad.
//
ulBadBlock = 0;
//
// Read the contents of each page in this block.
//
for(ulIdx = 0; ulIdx < ulPagesPerBlock; ulIdx++)
{
SMReadPage((ulBlock * ulPagesPerBlock) + ulIdx, 1,
ucBuffer + (ulIdx * ulPageSize));
}
//
// Test this block with our four bit patterns (all zeros, all ones, and
// the two different checkboards).
//
for(ulPattern = 0; ulPattern < 4; ulPattern++)
{
//
// Erase this block.
//
SMEraseBlock(ulBlock);
//
// Fill the data buffer with the current pattern.
//
for(ulIdx = 0; ulIdx < ulPageSize; ulIdx++)
{
ucData[ulIdx] = ucPatterns[ulPattern];
}
//
// Write the data buffer to each page in this block.
//
for(ulIdx = 0; ulIdx < ulPagesPerBlock; ulIdx++)
{
SMWritePage((ulBlock * ulPagesPerBlock) + ulIdx, 1, ucData);
}
//
// Read back each page of this block.
//
for(ulIdx = 0; ulIdx < ulPagesPerBlock; ulIdx++)
{
//
// Read the page.
//
SMReadPage((ulBlock * ulPagesPerBlock) + ulIdx, 1, ucData);
//
// Check to see that each byte of the read back data matches
// the pattern that we wrote.
//
for(ulLoop = 0; ulLoop < ulPageSize; ulLoop++)
{
//
// Does this byte match?
//
if(ucData[ulLoop] != ucPatterns[ulPattern])
{
//
// One byte in this block is bad.
//
ulBadBlock = 1;
}
}
}
}
//
// Erase this block.
//
SMEraseBlock(ulBlock);
//
// Now write a different pattern in each page of the block.
//
for(ulIdx = 0; ulIdx < ulPagesPerBlock; ulIdx++)
{
//
// Create the data pattern in the buffer.
//
for(ulLoop = 0; ulLoop < ulPageSize; ulLoop = ulLoop + 4)
{
cTemp = (0x80 + ulIdx + ulLoop) & 0xff;
ucData[ulLoop] = cTemp;
ucData[ulLoop + 1] = cTemp;
ucData[ulLoop + 2] = cTemp;
ucData[ulLoop + 3] = cTemp;
}
//
// Write the data pattern to this page.
//
SMWritePage((ulBlock * ulPagesPerBlock) + ulIdx, 1, ucData);
}
//
// Read back the data for verification.
//
for(ulIdx = 0; ulIdx < ulPagesPerBlock; ulIdx++)
{
//
// Read this page.
//
SMReadPage((ulBlock * ulPagesPerBlock) + ulIdx, 1, ucData);
//
// Verify that the data matches the pattern written.
//
for(ulLoop = 0; ulLoop < ulPageSize; ulLoop = ulLoop + 4)
{
//
// Does this byte match?
//
cTemp = (0x80 + ulIdx + ulLoop) & 0xff;
if(cTemp != (ucData[ulLoop] | ucData[ulLoop + 1] |
ucData[ulLoop + 2] | ucData[ulLoop + 3]))
{
//
// One byte in this block is bad.
//
ulBadBlock = 1;
}
}
}
//
// Erase this block.
//
SMEraseBlock(ulBlock);
//
// Restore the original contents of this block.
//
for(ulIdx = 0; ulIdx < ulPagesPerBlock; ulIdx++)
{
SMWritePage((ulBlock * ulPagesPerBlock) + ulIdx, 1,
ucBuffer + (ulIdx * ulPageSize));
}
//
// If we found an error in this block, the increment the count of bad
// blocks.
//
if(ulBadBlock)
{
ulErrors++;
//
// Print out the number of errors.
//
PrintLong(ulErrors - 1, 175, 80, sErase);
PrintLong(ulErrors, 175, 80, sWrite);
}
}
}
//
// Ask the user to press a keyboard button.
//
LCDColorPrintString("The Smart Media test is completed.", 40, 100, sWrite);
LCDColorPrintString("Press one of the User keys on the", 40, 115, sWrite);
LCDColorPrintString("keypad to exit.", 40, 125, sWrite);
//
// Wait until a user button is pressed.
//
KPGetUserButton();
KPNoButton();
//
// Turn off the LCD panel.
//
LCDColorOff();
LCDColorBacklightOff();
LCDColorOff();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -