?? d13driver.c
字號(hào):
/****************************************Copyright (c)**************************************************
** Guangzhou ZLG-MCU Development Co.,LTD.
** graduate school
** http://www.zlgmcu.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name: D13Driver.c
** Last modified Date: 2004-12-10
** Last Version: V1.0
** Descriptions: ISP1181B (D13) 設(shè)備端驅(qū)動(dòng)程序 應(yīng)用層
** Soft Packet of USB Driver: the Driver of Device of ISP1181B(D13)
Application Layer
**------------------------------------------------------------------------------------------------------
** Created by: Ming Yuan Zheng
** Created date: 2004-12-10
** Version: V1.0
** Descriptions: The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
********************************************************************************************************/
#include "config.h"
#include "D13Config.h"
#include "D13CI.h"
#include "D13HAL.h"
#include "Chap_9.h"
#include "D13Driver.h"
extern EPPFLAGS bEPPflags;
/* Setup包處理任務(wù)堆棧 */
/* Stack of the task that deal with control transfer */
OS_STK TaskSetupStk[128];
/* Setup包處理任務(wù)事件指針 */
/* the pointer of Event that deal SETUP packet */
OS_EVENT *pSetup_Event;
/* ISP1181B 各端口對(duì)應(yīng)的 USB 接收或發(fā)送控制塊 */
/* USB receive or transmit control block of ISP1181B each endpoint */
CTRL_USB UsbSend_EP01; //端點(diǎn) 1 發(fā)送控制塊
CTRL_USB UsbRec_EP02; //端點(diǎn) 2 接收控制塊
CTRL_USB UsbSend_EP03; //端點(diǎn) 3 發(fā)送控制塊
CTRL_USB UsbRec_EP04; //端點(diǎn) 4 接收控制塊
CTRL_USB UsbSend_EP05; //端點(diǎn) 5 發(fā)送控制塊
CTRL_USB UsbRec_EP06; //端點(diǎn) 6 接收控制塊
/*******************************************************************************************************************************
** 函數(shù)名稱: INT8U WritePort1() Name: INT8U WritePort1()
** 功能描述: 用端口 1 發(fā)送len個(gè)字節(jié) Function: Send len Bytes via Port1
** 輸 入: INT32U len: 發(fā)送的字節(jié)數(shù) Input: INT32U len: numbers will be send
(取值范圍為0x00000001 ~ 0xFFFFFFFF) (range: 0x00000001 ~ 0xFFFFFFFF)
INT8U sendbuff: 發(fā)送緩沖區(qū)指針 INT8U sendbuff: send buffer
INT16U timeout: 超時(shí)等待時(shí)間, 必須大于等于0 INT16U timeout: timeout of transmitting
** 輸 出: 0: 發(fā)送成功 > 0: 發(fā)送失敗(錯(cuò)誤碼) Output: 0: sucessfully >0 fail (error code)
*******************************************************************************************************************************/
INT8U WritePort1(INT32U len,INT8U *sendbuff,INT16U timeout)
{
return (USB_WritePort(EPINDEX4EP01,16,1,&UsbSend_EP01,sendbuff,len,timeout));
} //往端口1發(fā)送數(shù)據(jù)
/*******************************************************************************************************************************
** 函數(shù)名稱: INT8U WritePort2() Name: INT8U WritePort2()
** 功能描述: 用端口 2 發(fā)送len個(gè)字節(jié) Function: Send len Bytes via Port2
** 輸 入: INT32U len: 發(fā)送的字節(jié)數(shù) Input: INT32U len: numbers will be send
(取值范圍為0x00000001 ~ 0xFFFFFFFF) (range: 0x00000001 ~ 0xFFFFFFFF)
INT8U sendbuff: 發(fā)送緩沖區(qū)指針 INT8U sendbuff: send buffer
INT16U timeout: 超時(shí)等待時(shí)間, 必須大于等于0 INT16U timeout: timeout of transmitting
** 輸 出: 0: 發(fā)送成功 > 0: 發(fā)送失敗(錯(cuò)誤碼) Output: 0: sucessfully >0 fail (error code)
*******************************************************************************************************************************/
INT8U WritePort2(INT32U len,INT8U *sendbuff,INT16U timeout)
{
return (USB_WritePort(EPINDEX4EP03,64,2,&UsbSend_EP03,sendbuff,len,timeout));
} //往端點(diǎn)3發(fā)送數(shù)據(jù)
/*******************************************************************************************************************************
** 函數(shù)名稱: INT8U WritePort3() Name: INT8U WritePort3()
** 功能描述: 用端口 3 發(fā)送len個(gè)字節(jié) Function: Send len Bytes via Port3
** 輸 入: INT32U len: 發(fā)送的字節(jié)數(shù) Input: INT32U len: numbers will be send
(取值范圍為0x00000001 ~ 0xFFFFFFFF) (range: 0x00000001 ~ 0xFFFFFFFF)
INT8U sendbuff: 發(fā)送緩沖區(qū)指針 INT8U sendbuff: send buffer
INT16U timeout: 超時(shí)等待時(shí)間, 必須大于等于0 INT16U timeout: timeout of transmitting
** 輸 出: 0: 發(fā)送成功 > 0: 發(fā)送失敗(錯(cuò)誤碼) Output: 0: sucessfully >0 fail (error code)
*******************************************************************************************************************************/
INT8U WritePort3(INT32U len,INT8U *sendbuff,INT16U timeout)
{
return (USB_WritePort(EPINDEX4EP05,64,2,&UsbSend_EP05,sendbuff,len,timeout));
} //往端點(diǎn)5發(fā)送數(shù)據(jù)
/*******************************************************************************************************************************
** 函數(shù)名稱: INT8U ReadPort1() Name: INT8U ReadPort1()
** 功能描述: 從端口 1 接收l(shuí)en個(gè)字節(jié) Function: receive len Bytes from Port1
** 輸 入: INT32U len: 要接收的字節(jié)數(shù) Input: INT32U len: numbers will be receive
(取值范圍為0x00000001 ~ 0xFFFFFFFF) (range: 0x00000001 ~ 0xFFFFFFFF)
INT8U recbuff: 接收緩沖區(qū)指針 INT8U sendbuff: receive buffer
INT16U timeout: 超時(shí)等待時(shí)間, 必須大于等于0 INT16U timeout: timeout of receiving
** 輸 出: 0: 接收成功 > 0: 接收失敗(錯(cuò)誤碼) Output: 0: sucessfully >0 fail (error code)
*******************************************************************************************************************************/
INT8U ReadPort1(INT32U len,INT8U *recbuff,INT16U timeout)
{
return (USB_ReadPort(EPINDEX4EP02,1,&UsbRec_EP02,len,recbuff,timeout));
} //從端點(diǎn)2接收數(shù)據(jù)
/*******************************************************************************************************************************
** 函數(shù)名稱: INT8U ReadPort2() Name: INT8U ReadPort2()
** 功能描述: 從端口 2 接收l(shuí)en個(gè)字節(jié) Function: receive len Bytes from Port2
** 輸 入: INT32U len: 要接收的字節(jié)數(shù) Input: INT32U len: numbers will be receive
(取值范圍為0x00000001 ~ 0xFFFFFFFF) (range: 0x00000001 ~ 0xFFFFFFFF)
INT8U recbuff: 接收緩沖區(qū)指針 INT8U sendbuff: receive buffer
INT16U timeout: 超時(shí)等待時(shí)間, 必須大于等于0 INT16U timeout: timeout of receiving
** 輸 出: 0: 接收成功 > 0: 接收失敗(錯(cuò)誤碼) Output: 0: sucessfully >0 fail (error code)
*******************************************************************************************************************************/
INT8U ReadPort2(INT32U len,INT8U *recbuff,INT16U timeout)
{
return (USB_ReadPort(EPINDEX4EP04,2,&UsbRec_EP04,len,recbuff,timeout));
} //從端點(diǎn)4接收數(shù)據(jù)
/*******************************************************************************************************************************
** 函數(shù)名稱: INT8U ReadPort3() Name: INT8U ReadPort3()
** 功能描述: 從端口 3 接收l(shuí)en個(gè)字節(jié) Function: receive len Bytes from Port3
** 輸 入: INT32U len: 要接收的字節(jié)數(shù) Input: INT32U len: numbers will be receive
(取值范圍為0x00000001 ~ 0xFFFFFFFF) (range: 0x00000001 ~ 0xFFFFFFFF)
INT8U recbuff: 接收緩沖區(qū)指針 INT8U sendbuff: receive buffer
INT16U timeout: 超時(shí)等待時(shí)間, 必須大于等于0 INT16U timeout: timeout of receiving
** 輸 出: 0: 接收成功 > 0: 接收失敗(錯(cuò)誤碼) Output: 0: sucessfully >0 fail (error code)
*******************************************************************************************************************************/
INT8U ReadPort3(INT32U len,INT8U *recbuff,INT16U timeout)
{
return (USB_ReadPort(EPINDEX4EP06,2,&UsbRec_EP06,len,recbuff,timeout));
} //從端點(diǎn)5接收數(shù)據(jù)
/**********************************************************************************************************************
** 函數(shù)名稱: Init_D13() Name: Init_D13()
** 功能描述: 設(shè)置 D13(ISP1181B) 與MCU的連接接口, Function: Configure the interface connected to MCU,reset D13,
復(fù)位D13,連接上USB總線 connected to USB bus
** 輸 入: 無(wú) Input: NULL
** 輸 出: 0: 初始化成功 1: 初始化失敗 Output: 0: Initialize sucessfully 1: Initialize fail
** 注 意: 請(qǐng)?jiān)谡{(diào)用該函數(shù)以后再打開(kāi)D13中斷 Note: Enable the interrupt of D13 after the function be called
***********************************************************************************************************************/
INT8U Init_D13(void)
{
INT32U i;
OS_ENTER_CRITICAL();
Init_D13Port(); //初始化MCU與ISP1181B 連接的接口 initialize MCU and ISP1181B's Interface
Rst_D13(); //復(fù)位D13 reset D13 chip
reconnect_USB(); //重新連接USB總線 reconnect USB bus
i = D13_ReadChipID(); //讀芯片ID號(hào) read ChipID
if (i!= ISP1181B_CHIPID && i != ISP1181A_CHIPID &&
i!= ISP1161A_CHIPID)
{
OS_EXIT_CRITICAL();
return 1; //讀芯片ID號(hào)不正確,返回失敗 ChipID is error,return 1
}
bEPPflags.value = 0; //USB事件標(biāo)志置0 USB Event Flag clear to zero
UsbRec_EP02.Sem = 0; //初始化 USB 接收或發(fā)送控制塊
UsbRec_EP04.Sem = 0; //Initialize CTRL_USB structure
UsbRec_EP06.Sem = 0;
UsbSend_EP01.Sem = 0;
UsbSend_EP03.Sem = 0;
UsbSend_EP05.Sem = 0;
UsbRec_EP02.Grp = 0;
UsbRec_EP04.Grp = 0;
UsbRec_EP06.Grp = 0;
UsbSend_EP01.Grp = 0;
UsbSend_EP03.Grp = 0;
UsbSend_EP05.Grp = 0;
for (i = 0; i < OS_RDY_TBL_SIZE; i++){
UsbRec_EP02.Tbl[i] = 0; //清空各端口接收與發(fā)送等待任務(wù)列表
UsbRec_EP04.Tbl[i] = 0; //clear the waiting task table of each port
UsbRec_EP06.Tbl[i] = 0;
UsbSend_EP01.Tbl[i] = 0;
UsbSend_EP03.Tbl[i] = 0;
UsbSend_EP05.Tbl[i] = 0;
}
pSetup_Event = OSSemCreate(0); //創(chuàng)建Setup包處理任務(wù)信號(hào)量
//create the semaphore of the task of Handling SETUP packet
if (pSetup_Event == NULL)
{
OS_EXIT_CRITICAL();
return 1; //return 1 when create the semaphore fail
}
OS_EXIT_CRITICAL();
return 0; //初始化成功 initialize sucessfully
}
/******************************************************************************************************************
** 函數(shù)名稱: Usb_Exception() Name: Usb_Exception()
** 功能描述: ISP1181B(D13) 中斷服務(wù)程序 Function: the interrupt service routine of ISP1181B(D13)
*******************************************************************************************************************/
void Usb_Exception(void)
{
INT32U i_st;
OS_ENTER_CRITICAL(); //關(guān)中斷 disable all interrupt
D13_LockDevice(0xAA37);
i_st = D13_ReadInterruptRegister(); //讀取D13中斷寄存器值 read the interrupt register of ISP1181B
if(i_st != 0){
if(i_st & D13REG_INTSRC_BUSRESET){
bus_reset(); //總線復(fù)位處理 deal with the bus reset
bEPPflags.bits.bus_reset = 1;
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -