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

📄 cycle.h

📁 Utils and test SD card read write cycles
💻 H
字号:
#ifndef TEST56
#define TEST56
#pragma once

#include <stdio.h>
#include <conio.h>
#include <io.h>
//#include <sys/hyrtk.h>

//#include "sdlib.h"

#ifdef CARD
extern int bigendian;
#else
// int bigendian = 0;
#endif

#define WITH_ECC                 (1<<1)
#define BUFFER_LOAD_BIT          (1<<4)
#define DO_NOT_ERASE_BIT         (1<<5)
#define DO_NOT_PROGRAM_BIT       (1<<6)
#define DO_NOT_READ_BIT          (1<<7)
#define DO_NOT_VERIFY_BIT        (1<<8)
#define ALL_ERRORS_BIT           (1<<10)
#define HALT_ON_ERROR_BIT        (1<<22)
// (1<<9) reserved

#define WRITE_BACK_PTR(x,y)    x &= 0x0000ffffL, x |= (y)<<16

#define CMD_MASK  (1<<4)             /* data hy_d04  */
#define DAT_MASK   1
#define D_CRC_POLYN 0x1021

// #define BUFFER_INDEX(x)             ((x>>1) & 0x00000007)
// #define ERROR_COUNT_LIMIT(x)        ((x>>18) & 0x00000007)

#define BG_PATTERN      0xFA357C53
#define NUP_PATTERN_1   0x5500AAFF
#define NUP_PATTERN_2   0x005500AA
#define NUP_PATTERN_3   0xFF005500
#define NUP_PATTERN_4   0xAAFF0055
#define NUP_PATTERN_5   0x00AAFF00


typedef enum
{
    CMD_BYTE_LENGTH     = 6,
    MAX_CYC_ERRORS      = 64,
    SECTOR_SIZE_INT     = 128,
    SECTOR_SIZE         = 512,
    MAX_SECTOR_NO       = (1 << 17) - 1
} SIZE_T;


typedef enum
{
    CMD_13 = 13,
    CMD_56 = 56,
} STATUS_T;

#define UNKNOWN_ERROR_BIT        (1<<11)
#define WR_FAILURE_ERROR_BIT     (1<<12)
#define RD_FAILURE_ERROR_BIT     (1<<13)
#define DIFF_ERROR_BIT           (1<<14)
#define BAD_BLOCK_ERROR_BIT      (1<<15)
#define BAD_8_BLOCKS_ERROR_BIT   (1<<16)

typedef enum
{
    OK,
    CYC_ERROR_UNKNOWN               = 1<<0,
    CYC_ERROR_COMPARE               = 1<<1,
    CYC_ERROR_PROGRAM               = 1<<2,
    CYC_ERROR_ERASE                 = 1<<3,
    CYC_ERROR_READ                  = 1<<4,
    CYC_ERROR_BUFFERS_FULL          = 1<<5,
    CYC_ERROR_BUFFER_INDEX_EXCEED   = 1<<6,
    ERR
} STATUS_T;

typedef enum
{
    READ = 0,
    WRITE,
} BUFFER_DIR_T;

typedef enum
{
    STATUS_CMD  = 0x3,
    FLOW_CMD    = 0x4
} CMD_TYPE_T;


int cycBuffer_ref[SECTOR_SIZE_INT];
int cycBuffer_read[SECTOR_SIZE_INT];


typedef enum
{
    ERROR_STATUS    = 0x2,
    BB_STATUS       = 0X3,
    FLASH_INFO      = 0X5,
    SHORT_STATUS    = 0X10
} STATUS_SUB_T;

typedef enum
{
    PROGRAM_BG      = 0x20,
    CYCLE           = 0X21,
    RETEN_PRE       = 0X22,
    RD_AFTER_RETEN  = 0X23,
    TST_AFTER_RETEN = 0X24,
    ERASE_FW        = 0X7F
} FLOW_SUB_T;


typedef enum
{
    FLASH_DIA_0, 
    FLASH_DIA_1,
    FLASH_DIA_2,
    FLASH_DIA_3
} FLASH_DIA_T;

typedef union    
{
    unsigned int argument;
    struct
    {
        char cmdType     :8;
        char cmdSubType  :8;
    } cmd;
} ARG_T;

typedef struct
{   
    int failAddress;    // The address is offset by dia
    int failParam;      // dia 2bit Up to 4 dia in card
                        // errorType 6bit Error type
                        // opIdent  4bit Identical the operation mode
                        // Phasecounter 20bit an internal counter for each action
} ERROR_STATUS_T;
ERROR_STATUS_T ErrorStatus[MAX_CYC_ERRORS];
ERROR_STATUS_T BBStatus[MAX_CYC_ERRORS];
int phasecounter_m;

unsigned char CommandBuffer[6], response[6];
unsigned int NumberOfSectors;
#define SECTOR_BUFFER (unsigned char *) 0xC8000000

STATUS_T WaitUntillReady(int timeout);
unsigned int CRC16(int sector[], int length, int offset, int jump);
STATUS_T CycleTestRead(ARG_T arg, int *phasecounter);
STATUS_T CycleTestWrite(ARG_T arg, int *phasecounter);
STATUS_T createBG_buffer(int *sector);
STATUS_T createNUP_buffer(int *sector);
STATUS_T get_bitstrg(unsigned char cmd, unsigned long arg, unsigned char *bitstrg);
STATUS_T send_bitstrg(unsigned char *bitstrg);
unsigned char get_CRC7(unsigned char cmd_bytes[] );
STATUS_T WriteSector(unsigned int *Sector, int *SectorCRC, int SectorNumber);
unsigned int ReadSectorFromFlash(unsigned int LogSectorNumber, unsigned char *SectorBuffer);
unsigned int EraseBlockRom(unsigned int SectorNumber, unsigned int Flags);
STATUS_T ProgramBG(int *phasecounter);
STATUS_T createNUP_buffer(int *sector);
STATUS_T RternPre(int *phasecounter);
STATUS_T RDAfterReten(int *phasecounter);
STATUS_T TestAfterReten(int *phasecounter);
STATUS_T EraseFW(int *phasecounter);
STATUS_T get_response(ARG_T argument);
STATUS_T EraseBlocks(int statrtBlock, int NumberOfBlocks, int phasecounter);
STATUS_T Cycle25(int *phasecounter);
int send_sector (int sector[]);
STATUS_T RegisterCycError(unsigned int sectorNo, STATUS_T errorType, 
                               int opIdent, int phasecounter);
STATUS_T CheckSector(unsigned int *S1, unsigned int *S2);

#define	EraseBlock(SectorNumber) EraseBlockRom(SectorNumber,SkipErase)

#endif // TEST56

⌨️ 快捷键说明

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