]> rtime.felk.cvut.cz Git - fpga/lx-cpu1/lx-dad.git/blob - sw/app/lx_dad/appl_loop.c
95f5cad0c0de2cce3b4a4099c7012fd0a4ad0ea7
[fpga/lx-cpu1/lx-dad.git] / sw / app / lx_dad / appl_loop.c
1 #include <system_def.h>
2 #include <stdio.h>
3 #include <hal_machperiph.h>
4
5 #include <lt_timer.h>
6
7 #include "appl_defs.h"
8
9 int app_exit_request;
10
11 int timer_led_usbact_off;
12 int timer_led_usbconfigured;
13 int timer_str;
14
15 void timer_10ms(void)
16 {
17  #ifndef APPL_WITH_SIM_POSIX
18   if (timer_led_usbact_off!=0) timer_led_usbact_off--;
19   else SET_OUT_PIN(LED_PORT,LED2_BIT);
20  #ifdef APPL_WITH_ULAN
21   if (!timer_str) {
22     timer_str=10;
23     ul_stroke(ul_fd);
24   } else timer_str--;
25  #endif /*APPL_WITH_ULAN*/
26   if (timer_led_usbconfigured!=0) timer_led_usbconfigured--;
27   else {
28     timer_led_usbconfigured=20;
29     if (1 /*!ul_dcnv_is_open(&ep1_dcnv_state)*/) {
30       if(GET_IN_PIN(LED_PORT,LED1_BIT))
31         CLR_OUT_PIN(LED_PORT,LED1_BIT);
32       else
33         SET_OUT_PIN(LED_PORT,LED1_BIT);
34     }
35   }
36  #endif /*APPL_WITH_SIM_POSIX*/
37 }
38
39
40 void mloop()
41 {
42   lt_mstime_t ltime;
43
44   lt_mstime_t led1_time;
45   lt_mstime_t led2_time;
46
47   lt_mstime_update();
48   ltime=actual_msec;
49   led1_time=actual_msec;
50   led2_time=actual_msec;
51
52   while(!app_exit_request){
53
54     /* 10ms timer */
55     if (lt_10msec_expired(10)) {
56       timer_10ms();
57
58       #ifdef CONFIG_OC_MWENGINE
59        appl_update_indicators();
60       #endif /*CONFIG_OC_MWENGINE*/
61
62       #ifdef WATCHDOG_ENABLED
63         watchdog_feed();
64       #endif /* WATCHDOG_ENABLED */
65     }
66
67   #ifdef APPL_WITH_ULAN
68     if (ul_inepoll(ul_fd)>0) {
69       int free_fl = 0;
70       do {
71         /* processing of ulan messages */
72         if (ul_acceptmsg(ul_fd, &umsginfo)<0)
73           break;        /* No mesage reported - break */
74         free_fl = 1;
75         if (umsginfo.flg&(UL_BFL_PROC|UL_BFL_FAIL))
76           break;        /* Reported message informs about fault or carried out processing */
77
78         if(umsginfo.cmd==uloi_con_ulan_cmd(coninfo)){
79           if (uloi_process_msg(ULOI_ARG_coninfo (uloi_objdes_array_t*)&uloi_objdes_main, &umsginfo)>=0)
80             free_fl = 0;
81           break;
82         }
83        #ifdef CONFIG_ULAN_DY
84         if (umsginfo.cmd==UL_CMD_NCS) {
85           if(uldy_process_msg(ULDY_ARG_ul_dyac &umsginfo)>=0)
86             free_fl = 0;
87           break;
88         }
89        #endif /*CONFIG_ULAN_DY*/
90
91       } while(0);
92
93       if (free_fl)
94         ul_freemsg(ul_fd);
95     }
96    #ifdef CONFIG_ULAN_DY
97     /* test request for address */
98     if (uldy_rqa(ULDY_ARG1_ul_dyac))
99       uldy_addr_rq(ULDY_ARG1_ul_dyac);
100    #endif /*CONFIG_ULAN_DY*/
101   #endif /*APPL_WITH_ULAN*/
102
103     lt_mstime_update();
104     if((lt_msdiff_t)(actual_msec-ltime) > 5000){
105       ltime+=5000;
106
107     }
108
109    #ifdef APPL_RUN_AT_MAIN_LOOP
110     APPL_RUN_AT_MAIN_LOOP;
111    #endif /*APPL_RUN_AT_MAIN_LOOP*/
112
113    #ifdef CONFIG_OC_MWENGINE
114     gui_poll();
115    #endif /*CONFIG_OC_MWENGINE*/
116
117    #ifdef APPL_WITH_USB
118     if(usb_enable_flag) {
119       if(usb_app_poll()>0) {
120         timer_led_usbact_off=5;
121         CLR_OUT_PIN(LED_PORT,LED2_BIT);
122       }
123     }
124    #endif /*APPL_WITH_USB*/
125
126    #ifdef CONFIG_OC_CMDPROC
127     cmdproc_poll();
128    #endif /*CONFIG_OC_CMDPROC*/
129
130    #ifdef APPL_WITH_DISTORE_EEPROM_USER
131     appl_distore_user_change_check();
132    #endif /*APPL_WITH_DISTORE_EEPROM_USER*/
133   }
134 }