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

pedal.c

Go to the documentation of this file.
00001 /*@{*//*@}*/
00014 
00015 /******************************************************************************/
00016 /* Includes (#include)                                                        */
00017 #include <avr/io.h>
00018 #include <avr/interrupt.h>
00019 
00020 /* Own header files */
00021 #include "xtypes.h"
00022 #include "global.h"
00023 
00024 #include "timer.h"
00025 #include "memory.h"
00026 
00027 #define EXPORT
00028   #include "pedal.h"
00029 #undef EXPORT
00030 
00031 /******************************************************************************/
00032 /* Constants (#define)                *//*@{*/
00033 /* End: Constants (#define)                                             *//*@}*/
00034 /******************************************************************************/
00035 
00036 /******************************************************************************/
00037 /* Macro definitions (#define)           *//*@{*/
00038 
00040 #define PEDAL_INT_ENABLE()  EIMSK |=  (1<<INT1);
00041 
00043 #define PEDAL_INT_DISABLE() EIMSK &= ~(1<<INT1);
00044 
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_u32TickTime;
00063 
00065 STATIC VOLATILE UINT32 mg_u32Rpm;
00066 
00068 STATIC UINT8  mg_u8NumMagnetsPedal  = DEFAULT_MAGNET_NUMBER_PEDAL;
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 /* ****************************************************************************/
00098 /* ****************************************************************************/
00099 ISR (SIG_INTERRUPT1)
00100 {
00101   LOCAL_STATIC  UINT32  u32CurrentTime;
00102                 UINT32  u32DiffTime;
00103   
00104   PEDAL_INT_DISABLE();
00105   
00106   u32CurrentTime = timer_GetSystemTime();
00107   u32DiffTime = u32CurrentTime - mg_u32TickTime;
00108   if(0UL != u32DiffTime)
00109   {
00110     mg_u32TickTime = u32CurrentTime;
00111     mg_u32Rpm = ONE_MINUTE_MS / u32DiffTime / mg_u8NumMagnetsPedal;
00112   }
00113   
00114   PEDAL_INT_ENABLE();
00115 }
00116 
00117 /* End: Local functions                                                 *//*@}*/
00118 /******************************************************************************/
00119 
00120 /******************************************************************************/
00121 /* Global functions          *//*@{*/
00122 
00123 /* ****************************************************************************/
00131 /* ****************************************************************************/
00132 void pedal_Init (void)
00133 {
00134   mg_u8NumMagnetsPedal  = memory_Get()->u8NumMagnetsPedal;
00135   
00136   INT1_DDR  &= ~(1U << INT1_BIT);   /* set ext. interrupt pin as input pin */
00137   
00138   /* setup for falling edge */
00139   EICRA |=  (1<<ISC11);
00140   EICRA &= ~(1<<ISC10);
00141   
00142   mg_u32TickTime  = 0UL;
00143   mg_u32Rpm       = 0UL;
00144   
00145   /* enable interrupt */
00146   PEDAL_INT_ENABLE();
00147 }
00148 
00149 
00150 /* ****************************************************************************/
00169 /* ****************************************************************************/
00170 UINT32 pedal_GetTimeout (void)
00171 {
00172   UINT32 u32SysTime;
00173   UINT32 u32TickTime;
00174   UINT32 u32Ret;
00175   
00176   u32SysTime = timer_GetSystemTime();
00177   asm("nop");
00178   cli();
00179   u32TickTime = mg_u32TickTime;
00180   sei();
00181   
00182   u32Ret = u32SysTime - u32TickTime;
00183   if(u32Ret > PEDAL_TIMEOUT)
00184   {
00185     mg_u32Rpm = 0UL;
00186     u32Ret = PEDAL_TIMEOUT;
00187   }
00188   
00189   return(u32Ret);
00190 }
00191 
00192 
00193 /* ****************************************************************************/
00204 /* ****************************************************************************/
00205 UINT32 pedal_GetRpm (void)
00206 {
00207   UINT32 u32Ret;
00208   cli();
00209   u32Ret = mg_u32Rpm;
00210   sei();
00211   return (u32Ret);
00212 }
00213 
00214 
00215 /* End: Global functions                                                *//*@}*/
00216 /******************************************************************************/
00217 
00218 /**** Last line of code                                                    ****/

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