⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 function.c

📁 本电子词典是名人928的学习机代码,主要是电子学习机AP,其他还没有传
💻 C
📖 第 1 页 / 共 2 页
字号:

#define __OS_SOURCE_FILE__

#ifndef _WIN32

#include "Kernel.h"
#include "SCL.h"
#include "RbcCmd.h"
#include "HAL.h"

#define SWAP2(x)   ((((x) & 0xFF) << 8) | (((x) >> 8) & 0xFF))

#ifdef C33
	unsigned SWAP4(unsigned x) // should use the "swap" instructure.
	{
		return x;
	}
#else
	#define SWAP4(x)   ((((x) & 0xFF) << 24) | ((((x) >> 8) & 0xFF) << 16) \
				   | ((((x) >> 16) & 0xFF)<< 8)| (((x) >> 24) & 0xFF))
#endif 

const STD_INQUIRYDATA InquiryData =
{
    0x00,	// SBC_DEVICE, :5
    0,		//INT8 Reserved0 : 3;
	
    0,		//INT8 Reserved1 : 7;
    0,		//INT8 RemovableMedia : 1;

    0,		//INT8 Reserved2;

    0,		//INT8 Reserved3 : 5;
    0,		//INT8 NormACA : 1;
    0,		//INT8 Obsolete0 : 1;
    0,		//INT8 AERC : 1;

    //INT8 Reserved4[3];
    0x20,
    0,
    0,
    
    0,		//INT8 SoftReset : 1;
    0,		//INT8 CommandQueue : 1;
	0,		//INT8 Reserved5 : 1;
	0,		//INT8 LinkedCommands : 1;
	0,		//INT8 Synchronous : 1;
	0,		//INT8 Wide16Bit : 1;
	0,		//INT8 Wide32Bit : 1;
	0,		//INT8 RelativeAddressing : 1;

    //INT8 VendorId[8];
    {
        'M', 'E', 'I', 'J',
        'I', 'N', ' ', ' '
    },

	//INT8 ProductId[16];
    {
        ' ',' ',' ',' ',
    	' ',' ',' ',' ',
    	' ',' ',' ',' ',
    	' ',' ',' ',' '
    },

	//INT8 ProductRevisionLevel[4];
    {
        '0','.','0','0'
    }
};

//const REQUEST_SENSE_DATA   Req_SenseData=
REQUEST_SENSE_DATA   Req_SenseData;
/*
{

     0x70,		// INT8 ResponseCode : 7;
	 1,			// INT8 Valid : 1;

	 0,			// INT8 SegmentNum;

	 0x0,		// INT8 SenseKey : 4; 5= illegal request
	 0,			// INT8 Reserved0 : 1;
	 0,			// INT8 WrongLenIndicator : 1;
	 0,			// INT8 EndofMedium : 1;
	 0,			// INT8 FileMark : 1;

	 0,			// INT8 Info_0;
	 0,			// INT8 Info_1;
	 0,			// INT8 Info_2;
	 0,			// INT8 Info_3;

	0x0b,		// INT8 AdditionalSenseLen;

	0,			// INT8 CommandSpecInfo_0;
	0,			// INT8 CommandSpecInfo_1;
	0,			// INT8 CommandSpecInfo_2;
	0,			// INT8 CommandSpecInfo_3;

	0x28,		// INT8 ASC;
	0,			// INT8 ASCQ;
	0,			// INT8 FieldReplacableUnitCode;
	0,			// INT8 SenseKeySpec_0 : 7;
	0,			// INT8 SenseKeySpecValid : 1;
	0,			// INT8 SenseKeySpec_1;
	0			// INT8 SenseKeySpec_2;
};
*/
const BYTE UnknownCommand[] = {0x00, 0x00, 0x00, 0x10, 0x00, 0x01, 0xf4, 0x00, 0x02, 0x00, 
0x02, 0x00, 0x00, 0x01, 0xf4, 0x00, 0x00, 0x00, 0x02, 0x00};
/*const BYTE UnknownCommand[] = 
{
0xff,0xff,0xee,0xff,0xff,0xff,0xee,0xff,0xff,0xff,0xee,0xff,0xff,0xff,0xee,0xff,
0xff,0xff,0xee,0xff,0xff,0xff,0xee,0xff,0xff,0xff,0xee,0xff,0xff,0xff,0xee,0xff,
0xff,0xff,0xee,0xff,0xff,0xff,0xee,0xff,0xff,0xff,0xee,0xff,0xff,0xff,0xee,0xff,
0xff,0xff,0xee,0xff,0xff,0xff,0xee,0xff,0xff,0xff,0xee,0xff,0xff,0xff,0xee,0xff,
0xd9,0xd9,0xdf,0xd9,0xd9,0xd9,0xdf,0xd9,0xd9,0xd9,0xdf,0xd9,0xd9,0xd9,0xdf,0xd9,
0xd9,0xd9,0xdf,0xd9,0xd9,0xd9,0xdf,0xd9,0xd9,0xd9,0xdf,0xd9,0xd9,0xd9,0xdf,0xd9,
0xd9,0xd9,0xdf,0xd9,0xd9,0xd9,0xdf,0xd9,0xd9,0xd9,0xdf,0xd9,0xd9,0xd9,0xdf,0xd9,
0xd9,0xd9,0xdf,0xd9,0xd9,0xd9,0xdf,0xd9,0xd9,0xd9,0xdf,0xd9,0xd9,0xd9,0xdf,0xd9,
0xff,0xff,0xee,0xff,0xff,0xff,0xee,0xff,0xff,0xff,0xee,0xff,0xff,0xff,0xee,0xff,
0xff,0xff,0xee,0xff,0xff,0xff,0xee,0xff,0xff,0xff,0xee,0xff,0xff,0xff,0xee,0xff,
0xff,0xff,0xee,0xff,0xff,0xff,0xee,0xff,0xff,0xff,0xee,0xff,0xff,0xff,0xee,0xff,
0xff,0xff,0xee,0xff,0xff,0xff,0xee,0xff,0xff,0xff,0xee,0xff,0xff,0xff,0xee,0xff,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};*/
//BYTE ModeSenseData[] = {0x03, 0x00, 0x80, 0x00};
const BYTE ModeSenseData[] = {0x3a, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0xfa, 0x00, 0x00, 0x00, 
0x00, 0x02, 0x00, 0x01, 0x0a, 0x80, 0x10, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 
0x05, 0x1e, 0x0f, 0xa0, 0x08, 0x20, 0x02, 0x00, 0x01, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00};
// INQUIRY command

extern UINT32 g_BufferSize;


MS_STATUS cmd_iqChkCmd(void)
{
//	NU_Printf("INQUIRY - Check command\n\r");
	return GOOD;
}

MS_STATUS cmd_iqBuildResponse(void)
{
#ifdef	SYS_UPDATE
//	const static char ret[]={0x00,0x80,0x00,0x00,0x20,0x00,0x00,0x00,0x47,0x65,0x6e,0x65,0x73,0x79,
//		0x73,0x20,0x53,0x54,0x4f,0x52,0x41,0x47,0x45,0x20,
//		0x44,0x45,0x56,0x49,0x43,0x45,0x20,0x20,0x30,0x31};
	BOL_BulkIn(sizeof(InquiryData), (UINT8*)InquiryData);
	*g_pdwResidue = g_dwXansfer - sizeof(ret);
#else
	BOL_BulkIn(sizeof(InquiryData), (BYTE *)&InquiryData);
	*g_pdwResidue = g_dwXansfer - sizeof(InquiryData);
#endif
        Req_SenseData.SenseKey = 0;
        Req_SenseData.ASC = 0;
        Req_SenseData.ASCQ = 0;
	return GOOD;
}

MS_STATUS cmd_readChkCmd(void)
{
	//NU_Printf("READ - Check command\n\r");
	return GOOD;
}

const static UINT8 tmpBuf[] = {
	0xEB,0x3C,0x90,0x4D,0x53,0x44,0x4F,0x53,0x35,0x2E,0x30,0x00,0x02,0x01,0x08,0x00,
	0x02,0x00,0x02,0x18,0x06,0xF8,0xF8,0x00,0x3F,0x00,0xFF,0x00,0x23,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x29,0xE9,0xCA,0x65,0x60,0x4E,0x4F,0x20,0x4E,0x41,
	0x4D,0x45,0x20,0x20,0x20,0x20,0x46,0x41,0x54,0x31,0x36,0x20,0x20,0x20,0x33,0xC9,
	0x8E,0xD1,0xBC,0xF0,0x7B,0x8E,0xD9,0xB8,0x00,0x20,0x8E,0xC0,0xFC,0xBD,0x00,0x7C,
	0x38,0x4E,0x24,0x7D,0x24,0x8B,0xC1,0x99,0xE8,0x3C,0x01,0x72,0x1C,0x83,0xEB,0x3A,
	0x66,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,0x0F,0xB6,0xC8,
	0x4A,0x4A,0x8A,0x46,0x0D,0x32,0xE4,0xF7,0xE2,0x03,0x46,0xFC,0x13,0x56,0xFE,0xEB,
	0x4A,0x52,0x50,0x06,0x53,0x6A,0x01,0x6A,0x10,0x91,0x8B,0x46,0x18,0x96,0x92,0x33,
	0xD2,0xF7,0xF6,0x91,0xF7,0xF6,0x42,0x87,0xCA,0xF7,0x76,0x1A,0x8A,0xF2,0x8A,0xE8,
	0xC0,0xCC,0x02,0x0A,0xCC,0xB8,0x01,0x02,0x80,0x7E,0x02,0x0E,0x75,0x04,0xB4,0x42,
	0x8B,0xF4,0x8A,0x56,0x24,0xCD,0x13,0x61,0x61,0x72,0x0B,0x40,0x75,0x01,0x42,0x03,
	0x5E,0x0B,0x49,0x75,0x06,0xF8,0xC3,0x41,0xBB,0x00,0x00,0x60,0x66,0x6A,0x00,0xEB,
	0xB0,0x4E,0x54,0x4C,0x44,0x52,0x20,0x20,0x20,0x20,0x20,0x20,0x0D,0x0A,0x4E,0x54,
	0x4C,0x44,0x52,0x20,0x69,0x73,0x20,0x6D,0x69,0x73,0x73,0x69,0x6E,0x67,0xFF,0x0D,
	0x0A,0x44,0x69,0x73,0x6B,0x20,0x65,0x72,0x72,0x6F,0x72,0xFF,0x0D,0x0A,0x50,0x72,
	0x65,0x73,0x73,0x20,0x61,0x6E,0x79,0x20,0x6B,0x65,0x79,0x20,0x74,0x6F,0x20,0x72,
	0x65,0x73,0x74,0x61,0x72,0x74,0x0D,0x0A,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xAC,0xBF,0xCC,0x55,0xAA,
};

#define SECTOR_SUM(disksize)	(disksize/0x200+0x218)

MS_STATUS cmd_readBuildResponse(void)
{
//	READ10_CMD ReadCmd;
	UINT32 dwBlock, dwCount;	//, LBA_Addr;
	UINT16 wBlocks, i, BlockLen, wOffset;
	MFlashInfo FlashInfo;
	
//	ReadCmd.dwLBA = READ_DWORD(g_pCDB + 2);
//	ReadCmd.wBlockNum = READ_WORD(g_pCDB + 7);
#ifdef  SYS_UPDATE
	UINT16	tmpIndex;
	dwBlock = SWAP4(READ_DWORD(g_pCDB + 2));
	wBlocks = SWAP2(READ_DWORD(g_pCDB + 7));

	wOffset = (UINT16)( g_BufferSize / 512);

	for (i=0; i<wBlocks; i += wOffset)
	{
		UINT32 unReadBlockNum;
		UINT32 dwSend;
	
		unReadBlockNum = wBlocks - i;
		if(unReadBlockNum > wOffset)
			unReadBlockNum = wOffset;
		if(0 == dwBlock)	
		{
#ifdef _BOARD
            UINT16 uSize = SECTOR_SUM(0xE0000);
#endif
#ifdef  __ED106__
            UINT16 uSize = SECTOR_SUM(0xF0000);
#endif
			
			memcpy(g_pData, tmpBuf, sizeof(tmpBuf));
			g_pData[0x13] = uSize & 0xFF;
			g_pData[0x14] = (uSize >> 8) & 0xFF;
			dwCount = unReadBlockNum * 512;
		}
		if(0 != dwBlock)
		{
			memset(g_pData,0,1024);
			dwCount = unReadBlockNum * 512;
		}
	
		dwSend = BOL_BulkIn(dwCount, g_pData);
		*g_pdwResidue -= dwSend;
		if (dwSend != dwCount)
		{
			return CHECK_CONDITION;
		}
	}
	
#else
	FlashIoCtrl(NULL, FLASH_COMMAND_GETINFO, &FlashInfo);	//取得块大小和块数
//	LBA_Addr = FlashInfo.uPageSum - 1;
	BlockLen = FlashInfo.uPageSize;
	
	*g_pdwResidue = g_dwXansfer;
	
	dwBlock = SWAP4(READ_DWORD(g_pCDB + 2));
	wBlocks = SWAP2(READ_DWORD(g_pCDB + 7));

	wOffset = g_BufferSize / BlockLen;
	
//	if (LBA_Addr < (dwBlock + wBlocks))
//		return CHECK_CONDITION;

//	if(wBlocks > BUFFER_SIZE / BlockLen)
//		wBlocks = BUFFER_SIZE / BlockLen;

	for (i=0; i < wBlocks; i += wOffset)
	{
		UINT16 unReadBlockNum;
		UINT32 dwSend;

		unReadBlockNum = wBlocks - i;
		if(unReadBlockNum > wOffset)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -