00001
00015
00016
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 #include <string.h>
00047
00048 #include "compiler.h"
00049
00050 #include "gpio.h"
00051
00052
00053 #include "FreeRTOS.h"
00054 #include "task.h"
00055
00056 #include "datalog.h"
00057 #include "shell.h"
00058 #include "board.h"
00059 #include "sensor.h"
00060 #include "config_file.h"
00061 #include "fsaccess.h"
00062
00063 #include "MMI.h"
00064
00065 #include "BasicSMTP.h"
00066
00067
00068
00070 #define JS_GETCONF_MAXLEN 16
00071
00073 #define JS_NB_EVENT 32
00074
00076 #define JS_EVENT_PUSH 0x01
00077 #define JS_EVENT_LEFT 0x02
00078 #define JS_EVENT_RIGHT 0x04
00079 #define JS_EVENT_UP 0x08
00080 #define JS_EVENT_DOWN 0x10
00081
00083 #define SENSOR_JS_CONFIG_FILE "A:/CFG/JS.TXT"
00084
00085
00086
00088 const signed portCHAR *acpc_js_events[JS_NB_EVENT] = {
00089 (signed portCHAR *)"RELEASE",(signed portCHAR *)"PRESS",(signed portCHAR *)"LEFT",(signed portCHAR *)"LEFT/PRESS",
00090 (signed portCHAR *)"RIGHT",(signed portCHAR *)"RIGHT/PRESS",(signed portCHAR *)"?",(signed portCHAR *)"?",
00091 (signed portCHAR *)"UP",(signed portCHAR *)"UP/PRESS",(signed portCHAR *)"UP/LEFT",(signed portCHAR *)"UP/LEFT/PRESS",
00092 (signed portCHAR *)"UP/RIGHT",(signed portCHAR *)"UP/RIGHT/PRESS",(signed portCHAR *)"?",(signed portCHAR *)"?",
00093 (signed portCHAR *)"DOWN",(signed portCHAR *)"DOWN/PRESS",(signed portCHAR *)"DOWN/LEFT",(signed portCHAR *)"DOWN/LEFT/PRESS",
00094 (signed portCHAR *)"DOWN/RIGHT",(signed portCHAR *)"DOWN/RIGHT/PRESS",(signed portCHAR *)"?",(signed portCHAR *)"?",
00095 (signed portCHAR *)"?",(signed portCHAR *)"?",(signed portCHAR *)"?",(signed portCHAR *)"?",
00096 (signed portCHAR *)"?",(signed portCHAR *)"?",(signed portCHAR *)"?",(signed portCHAR *)"?",
00097 };
00098
00100 static unsigned short x_joystick = 0;
00101
00103 static Bool bAlarm = FALSE;
00104
00106 static U32 u32LastCountValue = 0;
00107
00109 extern xSemaphoreHandle xCFGMutex;
00110
00111
00112
00113
00114 #if defined(__GNUC__)
00115 __attribute__((__naked__))
00116 #elif defined(__ICCAVR32__)
00117 #pragma shadow_registers = full // Naked.
00118 #endif
00119 void vjoystick_ISR( void );
00120
00121
00122 #ifdef __GNUC__
00123 __attribute__((__noinline__))
00124 #endif
00125 static portBASE_TYPE prvjoystick_ISR_NonNakedBehaviour( void );
00126
00127
00133 Bool b_joystick_init ( void )
00134 {
00135 portCHAR token[6];
00136
00137
00138 if( pdTRUE == x_supervisor_SemaphoreTake( xCFGMutex, 0 ) )
00139 {
00140
00141 if (config_file_get_value(SENSOR_JS_CONFIG_FILE, "alarm" , token) >= 0)
00142 {
00143
00144 if (!strcmp(token, "on"))
00145 {
00146 bAlarm = pdTRUE;
00147 }
00148 }
00149
00150 x_supervisor_SemaphoreGive( xCFGMutex );
00151 }
00152
00153 gpio_enable_pin_interrupt(GPIO_JOYSTICK_UP , GPIO_PIN_CHANGE);
00154
00155 gpio_enable_pin_interrupt(GPIO_JOYSTICK_DOWN , GPIO_PIN_CHANGE);
00156
00157 gpio_enable_pin_interrupt(GPIO_JOYSTICK_RIGHT , GPIO_PIN_CHANGE);
00158
00159 gpio_enable_pin_interrupt(GPIO_JOYSTICK_LEFT , GPIO_PIN_CHANGE);
00160
00161 gpio_enable_pin_interrupt(GPIO_JOYSTICK_PUSH , GPIO_PIN_CHANGE);
00162
00163 Disable_global_interrupt();
00164
00165 INTC_register_interrupt( (__int_handler)&vjoystick_ISR, AVR32_GPIO_IRQ_0 + (GPIO_JOYSTICK_UP/8), AVR32_INTC_INT3);
00166 INTC_register_interrupt( (__int_handler)&vjoystick_ISR, AVR32_GPIO_IRQ_0 + (GPIO_JOYSTICK_PUSH/8), AVR32_INTC_INT3);
00167
00168 Enable_global_interrupt();
00169 return (TRUE);
00170 }
00171
00175 void v_joystick_stop( void )
00176 {
00177
00178 gpio_disable_pin_interrupt( GPIO_JOYSTICK_UP );
00179 gpio_disable_pin_interrupt( GPIO_JOYSTICK_DOWN );
00180 gpio_disable_pin_interrupt( GPIO_JOYSTICK_RIGHT );
00181 gpio_disable_pin_interrupt( GPIO_JOYSTICK_LEFT );
00182 gpio_disable_pin_interrupt( GPIO_JOYSTICK_PUSH );
00183 }
00184
00185
00195 eExecStatus e_joystick_get_config( signed portCHAR **ppcStringReply )
00196 {
00197
00198 if ( bAlarm == TRUE )
00199 *ppcStringReply = (signed portCHAR *)SENSOR_MSG_ALARM_ON;
00200 else
00201
00202 *ppcStringReply = (signed portCHAR *)SENSOR_MSG_ALARM_OFF;
00203 return( SHELL_EXECSTATUS_OK_NO_FREE );
00204 }
00205
00215 eExecStatus e_joystick_set_config( signed portCHAR **ppcStringReply, int ac, signed portCHAR *av[] )
00216 {
00217
00218
00219 if (config_file_set_value(SENSOR_JS_CONFIG_FILE, ac, av) != 0)
00220 {
00221 *ppcStringReply = (signed portCHAR *)SHELL_ERRMSG_CONFIGERROR;
00222
00223 return( SHELL_EXECSTATUS_KO );
00224 }
00225
00226 if (!strcmp((char *)av[1] , "on"))
00227 {
00228 bAlarm = pdTRUE;
00229 *ppcStringReply = (signed portCHAR *)SENSOR_MSG_ALARM_ON;
00230 return( SHELL_EXECSTATUS_OK_NO_FREE );
00231 }
00232
00233 else if (!strcmp( (char *)av[1], "off"))
00234 {
00235 bAlarm = pdFALSE;
00236 *ppcStringReply = (signed portCHAR *)SENSOR_MSG_ALARM_OFF;
00237 return( SHELL_EXECSTATUS_OK_NO_FREE );
00238 }
00239
00240 else
00241 {
00242 *ppcStringReply = (signed portCHAR *)SHELL_ERRMSG_CONFIGERROR;
00243 return( SHELL_EXECSTATUS_KO );
00244 }
00245 }
00246
00254 Bool b_joystick_get_value( xLogDef *pxLog )
00255 {
00256
00257
00258 pxLog->pfFreeStringLog = NULL;
00259 pxLog->pcStringLog = (portCHAR *)acpc_js_events[x_joystick];
00260
00261 return( TRUE );
00262 }
00263
00264
00268 #if defined(__GNUC__)
00269 __attribute__((__naked__))
00270 #elif defined(__ICCAVR32__)
00271 #pragma shadow_registers = full // Naked.
00272 #endif
00273 void vjoystick_ISR( void )
00274 {
00275
00276
00277
00278 portENTER_SWITCHING_ISR();
00279
00280 prvjoystick_ISR_NonNakedBehaviour();
00281
00282 portEXIT_SWITCHING_ISR();
00283 }
00284
00288 #if defined(__GNUC__)
00289 __attribute__((__noinline__))
00290 #elif defined(__ICCAVR32__)
00291 #pragma optimize = no_inline
00292 #endif
00293 static portBASE_TYPE prvjoystick_ISR_NonNakedBehaviour( void )
00294 {
00295 xLogDef *pxLog;
00296 U32 u32CurrentCountValue = xTaskGetTickCount();
00297
00298
00299
00300
00301 if((( u32CurrentCountValue >= u32LastCountValue )
00302 && ( u32CurrentCountValue - u32LastCountValue <= 250))
00303 ||
00304 (( u32CurrentCountValue < u32LastCountValue )
00305 && ( u32CurrentCountValue + (0xFFFFFFFF - u32LastCountValue) <= 250)))
00306 {
00307
00308 gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_PUSH);
00309 Clr_bits(x_joystick, JS_EVENT_PUSH);
00310 gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_LEFT);
00311 Clr_bits(x_joystick, JS_EVENT_LEFT);
00312 gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_RIGHT);
00313 Clr_bits(x_joystick, JS_EVENT_RIGHT);
00314 gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_UP);
00315 Clr_bits(x_joystick, JS_EVENT_UP);
00316 gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_DOWN);
00317 Clr_bits(x_joystick, JS_EVENT_DOWN);
00318 return(pdFALSE);
00319 }
00320 else
00321 {
00322
00323 u32LastCountValue = u32CurrentCountValue;
00324
00325
00326 if (gpio_get_pin_interrupt_flag(GPIO_JOYSTICK_UP))
00327 {
00328
00329 if (gpio_get_pin_value(GPIO_JOYSTICK_UP))
00330 {
00331
00332 Clr_bits(x_joystick, JS_EVENT_UP);
00333 }
00334 else
00335 {
00336 Set_bits(x_joystick, JS_EVENT_UP);
00337 }
00338
00339 gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_UP);
00340 }
00341 if (gpio_get_pin_interrupt_flag(GPIO_JOYSTICK_DOWN))
00342 {
00343
00344 if (gpio_get_pin_value(GPIO_JOYSTICK_DOWN))
00345 {
00346 Clr_bits(x_joystick, JS_EVENT_DOWN);
00347 }
00348 else
00349 {
00350 Set_bits(x_joystick, JS_EVENT_DOWN);
00351 }
00352
00353 gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_DOWN);
00354 }
00355 if (gpio_get_pin_interrupt_flag(GPIO_JOYSTICK_LEFT))
00356 {
00357
00358 if (gpio_get_pin_value(GPIO_JOYSTICK_LEFT))
00359 {
00360 Clr_bits(x_joystick, JS_EVENT_LEFT);
00361 }
00362 else
00363 {
00364 Set_bits(x_joystick, JS_EVENT_LEFT);
00365 #ifdef MMILCD_ENABLE
00366 vMMI_UserMenuDisplayPreviousItem(pdTRUE);
00367 #endif
00368 }
00369
00370 gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_LEFT);
00371 }
00372 if (gpio_get_pin_interrupt_flag(GPIO_JOYSTICK_RIGHT))
00373 {
00374
00375 if (gpio_get_pin_value(GPIO_JOYSTICK_RIGHT))
00376 {
00377 Clr_bits(x_joystick, JS_EVENT_RIGHT);
00378 }
00379 else
00380 {
00381 Set_bits(x_joystick, JS_EVENT_RIGHT);
00382 #ifdef MMILCD_ENABLE
00383 vMMI_UserMenuDisplayNextItem(pdTRUE);
00384 #endif
00385 }
00386
00387 gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_RIGHT);
00388 }
00389 if (gpio_get_pin_interrupt_flag(GPIO_JOYSTICK_PUSH))
00390 {
00391
00392 if (gpio_get_pin_value(GPIO_JOYSTICK_PUSH))
00393 {
00394 Clr_bits(x_joystick, JS_EVENT_PUSH);
00395 }
00396 else
00397 {
00398 Set_bits(x_joystick, JS_EVENT_PUSH);
00399 if ( bAlarm == pdTRUE )
00400 {
00401
00402 v_SMTP_PostFromISR("Joystick Alarm", NULL);
00403 }
00404
00405 #ifdef MMILCD_ENABLE
00406 vMMI_UserMenuValidateItem(pdTRUE);
00407 #endif
00408 }
00409
00410 gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_PUSH);
00411 }
00412 }
00413
00414 pxLog = pxdatalog_log_alloc_init_FromISR();
00415 if( NULL == pxLog )
00416 return( pdFALSE );
00417
00418 pxLog->id = DATALOG_ID_JS;
00419
00420 pxLog->pcStringLog = (portCHAR *)acpc_js_events[x_joystick];
00421
00422 pxLog->pfFreeStringLog = NULL;
00423
00424 return( x_datalog_AddLogFromISR( pxLog ) );
00425 }