1 /******************************************************************************
2  * Copyright (c) 2022 Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK")
3  * All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *   http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *****************************************************************************/
18 
19 /********************************************************************************************************
20  * @file	usbhw.c
21  *
22  * @brief	This is the source file for B91
23  *
24  * @author	Driver Group
25  *
26  *******************************************************************************************************/
27 #include "usbhw.h"
28 /**
29  * @brief      This function disables the manual interrupt
30  *             (Endpont8 is the alias of endpoint0)
31  * @param[in]  m - the irq mode needs to set
32  * @return     none
33  */
usbhw_disable_manual_interrupt(int m)34 void usbhw_disable_manual_interrupt(int m) {
35 	BM_SET(reg_ctrl_ep_irq_mode, m);
36 }
37 
38 /**
39  * @brief      This function enable the manual interrupt
40  * @param[in]  m - the irq mode needs to set
41  * @return     none
42  */
usbhw_enable_manual_interrupt(int m)43 void usbhw_enable_manual_interrupt(int m) {
44 	BM_CLR(reg_ctrl_ep_irq_mode, m);
45 }
46 
47 /**
48  * @brief      This function sends a bulk of data to host via the specified endpoint
49  * @param[in]  ep - the number of the endpoint
50  * @param[in]  data - pointer to the data need to send
51  * @param[in]  len - length in byte of the data need to send
52  * @return     none
53  */
usbhw_write_ep(unsigned int ep,unsigned char * data,int len)54 void usbhw_write_ep(unsigned int ep, unsigned char * data, int len) {
55 	reg_usb_ep_ptr(ep) = 0;
56 
57 	for(int i = 0; i < (len); ++i){
58 		reg_usb_ep_dat(ep) = data[i];
59 	}
60 	reg_usb_ep_ctrl(ep) = FLD_EP_DAT_ACK;		// ACK
61 }
62 
63 /**
64  * @brief      This function sends two bytes data to host via the control endpoint
65  *             (handy help function)
66  * @param[in]  v - the two bytes data need to send
67  * @return     none
68  */
usbhw_write_ctrl_ep_u16(unsigned short v)69 void usbhw_write_ctrl_ep_u16(unsigned short v){
70 	usbhw_write_ctrl_ep_data(v & 0xff);
71 	usbhw_write_ctrl_ep_data(v >> 8);
72 }
73 
74 /**
75  * @brief   This function reads two bytes data from host via the control endpoint
76  * @param   none
77  * @return  the two bytes data read from the control endpoint
78  */
usbhw_read_ctrl_ep_u16(void)79 unsigned short usbhw_read_ctrl_ep_u16(void){
80 	unsigned short v = usbhw_read_ctrl_ep_data();
81 	return (usbhw_read_ctrl_ep_data() << 8) | v;
82 }
83 
84 
85 
86 
87