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

📄 tpc.c

📁 索尼记忆棒的示例源码。采自日文期刊Interface的附属光盘。
💻 C
字号:
//---------------------------------------------------------------------
//  関数名:	HALF get_int                                         
//  引値  :	BYTE *reg    	[OUT]IntRegister値                   
//  返値  :	正常終了=	0                                          
//        	エラー時=	SYSTEM_ERROR		予想外のエラー             
//                     	PROTOCOL_ERROR	Retry失敗/不可能          
//---------------------------------------------------------------------

HALF get_int(BYTE *reg)
{
	BYTE	stat;
    	short	i;

    	i = PROTOCOL_RETRY;
    	while(1) {
		stat = read_protocol(TPC_GET_INT,1,reg,&protocol_status);
		if (stat != 0) {
			return(SYSTEM_ERROR);
		} else if ((protocol_status & (PROTOCOL_STAT_TOE|PROTOCOL_STAT_CRC)) == 0) {
	    		return(0);
		}

		/* TOE,CRC -> Retry */
		if (--i <= 0) {
		    	return(PROTOCOL_ERROR);
		}
    	}
}


//---------------------------------------------------------------------
//  関数名:	HALF write_reg                                        
//  引数  :	BYTE *data   		[IN]データバッファ先頭アドレス                    
//  返値  :	正常終了 =	0                                            
//         	エラー時 =	SYSTEM_ERROR		予想外のエラー               
//                   	PROTOCOL_ERROR 	Retry失敗/不可能            
//---------------------------------------------------------------------
HALF write_reg(BYTE *data)
{	
    	short	i;

    	i = PROTOCOL_RETRY;
   	while(1) {
    		stat = write_protocol(TPC_WRITE_REG,MSREG_WRITE_SIZE,data,&protocol_status);
		if (stat != 0) {
			return(SYSTEM_ERROR);
		} else if ((protocol_status & PROTOCOL_STAT_TOE) == 0) {
 		    	return(0);
		}

		/* TOE -> Retry */
    		if (--i <= 0) {
	    		return(PROTOCOL_ERROR);
		}
    	}
}


//---------------------------------------------------------------------
//  関数名:	HALF read_reg                                         
//  引数  :	BYTE *data	[OUT]データバッファ先頭アドレス
//  返値  :	正常終了 =	0                                            
//        	エラー時 =	SYSTEM_ERROR     予想外のエラー               
//                    	PROTOCOL_ERROR   Retry失敗/不可能            
//---------------------------------------------------------------------
HALF read_reg(BYTE *data)
{
    	short	i;

    	i = PROTOCOL_RETRY;
    	while(1) {
    		stat = read_protocol(TPC_READ_REG,MSREG_READ_SIZE,data,&protocol_status);
		if (stat != 0) {
			return(SYSTEM_ERROR);
		} else if ((protocol_status & (PROTOCOL_STAT_TOE|PROTOCOL_STAT_CRC)) == 0) {
 	 	   	return(0);
		}
	
		/* TOE,CRC -> Retry */
   	 	if (--i <= 0) {
	    		return(PROTOCOL_ERROR);
		}
    	}
}


//---------------------------------------------------------------------
//  関数名:	HALF set_cmd                                         
//  引数  :	BYTE command  	[IN]コマンド値                                  
//  返値  :	正常終了 =	0                                      
//         	エラー時 =	SYSTEM_ERROR  	予想外のエラー     
//                     	PROTOCOL_ERROR	Retry失敗/不可能   
//---------------------------------------------------------------------
HALF set_cmd(BYTE cmd)
{
    	short	i;

    	i = PROTOCOL_RETRY;
    	while(1) {
    		stat = write_protocol(TPC_SET_CMD,1,&cmd,&protocol_status);
		if (stat != 0) {
			return(SYSTEM_ERROR);
		} else if ((protocol_status & PROTOCOL_STAT_TOE) == 0) {
 	   		return(0);
		}

    		/* TOE -> Retry */
    		if (--i <= 0) {
			return(PROTOCOL_ERROR);
    		}
    	}
}


//---------------------------------------------------------------------
//  関数名:	HALF read_page_data                                  
//  引数  :	BYTE  *data	[OUT]データバッファ先頭アドレス
//  返値  :	正常終了=	0                                           
//        	エラー時=	SYSTEM_ERROR		予想外のエラー              
//                   	PROTOCOL_ERROR	Retry失敗/不可能           
//---------------------------------------------------------------------
HALF read_page_data(BYTE *data)
{
    	short	i;

    	i = PROTOCOL_RETRY;
    	while(1) {
    		stat = read_protocol(TPC_READ_PAGE_DATA,PAGE_SIZE,data,&protocol_status);
		if (stat != 0) {
			return(SYSTEM_ERROR);
		} else if ((protocol_status & (PROTOCOL_STAT_TOE|PROTOCOL_STAT_CRC)) == 0) {
		    	return(0);
		} else if (protocol_status & PROTOCOL_STAT_CRC) {
			return(PROTOCOL_ERROR); 
		}

    		/* TOE -> Retry */
    		if (--i <= 0) {
	    		return(PROTOCOL_ERROR);
		}
    	}
}


//---------------------------------------------------------------------
//  関数名:	HALF write_page_data                                   
//  引数  :	BYTE  *data		[IN]データバッファ先頭アドレス
//  返値  :	正常終了 =	0                                        
//         	エラー時 =	SYSTEM_ERROR		予想外のエラー       
//                   	PROTOCOL_ERROR	Retry失敗/不可能     
//---------------------------------------------------------------------
HALF write_page_data(BYTE *data)
{
    	short	i;

    	i = PROTOCOL_RETRY;
    	while(1) {
    		stat = write_protocol(TPC_WRITE_PAGE_DATA,PAGE_SIZE,data,&protocol_status);
		if (stat != 0) {
			return(SYSTEM_ERROR);
		} else if ((protocol_status & PROTOCOL_STAT_TOE) == 0) {
		    	return(0);
		}

    		/* TOE -> Retry */
    		if (--i <= 0) {
			return(PROTOCOL_ERROR);
		}
    	}
}


⌨️ 快捷键说明

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