Subversion Repositories HomeAutomation

Rev

Rev 408 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. #ifndef timebase_h_
  2. #define timebase_h_
  3.  
  4.  
  5. /*-----------------------------------------------------------------------------
  6.  * Includes
  7.  *---------------------------------------------------------------------------*/
  8. #include <inttypes.h>
  9.  
  10.  
  11. /*-----------------------------------------------------------------------------
  12.  * Defines
  13.  *---------------------------------------------------------------------------*/
  14. /* Enable timer2 if you want to use as many PWM outputs as possible */
  15. #ifndef TIMEBASE_TIMER0
  16. #define TIMER2
  17. #endif
  18.  
  19. // Uncomment the following line to test the improved timebase implementation
  20. //#define TIMEBASE_NEW_IMPLEMENTATION
  21.  
  22. #define TIMEBASE_PRESCALE (64)
  23. #define TIMEBASE_HITS_PER_1MS (F_CPU/TIMEBASE_PRESCALE/1000)
  24.  
  25. #if TIMEBASE_HITS_PER_1MS > 255
  26. #undef TIMEBASE_PRESCALE
  27. #define TIMEBASE_PRESCALE (256)
  28. #undef TIMEBASE_HITS_PER_1MS
  29. #define TIMEBASE_HITS_PER_1MS (F_CPU/TIMEBASE_PRESCALE/1000)    // behöver denna definieras om ifall prescalern definierats om?
  30. #endif
  31.  
  32. #define TIMEBASE_RELOAD ((uint8_t)(0xff-TIMEBASE_HITS_PER_1MS+1))
  33.  
  34.  
  35. /*-----------------------------------------------------------------------------
  36.  * Public Function Prototypes
  37.  *---------------------------------------------------------------------------*/
  38. void Timebase_Init(void);
  39. uint32_t Timebase_CurrentTime(void);
  40. uint32_t Timebase_PassedTimeMillis(uint32_t t0);
  41.  
  42.  
  43. #endif
  44.