00001 /****************************************************************************** 00002 * $Id$ / 1.0 / 2009.12.18 00003 * http://emea.fujitsu.com 00004 *****************************************************************************/ 00005 /* (C) Fujitsu Microelectronics Europe GmbH */ 00006 /* */ 00007 /* The following software deliverable is intended for and must only be */ 00008 /* used in an evaluation laboratory environment. */ 00009 /* It is provided without charge and therefore provided on an as-is */ 00010 /* basis, subject to alterations. */ 00011 /* */ 00012 /* The software deliverable is to be used exclusively in connection */ 00013 /* with FME products. */ 00014 /* In the event the software deliverable includes the use of open */ 00015 /* source components, the provisions of the governing open source */ 00016 /* license agreement shall apply with respect to such software */ 00017 /* deliverable. */ 00018 /* FME does not warrant that the deliverables do not infringe any */ 00019 /* third party intellectual property right (IPR). In the event that */ 00020 /* the deliverables infringe a third party IPR it is the sole */ 00021 /* responsibility of the customer to obtain necessary licenses to */ 00022 /* continue the usage of the deliverable. */ 00023 /* */ 00024 /* To the maximum extent permitted by applicable law FME disclaims all */ 00025 /* warranties, whether express or implied, in particular, but not */ 00026 /* limited to, warranties of merchantability and fitness for a */ 00027 /* particular purpose for which the deliverable is not designated. */ 00028 /* */ 00029 /* To the maximum extent permitted by applicable law, FME’s liability */ 00030 /* is restricted to intention and gross negligence. */ 00031 /* FME is not liable for consequential damages. */ 00032 /* */ 00033 /* (Disclaimer V1.2) */ 00034 /*****************************************************************************/ 00043 /*****************************************************************************/ 00044 /* Include files */ 00045 /*****************************************************************************/ 00046 #include "base_type.h" 00047 #include "UsbClass.h" 00048 #include "UsbFunction.h" 00049 00050 00051 /*****************************************************************************/ 00052 /* Local pre-processor symbols/macros ('#define') */ 00053 /*****************************************************************************/ 00054 00055 00056 00057 /*****************************************************************************/ 00058 /* Global variable definitions (declared in header file with 'extern') */ 00059 /*****************************************************************************/ 00060 00061 /*****************************************************************************/ 00062 /* Local type definitions ('typedef') */ 00063 /*****************************************************************************/ 00064 00065 00066 00067 /*****************************************************************************/ 00068 /* Local variable definitions ('static') */ 00069 /*****************************************************************************/ 00070 00071 uint8_t DataReceivedFlags = 0; //Status for received data 00072 uint8_t DataSentFlags = 0; //Status for sent data 00073 uint32_t u32LastReceivedSize1; // last received size 00074 usb_buffer_t stcCustomClassBuffer1; //struct for custom buffer 00075 uint8_t pu8CustomClassBufferEndpoint1[BUFFER_SIZE_ENDPOINT1]; // custom buffer 00076 00077 00078 /*****************************************************************************/ 00079 /* Local function prototypes ('static') */ 00080 /*****************************************************************************/ 00081 00082 00083 00084 /*****************************************************************************/ 00085 /* Function implementation - global ('extern') and local ('static') */ 00086 /*****************************************************************************/ 00087 00088 void UsbClass_Init(void) 00089 { 00090 stcCustomClassBuffer1.u32BufferSize = BUFFER_SIZE_ENDPOINT1; // initalizes buffer 00091 stcCustomClassBuffer1.pu8Buffer = pu8CustomClassBufferEndpoint1; // initalizes buffer 00092 UsbFunction_SetCustomEndpointBuffer(1,&stcCustomClassBuffer1); // initalizes buffer 00093 UsbFunction_SetEventHandler(USB_EVENT_TARGET_VENDOR,USB_EVENT_RECEIVE,USB_EP_1,UsbClass_DataReceiveEventEndpoint1); // setup receive event 00094 00095 UsbFunction_SetEventHandler(USB_EVENT_TARGET_VENDOR, USB_EVENT_SENT, USB_EP_5, UsbClass_DataSentEventEndpoint5); 00096 UsbFunction_SetEventHandler(USB_EVENT_TARGET_VENDOR,USB_EVENT_CLASSREQUEST,0,UsbClass_ClassEventHandler); 00097 } 00098 00099 00106 uint8_t UsbClass_DataReceiveEventEndpoint1(usb_event_t * stcEvent) 00107 { 00108 uint8_t* pu8Buffer = stcEvent->pstcEndpointBuffer->pu8Buffer; 00109 uint32_t u32DataSize = stcEvent->u32DataSize; 00110 u32LastReceivedSize1 = u32DataSize; 00111 DataReceivedFlags |= (1<<1); // setting data received flag 00112 00113 //Add your code here to process the received buffer 00114 00115 return 1; 00116 } 00117 00118 00125 uint32_t UsbClass_GetReceivedDataEndpoint1(uint8_t** pu8Buffer) 00126 { 00127 if ((DataReceivedFlags & (1<<1)) == 0) 00128 { 00129 return 0; // nothing to receive 00130 } 00131 DataReceivedFlags -= (1<<1); 00132 *pu8Buffer = pu8CustomClassBufferEndpoint1; 00133 return u32LastReceivedSize1; 00134 } 00135 00146 uint8_t SendDataVia5(puint8_t u8Buffer, uint32_t u32DataSize, uint8_t u8PollingMode) 00147 { 00148 dbgval("Class Send, Size:", (uint32_t)u32DataSize); 00149 dbgval("Class Send, Address:", (uint32_t)u8Buffer); 00150 dbgval("Class Send, Mode:", u8PollingMode); 00151 00152 if ((UsbFunction_GetStatus() & USB_STATUS_CONFIGURED) > 0) 00153 { 00154 DataSentFlags &= ~(1<<5); 00155 UsbFunction_SendData(5,u8Buffer,u32DataSize,u8PollingMode); 00156 if (u8PollingMode == 1) 00157 { 00158 DataSentFlags |= (1<<5); 00159 } 00160 return 1; 00161 } 00162 return 0; 00163 } 00164 00171 uint8_t UsbClass_DataSentEventEndpoint5(usb_event_t * stcEvent) 00172 { 00173 stcEvent = stcEvent; 00174 DataSentFlags |= (1<<5); 00175 return 1; 00176 } 00182 uint8_t UsbClass_DataSent5(void) 00183 { 00184 if ((DataSentFlags & (1<<5)) > 0) 00185 { 00186 return 1; 00187 } 00188 else 00189 { 00190 return 0; 00191 } 00192 } 00193 00200 uint8_t UsbClass_ClassEventHandler(usb_event_t * stcEvent) 00201 { 00202 switch(stcEvent->u8Event) 00203 { 00204 case USB_EVENT_CONNECT: 00205 // paste your connect event here 00206 break; 00207 case USB_EVENT_DISCONNECT: 00208 // paste your disconnect event here 00209 break; 00210 case USB_EVENT_RECEIVE: 00211 dbg("WARNING: The Class Event Handler should not receive any data!\n"); 00212 break; 00213 case USB_EVENT_SENT: 00214 dbg("WARNING: The Class Event Handler should not send any data!\n"); 00215 break; 00216 case USB_EVENT_CONFIGURED: 00217 // paste your connect event here 00218 break; 00219 case USB_EVENT_DECONFIGURED: 00220 // paste your connect event here 00221 break; 00222 case USB_EVENT_CLASSREQUEST: 00223 switch (stcEvent->Request->Request) 00224 { 00225 // decode the request here 00226 default: 00227 break; 00228 } 00229 break; 00230 default: 00231 // not handled? 00232 return 0; // return error 00233 } 00234 return 1; 00235 } 00236
1.6.1