USB-BDI
M:/USB-BDI/USB-BDI/Firmware/MPC555-USB-BDI/src/usb_class_requests.c
Go to the documentation of this file.
00001 /*      USB-BDI Used for programming and debugging a MPC555 over USB
00002  *
00003  *  Copyright 2005 NTB Interstate University of Applied Sciences of Technology Buchs
00004  *
00005  *  This program is free software: you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation, either version 3 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  */
00015 
00024 #include "usb_class_requests.h"
00025 #include "usb_common.h"
00026 #include "BDI.h"
00027 #include "virtual_com_port.h"
00028 #include "usbpdi_common.h"
00029 #include "UART.h"
00030 
00037 void sendEncapsulatedCommand(void){
00038         EP0BCH = 0;
00039         EP0BCL = 0;
00040         EP0CS |= bmHSNAK;
00041 }
00042 
00050 void getEncapsulatedCommand(void){
00051         EP0BCH = 0;
00052         EP0BCL = 0;
00053 }
00054 
00060 void setLineCoding(void){
00061                 EP0BCH = 0;
00062                 EP0BCL = 0x0; //start receiving data
00063                 while (EP0CS&bmEPBUSY);//wait till data is loaded
00064 
00065                 if(EP0BCL==7){  //if the length is not 7 there is a failure
00066 
00067                         bitRate = EP0BUF[3];
00068                         bitRate = (bitRate<<8)| EP0BUF[2];
00069                         bitRate = (bitRate<<8)| EP0BUF[1];
00070                         bitRate = (bitRate<<8)| EP0BUF[0];
00071                         //min and max bit rate caused of the timer options
00072                         if(bitRate<3000){
00073                                 bitRate = 3000;
00074                         }else if (bitRate>750000){
00075                                 bitRate = 750000;
00076                         }
00077                         stopBit = EP0BUF[4];
00078                         parityBit = EP0BUF[5];
00079                         dataBits = EP0BUF[6];
00080                         changeBaudRate(bitRate);
00081 
00082                         EP0CS |= bmHSNAK;
00083                 }else{
00084                         EP0CS |= bmEPSTALL;
00085                 }
00086 
00087 }
00088 
00115 void getLineCoding(void){
00116 
00117         EP0BUF[0] = bitRate;
00118         EP0BUF[1] = bitRate>>8;
00119         EP0BUF[2] = bitRate>>16;
00120         EP0BUF[3] = bitRate>>24;
00121         EP0BUF[4] = stopBit;
00122         EP0BUF[5] = parityBit;
00123         EP0BUF[6] = dataBits;
00124         EP0BCH = 0;
00125         EP0BCL = 7;
00126 }
00127 
00133 void setControlLineState(void){
00134         EP0BCH = 0;
00135         EP0BCL = 0;
00136         EP0CS |= bmHSNAK;
00137         rts = wValueL & 0x01;
00138         dtr = (wValueL & 0x02)>>1;
00139 
00140 
00141 }
00142 
00148 void sendBreak(void){
00149         short wValue = (wValueH<<8)|wValueL; //puts together the lower and the higher part of wValue
00150         stopTime = wValue;
00151         EP0BCH = 0;
00152         EP0BCL = 0;
00153         EP0CS |= bmHSNAK;
00154 }
00155 
00161 void setCommFeature(void){
00162 }
00163 
00169 void getCommFeature(void){
00170 }
00171 
00177 void clearCommFeature(void){
00178 }
00179 
00185 void classRequest(void){
00186         short wIndex = (wIndexH<<8)|wIndexL; //puts together the lower and the higher part of wIndex
00187 
00188         if (wIndex == VCP_COM_INTERFACE_NR){
00189                 switch(bRequest){
00190                         case SEND_ENCAPSULATED_COMMAND:
00191                                 sendEncapsulatedCommand();
00192                                 break;
00193                         case GET_ENCAPSULATED_RESPONSE:
00194                                 getEncapsulatedCommand();
00195                                 break;
00196                         case SET_LINE_CODING:
00197                                 setLineCoding();
00198                                 break;
00199                         case GET_LINE_CODING:
00200                                 getLineCoding();
00201                                 break;
00202                         case SET_CONTROL_LINE_STATE:
00203                                 setControlLineState();
00204                                 break;
00205                         case SEND_BREAK:
00206                                 sendBreak();
00207                                 break;
00208                         case SET_COMM_FEATURE:
00209                                 setCommFeature();
00210                                 break;
00211                         case GET_COMM_FEATURE:
00212                                 getCommFeature();
00213                                 break;
00214                         case CLEAR_COMM_FEATURE:
00215                                 clearCommFeature();
00216                                 break;
00217                         default:
00218                                 break;
00219                 }
00220         }else if(wIndex == VCP_COM_INTERFACE_NR){
00221                 //there shoudn't be class requests for this interface
00222                 EP0CS |= bmEPSTALL;
00223 
00224         }else if (wIndex == BDI_INTERFACE_NR){
00225                 //there shoudn't be class requests for this interface
00226                 EP0CS |= bmEPSTALL;
00227         }
00228 }
00229 
00230 
 All Files Functions Variables Defines