Rev 1 | Rev 70 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1 | Rev 41 | ||
---|---|---|---|
Line 52... | Line 52... | ||
52 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
52 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
53 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
53 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
54 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
54 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
55 | // + POSSIBILITY OF SUCH DAMAGE. |
55 | // + POSSIBILITY OF SUCH DAMAGE. |
56 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
56 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | 57 | #include "91x_lib.h" |
|
57 | #include "main.h" |
58 | #include "uart1.h" |
58 | - | ||
- | 59 | #include "usb.h" |
|
59 | //----------------------------------------------------------------- |
60 | //----------------------------------------------------------------- |
60 | void USB_ConfigInit(void) |
61 | void USB_ConfigInit(void) |
61 | { |
62 | { |
62 | GPIO_InitTypeDef GPIO_InitStructure; |
63 | GPIO_InitTypeDef GPIO_InitStructure; |
63 | - | ||
64 | SerialPutString("USB init..."); |
- | |
65 | - | ||
66 | //USB clock = MCLK= 48MHz |
- | |
67 | SCU_USBCLKConfig(SCU_USBCLK_MCLK); |
- | |
68 | //Enable USB clock |
- | |
69 | SCU_AHBPeriphClockConfig(__USB,ENABLE); |
- | |
70 | SCU_AHBPeriphReset(__USB,DISABLE); |
- | |
71 | SCU_AHBPeriphClockConfig(__USB48M,ENABLE); |
- | |
72 | - | ||
73 | //Configure GPIO0 (D+ Pull-Up on P0.1) |
- | |
74 | SCU_APBPeriphClockConfig(__GPIO0 ,ENABLE); |
- | |
75 | SCU_APBPeriphReset(__GPIO0,DISABLE); |
- | |
76 | - | ||
77 | // GPIO_DeInit(GPIO0); |
- | |
78 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
- | |
79 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; |
- | |
80 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
- | |
81 | GPIO_InitStructure.GPIO_IPConnected=GPIO_IPConnected_Enable; |
- | |
82 | GPIO_InitStructure.GPIO_Alternate=GPIO_OutputAlt1; |
- | |
83 | GPIO_Init (GPIO0, &GPIO_InitStructure); |
- | |
84 | - | ||
85 | PowerOff(); |
- | |
86 | Virtual_Com_Port_Reset(); |
- | |
Line -... | Line 64... | ||
- | 64 | ||
- | 65 | SerialPutString("\r\n USB init..."); |
|
- | 66 | #ifdef MCLK96MHZ |
|
87 | 67 | //USB clock = MCLK/2 = 48MHz |
|
- | 68 | SCU_USBCLKConfig(SCU_USBCLK_MCLK2); |
|
- | 69 | #else |
|
- | 70 | //USB clock = MCLK = 48MHz |
|
- | 71 | SCU_USBCLKConfig(SCU_USBCLK_MCLK); |
|
- | 72 | #endif |
|
- | 73 | //Enable USB clock |
|
88 | VIC_Config(USBLP_ITLine, VIC_IRQ, 2); |
74 | SCU_AHBPeriphClockConfig(__USB,ENABLE); |
- | 75 | SCU_AHBPeriphReset(__USB,DISABLE); |
|
- | 76 | SCU_AHBPeriphClockConfig(__USB48M,ENABLE); |
|
- | 77 | ||
- | 78 | //Configure GPIO0 (D+ Pull-Up on P0.1) |
|
- | 79 | SCU_APBPeriphClockConfig(__GPIO0 ,ENABLE); |
|
- | 80 | SCU_APBPeriphReset(__GPIO0,DISABLE); |
|
- | 81 | ||
- | 82 | // GPIO_DeInit(P0.1); |
|
- | 83 | GPIO_StructInit(&GPIO_InitStructure); |
|
- | 84 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
|
- | 85 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; |
|
- | 86 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
|
- | 87 | GPIO_InitStructure.GPIO_IPConnected=GPIO_IPConnected_Enable; |
|
- | 88 | GPIO_InitStructure.GPIO_Alternate=GPIO_OutputAlt1; |
|
- | 89 | GPIO_Init (GPIO0, &GPIO_InitStructure); |
|
- | 90 | ||
- | 91 | PowerOff(); |
|
Line -... | Line 92... | ||
- | 92 | Virtual_Com_Port_Reset(); |
|
89 | VIC_ITCmd(USBLP_ITLine, ENABLE); |
93 | |
Line 90... | Line 94... | ||
90 | 94 | VIC_Config(USBLP_ITLine, VIC_IRQ, 2); |
|
Line -... | Line 95... | ||
- | 95 | VIC_ITCmd(USBLP_ITLine, ENABLE); |
|
91 | USB_Init(); |
96 | |
Line 92... | Line 97... | ||
92 | 97 | USB_Init(); |
|
93 | SerialPutString("ok\n\r"); |
98 | |
94 | 99 | SerialPutString("ok"); |
|
95 | } |
100 | } |
96 | 101 | ||
97 | //----------------------------------------------------------------- |
102 | //----------------------------------------------------------------- |
98 | void USB_Cable_Config (FunctionalState NewState) |
103 | void USB_Cable_Config (FunctionalState NewState) |
99 | { |
104 | { |
Line 100... | Line 105... | ||
100 | if (NewState == ENABLE) |
105 | if (NewState == ENABLE) |
101 | GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_RESET); |
106 | GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_RESET); |
102 | else |
107 | else |
103 | GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_SET); |
108 | GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_SET); |
104 | } |
109 | } |
105 | 110 | ||
106 | //----------------------------------------------------------------- |
111 | //----------------------------------------------------------------- |
107 | void USB_Send_String(u8 *StrPtr) |
112 | void USB_Send_String(u8 *StrPtr) |
108 | { |
113 | { |
109 | u8 i = 0; |
114 | u8 i = 0; |
110 | u16 timeout = 0; |
115 | u16 timeout = 0; |
111 | 116 | ||
Line 112... | Line 117... | ||
112 | while (StrPtr[i++] !=0){} |
117 | while (StrPtr[i++] !=0){} // get string len |
113 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;} |
118 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;} |
114 | UserToPMABufferCopy(StrPtr, ENDP1_TXADDR, ++i); |
119 | UserToPMABufferCopy(StrPtr, ENDP1_TXADDR, ++i); // copy string to usb buffer |
115 | SetEPTxCount(ENDP1,i); |
120 | SetEPTxCount(ENDP1,i); |
116 | SetEPTxValid(ENDP1); |
121 | SetEPTxValid(ENDP1); |
117 | } |
122 | } |
118 | 123 | ||
119 | //----------------------------------------------------------------- |
124 | //----------------------------------------------------------------- |
120 | void USB_Send_Char(u8 ch) |
125 | void USB_Send_Char(u8 ch) |
- | 126 | { |
|
121 | { |
127 | u16 timeout = 0; |
122 | u16 timeout = 0; |
128 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;} |
123 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;} |
129 | UserToPMABufferCopy(&ch, ENDP1_TXADDR, 2); |
124 | UserToPMABufferCopy(&ch, ENDP1_TXADDR, 2); |
- | |
125 | SetEPTxCount(ENDP1,2); |
130 | SetEPTxCount(ENDP1,2); |
126 | SetEPTxValid(ENDP1); |
- | |
127 | } |
- | |
128 | //----------------------------------------------------------------- |
131 | SetEPTxValid(ENDP1); |
129 | void USB_Send_Data(u8 *data, u16 count) |
- | |
130 | { |
- | |
131 | u16 timeout = 0; |
- | |
132 | u8 i; |
- | |
133 | - | ||
134 | - | ||
135 | count++; |
- | |
136 | - | ||
137 | for (i=0;i< (count/64)+1;i++) |
- | |
138 | { |
- | |
139 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK); |
- | |
140 | if (i < (count/64)) |
- | |
Line -... | Line 132... | ||
- | 132 | } |
|
- | 133 | ||
- | 134 | //----------------------------------------------------------------- |
|
- | 135 | void USB_Send_Data(u8 *data, u16 count) |
|
- | 136 | { |
|
- | 137 | u8 i; |
|
- | 138 | count++; |
|
- | 139 | ||
- | 140 | for (i=0;i< (count/64)+1;i++) |
|
- | 141 | { |
|
- | 142 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK); |
|
- | 143 | if (i < (count/64)) |
|
- | 144 | { |
|
- | 145 | UserToPMABufferCopy(&data[i*64], ENDP1_TXADDR, 64); |
|
141 | { UserToPMABufferCopy(&data[i*64], ENDP1_TXADDR, 64); |
146 | SetEPTxCount(ENDP1,64); |
142 | SetEPTxCount(ENDP1,64); |
147 | } |
143 | } |
148 | else |