This file manages the USB device control panel task.
Definition in file device_ctrl_panel_task.h.
#include "conf_usb.h"
Go to the source code of this file.
Functions | |
void | device_full_custom_task (void *pvParameters) |
Entry point of the device full custom task management. | |
void | device_full_custom_task_init (void) |
This function initializes the hardware/software resources required for the USB Full custom task. | |
void | usb_sof_action (void) |
usb_sof_action |
void device_full_custom_task | ( | void * | pvParameters | ) |
Entry point of the device full custom task management.
Definition at line 150 of file device_ctrl_panel_task.c.
References accelerometer_measure(), b_joystick_get_value(), b_ledm1_get_value(), b_ledm2_get_value(), b_ledm3_get_value(), b_ledm4_get_value(), b_light_get_value(), b_pushb1_get_value(), b_pushb2_get_value(), b_report_pending, b_temperature_get_value(), build_answer(), configTSK_USB_DFC_PERIOD, data_to_transfer, e_ledm1_set_value(), e_ledm2_set_value(), e_ledm3_set_value(), e_ledm4_set_value(), e_ledm_refresh_intensity(), EP_FC_IN, EP_FC_OUT, rxbuf, RXBUF_SIZE, STARTUP_LED_DELAY, STR_SET_LEDM1, STR_SET_LEDM2, STR_SET_LEDM3, STR_SET_LEDM4, txbuf, and TXBUF_SIZE.
Referenced by device_full_custom_task_init().
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 // First, check the device enumeration state 00182 if (!Is_device_enumerated()) continue; 00183 #else 00184 // First, check the device enumeration state 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 //printf("Received %s\n\r", rxbuf); 00196 if( !strcmp((const char*)rxbuf, "get_sensor_value sensor=temp") ) 00197 { // Temperature sensor 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 { // Joystick 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 { // Push button 1 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 { // Push button 2 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 { // Push button 3 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 { // light 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 { // led1 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 { // led2 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 { // led3 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 { // led4 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 { // led1 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 { // led2 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 { // led3 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 { // led4 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 { // accelerometer 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 { // accelerometer 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 //printf( "Sending %s", txbuf); 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 }
void device_full_custom_task_init | ( | void | ) |
This function initializes the hardware/software resources required for the USB Full custom task.
Definition at line 105 of file device_ctrl_panel_task.c.
References accelerometer_init(), configTSK_USB_DFC_NAME, configTSK_USB_DFC_PRIORITY, configTSK_USB_DFC_STACK_SIZE, device_full_custom_task(), and sof_cnt.
Referenced by main().
00106 { 00107 sof_cnt = 0; 00108 #ifndef FREERTOS_USED 00109 #if USB_HOST_FEATURE == ENABLED 00110 // If both device and host features are enabled, check if device mode is engaged 00111 // (accessing the USB registers of a non-engaged mode, even with load operations, 00112 // may corrupt USB FIFO data). 00113 if (Is_usb_device()) 00114 #endif // USB_HOST_FEATURE == ENABLED 00115 Usb_enable_sof_interrupt(); 00116 #endif // FREERTOS_USED 00117 00118 // Initialize Leds state 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 // Initialize accelerometer sensor 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 }