📄 prgmacro.c
字号:
#ifndef _PRGMACRO_C_
#define _PRGMACRO_C_
/****************************************************************************
*
* Copyright (c) 2005 by HCC Embedded
*
* This software is copyrighted by and is the sole property of
* HCC. All rights, title, ownership, or other interests
* in the software remain the property of HCC. This
* software may only be used in accordance with the corresponding
* license agreement. Any unauthorized use, duplication, transmission,
* distribution, or disclosure of this software is expressly forbidden.
*
* This Copyright notice may not be removed or modified without prior
* written consent of HCC.
*
* HCC reserves the right to modify this software without notice.
*
* HCC Embedded
* Budapest 1132
* Victor Hugo Utca 11-15
* Hungary
*
* Tel: +36 (1) 450 1302
* Fax: +36 (1) 450 1303
* http: www.hcc-embedded.com
* email: info@hcc-embedded.com
*
***************************************************************************/
#include "mlayer.h"
#include "llayer.h"
#include "prgmacro.h"
#include "mdebug.h"
extern void prg_winshow(void);
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/****************************************************************************
*
* static variables
*
***************************************************************************/
static long *gl_prg;
static long gl_state;
static long gl_pc;
static unsigned long gl_counters[CNT_MAX];
/****************************************************************************
*
* cnt_resets
*
* resetting all the counters
*
***************************************************************************/
void cnt_resets() {
unsigned char a;
for (a=0; a<CNT_MAX; a++) gl_counters[a]=0;
}
/****************************************************************************
*
* cnt_increase
*
* increasing a counter value
*
* INPUTS
*
* counter - which counter need to be increased (CNT_xxx)
*
***************************************************************************/
void cnt_increase(unsigned char counter) {
if (counter<CNT_MAX) gl_counters[counter]++;
if (counter==CNT_ERROR) {
counter=CNT_ERROR;
}
}
/****************************************************************************
*
* cnt_getvalue
*
* getting a counter current value
*
* INPUTS
*
* counter - which counter value is needed (CNT_xxx)
*
* RETURNS
*
* returns with the counter value
*
***************************************************************************/
unsigned long cnt_getvalue(unsigned char counter) {
if (counter<CNT_MAX) return gl_counters[counter];
return 0;
}
enum {
CHECK_LEN = 2
};
unsigned long sectorrand[MAX_SECTOR*MLAYER_SETS];
/****************************************************************************
debug code to check page data content ...
****************************************************************************/
//static long filtest_page_data_value = 0;
unsigned char prg_buffer [MAX_DATA_SIZE];
#define CHECK_LEN 2
void prg_set_content(long sector) {
long *lptr = (long *) prg_buffer;
unsigned long r=rand();
r<<=16;
r+=rand();
lptr[0] = sector;
lptr[1] = r;
sectorrand[sector]=r;
}
int prg_check_content(unsigned long sector) {
unsigned long *lptr = (unsigned long *) prg_buffer;
if (sector != lptr[0] || sectorrand[sector]!=lptr[1]) {
cnt_increase(CNT_ERROR);
// printf("error at page %l: exp %lx got %lx offset %lx\n", sector, sector, lptr[0], lptr[1]);
return 1;
}
return 0; //ok
}
/****************************************************************************
*
* prg_srand
*
* reinitialize the random number generator
*
***************************************************************************/
static void prg_srand(void) {
srand(0); //040611_nicola
}
/****************************************************************************
*
* prg_readsector
*
* read a simple sector n times
*
* INPUTS
*
* sector - which sector is requested
* times - number of writing
*
***************************************************************************/
static void prg_readsector(long sector,long times) {
while (times--) {
if (ml_open(sector, 1,ML_READ)) cnt_increase(CNT_ERROR);
if (ml_read(prg_buffer)) cnt_increase(CNT_ERROR);
if (ml_close()) cnt_increase(CNT_ERROR);
prg_check_content(sector);
}
}
/****************************************************************************
*
* prg_readlinear
*
* reading a range of sectors n times linearly
*
* INPUTS
*
* startsector - 1st sector in range
* endsector - last sector (this sector won't be written!)
* times - number of cycles
*
***************************************************************************/
static void prg_readlinear(long startsector,long endsector,long times) {
long sector;
while (times--) {
for (sector=startsector; sector<endsector; sector++) {
if (ml_open(sector, 1 ,ML_READ)) cnt_increase(CNT_ERROR);
if (ml_read(prg_buffer)) cnt_increase(CNT_ERROR);
if (ml_close()) cnt_increase(CNT_ERROR);
prg_check_content(sector);
}
}
}
/****************************************************************************
*
* prg_readbatch
*
* reading a range of sectors n times linearly, with 1 open
*
* INPUTS
*
* startsector - 1st sector in range
* numsector - number of sectors
* times - number of cycles
*
***************************************************************************/
static void prg_readbatch(long startsector,long numsector,long times) {
long sector;
while (times--) {
if (ml_open(startsector,numsector,ML_READ)) cnt_increase(CNT_ERROR);
for (sector=0; sector<numsector; sector++) {
if(ml_read(prg_buffer)) cnt_increase(CNT_ERROR);
prg_check_content(sector+startsector);
}
if (ml_close()) cnt_increase(CNT_ERROR);
}
}
/****************************************************************************
*
* prg_readrandom
*
* writing a range of sectors n times randomly
*
* INPUTS
*
* startsector - 1st sector in range
* endsector - last sector (this sector won't be written!)
* times - number of cycles
*
***************************************************************************/
static void prg_readrandom(long startsector,long endsector,long times) {
long range=endsector-startsector;
while (times--) {
unsigned long r=rand();
r<<=16;
r+=rand();
r%=range;
if (ml_open(r+startsector, 1,ML_READ)) cnt_increase(CNT_ERROR);
if (ml_read(prg_buffer)) cnt_increase(CNT_ERROR);
if (ml_close()) cnt_increase(CNT_ERROR);
prg_check_content(r+startsector);
}
}
/****************************************************************************
*
* prg_writesector
*
* writing a simple sector n times
*
* INPUTS
*
* sector - which sector is requested
* times - number of writing
*
***************************************************************************/
static void prg_writesector(long sector,long times) {
while (times--) {
if (ml_open(sector, 1,ML_WRITE)) cnt_increase(CNT_ERROR);
prg_set_content(sector);
if (ml_write(prg_buffer)) cnt_increase(CNT_ERROR);
if (ml_close()) cnt_increase(CNT_ERROR);
}
}
/****************************************************************************
*
* prg_writelinear
*
* writing a range of sectors n times linearly
*
* INPUTS
*
* startsector - 1st sector in range
* endsector - last sector (this sector won't be written!)
* times - number of cycles
*
***************************************************************************/
static void prg_writelinear(long startsector,long endsector,long times) {
long sector;
while (times--) {
for (sector=startsector; sector<endsector; sector++) {
if (ml_open(sector,1,ML_WRITE)) cnt_increase(CNT_ERROR);
prg_set_content(sector);
if (ml_write(prg_buffer)) cnt_increase(CNT_ERROR);
if (ml_close()) cnt_increase(CNT_ERROR);
}
}
}
/****************************************************************************
*
* prg_writebatch
*
* writing a range of sectors n times linearly with 1 open
*
* INPUTS
*
* startsector - 1st sector in range
* numsector - number of sectors
* times - number of cycles
*
***************************************************************************/
static void prg_writebatch(long startsector,long numsector,long times) {
long sector;
while (times--) {
if (ml_open(startsector, numsector,ML_WRITE)) cnt_increase(CNT_ERROR);
for (sector=0; sector<numsector; sector++) {
prg_set_content(sector+startsector);
if (ml_write(prg_buffer)) cnt_increase(CNT_ERROR);
}
if (ml_close()) cnt_increase(CNT_ERROR);
}
}
/****************************************************************************
*
* prg_writerandom
*
* writing a range of sectors n times randomly
*
* INPUTS
*
* startsector - 1st sector in range
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -