ui_sync_led.c

Go to the documentation of this file.
00001 
00010 #include <includes.h>
00011 
00012 #define FLASH_PERIOD_HALFQUARTER 125 //125ms
00013 #define FLASH_PERIOD_QUARTER 250 //250ms
00014 #define FLASH_PERIOD_HALF 500 //500ms
00015 #define FLASH_PERIOD_SEC 1000 //1000ms
00016 #define LED_ON_PERIOD 50  //50ms
00017 
00018 int led_on_flag = 0;
00019 int ts = 0;
00020 
00024 static INT_VOID_F led_get_timestamp = intvoid;
00025 
00030 void ui_sync_led_init(INT_VOID_F timestamp_in)
00031 {
00032   led_get_timestamp = timestamp_in;
00033   ui_sync_led_off();
00034 }
00035 
00039 void ui_sync_led_on(void)
00040 {
00041 //  ui_led_rgb(1, 100,0,0);   //LED1, red, at back
00042   FIO0SET = 1<<16;    //Green top LED on
00043 }
00044 
00048 void ui_sync_led_off(void)
00049 {
00050 //  ui_led_rgb(1, 0,0,0); //LED1, red, at back
00051   FIO0CLR = 1<<16;      //Green top LED off
00052 }
00053 
00058 void ui_sync_led_flash(void)
00059 {  
00060   static unsigned short flag = 0;
00061   unsigned long remainder;
00062 
00063   remainder = led_get_timestamp() % FLASH_PERIOD_HALFQUARTER;
00064   
00065   //This logic is intended to detect the first iteration at which the remainder
00066   //has passed zero, and to run the ui_sync_led_flash_pattern at that time only.
00067   //Note that the remainder is non-negative.
00068   if (remainder < (FLASH_PERIOD_HALFQUARTER >> 1))
00069   {
00070     if (flag)
00071     {
00072       ui_sync_led_flash_pattern();
00073     }
00074     flag = 0;       
00075   }
00076   else
00077   {
00078     flag = 1;
00079   } 
00080 }
00081 
00086 static void ui_sync_led_flash_pattern(void)
00087 {
00088   static int sync_flag = 0;
00089   static unsigned short flag = 0;
00090   unsigned long remainder = led_get_timestamp() % FLASH_PERIOD_SEC;
00091   int sync_count = (led_get_timestamp() / FLASH_PERIOD_HALFQUARTER) % 8;
00092 
00093   if(led_get_timestamp() - ts > LED_ON_PERIOD) led_on_flag = 0;
00094 
00095   //This logic is intended to detect the first iteration at which the remainder
00096   //has passed zero, and to run the ui_sync_led_flash_pattern at that time only.
00097   //Note that the remainder is non-negative.
00098   if (remainder < (FLASH_PERIOD_SEC >> 1))
00099   {
00100     if (flag)
00101     {
00102       sync_flag++;
00103       if (sync_flag >= 10)
00104       {
00105         sync_flag = 0;
00106       }     
00107       flag = 0;
00108     }       
00109   }
00110   else
00111   {
00112     flag = 1;
00113   }
00114   switch (sync_flag) {  
00115     case 0:
00116       if ((sync_count == 0) || (sync_count == 6)){
00117         led_on_flag = 1;
00118         ts = led_get_timestamp();
00119       } 
00120 //      else if (sync_count == 2){
00121 //        ui_sync_led_off();
00122 //      }
00123       break;   
00124     case 1:
00125       if (sync_count == 2){
00126         led_on_flag = 1;
00127         ts = led_get_timestamp();
00128       } 
00129 //      else if (sync_count == 4){
00130 //        ui_sync_led_off();
00131 //      } 
00132       break;     
00133     case 2:
00134       if ((sync_count == 0) || (sync_count == 4)){
00135         led_on_flag = 1;
00136         ts = led_get_timestamp();
00137       } 
00138 //      else if ((sync_count == 2) || (sync_count == 6)){
00139 //        ui_sync_led_off();
00140 //      }  
00141       break;     
00142     case 3:
00143       if ((sync_count == 0) || (sync_count == 7)){
00144         //ui_sync_led_on();
00145         led_on_flag = 1;
00146         ts = led_get_timestamp();
00147       } 
00148 //      else if (sync_count == 2){
00149 //        ui_sync_led_off();
00150 //      } 
00151       break;
00152     case 4:
00153       if ((sync_count == 2) || (sync_count == 6)){
00154         //ui_sync_led_on();
00155         led_on_flag = 1;
00156         ts = led_get_timestamp();
00157       } 
00158 //      if ((sync_count == 0) || (sync_count == 4)){
00159 //        ui_sync_led_off();
00160 //      } 
00161       break;
00162     case 5:
00163       if (sync_count == 2){
00165         led_on_flag = 1;
00166         ts = led_get_timestamp();
00167       } 
00168 //      else if ((sync_count == 0) || (sync_count == 4)){
00169 //        ui_sync_led_off();
00170 //      } 
00171       break;
00172     case 6:
00173       if ((sync_count == 0) || (sync_count == 4)){
00174         ui_sync_led_on();
00175       } 
00176 //      else if ((sync_count == 2) || (sync_count == 6)){
00177 //        ui_sync_led_off();
00178 //      }  
00179       break;
00180     case 7:
00181       if ((sync_count == 0) || (sync_count == 4)){
00182         //ui_sync_led_on();
00183         led_on_flag = 1;
00184         ts = led_get_timestamp();
00185       } 
00186 //      else if ((sync_count == 2) || (sync_count == 6)){
00187 //        ui_sync_led_off();
00188 //      } 
00189       break;
00190     case 8:
00191       if ((sync_count == 0) || (sync_count == 4) || (sync_count == 6)){
00192         //ui_sync_led_on();
00193         led_on_flag = 1;
00194         ts = led_get_timestamp();
00195       } 
00196 //      else if ((sync_count == 2) || (sync_count == 5) || (sync_count == 7)){
00197 //        ui_sync_led_off();
00198 //      }
00199       break;
00200       
00201     case 9:
00202       if ((sync_count == 0) || (sync_count == 2) || (sync_count == 4) || (sync_count == 6)){
00203         //ui_sync_led_on();
00204         led_on_flag = 1;
00205         ts = led_get_timestamp();
00206       } 
00207 //      else if ((sync_count == 1) || (sync_count == 3) || (sync_count == 5) || (sync_count == 7)){
00208 //        ui_sync_led_off();
00209 //      }
00210       break;           
00211   }
00212 
00213   //flash LED
00214   if(led_on_flag == 1) ui_sync_led_on();
00215   else ui_sync_led_off();
00216 }
00217 
00218 
00219 
00220 
Generated on Tue Jun 29 16:36:14 2010 by  doxygen 1.6.3