?? hoststack.h
字號:
/****************************************Copyright (c)**************************************************
** Guangzou ZLG-MCU Development Co.,LTD.
** graduate school
** http://www.zlgmcu.com
**
**--------------File Info-------------------------------------------------------------------------------
** File Name: HostStack.h
** Last modified Date: 2005-12-15
** Last Version: V1.0
** Description:
**
**------------------------------------------------------------------------------------------------------
** Created By: Lishan Zhou
** Created date: 2005-12-15
** Version: V1.0
** Description:
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Description:
**
********************************************************************************************************/
#ifndef __HOST_STACK_H
#define __HOST_STACK_H
#ifdef __cplusplus
extern "C" {
#endif
#define find_mass_device(x) find_class_interface(0x08, x) // 查找大容量設備
__swi(0xaa) unsigned int SwiHandle(int, ...);
#define hMedLUN void
#define device_instance void // 設備描述信息結構指針
#define endpoint_info void // 端點描述信息結構指針
#define transfer_instance void // 傳輸描述符描述信息結構指針
/*********************************************************************************************************
** Function name: USB_Host_Serve
** Descriptions: USB主機服務任務,應用程序中創建一個任務調用該函數。
** Input: 無
** Output : 無
** Created by:
** Created Date:
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
__inline void USB_Host_Serve(void)
{
SwiHandle(0x10f);
}
/*********************************************************************************************************
** 注冊類驅動使用的宏
*********************************************************************************************************/
#define HUB_CLASS_DEVICE 0x09
#define AUDIO_CLASS_INTERFACE 0x01
#define HID_CLASS_INTERFACE 0x03
#define PRINTER_CLASS_INTERFACE 0x07
#define MASSSTRAGE_CLASS_INTERFACE 0x08
#define HUB_CLASS_INTERFACE 0x09
/*********************************************************************************************************
** Function name: class_driver_registration
** Descriptions: 注冊類設備驅動
** Input:ClassCode,類代碼
** init_commands,安裝設備類驅動調用的函數
** dispose_process,卸載設備類驅動調用的函數
** Output : 正常完成返回0,出錯返回非0
** Created by:
** Created Date:
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
__inline int class_driver_registration(unsigned char ClassCode,
unsigned short (*init_commands)( device_instance *dvi_ptr ),
unsigned short (*dispose_process)( device_instance *dvi_ptr ))
{
return SwiHandle(0x110, ClassCode, init_commands, dispose_process);
}
/*********************************************************************************************************
** Function name: find_device
** Descriptions: 根據設備地址查找設備.
** Input: address,設備地址,地址范圍2~127。
** Output: device_instance,設備信息指針
** Created by:
** Created Date:
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
__inline device_instance *find_device(unsigned char address)
{
return (device_instance *)SwiHandle(0x111, address);
}
/*********************************************************************************************************
** Function name: find_class_interface
** Descriptions: 查找設備接口類
** Input: InterfaceClassID,查找接口類ID
** DeviceIndex,同類設備索引號
** Output: device_instance,設備信息指針
** Created by:
** Created Date:
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
__inline device_instance *find_class_interface(unsigned char InterfaceClassID, unsigned char DeviceIndex)
{
return (device_instance *)SwiHandle(0x112, InterfaceClassID, DeviceIndex);
}
/*********************************************************************************************************
** Function name: find_pid_vid
** Descriptions: 根據設備的產家ID號和產品ID號找查設備.
** Input: VID,產家ID號
** PID,產品ID號
** Output: device_instance,設備信息指針
** Created by:
** Created Date:
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
__inline device_instance *find_pid_vid(unsigned short VID, unsigned short PID)
{
return (device_instance *)SwiHandle(0x113, VID, PID);
}
/*********************************************************************************************************
** Function name: h_set_class_instance
** Descriptions: 編寫設備類驅動時,可能需要使用一些私有數據,通過該函數將私有數據指針,寫入到設備描述信息
** 數據結構.
** Input:*dvi_ptr , 設備描述信息數據結構指針
** *class_instance_ptr, 類設備描述信息數據結構指針(類驅動的私有數據)
** Output : 無
** Created by:
** Created Date:
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
__inline void h_set_class_instance(device_instance *dvi_ptr, void *class_instance_ptr)
{
SwiHandle(0x114, dvi_ptr, class_instance_ptr);
}
/*********************************************************************************************************
** Function name: h_get_class_instance
** Descriptions: 從設備描述信息數據結構中獲取類驅動的私有數據
** Input:*dvi_ptr , 設備描述信息數據結構指針
** Output : 類設備描述信息結構指針
** Created by:
** Created Date:
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
__inline void *h_get_class_instance(device_instance *dvi_ptr)
{
return (void *)SwiHandle(0x115, dvi_ptr);
}
/********************************************************************************************************
** 查找設備指定端點使用的宏
********************************************************************************************************/
// 端點類型
#define Ep_TransferType_Control 0x0 // 控制傳輸端點
#define Ep_TransferType_Isochronous 0x1 // 同步傳輸端點
#define Ep_TransferType_Bulk 0x2 // 批量傳輸端點
#define Ep_TransferType_Interrupt 0x3 // 中斷傳輸端點
// 端點方向
#define Ep_Direction_OUT_ENDPOINT 0 // 主機到設備
#define Ep_Direction_IN_ENDPOINT 1 // 設備到主機
#define Ep_Direction_CONTROL_ENDPOINT 2 // 僅為查找控制傳輸端點使用
/*********************************************************************************************************
** Function name: find_endport_type
** Descriptions: 從指定的設備中查找特定的端點類型.
** Input:dviPtr,設備信息指針
** endport_type,端點類型
** endport_direction,端點的方向,輸入(1)或輸出(0)
** index,端點序號,如果設備有多個同類型的端點,可以通過序號選擇。
** Output : 返回端點指針,空指針查找失敗
** Created by:
** Created Date:
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
__inline endpoint_info * find_endport_type(device_instance *dviPtr, unsigned char endport_type,
unsigned char endport_direction,unsigned char index)
{
return (endpoint_info *)SwiHandle(0x116, dviPtr, endport_type, endport_direction, index);
}
/*********************************************************************************************************
** Function name: find_endport_number
** Descriptions: 從指定的設備中查找特定的端點,根據端點口與端點傳輸方向
** Input: dviPtr,設備信息指針
** endport_number,端點號
** endport_direction,端點的方向,輸入(1)或輸出(0)
** Output : 返回端點指針,空指針查找失敗
** Created by:
** Created Date:
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date:
**------------------------------------------------------------------------------------------------------
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -