csr_leds.c

00001 #include <includes.h>
00002 
00003 //Global LED blink variables
00004 volatile unsigned short csr_red_can1_time = 0, csr_green_can1_time = 0;
00005 volatile unsigned short csr_red_can2_time = 0, csr_green_can2_time = 0;
00006 volatile unsigned short csr_red_can3_time = 0, csr_green_can3_time = 0;
00007 volatile unsigned short csr_red_can4_time = 0, csr_green_can4_time = 0;
00008 
00009 volatile unsigned short csr_red_mcu_time = 0, csr_green_mcu_time = 0, csr_blue_mcu_time = 0;
00010 
00011 //CAN bus loading globals
00012 volatile short unsigned int csr_can1_packet_rate = 0;
00013 volatile short unsigned int csr_can2_packet_rate = 0;
00014 volatile short unsigned int csr_can3_packet_rate = 0;
00015 volatile short unsigned int csr_can4_packet_rate = 0; 
00016 
00018 void csr_can1_packet_count(void)
00019 {
00020   ++csr_can1_packet_rate;
00021 }
00022 
00023 void csr_can2_packet_count(void)
00024 {
00025   ++csr_can2_packet_rate;
00026 }
00027 
00028 void csr_can3_packet_count(void)
00029 {
00030   ++csr_can3_packet_rate;
00031 }
00032 
00033 void csr_can4_packet_count(void)
00034 {
00035   ++csr_can4_packet_rate;
00036 }
00038 
00040 void csr_update_mcu_leds(void)
00041 {
00042 /*
00043   if (FIO1PIN & 25) //ARM9 controls MCU G/R LEDs while blue LED is off
00044   {
00045     if (FIO0PIN & 1<<15)     //LPC3250 GPIO_0
00046     {
00047      MCU_LED_GREEN_ON;    //turn on green ARM7 MCU LED
00048     }
00049     else
00050     {
00051      MCU_LED_GREEN_OFF;    //turn off green ARM7 MCU LED
00052     }
00053 
00054     if (FIO0PIN & 1<<16)     //LPC3250 GPIO_1
00055     {
00056       MCU_LED_RED_ON;     // turn on red MCU LED
00057     }
00058     else
00059     {
00060       MCU_LED_RED_OFF;    // turn off red MCU LED
00061     }  
00062   }
00063   else  //ARM7 controls MCU G/R LEDs while blue LED is on
00064   */  // *** test code
00065   
00066   {
00067     if (csr_red_mcu_time > 0)
00068     {
00069       --csr_red_mcu_time;
00070       MCU_LED_RED_ON;
00071     }
00072     else
00073     {
00074       MCU_LED_RED_OFF;
00075     }
00076   
00077     if (csr_green_mcu_time > 0)
00078     {
00079       --csr_green_mcu_time;
00080       MCU_LED_GREEN_ON;
00081     }
00082     else
00083     {
00084       MCU_LED_GREEN_OFF;
00085     }
00086     
00087     if (csr_blue_mcu_time > 0)
00088     {
00089       --csr_blue_mcu_time;
00090       MCU_LED_BLUE_ON;
00091     }
00092     else
00093     {
00094       MCU_LED_BLUE_OFF;
00095     }
00096     
00097   }
00098 }
00100 
00102 
00103 void csr_mcu_red_led_blink(short unsigned int time)
00104 {
00105   csr_red_mcu_time = time;
00106 }
00107 
00108 void csr_mcu_green_led_blink(short unsigned int time)
00109 {
00110   csr_green_mcu_time = time;
00111 }
00112 
00113 void csr_mcu_blue_led_blink(short unsigned int time)
00114 {
00115   csr_blue_mcu_time = time;
00116 }
00117 
00118 void csr_can1_red_led_blink(short unsigned int time)
00119 {
00120   csr_red_can1_time = time;
00121 }
00122 
00123 void csr_can1_green_led_blink(short unsigned int time)
00124 {
00125   csr_green_can1_time = time;
00126 }
00127 
00128 void csr_can2_red_led_blink(short unsigned int time)
00129 {
00130   csr_red_can2_time = time;
00131 }
00132 
00133 void csr_can2_green_led_blink(short unsigned int time)
00134 {
00135   csr_green_can2_time = time;
00136 }
00137 
00138 void csr_can3_red_led_blink(short unsigned int time)
00139 {
00140   csr_red_can3_time = time;
00141 }
00142 
00143 void csr_can3_green_led_blink(short unsigned int time)
00144 {
00145   csr_green_can3_time = time;
00146 }
00147 
00148 void csr_can4_red_led_blink(short unsigned int time)
00149 {
00150   csr_red_can4_time = time;
00151 }
00152 
00153 void csr_can4_green_led_blink(short unsigned int time)
00154 {
00155   csr_green_can4_time = time;
00156 }
00158 void csr_update_can_leds(void)
00159 {
00160   static short unsigned int i = 0;
00161 
00162   if (csr_red_can1_time > 0)
00163   {
00164     --csr_red_can1_time;
00165     CAN1_LED_RED_ON;
00166   }
00167   else
00168   {
00169     CAN1_LED_RED_OFF;
00170   }
00171   
00172   if (csr_green_can1_time > 0)
00173   {
00174     --csr_green_can1_time;
00175     CAN1_LED_GREEN_ON;
00176   }
00177   else
00178   {
00179     CAN1_LED_GREEN_OFF;
00180   }
00181   
00182   if (csr_red_can2_time > 0)
00183   {
00184     --csr_red_can2_time;
00185     CAN2_LED_RED_ON;
00186   }
00187   else
00188   {
00189     CAN2_LED_RED_OFF;
00190   }
00191   
00192   if (csr_green_can2_time > 0)
00193   {
00194     --csr_green_can2_time;
00195     CAN2_LED_GREEN_ON;
00196   }
00197   else
00198   {
00199     CAN2_LED_GREEN_OFF;
00200   }
00201   
00202   if (csr_red_can3_time > 0)
00203   {
00204     --csr_red_can3_time;
00205     CAN3_LED_RED_ON;
00206   }
00207   else
00208   {
00209     CAN3_LED_RED_OFF;
00210   }
00211   
00212   if (csr_green_can3_time > 0)
00213   {
00214     --csr_green_can3_time;
00215     CAN3_LED_GREEN_ON;
00216   }
00217   else
00218   {
00219     CAN3_LED_GREEN_OFF;
00220   }
00221   
00222   if (csr_red_can4_time > 0)
00223   {
00224     --csr_red_can4_time;
00225     CAN4_LED_RED_ON;
00226   }
00227   else
00228   {
00229     CAN4_LED_RED_OFF;
00230   }
00231   
00232   if (csr_green_can4_time > 0)
00233   {
00234     --csr_green_can4_time;
00235     CAN4_LED_GREEN_ON;
00236   }
00237   else
00238   {
00239     CAN4_LED_GREEN_OFF;
00240   }
00241   
00242   
00243   //Light up green LEDs for a time proportional to CAN bus loading
00244   ++i;
00245   if (i >= 10)
00246   {
00247     i = 0;
00248     if (csr_can1_packet_rate > 0){csr_green_can1_time = (csr_can1_packet_rate >> 4);}
00249     if (csr_can2_packet_rate > 0){csr_green_can2_time = (csr_can2_packet_rate >> 4);}
00250     if (csr_can3_packet_rate > 0){csr_green_can3_time = (csr_can3_packet_rate >> 4);}
00251     if (csr_can4_packet_rate > 0){csr_green_can4_time = (csr_can4_packet_rate >> 4);}
00252     
00253     //Error checks - send error or warning if CAN loading too high
00254   
00255     //Reset packet rate/CAN loading variables
00256     csr_can1_packet_rate = 0;
00257     csr_can2_packet_rate = 0;
00258     csr_can3_packet_rate = 0;
00259     csr_can4_packet_rate = 0;     
00260   }    
00261 }
Generated on Tue Jun 29 16:36:14 2010 by  doxygen 1.6.3