• Main Page
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

timer.c

Go to the documentation of this file.
00001 /*@{*//*@}*/
00015 
00016 /******************************************************************************/
00017 /* Includes (#include)                                                        */
00018 #include <avr/io.h>   //debug
00019 #include <avr/interrupt.h>
00020 
00021 /* Own headers */
00022 #include "xtypes.h"
00023 #include "global.h"
00024 
00025 #include "leds.h"
00026 #include "speed.h"
00027 #include "safety.h"
00028 #include "speaker.h"
00029 
00030 #define EXPORT
00031   #include "timer.h"
00032 #undef EXPORT
00033 
00034 /******************************************************************************/
00035 /* Constants (#define)                *//*@{*/
00036 
00038 #define OCR_VALUE     ((F_CPU / 64U) / 1000U) - 1U
00039 
00040 /* End: Constants (#define)                                             *//*@}*/
00041 /******************************************************************************/
00042 
00043 /******************************************************************************/
00044 /* Macro definitions (#define)           *//*@{*/
00045 /* End: Macro definitions (#define)                                     *//*@}*/
00046 /******************************************************************************/
00047 
00048 /******************************************************************************/
00049 /* Basic types (typedef)                 *//*@{*/
00050 /* End: Basic types (typedef)                                           *//*@}*/
00051 /******************************************************************************/
00052 
00053 /******************************************************************************/
00054 /* Local constants (const)      *//*@{*/
00055 /* End: Local constants (const)                                         *//*@}*/
00056 /******************************************************************************/
00057 
00058 /******************************************************************************/
00059 /* Local variables              *//*@{*/
00060 
00062 STATIC VOLATILE UINT32 mg_u32SystemTime  = 0U;
00063 
00065 STATIC VOLATILE UINT8  mg_u8Ticks        = NO_TICK;
00066 
00068          STATIC UINT8  mg_u8TicksOut     = NO_TICK;
00069 
00070 /* End: Local variables                                                 *//*@}*/
00071 /******************************************************************************/
00072 
00073 /******************************************************************************/
00074 /* Global variables           *//*@{*/
00075 /* End: Global variables                                                *//*@}*/
00076 /******************************************************************************/
00077 
00078 /******************************************************************************/
00079 /* Prototype declarations                                                     */
00080 /* End: Prototype declarations                                                */
00081 /******************************************************************************/
00082 
00083 /******************************************************************************/
00084 /* Local functions             *//*@{*/
00085 
00086 /* ****************************************************************************/
00105 /* ****************************************************************************/
00106 ISR(SIG_OUTPUT_COMPARE2A)
00107 {
00108   LOCAL_STATIC UINT8 u8Toggle = 0U;
00109   
00110   mg_u32SystemTime++;
00111   
00112   /* multiplexing the LEDs */
00113   u8Toggle++;
00114   if((u8Toggle & 0x01) != 0U)
00115   {
00116     leds_ShowVoltage();
00117   }
00118   else
00119   {
00120     leds_ShowCurrent();
00121   }
00122   
00123   if(0UL == (mg_u32SystemTime & 1023UL))
00124   {
00125     mg_u8Ticks |= (TICK128 | TICK256 | TICK512 |TICK1024);
00126   }
00127   else if(0UL == (mg_u32SystemTime & 511UL))
00128   {
00129     mg_u8Ticks |= (TICK128 | TICK256 | TICK512);
00130   }
00131   else if(0UL == (mg_u32SystemTime & 255UL))
00132   {
00133     mg_u8Ticks |= (TICK128 | TICK256);
00134   }
00135   else if(0UL == (mg_u32SystemTime & 63UL))
00136   {
00137     mg_u8Ticks |= (TICK128);
00138   }
00139   
00140   /* activate the speaker in case of a warning condition */
00141   if( (safety_GetCondition() &  (COND_CURR_WARN
00142                                 |COND_TEMP_WARN
00143                                 |COND_CURR_ERR
00144                                 |COND_TEMP_ERR)) != 0U )
00145   {
00146     if((mg_u32SystemTime & 256UL) == 0UL)
00147     {
00148       speaker_Buzz();
00149     }
00150   }
00151   else
00152   {
00153     speaker_Off();
00154   }
00155 }
00156 
00157 /* End: Local functions                                                 *//*@}*/
00158 /******************************************************************************/
00159 
00160 /******************************************************************************/
00161 /* Global functions          *//*@{*/
00162 
00163 /* ****************************************************************************/
00171 /* ****************************************************************************/
00172 void timer_Init (void)
00173 {
00174   // Timer2 einstellen
00175   TCCR2A  = (1<<WGM21);
00176   TCCR2B  = (1<<CS22);
00177   TCNT2   = 0U;
00178   OCR2A   = OCR_VALUE;
00179   TIMSK2 |= (1<<OCIE2A);
00180 }
00181 
00182 
00183 /* ****************************************************************************/
00193 /* ****************************************************************************/
00194 UINT8 timer_GetTicks (void)
00195 {
00196   return (mg_u8TicksOut);
00197 }
00198 
00199 
00200 /* ****************************************************************************/
00211 /* ****************************************************************************/
00212 void timer_LockTicks (void)
00213 {
00214   cli();
00215   mg_u8TicksOut = mg_u8Ticks;
00216   mg_u8Ticks    = NO_TICK;
00217   sei();
00218 }
00219 
00220 
00221 /* ****************************************************************************/
00232 /* ****************************************************************************/
00233 inline UINT32 timer_GetSystemTime(void)
00234 {
00235   UINT32 u32Ret;
00236   cli();
00237   u32Ret = mg_u32SystemTime;
00238   sei();
00239   return (u32Ret);
00240 }
00241 
00242 /* End: Global functions                                                *//*@}*/
00243 /******************************************************************************/
00244 
00245 /**** Last line of code                                                    ****/

Generated on Sun Jan 23 2011 14:05:40 for ULA replacement firmware by  doxygen 1.7.2