📄 flashtest.c
字号:
/*
* Copyright (c) 1995 - 2000 by TriMedia Technologies.
*
* +------------------------------------------------------------------+
* | This software is furnished under a license and may only be used |
* | and copied in accordance with the terms and conditions of such |
* | a license and with the inclusion of this copyright notice. This |
* | software or any other copies of this software may not be provided|
* | or otherwise made available to any other person. The ownership |
* | and title of this software is not transferred. |
* | |
* | The information in this software is subject to change without |
* | any prior notice and should not be construed as a commitment by |
* | TriMedia Technologies. |
* | |
* | this code and information is provided "as is" without any |
* | warranty of any kind, either expressed or implied, including but |
* | not limited to the implied warranties of merchantability and/or |
* | fitness for any particular purpose. |
* +------------------------------------------------------------------+
*
* Module name : flashTest.c 1.3
*
* Last update : 17:20:43 - 00/11/09
*
* Description : Simple flash test program.
*/
#include <stdio.h>
#include <tm1/tsaFlash.h>
#include <tmlib/tmtypes.h>
#include <stdlib.h>
#define NUM_BYTES 10
#define NUM_WORDS 4
#define NUM_SECTORS 4
#define FLASH_BLOCK_SIZE 0x00040000
void main(void)
{
tmLibdevErr_t err;
UInt32 instance;
UInt32 dataWord;
UInt32 dataBlock[100];
UInt32 size;
UInt32 address;
UInt32 sector;
UInt32 i;
ptsaFlashCapabilities_t caps;
Char ins[80];
Bool done = False;
printf("\nFlash test program.\n\n");
err = tsaFlashGetCapabilities(&caps);
if (err)
{
printf("Error (%#x) while getting flash capabilities.\n", err);
return;
}
printf("Flash name: %s\n", caps->flashName);
printf("Flash size: %010#x\n", caps->flashSize);
printf("Flash numberOfSectors: %010#x\n", caps->numberOfSectors);
printf("Flash sector size: %010#x\n", caps->sectorSize);
printf("Erased word: %010#x\n", caps->erasedWord);
printf("Number of sup. instances: %d\n", caps->numSupportedInstances);
printf("Number of used instances: %d\n", caps->numCurrentInstances);
err = tsaFlashOpen(&instance);
if (err)
{
printf("Error (%#x) while opening flash library.\n", err);
return;
}
while (!done)
{
printf("\nww <a> <d> - write word <d> to address <d>");
printf("\nrw <a> - read word at <a>");
printf("\nwb <a> <d> <n> - write <d> to a block of <n> words starting");
printf("\n at address <a> (max. 100 words)");
printf("\nrb <a> <n> - read a block of <n> words starting at address <a>");
printf("\n (max. 100 words)");
printf("\nes <n> - erase sector number <n>");
printf("\nea - erase entire flash");
printf("\ncaps - print flash capabilities");
printf("\nquit - to quit program\n\n");
gets(ins);
if (!strncmp(ins, "ww", 2))
{
sscanf(ins, "ww %x %x", &address, &dataWord);
err = tsaFlashWriteWord(instance, address, dataWord);
if (err != TMLIBDEV_OK)
printf(" Error (%#x) while writing\n", err);
else
printf(" Wrote %010#x to address %#x\n", dataWord, address);
}
else if(!strncmp(ins, "rw", 2))
{
sscanf(ins, "rw %x", &address);
err = tsaFlashReadWord(instance, address, &dataWord);
if (err)
printf("Error (%#x) while reading at address.\n", err, address);
else
printf("Read %010#x at address %#x\n", dataWord, address);
}
else if(!strncmp(ins, "wb", 2))
{
sscanf(ins, "wb %x %x %d", &address, &dataWord, &size);
for (i = 0; i < size; i++)
dataBlock[i] = dataWord;
err = tsaFlashWriteBlock(instance, address, dataBlock, size);
if (err != TMLIBDEV_OK)
printf(" Error (%#x) while writing\n", err);
}
else if(!strncmp(ins, "rb", 2))
{
sscanf(ins, "rb %x %d", &address, &size);
printf("Reading %d words from %#x\n", size, address);
err = tsaFlashReadBlock(instance, address, dataBlock, size);
if (err != TMLIBDEV_OK)
printf(" Error (%#x) while writing\n", err);
else
{
for (i = 0; i < size; i++)
printf("Read %010#x at %#x\n", dataBlock[i], address + i);
}
}
else if(!strncmp(ins, "es", 2))
{
sscanf(ins, "es %x", §or);
err = tsaFlashEraseSector(instance, sector);
if (err)
printf("Error (%#x) while erasing sector %#x.\n", err, sector);
}
else if(!strncmp(ins, "ea", 2))
{
err = tsaFlashEraseAll(instance);
if (err)
printf("Error (%#x) while erasing whole flash.\n", err);
}
else if(!strncmp(ins, "caps", 4))
{
err = tsaFlashGetCapabilities(&caps);
if (err)
{
printf("Error (%#x) while getting flash capabilities.\n", err);
return;
}
else
{
printf("Flash name: %s\n", caps->flashName);
printf("Flash size: %010#x\n", caps->flashSize);
printf("Flash numberOfSectors: %010#x\n", caps->numberOfSectors);
printf("Flash sector size: %010#x\n", caps->sectorSize);
printf("Erased word: %010#x\n", caps->erasedWord);
printf("Number of sup. instances: %d\n", caps->numSupportedInstances);
printf("Number of used instances: %d\n", caps->numCurrentInstances);
}
}
else if(!strncmp(ins, "quit", 4))
{
done = True;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -