00001
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 #include <string.h>
00051 #include <stdio.h>
00052 #include "conf_usb.h"
00053 #include "compiler.h"
00054
00055
00056 #if USB_DEVICE_FEATURE == ENABLED
00057
00058 #include "board.h"
00059 #include "usb_drv.h"
00060 #include "gpio.h"
00061 #include "usb_descriptors.h"
00062 #include "usb_standard_request.h"
00063 #include "device_ctrl_panel_task.h"
00064 #include "adc.h"
00065 #include "cpled.h"
00066 #include "s_accelerometer.h"
00067 #include "s_joystick.h"
00068 #include "s_light.h"
00069 #include "s_pushb.h"
00070 #include "s_temperature.h"
00071 #ifdef FREERTOS_USED
00072 #include "FreeRTOS.h"
00073 #include "task.h"
00074 #endif
00075
00076
00077
00078
00079
00080
00081
00082 #define STR_SET_LEDM1 "set_actuator_value actuator=ledm1 state="
00083 #define STR_SET_LEDM2 "set_actuator_value actuator=ledm2 state="
00084 #define STR_SET_LEDM3 "set_actuator_value actuator=ledm3 state="
00085 #define STR_SET_LEDM4 "set_actuator_value actuator=ledm4 state="
00086
00087
00088 static U16 sof_cnt;
00089
00090 #define RXBUF_SIZE 64
00091 #define TXBUF_SIZE 40
00092 char rxbuf[RXBUF_SIZE];
00093 char txbuf[TXBUF_SIZE];
00094
00095 Bool b_report_pending=FALSE;
00096
00097
00098
00099
00100
00105 void device_full_custom_task_init(void)
00106 {
00107 sof_cnt = 0;
00108 #ifndef FREERTOS_USED
00109 #if USB_HOST_FEATURE == ENABLED
00110
00111
00112
00113 if (Is_usb_device())
00114 #endif // USB_HOST_FEATURE == ENABLED
00115 Usb_enable_sof_interrupt();
00116 #endif // FREERTOS_USED
00117
00118
00119 LED_Off( LED_MONO0_GREEN );
00120 LED_Off( LED_MONO1_GREEN );
00121 LED_Off( LED_MONO2_GREEN );
00122 LED_Off( LED_MONO3_GREEN );
00123
00124
00125 accelerometer_init();
00126
00127 #ifdef FREERTOS_USED
00128 xTaskCreate(device_full_custom_task,
00129 configTSK_USB_DFC_NAME,
00130 configTSK_USB_DFC_STACK_SIZE,
00131 NULL,
00132 configTSK_USB_DFC_PRIORITY,
00133 NULL);
00134 #endif // FREERTOS_USED
00135 }
00136
00137
00138
00139 static U32 build_answer( char* output, const char * log)
00140 {
00141 return sprintf( output, "%s|00/00/00 00:00:00|", log);
00142 }
00143
00144
00145
00149 #ifdef FREERTOS_USED
00150 void device_full_custom_task(void *pvParameters)
00151 #else
00152 void device_full_custom_task(void)
00153 #endif
00154 {
00155 U32 time=0;
00156 Bool startup=TRUE;
00157
00158 #ifdef FREERTOS_USED
00159 portTickType xLastWakeTime;
00160
00161 xLastWakeTime = xTaskGetTickCount();
00162 while (TRUE)
00163 {
00164 vTaskDelayUntil(&xLastWakeTime, configTSK_USB_DFC_PERIOD);
00165
00166 if( startup )
00167 {
00168 time+=configTSK_USB_DFC_PERIOD;
00169 #define STARTUP_LED_DELAY 100
00170 if ( time== 1*STARTUP_LED_DELAY ) LED_On( LED_MONO0_GREEN );
00171 else if( time== 2*STARTUP_LED_DELAY ) LED_On( LED_MONO1_GREEN );
00172 else if( time== 3*STARTUP_LED_DELAY ) LED_On( LED_MONO2_GREEN );
00173 else if( time== 4*STARTUP_LED_DELAY ) LED_On( LED_MONO3_GREEN );
00174 else if( time== 5*STARTUP_LED_DELAY ) LED_Off( LED_MONO0_GREEN );
00175 else if( time== 6*STARTUP_LED_DELAY ) LED_Off( LED_MONO1_GREEN );
00176 else if( time== 7*STARTUP_LED_DELAY ) LED_Off( LED_MONO2_GREEN );
00177 else if( time== 8*STARTUP_LED_DELAY ) LED_Off( LED_MONO3_GREEN );
00178 else if( time== 9*STARTUP_LED_DELAY ) startup=FALSE;
00179 }
00180
00181
00182 if (!Is_device_enumerated()) continue;
00183 #else
00184
00185 if (!Is_device_enumerated()) return;
00186 #endif // FREERTOS_USED
00187
00188 if(Is_usb_out_received(EP_FC_OUT))
00189 {
00190 U32 nchar;
00191 Usb_reset_endpoint_fifo_access(EP_FC_OUT);
00192 memset(rxbuf, 0, RXBUF_SIZE);
00193 usb_read_ep_rxpacket(EP_FC_OUT, &rxbuf, RXBUF_SIZE, NULL);
00194 Usb_ack_out_received_free(EP_FC_OUT);
00195
00196 if( !strcmp((const char*)rxbuf, "get_sensor_value sensor=temp") )
00197 {
00198 nchar=build_answer(txbuf, "temp");
00199 b_temperature_get_value( txbuf+nchar );
00200 b_report_pending=TRUE;
00201 }
00202
00203 else if( !strcmp((const char*)rxbuf, "get_sensor_value sensor=js") )
00204 {
00205 nchar=build_answer(txbuf, "js");
00206 b_joystick_get_value( txbuf+nchar );
00207 b_report_pending=TRUE;
00208 }
00209
00210 else if( !strcmp((const char*)rxbuf, "get_sensor_value sensor=pb1") )
00211 {
00212 nchar=build_answer(txbuf, "pb1");
00213 b_pushb1_get_value( txbuf+nchar );
00214 b_report_pending=TRUE;
00215 }
00216
00217 else if( !strcmp((const char*)rxbuf, "get_sensor_value sensor=pb2") )
00218 {
00219 nchar=build_answer(txbuf, "pb2");
00220 b_pushb2_get_value( txbuf+nchar );
00221 b_report_pending=TRUE;
00222 }
00223
00224 #if BOARD == EVK1100
00225 else if( !strcmp((const char*)rxbuf, "get_sensor_value sensor=pb3") )
00226 {
00227 nchar=build_answer(txbuf, "pb3");
00228 sprintf( txbuf+nchar, "RELEASE\r\n");
00229 b_report_pending=TRUE;
00230 }
00231 #endif
00232
00233 else if( !strcmp((const char*)rxbuf, "get_sensor_value sensor=light") )
00234 {
00235 U32 value;
00236 nchar=build_answer(txbuf, "light");
00237 b_light_get_value( txbuf+nchar, &value );
00238 e_ledm_refresh_intensity( value );
00239 b_report_pending=TRUE;
00240 }
00241
00242
00243 else if( !strcmp((const char*)rxbuf, "get_actuator_value actuator=ledm1") )
00244 {
00245 nchar=build_answer(txbuf, "ledm1");
00246 b_ledm1_get_value( txbuf+nchar );
00247 b_report_pending=TRUE;
00248 }
00249 else if( !strcmp((const char*)rxbuf, "get_actuator_value actuator=ledm2") )
00250 {
00251 nchar=build_answer(txbuf, "ledm2");
00252 b_ledm2_get_value( txbuf+nchar );
00253 b_report_pending=TRUE;
00254 }
00255 else if( !strcmp((const char*)rxbuf, "get_actuator_value actuator=ledm3") )
00256 {
00257 nchar=build_answer(txbuf, "ledm3");
00258 b_ledm3_get_value( txbuf+nchar );
00259 b_report_pending=TRUE;
00260 }
00261 else if( !strcmp((const char*)rxbuf, "get_actuator_value actuator=ledm4") )
00262 {
00263 nchar=build_answer(txbuf, "ledm4");
00264 b_ledm4_get_value( txbuf+nchar );
00265 b_report_pending=TRUE;
00266 }
00267
00268
00269 else if( !strncmp((const char*)rxbuf, STR_SET_LEDM1, strlen(STR_SET_LEDM1)) )
00270 {
00271 nchar=build_answer(txbuf, "ledm1");
00272 e_ledm1_set_value(rxbuf+strlen(STR_SET_LEDM1), txbuf+nchar);
00273 b_report_pending=TRUE;
00274 }
00275 else if( !strncmp((const char*)rxbuf, STR_SET_LEDM2, strlen(STR_SET_LEDM2)) )
00276 {
00277 nchar=build_answer(txbuf, "ledm2");
00278 e_ledm2_set_value(rxbuf+strlen(STR_SET_LEDM2), txbuf+nchar);
00279 b_report_pending=TRUE;
00280 }
00281 else if( !strncmp((const char*)rxbuf, STR_SET_LEDM3, strlen(STR_SET_LEDM3)) )
00282 {
00283 nchar=build_answer(txbuf, "ledm3");
00284 e_ledm3_set_value(rxbuf+strlen(STR_SET_LEDM2), txbuf+nchar);
00285 b_report_pending=TRUE;
00286 }
00287 else if( !strncmp((const char*)rxbuf, STR_SET_LEDM4, strlen(STR_SET_LEDM4)) )
00288 {
00289 nchar=build_answer(txbuf, "ledm4");
00290 e_ledm4_set_value(rxbuf+strlen(STR_SET_LEDM2), txbuf+nchar);
00291 b_report_pending=TRUE;
00292 }
00293
00294
00295 else if( !strcmp((const char*)rxbuf, "get_sensor_value sensor=accx") )
00296 {
00297 nchar=build_answer(txbuf, "accx");
00298 accelerometer_measure(0, txbuf+nchar);
00299 b_report_pending=TRUE;
00300 }
00301 else if( !strcmp((const char*)rxbuf, "get_sensor_value sensor=accy") )
00302 {
00303 nchar=build_answer(txbuf, "accy");
00304 accelerometer_measure(1, txbuf+nchar);
00305 b_report_pending=TRUE;
00306 }
00307 }
00308
00309 if( b_report_pending && Is_usb_in_ready(EP_FC_IN) )
00310 {
00311 U8 data_to_transfer;
00312 char* ptr_cram=txbuf;
00313
00314
00315 #if 0
00316 Usb_reset_endpoint_fifo_access(EP_FC_IN);
00317 usb_write_ep_txpacket(EP_FC_IN, &txbuf, TXBUF_SIZE, NULL);
00318 Usb_ack_in_ready_send(EP_FC_IN);
00319 #endif
00320
00321 data_to_transfer = strlen(txbuf);
00322 while (data_to_transfer)
00323 {
00324 while (!Is_usb_in_ready(EP_FC_IN));
00325
00326 Usb_reset_endpoint_fifo_access(EP_FC_IN);
00327 data_to_transfer = usb_write_ep_txpacket(EP_FC_IN, ptr_cram, data_to_transfer, (const void**)&ptr_cram);
00328 Usb_ack_in_ready_send(EP_FC_IN);
00329 }
00330 b_report_pending=FALSE;
00331 }
00332 #ifdef FREERTOS_USED
00333 }
00334 #endif
00335 }
00336
00337
00345 void usb_sof_action(void)
00346 {
00347 sof_cnt++;
00348 }
00349
00350
00351 #endif // USB_DEVICE_FEATURE == ENABLED