?? d13driver.c
字號:
}
else if(i_st &D13REG_INTSRC_SUSPEND){
usb_suspend(); //ISP1181B掛起中斷處理 deal with the suspend interrupt of
bEPPflags.bits.suspend = 1; // ISP1181B
}
else if(i_st & D13REG_INTSRC_EOT)
dma_eot(); //DMA傳輸結束處理 deal with the end of DMA transfer
else if(i_st & D13REG_INTSRC_RESUME){
D13_LockDevice(0xAA37); //解鎖設備,重新使能其它寄存器 unlock the device,enable all register
//添加恢復系統所有元件正常功能代碼
}
else {
if(i_st & D13REG_INTSRC_EP0IN)
ep0_txdone(); //控制端點發送數據處理 deal with the transmit of control endpoint IN
if(i_st & D13REG_INTSRC_EP0OUT)
ep0_rxdone(); //控制端點接收數據處理 deal with the receive of control endpoint OUT
if(i_st & D13REG_INTSRC_EP01)
USB_WriteISR(&UsbSend_EP01,EPINDEX4EP01,16,1); //端點 1 發送數據處理 deal with the transmit of endpoint 1
if(i_st & D13REG_INTSRC_EP02)
USB_ReadISR(&UsbRec_EP02,EPINDEX4EP02,16,1); //端點 2 接收數據處理 deal with the receive of endpoint 2
if(i_st & D13REG_INTSRC_EP03)
USB_WriteISR(&UsbSend_EP03,EPINDEX4EP03,64,2); //端點 3 發送數據處理 deal with the transmit of endpoint 3
if(i_st & D13REG_INTSRC_EP04)
USB_ReadISR(&UsbRec_EP04,EPINDEX4EP04,64,2); //端點 4 接收數據處理 deal with the receive of endpoint 4
if(i_st & D13REG_INTSRC_EP05)
USB_WriteISR(&UsbSend_EP05,EPINDEX4EP05,64,2); //端點 5 發送數據處理 deal with the transmit of endpoint 5
if(i_st & D13REG_INTSRC_EP06)
USB_ReadISR(&UsbRec_EP06,EPINDEX4EP06,64,2); //端點 6 接收數據處理 deal with the receive of endpoint 6
}
}
//add for ARM
CLR_INTD13(); //清除 ISP1181B 的中斷標志 clear the interrupt flag of ISP1181B
CLR_INT(); //通知中斷結束 info ARM the end of the interrupt
OS_EXIT_CRITICAL(); //退出中斷服務程序時開中斷 enable all interrupt when interrupt rountine exit
}
/***********************************************************************************************************************
** 函數名稱: void TaskSetup(void *pdata) Name: void TaskSetup(void *pdata)
** 功能描述: 控制傳輸處理 Function: deal with control transfer
** 輸 入: void *pdata 任務參數 Input: void *pdata: parameter of the task
** 輸 出: 無 Output: NULL
** 注 意: 該任務的優先級應高于其它任務,才能在 Note: the prior of the task must be higher than other,so
任何情況下傳輸SETUP包 it will be sucessful when tranfering SETUP packet
************************************************************************************************************************/
void TaskSetup(void *pdata)
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
INT8U err;
pdata = pdata; /* Prevent compiler warning */
for (;;)
{
OSSemPend(pSetup_Event,0,&err); //等待Setup包 wait for SETUP packet
if (err == OS_NO_ERR){ //接收到Setup包 have received SETUP packet
OS_ENTER_CRITICAL(); //關中斷 disable all interrupt
control_handler(); //進行控制傳輸處理 deal with control transfer
OS_EXIT_CRITICAL(); //開中斷 enable all interrupt
}
}
}
/************************************************************************************************************************
** 函數名稱: USB_ReadISR() Name: USB_ReadISR()
** 功能描述: USB 端點接收中斷服務程序 Function: the reception interrupt service of USB endpoint
** 輸 入: CTRL_USB *pUsb: USB接收與發送控制結構體指針 Input: CTRL_USB *pUsb: the CTRL_USB structure
INT8U endp: 端點索引號 INT8U endp: the index of endpoint
INT32U eppsize: 端點最大信息包大小 INT32U eppsize: max size of the endpoint
INT8U buffnums: 該端點緩沖區個數 INT8U buffnums: numbers of endpoint buffer
** 輸 出: 無 Output: NULL
*************************************************************************************************************************/
void USB_ReadISR(CTRL_USB *pUsb,INT8U endp,INT32U eppsize,INT8U buffnums)
{
INT8U *pBuff,endpstatus,i;
INT32U len;
D13_GetEndpointStatusWInteruptClear(endp); //清空該端點的中斷標志 clear the flag of the endpoint interrupt register
if (pUsb->Grp != 0){ //有任務在等待接收 exist task waiting for reception
if (pUsb->Sem == 0){ //沒有任務占用該端點 no task use the endpoint
pUsb->Prio = USB_GetHighPrio(pUsb); //取等待任務列表中優先級最高的任務的優先級 get the highest prior of wating table
pUsb->Cnt = 0; //接收計數清0 counter clear to zero
pUsb->Sem = 1; //標志有任務獨占了該端點 flag that task use the endpoint
}
pBuff = pUsb->pBuff[pUsb->Prio]; //取得接收指針 get the pointer of reception
for (i = 0; i < buffnums; i++){
len = pUsb->Max[pUsb->Prio] - pUsb->Cnt; //計算未接收字節數 calculate the numbers of bytes that will be received
if (len > 0){
if (len >= eppsize)
len = (INT8U)D13_ReadEndpoint(endp,(INT8U)eppsize,pBuff + pUsb->Cnt);//接收整個緩沖區 receive a endpoint buffer
else
len = (INT8U)D13_ReadEndpoint(endp,(INT8U)len,pBuff + pUsb->Cnt); //接收len個字節 receive len bytes
pUsb->Cnt = pUsb->Cnt + len; //計數器計數 counter counting
}
if (pUsb->Cnt >= pUsb->Max[pUsb->Prio]){ //如果接收完畢 if the reception is finished
pUsb->Max[pUsb->Prio] = 0; //接收完成標志置0,表示正確接收 set zero indicate reception is correct
pUsb->Sem = 0; //釋放該端點接收資源 release of the resourece of endpoint reception
USB_DelPrio(pUsb,pUsb->Prio); //將該任務從等待隊列中刪除 delete the task from waiting table
OSTimeDlyResume(pUsb->Prio); //使該接收任務就緒 resume the reception task
break;
}
endpstatus = D13_GetEndpointStatusWOInteruptClear(endp); //讀該端點狀態寄存器 read endpoint status register
if ((endpstatus & 0x60) == 0)
break; //如果緩沖為空,立即跳出循環 if buffer is null,break
else if(i == 0)
D13_GetEndpointStatusWInteruptClear(endp);
}//end of for()
}//end of if (pUsb->Grp != 0)
else{
for (i = 0; i < buffnums; i++){ //沒有任務接收數據,清空該端點接收緩沖區
D13_ClearBuffer(endp); //清空接收緩沖區
endpstatus = D13_GetEndpointStatusWOInteruptClear(endp); //讀該端點狀態寄存器 read endpoint status register
if ((endpstatus & 0x60) == 0)
break; //如果緩沖為空,無須清空 if buffer is null,break
else if(i == 0)
D13_GetEndpointStatusWInteruptClear(endp);
}//end of for()
}
} //no task is ready to receive data,clear the endpoint buffer
/************************************************************************************************************************
** 函數名稱: USB_WriteISR() Name: USB_WriteISR()
** 功能描述: USB 端點發送中斷服務程序 Function: the transmittion interrupt service of USB endpoint
** 輸 入: CTRL_USB *pUsb: USB接收與發送控制結構體指針 Input: CTRL_USB *pUsb: the CTRL_USB structure
INT8U endp: 端點索引號 INT8U endp: the index of endpoint
INT32U eppsize: 端點最大信息包大小 INT32U eppsize: max size of the endpoint
INT8U buffnums: 該端點緩沖區個數 INT8U buffnums: numbers of endpoint buffer
** 輸 出: 無 Output: NULL
*************************************************************************************************************************/
void USB_WriteISR(CTRL_USB *pUsb,INT8U endp,INT32U eppsize,INT8U buffnums)
{
INT32U len;
INT8U *pBuff,i,endpstatus,status;
endpstatus = D13_GetEndpointStatusWInteruptClear(endp); //清空對應端點的中斷標志位
if (pUsb->Grp != 0){
if (pUsb->Cnt >= pUsb->Max[pUsb->Prio]){ //獨占任務全部數據寫入緩沖區 the task of transmittion have write all data into the buffer
endpstatus = D13_GetEndpointStatusWOInteruptClear(endp) & 0x60;
if (endpstatus == 0){ //緩沖區中的數據全部發送完畢 all the data in buffer is all send
pUsb->Sem = 0; //釋放該端點的發送資源 release the transmittion resource of the endpoint
pUsb->Max[pUsb->Prio] = 0; //置正確發送標志為0 flag trasmittion is correct
USB_DelPrio(pUsb,pUsb->Prio); //將該任務從等待隊列中刪除 delete the task from waiting table
OSTimeDlyResume(pUsb->Prio); //使該任務就緒 resume the task
}
}
}
else
return;
if (pUsb->Grp != 0){ //有任務在等待發送數據 exist task waiting for transmitting data
if (pUsb->Sem == 0){ //該發送端點可以使用 no task use the endpoint
pUsb->Prio = USB_GetHighPrio(pUsb);
pUsb->Cnt = 0; //發送計數清0 clear the counter to zero
pUsb->Sem = 1; //使該任務獨占該發送資源 flag that task use the endpoint
}
pBuff = pUsb->pBuff[pUsb->Prio]; //得到發送緩沖區指針 get the pointer of send buffer
for (i = 0; i < buffnums; i++){
status = (D13_GetEndpointStatusWOInteruptClear(endp) & 0x60);
if (status == 0x60) break; //如果緩沖區全部都滿,那么不可以再寫入//if buffer is full,break
len = pUsb->Max[pUsb->Prio] - pUsb->Cnt;
if (len > 0){ //有空的緩沖區且等待發送字節數大于0 buffer is empty and len above zero
if (len >= eppsize) //寫滿緩沖區 write an entire buffer
len = D13_WriteEndpoint(endp,(INT8U)eppsize,pBuff + pUsb->Cnt);
else //寫len個字節 write len length bytes into buffer
len = D13_WriteEndpoint(endp,(INT8U)len,pBuff + pUsb->Cnt);
pUsb->Cnt = pUsb->Cnt + len; //發送計數器更新計數 counter is counting
}//end of if (len > 0)
}//end of for()
}//end of if (pUsb->Grp != 0)
}
/*************************************************************************************************************************
** 函數名稱: USB_ReadPort() Name: USB_ReadPort()
** 功能描述: 讀端點 Function: read data from endpoint
** 輸 入: INT8U endp: 端點索引號 Input: INT8U endp: the index of endpoint
INT8U buffnums: 該端點的緩沖區個數 INT8U buffnums: numbers of endpoint buffer
CTRL_USB *pUsb: USB接收與發送控制結構體指針 CTRL_USB *pUsb: the CTRL_USB structure
INT32U len: 接收字節個數 INT32U len: the numbers(Bytes) that will be received
INT8U *recbuff: 接收緩沖區 INT8U *recbuff: the reception buffer
INT16U timeout: 等待超時時間 INT16U timeout: waiting timeout
** 輸 出: 0: 讀成功 > 0 讀失敗(錯誤碼) Output: 0: sucessfully >0: fail (it is error code)
**************************************************************************************************************************/
INT8U USB_ReadPort(INT8U endp,INT8U buffnums,CTRL_USB *pUsb,INT32U len,INT8U *recbuff,INT16U timeout)
{
INT8U err;
err = USB_RW_Param(pUsb,len,recbuff); //填寫USB接收或發送控制塊參數 filled CTRL_USB struct with parameter
if (err != USB_NO_ERR) return err;
OS_ENTER_CRITICAL();
if (pUsb->Max[OSPrioCur] != 0){ //如果還沒接收完成 if reception is not finished
OS_EXIT_CRITICAL();
OSTimeDly(timeout); //定義超時等待 define timeout
}
OS_EXIT_CRITICAL();
return (USB_RW_Result(endp,buffnums,pUsb,1,timeout)); //返回接收結果 return the result of reception
}
/*************************************************************************************************************************
** 函數名稱: USB_WritePort() Name: USB_WritePort()
** 功能描述: 寫端點 Function: write data to endpoint
** 輸 入: INT8U endp : 端點索引號 Input: INT8U endp: the index of endpoint
INT32U eppsize : 該端點的的信息包大小 INT32U eppsize: max size of the endpoint
INT8U buffnums : 該端點發送緩沖區個數 INT8U buffnums: numbers of endpoint buffer
CTRL_USB *pUsb : 該端點的接收或發送控制塊指針 CTRL_USB *pUsb: the CTRL_USB structure
INT8U *sendbuff : 發送數據字節指針 INT8U *recbuff: the transmittion buffer
INT32U len : 發送數據字節長度 INT32U len: the numbers(Bytes) that will be transmitted
INT16U timeout : 等待超時時間 INT16U timeout: waiting timeout
** 輸 出: 0 發送成功 > 0 發送失敗(錯誤碼) Output: 0: sucessfully >0: fail (it is error code)
**************************************************************************************************************************/
INT8U USB_WritePort(INT8U endp,INT32U eppsize,INT8U buffnums,CTRL_USB *pUsb,
INT8U *sendbuff,INT32U len,INT16U timeout)
{
INT8U err,i;
INT32U length;
err = USB_RW_Param(pUsb,len,sendbuff); //填寫USB接收或發送控制塊參數 filled CTRL_USB struct with parameter
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -