📄 image.c
字号:
#include <machine.h>
#include <string.h>
#include "flashdisk.h"
#include "genEcc.h"
#include "h8s2215.h"
#include "sci.h"
#define IMG_BLK_SIZE 2048
#define IMG_FILE_ID "_LCD_IMAGE"
#define IMG_ADDR_START_16M 50
#define BLOCK_SIZE 16384
#define LITTLE
#ifdef LITTLE
unsigned long GetLong( unsigned char *buf )
{
return ((unsigned long)(buf[0])|(((unsigned long)buf[1])<<8)|(((unsigned long)buf[2])<<16)|(((unsigned long)buf[3])<<24));
}
unsigned short GetShort( unsigned char *buf)
{
return ((unsigned short)(buf[0])|(((unsigned short)buf[1])<<8));
}
#else
unsigned long GetLong( unsigned char *buf )
{
return ((unsigned long)(buf[3])|(((unsigned long)buf[2])<<8)|(((unsigned long)buf[1])<<16)|(((unsigned long)buf[0])<<24));
}
unsigned short GetShort( unsigned char *buf)
{
return ((unsigned short)(buf[1])|(((unsigned short)buf[0])<<8));
}
#endif
extern unsigned char g_filecnt, g_FileID;
struct _disk_map
{
unsigned char disk_size;
//disk_size 16M:1, 32M:2, 64M:4, 128M:8, 256M:16, 512M:32, 1024M:64
//addr_img_blk 50 50 ...
//addr_param_blk 950 1950 ...
//addr_reserved 1000 2020 ...
unsigned long addr_img_blk;
unsigned long addr_param_blk;
unsigned long addr_reserved;
}map_disk;
extern FLASH_RW flash_rw;
extern DATA_BUFF Cache[];
unsigned long dwAddrImg;
unsigned long dwFileSize;
unsigned short* GetImgBuf( int ImgID );
int IsExistImgFile( int FileID, unsigned long *FileSize,unsigned short *wWidth, unsigned short *wHeight );
int init_img_disk();
// usage:
// 1. check the image file is exist
// 2. get the image buf
unsigned short* GetImgBuf( int ImgID )
{
int i;
#if 1
ChipSelect_F1 // chip select
// for( i =0; i<4; i++ )
{
// flash_rw.addr = dwAddrImg+ImgID*4+1+i;
flash_rw.addr = dwAddrImg+ImgID;
flash_rw.length = 512;
// flash_rw.buff_ptr = &Cache->data_buff[0+512*i];
flash_rw.buff_ptr = &Cache->data_buff[0];
fread_sector_no_ecc();
}
De_ChipSelect_F1
#endif
#if 0
ChipSelect_F1 // chip select
// for( i=0; i<4; i++ )
{
// flash_rw.addr = dwAddrImg+ImgID*4+1+i;
flash_rw.addr = dwAddrImg+ImgID;
flash_rw.length = 512;
// flash_rw.buff_ptr = &Cache->data_buff[0+512*i];
flash_rw.buff_ptr = &Cache->data_buff[0];
fread_data(0);
}
De_ChipSelect_F1
#endif
return (unsigned short*)&Cache->data_buff[0];
}
int IsExistImgFile( int FileID, unsigned long *FileSize ,unsigned short *wWidth, unsigned short *wHeight)
{
int i,j;
dwAddrImg = map_disk.addr_img_blk*32;//50*32
// dwAddrImg = dwAddrImg+FileID*((dwFileSize+512)/BLOCK_SIZE+1)*32;
dwAddrImg = dwAddrImg+FileID*32*5;
ChipSelect_F1 // chip select
for( i=0; i<5; i++ )
{
flash_rw.addr = dwAddrImg;
flash_rw.length = 22;
flash_rw.buff_ptr = &Cache->ReadCache.Buf[0];
fread_data(0);
if( !memcmp( &Cache->ReadCache.Buf[0], IMG_FILE_ID, 10 ) )
{
SCI_Str("\r\nDebug the data: ");
for( j =0 ; j<22; j++ )
{
SCI_HexB( Cache->ReadCache.Buf[j] );
SCI_Char(' ');
}
SCI_Str("\r\n");
*FileSize = GetLong( &Cache->ReadCache.Buf[10] );
*wWidth = GetShort( &Cache->ReadCache.Buf[14] );
*wHeight = GetShort( &Cache->ReadCache.Buf[18] );
break;
}
dwAddrImg += 32;
}
De_ChipSelect_F1
if( i == 6 )
{
SCI_Str("\r\nCan't find the image file ID = 0x=: ");
SCI_Hex( (unsigned long)FileID );
SCI_Str("\r\n");
return 1;
}
else
{
SCI_Str("\r\nFind the image file, File ID = 0x");
SCI_Hex((unsigned long)FileID);
SCI_Str("Addr = 0x");
SCI_Hex((unsigned long)dwAddrImg);
SCI_Str("FileSize = 0x");
SCI_Hex((unsigned long)*FileSize);
SCI_Str("wWidth = 0x");
SCI_HexS((unsigned short)*wWidth);
SCI_Str("Height = 0x");
SCI_HexS((unsigned short)*wHeight);
dwAddrImg++;
return 0;
}
}
int init_img_disk()
{
int i=1,j, ret=0;
map_disk.disk_size = 1;
map_disk.addr_img_blk = IMG_ADDR_START_16M;
map_disk.addr_param_blk = 950;
dwAddrImg = map_disk.addr_img_blk*32;
g_filecnt = 0;
ChipSelect_F1 // chip select
while( i<800 )
{
flash_rw.addr = dwAddrImg;
flash_rw.length = 22;
flash_rw.buff_ptr = &Cache->ReadCache.Buf[0];
fread_data(0);
Cache->ReadCache.Buf[10] = 0;
if( !memcmp( &Cache->ReadCache.Buf[0], IMG_FILE_ID, 10 ) )
{
if( g_filecnt == 0 )
map_disk.addr_img_blk = dwAddrImg/32;
dwFileSize = GetLong( &Cache->ReadCache.Buf[10] );
SCI_Str("\r\nFind the image : Address=0x");
SCI_Hex((unsigned long)dwAddrImg);
SCI_Str("\r\nThis image size: dwFileSize=0x");
SCI_Hex((unsigned long)dwFileSize);
SCI_Str("\r\nDebug the data: ");
for( j =0 ; j<22; j++ )
{
SCI_HexB( Cache->ReadCache.Buf[j] );
SCI_Char(' ');
}
SCI_Str("\r\n");
g_filecnt++;
}
dwAddrImg+=32;
i++;
}
SCI_Str("\r\nFind 0x ");
SCI_Hex((unsigned long)g_filecnt );
SCI_Str(" images\r\n");
SCI_Str("\r\nThe Image Size: dwFileSize=0x");
SCI_Hex((unsigned long)dwFileSize);
SCI_Str("\r\nDebug the data: ");
De_ChipSelect_F1
}
void debug_flash()
{
int i = 1, j;
ChipSelect_F1 // chip select
while( i )
{
flash_rw.addr = (unsigned long)i*32;
flash_rw.length = 22;
flash_rw.buff_ptr = &Cache->ReadCache.Buf[0];
fread_data(0);
SCI_Str("\r\nDebug the data: ");
for( j =0 ; j<22; j++ )
{
SCI_HexB( Cache->ReadCache.Buf[j] );
SCI_Char(' ');
}
SCI_Str("\r\n");
i++;
if( i>=1024 )
break;
}
De_ChipSelect_F1
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -