Subversion Repositories NaviCtrl

Rev

Rev 110 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 110 Rev 111
Line 55... Line 55...
55
// +  POSSIBILITY OF SUCH DAMAGE. 
55
// +  POSSIBILITY OF SUCH DAMAGE. 
56
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
56
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
57
#include "91x_lib.h"
57
#include "91x_lib.h"
58
#include "uart1.h"
58
#include "uart1.h"
59
#include "usb.h"
59
#include "usb.h"
-
 
60
#include "mkprotocol.h"
-
 
61
 
-
 
62
 
-
 
63
// the tx buffer
-
 
64
#define USB_TX_BUFFER_LEN  150
-
 
65
u8 USB_tbuffer[USB_TX_BUFFER_LEN];
-
 
66
Buffer_t USB_tx_buffer;
-
 
67
 
-
 
68
// the rx buffer
-
 
69
#define USB_RX_BUFFER_LEN  150
-
 
70
u8 USB_rbuffer[USB_RX_BUFFER_LEN];
-
 
71
Buffer_t USB_rx_buffer;
-
 
72
 
-
 
73
 
60
//-----------------------------------------------------------------
74
//-----------------------------------------------------------------
61
void USB_ConfigInit(void)
75
void USB_ConfigInit(void)
62
{
76
{
63
        GPIO_InitTypeDef GPIO_InitStructure;
77
        GPIO_InitTypeDef GPIO_InitStructure;
Line 86... Line 100...
86
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
100
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
87
        GPIO_InitStructure.GPIO_IPConnected=GPIO_IPConnected_Enable;
101
        GPIO_InitStructure.GPIO_IPConnected=GPIO_IPConnected_Enable;
88
        GPIO_InitStructure.GPIO_Alternate=GPIO_OutputAlt1;
102
        GPIO_InitStructure.GPIO_Alternate=GPIO_OutputAlt1;
89
        GPIO_Init (GPIO0, &GPIO_InitStructure);
103
        GPIO_Init (GPIO0, &GPIO_InitStructure);
Line -... Line 104...
-
 
104
 
-
 
105
                // initialize txd buffer
-
 
106
        USB_tx_buffer.pData = USB_tbuffer;
-
 
107
        USB_tx_buffer.Size = USB_TX_BUFFER_LEN;
-
 
108
        USB_tx_buffer.Position = 0;
-
 
109
        USB_tx_buffer.Locked = FALSE;
-
 
110
       
-
 
111
        // initialize rxd buffer
-
 
112
        USB_rx_buffer.pData = USB_rbuffer;
-
 
113
        USB_rx_buffer.Size = USB_RX_BUFFER_LEN;
-
 
114
        USB_rx_buffer.Position = 0;
-
 
115
        USB_rx_buffer.Locked = FALSE;
-
 
116
 
90
 
117
 
91
        PowerOff();
118
        PowerOff();
Line 92... Line 119...
92
        Virtual_Com_Port_Reset();
119
        Virtual_Com_Port_Reset();
93
 
120
 
Line 98... Line 125...
98
 
125
 
99
        UART1_PutString("ok");  
126
        UART1_PutString("ok");  
Line 100... Line 127...
100
}
127
}
101
 
128
 
102
//-----------------------------------------------------------------
129
//-----------------------------------------------------------------
103
void USB_Cable_Config (FunctionalState NewState)
130
void USB_CableConfig(FunctionalState NewState)
104
{
131
{
105
        if (NewState == ENABLE)
132
        if (NewState == ENABLE)
106
        GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_RESET);
133
        GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_RESET);
107
        else
134
        else
Line 108... Line 135...
108
        GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_SET);
135
        GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_SET);
109
}
136
}
110
 
137
 
111
//-----------------------------------------------------------------
138
//-----------------------------------------------------------------
112
void USB_Send_String(u8 *StrPtr)
139
void USB_PutString(u8 *string)
Line 113... Line 140...
113
{
140
{
114
        u8 i = 0;
141
        u8 i = 0;
115
        u16 timeout = 0;
142
        u16 timeout = 0;
116
       
143
       
117
        while (StrPtr[i++] !=0){} // get string len
144
        while (string[i++] != 0){} // get string len
118
        while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;}
145
        while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;}
Line 119... Line 146...
119
        UserToPMABufferCopy(StrPtr, ENDP1_TXADDR, ++i); // copy string to usb buffer
146
        UserToPMABufferCopy(string, ENDP1_TXADDR, ++i); // copy string to usb buffer
120
        SetEPTxCount(ENDP1,i);
147
        SetEPTxCount(ENDP1,i);
121
        SetEPTxValid(ENDP1);
148
        SetEPTxValid(ENDP1);
122
}
149
}
123
 
150
 
124
//-----------------------------------------------------------------
151
//-----------------------------------------------------------------
125
void USB_Send_Char(u8 ch)
152
void USB_PutChar(u8 c)
126
{
153
{
127
        u16 timeout = 0;
154
        u16 timeout = 0;
Line 128... Line 155...
128
        while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;}
155
        while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;}
129
        UserToPMABufferCopy(&ch, ENDP1_TXADDR, 2);
156
        UserToPMABufferCopy(&c, ENDP1_TXADDR, 2);
130
        SetEPTxCount(ENDP1,2);
157
        SetEPTxCount(ENDP1,2);
131
        SetEPTxValid(ENDP1);
158
        SetEPTxValid(ENDP1);
132
}
159
}
Line 133... Line 160...
133
 
160
 
134
//-----------------------------------------------------------------
161
//-----------------------------------------------------------------
135
void USB_Send_Data(u8 *data, u16 count)
162
void USB_SendData(u8 *pdata, u16 count)
136
{
163
{
137
        u8 i;
164
        u8 i;
138
        count++;
165
        count++;
139
       
166
       
140
        for (i=0;i< (count/64)+1;i++)  
167
        for (i=0;i< (count/64)+1;i++)  
141
        {
168
        {
142
                while (_GetEPTxStatus(ENDP1) != EP_TX_NAK);
169
                while (_GetEPTxStatus(ENDP1) != EP_TX_NAK);
143
                if (i < (count/64))
170
                if (i < (count/64))
144
                {
171
                {
145
                        UserToPMABufferCopy(&data[i*64], ENDP1_TXADDR, 64);
172
                        UserToPMABufferCopy(&pdata[i*64], ENDP1_TXADDR, 64);
146
                        SetEPTxCount(ENDP1,64);
-
 
147
                }
173
                        SetEPTxCount(ENDP1,64);
148
                else
174
                }
149
                {
175
                else