📄 lowlevel.c
字号:
/******************************************************************************/
/* */
/* Copyright (C), 1995-2006, msystems Ltd. All rights reserved. */
/* */
/* Redistribution and use in source and binary forms, with or without */
/* modification, are permitted provided that the following conditions are */
/* met: */
/* 1. Redistributions of source code must retain the above copyright notice, */
/* this list of conditions and the following disclaimer. */
/* 2. Redistributions in binary form must reproduce the above copyright */
/* notice, this list of conditions and the following disclaimer in the */
/* documentation and/or other materials provided with the distribution. */
/* 3. Neither the name of msystems nor the names of its contributors may be */
/* used to endorse or promote products derived from this software without */
/* specific prior written permission. */
/* */
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
/* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED */
/* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR */
/* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
/* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
/* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR */
/* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
/* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
/* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
/* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
/* */
/******************************************************************************/
/*
* $Log: V:/PVCSDB/DiskOnChip/archives/version 6.3-up/TrueFFS/examples/lowlevel/lowlevel.c-arc $
*
* Rev 1.9 Sep 11 2006 13:42:40 yaniv.iarovici
* Legal Header added
*
* Rev 1.8 Aug 16 2006 09:02:04 Yaniv.Iarovici
* Support DRQ>1
*
* Rev 1.7 Aug 09 2006 17:48:40 Polina.Marimont
* intial for DOC Driver 1.0
*/
#include <windows.h>
#include <stdio.h>
#include "blockdev.h"
#ifndef PRINTF
#define PRINTF printf
#endif /* PRINTF */
/* --------------------------------------------------------------------------- */
#define IOSIZE 32
#define DRQ_SIZE 1
FLByte GLOBAL_BUFF[IOSIZE << FL_SECTOR_SIZE_BITS /* x512 */];
IOreq ioreq;
/**********************/
/* Function prototype */
/**********************/
IOreq*SetIoreq(FLHandle irHandle,FLDword irFlags,
void FAR1*irData,FLDword irLength,FLDword irCount);
FLStatus myProgressCallBack(FLWord a,FLWord b);
FLStatus FlashFormatMedia(void);
FLStatus WriteSectors(FLDword sectorNo, FLDword length);
FLStatus ReadSectors(FLDword sectorNo, FLDword length);
/********************/
/**** ****/
/**** Main ****/
/**** ****/
/********************/
int main(int argc, char * argv[])
{
FLDword fillSectors, sectorNo;
FLStatus status;
FLDword prevValue;
/*********************************/
/* Format the media before start */
/*********************************/
#ifdef FL_FORMAT_VOLUME
status = FlashFormatMedia();
if(status != flOK)
{
PRINTF("Failed (flash) formating the DiskOnChip device with status of %d\r\n",status);
return status;
}
#endif /* FL_FORMAT_VOLUME */
PRINTF("\r\nSet Data Transfer Mode to DRQ=%d\r\n", DRQ_SIZE);
flSetEnvAll(FL_SET_TRANSFER_MODE, DRQ_SIZE, &prevValue);
/********************************************/
/* Mount the media for block device access */
/********************************************/
PRINTF("\r\nMounting media for absolute read & write operations\r\n");
status = flAbsMountVolume(SetIoreq(0,0,NULL,0,0));
if(status != flOK)
{
PRINTF("Failed mounting the DiskOnChip device with status of %d\r\n",status);
return status;
}
/* Get the number of available sectors on the partition */
status = flSectorsInVolume(SetIoreq(0,0,NULL,0,0));
if(status != flOK)
{
PRINTF("Failed getting the number of sectors on the media with status of %d\r\n",status);
return status;
}
fillSectors = ioreq.irLength;
/*****************/
/* Write sectors */
/*****************/
/* Prepare buffers */
memset(GLOBAL_BUFF,0,sizeof(GLOBAL_BUFF));
SetIoreq(0,0,GLOBAL_BUFF,0, IOSIZE );
PRINTF("\r\nBDTL writing %lu sectors (using %u sector per write operation)\r\n", fillSectors, IOSIZE);
for(sectorNo = 0; sectorNo < fillSectors; sectorNo += IOSIZE)
{
PRINTF("Write %lu sectors starting on sector %lu out of %lu\r",(FLDword)IOSIZE,sectorNo,fillSectors);
/* Store sector number in the buffer */
GLOBAL_BUFF[0] = (FLByte)(sectorNo & 0xff);
GLOBAL_BUFF[1] = (FLByte)((sectorNo>>8) & 0xff);
GLOBAL_BUFF[2] = (FLByte)((sectorNo>>16) & 0xff);
GLOBAL_BUFF[3] = (FLByte)((sectorNo>>24) & 0xff);
/* Actual write the data */
status = WriteSectors(sectorNo, min(IOSIZE,fillSectors-sectorNo));
if(status != flOK)
{
PRINTF("\r\nFailed writing to the DiskOnChip device with status of %d\r\n",status);
return status;
}
}
PRINTF("\r\n\nWrite success!!!\r\n\n");
/****************/
/* Read sectors */
/****************/
/* Prepare buffers */
memset(GLOBAL_BUFF,0,sizeof(GLOBAL_BUFF));
SetIoreq(0,0,GLOBAL_BUFF,0, IOSIZE );
for(sectorNo = 0; sectorNo < fillSectors; sectorNo += IOSIZE)
{
PRINTF("Read %lu sectors starting on sector %lu out of %lu\r",(FLDword)IOSIZE,sectorNo,fillSectors);
/* Actual write the data */
status = ReadSectors(sectorNo, min(IOSIZE,fillSectors-sectorNo));
if(status != flOK)
{
PRINTF("\r\nFailed writing to the DiskOnChip device with status of %d\r\n",status);
return status;
}
/* Compare data to the expected pattern - only first 4 bytes */
if( (GLOBAL_BUFF[0] != (FLByte)(sectorNo & 0xff)) ||
(GLOBAL_BUFF[1] != (FLByte)((sectorNo>>8) & 0xff)) ||
(GLOBAL_BUFF[2] != (FLByte)((sectorNo>>16) & 0xff)) ||
(GLOBAL_BUFF[3] != (FLByte)((sectorNo>>24) & 0xff)) )
{
PRINTF("\r\nData read is not the correct data\r\n");
return flGeneralFailure;
}
}
PRINTF("\r\n\nRead success!!!\r\n");
/* ----------------------------------------------------------- */
flDismountVolume(SetIoreq(0,0,NULL,0,0));
#ifdef FL_EXIT
flExit();
#endif /* FL_EXIT */
PRINTF("\r\nTest Successfull\r\n");
return flOK;
}
/*************************************/
/**** ****/
/**** Routines Used by Main ****/
/**** ****/
/*************************************/
/* --------------------------------------------------------------------------- */
/* Initialize TrueFFS IO request structure */
/* --------------------------------------------------------------------------- */
IOreq*SetIoreq(FLHandle irHandle,FLDword irFlags,void FAR1*irData,FLDword irLength,FLDword irCount)
{
ioreq.irHandle = irHandle;
ioreq.irFlags = irFlags;
ioreq.irData = irData;
ioreq.irLength = irLength;
ioreq.irCount = irCount;
return &ioreq;
}
#ifdef FL_FORMAT_VOLUME
/* --------------------------------------------------------------------- */
/* Progress call back routine for the format routine */
/* --------------------------------------------------------------------- */
FLStatus myProgressCallBack(FLWord a,FLWord b)
{
PRINTF("Total = %d Current= %d\r", a, b);
return flOK ;
}
/* --------------------------------------------------------------------------- */
/* Call TrueFFS flash format routine */
/* --------------------------------------------------------------------------- */
FLStatus FlashFormatMedia(void)
{
FLStatus status;
FormatParams3 formatParams = STD_FORMAT_PARAMS3;
BDTLPartitionFormatParams3 bdtlPartitionFormatParams = STD_BDTL_PARAMS3;
PRINTF("\r\nFormatting Media (flash format) \r\n");
formatParams.BDTLPartitionInfo = &bdtlPartitionFormatParams;
formatParams.progressCallback = myProgressCallBack;
status = flFlashFormat(SetIoreq(0,TL_NORMAL_FORMAT,&formatParams,0,0));
PRINTF("\n\r");
return status;
}
#endif /* FL_FORMAT_VOLUME */
/* --------------------------------------------------------------------------- */
/* Call TrueFFS sector write routine */
/* --------------------------------------------------------------------------- */
FLStatus WriteSectors(FLDword sectorNo, FLDword length)
{
/**************************************/
/* Fill the TrueFFS IO request packet */
/**************************************/
ioreq.irData = ioreq.irData; /* User buffer */
ioreq.irHandle = 0; /* Partition number */
ioreq.irFlags = 0; /* RFU 0 */
ioreq.irSectorNo = sectorNo; /* Start sector */
ioreq.irSectorCount = length; /* Number of sectors */
/* Or simply => SetIoreq(0,0,ioreq.irData,sectorNo,length) */
/****************/
/* Call TrueFFS */
/****************/
return flAbsWrite(&ioreq);
}
/* --------------------------------------------------------------------------- */
/* Call TrueFFS sector read routine */
/* --------------------------------------------------------------------------- */
FLStatus ReadSectors(FLDword sectorNo, FLDword length)
{
/**************************************/
/* Fill the TrueFFS IO request packet */
/**************************************/
ioreq.irData = ioreq.irData; /* User buffer */
ioreq.irHandle = 0; /* Partition number */
ioreq.irFlags = 0; /* RFU 0 */
ioreq.irSectorNo = sectorNo; /* Start sector */
ioreq.irSectorCount = length; /* Number of sectors */
/* Or simply => SetIoreq(0,0,ioreq.irData,sectorNo,length) */
/****************/
/* Call TrueFFS */
/****************/
return flAbsRead(&ioreq);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -